NonRT-RIC A1 Northbound API
[nonrtric.git] / sdnc-a1-controller / oam / configbackuprestore / vnfconfigbackupservice / src / main / webapp / js / sdnc-controller / sdnc-viewreport-controller.js
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : SDNC-FEATURES
4  * ================================================================================
5  * Copyright 2018 TechMahindra
6  *=================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 myApp.controller(
22                                 'ReportController',
23                                 [
24                                                 '$scope',
25                                                 '$http',
26                                                 '$filter',
27                                                 'viewReportService',
28                                                 'growl',
29                                                 function($scope, $http, $filter, viewReportService,
30                                                                 growl) {
31                                                         $scope.isDisabled = true;
32                                                         $scope.pagination = false;
33                                                         $scope.selectedDevice;
34                                                         $scope.ShowResult = false;
35                                                         $scope.dateValidation = false;
36                                                         $scope.NoSearchResult = false;
37                                                         $scope.showError = false;
38                                                         $scope.errorMessage = "";
39                                                         $scope.showSuccess = false;
40                                                         $scope.successMessage = "";
41                                                         $scope.showWarning = false;
42                                                         $scope.warningMessage = "";
43                                                         $scope.showExecutionDetails = true;
44                                                         $scope.showData = false;
45
46                                                         $scope.gap = 2;
47                                                         $scope.filteredItems = [];
48                                                         $scope.groupedItems = [];
49                                                         $scope.itemsPerPage = 5;
50                                                         $scope.pagedItems = [];
51                                                         $scope.currentPage = 0;
52
53                                                         // THIS FUNCTION WILL BE CALLED ON PAGE LOAD
54                                                         $scope.getAllVNF = function() {
55
56                                                                 viewReportService
57                                                                                 .getAllVNF()
58                                                                                 .then(
59                                                                                                 function(data) {
60                                                                                                         if (data != null) {
61                                                                                                                 console.log(data);
62                                                                                                                 $scope.objvnfList = data;
63                                                                                                                 console
64                                                                                                                                 .log("ViewConfigCtrl:getAllVNF called"
65                                                                                                                                                 + $scope.objvnfList);
66                                                                                                         } else {
67                                                                                                                 $scope.warningMessage = "No VNF is eligible for configuration!!!";
68                                                                                                                 growl
69                                                                                                                                 .error(
70                                                                                                                                                 $scope.warningMessage,
71                                                                                                                                                 {
72                                                                                                                                                         title : 'Warning!',
73                                                                                                                                                         globalDisableCloseButton : false,
74                                                                                                                                                         ttl : 7000,
75                                                                                                                                                         disableCountDown : true
76                                                                                                                                                 });
77                                                                                                         }
78                                                                                                 });
79                                                         };
80                                                         $scope.getAllVNF();
81
82                                                         $scope.selectVnf = function(selectedValueVnf) {
83
84                                                                 if (selectedValueVnf != null
85                                                                                 && selectedValueVnf != "") {
86                                                                         console.log("selectedvnf Value",
87                                                                                         selectedValueVnf);
88                                                                         var vnfId = selectedValueVnf;
89                                                                         $scope.ShowResult = true;
90
91                                                                 } else {
92                                                                         $scope.ShowResult = false;
93                                                                         $scope.showCompare = false;
94                                                                         $scope.showResult = false;
95                                                                         $scope.errorMessage = "Please select a VNF!!!";
96                                                                         growl.error($scope.errorMessage, {
97                                                                                 title : 'Error!',
98                                                                                 globalDisableCloseButton : false,
99                                                                                 ttl : 7000,
100                                                                                 disableCountDown : true
101                                                                         });
102                                                                 }
103                                                         }
104
105                                                         // THIS FUNCTION WILL BE CALLED WHEN USER CLICK
106                                                         // SUBMIT FROM UI
107                                                         $scope.getReportsById = function(selectedValueVnf,
108                                                                         startdate, enddate) {
109
110                                                                 $scope.ShowResult = true;
111                                                                 if (new Date(startdate) > new Date(enddate)) {
112                                                                         $scope.dateValidation = true;
113                                                                         $scope.showError = true;
114                                                                         $scope.errorMessage = "Start date cannot be greated than End date";
115                                                                         growl.error($scope.errorMessage, {
116                                                                                 title : 'Error!',
117                                                                                 globalDisableCloseButton : false,
118                                                                                 ttl : 7000,
119                                                                                 disableCountDown : true
120                                                                         });
121                                                                         return false;
122                                                                 }
123                                                                 var date = new Date(startdate);
124                                                                 if (angular.isDefined(startdate)) {
125                                                                         $scope.startDate = startdate;
126                                                                 }
127                                                                 if (angular.isDefined(enddate)) {
128                                                                         $scope.endDate = enddate;
129                                                                 }
130
131                                                                 $scope.startdate1 = $filter('date')(
132                                                                                 $scope.startDate, 'dd-MM-yyyy');
133                                                                 $scope.enddate1 = $filter('date')(
134                                                                                 $scope.endDate, 'dd-MM-yyyy');
135                                                                 if (startdate != null && enddate != null) {
136
137                                                                         // service call to fetch the reports start
138                                                                         // date,end date,test name
139                                                                         viewReportService
140                                                                                         .getDataById(selectedValueVnf,
141                                                                                                         $scope.startdate1,
142                                                                                                         $scope.enddate1)
143                                                                                         .then(
144                                                                                                         function(result) {
145                                                                                                                 console
146                                                                                                                                 .log(
147                                                                                                                                                 "-----------------------------------ReportController::getdata called from controler--",
148                                                                                                                                                 JSON
149                                                                                                                                                                 .stringify(result.data));
150                                                                                                                 if (result.status == 200) {
151                                                                                                                         if (result.data != null
152                                                                                                                                         && result.data.length >= 1) {
153
154                                                                                                                                 // in case of
155                                                                                                                                 // success,
156                                                                                                                                 // build the
157                                                                                                                                 // model object
158                                                                                                                                 // to store the
159                                                                                                                                 // service
160                                                                                                                                 // output here
161                                                                                                                                 $scope
162                                                                                                                                                 .createTestReportModel(result.data);// result.data.data
163                                                                                                                         } else {
164                                                                                                                                 $scope.ShowResult = false;
165                                                                                                                                 $scope.showWarning = true;
166                                                                                                                                 $scope.warningMessage = "No result found for specified Date !!";
167                                                                                                                                 growl
168                                                                                                                                                 .warning(
169                                                                                                                                                                 $scope.warningMessage,
170                                                                                                                                                                 {
171                                                                                                                                                                         title : 'Warning!',
172                                                                                                                                                                         globalDisableCloseButton : false,
173                                                                                                                                                                         ttl : 7000,
174                                                                                                                                                                         disableCountDown : true
175                                                                                                                                                                 });
176                                                                                                                         }
177                                                                                                                 } else {
178                                                                                                                         $scope.ShowResult = false;
179                                                                                                                         $scope.showWarning = true;
180                                                                                                                         $scope.warningMessage = "No result found for specified Date !!";
181                                                                                                                         growl
182                                                                                                                                         .warning(
183                                                                                                                                                         $scope.warningMessage,
184                                                                                                                                                         {
185                                                                                                                                                                 title : 'Warning!',
186                                                                                                                                                                 globalDisableCloseButton : false,
187                                                                                                                                                                 ttl : 7000,
188                                                                                                                                                                 disableCountDown : true
189                                                                                                                                                         });
190                                                                                                                 }
191                                                                                                         },
192                                                                                                         function(response) {
193                                                                                                                 $scope.ShowError = true;
194                                                                                                                 $scope.errorMessage = "Something went wrong, Please try again !!";
195                                                                                                                 growl
196                                                                                                                                 .error(
197                                                                                                                                                 $scope.errorMessage,
198                                                                                                                                                 {
199                                                                                                                                                         title : 'Error!',
200                                                                                                                                                         globalDisableCloseButton : false,
201                                                                                                                                                         ttl : 7000,
202                                                                                                                                                         disableCountDown : true
203                                                                                                                                                 });
204                                                                                                                 console
205                                                                                                                                 .log(
206                                                                                                                                                 "--ReportController::getdata::Error--",
207                                                                                                                                                 response);
208                                                                                                         });
209                                                                 }
210                                                         }
211
212                                                         // FUNCTION WILL BE CALLED WHEN USER CLICK DOWNLOAD
213                                                         // FROM UI
214                                                         $scope.exportToExcel = function(tableId) { // ex:
215                                                                                                                                                 // '#my-table'
216                                                                 var exportHref = Excel.tableToExcel(tableId,
217                                                                                 'export');
218                                                                 $timeout(function() {
219                                                                         location.href = exportHref;
220                                                                 }, 100); // trigger download
221
222                                                                 console
223                                                                                 .log("--ReportController::exportToexcel--");
224                                                         }
225
226                                                         $scope.createTestReportModel = function(result) {
227
228                                                                 $scope.showError = false;
229                                                                 $scope.showWarning = false;
230                                                                 $scope.objTestReportModel = result;
231                                                                 $scope.objTestModel = [];
232
233                                                                 if ($scope.objTestReportModel.length >= 1) {
234                                                                         for (var i = 0; i < $scope.objTestReportModel.length; i++) {
235                                                                                 var objTestReport = {};
236                                                                                 objTestReport.vnfname = $scope.objTestReportModel[i].vnfname;
237                                                                                 objTestReport.vnfid = $scope.objTestReportModel[i].vnfid;
238                                                                                 objTestReport.versionNo = $scope.objTestReportModel[i].vnfversion;
239                                                                                 objTestReport.createdAt = $scope.objTestReportModel[i].creationdate;
240                                                                                 objTestReport.updatedAt = $scope.objTestReportModel[i].lastupdated;
241                                                                                 objTestReport.status = $scope.objTestReportModel[i].status;
242                                                                                 objTestReport.Id = $scope.objTestReportModel[i].id;
243                                                                                 // objTestReport.configinfo =
244                                                                                 // $scope.objVersionModel[i].configinfo;
245                                                                                 $scope.objTestModel.push(objTestReport);
246                                                                                 console
247                                                                                                 .log(
248                                                                                                                 "--ReportController::CreateTestReportModel--",
249                                                                                                                 JSON
250                                                                                                                                 .stringify($scope.objTestModel));
251
252                                                                         }
253                                                                         $scope.showresult = true;
254                                                                         $scope.pagination = true;
255                                                                 }
256                                                                 console
257                                                                                 .log("--ReportController::createTestReportModel::final TestReportModel--"
258                                                                                                 + JSON
259                                                                                                                 .stringify($scope.objTestModel));
260                                                                 $scope.csvOrder = [ 'testname', 'timeStamp',
261                                                                                 'status', 'statistics', 'avgTime',
262                                                                                 'result' ];
263
264                                                         }
265
266                                                         // THIS FUNCTION WILL BE CALLED WHEN USER CLICK
267                                                         // SUBMIT FROM UI
268                                                         $scope.getReports = function(startdate, enddate) {
269
270                                                                 $scope.ShowResult = false;
271                                                                 if (new Date(startdate) > new Date(enddate)) {
272                                                                         $scope.dateValidation = true;
273                                                                         $scope.showError = true;
274                                                                         $scope.errorMessage = "Start date cannot be greated than End date";
275                                                                         growl.error($scope.errorMessage, {
276                                                                                 title : 'Error!',
277                                                                                 globalDisableCloseButton : false,
278                                                                                 ttl : 7000,
279                                                                                 disableCountDown : true
280                                                                         });
281                                                                         return false;
282                                                                 }
283                                                                 var date = new Date(startdate);
284                                                                 /*
285                                                                  * if (angular.isDefined(deviceName)) {
286                                                                  * $scope.DeviceName = deviceName; }
287                                                                  */
288                                                                 if (angular.isDefined(startdate)) {
289                                                                         $scope.startDate = startdate;
290                                                                 }
291                                                                 if (angular.isDefined(enddate)) {
292                                                                         $scope.endDate = enddate;
293                                                                 }
294
295                                                                 $scope.startdate1 = $filter('date')(
296                                                                                 $scope.startDate, 'dd-MM-yyyy');
297                                                                 $scope.enddate1 = $filter('date')(
298                                                                                 $scope.endDate, 'dd-MM-yyyy');
299                                                                 if (startdate != null && enddate != null) {
300
301                                                                         // service call to fetch the reports start
302                                                                         // date,end date,test name
303                                                                         viewReportService
304                                                                                         .getData($scope.startdate1,
305                                                                                                         $scope.enddate1)
306                                                                                         .then(
307                                                                                                         function(result) {
308                                                                                                                 console
309                                                                                                                                 .log(
310                                                                                                                                                 "-----------------------------------ReportController::getdata called from controler--",
311                                                                                                                                                 JSON
312                                                                                                                                                                 .stringify(result.data));
313                                                                                                                 if (result.status == 200) {
314                                                                                                                         if (result.data != null
315                                                                                                                                         && result.data.length >= 1) {
316
317                                                                                                                                 // in case of
318                                                                                                                                 // success,
319                                                                                                                                 // build the
320                                                                                                                                 // model object
321                                                                                                                                 // to store the
322                                                                                                                                 // service
323                                                                                                                                 // output here
324                                                                                                                                 $scope
325                                                                                                                                                 .createTestReportModel(result.data);// result.data.data
326                                                                                                                         } else {
327                                                                                                                                 $scope.ShowResult = false;
328                                                                                                                                 $scope.showWarning = true;
329                                                                                                                                 $scope.warningMessage = "No result found for specified Date !!";
330                                                                                                                                 growl
331                                                                                                                                                 .warning(
332                                                                                                                                                                 $scope.warningMessage,
333                                                                                                                                                                 {
334                                                                                                                                                                         title : 'Warning!',
335                                                                                                                                                                         globalDisableCloseButton : false,
336                                                                                                                                                                         ttl : 7000,
337                                                                                                                                                                         disableCountDown : true
338                                                                                                                                                                 });
339                                                                                                                         }
340                                                                                                                 } else {
341                                                                                                                         $scope.ShowResult = false;
342                                                                                                                         $scope.showWarning = true;
343                                                                                                                         $scope.warningMessage = "No result found for specified Date !!";
344                                                                                                                         growl
345                                                                                                                                         .warning(
346                                                                                                                                                         $scope.warningMessage,
347                                                                                                                                                         {
348                                                                                                                                                                 title : 'Warning!',
349                                                                                                                                                                 globalDisableCloseButton : false,
350                                                                                                                                                                 ttl : 7000,
351                                                                                                                                                                 disableCountDown : true
352                                                                                                                                                         });
353                                                                                                                 }
354                                                                                                         },
355                                                                                                         function(response) {
356                                                                                                                 $scope.ShowError = true;
357                                                                                                                 $scope.errorMessage = "Something went wrong, Please try again !!";
358                                                                                                                 growl
359                                                                                                                                 .error(
360                                                                                                                                                 $scope.errorMessage,
361                                                                                                                                                 {
362                                                                                                                                                         title : 'Error!',
363                                                                                                                                                         globalDisableCloseButton : false,
364                                                                                                                                                         ttl : 7000,
365                                                                                                                                                         disableCountDown : true
366                                                                                                                                                 });
367                                                                                                                 console
368                                                                                                                                 .log(
369                                                                                                                                                 "--ReportController::getdata::Error--",
370                                                                                                                                                 response);
371                                                                                                         });
372                                                                 }
373                                                         }
374
375                                                         // FUNCTION WILL BE CALLED WHEN USER CLICK DOWNLOAD
376                                                         // FROM UI
377                                                         $scope.exportToExcel = function(tableId) { // ex:
378                                                                                                                                                 // '#my-table'
379                                                                 var exportHref = Excel.tableToExcel(tableId,
380                                                                                 'export');
381                                                                 $timeout(function() {
382                                                                         location.href = exportHref;
383                                                                 }, 100); // trigger download
384
385                                                                 console
386                                                                                 .log("--ReportController::exportToexcel--");
387                                                         }
388
389                                                         $scope.createTestReportModel = function(result) {
390
391                                                                 $scope.showError = false;
392                                                                 $scope.showWarning = false;
393                                                                 $scope.objTestReportModel = result;
394                                                                 $scope.objTestModel = [];
395
396                                                                 if ($scope.objTestReportModel.length >= 1) {
397                                                                         for (var i = 0; i < $scope.objTestReportModel.length; i++) {
398                                                                                 var objTestReport = {};
399                                                                                 objTestReport.vnfname = $scope.objTestReportModel[i].vnfname;
400                                                                                 objTestReport.vnfid = $scope.objTestReportModel[i].vnfid;
401                                                                                 objTestReport.versionNo = $scope.objTestReportModel[i].vnfversion;
402                                                                                 objTestReport.createdAt = $scope.objTestReportModel[i].creationdate;
403                                                                                 objTestReport.updatedAt = $scope.objTestReportModel[i].lastupdated;
404                                                                                 objTestReport.status = $scope.objTestReportModel[i].status;
405                                                                                 objTestReport.Id = $scope.objTestReportModel[i].id;
406                                                                                 // objTestReport.configinfo =
407                                                                                 // $scope.objVersionModel[i].configinfo;
408                                                                                 $scope.objTestModel.push(objTestReport);
409                                                                                 console
410                                                                                                 .log(
411                                                                                                                 "--ReportController::CreateTestReportModel--",
412                                                                                                                 JSON
413                                                                                                                                 .stringify($scope.objTestModel));
414
415                                                                         }
416                                                                         $scope.showresult = true;
417                                                                         $scope.pagination = true;
418                                                                 }
419                                                                 console
420                                                                                 .log("--ReportController::createTestReportModel::final TestReportModel--"
421                                                                                                 + JSON
422                                                                                                                 .stringify($scope.objTestModel));
423                                                                 $scope.csvOrder = [ 'testname', 'timeStamp',
424                                                                                 'status', 'statistics', 'avgTime',
425                                                                                 'result' ];
426
427                                                                 // init
428                                                                 $scope.sort = {
429                                                                         sortingOrder : 'createdAt',
430                                                                         reverse : false
431                                                                 };
432
433                                                                 var searchMatch = function(haystack, needle) {
434                                                                         if (!needle) {
435                                                                                 return true;
436                                                                         }
437                                                                         return haystack.toLowerCase().indexOf(
438                                                                                         needle.toLowerCase()) !== -1;
439                                                                 };
440
441                                                                 // init the filtered items
442                                                                 $scope.search = function() {
443                                                                         $scope.filteredItems = $filter('filter')(
444                                                                                         $scope.objTestModel,
445                                                                                         function(item) {
446                                                                                                 for ( var attr in item) {
447                                                                                                         if (searchMatch(item[attr],
448                                                                                                                         $scope.query))
449                                                                                                                 return true;
450                                                                                                 }
451                                                                                                 return false;
452                                                                                         });
453                                                                         // take care of the sorting order
454                                                                         if ($scope.sort.sortingOrder !== '') {
455                                                                                 $scope.filteredItems = $filter(
456                                                                                                 'orderBy')(
457                                                                                                 $scope.filteredItems,
458                                                                                                 $scope.sort.sortingOrder,
459                                                                                                 $scope.sort.reverse);
460                                                                         }
461                                                                         $scope.currentPage = 0;
462                                                                         // now group by pages
463                                                                         $scope.groupToPages();
464                                                                 };
465
466                                                                 // calculate page in place
467                                                                 $scope.groupToPages = function() {
468                                                                         $scope.pagedItems = [];
469
470                                                                         for (var i = 0; i < $scope.filteredItems.length; i++) {
471                                                                                 if (i % $scope.itemsPerPage === 0) {
472                                                                                         $scope.pagedItems[Math.floor(i
473                                                                                                         / $scope.itemsPerPage)] = [ $scope.filteredItems[i] ];
474                                                                                 } else {
475                                                                                         $scope.pagedItems[Math.floor(i
476                                                                                                         / $scope.itemsPerPage)]
477                                                                                                         .push($scope.filteredItems[i]);
478                                                                                 }
479                                                                         }
480                                                                 };
481
482                                                                 $scope.range = function(size, start, end) {
483                                                                         var ret = [];
484                                                                         console.log(size, start, end);
485
486                                                                         if (size < end) {
487                                                                                 end = size;
488                                                                                 start = size - $scope.gap;
489                                                                         }
490                                                                         for (var i = start; i < end; i++) {
491                                                                                 ret.push(i);
492                                                                         }
493                                                                         console.log(ret);
494                                                                         return ret;
495                                                                 };
496
497                                                                 $scope.prevPage = function() {
498                                                                         if ($scope.currentPage > 0) {
499                                                                                 $scope.currentPage--;
500                                                                         }
501                                                                 };
502
503                                                                 $scope.nextPage = function() {
504                                                                         if ($scope.currentPage < $scope.pagedItems.length - 1) {
505                                                                                 $scope.currentPage++;
506                                                                         }
507                                                                 };
508
509                                                                 $scope.setPage = function() {
510                                                                         $scope.currentPage = this.n;
511                                                                 };
512
513                                                                 // functions have been describe process the data
514                                                                 // for display
515                                                                 $scope.search();
516
517                                                         }
518
519                                                 } ]);