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});
82 $scope.$on(COMPONENT.CREATE_COMPONENT, function (event, request) {
83 $scope.isSpinnerVisible = true;
84 $scope.isErrorVisible = false;
85 $scope.isDataVisible = false;
86 $scope.isConfirmEnabled = false;
87 $scope.isDialogVisible = true;
88 $scope.popup.isVisible = true;
91 if (!$scope.shouldShowOldPopup()) {
92 let modelNameVersionId = request.modelNameVersionId ?
93 request.modelNameVersionId :
94 (DataService.getModelInfo(COMPONENT.SERVICE) ? DataService.getModelInfo(COMPONENT.SERVICE).modelNameVersionId : "");
95 if(DataService.getIsInstantiationTemplateExists()){
96 $scope.url = COMPONENT.INSTANTIATION_TEMPLATES_IFRAME_URL + modelNameVersionId;
97 window.addEventListener("message", receiveMessage, false);
99 $scope.url = COMPONENT.SERVICE_POPUP_IFRAME_URL + modelNameVersionId + "&isCreate=true&r=" + Math.random();
100 window.addEventListener("message", receiveMessage, false);
104 callbackFunction = request.callbackFunction;
105 componentId = request.componentId;
106 CreationService.initializeComponent(request.componentId);
108 CreationService.setHttpErrorHandler(function (response) {
109 $scope.isServiceError = true;
110 showError(FIELD.ERROR.SYSTEM_FAILURE, UtilityService
111 .getHttpErrorMessage(response));
114 $scope.componentName = CreationService.getComponentDisplayName();
116 CreationService.getParameters(handleGetParametersResponse);
121 var handleGetParametersResponse = function (parameters) {
122 $scope.summaryControl.setList(parameters.summaryList);
123 $scope.userProvidedControl.setList(parameters.userProvidedList);
125 $scope.isSpinnerVisible = false;
126 $scope.isDataVisible = true;
127 $scope.isConfirmEnabled = true;
130 var validateInstanceName = function (iname) {
131 var patt1 = /^([a-z])+([0-9a-z\-_\.]*)$/i;
136 if (!iname.match(patt1)) {
141 var validateMap = function (mname) {
142 var patt1 = /^{(\s*\w+\s*:\s*\w+\s*)(\s*,\s*\w+\s*:\s*\w+\s*)*}$/im;
146 if (!mname.match(patt1)) {
152 var validateList = function (lname) {
153 var patt1 = /^\[(\s*\w+\s*)(\s*,\s*\w+\s*)*\]$/i;
157 if (!lname.match(patt1)) {
163 $scope.userParameterChanged = function (id) {
164 CreationService.updateUserParameterList(id, $scope.userProvidedControl);
167 $scope.confirm = function () {
169 var requiredFields = $scope.userProvidedControl.getRequiredFields();
170 if (requiredFields !== "") {
171 showError(FIELD.ERROR.MISSING_DATA, requiredFields);
175 var isUploadAvailable = false;
177 var paramList = $scope.userProvidedControl.getList();
178 var isAnyError = false;
179 for (var i = 0; i < paramList.length; i++) {
180 if (paramList[i].id === FIELD.ID.SUPPLEMENTORY_DATA_FILE) {
181 isUploadAvailable = true;
184 if (paramList[i].id === FIELD.ID.UPLOAD_SUPPLEMENTORY_DATA_FILE && paramList[i].value && document.getElementById(FIELD.ID.SUPPLEMENTORY_DATA_FILE).value == '') {
189 if (isUploadAvailable && isAnyError) {
190 showError(FIELD.ERROR.MISSING_DATA, FIELD.ERROR.MISSING_FILE);
192 } else if (isUploadAvailable && document.getElementById(FIELD.ID.SUPPLEMENTORY_DATA_FILE).value != '') {
194 var fileInput = document.getElementById(FIELD.ID.SUPPLEMENTORY_DATA_FILE);
195 var file = fileInput.files[0];
196 var reader = new FileReader();
197 reader.onload = function (e) {
199 paramList[uploadIndex].value = JSON.parse(reader.result);
200 FIELD.PARAMETER.SUPPLEMENTORY_DATA_FILE['value'] = paramList[uploadIndex].value;
202 var instanceName = "";
204 if (DataService.getALaCarte()) {
205 if (paramList != null) {
206 for (var i = 0; i < paramList.length; i++) {
207 if (paramList[i].id === FIELD.ID.INSTANCE_NAME) {
208 instanceName = paramList[i].value;
213 var isValid = validateInstanceName(instanceName);
215 $scope.isErrorVisible = false;
217 showError(FIELD.ERROR.INVALID_INSTANCE_NAME + instanceName,
218 FIELD.ERROR.INSTANCE_NAME_VALIDATE);
222 var arbitraryParametersList = DataService.getArbitraryParameters();
224 if (UtilityService.hasContents(arbitraryParametersList)) {
225 for (var i = 0; i < arbitraryParametersList.length; i++) {
226 p = arbitraryParametersList[i];
227 if (p.type === PARAMETER.MAP) {
228 //validate a map: { <entry_key_1>: <entry_value_1>, ... , <entry_key_n>: <entry_value_n> }
229 // need to find the value in paramList
230 for (var j = 0; j < paramList.length; j++) {
231 if (paramList[j].id === p.id) {
232 p.value = paramList[j].value;
233 var isValid = validateMap(p.value);
235 $scope.isErrorVisible = false;
239 showError(FIELD.ERROR.INVALID_MAP + p.id,
240 FIELD.ERROR.MAP_VALIDATE);
245 } else if (p.type === PARAMETER.LIST) {
246 //validate a list: { value or a list of comma separated values }
247 // need to find the value in paramList
248 for (var j = 0; j < paramList.length; j++) {
249 if (paramList[j].id === p.id) {
250 p.value = paramList[j].value;
251 var isValid = validateList(p.value);
253 $scope.isErrorVisible = false;
257 showError(FIELD.ERROR.INVALID_LIST + p.id,
258 FIELD.ERROR.LIST_VALIDATE);
266 var requestDetails = CreationService
267 .getMsoRequestDetails($scope.userProvidedControl.getList());
269 $scope.isDialogVisible = false;
271 $scope.$broadcast(COMPONENT.MSO_CREATE_REQ, {
272 url: CreationService.getMsoUrl(),
273 requestDetails: requestDetails,
274 componentId: componentId,
275 callbackFunction: function (response) {
276 if (response.isSuccessful) {
277 $scope.popup.isVisible = false;
278 runCallback(response);
280 $scope.isDialogVisible = false;
281 $scope.popup.isVisible = false;
287 errorMsg = errorMsg + FIELD.ERROR.INVALID_DATA_FORMAT;
289 if (errorMsg !== "") {
290 showError(FIELD.ERROR.SYSTEM_FAILURE, errorMsg);
294 reader.readAsText(file);
297 var paramList = $scope.userProvidedControl.getList();
298 var instanceName = "";
300 if (DataService.getALaCarte()) {
301 if (paramList != null) {
302 for (var i = 0; i < paramList.length; i++) {
303 if (paramList[i].id === FIELD.ID.INSTANCE_NAME) {
304 instanceName = paramList[i].value;
309 var isValid = validateInstanceName(instanceName);
311 $scope.isErrorVisible = false;
313 showError(FIELD.ERROR.INVALID_INSTANCE_NAME + instanceName,
314 FIELD.ERROR.INSTANCE_NAME_VALIDATE);
318 var arbitraryParametersList = DataService.getArbitraryParameters();
320 if (UtilityService.hasContents(arbitraryParametersList)) {
321 for (var i = 0; i < arbitraryParametersList.length; i++) {
322 p = arbitraryParametersList[i];
323 if (p.type === PARAMETER.MAP) {
324 //validate a map: { <entry_key_1>: <entry_value_1>, ... , <entry_key_n>: <entry_value_n> }
325 // need to find the value in paramList
326 for (var j = 0; j < paramList.length; j++) {
327 if (paramList[j].id === p.id) {
328 p.value = paramList[j].value;
329 var isValid = validateMap(p.value);
331 $scope.isErrorVisible = false;
335 showError(FIELD.ERROR.INVALID_MAP + p.id,
336 FIELD.ERROR.MAP_VALIDATE);
341 } else if (p.type === PARAMETER.LIST) {
342 //validate a list: { value or a list of comma separated values }
343 // need to find the value in paramList
344 for (var j = 0; j < paramList.length; j++) {
345 if (paramList[j].id === p.id) {
346 p.value = paramList[j].value;
347 var isValid = validateList(p.value);
349 $scope.isErrorVisible = false;
353 showError(FIELD.ERROR.INVALID_LIST + p.id,
354 FIELD.ERROR.LIST_VALIDATE);
362 var requestDetails = CreationService
363 .getMsoRequestDetails($scope.userProvidedControl.getList());
365 $scope.isDialogVisible = false;
367 $scope.$broadcast(COMPONENT.MSO_CREATE_REQ, {
368 url: CreationService.getMsoUrl(),
369 requestDetails: requestDetails,
370 componentId: componentId,
371 callbackFunction: function (response) {
372 if (response.isSuccessful) {
373 $scope.popup.isVisible = false;
374 runCallback(response);
376 $scope.isDialogVisible = false;
377 $scope.popup.isVisible = false;
378 runCallback(response);
385 $scope.cancel = function () {
386 $scope.isDialogVisible = false;
387 $scope.popup.isVisible = false;
392 var runCallback = function (response) {
393 if (angular.isFunction(callbackFunction)) {
395 isSuccessful: response.isSuccessful,
396 control: $scope.userProvidedControl.getList(),
397 instanceId: response.instanceId
402 var showError = function (summary, details) {
403 var message = summary;
404 if (UtilityService.hasContents(details)) {
405 message += " (" + details + ")";
407 $scope.isSpinnerVisible = false;
408 $scope.isErrorVisible = true;
409 $scope.error = message;
414 appDS2.controller("creationDialogController", ["COMPONENT", "FIELD", "PARAMETER", "$scope", "$http",
415 "$timeout", "$log", "CreationService", "UtilityService", "DataService", "VIDCONFIGURATION", "$location",
416 "$uibModal", "featureFlags",
417 creationDialogController]);