[UI] Ignore malformed results
[validation.git] / ui / src / main / webapp / app / BluvalUI / UnRegisterBlueprint / UnRegisterBlueprintController.js
1 /*
2  * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 var app = angular.module('UnRegisterBlueprint');
18 app
19         .controller(
20                 'UnRegisterBlueprintController',
21                 function($scope, restAPISvc) {
22
23                     initialize();
24
25                     function initialize() {
26                         $scope.loadingBlueprints = true;
27                         $scope.blueprintInfos = [];
28                         $scope.blueprints = [];
29                         $scope.selectedBlueprint = '';
30                         restAPISvc.getRestAPI("/api/v1/blueprint/", function(
31                                 data) {
32                             if (data) {
33                                 $scope.blueprintInfos = data;
34                                 angular.forEach(data, function(blueprint) {
35                                     $scope.blueprints
36                                             .push(blueprint.blueprintName);
37                                 });
38                             } else {
39                                 confirm("No blueprints found");
40                             }
41                             $scope.loadingBlueprints = false;
42                         });
43                     }
44
45                     $scope.unRegister = function() {
46                         if (!$scope.selectedBlueprint) {
47                             confirm("You must select a blueprint");
48                             return;
49                         }
50                         var finalBlueprintInfo = '';
51                         angular
52                                 .forEach(
53                                         $scope.blueprintInfos,
54                                         function(blueprintInfo) {
55                                             if ($scope.selectedBlueprint.trim() === blueprintInfo.blueprintName
56                                                     .trim()) {
57                                                 finalBlueprintInfo = blueprintInfo;
58                                             }
59                                         });
60                         if (!finalBlueprintInfo) {
61                             return;
62                         }
63                         restAPISvc
64                                 .deleteRestAPI(
65                                         "/api/v1/blueprint/",
66                                         finalBlueprintInfo,
67                                         function(data) {
68                                             if (data) {
69                                                 var confirmText = "The blueprint has been unregistered successfully."
70                                                 confirm(confirmText);
71                                             } else {
72                                                 confirm("Error when unregistering the blueprint");
73                                             }
74                                             initialize();
75                                         });
76                     }
77                 });