2 * ============LICENSE_START=======================================================
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
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=========================================================
23 var creationDialogController = function (COMPONENT, FIELD, PARAMETER, $scope, $http, $timeout, $log,
24 CreationService, UtilityService, DataService, VIDCONFIGURATION, $location, $uibModal, featureFlags) {
26 $scope.isDialogVisible = false;
27 $scope.isServiceError = false;
28 $scope.summaryControl = {};
29 $scope.userProvidedControl = {};
32 var callbackFunction = undefined;
33 var componentId = undefined;
35 $scope.showReportWindow = function() {
39 if($scope.error !== undefined && $scope.error != null) {
40 errorMsg = $scope.error;
45 const modalWindow = $uibModal.open({
46 templateUrl: 'app/vid/scripts/modals/report-modal/report-modal.html',
47 controller: 'reportModalController',
50 errorMsg: function () {
56 $scope.isDialogVisible = false;
57 $scope.popup.isVisible = false;
60 $scope.isShowErrorReport = function() {
61 return featureFlags.isOn(COMPONENT.FEATURE_FLAGS.FLAG_CREATE_ERROR_REPORTS);
64 $scope.shouldShowOldPopup = function () {
65 return !DataService.getShouldIncludeInAsyncInstantiationFlow();
68 function receiveMessage(event) {
69 if (event.data == 'closeIframe') {
70 window.removeEventListener("message", receiveMessage, false);
74 else if (event.data.eventId == 'submitIframe') {
76 $location.path('/servicePlanning').search({serviceModelId: event.data.data.serviceModelId});
78 } else if (event.data.eventId == 'showPreviousInstantiations') {
80 $location.path('/instantiationStatus').search({filterText: event.data.data.serviceModelId});
86 $scope.$on(COMPONENT.CREATE_COMPONENT, function (event, request) {
87 $scope.isSpinnerVisible = true;
88 $scope.isErrorVisible = false;
89 $scope.isDataVisible = false;
90 $scope.isConfirmEnabled = false;
91 $scope.isDialogVisible = true;
92 $scope.popup.isVisible = true;
95 if (!$scope.shouldShowOldPopup()) {
96 let modelNameVersionId = request.modelNameVersionId ?
97 request.modelNameVersionId :
98 (DataService.getModelInfo(COMPONENT.SERVICE) ? DataService.getModelInfo(COMPONENT.SERVICE).modelNameVersionId : "");
99 if(DataService.getIsInstantiationTemplateExists()){
100 $scope.url = COMPONENT.INSTANTIATION_TEMPLATES_IFRAME_URL + modelNameVersionId;
101 window.addEventListener("message", receiveMessage, false);
103 $scope.url = COMPONENT.SERVICE_POPUP_IFRAME_URL + modelNameVersionId + "&isCreate=true&r=" + Math.random();
104 window.addEventListener("message", receiveMessage, false);
108 callbackFunction = request.callbackFunction;
109 componentId = request.componentId;
110 CreationService.initializeComponent(request.componentId);
112 CreationService.setHttpErrorHandler(function (response) {
113 $scope.isServiceError = true;
114 showError(FIELD.ERROR.SYSTEM_FAILURE, UtilityService
115 .getHttpErrorMessage(response));
118 $scope.componentName = CreationService.getComponentDisplayName();
120 CreationService.getParameters(handleGetParametersResponse);
125 var handleGetParametersResponse = function (parameters) {
126 $scope.summaryControl.setList(parameters.summaryList);
127 $scope.userProvidedControl.setList(parameters.userProvidedList);
129 $scope.isSpinnerVisible = false;
130 $scope.isDataVisible = true;
131 $scope.isConfirmEnabled = true;
134 var validateInstanceName = function (iname) {
135 var patt1 = /^([a-z])+([0-9a-z\-_\.]*)$/i;
140 if (!iname.match(patt1)) {
145 var validateMap = function (mname) {
146 var patt1 = /^{(\s*\w+\s*:\s*\w+\s*)(\s*,\s*\w+\s*:\s*\w+\s*)*}$/im;
150 if (!mname.match(patt1)) {
156 var validateList = function (lname) {
157 var patt1 = /^\[(\s*\w+\s*)(\s*,\s*\w+\s*)*\]$/i;
161 if (!lname.match(patt1)) {
167 $scope.userParameterChanged = function (id) {
168 CreationService.updateUserParameterList(id, $scope.userProvidedControl);
171 $scope.confirm = function () {
173 var requiredFields = $scope.userProvidedControl.getRequiredFields();
174 if (requiredFields !== "") {
175 showError(FIELD.ERROR.MISSING_DATA, requiredFields);
179 var isUploadAvailable = false;
181 var paramList = $scope.userProvidedControl.getList();
182 var isAnyError = false;
183 for (var i = 0; i < paramList.length; i++) {
184 if (paramList[i].id === FIELD.ID.SUPPLEMENTORY_DATA_FILE) {
185 isUploadAvailable = true;
188 if (paramList[i].id === FIELD.ID.UPLOAD_SUPPLEMENTORY_DATA_FILE && paramList[i].value && document.getElementById(FIELD.ID.SUPPLEMENTORY_DATA_FILE).value == '') {
193 if (isUploadAvailable && isAnyError) {
194 showError(FIELD.ERROR.MISSING_DATA, FIELD.ERROR.MISSING_FILE);
196 } else if (isUploadAvailable && document.getElementById(FIELD.ID.SUPPLEMENTORY_DATA_FILE).value != '') {
198 var fileInput = document.getElementById(FIELD.ID.SUPPLEMENTORY_DATA_FILE);
199 var file = fileInput.files[0];
200 var reader = new FileReader();
201 reader.onload = function (e) {
203 paramList[uploadIndex].value = JSON.parse(reader.result);
204 FIELD.PARAMETER.SUPPLEMENTORY_DATA_FILE['value'] = paramList[uploadIndex].value;
206 var instanceName = "";
208 if (DataService.getALaCarte()) {
209 if (paramList != null) {
210 for (var i = 0; i < paramList.length; i++) {
211 if (paramList[i].id === FIELD.ID.INSTANCE_NAME) {
212 instanceName = paramList[i].value;
217 var isValid = validateInstanceName(instanceName);
219 $scope.isErrorVisible = false;
221 showError(FIELD.ERROR.INVALID_INSTANCE_NAME + instanceName,
222 FIELD.ERROR.INSTANCE_NAME_VALIDATE);
226 var arbitraryParametersList = DataService.getArbitraryParameters();
228 if (UtilityService.hasContents(arbitraryParametersList)) {
229 for (var i = 0; i < arbitraryParametersList.length; i++) {
230 p = arbitraryParametersList[i];
231 if (p.type === PARAMETER.MAP) {
232 //validate a map: { <entry_key_1>: <entry_value_1>, ... , <entry_key_n>: <entry_value_n> }
233 // need to find the value in paramList
234 for (var j = 0; j < paramList.length; j++) {
235 if (paramList[j].id === p.id) {
236 p.value = paramList[j].value;
237 var isValid = validateMap(p.value);
239 $scope.isErrorVisible = false;
243 showError(FIELD.ERROR.INVALID_MAP + p.id,
244 FIELD.ERROR.MAP_VALIDATE);
249 } else if (p.type === PARAMETER.LIST) {
250 //validate a list: { value or a list of comma separated values }
251 // need to find the value in paramList
252 for (var j = 0; j < paramList.length; j++) {
253 if (paramList[j].id === p.id) {
254 p.value = paramList[j].value;
255 var isValid = validateList(p.value);
257 $scope.isErrorVisible = false;
261 showError(FIELD.ERROR.INVALID_LIST + p.id,
262 FIELD.ERROR.LIST_VALIDATE);
270 var requestDetails = CreationService
271 .getMsoRequestDetails($scope.userProvidedControl.getList());
273 $scope.isDialogVisible = false;
275 $scope.$broadcast(COMPONENT.MSO_CREATE_REQ, {
276 url: CreationService.getMsoUrl(),
277 requestDetails: requestDetails,
278 componentId: componentId,
279 callbackFunction: function (response) {
280 if (response.isSuccessful) {
281 $scope.popup.isVisible = false;
282 runCallback(response);
284 $scope.isDialogVisible = false;
285 $scope.popup.isVisible = false;
291 errorMsg = errorMsg + FIELD.ERROR.INVALID_DATA_FORMAT;
293 if (errorMsg !== "") {
294 showError(FIELD.ERROR.SYSTEM_FAILURE, errorMsg);
298 reader.readAsText(file);
301 var paramList = $scope.userProvidedControl.getList();
302 var instanceName = "";
304 if (DataService.getALaCarte()) {
305 if (paramList != null) {
306 for (var i = 0; i < paramList.length; i++) {
307 if (paramList[i].id === FIELD.ID.INSTANCE_NAME) {
308 instanceName = paramList[i].value;
313 var isValid = validateInstanceName(instanceName);
315 $scope.isErrorVisible = false;
317 showError(FIELD.ERROR.INVALID_INSTANCE_NAME + instanceName,
318 FIELD.ERROR.INSTANCE_NAME_VALIDATE);
322 var arbitraryParametersList = DataService.getArbitraryParameters();
324 if (UtilityService.hasContents(arbitraryParametersList)) {
325 for (var i = 0; i < arbitraryParametersList.length; i++) {
326 p = arbitraryParametersList[i];
327 if (p.type === PARAMETER.MAP) {
328 //validate a map: { <entry_key_1>: <entry_value_1>, ... , <entry_key_n>: <entry_value_n> }
329 // need to find the value in paramList
330 for (var j = 0; j < paramList.length; j++) {
331 if (paramList[j].id === p.id) {
332 p.value = paramList[j].value;
333 var isValid = validateMap(p.value);
335 $scope.isErrorVisible = false;
339 showError(FIELD.ERROR.INVALID_MAP + p.id,
340 FIELD.ERROR.MAP_VALIDATE);
345 } else if (p.type === PARAMETER.LIST) {
346 //validate a list: { value or a list of comma separated values }
347 // need to find the value in paramList
348 for (var j = 0; j < paramList.length; j++) {
349 if (paramList[j].id === p.id) {
350 p.value = paramList[j].value;
351 var isValid = validateList(p.value);
353 $scope.isErrorVisible = false;
357 showError(FIELD.ERROR.INVALID_LIST + p.id,
358 FIELD.ERROR.LIST_VALIDATE);
366 var requestDetails = CreationService
367 .getMsoRequestDetails($scope.userProvidedControl.getList());
369 $scope.isDialogVisible = false;
371 $scope.$broadcast(COMPONENT.MSO_CREATE_REQ, {
372 url: CreationService.getMsoUrl(),
373 requestDetails: requestDetails,
374 componentId: componentId,
375 callbackFunction: function (response) {
376 if (response.isSuccessful) {
377 $scope.popup.isVisible = false;
378 runCallback(response);
380 $scope.isDialogVisible = false;
381 $scope.popup.isVisible = false;
382 runCallback(response);
389 $scope.cancel = function () {
390 $scope.isDialogVisible = false;
391 $scope.popup.isVisible = false;
396 var runCallback = function (response) {
397 if (angular.isFunction(callbackFunction)) {
399 isSuccessful: response.isSuccessful,
400 control: $scope.userProvidedControl.getList(),
401 instanceId: response.instanceId
406 var showError = function (summary, details) {
407 var message = summary;
408 if (UtilityService.hasContents(details)) {
409 message += " (" + details + ")";
411 $scope.isSpinnerVisible = false;
412 $scope.isErrorVisible = true;
413 $scope.error = message;
418 appDS2.controller("creationDialogController", ["COMPONENT", "FIELD", "PARAMETER", "$scope", "$http",
419 "$timeout", "$log", "CreationService", "UtilityService", "DataService", "VIDCONFIGURATION", "$location",
420 "$uibModal", "featureFlags",
421 creationDialogController]);