From 43d4b00848ebd0567b020fe219f07d4f7049ff0b Mon Sep 17 00:00:00 2001 From: DushyantSinghThakur Date: Thu, 6 Sep 2018 12:46:04 +0530 Subject: Epic-231:versioning, and backup the configuration Merging the sdnc jira stories- 255,256 Change-Id: Iacb9274dae93f534f1331c4eb7d0669896d379d4 Issue-ID: SDNC-256 Signed-off-by: DushyantSinghThakur Former-commit-id: 94d8b3d82b82dedfd5949da2e5d1ed348ab066e2 --- .../sdnc-controller/sdnc-applyConfig-controller.js | 93 +++ .../sdnc-backupConfig-controller.js | 314 ++++++++++ .../sdnc-compareConfig-controller.js | 690 +++++++++++++++++++++ .../sdnc-validationTest-controller.js | 222 +++++++ .../sdnc-controller/sdnc-viewreport-controller.js | 519 ++++++++++++++++ 5 files changed, 1838 insertions(+) create mode 100644 configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-applyConfig-controller.js create mode 100644 configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-backupConfig-controller.js create mode 100644 configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-compareConfig-controller.js create mode 100644 configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-validationTest-controller.js create mode 100644 configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-viewreport-controller.js (limited to 'configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller') diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-applyConfig-controller.js b/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-applyConfig-controller.js new file mode 100644 index 00000000..faff3633 --- /dev/null +++ b/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-applyConfig-controller.js @@ -0,0 +1,93 @@ +myApp.controller('ApplyConfigCtrl', ['$scope','$window', '$http', 'growl', 'deviceConfigService', 'ObjectDiff', function($scope, $http,$window, growl, deviceConfigService, ObjectDiff) { + + $scope.showResult = false; + + //THIS FUNCTION WILL BE CALLED ON PAGE LOAD + $scope.getAllVNFFromRc = function() { + + deviceConfigService.getAllVNFFromRc().then(function(data) { + if (data != null) { + console.log(data); + $scope.objvnfList = data; + console.log("CompareConfigCtrl:getAllVNFFromRc called" + $scope.objvnfList); + } else { + $scope.warningMessage = "No VNF is eligible for configuration!!!"; + growl.error($scope.warningMessage, { + title: 'Warning!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + } + }); + }; + $scope.getAllVNFFromRc(); + + + + $scope.selectVnf = function(selectedValueVnf) { + + var vnfId = selectedValueVnf; + + $scope.fileContent = ''; + $scope.fileSize = 0; + $scope.fileName = ''; + + $scope.submit = function () { + var file = document.getElementById("myFileInput").files[0]; + $scope.result1={}; + + if (file) { + var aReader = new FileReader(); + aReader.readAsText(file, "UTF-8"); + aReader.onload = function (evt) { + // $scope.fileContent = aReader.result; + $scope.fileName = document.getElementById("myFileInput").files[0].name; + $scope.fileSize = document.getElementById("myFileInput").files[0].size; + var id= vnfId; + result1=JSON.parse(aReader.result); + /*var item = JSON.parse(result1);*/ + $scope.fileContent = aReader.result.search(id); + $scope.successMessagebool = false; + if( $scope.fileContent == -1){ + $scope.errorMessage = "VNF Id is different!!! Select different file and try again"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + } + else{ + + $scope.apply(); + + } + } + aReader.onerror = function (evt) { + $scope.fileContent = "error"; + } + } + $scope.successMessagebool1 = false; + $scope.apply = function() { + if (file) { + deviceConfigService.runApplyconfig(vnfId,result1); + $scope.successMessage = "File uploaded successfully"; + growl.success($scope.successMessage, { + title: 'Success!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + $scope.successMessagebool1 = true; + + + } }; + + } + + } + + +}]); + diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-backupConfig-controller.js b/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-backupConfig-controller.js new file mode 100644 index 00000000..3ea9c755 --- /dev/null +++ b/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-backupConfig-controller.js @@ -0,0 +1,314 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : SDNC-FEATURES + * ================================================================================ + * Copyright 2018 TechMahindra + *================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +myApp.controller('BackupConfigCtrl', ['$scope', '$http','$window', 'growl', 'deviceConfigService', 'ObjectDiff', '$timeout' , function($scope, $http, $window, growl, deviceConfigService, ObjectDiff, $timeout) { + + $scope.showResult = false; + $scope.showCompare = false; + + //THIS FUNCTION WILL BE CALLED ON PAGE LOAD + $scope.getAllVNF = function() { + + deviceConfigService.getAllVNF().then(function(data) { + if (data != null) { + console.log(data); + $scope.objvnfList = data; + console.log("CompareConfigCtrl:getAllVNF called" + $scope.objvnfList); + } else { + $scope.warningMessage = "No VNF is eligible for configuration!!!"; + growl.error($scope.warningMessage, { + title: 'Warning!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + } + }); + }; + $scope.getAllVNF(); + + $scope.selectVnf = function(selectedValueVnf) { + + if (selectedValueVnf != null && selectedValueVnf != "") { + console.log("selectedvnf Value", selectedValueVnf); + //selectedItem = selectedValueVnf.split("%"); +// var vnfName = selectedItem[0]; +// var vnfType = selectedItem[1]; + var vnfId = selectedValueVnf; + $scope.getVersionList(vnfId); + } else { + $scope.ShowResult = false; + $scope.showCompare = false; + $scope.showResult = false; + $scope.errorMessage = "Please select a VNF!!!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + } + + } + + //THIS FUNCTION WILL BE CALLED ON SELECTION OF VNF + $scope.getVersionList = function(vnfId) { + + $scope.ShowResult = false; + + //service call to fetch the version list + deviceConfigService.getVersions(vnfId).then(function(result) { + console.log("--CompareConfigCtrl::getVersionList called from controler--", JSON.stringify(result)); + var status = result.status; + var result = result.data; + if (status == 200) { + if (result.length >= 1) { + //in case of success, build the model object to store the service output here + $scope.createVersionModel(result); + } else { + $scope.ShowResult = false; + $scope.warningMessage = "No configruation found for the selected VNF !!"; + growl.warning($scope.warningMessage, { + title: 'Warning!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + } + } else { + $scope.ShowResult = false; + $scope.warningMessage = "No configruation found for the selected VNF !!"; + growl.warning($scope.warningMessage, { + title: 'Warning!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + } + }, + function(response) { + $scope.errorMessage = "Something went wrong, Please try again !!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + console.log("--CompareConfigCtrl::getVersionList::Error--", response); + }); + } + + //Function to build the UI model to be shown + $scope.createVersionModel = function(result) { + + $scope.objVersionModel = result; + $scope.objVersion = []; + + console.log("--CompareConfigCtrl::createVersionModel::--", JSON.stringify($scope.objVersionModel)); + if ($scope.objVersionModel.length >= 1) { + $scope.ShowResult = true; + $scope.showCompare = true; + for (var i = 0; i < $scope.objVersionModel.length; i++) { + var objVersionDetail = {}; + objVersionDetail.vnfname = $scope.objVersionModel[i].vnfname; + objVersionDetail.vnfid = $scope.objVersionModel[i].vnfid; + objVersionDetail.versionNo = $scope.objVersionModel[i].vnfversion; + objVersionDetail.createdAt = $scope.objVersionModel[i].creationdate; + objVersionDetail.configinfo = $scope.objVersionModel[i].configinfo; + objVersionDetail.selected = false; + + $scope.objVersion.push(objVersionDetail); + } + } + console.log("--CompareConfigCtrl::createVersionModel::final VersionModel--" + JSON.stringify($scope.objVersion)); + + } + + $scope.CompareConfig = function(objVersion) { + var count = 0; + angular.forEach(objVersion, function(item) { + if (item.selected == true) + count++; + }); + if (count > 2) { + $scope.errorMessage = "Only two config files can be selected for the comparison!!!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + } else if (count === 1){ + $scope.errorMessage = "At least two config files can be selected for the comparison!!!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + }else + $scope.createCompareModelNew(objVersion); + }; + + $scope.createCompareModelNew = function(objVersion) { + + $scope.objCompareModel1 = {}; + $scope.objCompareModel2 = {}; + + $scope.versionsSelected = []; + angular.forEach(objVersion, function(item) { + angular.forEach($scope.objVersionModel, function(val, index) { + if (item.versionNo == val['versionNo'] && item.selected == false) { + $scope.objVersionModel.splice(index, 1); + } + if (item.selected) { + if ($scope.versionsSelected.indexOf(item) == -1) + $scope.versionsSelected.push(item); + } + }) + }); + console.log("--CompareConfigCtrl::createCompareModel::$scope.objVersionModel", JSON.stringify($scope.objVersionModel)); + angular.forEach($scope.objVersionModel, function(item) { + var versionObj = {}; + var versionDetails = {}; + versionDetails.versionNo = item['vnfversion']; + /*versionDetails.vnfName = item['vnfname']; + versionDetails.vnfid = item['vnfid'];*/ + versionDetails.timeStamp = item.creationdate; + versionObj.versionDetails = versionDetails; + + //fetch all the other topology/network,opertaion status for the vnf + // versionObj.topologyInfo = $scope.fetchConfigDetails(item); + versionObj.topologyInfo = $scope.fetchTopologyInfo(item); + + versionObj.networkTopologyInfo = $scope.fetchNetworkTopologyInfo(item); + versionObj.operationStatus = $scope.operationStatus(item); + versionObj.vnfTopologyIdentifier = $scope.vnfTopologyIdentifier(item); + + if ((versionObj.versionDetails.versionNo == $scope.versionsSelected[0].versionNo)) { + $scope.objCompareModel1 = versionObj; + } else + $scope.objCompareModel2 = versionObj; + + }); + $scope.showResult = true; + console.log("CompareConfigCtrl::createCompareModel::objCompareModel1", JSON.stringify($scope.objCompareModel1)); + console.log("CompareConfigCtrl::createCompareModel::objCompareModel2", JSON.stringify($scope.objCompareModel2)); + } + + + + $scope.fetchTopologyInfo = function(item) { + var topologyInfo = {}; + item = JSON.parse(item.configinfo); + if (angular.isDefined(item['preload-data']) && angular.isDefined(item['preload-data']['vnf-topology-information'])) { + var vnfTopologyInfo = item['preload-data']['vnf-topology-information']; + if (angular.isDefined(vnfTopologyInfo['vnf-parameters'] && vnfTopologyInfo['vnf-parameters'] != null)) { + var vnfParameters = vnfTopologyInfo['vnf-parameters']; + for (var i = 0; i < vnfParameters.length; i++) { + + var key = vnfParameters[i]['vnf-parameter-name']; + var value = vnfParameters[i]['vnf-parameter-value']; + console.log("CompareConfigCtrl::fetchTopologyInfo::key", key); + console.log("CompareConfigCtrl::fetchTopologyInfo::value", value); + topologyInfo[key] = value; + + } + console.log("CompareConfigCtrl::fetchTopologyInfo::", JSON.stringify(topologyInfo)); + return topologyInfo; + } + } + } + + $scope.fetchNetworkTopologyInfo = function(item) { + var networkTopology = {}; + item = JSON.parse(item.configinfo); + if (angular.isDefined(item['preload-data']) && angular.isDefined(item['preload-data']['network-topology-information'])) { + var netwrokTopologyInfo = item['preload-data']['network-topology-information']; + if (angular.isDefined(netwrokTopologyInfo) && netwrokTopologyInfo != null) { + for (var i = 0; i < netwrokTopologyInfo.length; i++) { + + var key = netwrokTopologyInfo[i]['vnf-parameter-name']; + var value = netwrokTopologyInfo[i]['vnf-parameter-value']; + console.log("CompareConfigCtrl::fetchTopologyInfo::key", key); + console.log("CompareConfigCtrl::fetchTopologyInfo::value", value); + networkTopology[key] = value; + } + } + } + console.log("CompareConfigCtrl::fetchNetworkTopologyInfo::", JSON.stringify(networkTopology)); + return networkTopology; + } + + $scope.operationStatus = function(item) { + var operationStatus = {}; + item = JSON.parse(item.configinfo); + if (angular.isDefined(item['preload-data']) && angular.isDefined(item['preload-data']['oper-status'])) { + var operStatus = item['preload-data']['oper-status']; + if (angular.isDefined(operStatus) && operStatus != null) { + + var value = operStatus['order-status']; + operationStatus['order-status'] = value; + + } + } + console.log("CompareConfigCtrl::operationStatus::", JSON.stringify(operationStatus)); + return operationStatus; + } + + $scope.vnfTopologyIdentifier = function(item) { + var topologyIdnetifier = {}; + item = JSON.parse(item.configinfo); + if (angular.isDefined(item['preload-data']) && angular.isDefined(item['preload-data']['vnf-topology-information']['vnf-topology-identifier'])) { + var topologyInfoidentifier = item['preload-data']['vnf-topology-information']['vnf-topology-identifier']; + if (angular.isDefined(topologyInfoidentifier)) { + angular.forEach(topologyInfoidentifier, function(value, key) { + + console.log("CompareConfigCtrl::fetchTopologyInfo::key", key); + console.log("CompareConfigCtrl::fetchTopologyInfo::value", value); + topologyIdnetifier[key] = value; + }); + } + } + + console.log("CompareConfigCtrl::vnfTopologyIdentifier::", JSON.stringify(topologyIdnetifier)); + return topologyIdnetifier; + } + + $scope.invokeBackup = function(){ + deviceConfigService.invokeBackup().then(function(data) { + console.log("response -- data -- "+data) + $window.location.reload(); + }); + } + + $scope.getLastModifiedTime=function(){ +// $timeout(function(result){ +// console.log("response-data-"+ result); +// $scope.lastModifiedTime="Testcode Dushyant" +// } +// ,5000); + + deviceConfigService.getlastupdated().then(function(result) { + $scope.lastModifiedTime= result.data; + console.log("response -- getlastupdated -- "+JSON.stringify(result)) + }); + } + $scope.getLastModifiedTime() +}]); \ No newline at end of file diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-compareConfig-controller.js b/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-compareConfig-controller.js new file mode 100644 index 00000000..91584b00 --- /dev/null +++ b/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-compareConfig-controller.js @@ -0,0 +1,690 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : SDNC-FEATURES + * ================================================================================ + * Copyright 2018 TechMahindra + *================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +myApp.controller('CompareConfigCtrl', ['$scope','$filter', '$http','$window', 'growl', 'deviceConfigService', 'ObjectDiff', function($scope,$filter, $http,$window, growl, deviceConfigService, ObjectDiff) { + + $scope.showResult = false; + $scope.showCompare = false; + $scope.showView=false; + $scope.pagination = false; + $scope.gap = 2; + $scope.filteredItems = []; + $scope.groupedItems = []; + $scope.itemsPerPage = 5; + $scope.pagedItems = []; + $scope.currentPage = 0; + //THIS FUNCTION WILL BE CALLED ON PAGE LOAD + $scope.getAllVNF = function() { + + deviceConfigService.getAllVNF().then(function(data) { + if (data != null) { + console.log(data); + $scope.objvnfList = data; + console.log("CompareConfigCtrl:getAllVNF called" + $scope.objvnfList); + } else { + $scope.warningMessage = "No VNF is eligible for configuration!!!"; + growl.error($scope.warningMessage, { + title: 'Warning!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + } + }); + }; + $scope.getAllVNF(); + + $scope.selectVnf = function(selectedValueVnf) { + + if (selectedValueVnf != null && selectedValueVnf != "") { + console.log("selectedvnf Value", selectedValueVnf); + //selectedItem = selectedValueVnf.split("%"); +// var vnfName = selectedItem[0]; +// var vnfType = selectedItem[1]; + var vnfId = selectedValueVnf; + $scope.getVersionList(vnfId); + } else { + $scope.ShowResult = false; + $scope.showCompare = false; + $scope.showResult = false; + $scope.errorMessage = "Please select a VNF!!!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + } + + } + + //THIS FUNCTION WILL BE CALLED ON SELECTION OF VNF + $scope.getVersionList = function(vnfId) { + + $scope.ShowResult = false; + + //service call to fetch the version list + deviceConfigService.getVersions(vnfId).then(function(result) { + console.log("-----CompareConfigCtrl::getVersionList called from controler--", JSON.stringify(result)); + var status = result.status; + var result = result.data; + if (status == 200) { + if (result.length >= 1) { + //in case of success, build the model object to store the service output here + $scope.createVersionModel(result); + + } else { + $scope.ShowResult = false; + $scope.warningMessage = "No configruation found for the selected VNF !!"; + growl.warning($scope.warningMessage, { + title: 'Warning!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + } + } else { + $scope.ShowResult = false; + $scope.warningMessage = "No configruation found for the selected VNF !!"; + growl.warning($scope.warningMessage, { + title: 'Warning!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + } + }, + function(response) { + $scope.errorMessage = "Something went wrong, Please try again !!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + console.log("--CompareConfigCtrl::getVersionList::Error--", response); + }); + } + + //Function to build the UI model to be shown + $scope.createVersionModel = function(result) { + + $scope.objVersionModel = result; + $scope.objVersion = []; + + console.log("-----CompareConfigCtrl::createVersionModel::--", JSON.stringify($scope.objVersionModel)); + if ($scope.objVersionModel.length >= 1) { + $scope.ShowResult = true; + $scope.showCompare = true; + $scope.showView =true; + for (var i = 0; i < $scope.objVersionModel.length; i++) { + var objVersionDetail = {}; + objVersionDetail.vnfname = $scope.objVersionModel[i].vnfname; + objVersionDetail.vnfid = $scope.objVersionModel[i].vnfid; + objVersionDetail.vnfversion = $scope.objVersionModel[i].vnfversion; + objVersionDetail.createdAt = $scope.objVersionModel[i].creationdate; + objVersionDetail.updatedAt = $scope.objVersionModel[i].lastupdated; + objVersionDetail.configinfo = $scope.objVersionModel[i].configinfo; + objVersionDetail.selected = false; + $scope.objVersion.push(objVersionDetail); + + } + } + console.log("-----CompareConfigCtrl::createVersionModel::final VersionModel--" + JSON.stringify($scope.objVersion)); + + // init + $scope.sort = { + sortingOrder : 'vnfversion', + reverse : true + }; + + var searchMatch = function(haystack, needle) { + if (!needle) { + return true; + } + return haystack.toLowerCase().indexOf( + needle.toLowerCase()) !== -1; + }; + + // init the filtered items + $scope.search = function() { + $scope.filteredItems = $filter('filter')( + $scope.objVersion, + function(item) { + for ( var attr in item) { + if (searchMatch(item[attr], + $scope.query)) + return true; + } + return false; + }); + // take care of the sorting order + if ($scope.sort.sortingOrder !== '') { + $scope.filteredItems = $filter( + 'orderBy')( + $scope.filteredItems, + $scope.sort.sortingOrder, + $scope.sort.reverse); + } + $scope.currentPage = 0; + // now group by pages + $scope.groupToPages(); + }; + + // calculate page in place + $scope.groupToPages = function() { + $scope.pagedItems = []; + + for (var i = 0; i < $scope.filteredItems.length; i++) { + if (i % $scope.itemsPerPage === 0) { + $scope.pagedItems[Math.floor(i + / $scope.itemsPerPage)] = [ $scope.filteredItems[i] ]; + } else { + $scope.pagedItems[Math.floor(i + / $scope.itemsPerPage)] + .push($scope.filteredItems[i]); + } + } + }; + + $scope.range = function(size, start, end) { + var ret = []; + //console.log(size, start, end); + + if (size < end) { + end = size; + start = size - $scope.gap; + } + for (var i = start; i < end; i++) { + ret.push(i); + } + //console.log(ret); + return ret; + }; + + $scope.prevPage = function() { + if ($scope.currentPage > 0) { + $scope.currentPage--; + } + }; + + $scope.nextPage = function() { + if ($scope.currentPage < $scope.pagedItems.length - 1) { + $scope.currentPage++; + } + }; + + $scope.setPage = function() { + $scope.currentPage = this.n; + }; + + // functions have been describe process the data + // for display + $scope.search(); + + } + + + + //For apply version + + $scope.ApplyConfig = function(objVersion){ + var count = 0; + angular.forEach(objVersion, function(item) { + if (item.selected == true) + count++; + }); + if (count < 1) { + $scope.errorMessage = "Select a config file to apply !!!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + }else if (count > 1) { + $scope.errorMessage = "Only one config file can be applyed at a time !!!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + }else + $scope.applyModelNew(objVersion); + }; + + + $scope.applyModelNew = function(objVersion){ + + $scope.objCompareModel1 = {}; + + $scope.versionsSelected = []; + angular.forEach(objVersion, function(item) { + angular.forEach($scope.objVersionModel, function(val, index) { + /* if (item.vnfversion == val['vnfversion'] && item.selected == false) { + $scope.objVersionModel.splice(index, 1); + }*/ + if (item.selected) { + if ($scope.versionsSelected.indexOf(item) == -1) + $scope.versionsSelected.push(item); + } + }) + }); + console.log("--CompareConfigCtrl::createCompareModel::$scope.objVersionModel", JSON.stringify($scope.objVersionModel)); + + angular.forEach($scope.versionsSelected, function(item) { + var versionObj = {}; + var versionDetails = {}; + versionDetails.vnfversion = item['vnfversion']; + versionDetails.vnfName = item['vnfname']; + var vnfid = item['vnfid']; + // var config = JSON.parse(item['configinfo']); + var config = item['configinfo']; + var config1=JSON.parse(config); + console.log("CompareConfigCtrl::createCompareModel::objCompareModel1", config1); + deviceConfigService.runApplyconfig(vnfid,config1); + $scope.successMessage = "File uploaded successfully"; + growl.success($scope.successMessage, { + title: 'Success!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + }); + } + +//View Configuration + + $scope.ViewConfig = function(objVersion){ + var elmnt1 = document.getElementById("view"); + + elmnt1.style.display = "block"; + var count = 0; + angular.forEach(objVersion, function(item) { + if (item.selected == true) + count++; + }); + if (count < 1) { + $scope.showResult = false; + $scope.errorMessage = "Select a config file to view !!!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + }else if (count > 1) { + $scope.showResult = false; + $scope.errorMessage = "Only one config file can be viewed at a time !!!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + }else + $scope.ViewCompareModelNew(objVersion); + }; + + $scope.ViewCompareModelNew = function(objVersion) { + $scope.objCompareModel1 = {}; + + $scope.versionsSelected = []; + angular.forEach(objVersion, function(item) { + angular.forEach($scope.objVersionModel, function(val, index) { + /*if (item.vnfversion == val['vnfversion'] && item.selected == false) { + $scope.objVersionModel.splice(index, 1); + }*/ + if (item.selected) { + if ($scope.versionsSelected.indexOf(item) == -1) + $scope.versionsSelected.push(item); + } + }) + }); + console.log("--CompareConfigCtrl::createCompareModel::$scope.objVersionModel", JSON.stringify($scope.objVersionModel)); + + angular.forEach($scope.versionsSelected, function(item) { + var versionObj = {}; + var versionDetails = {}; + versionDetails.vnfversion = item['vnfversion']; + versionDetails.vnfName = item['vnfname']; + var vnfid = item['vnfid']; + + + versionDetails.timeStamp = item.createdAt; + versionObj.versionDetails = versionDetails; + + //fetch all the other topology/network,opertaion status for the vnf + // versionObj.topologyInfo = $scope.fetchConfigDetails(item); + versionObj.topologyInfo = $scope.fetchTopologyInfo(item); + versionObj.vnfIdInfo = $scope.fetchVnfId(item); + versionObj.serviceStatusInfo= $scope.fetchServiceStatus(item); + versionObj.vnfTopologyIdentifier = $scope.vnfTopologyIdentifier(item); + versionObj.operationStatus = $scope.operationStatus(item); + versionObj.vnfRequestInfo=$scope.fetchVnfRequestInfo(item); + versionObj.serviceInfo= $scope.fetchServiceInfo(item); + versionObj.requestHeader= $scope.serviceRequestHeader(item); + versionObj.requestInfo=$scope.fetchRequestInfo(item); + + if ((versionObj.versionDetails.vnfversion == $scope.versionsSelected[0].vnfversion)) { + $scope.objCompareModel1 = versionObj; + } else + {console.log("CompareConfigCtrl::createCompareModel::objCompareModel1"); + + } + document.getElementById("compare").style.display = "none"; + } ); + $scope.showView=true; + $scope.showResult = true; + var elmnt1 = document.getElementById("view"); + elmnt1.scrollIntoView(); + console.log("CompareConfigCtrl::createCompareModel::objCompareModel1", JSON.stringify($scope.objCompareModel1)); + } + + + //compare + + + $scope.CompareConfig = function(objVersion) { + var elmnt = document.getElementById("compare"); + elmnt.style.display = "block"; + var count = 0; + angular.forEach(objVersion, function(item) { + if (item.selected == true) + count++; + }); + if (count > 4) { + $scope.showResult = false; + $scope.errorMessage = "Four or lessthan four and gretterthan two config files can be selected for the comparison!!!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + } else if (count < 2){ + $scope.showResult = false; + $scope.errorMessage = "At least two config files can be selected for the comparison!!!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton: false, + ttl: 7000, + disableCountDown: true + }); + }else + $scope.createCompareModelNew(objVersion); + }; + + $scope.createCompareModelNew = function(objVersion) { + + $scope.objCompareModel1 = {}; + $scope.objCompareModel2 = {}; + + $scope.versionsSelected = []; + angular.forEach(objVersion, function(item) { + angular.forEach($scope.objVersionModel, function(val, index) { + /*if ((item.vnfversion == val['vnfversion']) && item.selected == false) { + // $scope.objVersionModel.splice(index, 1); + }*/ + if (item.selected) { + if ($scope.versionsSelected.indexOf(item) == -1) + $scope.versionsSelected.push(item); + } + }) + }); + console.log("--CompareConfigCtrl::createCompareModel::$scope.objVersionModel", JSON.stringify($scope.objVersionModel)); + console.log("--CompareConfigCtrl::createCompareModel::$scope.objVersionModel", JSON.stringify($scope.versionsSelected)); + + angular.forEach($scope.versionsSelected, function(item) { + var versionObj = {}; + var versionDetails = {}; + versionDetails.vnfversion = item.vnfversion; + /*versionDetails.vnfName = item['vnfname']; + versionDetails.vnfid = item['vnfid'];*/ + versionDetails.timeStamp = item.createdAt; + versionObj.versionDetails = versionDetails; + + //fetch all the other topology/network,opertaion status for the vnf + // versionObj.topologyInfo = $scope.fetchConfigDetails(item); + versionObj.topologyInfo = $scope.fetchTopologyInfo(item); + versionObj.vnfIdInfo = $scope.fetchVnfId(item); + versionObj.serviceStatusInfo= $scope.fetchServiceStatus(item); + versionObj.vnfTopologyIdentifier = $scope.vnfTopologyIdentifier(item); + versionObj.operationStatus = $scope.operationStatus(item); + versionObj.vnfRequestInfo=$scope.fetchVnfRequestInfo(item); + versionObj.serviceInfo= $scope.fetchServiceInfo(item); + versionObj.requestHeader= $scope.serviceRequestHeader(item); + versionObj.requestInfo=$scope.fetchRequestInfo(item); + + if ((versionObj.versionDetails.vnfversion == $scope.versionsSelected[0].vnfversion)) { + $scope.objCompareModel1 = versionObj; + } else if ((versionObj.versionDetails.vnfversion == $scope.versionsSelected[1].vnfversion)) + {$scope.objCompareModel2 = versionObj; + } + document.getElementById("view").style.display = "none"; + } ); + $scope.showResult = true; + var elmnt = document.getElementById("compare"); + elmnt.scrollIntoView(); + console.log("CompareConfigCtrl::createCompareModel::objCompareModel1", JSON.stringify($scope.objCompareModel1)); + console.log("CompareConfigCtrl::createCompareModel::objCompareModel2", JSON.stringify($scope.objCompareModel2)); + + } + + //1'st comparison for vnf topology info vnf-parameters + $scope.fetchTopologyInfo = function(item) { + var topologyInfo = {}; + item = JSON.parse(item.configinfo); + var item= item['vnf-list'][0]; + if (angular.isDefined(item['service-data']) && angular.isDefined(item['service-data']['vnf-topology-information'])) { + var vnfTopologyInfo = item['service-data']['vnf-topology-information']; + if (angular.isDefined(vnfTopologyInfo['vnf-parameters'] && vnfTopologyInfo['vnf-parameters'] != null)) { + var vnfParameters = vnfTopologyInfo['vnf-parameters']; + for (var i = 0; i < vnfParameters.length; i++) { + + var key = vnfParameters[i]['vnf-parameter-name']; + var value = vnfParameters[i]['vnf-parameter-value']; + console.log("CompareConfigCtrl::fetchTopologyInfo::key", key); + console.log("CompareConfigCtrl::fetchTopologyInfo::value", value); + topologyInfo[key] = value; + + } + console.log("CompareConfigCtrl::fetchTopologyInfo::", JSON.stringify(topologyInfo)); + return topologyInfo; + } + } + } + + + + //2nd comparison for vnf id + + $scope.fetchVnfId = function(item){ + var vnfIdInfo = {}; + item = JSON.parse(item.configinfo); + var item= item['vnf-list'][0]; + if (angular.isDefined(item['vnf-id'])) { + var key=item['vnf-id']; + vnfIdInfo['vnf-id']=key; + } + console.log("CompareConfigCtrl::fetchVnfId::", JSON.stringify( vnfIdInfo)); + return vnfIdInfo; + } + + + //3rd comparison for service status + + $scope.fetchServiceStatus = function(item) { + var serviceStatusInfo = {}; + + item = JSON.parse(item.configinfo); + var item= item['vnf-list'][0]; + + if (angular.isDefined(item['service-status'])) { + var serviceStatus = item['service-status']; + if (angular.isDefined(serviceStatus)) { + angular.forEach(serviceStatus, function(value, key) { + + console.log("CompareConfigCtrl::fetchServiceStatus::key", key); + console.log("CompareConfigCtrl::fetchServiceStatus::value", value); + serviceStatusInfo[key] = value; + }); + } + } + + console.log("CompareConfigCtrl::fetchServiceStatus::", JSON.stringify(serviceStatusInfo)); + return serviceStatusInfo; + } + + // 4th comparison for vnf topology identifire + + $scope.vnfTopologyIdentifier = function(item) { + var topologyIdnetifier = {}; + item = JSON.parse(item.configinfo); + var item= item['vnf-list'][0]; + if (angular.isDefined(item['service-data']) && angular.isDefined(item['service-data']['vnf-topology-information']['vnf-topology-identifier'])) { + var topologyInfoidentifier = item['service-data']['vnf-topology-information']['vnf-topology-identifier']; + if (angular.isDefined(topologyInfoidentifier)) { + angular.forEach(topologyInfoidentifier, function(value, key) { + + console.log("CompareConfigCtrl::fetchTopologyInfo::key", key); + console.log("CompareConfigCtrl::fetchTopologyInfo::value", value); + topologyIdnetifier[key] = value; + }); + } + } + + console.log("CompareConfigCtrl::vnfTopologyIdentifier::", JSON.stringify(topologyIdnetifier)); + return topologyIdnetifier; + } + + // 5th comparison for vnf request information + + $scope.fetchVnfRequestInfo = function(item) { + var vnfRequestInfo = {}; + item = JSON.parse(item.configinfo); + var item= item['vnf-list'][0]; + if (angular.isDefined(item['service-data']) && angular.isDefined(item['service-data']['vnf-request-information'])) { + var vnfRequest = item['service-data']['vnf-request-information']; + if (angular.isDefined(vnfRequest) && vnfRequest != null) { + + angular.forEach(vnfRequest, function(value, key) { + + console.log("CompareConfigCtrl::fetchVnfRequestInfo::key", key); + console.log("CompareConfigCtrl::fetchVnfRequestInfo::value", value); + vnfRequestInfo[key] = value; + }); + } + } +console.log("CompareConfigCtrl::fetchVnfRequestInfo::", JSON.stringify(vnfRequestInfo)); + return vnfRequestInfo; + } + + // 6th comparison for service info + + + $scope.fetchServiceInfo = function(item) { + var serviceInfo = {}; + item = JSON.parse(item.configinfo); + var item= item['vnf-list'][0]; + if (angular.isDefined(item['service-data']) && angular.isDefined(item['service-data']['service-information'])) { + var service= item['service-data']['service-information']; + if (angular.isDefined(service) && service != null) { + + angular.forEach(service, function(value, key) { + + console.log("CompareConfigCtrl::fetchServiceInfo::key", key); + console.log("CompareConfigCtrl::fetchServiceInfo::value", value); + serviceInfo[key] = value; + }); + } + } + console.log("CompareConfigCtrl::fetchServiceInfo::", JSON.stringify(serviceInfo)); + return serviceInfo; + } + + // 7th comparison for sdnc request header + + $scope.serviceRequestHeader = function(item) { + var requestHeader = {}; + item = JSON.parse(item.configinfo); + var item= item['vnf-list'][0]; + if (angular.isDefined(item['service-data']) && angular.isDefined(item['service-data']['sdnc-request-header'])) { + var requestHeaderInfo = item['service-data']['sdnc-request-header']; + if (angular.isDefined(requestHeaderInfo) && requestHeaderInfo != null) { + + angular.forEach(requestHeaderInfo, function(value, key) { + + console.log("CompareConfigCtrl::serviceRequestHeader::key", key); + console.log("CompareConfigCtrl::serviceRequestHeader::value", value); + requestHeader[key] = value; + }); + + } + } + console.log("CompareConfigCtrl::serviceRequestHeader::", JSON.stringify(requestHeader)); + return requestHeader; + } + + // 8th comparison for oper status + $scope.operationStatus = function(item) { + var operationStatus = {}; + item = JSON.parse(item.configinfo); + var item= item['vnf-list'][0]; + if (angular.isDefined(item['service-data']) && angular.isDefined(item['service-data']['oper-status'])) { + var operStatus = item['service-data']['oper-status']; + if (angular.isDefined(operStatus) && operStatus != null) { + + angular.forEach(operStatus, function(value, key) { + + console.log("CompareConfigCtrl::operationStatus::key", key); + console.log("CompareConfigCtrl::operationStatus::value", value); + operationStatus[key] = value; + }); + + } + } + console.log("CompareConfigCtrl::operationStatus::", JSON.stringify(operationStatus)); + return operationStatus; + } + // 9th comparison for request info + + $scope.fetchRequestInfo = function(item) { + var requestInfo = {}; + item = JSON.parse(item.configinfo); + var item= item['vnf-list'][0]; + if (angular.isDefined(item['service-data']) && angular.isDefined(item['service-data']['request-information'])) { + var request = item['service-data']['request-information']; + if (angular.isDefined(request) && request != null) { + + angular.forEach(request, function(value, key) { + + console.log("CompareConfigCtrl::fetchRequestInfo::key", key); + console.log("CompareConfigCtrl::fetchRequestInfo::value", value); + requestInfo[key] = value; + }); + + } + } + console.log("CompareConfigCtrl::fetchRequestInfo::", JSON.stringify(requestInfo)); + return requestInfo; + } + +}]); \ No newline at end of file diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-validationTest-controller.js b/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-validationTest-controller.js new file mode 100644 index 00000000..0e80836f --- /dev/null +++ b/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-validationTest-controller.js @@ -0,0 +1,222 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : SDNC-FEATURES +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* ============LICENSE_END========================================================= +*/ + + +myApp.controller('TestController', ['$scope', '$http', 'growl', 'viewReportService', 'validationTestService','CERTIFICATION_API_BASE', function($scope, $http, growl, viewReportService, validationTestService,CERTIFICATION_API_BASE) { + + $scope.showTestReport = false; + + //Input data for validation test dropdown + var validationTestList = [{ + "typeId": 1, + "validationType": "Network Layer", + "Selected": false + }, + { + "typeId": 2, + "validationType": "Protocol Layer", + "Selected": false + } + ]; + + $scope.validationTestList = validationTestList; + + + $scope.getselectval = function() { + $scope.selectedvalues = 'Name: ' + $scope.selitem.validationType + ' Id: ' + $scope.selitem.typeId; + } + + $scope.showError = false; + $scope.errorMessage = ""; + $scope.showSuccess = false; + $scope.successMessage = ""; + $scope.showWarning = false; + $scope.warningMessage = ""; + $scope.showInfo = false; + $scope.infoMessage = ""; + $scope.ShowResult = false; + $scope.allowTestSelection = false; + $scope.hostNamePattern = /([a-z0-9](.[a-z0-9-]*[a-z0-9]))/; + + //Called when user clicks on runtest button + $scope.runTest = function() { + + $scope.showError = false; + $scope.vnfSelected = []; + $scope.testSelected = []; + + var message = ""; + for (var i = 0; i < $scope.validationTestList.length; i++) { + if ($scope.validationTestList[i].Selected) { + var typeId = $scope.validationTestList[i].typeId; + var validationType = $scope.validationTestList[i].validationType; + message += "typeId: " + typeId + " validationType: " + validationType + "\n"; + console.log("--TestController::Runtest--", message); + var testDetails = {}; + testDetails.typeId = typeId; + testDetails.validationType = validationType; + $scope.testSelected.push(testDetails); + } + } + console.log("--TestController::Runtest--", JSON.stringify($scope.testSelected)); + + var vnfDetails = {}; + if ($scope.IPAddress != null && $scope.HostName != null && $scope.testSelected.length >= 1) { + vnfDetails.IpAddress = $scope.IPAddress; + vnfDetails.HostName = $scope.HostName; + $scope.vnfSelected.push(vnfDetails); + console.log("--TestController::Runtest--", JSON.stringify($scope.vnfSelected)); + + //Call the validation test service with vnfselected and testType as the parameter + + validationTestService.runPretest($scope.vnfSelected, $scope.testSelected).then(function(response) { + console.log("--TestController::runTest--", JSON.stringify(response)); + + //in case of success, build the model object to store the service output here + if (response.status === 200) { + if (response.preTestResponse != null && response.preTestResponse.length >= 1) { + $scope.ShowResult = true; + $scope.createTestModel(response.preTestResponse); + $scope.showMessage(response.preTestResponse); + + } else { + console.log(response); + $scope.showError = true; + $scope.errorMessage = "Something went wrong!!!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton:false + }); + } + } else { + console.log(response); + $scope.showError = true; + $scope.errorMessage = "Something went wrong!!! Please try again later"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton:false + }); + } + }, + function(response) { + console.log("--TestController--", response); + }); + } else { + $scope.showError = true; + $scope.errorMessage = "Please provide the inputs for VNF and test to be performed!!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton:false + }); + } + + }; + +$scope.showMessage=function(data){ + + var iterate = true; + if(angular.isDefined(data) && data.length>=1){ + + iterate=true; + angular.forEach(data, function(value, key){ + + if(iterate=true){ + if(value.status == "unreachable"){ + console.log("--TestController::showMessage--",value.status); + $scope.showError = true; + $scope.errorMessage = "PreTest validation Failed, Please check logs for further details!!!"; + growl.error($scope.errorMessage, { + title: 'Error!', + globalDisableCloseButton:false + }); + iterate=false; + } + } + else + { + $scope.showSuccess = true; + $scope.successMessage = "Pre test validation completed!!"; + growl.success($scope.successMessage, { + title: 'Success!', + globalDisableCloseButton:false + }); + } + + }); + + } + } + + //Function to build the UI model to be shown + $scope.createTestModel = function(result) { + + $scope.showError = false; + $scope.showWarning = false; + $scope.objPreTestModel = result; + $scope.objPreTest = []; + + + if ($scope.objPreTestModel.length >= 1) { + for (var i = 0; i < $scope.objPreTestModel.length; i++) { + var objTestReport = {}; + objTestReport.ipaddress = $scope.objPreTestModel[i].ipaddress; + objTestReport.status = $scope.objPreTestModel[i].status; + objTestReport.testtype = $scope.objPreTestModel[i].testtype; + objTestReport.statistics = $scope.objPreTestModel[i].statistics; + objTestReport.avgTime = $scope.objPreTestModel[i].avgTime; + + + if ($scope.objPreTestModel[i].testtype === "Network Layer") { + if (objTestReport.statistics != null) { + //fetching the statistics to show in progress bar + + var statistics = objTestReport.statistics; + statistics = statistics.split("%"); + objTestReport.statistics = statistics[0]; + if (objTestReport.statistics == 0) { + objTestReport.statisticPer = parseInt(objTestReport.statistics) + 50; + } else + objTestReport.statisticPer = objTestReport.statistics; + } + + //fetching the avg time to show in progress bar + + if (objTestReport.avgTime != null) { + var avgTime = objTestReport.avgTime; + avgTime = avgTime.split("="); + var Testtime = avgTime[1]; + objTestReport.avgTime = Testtime.slice(0, -2).trim(); + console.log("--TestController::createTestModel--", objTestReport.avgTime); + if (objTestReport.avgTime < 50) { + objTestReport.avgTimePer = parseInt(objTestReport.avgTime) + 10; + } else + objTestReport.avgTimePer = objTestReport.avgTime; + + } + } + $scope.objPreTest.push(objTestReport); + console.log("--TestController::createTestModel--", JSON.stringify($scope.objPreTest)); + } + } + console.log("--TestController::createTestModel::final PreTestModel--" + JSON.stringify($scope.objPreTest)); + + } + +}]); \ No newline at end of file diff --git a/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-viewreport-controller.js b/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-viewreport-controller.js new file mode 100644 index 00000000..951ac5d5 --- /dev/null +++ b/configbackuprestore/vnfconfigbackupservice/src/main/webapp/js/sdnc-controller/sdnc-viewreport-controller.js @@ -0,0 +1,519 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : SDNC-FEATURES + * ================================================================================ + * Copyright 2018 TechMahindra + *================================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +myApp.controller( + 'ReportController', + [ + '$scope', + '$http', + '$filter', + 'viewReportService', + 'growl', + function($scope, $http, $filter, viewReportService, + growl) { + $scope.isDisabled = true; + $scope.pagination = false; + $scope.selectedDevice; + $scope.ShowResult = false; + $scope.dateValidation = false; + $scope.NoSearchResult = false; + $scope.showError = false; + $scope.errorMessage = ""; + $scope.showSuccess = false; + $scope.successMessage = ""; + $scope.showWarning = false; + $scope.warningMessage = ""; + $scope.showExecutionDetails = true; + $scope.showData = false; + + $scope.gap = 2; + $scope.filteredItems = []; + $scope.groupedItems = []; + $scope.itemsPerPage = 5; + $scope.pagedItems = []; + $scope.currentPage = 0; + + // THIS FUNCTION WILL BE CALLED ON PAGE LOAD + $scope.getAllVNF = function() { + + viewReportService + .getAllVNF() + .then( + function(data) { + if (data != null) { + console.log(data); + $scope.objvnfList = data; + console + .log("ViewConfigCtrl:getAllVNF called" + + $scope.objvnfList); + } else { + $scope.warningMessage = "No VNF is eligible for configuration!!!"; + growl + .error( + $scope.warningMessage, + { + title : 'Warning!', + globalDisableCloseButton : false, + ttl : 7000, + disableCountDown : true + }); + } + }); + }; + $scope.getAllVNF(); + + $scope.selectVnf = function(selectedValueVnf) { + + if (selectedValueVnf != null + && selectedValueVnf != "") { + console.log("selectedvnf Value", + selectedValueVnf); + var vnfId = selectedValueVnf; + $scope.ShowResult = true; + + } else { + $scope.ShowResult = false; + $scope.showCompare = false; + $scope.showResult = false; + $scope.errorMessage = "Please select a VNF!!!"; + growl.error($scope.errorMessage, { + title : 'Error!', + globalDisableCloseButton : false, + ttl : 7000, + disableCountDown : true + }); + } + } + + // THIS FUNCTION WILL BE CALLED WHEN USER CLICK + // SUBMIT FROM UI + $scope.getReportsById = function(selectedValueVnf, + startdate, enddate) { + + $scope.ShowResult = true; + if (new Date(startdate) > new Date(enddate)) { + $scope.dateValidation = true; + $scope.showError = true; + $scope.errorMessage = "Start date cannot be greated than End date"; + growl.error($scope.errorMessage, { + title : 'Error!', + globalDisableCloseButton : false, + ttl : 7000, + disableCountDown : true + }); + return false; + } + var date = new Date(startdate); + if (angular.isDefined(startdate)) { + $scope.startDate = startdate; + } + if (angular.isDefined(enddate)) { + $scope.endDate = enddate; + } + + $scope.startdate1 = $filter('date')( + $scope.startDate, 'dd-MM-yyyy'); + $scope.enddate1 = $filter('date')( + $scope.endDate, 'dd-MM-yyyy'); + if (startdate != null && enddate != null) { + + // service call to fetch the reports start + // date,end date,test name + viewReportService + .getDataById(selectedValueVnf, + $scope.startdate1, + $scope.enddate1) + .then( + function(result) { + console + .log( + "-----------------------------------ReportController::getdata called from controler--", + JSON + .stringify(result.data)); + if (result.status == 200) { + if (result.data != null + && result.data.length >= 1) { + + // in case of + // success, + // build the + // model object + // to store the + // service + // output here + $scope + .createTestReportModel(result.data);// result.data.data + } else { + $scope.ShowResult = false; + $scope.showWarning = true; + $scope.warningMessage = "No result found for specified Date !!"; + growl + .warning( + $scope.warningMessage, + { + title : 'Warning!', + globalDisableCloseButton : false, + ttl : 7000, + disableCountDown : true + }); + } + } else { + $scope.ShowResult = false; + $scope.showWarning = true; + $scope.warningMessage = "No result found for specified Date !!"; + growl + .warning( + $scope.warningMessage, + { + title : 'Warning!', + globalDisableCloseButton : false, + ttl : 7000, + disableCountDown : true + }); + } + }, + function(response) { + $scope.ShowError = true; + $scope.errorMessage = "Something went wrong, Please try again !!"; + growl + .error( + $scope.errorMessage, + { + title : 'Error!', + globalDisableCloseButton : false, + ttl : 7000, + disableCountDown : true + }); + console + .log( + "--ReportController::getdata::Error--", + response); + }); + } + } + + // FUNCTION WILL BE CALLED WHEN USER CLICK DOWNLOAD + // FROM UI + $scope.exportToExcel = function(tableId) { // ex: + // '#my-table' + var exportHref = Excel.tableToExcel(tableId, + 'export'); + $timeout(function() { + location.href = exportHref; + }, 100); // trigger download + + console + .log("--ReportController::exportToexcel--"); + } + + $scope.createTestReportModel = function(result) { + + $scope.showError = false; + $scope.showWarning = false; + $scope.objTestReportModel = result; + $scope.objTestModel = []; + + if ($scope.objTestReportModel.length >= 1) { + for (var i = 0; i < $scope.objTestReportModel.length; i++) { + var objTestReport = {}; + objTestReport.vnfname = $scope.objTestReportModel[i].vnfname; + objTestReport.vnfid = $scope.objTestReportModel[i].vnfid; + objTestReport.versionNo = $scope.objTestReportModel[i].vnfversion; + objTestReport.createdAt = $scope.objTestReportModel[i].creationdate; + objTestReport.updatedAt = $scope.objTestReportModel[i].lastupdated; + objTestReport.status = $scope.objTestReportModel[i].status; + objTestReport.Id = $scope.objTestReportModel[i].id; + // objTestReport.configinfo = + // $scope.objVersionModel[i].configinfo; + $scope.objTestModel.push(objTestReport); + console + .log( + "--ReportController::CreateTestReportModel--", + JSON + .stringify($scope.objTestModel)); + + } + $scope.showresult = true; + $scope.pagination = true; + } + console + .log("--ReportController::createTestReportModel::final TestReportModel--" + + JSON + .stringify($scope.objTestModel)); + $scope.csvOrder = [ 'testname', 'timeStamp', + 'status', 'statistics', 'avgTime', + 'result' ]; + + } + + // THIS FUNCTION WILL BE CALLED WHEN USER CLICK + // SUBMIT FROM UI + $scope.getReports = function(startdate, enddate) { + + $scope.ShowResult = false; + if (new Date(startdate) > new Date(enddate)) { + $scope.dateValidation = true; + $scope.showError = true; + $scope.errorMessage = "Start date cannot be greated than End date"; + growl.error($scope.errorMessage, { + title : 'Error!', + globalDisableCloseButton : false, + ttl : 7000, + disableCountDown : true + }); + return false; + } + var date = new Date(startdate); + /* + * if (angular.isDefined(deviceName)) { + * $scope.DeviceName = deviceName; } + */ + if (angular.isDefined(startdate)) { + $scope.startDate = startdate; + } + if (angular.isDefined(enddate)) { + $scope.endDate = enddate; + } + + $scope.startdate1 = $filter('date')( + $scope.startDate, 'dd-MM-yyyy'); + $scope.enddate1 = $filter('date')( + $scope.endDate, 'dd-MM-yyyy'); + if (startdate != null && enddate != null) { + + // service call to fetch the reports start + // date,end date,test name + viewReportService + .getData($scope.startdate1, + $scope.enddate1) + .then( + function(result) { + console + .log( + "-----------------------------------ReportController::getdata called from controler--", + JSON + .stringify(result.data)); + if (result.status == 200) { + if (result.data != null + && result.data.length >= 1) { + + // in case of + // success, + // build the + // model object + // to store the + // service + // output here + $scope + .createTestReportModel(result.data);// result.data.data + } else { + $scope.ShowResult = false; + $scope.showWarning = true; + $scope.warningMessage = "No result found for specified Date !!"; + growl + .warning( + $scope.warningMessage, + { + title : 'Warning!', + globalDisableCloseButton : false, + ttl : 7000, + disableCountDown : true + }); + } + } else { + $scope.ShowResult = false; + $scope.showWarning = true; + $scope.warningMessage = "No result found for specified Date !!"; + growl + .warning( + $scope.warningMessage, + { + title : 'Warning!', + globalDisableCloseButton : false, + ttl : 7000, + disableCountDown : true + }); + } + }, + function(response) { + $scope.ShowError = true; + $scope.errorMessage = "Something went wrong, Please try again !!"; + growl + .error( + $scope.errorMessage, + { + title : 'Error!', + globalDisableCloseButton : false, + ttl : 7000, + disableCountDown : true + }); + console + .log( + "--ReportController::getdata::Error--", + response); + }); + } + } + + // FUNCTION WILL BE CALLED WHEN USER CLICK DOWNLOAD + // FROM UI + $scope.exportToExcel = function(tableId) { // ex: + // '#my-table' + var exportHref = Excel.tableToExcel(tableId, + 'export'); + $timeout(function() { + location.href = exportHref; + }, 100); // trigger download + + console + .log("--ReportController::exportToexcel--"); + } + + $scope.createTestReportModel = function(result) { + + $scope.showError = false; + $scope.showWarning = false; + $scope.objTestReportModel = result; + $scope.objTestModel = []; + + if ($scope.objTestReportModel.length >= 1) { + for (var i = 0; i < $scope.objTestReportModel.length; i++) { + var objTestReport = {}; + objTestReport.vnfname = $scope.objTestReportModel[i].vnfname; + objTestReport.vnfid = $scope.objTestReportModel[i].vnfid; + objTestReport.versionNo = $scope.objTestReportModel[i].vnfversion; + objTestReport.createdAt = $scope.objTestReportModel[i].creationdate; + objTestReport.updatedAt = $scope.objTestReportModel[i].lastupdated; + objTestReport.status = $scope.objTestReportModel[i].status; + objTestReport.Id = $scope.objTestReportModel[i].id; + // objTestReport.configinfo = + // $scope.objVersionModel[i].configinfo; + $scope.objTestModel.push(objTestReport); + console + .log( + "--ReportController::CreateTestReportModel--", + JSON + .stringify($scope.objTestModel)); + + } + $scope.showresult = true; + $scope.pagination = true; + } + console + .log("--ReportController::createTestReportModel::final TestReportModel--" + + JSON + .stringify($scope.objTestModel)); + $scope.csvOrder = [ 'testname', 'timeStamp', + 'status', 'statistics', 'avgTime', + 'result' ]; + + // init + $scope.sort = { + sortingOrder : 'createdAt', + reverse : false + }; + + var searchMatch = function(haystack, needle) { + if (!needle) { + return true; + } + return haystack.toLowerCase().indexOf( + needle.toLowerCase()) !== -1; + }; + + // init the filtered items + $scope.search = function() { + $scope.filteredItems = $filter('filter')( + $scope.objTestModel, + function(item) { + for ( var attr in item) { + if (searchMatch(item[attr], + $scope.query)) + return true; + } + return false; + }); + // take care of the sorting order + if ($scope.sort.sortingOrder !== '') { + $scope.filteredItems = $filter( + 'orderBy')( + $scope.filteredItems, + $scope.sort.sortingOrder, + $scope.sort.reverse); + } + $scope.currentPage = 0; + // now group by pages + $scope.groupToPages(); + }; + + // calculate page in place + $scope.groupToPages = function() { + $scope.pagedItems = []; + + for (var i = 0; i < $scope.filteredItems.length; i++) { + if (i % $scope.itemsPerPage === 0) { + $scope.pagedItems[Math.floor(i + / $scope.itemsPerPage)] = [ $scope.filteredItems[i] ]; + } else { + $scope.pagedItems[Math.floor(i + / $scope.itemsPerPage)] + .push($scope.filteredItems[i]); + } + } + }; + + $scope.range = function(size, start, end) { + var ret = []; + console.log(size, start, end); + + if (size < end) { + end = size; + start = size - $scope.gap; + } + for (var i = start; i < end; i++) { + ret.push(i); + } + console.log(ret); + return ret; + }; + + $scope.prevPage = function() { + if ($scope.currentPage > 0) { + $scope.currentPage--; + } + }; + + $scope.nextPage = function() { + if ($scope.currentPage < $scope.pagedItems.length - 1) { + $scope.currentPage++; + } + }; + + $scope.setPage = function() { + $scope.currentPage = this.n; + }; + + // functions have been describe process the data + // for display + $scope.search(); + + } + + } ]); \ No newline at end of file -- cgit 1.2.3-korg