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 | { id: 5, name: 'Last 6 Months' },
|
---|
180 | { id: 6, name: 'Last Year' }
|
---|
181 | ];
|
---|
182 | $scope.changeQuickSelection = function (quickSelection) {
|
---|
183 | var today = new Date();
|
---|
184 | var oneDayInMs = 24 * 60 * 60 * 1000;
|
---|
185 | switch (quickSelection.id) {
|
---|
186 | case 1:
|
---|
187 | $scope.fromDate = new Date(today.valueOf());
|
---|
188 | $scope.toDate = new Date(today.valueOf());
|
---|
189 | break;
|
---|
190 | case 2:
|
---|
191 | $scope.fromDate = new Date(today.valueOf() - oneDayInMs);
|
---|
192 | $scope.toDate = new Date(today.valueOf() - oneDayInMs);
|
---|
193 | break;
|
---|
194 | case 3:
|
---|
195 | $scope.fromDate = new Date(today.valueOf() - (7 * oneDayInMs));
|
---|
196 | $scope.toDate = new Date(today.valueOf());
|
---|
197 | break;
|
---|
198 | case 4:
|
---|
199 | $scope.fromDate = new Date(today.valueOf() - (30 * oneDayInMs));
|
---|
200 | $scope.toDate = new Date(today.valueOf());
|
---|
201 | break;
|
---|
202 | case 5:
|
---|
203 | var month = today.getMonth() - 6;
|
---|
204 | if (month < 0) {
|
---|
205 | month += 12;
|
---|
206 | }
|
---|
207 | $scope.fromDate = new Date(today.valueOf());
|
---|
208 | $scope.fromDate.setMonth(month);
|
---|
209 | $scope.toDate = new Date(today.valueOf());
|
---|
210 | break;
|
---|
211 | case 6:
|
---|
212 | $scope.fromDate = new Date(today.valueOf());
|
---|
213 | $scope.fromDate.setFullYear(today.getFullYear() - 1);
|
---|
214 | $scope.toDate = new Date(today.valueOf());
|
---|
215 | break;
|
---|
216 | }
|
---|
217 | $scope.curQuickSelection = quickSelection;
|
---|
218 | };
|
---|
219 | // set default 'today'
|
---|
220 | $scope.changeQuickSelection($scope.quickSelectionList[1]);
|
---|
221 |
|
---|
222 | $scope.openFromDateSelection = function ($event) {
|
---|
223 | $event.preventDefault();
|
---|
224 | $event.stopPropagation();
|
---|
225 | $scope.toIsOpen = false;
|
---|
226 | $scope.fromIsOpen = true;
|
---|
227 | $scope.curQuickSelection = $scope.quickSelectionList[0];
|
---|
228 | };
|
---|
229 |
|
---|
230 | $scope.openToDateSelection = function ($event) {
|
---|
231 | $event.preventDefault();
|
---|
232 | $event.stopPropagation();
|
---|
233 | $scope.fromIsOpen = false;
|
---|
234 | $scope.toIsOpen = true;
|
---|
235 | $scope.curQuickSelection = $scope.quickSelectionList[0];
|
---|
236 | };
|
---|
237 |
|
---|
238 | $scope.dateOptions = {
|
---|
239 | formatYear: 'yy',
|
---|
240 | startingDay: 1
|
---|
241 | };
|
---|
242 |
|
---|
243 | $scope.cpuSeries = [[]];
|
---|
244 | $scope.coreSeries = [[]];
|
---|
245 | $scope.memorySeries = [[]];
|
---|
246 |
|
---|
247 | $scope.updateCharts = function () {
|
---|
248 | clientService.getClientHistory({ id: $stateParams.id, start: ConvertFromDate($scope.fromDate), end: ConvertToDate($scope.toDate) }, function (status) {
|
---|
249 | var noOfStatus = status.length;
|
---|
250 | var cpuSeries = [];
|
---|
251 | var coreSeries = [[], []];
|
---|
252 | var memorySeries = [[], []];
|
---|
253 | for (var i = 0; i < noOfStatus; ++i) {
|
---|
254 | var curStatus = status[i];
|
---|
255 | var cpuData = Math.round(curStatus.CpuUtilization);
|
---|
256 | cpuSeries.push([curStatus.Timestamp, cpuData]);
|
---|
257 | coreSeries[0].push([curStatus.Timestamp, curStatus.TotalCores]);
|
---|
258 | coreSeries[1].push([curStatus.Timestamp, curStatus.UsedCores]);
|
---|
259 | memorySeries[0].push([curStatus.Timestamp, curStatus.TotalMemory]);
|
---|
260 | memorySeries[1].push([curStatus.Timestamp, curStatus.UsedMemory]);
|
---|
261 | }
|
---|
262 | $scope.cpuSeries = [{ data: cpuSeries, label: " CPU Utilization", color: "#f7921d" }];
|
---|
263 | $scope.coreSeries = [
|
---|
264 | { data: coreSeries[0], label: " Total Cores", color: "LightGreen" },
|
---|
265 | { data: coreSeries[1], label: " Used Cores", color: "LightPink" }
|
---|
266 | ];
|
---|
267 | $scope.memorySeries = [
|
---|
268 | { data: memorySeries[0], label: " Total Memory", color: "LightGreen" },
|
---|
269 | { data: memorySeries[1], label: " Used Memory", color: "LightPink" }
|
---|
270 | ];
|
---|
271 |
|
---|
272 | });
|
---|
273 | };
|
---|
274 |
|
---|
275 | var update = function () {
|
---|
276 | getClientDetails();
|
---|
277 | };
|
---|
278 |
|
---|
279 | $scope.updateInterval = $interval(update, $scope.interval);
|
---|
280 | var cancelInterval = $scope.$on('$locationChangeSuccess', function () {
|
---|
281 | $interval.cancel($scope.updateInterval);
|
---|
282 | cancelInterval();
|
---|
283 | });
|
---|
284 | update(); // init page
|
---|
285 | $scope.updateCharts();
|
---|
286 | }]
|
---|
287 | );
|
---|
288 | })(); |
---|