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 if(DataService.getIsInstantiationTemplateExists()){
97 $scope.url = COMPONENT.INSTANTIATION_TEMPLATES_IFRAME_URL + request.modelNameVersionId;
98 window.addEventListener("message", receiveMessage, false);
100 $scope.url = COMPONENT.SERVICE_POPUP_IFRAME_URL + request.modelNameVersionId + "&isCreate=true&r=" + Math.random();
101 window.addEventListener("message", receiveMessage, false);
105 callbackFunction = request.callbackFunction;
106 componentId = request.componentId;
107 CreationService.initializeComponent(request.componentId);
109 CreationService.setHttpErrorHandler(function (response) {
110 $scope.isServiceError = true;
111 showError(FIELD.ERROR.SYSTEM_FAILURE, UtilityService
112 .getHttpErrorMessage(response));
115 $scope.componentName = CreationService.getComponentDisplayName();
117 CreationService.getParameters(handleGetParametersResponse);
122 var handleGetParametersResponse = function (parameters) {
123 $scope.summaryControl.setList(parameters.summaryList);
124 $scope.userProvidedControl.setList(parameters.userProvidedList);
126 $scope.isSpinnerVisible = false;
127 $scope.isDataVisible = true;
128 $scope.isConfirmEnabled = true;
131 var validateInstanceName = function (iname) {
132 var patt1 = /^([a-z])+([0-9a-z\-_\.]*)$/i;
137 if (!iname.match(patt1)) {
142 var validateMap = function (mname) {
143 var patt1 = /^{(\s*\w+\s*:\s*\w+\s*)(\s*,\s*\w+\s*:\s*\w+\s*)*}$/im;
147 if (!mname.match(patt1)) {
153 var validateList = function (lname) {
154 var patt1 = /^\[(\s*\w+\s*)(\s*,\s*\w+\s*)*\]$/i;
158 if (!lname.match(patt1)) {
164 $scope.userParameterChanged = function (id) {
165 CreationService.updateUserParameterList(id, $scope.userProvidedControl);
168 $scope.confirm = function () {
170 var requiredFields = $scope.userProvidedControl.getRequiredFields();
171 if (requiredFields !== "") {
172 showError(FIELD.ERROR.MISSING_DATA, requiredFields);
176 var isUploadAvailable = false;
178 var paramList = $scope.userProvidedControl.getList();
179 var isAnyError = false;
180 for (var i = 0; i < paramList.length; i++) {
181 if (paramList[i].id === FIELD.ID.SUPPLEMENTORY_DATA_FILE) {
182 isUploadAvailable = true;
185 if (paramList[i].id === FIELD.ID.UPLOAD_SUPPLEMENTORY_DATA_FILE && paramList[i].value && document.getElementById(FIELD.ID.SUPPLEMENTORY_DATA_FILE).value == '') {
190 if (isUploadAvailable && isAnyError) {
191 showError(FIELD.ERROR.MISSING_DATA, FIELD.ERROR.MISSING_FILE);
193 } else if (isUploadAvailable && document.getElementById(FIELD.ID.SUPPLEMENTORY_DATA_FILE).value != '') {
195 var fileInput = document.getElementById(FIELD.ID.SUPPLEMENTORY_DATA_FILE);
196 var file = fileInput.files[0];
197 var reader = new FileReader();
198 reader.onload = function (e) {
200 paramList[uploadIndex].value = JSON.parse(reader.result);
201 FIELD.PARAMETER.SUPPLEMENTORY_DATA_FILE['value'] = paramList[uploadIndex].value;
203 var instanceName = "";
205 if (DataService.getALaCarte()) {
206 if (paramList != null) {
207 for (var i = 0; i < paramList.length; i++) {
208 if (paramList[i].id === FIELD.ID.INSTANCE_NAME) {
209 instanceName = paramList[i].value;
214 var isValid = validateInstanceName(instanceName);
216 $scope.isErrorVisible = false;
218 showError(FIELD.ERROR.INVALID_INSTANCE_NAME + instanceName,
219 FIELD.ERROR.INSTANCE_NAME_VALIDATE);
223 var arbitraryParametersList = DataService.getArbitraryParameters();
225 if (UtilityService.hasContents(arbitraryParametersList)) {
226 for (var i = 0; i < arbitraryParametersList.length; i++) {
227 p = arbitraryParametersList[i];
228 if (p.type === PARAMETER.MAP) {
229 //validate a map: { <entry_key_1>: <entry_value_1>, ... , <entry_key_n>: <entry_value_n> }
230 // need to find the value in paramList
231 for (var j = 0; j < paramList.length; j++) {
232 if (paramList[j].id === p.id) {
233 p.value = paramList[j].value;
234 var isValid = validateMap(p.value);
236 $scope.isErrorVisible = false;
240 showError(FIELD.ERROR.INVALID_MAP + p.id,
241 FIELD.ERROR.MAP_VALIDATE);
246 } else if (p.type === PARAMETER.LIST) {
247 //validate a list: { value or a list of comma separated values }
248 // need to find the value in paramList
249 for (var j = 0; j < paramList.length; j++) {
250 if (paramList[j].id === p.id) {
251 p.value = paramList[j].value;
252 var isValid = validateList(p.value);
254 $scope.isErrorVisible = false;
258 showError(FIELD.ERROR.INVALID_LIST + p.id,
259 FIELD.ERROR.LIST_VALIDATE);
267 var requestDetails = CreationService
268 .getMsoRequestDetails($scope.userProvidedControl.getList());
270 $scope.isDialogVisible = false;
272 $scope.$broadcast(COMPONENT.MSO_CREATE_REQ, {
273 url: CreationService.getMsoUrl(),
274 requestDetails: requestDetails,
275 componentId: componentId,
276 callbackFunction: function (response) {
277 if (response.isSuccessful) {
278 $scope.popup.isVisible = false;
279 runCallback(response);
281 $scope.isDialogVisible = false;
282 $scope.popup.isVisible = false;
288 errorMsg = errorMsg + FIELD.ERROR.INVALID_DATA_FORMAT;
290 if (errorMsg !== "") {
291 showError(FIELD.ERROR.SYSTEM_FAILURE, errorMsg);
295 reader.readAsText(file);
298 var paramList = $scope.userProvidedControl.getList();
299 var instanceName = "";
301 if (DataService.getALaCarte()) {
302 if (paramList != null) {
303 for (var i = 0; i < paramList.length; i++) {
304 if (paramList[i].id === FIELD.ID.INSTANCE_NAME) {
305 instanceName = paramList[i].value;
310 var isValid = validateInstanceName(instanceName);
312 $scope.isErrorVisible = false;
314 showError(FIELD.ERROR.INVALID_INSTANCE_NAME + instanceName,
315 FIELD.ERROR.INSTANCE_NAME_VALIDATE);
319 var arbitraryParametersList = DataService.getArbitraryParameters();
321 if (UtilityService.hasContents(arbitraryParametersList)) {
322 for (var i = 0; i < arbitraryParametersList.length; i++) {
323 p = arbitraryParametersList[i];
324 if (p.type === PARAMETER.MAP) {
325 //validate a map: { <entry_key_1>: <entry_value_1>, ... , <entry_key_n>: <entry_value_n> }
326 // need to find the value in paramList
327 for (var j = 0; j < paramList.length; j++) {
328 if (paramList[j].id === p.id) {
329 p.value = paramList[j].value;
330 var isValid = validateMap(p.value);
332 $scope.isErrorVisible = false;
336 showError(FIELD.ERROR.INVALID_MAP + p.id,
337 FIELD.ERROR.MAP_VALIDATE);
342 } else if (p.type === PARAMETER.LIST) {
343 //validate a list: { value or a list of comma separated values }
344 // need to find the value in paramList
345 for (var j = 0; j < paramList.length; j++) {
346 if (paramList[j].id === p.id) {
347 p.value = paramList[j].value;
348 var isValid = validateList(p.value);
350 $scope.isErrorVisible = false;
354 showError(FIELD.ERROR.INVALID_LIST + p.id,
355 FIELD.ERROR.LIST_VALIDATE);
363 var requestDetails = CreationService
364 .getMsoRequestDetails($scope.userProvidedControl.getList());
366 $scope.isDialogVisible = false;
368 $scope.$broadcast(COMPONENT.MSO_CREATE_REQ, {
369 url: CreationService.getMsoUrl(),
370 requestDetails: requestDetails,
371 componentId: componentId,
372 callbackFunction: function (response) {
373 if (response.isSuccessful) {
374 $scope.popup.isVisible = false;
375 runCallback(response);
377 $scope.isDialogVisible = false;
378 $scope.popup.isVisible = false;
379 runCallback(response);
386 $scope.cancel = function () {
387 $scope.isDialogVisible = false;
388 $scope.popup.isVisible = false;
393 var runCallback = function (response) {
394 if (angular.isFunction(callbackFunction)) {
396 isSuccessful: response.isSuccessful,
397 control: $scope.userProvidedControl.getList(),
398 instanceId: response.instanceId
403 var showError = function (summary, details) {
404 var message = summary;
405 if (UtilityService.hasContents(details)) {
406 message += " (" + details + ")";
408 $scope.isSpinnerVisible = false;
409 $scope.isErrorVisible = true;
410 $scope.error = message;
415 appDS2.controller("creationDialogController", ["COMPONENT", "FIELD", "PARAMETER", "$scope", "$http",
416 "$timeout", "$log", "CreationService", "UtilityService", "DataService", "VIDCONFIGURATION", "$location",
417 "$uibModal", "featureFlags",
418 creationDialogController]);