Merge pull request #19 from alberanid/master

counters for attendees
This commit is contained in:
Davide Alberani 2015-04-08 23:03:24 +02:00
commit e604a839ff
9 changed files with 108 additions and 58 deletions

View file

@ -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

View file

@ -1,11 +1,27 @@
<!-- show details of an Event -->
<div class="container">
<h1>{{event.title}}
<button ng-if="event._id" ng-click="$state.go('event.edit', {id: event._id})" class="btn btn-success">
<span class="glyphicon glyphicon-edit"></span>
{{'Edit' | translate}}
</button>
</h1>
<div class="container">
<div class="row">
<div class="col-md-7 col-xs-7 vcenter">
<h1>{{event.title}}
<button ng-if="event._id" ng-click="$state.go('event.edit', {id: event._id})" class="btn btn-success">
<span class="glyphicon glyphicon-edit"></span>
{{'Edit' | translate}}
</button>
</h1>
</div><!--
--><div class="col-md-5 col-xs-5 vcenter">
<div class="row">
<div class="col-md-6">
<h2><div class="label label-warning vcenter">{{'Registered:' | translate}} {{event.persons.length || 0}}</div></h2>
</div>
<div class="col-md-6">
<h2><div class="label label-info vcenter">{{'Attendees:' | translate}} {{countAttendees}}</div></h2>
</div>
</div>
</div>
</div>
</div>
<div class="container">
<div class="row">
@ -34,7 +50,7 @@
<th>{{'Person' | translate}}</th>
<th>{{'Email' | translate}}</th>
<th>{{'Attended' | translate}}</th>
<th>{{'Actions' | translate}}</th>
<th>{{'Delete' | translate}}</th>
</tr>
</thead>
<tbody>
@ -57,7 +73,7 @@
<div class="col-md-4">
<div class="panel panel-info table-striped top5">
<div class="panel-heading">{{'Fast add' | translate}}</div>
<div class="panel-heading">{{'Quick add' | translate}}</div>
<div class="panel-body">
<form>
<div class="input-group input-group-sm">

View file

@ -29,7 +29,7 @@
<thead>
<tr>
<td><strong>{{'Event' | translate}}</strong></td>
<td><strong>{{'Actions' | translate}}</strong></td>
<td><strong>{{'Delete' | translate}}</strong></td>
</tr>
</thead>
<tbody>

View file

@ -15,6 +15,7 @@
<script src="/static/js/eventman.js"></script>
<script src="/js/app.js"></script>
<script src="/js/i18n.js"></script>
<script src="/js/filters.js"></script>
<script src="/js/services.js"></script>
<script src="/js/controllers.js"></script>
<link href="/static/css/normalize.css" rel="stylesheet">

46
angular_app/js/app.js vendored
View file

@ -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) {

View file

@ -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;

52
angular_app/js/filters.js vendored Normal file
View file

@ -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;
}
}]
);

View file

@ -33,7 +33,7 @@
<thead>
<tr>
<td><strong>{{'Name' | translate}}</strong></td>
<td><strong>{{'Actions' | translate}}</strong></td>
<td><strong>{{'Delete' | translate}}</strong></td>
</tr>
</thead>
<tbody>

View file

@ -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; } */