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=========================================================
20 myApp.controller('BackupConfigCtrl', ['$scope', '$http','$window', 'growl', 'deviceConfigService', 'ObjectDiff', '$timeout' , function($scope, $http, $window, growl, deviceConfigService, ObjectDiff, $timeout) {
22 $scope.showResult = false;
23 $scope.showCompare = false;
25 //THIS FUNCTION WILL BE CALLED ON PAGE LOAD
26 $scope.getAllVNF = function() {
28 deviceConfigService.getAllVNF().then(function(data) {
31 $scope.objvnfList = data;
32 console.log("CompareConfigCtrl:getAllVNF called" + $scope.objvnfList);
34 $scope.warningMessage = "No VNF is eligible for configuration!!!";
35 growl.error($scope.warningMessage, {
37 globalDisableCloseButton: false,
39 disableCountDown: true
46 $scope.selectVnf = function(selectedValueVnf) {
48 if (selectedValueVnf != null && selectedValueVnf != "") {
49 console.log("selectedvnf Value", selectedValueVnf);
50 //selectedItem = selectedValueVnf.split("%");
51 // var vnfName = selectedItem[0];
52 // var vnfType = selectedItem[1];
53 var vnfId = selectedValueVnf;
54 $scope.getVersionList(vnfId);
56 $scope.ShowResult = false;
57 $scope.showCompare = false;
58 $scope.showResult = false;
59 $scope.errorMessage = "Please select a VNF!!!";
60 growl.error($scope.errorMessage, {
62 globalDisableCloseButton: false,
64 disableCountDown: true
70 //THIS FUNCTION WILL BE CALLED ON SELECTION OF VNF
71 $scope.getVersionList = function(vnfId) {
73 $scope.ShowResult = false;
75 //service call to fetch the version list
76 deviceConfigService.getVersions(vnfId).then(function(result) {
77 console.log("--CompareConfigCtrl::getVersionList called from controler--", JSON.stringify(result));
78 var status = result.status;
79 var result = result.data;
81 if (result.length >= 1) {
82 //in case of success, build the model object to store the service output here
83 $scope.createVersionModel(result);
85 $scope.ShowResult = false;
86 $scope.warningMessage = "No configruation found for the selected VNF !!";
87 growl.warning($scope.warningMessage, {
89 globalDisableCloseButton: false,
91 disableCountDown: true
95 $scope.ShowResult = false;
96 $scope.warningMessage = "No configruation found for the selected VNF !!";
97 growl.warning($scope.warningMessage, {
99 globalDisableCloseButton: false,
101 disableCountDown: true
106 $scope.errorMessage = "Something went wrong, Please try again !!";
107 growl.error($scope.errorMessage, {
109 globalDisableCloseButton: false,
111 disableCountDown: true
113 console.log("--CompareConfigCtrl::getVersionList::Error--", response);
117 //Function to build the UI model to be shown
118 $scope.createVersionModel = function(result) {
120 $scope.objVersionModel = result;
121 $scope.objVersion = [];
123 console.log("--CompareConfigCtrl::createVersionModel::--", JSON.stringify($scope.objVersionModel));
124 if ($scope.objVersionModel.length >= 1) {
125 $scope.ShowResult = true;
126 $scope.showCompare = true;
127 for (var i = 0; i < $scope.objVersionModel.length; i++) {
128 var objVersionDetail = {};
129 objVersionDetail.vnfname = $scope.objVersionModel[i].vnfname;
130 objVersionDetail.vnfid = $scope.objVersionModel[i].vnfid;
131 objVersionDetail.versionNo = $scope.objVersionModel[i].vnfversion;
132 objVersionDetail.createdAt = $scope.objVersionModel[i].creationdate;
133 objVersionDetail.configinfo = $scope.objVersionModel[i].configinfo;
134 objVersionDetail.selected = false;
136 $scope.objVersion.push(objVersionDetail);
139 console.log("--CompareConfigCtrl::createVersionModel::final VersionModel--" + JSON.stringify($scope.objVersion));
143 $scope.CompareConfig = function(objVersion) {
145 angular.forEach(objVersion, function(item) {
146 if (item.selected == true)
150 $scope.errorMessage = "Only two config files can be selected for the comparison!!!";
151 growl.error($scope.errorMessage, {
153 globalDisableCloseButton: false,
155 disableCountDown: true
157 } else if (count === 1){
158 $scope.errorMessage = "At least two config files can be selected for the comparison!!!";
159 growl.error($scope.errorMessage, {
161 globalDisableCloseButton: false,
163 disableCountDown: true
166 $scope.createCompareModelNew(objVersion);
169 $scope.createCompareModelNew = function(objVersion) {
171 $scope.objCompareModel1 = {};
172 $scope.objCompareModel2 = {};
174 $scope.versionsSelected = [];
175 angular.forEach(objVersion, function(item) {
176 angular.forEach($scope.objVersionModel, function(val, index) {
177 if (item.versionNo == val['versionNo'] && item.selected == false) {
178 $scope.objVersionModel.splice(index, 1);
181 if ($scope.versionsSelected.indexOf(item) == -1)
182 $scope.versionsSelected.push(item);
186 console.log("--CompareConfigCtrl::createCompareModel::$scope.objVersionModel", JSON.stringify($scope.objVersionModel));
187 angular.forEach($scope.objVersionModel, function(item) {
189 var versionDetails = {};
190 versionDetails.versionNo = item['vnfversion'];
191 /*versionDetails.vnfName = item['vnfname'];
192 versionDetails.vnfid = item['vnfid'];*/
193 versionDetails.timeStamp = item.creationdate;
194 versionObj.versionDetails = versionDetails;
196 //fetch all the other topology/network,opertaion status for the vnf
197 // versionObj.topologyInfo = $scope.fetchConfigDetails(item);
198 versionObj.topologyInfo = $scope.fetchTopologyInfo(item);
200 versionObj.networkTopologyInfo = $scope.fetchNetworkTopologyInfo(item);
201 versionObj.operationStatus = $scope.operationStatus(item);
202 versionObj.vnfTopologyIdentifier = $scope.vnfTopologyIdentifier(item);
204 if ((versionObj.versionDetails.versionNo == $scope.versionsSelected[0].versionNo)) {
205 $scope.objCompareModel1 = versionObj;
207 $scope.objCompareModel2 = versionObj;
210 $scope.showResult = true;
211 console.log("CompareConfigCtrl::createCompareModel::objCompareModel1", JSON.stringify($scope.objCompareModel1));
212 console.log("CompareConfigCtrl::createCompareModel::objCompareModel2", JSON.stringify($scope.objCompareModel2));
217 $scope.fetchTopologyInfo = function(item) {
218 var topologyInfo = {};
219 item = JSON.parse(item.configinfo);
220 if (angular.isDefined(item['preload-data']) && angular.isDefined(item['preload-data']['vnf-topology-information'])) {
221 var vnfTopologyInfo = item['preload-data']['vnf-topology-information'];
222 if (angular.isDefined(vnfTopologyInfo['vnf-parameters'] && vnfTopologyInfo['vnf-parameters'] != null)) {
223 var vnfParameters = vnfTopologyInfo['vnf-parameters'];
224 for (var i = 0; i < vnfParameters.length; i++) {
226 var key = vnfParameters[i]['vnf-parameter-name'];
227 var value = vnfParameters[i]['vnf-parameter-value'];
228 console.log("CompareConfigCtrl::fetchTopologyInfo::key", key);
229 console.log("CompareConfigCtrl::fetchTopologyInfo::value", value);
230 topologyInfo[key] = value;
233 console.log("CompareConfigCtrl::fetchTopologyInfo::", JSON.stringify(topologyInfo));
239 $scope.fetchNetworkTopologyInfo = function(item) {
240 var networkTopology = {};
241 item = JSON.parse(item.configinfo);
242 if (angular.isDefined(item['preload-data']) && angular.isDefined(item['preload-data']['network-topology-information'])) {
243 var netwrokTopologyInfo = item['preload-data']['network-topology-information'];
244 if (angular.isDefined(netwrokTopologyInfo) && netwrokTopologyInfo != null) {
245 for (var i = 0; i < netwrokTopologyInfo.length; i++) {
247 var key = netwrokTopologyInfo[i]['vnf-parameter-name'];
248 var value = netwrokTopologyInfo[i]['vnf-parameter-value'];
249 console.log("CompareConfigCtrl::fetchTopologyInfo::key", key);
250 console.log("CompareConfigCtrl::fetchTopologyInfo::value", value);
251 networkTopology[key] = value;
255 console.log("CompareConfigCtrl::fetchNetworkTopologyInfo::", JSON.stringify(networkTopology));
256 return networkTopology;
259 $scope.operationStatus = function(item) {
260 var operationStatus = {};
261 item = JSON.parse(item.configinfo);
262 if (angular.isDefined(item['preload-data']) && angular.isDefined(item['preload-data']['oper-status'])) {
263 var operStatus = item['preload-data']['oper-status'];
264 if (angular.isDefined(operStatus) && operStatus != null) {
266 var value = operStatus['order-status'];
267 operationStatus['order-status'] = value;
271 console.log("CompareConfigCtrl::operationStatus::", JSON.stringify(operationStatus));
272 return operationStatus;
275 $scope.vnfTopologyIdentifier = function(item) {
276 var topologyIdnetifier = {};
277 item = JSON.parse(item.configinfo);
278 if (angular.isDefined(item['preload-data']) && angular.isDefined(item['preload-data']['vnf-topology-information']['vnf-topology-identifier'])) {
279 var topologyInfoidentifier = item['preload-data']['vnf-topology-information']['vnf-topology-identifier'];
280 if (angular.isDefined(topologyInfoidentifier)) {
281 angular.forEach(topologyInfoidentifier, function(value, key) {
283 console.log("CompareConfigCtrl::fetchTopologyInfo::key", key);
284 console.log("CompareConfigCtrl::fetchTopologyInfo::value", value);
285 topologyIdnetifier[key] = value;
290 console.log("CompareConfigCtrl::vnfTopologyIdentifier::", JSON.stringify(topologyIdnetifier));
291 return topologyIdnetifier;
294 $scope.invokeBackup = function(){
295 deviceConfigService.invokeBackup().then(function(data) {
296 console.log("response -- data -- "+data)
297 $window.location.reload();
301 $scope.getLastModifiedTime=function(){
302 // $timeout(function(result){
303 // console.log("response-data-"+ result);
304 // $scope.lastModifiedTime="Testcode Dushyant"
308 deviceConfigService.getlastupdated().then(function(result) {
309 $scope.lastModifiedTime= result.data;
310 console.log("response -- getlastupdated -- "+JSON.stringify(result))
313 $scope.getLastModifiedTime()