fixes #82: sort events by date

This commit is contained in:
Davide Alberani 2016-04-25 13:40:03 +02:00
parent 458ece4791
commit f88294c7ba
4 changed files with 29 additions and 41 deletions

View file

@ -19,8 +19,8 @@
<select id="events-order" class="form-control" ng-model="eventsOrderProp">
<option value="title">{{'Title' | translate}}</option>
<option value="-title">{{'Title (descending)' | translate}}</option>
<option value="'begin-date'">{{'Date' | translate}}</option>
<option value="'-begin-date'">{{'Date (descending)' | translate}}</option>
<option value="begin_date">{{'Date' | translate}}</option>
<option value="-begin_date">{{'Date (descending)' | translate}}</option>
</select>
</div>
</form>

View file

@ -66,7 +66,7 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$modal', '
function ($scope, Event, $modal, $log, $translate, $rootScope) {
$scope.events = Event.all();
$scope.personsOrderProp = 'name';
$scope.eventsOrderProp = "'-begin-date'";
$scope.eventsOrderProp = "-begin_date";
$scope.confirm_delete = 'Do you really want to delete this event?';
$rootScope.$on('$translateChangeSuccess', function () {
@ -402,7 +402,7 @@ eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person', 'Setting'
eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$stateParams', 'Person', 'Event', 'Setting', '$log',
function ($scope, $stateParams, Person, Event, Setting, $log) {
$scope.personsOrderProp = 'name';
$scope.eventsOrderProp = '-begin-date';
$scope.eventsOrderProp = '-begin_date';
$scope.addToEvent = '';
$scope.customFields = Setting.query({setting: 'person_custom_field',
in_persons_list: true});

View file

@ -4,6 +4,18 @@
var eventManServices = angular.module('eventManServices', ['ngResource']);
/* Modify, in place, an object to convert datetime. */
function convert_dates(obj) {
if (obj['begin-date']) {
obj['begin-date'] = obj['begin_date'] = obj['begin-date'].getTime();
}
if (obj['end-date']) {
obj['end-date'] = obj['end_date'] = obj['end-date'].getTime();
}
return obj;
}
eventManServices.factory('Event', ['$resource', '$rootScope',
function($resource, $rootScope) {
return $resource('events/:id', {id: '@_id', person_id: '@person_id'}, {
@ -12,19 +24,18 @@ eventManServices.factory('Event', ['$resource', '$rootScope',
method: 'GET',
isArray: true,
transformResponse: function(data, headers) {
return angular.fromJson(data).events;
data = angular.fromJson(data);
angular.forEach(data.events || [], function(event_, event_idx) {
convert_dates(event_);
});
return data.events;
}
},
get: {method: 'GET',
transformResponse: function(data, headers) {
data = angular.fromJson(data);
if (data && data['begin-datetime']) {
data['begin-date'] = data['begin-date'].getTime();
}
if (data && data['end-datetime']) {
data['end-date'] = data['end-date'].getTime();
}
convert_dates(data);
// strip empty keys.
angular.forEach(data.persons || [], function(person, person_idx) {
angular.forEach(person, function(value, key) {
@ -92,34 +103,11 @@ eventManServices.factory('Person', ['$resource',
url: 'persons/:_id/events',
isArray: true,
transformResponse: function(data, headers) {
return angular.fromJson(data).events;
}
}
data = angular.fromJson(data);
angular.forEach(data.events || [], function(event_, event_idx) {
convert_dates(event_);
});
}]
);
eventManServices.factory('Person', ['$resource',
function($resource) {
return $resource('persons/:id', {id: '@_id'}, {
all: {
method: 'GET',
isArray: true,
transformResponse: function(data, headers) {
return angular.fromJson(data).persons;
}
},
update: {method: 'PUT'},
getEvents: {
method: 'GET',
url: 'persons/:_id/events',
isArray: true,
transformResponse: function(data, headers) {
return angular.fromJson(data).events;
return data.events;
}
}
});

View file

@ -19,8 +19,8 @@
<select id="events-order" class="form-control" ng-model="eventsOrderProp">
<option value="title">{{'Title' | translate}}</option>
<option value="-title">{{'Title (descending)' | translate}}</option>
<option value="begin-date">{{'Date' | translate}}</option>
<option value="-begin-date">{{'Date (descending)' | translate}}</option>
<option value="begin_date">{{'Date' | translate}}</option>
<option value="-begin_date">{{'Date (descending)' | translate}}</option>
</select>
</div>
</form>