/
partiesList.js
79 lines (67 loc) · 1.71 KB
/
partiesList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import angular from 'angular';
import angularMeteor from 'angular-meteor';
import uiRouter from 'angular-ui-router';
import utilsPagination from 'angular-utils-pagination';
import { Counts } from 'meteor/tmeasday:publish-counts';
import template from './partiesList.html';
import { Parties } from '../../../api/parties';
import { name as PartiesSort } from '../partiesSort/partiesSort';
import { name as PartyAdd } from '../partyAdd/partyAdd';
import { name as PartyRemove } from '../partyRemove/partyRemove';
class PartiesList {
constructor($scope, $reactive) {
'ngInject';
$reactive(this).attach($scope);
this.perPage = 3;
this.page = 1;
this.sort = {
name: 1
};
this.searchText = '';
this.subscribe('parties', () => [{
limit: parseInt(this.perPage),
skip: parseInt((this.getReactively('page') - 1) * this.perPage),
sort: this.getReactively('sort')
}, this.getReactively('searchText')
]);
this.helpers({
parties() {
return Parties.find({}, {
sort : this.getReactively('sort')
});
},
partiesCount() {
return Counts.get('numberOfParties');
}
});
}
pageChanged(newPage) {
this.page = newPage;
}
sortChanged(sort) {
this.sort = sort;
}
}
const name = 'partiesList';
// create a module
export default angular.module(name, [
angularMeteor,
uiRouter,
utilsPagination,
PartiesSort,
PartyAdd,
PartyRemove
]).component(name, {
template,
controllerAs: name,
controller: PartiesList
})
.config(config);
function config($stateProvider) {
'ngInject';
$stateProvider
.state('parties', {
url: '/parties',
template: '<parties-list></parties-list>'
});
}