2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
29 function($scope, $http, $filter, viewReportService,
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;
47 $scope.filteredItems = [];
48 $scope.groupedItems = [];
49 $scope.itemsPerPage = 5;
50 $scope.pagedItems = [];
51 $scope.currentPage = 0;
53 // THIS FUNCTION WILL BE CALLED ON PAGE LOAD
54 $scope.getAllVNF = function() {
62 $scope.objvnfList = data;
64 .log("ViewConfigCtrl:getAllVNF called"
67 $scope.warningMessage = "No VNF is eligible for configuration!!!";
70 $scope.warningMessage,
73 globalDisableCloseButton : false,
75 disableCountDown : true
82 $scope.selectVnf = function(selectedValueVnf) {
84 if (selectedValueVnf != null
85 && selectedValueVnf != "") {
86 console.log("selectedvnf Value",
88 var vnfId = selectedValueVnf;
89 $scope.ShowResult = true;
92 $scope.ShowResult = false;
93 $scope.showCompare = false;
94 $scope.showResult = false;
95 $scope.errorMessage = "Please select a VNF!!!";
96 growl.error($scope.errorMessage, {
98 globalDisableCloseButton : false,
100 disableCountDown : true
105 // THIS FUNCTION WILL BE CALLED WHEN USER CLICK
107 $scope.getReportsById = function(selectedValueVnf,
108 startdate, enddate) {
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, {
117 globalDisableCloseButton : false,
119 disableCountDown : true
123 var date = new Date(startdate);
124 if (angular.isDefined(startdate)) {
125 $scope.startDate = startdate;
127 if (angular.isDefined(enddate)) {
128 $scope.endDate = enddate;
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) {
137 // service call to fetch the reports start
138 // date,end date,test name
140 .getDataById(selectedValueVnf,
147 "-----------------------------------ReportController::getdata called from controler--",
149 .stringify(result.data));
150 if (result.status == 200) {
151 if (result.data != null
152 && result.data.length >= 1) {
162 .createTestReportModel(result.data);// result.data.data
164 $scope.ShowResult = false;
165 $scope.showWarning = true;
166 $scope.warningMessage = "No result found for specified Date !!";
169 $scope.warningMessage,
172 globalDisableCloseButton : false,
174 disableCountDown : true
178 $scope.ShowResult = false;
179 $scope.showWarning = true;
180 $scope.warningMessage = "No result found for specified Date !!";
183 $scope.warningMessage,
186 globalDisableCloseButton : false,
188 disableCountDown : true
193 $scope.ShowError = true;
194 $scope.errorMessage = "Something went wrong, Please try again !!";
200 globalDisableCloseButton : false,
202 disableCountDown : true
206 "--ReportController::getdata::Error--",
212 // FUNCTION WILL BE CALLED WHEN USER CLICK DOWNLOAD
214 $scope.exportToExcel = function(tableId) { // ex:
216 var exportHref = Excel.tableToExcel(tableId,
218 $timeout(function() {
219 location.href = exportHref;
220 }, 100); // trigger download
223 .log("--ReportController::exportToexcel--");
226 $scope.createTestReportModel = function(result) {
228 $scope.showError = false;
229 $scope.showWarning = false;
230 $scope.objTestReportModel = result;
231 $scope.objTestModel = [];
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);
248 "--ReportController::CreateTestReportModel--",
250 .stringify($scope.objTestModel));
253 $scope.showresult = true;
254 $scope.pagination = true;
257 .log("--ReportController::createTestReportModel::final TestReportModel--"
259 .stringify($scope.objTestModel));
260 $scope.csvOrder = [ 'testname', 'timeStamp',
261 'status', 'statistics', 'avgTime',
266 // THIS FUNCTION WILL BE CALLED WHEN USER CLICK
268 $scope.getReports = function(startdate, enddate) {
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, {
277 globalDisableCloseButton : false,
279 disableCountDown : true
283 var date = new Date(startdate);
285 * if (angular.isDefined(deviceName)) {
286 * $scope.DeviceName = deviceName; }
288 if (angular.isDefined(startdate)) {
289 $scope.startDate = startdate;
291 if (angular.isDefined(enddate)) {
292 $scope.endDate = enddate;
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) {
301 // service call to fetch the reports start
302 // date,end date,test name
304 .getData($scope.startdate1,
310 "-----------------------------------ReportController::getdata called from controler--",
312 .stringify(result.data));
313 if (result.status == 200) {
314 if (result.data != null
315 && result.data.length >= 1) {
325 .createTestReportModel(result.data);// result.data.data
327 $scope.ShowResult = false;
328 $scope.showWarning = true;
329 $scope.warningMessage = "No result found for specified Date !!";
332 $scope.warningMessage,
335 globalDisableCloseButton : false,
337 disableCountDown : true
341 $scope.ShowResult = false;
342 $scope.showWarning = true;
343 $scope.warningMessage = "No result found for specified Date !!";
346 $scope.warningMessage,
349 globalDisableCloseButton : false,
351 disableCountDown : true
356 $scope.ShowError = true;
357 $scope.errorMessage = "Something went wrong, Please try again !!";
363 globalDisableCloseButton : false,
365 disableCountDown : true
369 "--ReportController::getdata::Error--",
375 // FUNCTION WILL BE CALLED WHEN USER CLICK DOWNLOAD
377 $scope.exportToExcel = function(tableId) { // ex:
379 var exportHref = Excel.tableToExcel(tableId,
381 $timeout(function() {
382 location.href = exportHref;
383 }, 100); // trigger download
386 .log("--ReportController::exportToexcel--");
389 $scope.createTestReportModel = function(result) {
391 $scope.showError = false;
392 $scope.showWarning = false;
393 $scope.objTestReportModel = result;
394 $scope.objTestModel = [];
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);
411 "--ReportController::CreateTestReportModel--",
413 .stringify($scope.objTestModel));
416 $scope.showresult = true;
417 $scope.pagination = true;
420 .log("--ReportController::createTestReportModel::final TestReportModel--"
422 .stringify($scope.objTestModel));
423 $scope.csvOrder = [ 'testname', 'timeStamp',
424 'status', 'statistics', 'avgTime',
429 sortingOrder : 'createdAt',
433 var searchMatch = function(haystack, needle) {
437 return haystack.toLowerCase().indexOf(
438 needle.toLowerCase()) !== -1;
441 // init the filtered items
442 $scope.search = function() {
443 $scope.filteredItems = $filter('filter')(
446 for ( var attr in item) {
447 if (searchMatch(item[attr],
453 // take care of the sorting order
454 if ($scope.sort.sortingOrder !== '') {
455 $scope.filteredItems = $filter(
457 $scope.filteredItems,
458 $scope.sort.sortingOrder,
459 $scope.sort.reverse);
461 $scope.currentPage = 0;
462 // now group by pages
463 $scope.groupToPages();
466 // calculate page in place
467 $scope.groupToPages = function() {
468 $scope.pagedItems = [];
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] ];
475 $scope.pagedItems[Math.floor(i
476 / $scope.itemsPerPage)]
477 .push($scope.filteredItems[i]);
482 $scope.range = function(size, start, end) {
484 console.log(size, start, end);
488 start = size - $scope.gap;
490 for (var i = start; i < end; i++) {
497 $scope.prevPage = function() {
498 if ($scope.currentPage > 0) {
499 $scope.currentPage--;
503 $scope.nextPage = function() {
504 if ($scope.currentPage < $scope.pagedItems.length - 1) {
505 $scope.currentPage++;
509 $scope.setPage = function() {
510 $scope.currentPage = this.n;
513 // functions have been describe process the data