From 02767d44ae50d1442320e3dfbb03dc3642269a67 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Wed, 8 Apr 2015 21:55:05 +0200 Subject: [PATCH 1/4] add filters.js --- angular_app/js/filters.js | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 angular_app/js/filters.js diff --git a/angular_app/js/filters.js b/angular_app/js/filters.js new file mode 100644 index 0000000..bf5a483 --- /dev/null +++ b/angular_app/js/filters.js @@ -0,0 +1,52 @@ +'use strict'; + +/* Filters for EventMan(ager) lists of objects. */ + +/* Filter for events that have (or not) information about a registered person. */ +eventManApp.filter('eventWithPersonData', ['$filter', + function($filter) { + return function(inputArray, mustBePresent) { + if (mustBePresent === undefined) { + mustBePresent = true; + } + inputArray = inputArray || []; + var returnArray = []; + for (var x=0; x < inputArray.length; x++) { + var found = inputArray[x].person_data && inputArray[x].person_data.person_id; + if ((found && mustBePresent) || (!found && !mustBePresent)) { + returnArray.push(inputArray[x]); + } + } + return returnArray; + }; + }] +); + + +/* Filter for persons (not) registered for a given event. */ +eventManApp.filter('personRegistered', ['$filter', + function($filter) { + return function(inputArray, data) { + if (data.present === undefined) { + data.present = true; + } + inputArray = inputArray || []; + var returnArray = []; + var registeredIDs = []; + if (!(data.event && data.event.persons && data.event.persons.length)) { + return inputArray; + } + for (var x=0; x < data.event.persons.length; x++) { + registeredIDs.push(data.event.persons[x].person_id); + } + for (var x=0; x < inputArray.length; x++) { + var found = registeredIDs.indexOf(inputArray[x]._id) != -1; + if ((found && data.present) || (!found && !data.present)) { + returnArray.push(inputArray[x]); + } + } + return returnArray; + } + }] +); + From 6940534d4951e9e0a7d4649909dc746627921376 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Wed, 8 Apr 2015 21:55:23 +0200 Subject: [PATCH 2/4] counter of attendees --- angular_app/event-info.html | 30 +++++++++++++++++------ angular_app/index.html | 1 + angular_app/js/app.js | 46 ----------------------------------- angular_app/js/controllers.js | 25 +++++++++++++++++-- static/css/eventman.css | 4 +++ 5 files changed, 51 insertions(+), 55 deletions(-) diff --git a/angular_app/event-info.html b/angular_app/event-info.html index 3fab01a..eef7d03 100644 --- a/angular_app/event-info.html +++ b/angular_app/event-info.html @@ -1,11 +1,27 @@
-

{{event.title}} - -

+
+
+
+

{{event.title}} + +

+
+
+
+

{{'Registered:' | translate}} {{event.persons.length}}

+
+
+

{{'Attendees:' | translate}} {{countAttendees}}

+
+
+
+
+
@@ -57,7 +73,7 @@
-
{{'Fast add' | translate}}
+
{{'Quick add' | translate}}
diff --git a/angular_app/index.html b/angular_app/index.html index dbe19c3..9e31fc2 100644 --- a/angular_app/index.html +++ b/angular_app/index.html @@ -15,6 +15,7 @@ + diff --git a/angular_app/js/app.js b/angular_app/js/app.js index f306a10..09e8a7d 100644 --- a/angular_app/js/app.js +++ b/angular_app/js/app.js @@ -49,52 +49,6 @@ eventManApp.filter('splittedFilter', ['$filter', ); -/* Filter for events that have (or not) information about a registered person. */ -eventManApp.filter('eventWithPersonData', ['$filter', - function($filter) { - return function(inputArray, mustBePresent) { - if (mustBePresent === undefined) { - mustBePresent = true; - } - inputArray = inputArray || []; - var returnArray = []; - for (var x=0; x < inputArray.length; x++) { - var found = inputArray[x].person_data && inputArray[x].person_data.person_id; - if ((found && mustBePresent) || (!found && !mustBePresent)) { - returnArray.push(inputArray[x]); - } - } - return returnArray; - }; - }] -); - -eventManApp.filter('personRegistered', ['$filter', - function($filter) { - return function(inputArray, data) { - if (data.present === undefined) { - data.present = true; - } - inputArray = inputArray || []; - var returnArray = []; - var registeredIDs = []; - if (!(data.event && data.event.persons && data.event.persons.length)) { - return inputArray; - } - for (var x=0; x < data.event.persons.length; x++) { - registeredIDs.push(data.event.persons[x].person_id); - } - for (var x=0; x < inputArray.length; x++) { - var found = registeredIDs.indexOf(inputArray[x]._id) != -1; - if ((found && data.present) || (!found && !data.present)) { - returnArray.push(inputArray[x]); - } - } - return returnArray; - } - }] -); - /* Directive that can be used to make an input field react to the press of Enter. */ eventManApp.directive('ngEnter', function () { return function (scope, element, attrs) { diff --git a/angular_app/js/controllers.js b/angular_app/js/controllers.js index 7f15e00..2e41917 100644 --- a/angular_app/js/controllers.js +++ b/angular_app/js/controllers.js @@ -1,7 +1,7 @@ 'use strict'; /* Controllers; their method are available where specified with the ng-controller - * directive or for a given route (see app.js). They use some services to + * directive or for a given route/state (see app.js). They use some services to * connect to the backend (see services.js). */ var eventManControllers = angular.module('eventManControllers', []); @@ -57,8 +57,15 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', 'Person', function ($scope, Event, Person, $stateParams, $log) { $scope.personsOrderProp = 'name'; $scope.eventsOrderProp = '-begin-date'; + $scope.countAttendees = 0; if ($stateParams.id) { - $scope.event = Event.get($stateParams); + $scope.event = Event.get($stateParams, function() { + $scope.$watchCollection(function() { + return $scope.event.persons; + }, function(prev, old) { + $scope.calcAttendees(); + }); + }); $scope.allPersons = Person.all(); } // store a new Event or update an existing one @@ -76,6 +83,20 @@ eventManControllers.controller('EventDetailsCtrl', ['$scope', 'Event', 'Person', $scope.eventForm.$dirty = false; }; + $scope.calcAttendees = function() { + if (!($scope.event && $scope.event.persons)) { + return; + } + var attendees = 0; + $log.info($scope.event.persons.length); + angular.forEach($scope.event.persons, function(value, key) { + if (value.attended) { + attendees += 1; + } + }); + $scope.countAttendees = attendees; + }; + $scope._addAttendee = function(person_data) { person_data.person_id = person_data._id; person_data._id = $stateParams.id; diff --git a/static/css/eventman.css b/static/css/eventman.css index 4c3dd67..16d6541 100644 --- a/static/css/eventman.css +++ b/static/css/eventman.css @@ -14,5 +14,9 @@ body { padding-top: 70px; } .vcenter { vertical-align: middle; + /* display: table-cell !important; */ + display: inline-block !important; + float: none; } +/* .row { display: table; } */ From 87c72100f63881ead9dc0b858d14e722d94330a3 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Wed, 8 Apr 2015 22:06:11 +0200 Subject: [PATCH 3/4] rename some actions --- angular_app/event-info.html | 22 +++++++++++----------- angular_app/events-list.html | 2 +- angular_app/persons-list.html | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/angular_app/event-info.html b/angular_app/event-info.html index eef7d03..7e5271c 100644 --- a/angular_app/event-info.html +++ b/angular_app/event-info.html @@ -2,7 +2,7 @@
-
+

{{event.title}}

-
-
-

{{'Registered:' | translate}} {{event.persons.length}}

-
-
-

{{'Attendees:' | translate}} {{countAttendees}}

-
-
+ -->
+
+
+

{{'Registered:' | translate}} {{event.persons.length || 0}}

+
+
+

{{'Attendees:' | translate}} {{countAttendees}}

+
+
@@ -50,7 +50,7 @@ {{'Person' | translate}} {{'Email' | translate}} {{'Attended' | translate}} - {{'Actions' | translate}} + {{'Delete' | translate}} diff --git a/angular_app/events-list.html b/angular_app/events-list.html index 4708559..87a81fb 100644 --- a/angular_app/events-list.html +++ b/angular_app/events-list.html @@ -29,7 +29,7 @@ {{'Event' | translate}} - {{'Actions' | translate}} + {{'Delete' | translate}} diff --git a/angular_app/persons-list.html b/angular_app/persons-list.html index 9a93d88..93f22fc 100644 --- a/angular_app/persons-list.html +++ b/angular_app/persons-list.html @@ -33,7 +33,7 @@ {{'Name' | translate}} - {{'Actions' | translate}} + {{'Delete' | translate}} From a858c415b38c2b994389f2109374a419a1deb866 Mon Sep 17 00:00:00 2001 From: Davide Alberani Date: Wed, 8 Apr 2015 23:02:24 +0200 Subject: [PATCH 4/4] note about information about persons in different collections --- DEVELOPMENT.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index b2dead7..d024ed4 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -67,6 +67,8 @@ events collection Stores information about events and persons registered for a given event. +Please notice that information about a person registered for a given event is solely taken from the event.persons entry, and not to the relative entry in the persons collection. This may change in the future (to integrate missing information), but in general it is correct that, editing (or deleting) a person, older information about the partecipation to an event is not changed. + Main field: - title