2 * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 var app = angular.module('ModifyBlueprintInstance');
20 'ModifyBlueprintInstanceController',
21 function($scope, restAPISvc) {
25 function initialize() {
26 $scope.loadingBlueprintInstances = true;
27 $scope.loadingLayers = true;
28 $scope.blueprintInstanceInfos = [];
29 $scope.declerativeInsts = [];
30 $scope.selectedBlueprintInstance = '';
32 $scope.layerInfos = [];
33 $scope.selectedLayer = '';
34 $scope.configuredLayers = [];
35 $scope.oldLayers = [];
36 $scope.newLayers = [];
39 "/api/v1/blueprintinstance/",
42 $scope.blueprintInstanceInfos = data;
49 + blueprintInstance.blueprintInstanceId
51 + blueprintInstance["blueprint"]["blueprintName"]
53 + blueprintInstance["version"];
54 $scope.declerativeInsts
62 $scope.layerInfos = data2;
69 .indexOf(layer.layer) === -1) {
75 confirm("No layers found");
80 confirm("No blueprint instances found");
82 $scope.loadingBlueprintInstances = false;
83 $scope.loadingLayers = false;
87 $scope.selectedBlueprintInstanceChange = function() {
88 $scope.oldLayers = [];
89 $scope.newLayers = [];
90 var finalBlueprintInstanceInfo = '';
91 var id = $scope.selectedBlueprintInstance
92 .substring($scope.selectedBlueprintInstance
94 $scope.selectedBlueprintInstance
95 .indexOf("name") - 1);
98 $scope.blueprintInstanceInfos,
99 function(blueprintInstanceInfo) {
100 if (blueprintInstanceInfo.blueprintInstanceId
101 .toString().trim() === id
102 .toString().trim()) {
103 finalBlueprintInstanceInfo = blueprintInstanceInfo;
106 if (!finalBlueprintInstanceInfo) {
107 confirm("Error in blueprint instance data");
111 finalBlueprintInstanceInfo.blueprintLayers,
113 $scope.oldLayers.push(layer.layer);
117 $scope.addConfiguredLayer = function(configuredLayer) {
118 if ($scope.configuredLayers.indexOf(configuredLayer
120 $scope.configuredLayers.push(configuredLayer);
124 $scope.deleteConfiguredLayer = function(index) {
125 $scope.configuredLayers.splice(index, 1);
128 $scope.modify = function() {
129 if (!$scope.selectedBlueprintInstance
130 || !$scope.configuredLayers
131 || $scope.configuredLayers.length === 0) {
132 confirm("You must specify all the data");
135 var finalBlueprintInstanceInfo = '';
136 var id = $scope.selectedBlueprintInstance
137 .substring($scope.selectedBlueprintInstance
139 $scope.selectedBlueprintInstance
140 .indexOf("name") - 1);
143 $scope.blueprintInstanceInfos,
144 function(blueprintInstanceInfo) {
145 if (blueprintInstanceInfo.blueprintInstanceId
146 .toString().trim() === id
147 .toString().trim()) {
148 finalBlueprintInstanceInfo = blueprintInstanceInfo;
151 if (!finalBlueprintInstanceInfo) {
152 confirm("Error in blueprint instance data");
156 var blueprintLayers = [];
157 angular.forEach($scope.layerInfos, function(layerInfo) {
158 if ($scope.configuredLayers
159 .indexOf(layerInfo.layer) !== -1) {
160 blueprintLayers.push(layerInfo);
163 if (!blueprintLayers || blueprintLayers.length === 0) {
164 confirm("Error in blueprint layers data");
167 finalBlueprintInstanceInfo.blueprintLayers = blueprintLayers;
170 "/api/v1/blueprintinstance/",
171 finalBlueprintInstanceInfo,
174 var confirmText = "The blueprint instance has been modified successfully.";
175 confirm(confirmText);
177 confirm("Error when modifying the blueprint instance");