X-Git-Url: https://gerrit.akraino.org/r/gitweb?p=validation.git;a=blobdiff_plain;f=ui%2Fsrc%2Fmain%2Fwebapp%2Fapp%2FBluvalUI%2FRegisterBlueprintInstance%2FRegisterBlueprintInstanceController.js;fp=ui%2Fsrc%2Fmain%2Fwebapp%2Fapp%2FBluvalUI%2FRegisterBlueprintInstance%2FRegisterBlueprintInstanceController.js;h=e65f4db2c88f285cb3a11b12e26414b06b317711;hp=0000000000000000000000000000000000000000;hb=3ff5d7028b19a649f6b80c476ff45ced1fdd67dc;hpb=147ecf7bf79ea9967a121d0038103151a38ebef2 diff --git a/ui/src/main/webapp/app/BluvalUI/RegisterBlueprintInstance/RegisterBlueprintInstanceController.js b/ui/src/main/webapp/app/BluvalUI/RegisterBlueprintInstance/RegisterBlueprintInstanceController.js new file mode 100644 index 0000000..e65f4db --- /dev/null +++ b/ui/src/main/webapp/app/BluvalUI/RegisterBlueprintInstance/RegisterBlueprintInstanceController.js @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * + * 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. + */ + +var app = angular.module('RegisterBlueprintInstance'); +app + .controller( + 'RegisterBlueprintInstanceController', + function($scope, restAPISvc) { + + initialize(); + + function initialize() { + $scope.loadingBlueprints = true; + $scope.loadingLayers = true; + $scope.blueprints = []; + $scope.blueprintInfos = []; + $scope.layers = []; + $scope.layerInfos = []; + $scope.selectedLayer = ''; + $scope.configuredLayers = []; + restAPISvc + .getRestAPI( + "/api/v1/blueprint/", + function(data) { + if (data) { + $scope.blueprintInfos = data; + angular + .forEach( + data, + function( + blueprint) { + $scope.blueprints + .push(blueprint.blueprintName); + restAPISvc + .getRestAPI( + "/api/v1/layer/", + function( + data2) { + if (data2) { + $scope.layerInfos = data2; + angular + .forEach( + data2, + function( + layer) { + if ($scope.layers + .indexOf(layer.layer) === -1) { + $scope.layers + .push(layer.layer); + } + }); + } else { + confirm("No layers found"); + } + }); + }); + } else { + confirm("No blueprints found"); + } + $scope.loadingBlueprints = false; + $scope.loadingLayers = false; + }); + } + + $scope.addConfiguredLayer = function(configuredLayer) { + if ($scope.configuredLayers.indexOf(configuredLayer + .trim()) === -1) { + $scope.configuredLayers.push(configuredLayer); + } + } + + $scope.deleteConfiguredLayer = function(index) { + $scope.configuredLayers.splice(index, 1); + } + + $scope.register = function() { + if (!$scope.selectedBlueprint || !$scope.definedVersion + || !$scope.configuredLayers + || $scope.configuredLayers.length === 0) { + confirm("You must specify all the fields"); + return; + } + var blueprint = ''; + angular + .forEach( + $scope.blueprintInfos, + function(blueprintInfo) { + if (blueprintInfo.blueprintName + .toString().trim() === $scope.selectedBlueprint + .toString().trim()) { + blueprint = blueprintInfo; + } + }); + if (!blueprint) { + confirm("Error in blueprint data"); + return; + } + var blueprintLayers = []; + angular.forEach($scope.layerInfos, function(layerInfo) { + if ($scope.configuredLayers + .indexOf(layerInfo.layer) !== -1) { + blueprintLayers.push(layerInfo); + } + }); + if (!blueprintLayers || blueprintLayers.length === 0) { + confirm("Error in blueprint layers data"); + return; + } + var blueprintInstance = { + "blueprint" : blueprint, + "version" : $scope.definedVersion, + "blueprintLayers" : blueprintLayers + }; + restAPISvc + .postRestAPI( + "/api/v1/blueprintinstance/", + blueprintInstance, + function(data) { + if (data) { + var confirmText = "The blueprint instance has been registered successfully. Blueprint instance id:" + + data.blueprintInstanceId; + confirm(confirmText); + } else { + confirm("Error when registering the blueprint instance"); + } + initialize(); + }); + } + });