1 | (function () {
|
---|
2 | var module = appStatisticsPlugin.getAngularModule();
|
---|
3 | module.controller('app.statistics.jobsCtrl',
|
---|
4 | ['$scope', '$interval', 'app.statistics.jobService', function ($scope, $interval, jobService) {
|
---|
5 | var first = true;
|
---|
6 | $scope.isAdministrator = false;
|
---|
7 | $scope.interval = defaultPageUpdateInterval;
|
---|
8 | $scope.completedJobCurPage = 1;
|
---|
9 | $scope.completedJobPageSize = 20;
|
---|
10 |
|
---|
11 | var getAllJobs = function() {
|
---|
12 | jobService.getAllJobs({ completed: false }, function(jobs) {
|
---|
13 | $scope.jobs = jobs;
|
---|
14 | });
|
---|
15 | };
|
---|
16 |
|
---|
17 | var getCompletedJobs = function() {
|
---|
18 | jobService.getJobs({ page: $scope.completedJobCurPage, size: $scope.completedJobPageSize, completed: true },
|
---|
19 | function (jobPage) {
|
---|
20 | $scope.completedJobPage = jobPage;
|
---|
21 | }
|
---|
22 | );
|
---|
23 | };
|
---|
24 |
|
---|
25 | var getAllActiveJobsFromAllUsers = function () {
|
---|
26 | jobService.getAllActiveJobsFromAllUsers({}, function (jobs) {
|
---|
27 | $scope.isAdministrator = true;
|
---|
28 | $scope.allUsersJobs = jobs;
|
---|
29 | });
|
---|
30 | };
|
---|
31 |
|
---|
32 | $scope.changeCompletedJobPage = function () {
|
---|
33 | update();
|
---|
34 | };
|
---|
35 |
|
---|
36 | var update = function () {
|
---|
37 | getAllJobs();
|
---|
38 | if (first || $scope.isAdministrator) {
|
---|
39 | getAllActiveJobsFromAllUsers();
|
---|
40 | }
|
---|
41 | getCompletedJobs();
|
---|
42 | };
|
---|
43 |
|
---|
44 | $scope.updateInterval = $interval(update, $scope.interval);
|
---|
45 | var cancelInterval = $scope.$on('$locationChangeSuccess', function () {
|
---|
46 | $interval.cancel($scope.updateInterval);
|
---|
47 | cancelInterval();
|
---|
48 | });
|
---|
49 | update(); // init page
|
---|
50 | first = false;
|
---|
51 | }]
|
---|
52 | );
|
---|
53 | })(); |
---|