Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Services.WebApp.Statistics/3.3/WebApp/clients/details/clientDetailsCtrl.js @ 12551

Last change on this file since 12551 was 12551, checked in by dglaser, 9 years ago

#2388:

HeuristicLab.Services.Hive.DataAccess-3.3:

  • updated database schema
  • updated sql scripts
  • updated HiveStatisticsGenerator

HeuristicLab.Services.WebApp-3.3:

  • merged from trunk

HeuristicLab.Services.WebApp.Status-3.3:

  • updated data api controller

HeuristicLab.Services.WebApp.Statistics-3.3:

  • added exception page
  • improved jobs, clients, users and groups page
File size: 9.1 KB
Line 
1(function () {
2    var module = appStatisticsPlugin.getAngularModule();
3    module.controller('app.statistics.clientDetailsCtrl',
4        ['$scope', '$stateParams', '$interval', 'app.statistics.clientService', 'app.statistics.taskService', '$modal',
5        function ($scope, $stateParams, $interval, clientService, taskService, $modal) {
6            $scope.curUserId = '00000000-0000-0000-0000-000000000000';
7            $scope.curUserName = 'All Users';
8            $scope.interval = defaultPageUpdateInterval;
9            $scope.curTaskPage = 1;
10            $scope.taskPageSize = 12;
11
12            // details
13            $scope.knobOptions = {
14                'fgColor': "#f7921d",
15                'angleOffset': -125,
16                'angleArc': 250,
17                'readOnly': true,
18                'width': "80%",
19                'targetvalue': "100",
20                'format': function (value) {
21                    return value;
22                },
23                draw: function () {
24                    $(this.i).val(this.cv + '%');
25                }
26            };
27
28            $scope.knobData = {
29                cores: 0,
30                cpu: 0,
31                memory: 0
32            };
33
34            var getClientDetails = function () {
35                clientService.getClientDetails({ id: $stateParams.id }, function (client) {
36                    $scope.client = client;
37                    $scope.knobData.cores = (client.UsedCores / client.TotalCores) * 100;
38                    $scope.knobData.cpu = client.CpuUtilization;
39                    $scope.knobData.memory = (client.UsedMemory / client.TotalMemory) * 100;
40
41                    var length = client.TasksStates.length;
42                    var total = 0;
43                    var jsStates = [];
44                    for (var i = 0; i < length; ++i) {
45                        var state = client.TasksStates[i];
46                        var selected = true;
47                        if (isDefined($scope.states)) {
48                            for (var j = 0; j < $scope.states.length; ++j) {
49                                if (state.State == $scope.states[j].State) {
50                                    selected = $scope.states[j].Selected;
51                                    break;
52                                }
53                            }
54                        }
55                        jsStates.push({
56                            State: state.State,
57                            Count: state.Count,
58                            Selected: selected
59                        });
60                        total += state.Count;
61                    }
62                    $scope.totalClientTasks = total;
63                    $scope.states = jsStates;
64                    getTasks();
65                });
66            };
67
68            // tasks
69            var getTasks = function () {
70                var states = [];
71                var length = $scope.states.length;
72                for (var i = 0; i < length; ++i) {
73                    var state = $scope.states[i];
74                    if (state.Selected) {
75                        states.push(state.State);
76                    }
77                }
78
79                taskService.getTasksByClientId({ id: $stateParams.id, page: $scope.curTaskPage, size: $scope.taskPageSize, userId: $scope.curUserId }, states,
80                    function (taskPage) {
81                        $scope.taskPage = taskPage;
82                    }
83                );
84            };
85
86            $scope.changeTaskPage = function () {
87                getClientDetails();
88                $('html, body').animate({
89                    scrollTop: $("#tasks-filter").offset().top
90                }, 10);
91            };
92
93            $scope.filterTaskState = function (state) {
94                state.Selected = !state.Selected;
95                $scope.curTaskPage = 1;
96                getClientDetails();
97            };
98
99            $scope.userChanged = function(id, name) {
100                $scope.curUserId = id;
101                $scope.curUserName = name;
102                getClientDetails();
103            };
104
105            $scope.openDialog = function (taskNo, task) {
106                $scope.currentTaskNo = taskNo;
107                $scope.currentTask = task;
108                $modal.open({
109                    templateUrl: 'plugin=statistics&view=WebApp/clients/details/clientTaskDetailsDialog.cshtml',
110                    controller: 'app.statistics.clientTaskDetailsDialogCtrl',
111                    windowClass: 'app-modal-window',
112                    resolve: {
113                        task: function () {
114                            return $scope.currentTask;
115                        },
116                        taskNo: function () {
117                            return $scope.currentTaskNo;
118                        }
119                    }
120                });
121            };
122
123            // charts
124            $scope.chartOptions = {
125                grid: {
126                    borderWidth: 1,
127                    labelMargin: 15
128                },
129                series: {
130                    shadowSize: 0
131                },
132                yaxis: {
133                    min: 0,
134                    max: 100,
135                    zoomRange: false,
136                    panRange: false
137                },
138                xaxis: {
139                    mode: "time",
140                    twelveHourClock: false
141                }
142            };
143
144            $scope.fillChartOptions = {
145                grid: {
146                    borderWidth: 1,
147                    labelMargin: 15
148                },
149                series: {
150                    shadowSize: 0,
151                    lines: {
152                        show: true,
153                        fill: true
154                    }
155                },
156                yaxis: {
157                    zoomRange: false,
158                    panRange: false
159                },
160                xaxis: {
161                    mode: "time",
162                    twelveHourClock: false
163                }
164            };
165
166            $scope.fromDate = new Date();
167            $scope.toDate = new Date();
168
169            $scope.fromIsOpen = false;
170            $scope.toIsOpen = false;
171
172            $scope.openFromDateSelection = function ($event) {
173                $event.preventDefault();
174                $event.stopPropagation();
175                $scope.toIsOpen = false;
176                $scope.fromIsOpen = true;
177            };
178
179            $scope.openToDateSelection = function ($event) {
180                $event.preventDefault();
181                $event.stopPropagation();
182                $scope.fromIsOpen = false;
183                $scope.toIsOpen = true;
184            };
185
186            $scope.dateOptions = {
187                formatYear: 'yy',
188                startingDay: 1
189            };
190
191            $scope.cpuSeries = [[]];
192            $scope.coreSeries = [[]];
193            $scope.memorySeries = [[]];
194
195            $scope.updateCharts = function () {
196                clientService.getClientHistory({ id: $stateParams.id, start: ConvertFromDate($scope.fromDate), end: ConvertToDate($scope.toDate) }, function (status) {
197                    var noOfStatus = status.length;
198                    var cpuSeries = [];
199                    var coreSeries = [[], []];
200                    var memorySeries = [[], []];
201                    for (var i = 0; i < noOfStatus; ++i) {
202                        var curStatus = status[i];
203                        var cpuData = Math.round(curStatus.CpuUtilization);
204                        cpuSeries.push([curStatus.Timestamp, cpuData]);
205                        coreSeries[0].push([curStatus.Timestamp, curStatus.TotalCores]);
206                        coreSeries[1].push([curStatus.Timestamp, curStatus.UsedCores]);
207                        memorySeries[0].push([curStatus.Timestamp, curStatus.TotalMemory]);
208                        memorySeries[1].push([curStatus.Timestamp, curStatus.UsedMemory]);
209                    }
210                    $scope.cpuSeries = [{ data: cpuSeries, label: "&nbsp;CPU Utilization", color: "#f7921d" }];
211                    $scope.coreSeries = [
212                        { data: coreSeries[0], label: "&nbsp;Total Cores", color: "LightGreen" },
213                        { data: coreSeries[1], label: "&nbsp;Used Cores", color: "LightPink" }
214                    ];
215                    $scope.memorySeries = [
216                        { data: memorySeries[0], label: "&nbsp;Total Memory", color: "LightGreen" },
217                        { data: memorySeries[1], label: "&nbsp;Used Memory", color: "LightPink" }
218                    ];
219
220                });
221            };
222
223            var update = function () {
224                getClientDetails();
225            };
226
227            $scope.updateInterval = $interval(update, $scope.interval);
228            var cancelInterval = $scope.$on('$locationChangeSuccess', function () {
229                $interval.cancel($scope.updateInterval);
230                cancelInterval();
231            });
232            update(); // init page
233            $scope.updateCharts();
234        }]
235    );
236})();
Note: See TracBrowser for help on using the repository browser.