1 | (function () {
|
---|
2 | var module = appStatisticsPlugin.getAngularModule();
|
---|
3 | module.controller('app.statistics.userDetailsCtrl',
|
---|
4 | ['$scope', '$stateParams', '$interval', 'app.statistics.userService', 'app.statistics.jobService',
|
---|
5 | function ($scope, $stateParams, $interval, userService, jobService) {
|
---|
6 | $scope.interval = defaultPageUpdateInterval;
|
---|
7 | $scope.completedJobCurPage = 1;
|
---|
8 | $scope.completedJobPageSize = 20;
|
---|
9 |
|
---|
10 | var getUserDetails = function () {
|
---|
11 | userService.getUser({ id: $stateParams.id }, function(user) {
|
---|
12 | $scope.user = user;
|
---|
13 |
|
---|
14 | var length = user.TasksStates.length;
|
---|
15 | var total = 0;
|
---|
16 | for (var i = 0; i < length; ++i) {
|
---|
17 | total += user.TasksStates[i].Count;
|
---|
18 | }
|
---|
19 | $scope.totalUserTasks = total;
|
---|
20 | });
|
---|
21 | };
|
---|
22 |
|
---|
23 | var getAllJobs = function () {
|
---|
24 | jobService.getAllJobsByUserId({ id: $stateParams.id, completed: false }, function (jobs) {
|
---|
25 | $scope.jobs = jobs;
|
---|
26 | });
|
---|
27 | };
|
---|
28 |
|
---|
29 | var getCompletedJobs = function () {
|
---|
30 | jobService.getJobsByUserId({ id: $stateParams.id, page: $scope.completedJobCurPage, size: $scope.completedJobPageSize, completed: true },
|
---|
31 | function (jobPage) {
|
---|
32 | $scope.completedJobPage = jobPage;
|
---|
33 | }
|
---|
34 | );
|
---|
35 | };
|
---|
36 |
|
---|
37 | $scope.changeCompletedJobPage = function () {
|
---|
38 | update();
|
---|
39 | };
|
---|
40 |
|
---|
41 | var update = function () {
|
---|
42 | getUserDetails();
|
---|
43 | getAllJobs();
|
---|
44 | getCompletedJobs();
|
---|
45 | };
|
---|
46 |
|
---|
47 | $scope.updateInterval = $interval(update, $scope.interval);
|
---|
48 | var cancelInterval = $scope.$on('$locationChangeSuccess', function () {
|
---|
49 | $interval.cancel($scope.updateInterval);
|
---|
50 | cancelInterval();
|
---|
51 | });
|
---|
52 | update(); // init page
|
---|
53 | }]
|
---|
54 | );
|
---|
55 | })(); |
---|