Semicolon at the end of the Statement and Remove trailing whitespaces at the end...
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / controller / pnfSearchAssociationController.js
1 /*-
2 * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
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
10  * 
11  *       http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19 */
20
21 /**
22  * The Instantiation (or View/Edit) Controller controls the instantiation/removal of
23  * deployable objects (Services, VNFs, VF-Modules, Networks, and Volume-Groups)
24  */
25
26 "use strict";
27
28 appDS2.controller("pnfSearchAssociationController", ["COMPONENT", "$log", "FIELD", "PARAMETER", "DataService", "CreationService", "$scope", "$window", "$location", "AaiService", "$uibModal", "UtilityService", "vidService", "$timeout",
29     function (COMPONENT, $log, FIELD, PARAMETER, DataService, CreationService, $scope, $window, $location, AaiService, $uibModal, UtilityService, vidService, $timeout) {
30
31         var requestParams = {};
32
33         $scope.selectedMetadata = {};
34
35         $scope.serviceMetadataFields = [];
36         $scope.nodeTemplateFields = {};
37
38         $scope.pnfInstance= false;
39         $scope.notFound= false;
40
41         $scope.pnfMetadata = [];
42
43         $scope.errorMsg = FIELD.ERROR.INSTANCE_NAME_VALIDATE;
44
45         $scope.modelName = DataService.getModelInfo(COMPONENT.VNF).modelCustomizationName;
46
47         var handleGetParametersResponse = function(parameters) {
48             $scope.serviceMetadataFields = parameters.summaryList;
49             $scope.serviceMetadataFields.forEach(function (t, number) {
50                 $scope.serviceMetadataFields[number].key = $scope.serviceMetadataFields[number].name.split(' ').join('');
51             });
52             $scope.nodeTemplateFields = _.keyBy(parameters.userProvidedList, 'id');
53         };
54
55         CreationService.initializeComponent(COMPONENT.VNF);
56
57         CreationService.getParameters(handleGetParametersResponse);
58
59         $scope.back = function()  {
60             $window.history.back();
61         };
62
63         $scope.searchPnf = function(pnfName) {
64             $scope.pnfInstance= false;
65             $scope.notFound=false;
66
67             AaiService.getPnfByName(pnfName)
68                 .then(function (response) {
69                     $scope.pnfInstance = response.data;
70                     requestParams.pnf = response.data.pnfName;
71                 })
72                 .catch(function (error) {
73                     $scope.pnfNameNotFound= pnfName;
74                    $scope.notFound= true;
75                 });
76
77         };
78         var modalInstance;
79
80         $scope.associate = function()  {
81
82             requestParams.serviceModelInfo = vidService.getModel().service;
83             requestParams.attuuid = DataService.getLoggedInUserId();
84             requestParams.instanceId = DataService.getServiceInstanceId();
85
86             modalInstance = $uibModal.open({
87                 templateUrl: 'app/vid/scripts/modals/mso-commit/mso-commit.html',
88                 controller: "msoCommitModalController",
89                 backdrop: false,
90                 resolve: {
91                     msoType: function () {
92                         return COMPONENT.MSO_CREATE_REALATIONSHIP;
93                     },
94                     requestParams: function () {
95                         requestParams.callbackFunction = updateViewCallbackFunction;
96                         return requestParams;
97                     },
98                     configuration: function () {
99                         return null;
100                     }
101                 }
102             });
103         };
104
105         var updateViewCallbackFunction = function(response) {
106             $scope.callbackResults = "";
107             var color = FIELD.ID.COLOR_NONE;
108             $scope.callbackStyle = {
109                 "background-color" : color
110             };
111
112             /*
113              * This 1/2 delay was only added to visually highlight the status
114              * change. Probably not needed in the real application code.
115              */
116             $timeout(function() {
117                 $scope.callbackResults = UtilityService.getCurrentTime()
118                     + FIELD.STATUS.IS_SUCCESSFUL + response.isSuccessful;
119                 if (response.isSuccessful) {
120                     color = FIELD.ID.COLOR_8F8;
121                     $scope.back();
122                 } else {
123                     color = FIELD.ID.COLOR_F88;
124                 }
125                 $scope.callbackStyle = {
126                     "background-color" : color
127                 };
128             }, 500);
129         };
130
131
132         $scope.cancel = function()  {
133             modalInstance.dismiss('cancel');
134         };
135
136
137     }]);
138
139