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 $scope.url = COMPONENT.SERVICE_POPUP_IFRAME_URL + request.modelNameVersionId + "&isCreate=true&r=" + Math.random();
97 window.addEventListener("message", receiveMessage, false);
101 callbackFunction = request.callbackFunction;
102 componentId = request.componentId;
103 CreationService.initializeComponent(request.componentId);
105 CreationService.setHttpErrorHandler(function (response) {
106 $scope.isServiceError = true;
107 showError(FIELD.ERROR.SYSTEM_FAILURE, UtilityService
108 .getHttpErrorMessage(response));
111 $scope.componentName = CreationService.getComponentDisplayName();
113 CreationService.getParameters(handleGetParametersResponse);
118 var handleGetParametersResponse = function (parameters) {
119 $scope.summaryControl.setList(parameters.summaryList);
120 $scope.userProvidedControl.setList(parameters.userProvidedList);
122 $scope.isSpinnerVisible = false;
123 $scope.isDataVisible = true;
124 $scope.isConfirmEnabled = true;
127 var validateInstanceName = function (iname) {
128 var patt1 = /^([a-z])+([0-9a-z\-_\.]*)$/i;
133 if (!iname.match(patt1)) {
138 var validateMap = function (mname) {
139 var patt1 = /^{(\s*\w+\s*:\s*\w+\s*)(\s*,\s*\w+\s*:\s*\w+\s*)*}$/im;
143 if (!mname.match(patt1)) {
149 var validateList = function (lname) {
150 var patt1 = /^\[(\s*\w+\s*)(\s*,\s*\w+\s*)*\]$/i;
154 if (!lname.match(patt1)) {
160 $scope.userParameterChanged = function (id) {
161 CreationService.updateUserParameterList(id, $scope.userProvidedControl);
164 $scope.confirm = function () {
166 var requiredFields = $scope.userProvidedControl.getRequiredFields();
167 if (requiredFields !== "") {
168 showError(FIELD.ERROR.MISSING_DATA, requiredFields);
172 var isUploadAvailable = false;
174 var paramList = $scope.userProvidedControl.getList();
175 var isAnyError = false;
176 for (var i = 0; i < paramList.length; i++) {
177 if (paramList[i].id === FIELD.ID.SUPPLEMENTORY_DATA_FILE) {
178 isUploadAvailable = true;
181 if (paramList[i].id === FIELD.ID.UPLOAD_SUPPLEMENTORY_DATA_FILE && paramList[i].value && document.getElementById(FIELD.ID.SUPPLEMENTORY_DATA_FILE).value == '') {
186 if (isUploadAvailable && isAnyError) {
187 showError(FIELD.ERROR.MISSING_DATA, FIELD.ERROR.MISSING_FILE);
189 } else if (isUploadAvailable && document.getElementById(FIELD.ID.SUPPLEMENTORY_DATA_FILE).value != '') {
191 var fileInput = document.getElementById(FIELD.ID.SUPPLEMENTORY_DATA_FILE);
192 var file = fileInput.files[0];
193 var reader = new FileReader();
194 reader.onload = function (e) {
196 paramList[uploadIndex].value = JSON.parse(reader.result);
197 FIELD.PARAMETER.SUPPLEMENTORY_DATA_FILE['value'] = paramList[uploadIndex].value;
199 var instanceName = "";
201 if (DataService.getALaCarte()) {
202 if (paramList != null) {
203 for (var i = 0; i < paramList.length; i++) {
204 if (paramList[i].id === FIELD.ID.INSTANCE_NAME) {
205 instanceName = paramList[i].value;
210 var isValid = validateInstanceName(instanceName);
212 $scope.isErrorVisible = false;
214 showError(FIELD.ERROR.INVALID_INSTANCE_NAME + instanceName,
215 FIELD.ERROR.INSTANCE_NAME_VALIDATE);
219 var arbitraryParametersList = DataService.getArbitraryParameters();
221 if (UtilityService.hasContents(arbitraryParametersList)) {
222 for (var i = 0; i < arbitraryParametersList.length; i++) {
223 p = arbitraryParametersList[i];
224 if (p.type === PARAMETER.MAP) {
225 //validate a map: { <entry_key_1>: <entry_value_1>, ... , <entry_key_n>: <entry_value_n> }
226 // need to find the value in paramList
227 for (var j = 0; j < paramList.length; j++) {
228 if (paramList[j].id === p.id) {
229 p.value = paramList[j].value;
230 var isValid = validateMap(p.value);
232 $scope.isErrorVisible = false;
236 showError(FIELD.ERROR.INVALID_MAP + p.id,
237 FIELD.ERROR.MAP_VALIDATE);
242 } else if (p.type === PARAMETER.LIST) {
243 //validate a list: { value or a list of comma separated values }
244 // need to find the value in paramList
245 for (var j = 0; j < paramList.length; j++) {
246 if (paramList[j].id === p.id) {
247 p.value = paramList[j].value;
248 var isValid = validateList(p.value);
250 $scope.isErrorVisible = false;
254 showError(FIELD.ERROR.INVALID_LIST + p.id,
255 FIELD.ERROR.LIST_VALIDATE);
263 var requestDetails = CreationService
264 .getMsoRequestDetails($scope.userProvidedControl.getList());
266 $scope.isDialogVisible = false;
268 $scope.$broadcast(COMPONENT.MSO_CREATE_REQ, {
269 url: CreationService.getMsoUrl(),
270 requestDetails: requestDetails,
271 componentId: componentId,
272 callbackFunction: function (response) {
273 if (response.isSuccessful) {
274 $scope.popup.isVisible = false;
275 runCallback(response);
277 $scope.isDialogVisible = false;
278 $scope.popup.isVisible = false;
284 errorMsg = errorMsg + FIELD.ERROR.INVALID_DATA_FORMAT;
286 if (errorMsg !== "") {
287 showError(FIELD.ERROR.SYSTEM_FAILURE, errorMsg);
291 reader.readAsText(file);
294 var paramList = $scope.userProvidedControl.getList();
295 var instanceName = "";
297 if (DataService.getALaCarte()) {
298 if (paramList != null) {
299 for (var i = 0; i < paramList.length; i++) {
300 if (paramList[i].id === FIELD.ID.INSTANCE_NAME) {
301 instanceName = paramList[i].value;
306 var isValid = validateInstanceName(instanceName);
308 $scope.isErrorVisible = false;
310 showError(FIELD.ERROR.INVALID_INSTANCE_NAME + instanceName,
311 FIELD.ERROR.INSTANCE_NAME_VALIDATE);
315 var arbitraryParametersList = DataService.getArbitraryParameters();
317 if (UtilityService.hasContents(arbitraryParametersList)) {
318 for (var i = 0; i < arbitraryParametersList.length; i++) {
319 p = arbitraryParametersList[i];
320 if (p.type === PARAMETER.MAP) {
321 //validate a map: { <entry_key_1>: <entry_value_1>, ... , <entry_key_n>: <entry_value_n> }
322 // need to find the value in paramList
323 for (var j = 0; j < paramList.length; j++) {
324 if (paramList[j].id === p.id) {
325 p.value = paramList[j].value;
326 var isValid = validateMap(p.value);
328 $scope.isErrorVisible = false;
332 showError(FIELD.ERROR.INVALID_MAP + p.id,
333 FIELD.ERROR.MAP_VALIDATE);
338 } else if (p.type === PARAMETER.LIST) {
339 //validate a list: { value or a list of comma separated values }
340 // need to find the value in paramList
341 for (var j = 0; j < paramList.length; j++) {
342 if (paramList[j].id === p.id) {
343 p.value = paramList[j].value;
344 var isValid = validateList(p.value);
346 $scope.isErrorVisible = false;
350 showError(FIELD.ERROR.INVALID_LIST + p.id,
351 FIELD.ERROR.LIST_VALIDATE);
359 var requestDetails = CreationService
360 .getMsoRequestDetails($scope.userProvidedControl.getList());
362 $scope.isDialogVisible = false;
364 $scope.$broadcast(COMPONENT.MSO_CREATE_REQ, {
365 url: CreationService.getMsoUrl(),
366 requestDetails: requestDetails,
367 componentId: componentId,
368 callbackFunction: function (response) {
369 if (response.isSuccessful) {
370 $scope.popup.isVisible = false;
371 runCallback(response);
373 $scope.isDialogVisible = false;
374 $scope.popup.isVisible = false;
381 $scope.cancel = function () {
382 $scope.isDialogVisible = false;
383 $scope.popup.isVisible = false;
388 var runCallback = function (response) {
389 if (angular.isFunction(callbackFunction)) {
391 isSuccessful: response.isSuccessful,
392 control: $scope.userProvidedControl.getList(),
393 instanceId: response.instanceId
398 var showError = function (summary, details) {
399 var message = summary;
400 if (UtilityService.hasContents(details)) {
401 message += " (" + details + ")";
403 $scope.isSpinnerVisible = false;
404 $scope.isErrorVisible = true;
405 $scope.error = message;
410 appDS2.controller("creationDialogController", ["COMPONENT", "FIELD", "PARAMETER", "$scope", "$http",
411 "$timeout", "$log", "CreationService", "UtilityService", "DataService", "VIDCONFIGURATION", "$location",
412 "$uibModal", "featureFlags",
413 creationDialogController]);