+ $scope.list = [];
+ $scope.list_results = 0;
+ $scope.pager = {
+ page: 1,
+ limit: 10,
+ results: 0,
+ last_page: 0
+ };
+ $scope.search = {};
+ $scope.ready = false;
+ $scope.filters = [ 'student', 'hpd_member', 'reception', 'dinner' ];
+
+ $scope.all_registrations = Registration.query( function() {
+ var Counts = {};
+ var inc_count = function(type) {
+ if ( ! angular.isNumber( Counts[type] ) ) {
+ Counts[type] = 1;
+ } else {
+ Counts[type]++;
+ }
+ };
+ angular.forEach( $scope.all_registrations, function(value, key) {
+ if ( ! value.user ) {
+ $log.error("all_registrations user corrupted for registration", key, value);
+ return;
+ }
+
+ var type = value.user.registration_type;
+ inc_count( type );
+ inc_count( '' ); // total
+ angular.forEach( $scope.filters, function(subtype) {
+ var v = value.user[subtype];
+ if ( v === 'yes' || v === true ) {
+ inc_count( subtype );
+ inc_count( type + '+' + subtype );
+ inc_count( '+' + subtype ); // total
+ }
+ });
+
+ // for filter
+ value.registration_type = type;
+ angular.forEach( $scope.filters, function(f) {
+ var v = value.user[f];
+ value[f] = v == true || v == 'yes' ? true : false;
+ });
+
+// $log.info( key, value, Counts[type] );
+ });
+ $log.info('Counts', Counts);
+ $scope.Counts = Counts;
+
+// $scope.list = $scope.all_registrations; // FIXME show all registrations on page loadyy
+ $scope.ready = true;
+
+ });
+
+ $scope.filter_list = function(newVal, oldVal) {
+ if ( newVal == oldVal ) return;
+ $log.info('filter_list', newVal, oldVal, 'search', $scope.search);
+ var filtered =
+ $filter('filter')($scope.all_registrations, $scope.search);
+
+// $scope.pager.page = 1;
+ $scope.pager.results = filtered.length;
+ $scope.pager.last_page = Math.ceil( $scope.pager.results / $scope.pager.limit );
+ if ( $scope.pager.page > $scope.pager.last_page ) {
+ $scope.pager.page = 1;
+ }
+ $log.info('pager', $scope.pager);
+
+ var from = ( $scope.pager.page - 1 ) * $scope.pager.limit;
+ $scope.list = [];
+ angular.forEach( filtered, function(v,k) {
+ if ( k >= from && k < from + $scope.pager.limit ) {
+ v.nr = k + 1;
+ this.push(v);
+ }
+ }, $scope.list );
+ $log.info('list length=', $scope.list.length, "offset=", from);
+ };
+ angular.forEach( $scope.filters, function(f) {
+ $scope.$watch('search.'+f, $scope.filter_list);
+ $log.info('watch search.'+f);
+ });
+ $scope.$watch('search.registration_type', $scope.filter_list);
+ $scope.$watch('search.$', $scope.filter_list);
+ $scope.$watch('pager.page', $scope.filter_list);
+ $scope.$watch('pager.limit', $scope.filter_list);
+
+ $scope.RegistrationTypes = RegistrationTypes;
+ $log.info( "RegistrationTypes", RegistrationTypes );