2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
40 class AppDetailsModalCtrl {
41 constructor($scope, $log, $timeout, applicationsService, errorMessageByCode,
42 ECOMP_URL_REGEX,userProfileService, $cookies, confirmBoxService,items) {
43 // let emptyImg = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
44 // empty image should really be empty, or it causes problems for the back end
46 this.emptyImgForPreview = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
47 $scope.ngDialogData=items;
60 'thumbnail': emptyImg,
62 'restrictedApp': false,
64 'isCentralAuth': false
68 $log.info('AppDetailsModalCtrl::init');
69 this.isSaving = false;
70 if($scope.ngDialogData && $scope.ngDialogData.app){
71 $log.debug('AppDetailsModalCtrl:init:: Edit app mode for', $scope.ngDialogData.app);
72 this.isEditMode = true;
73 this.app = _.clone($scope.ngDialogData.app);
75 $log.debug('AppDetailsModalCtrl:init:: New app mode');
76 this.isEditMode = false;
77 this.app = _.clone(newAppModel);
79 this.originalImage = null
82 this.ECOMP_URL_REGEX = ECOMP_URL_REGEX;
85 this.removeImage = () => {
86 $log.debug('AppDetailsModalCtrl:removeImage:: entering removeImage');
88 confirmBoxService.confirm("Are you sure you want to remove the image?").then(isConfirmed => {
90 this.imageApi.clearFile();
91 this.app.thumbnail = emptyImg;
92 this.originalImage = null;
93 this.app.imageUrl = null;
94 this.app.imageLink = null;
97 $log.error('AppDetailsModalCtrl:removeImage error:: ',err);
101 //This part handles conflict errors (409)
102 this.conflictMessages = {};
104 let handleConflictErrors = err => {
108 if(!err.data.length){ //support objects
109 err.data = [err.data]
111 _.forEach(err.data, item => {
112 _.forEach(item.fields, field => {
113 //set conflict message
114 this.conflictMessages[field.name] = errorMessageByCode[item.errorCode];
115 //set field as invalid
116 $scope.appForm[field.name].$setValidity('conflict', false);
117 //set watch once to clear error after user correction
118 watchOnce[field.name]();
121 this.scrollApi.scrollTop();
124 let resetConflict = fieldName => {
125 delete this.conflictMessages[fieldName];
126 if($scope.appForm[fieldName]){
127 $scope.appForm[fieldName].$setValidity('conflict', true);
132 let emptyCookies = () => {
133 $log.debug('AppDetailsModalCtrl:emptyCookies:: entering emptyCookies');
134 userProfileService.getUserProfile()
136 // $log.info(profile);
137 $scope.orgUserId = profile.orgUserId;
138 $log.debug('AppDetailsModalCtrl:emptyCookies for the following orgUserId: ' + profile.orgUserId);
139 if ($cookies.getObject($scope.orgUserId + '_apps') != undefined && $cookies.getObject($scope.orgUserId + '_apps') != null) {
140 $cookies.remove($scope.orgUserId + '_apps');
141 $log.debug('AppDetailsModalCtrl:emptyCookies removed: ' + $scope.orgUserId + '_apps');
143 if ($cookies.getObject($scope.orgUserId + '_widget') != undefined && $cookies.getObject($scope.orgUserId + '_widget') != null) {
144 $cookies.remove($scope.orgUserId + '_widget');
145 $log.debug('AppDetailsModalCtrl:emptyCookies removed: ' + $scope.orgUserId + '_widget');
148 $log.error('AppDetailsModalCtrl:emptyCookies error:: '+ JSON.stringify(err));
155 let unregisterName = $scope.$watch('appDetails.app.name', (newVal, oldVal) => {
156 // $log.debug('newVal, oldVal = ' + newVal.toLowerCase() + " | " + oldVal.toLowerCase())
157 if(newVal.toLowerCase() !== oldVal.toLowerCase()){
158 resetConflict('name');
164 let unregisterUrl = $scope.$watch('appDetails.app.url', (newVal, oldVal) => {
165 if(newVal.toLowerCase() !== oldVal.toLowerCase()) {
166 resetConflict('url');
172 //***************************
174 this.saveChanges = () => {
176 if(this.app.isCentralAuth){
178 if(!this.app.isEnabled)
180 if(((angular.isUndefined(this.app.name) || !this.app.name)||(angular.isUndefined(this.app.nameSpace) || !this.app.nameSpace)
181 ||(angular.isUndefined(this.app.username) || !this.app.username))) {
182 confirmBoxService.showInformation('Please fill in all required fields for centralized application').then(isConfirmed => {});
186 if(this.app.isEnabled){
187 if(((angular.isUndefined(this.app.myLoginsAppName) || !this.app.myLoginsAppName)||(angular.isUndefined(this.app.myLoginsAppOwner) || !this.app.myLoginsAppOwner)||(angular.isUndefined(this.app.name) || !this.app.name)||(angular.isUndefined(this.app.url) || !this.app.url)
188 ||(angular.isUndefined(this.app.username) || !this.app.username)||(angular.isUndefined(this.app.nameSpace) || !this.app.nameSpace))) {
189 confirmBoxService.showInformation('Please fill in all required fields for centralized active application').then(isConfirmed => {});
195 if(!this.app.isEnabled)
197 if((angular.isUndefined(this.app.name) || !this.app.name)){
198 confirmBoxService.showInformation('Please fill in all required field ApplicationName to Save the applictaion').then(isConfirmed => {});
201 }else if(this.app.isEnabled && !this.app.restrictedApp){
202 if(((angular.isUndefined(this.app.myLoginsAppName) || !this.app.myLoginsAppName)||(angular.isUndefined(this.app.myLoginsAppOwner) || !this.app.myLoginsAppOwner)||(angular.isUndefined(this.app.name) || !this.app.name)||(angular.isUndefined(this.app.url) || !this.app.url)
203 ||(angular.isUndefined(this.app.username) || !this.app.username)||(angular.isUndefined(this.app.appPassword) || !this.app.appPassword))) {
204 confirmBoxService.showInformation('Please fill in all required fields along with password as the app is not centralized').then(isConfirmed => {});
206 } }else if(this.app.isEnabled && this.app.restrictedApp){
207 if((angular.isUndefined(this.app.name) || !this.app.name) ||(angular.isUndefined(this.app.url) || !this.app.url)){
208 confirmBoxService.showInformation('Please fill in all required fields').then(isConfirmed => {});
214 this.isSaving = true;
215 // For a restricted app, null out all irrelevant fields
216 if (this.app.restrictedApp) {
217 this.app.restUrl = null;
218 this.app.isOpen = true;
219 this.app.username = null;
220 this.app.appPassword = null;
221 this.app.uebTopicName = null;
222 this.app.uebKey = null;
223 this.app.uebSecret = null;
226 if (this.app.nameSpace=="") {this.app.nameSpace = null;}
227 applicationsService.updateOnboardingApp(this.app)
229 $log.debug('AppDetailsModalCtrl:updateOnboardingApp:: App update succeeded!');
230 // $scope.closeThisDialog(true);
231 $scope.$dismiss('cancel');
234 switch (err.status) {
235 case '409': // Conflict
236 handleConflictErrors(err);
238 case '500': // Internal Server Error
239 confirmBoxService.showInformation('There was a problem updating the application changes. ' +
240 'Please try again later. Error: ' + err.status).then(isConfirmed => {});
242 case '403': // Forbidden... possible webjunction error to try again
243 confirmBoxService.showInformation('There was a problem updating the application changes. ' +
244 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => {});
247 confirmBoxService.showInformation('There was a problem updating the application changes. ' +
248 'Please try again. If the problem persists, then try again later. Error: ' + err.status).then(isConfirmed => {});
250 $log.error('applicationsService:updateOnboardingApp error:: '+ JSON.stringify(err));
252 this.isSaving = false;
254 var objOffsetVersion = objAgent.indexOf("MSIE");
255 if (objOffsetVersion != -1) {
256 $log.debug('AppDetailsModalCtrl:updateOnboardingApp:: Browser is IE, forcing Refresh');
257 $window.location.reload(); // for bug in IE 11
262 applicationsService.addOnboardingApp(this.app)
264 $log.debug('App creation succeeded!');
265 //$scope.closeThisDialog(true);
266 $scope.$dismiss('cancel');
269 switch (err.status) {
270 case '409': // Conflict
271 handleConflictErrors(err);
273 case '500': // Internal Server Error
274 confirmBoxService.showInformation('There was a problem adding the application information. ' +
275 'Please try again later. Error: ' + err.status).then(isConfirmed => {});
278 confirmBoxService.showInformation('There was a problem updating the application changes. ' +
279 'Please try again. If the problem persists, then try again later. Error: ' +
280 err.status).then(isConfirmed => {});
282 $log.error('applicationsService:addOnboardingApp error:: '+ JSON.stringify(err));
284 this.isSaving = false;
286 var objOffsetVersion = objAgent.indexOf("MSIE");
287 if (objOffsetVersion != -1) {
288 $log.debug('applicationsService:addOnboardingApp:: Browser is IE, forcing Refresh');
289 $window.location.reload(); // for bug in IE 11
297 // Caches the file name supplied by the event handler.
298 $scope.appImageHandler = (event, files) => {
300 var fileName = files[0].name;
301 var validFormats = ['jpg', 'jpeg', 'bmp', 'gif', 'png'];
303 var ext = fileName.substring(fileName.lastIndexOf('.') + 1).toLowerCase();
304 //Check for valid format
305 if(validFormats.indexOf(ext) == -1){
306 $scope.appImageTypeError=true;
308 $scope.appImageTypeError=false;
312 }; // file change handler
317 $scope.$watch('appDetails.originalImage', (newVal, oldVal) => {
318 if((!newVal || !newVal.resized) && !this.app.imageUrl){
320 $log.debug('applicationsService:$scope.$watch:: originalImage: newVal is null');
322 $log.debug('applicationsService:$scope.$watch:: originalImage: newVal is not resized and no imageUrl');
324 this.app.imageUrl = null;
325 this.app.thumbnail = emptyImg;
329 if(!(_.isEqual(newVal, oldVal))){
330 $log.debug('applicationsService:$scope.$watch:: thumbnail updated!');
331 this.app.imageUrl = null;
332 this.app.imageLink = null;
333 this.app.thumbnail = newVal.resized.dataURL;
337 $scope.$on('$stateChangeStart', e => {
338 //Disable navigation when modal is opened
343 AppDetailsModalCtrl.$inject = ['$scope', '$log', '$timeout', 'applicationsService', 'errorMessageByCode',
344 'ECOMP_URL_REGEX','userProfileService','$cookies', 'confirmBoxService','items'];
345 angular.module('ecompApp').controller('AppDetailsModalCtrl', AppDetailsModalCtrl);