Free cookie consent management tool by TermsFeed Policy Generator

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

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

#2388:

HeuristicLab.Services.WebApp.Statistics-3.3:

  • Added QuickSelection button to the client and group pag

HeuristicLab.Services.WebApp-3.3:
HeuristicLab.Services.WebApp.Statistics-3.3:

  • Changed 'User Name' to 'Username' to be consistent throughout the whole WebApp
File size: 10.8 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                $scope.curTaskPage = 1;
103                getClientDetails();
104            };
105
106            $scope.openDialog = function (taskNo, task) {
107                $scope.currentTaskNo = taskNo;
108                $scope.currentTask = task;
109                $modal.open({
110                    templateUrl: 'plugin=statistics&view=WebApp/clients/details/clientTaskDetailsDialog.cshtml',
111                    controller: 'app.statistics.clientTaskDetailsDialogCtrl',
112                    windowClass: 'app-modal-window',
113                    resolve: {
114                        task: function () {
115                            return $scope.currentTask;
116                        },
117                        taskNo: function () {
118                            return $scope.currentTaskNo;
119                        }
120                    }
121                });
122            };
123
124            // charts
125            $scope.chartOptions = {
126                grid: {
127                    borderWidth: 1,
128                    labelMargin: 15
129                },
130                series: {
131                    shadowSize: 0
132                },
133                yaxis: {
134                    min: 0,
135                    max: 100,
136                    zoomRange: false,
137                    panRange: false
138                },
139                xaxis: {
140                    mode: "time",
141                    twelveHourClock: false
142                }
143            };
144
145            $scope.fillChartOptions = {
146                grid: {
147                    borderWidth: 1,
148                    labelMargin: 15
149                },
150                series: {
151                    shadowSize: 0,
152                    lines: {
153                        show: true,
154                        fill: true
155                    }
156                },
157                yaxis: {
158                    zoomRange: false,
159                    panRange: false
160                },
161                xaxis: {
162                    mode: "time",
163                    twelveHourClock: false
164                }
165            };
166
167            $scope.fromDate = new Date();
168            $scope.toDate = new Date();
169
170            $scope.fromIsOpen = false;
171            $scope.toIsOpen = false;
172
173            $scope.quickSelectionList = [
174                { id: 0, name: 'Custom' },
175                { id: 1, name: 'Today' },
176                { id: 2, name: 'Yesterday' },
177                { id: 3, name: 'Last 7 Days' },
178                { id: 4, name: 'Last 30 Days' }
179            ];
180            $scope.changeQuickSelection = function (quickSelection) {
181                var today = new Date();
182                var oneDayInMs = 24 * 60 * 60 * 1000;
183                switch (quickSelection.id) {
184                    case 1:
185                        $scope.fromDate = new Date(today.valueOf());
186                        $scope.toDate = new Date(today.valueOf());
187                        break;
188                    case 2:
189                        $scope.fromDate = new Date(today.valueOf() - oneDayInMs);
190                        $scope.toDate = new Date(today.valueOf() - oneDayInMs);
191                        break;
192                    case 3:
193                        $scope.fromDate = new Date(today.valueOf() - (7 * oneDayInMs));
194                        $scope.toDate = new Date(today.valueOf());
195                        break;
196                    case 4:
197                        $scope.fromDate = new Date(today.valueOf() - (30 * oneDayInMs));
198                        $scope.toDate = new Date(today.valueOf());
199                        break;
200                }
201                $scope.curQuickSelection = quickSelection;
202            };
203            // set default 'today'
204            $scope.changeQuickSelection($scope.quickSelectionList[1]);
205
206            $scope.openFromDateSelection = function ($event) {
207                $event.preventDefault();
208                $event.stopPropagation();
209                $scope.toIsOpen = false;
210                $scope.fromIsOpen = true;
211                $scope.curQuickSelection = $scope.quickSelectionList[0];
212            };
213
214            $scope.openToDateSelection = function ($event) {
215                $event.preventDefault();
216                $event.stopPropagation();
217                $scope.fromIsOpen = false;
218                $scope.toIsOpen = true;
219                $scope.curQuickSelection = $scope.quickSelectionList[0];
220            };
221
222            $scope.dateOptions = {
223                formatYear: 'yy',
224                startingDay: 1
225            };
226
227            $scope.cpuSeries = [[]];
228            $scope.coreSeries = [[]];
229            $scope.memorySeries = [[]];
230
231            $scope.updateCharts = function () {
232                clientService.getClientHistory({ id: $stateParams.id, start: ConvertFromDate($scope.fromDate), end: ConvertToDate($scope.toDate) }, function (status) {
233                    var noOfStatus = status.length;
234                    var cpuSeries = [];
235                    var coreSeries = [[], []];
236                    var memorySeries = [[], []];
237                    for (var i = 0; i < noOfStatus; ++i) {
238                        var curStatus = status[i];
239                        var cpuData = Math.round(curStatus.CpuUtilization);
240                        cpuSeries.push([curStatus.Timestamp, cpuData]);
241                        coreSeries[0].push([curStatus.Timestamp, curStatus.TotalCores]);
242                        coreSeries[1].push([curStatus.Timestamp, curStatus.UsedCores]);
243                        memorySeries[0].push([curStatus.Timestamp, curStatus.TotalMemory]);
244                        memorySeries[1].push([curStatus.Timestamp, curStatus.UsedMemory]);
245                    }
246                    $scope.cpuSeries = [{ data: cpuSeries, label: "&nbsp;CPU Utilization", color: "#f7921d" }];
247                    $scope.coreSeries = [
248                        { data: coreSeries[0], label: "&nbsp;Total Cores", color: "LightGreen" },
249                        { data: coreSeries[1], label: "&nbsp;Used Cores", color: "LightPink" }
250                    ];
251                    $scope.memorySeries = [
252                        { data: memorySeries[0], label: "&nbsp;Total Memory", color: "LightGreen" },
253                        { data: memorySeries[1], label: "&nbsp;Used Memory", color: "LightPink" }
254                    ];
255
256                });
257            };
258
259            var update = function () {
260                getClientDetails();
261            };
262
263            $scope.updateInterval = $interval(update, $scope.interval);
264            var cancelInterval = $scope.$on('$locationChangeSuccess', function () {
265                $interval.cancel($scope.updateInterval);
266                cancelInterval();
267            });
268            update(); // init page
269            $scope.updateCharts();
270        }]
271    );
272})();
Note: See TracBrowser for help on using the repository browser.