fixes #82: sort events by date
This commit is contained in:
parent
458ece4791
commit
f88294c7ba
4 changed files with 29 additions and 41 deletions
|
@ -19,8 +19,8 @@
|
||||||
<select id="events-order" class="form-control" ng-model="eventsOrderProp">
|
<select id="events-order" class="form-control" ng-model="eventsOrderProp">
|
||||||
<option value="title">{{'Title' | translate}}</option>
|
<option value="title">{{'Title' | translate}}</option>
|
||||||
<option value="-title">{{'Title (descending)' | translate}}</option>
|
<option value="-title">{{'Title (descending)' | translate}}</option>
|
||||||
<option value="'begin-date'">{{'Date' | translate}}</option>
|
<option value="begin_date">{{'Date' | translate}}</option>
|
||||||
<option value="'-begin-date'">{{'Date (descending)' | translate}}</option>
|
<option value="-begin_date">{{'Date (descending)' | translate}}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
4
angular_app/js/controllers.js
vendored
4
angular_app/js/controllers.js
vendored
|
@ -66,7 +66,7 @@ eventManControllers.controller('EventsListCtrl', ['$scope', 'Event', '$modal', '
|
||||||
function ($scope, Event, $modal, $log, $translate, $rootScope) {
|
function ($scope, Event, $modal, $log, $translate, $rootScope) {
|
||||||
$scope.events = Event.all();
|
$scope.events = Event.all();
|
||||||
$scope.personsOrderProp = 'name';
|
$scope.personsOrderProp = 'name';
|
||||||
$scope.eventsOrderProp = "'-begin-date'";
|
$scope.eventsOrderProp = "-begin_date";
|
||||||
|
|
||||||
$scope.confirm_delete = 'Do you really want to delete this event?';
|
$scope.confirm_delete = 'Do you really want to delete this event?';
|
||||||
$rootScope.$on('$translateChangeSuccess', function () {
|
$rootScope.$on('$translateChangeSuccess', function () {
|
||||||
|
@ -402,7 +402,7 @@ eventManControllers.controller('PersonsListCtrl', ['$scope', 'Person', 'Setting'
|
||||||
eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$stateParams', 'Person', 'Event', 'Setting', '$log',
|
eventManControllers.controller('PersonDetailsCtrl', ['$scope', '$stateParams', 'Person', 'Event', 'Setting', '$log',
|
||||||
function ($scope, $stateParams, Person, Event, Setting, $log) {
|
function ($scope, $stateParams, Person, Event, Setting, $log) {
|
||||||
$scope.personsOrderProp = 'name';
|
$scope.personsOrderProp = 'name';
|
||||||
$scope.eventsOrderProp = '-begin-date';
|
$scope.eventsOrderProp = '-begin_date';
|
||||||
$scope.addToEvent = '';
|
$scope.addToEvent = '';
|
||||||
$scope.customFields = Setting.query({setting: 'person_custom_field',
|
$scope.customFields = Setting.query({setting: 'person_custom_field',
|
||||||
in_persons_list: true});
|
in_persons_list: true});
|
||||||
|
|
58
angular_app/js/services.js
vendored
58
angular_app/js/services.js
vendored
|
@ -4,6 +4,18 @@
|
||||||
var eventManServices = angular.module('eventManServices', ['ngResource']);
|
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',
|
eventManServices.factory('Event', ['$resource', '$rootScope',
|
||||||
function($resource, $rootScope) {
|
function($resource, $rootScope) {
|
||||||
return $resource('events/:id', {id: '@_id', person_id: '@person_id'}, {
|
return $resource('events/:id', {id: '@_id', person_id: '@person_id'}, {
|
||||||
|
@ -12,19 +24,18 @@ eventManServices.factory('Event', ['$resource', '$rootScope',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
isArray: true,
|
isArray: true,
|
||||||
transformResponse: function(data, headers) {
|
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',
|
get: {method: 'GET',
|
||||||
transformResponse: function(data, headers) {
|
transformResponse: function(data, headers) {
|
||||||
data = angular.fromJson(data);
|
data = angular.fromJson(data);
|
||||||
if (data && data['begin-datetime']) {
|
convert_dates(data);
|
||||||
data['begin-date'] = data['begin-date'].getTime();
|
|
||||||
}
|
|
||||||
if (data && data['end-datetime']) {
|
|
||||||
data['end-date'] = data['end-date'].getTime();
|
|
||||||
}
|
|
||||||
// strip empty keys.
|
// strip empty keys.
|
||||||
angular.forEach(data.persons || [], function(person, person_idx) {
|
angular.forEach(data.persons || [], function(person, person_idx) {
|
||||||
angular.forEach(person, function(value, key) {
|
angular.forEach(person, function(value, key) {
|
||||||
|
@ -92,34 +103,11 @@ eventManServices.factory('Person', ['$resource',
|
||||||
url: 'persons/:_id/events',
|
url: 'persons/:_id/events',
|
||||||
isArray: true,
|
isArray: true,
|
||||||
transformResponse: function(data, headers) {
|
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;
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
<select id="events-order" class="form-control" ng-model="eventsOrderProp">
|
<select id="events-order" class="form-control" ng-model="eventsOrderProp">
|
||||||
<option value="title">{{'Title' | translate}}</option>
|
<option value="title">{{'Title' | translate}}</option>
|
||||||
<option value="-title">{{'Title (descending)' | translate}}</option>
|
<option value="-title">{{'Title (descending)' | translate}}</option>
|
||||||
<option value="begin-date">{{'Date' | translate}}</option>
|
<option value="begin_date">{{'Date' | translate}}</option>
|
||||||
<option value="-begin-date">{{'Date (descending)' | translate}}</option>
|
<option value="-begin_date">{{'Date (descending)' | translate}}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in a new issue