2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
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 * ================================================================================
22 class AppDetailsModalCtrl {
23 constructor($scope, $log, applicationsService, errorMessageByCode,
24 ECOMP_URL_REGEX,userProfileService, $cookies, confirmBoxService) {
26 this.emptyImgForPreview = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
40 'thumbnail': emptyImg,
42 'restrictedApp': false
46 $log.info('AppDetailsModalCtrl::init');
47 this.isSaving = false;
48 if($scope.ngDialogData && $scope.ngDialogData.app){
49 $log.debug('AppDetailsModalCtrl:init:: Edit app mode for', $scope.ngDialogData.app);
50 this.isEditMode = true;
51 this.app = _.clone($scope.ngDialogData.app);
53 $log.debug('AppDetailsModalCtrl:init:: New app mode');
54 this.isEditMode = false;
55 this.app = _.clone(newAppModel);
57 this.originalImage = null
60 this.ECOMP_URL_REGEX = ECOMP_URL_REGEX;
63 this.removeImage = () => {
64 $log.debug('AppDetailsModalCtrl:removeImage:: entering removeImage');
66 confirmBoxService.confirm("Are you sure you want to remove the image?").then(isConfirmed => {
68 this.imageApi.clearFile();
69 this.app.thumbnail = emptyImg;
70 this.originalImage = null;
71 this.app.imageUrl = null;
74 $log.error('AppDetailsModalCtrl:removeImage error:: ',err);
78 this.conflictMessages = {};
80 let handleConflictErrors = err => {
87 _.forEach(err.data, item => {
88 _.forEach(item.fields, field => {
89 this.conflictMessages[field.name] = errorMessageByCode[item.errorCode];
90 $scope.appForm[field.name].$setValidity('conflict', false);
91 watchOnce[field.name]();
94 this.scrollApi.scrollTop();
97 let resetConflict = fieldName => {
98 delete this.conflictMessages[fieldName];
99 if($scope.appForm[fieldName]){
100 $scope.appForm[fieldName].$setValidity('conflict', true);
105 let emptyCookies = () => {
106 $log.debug('AppDetailsModalCtrl:emptyCookies:: entering emptyCookies');
107 userProfileService.getUserProfile()
109 $scope.userId = profile.orgUserId;
110 $log.debug('AppDetailsModalCtrl:emptyCookies for the following userId: ' + profile.orgUserId);
111 if ($cookies.getObject($scope.userId + '_apps') != undefined && $cookies.getObject($scope.userId + '_apps') != null) {
112 $cookies.remove($scope.userId + '_apps');
113 $log.debug('AppDetailsModalCtrl:emptyCookies removed: ' + $scope.userId + '_apps');
115 if ($cookies.getObject($scope.userId + '_widget') != undefined && $cookies.getObject($scope.userId + '_widget') != null) {
116 $cookies.remove($scope.userId + '_widget');
117 $log.debug('AppDetailsModalCtrl:emptyCookies removed: ' + $scope.userId + '_widget');
120 $log.error('AppDetailsModalCtrl:emptyCookies error:: '+ JSON.stringify(err));
127 let unregisterName = $scope.$watch('appDetails.app.name', (newVal, oldVal) => {
128 if(newVal.toLowerCase() !== oldVal.toLowerCase()){
129 resetConflict('name');
135 let unregisterUrl = $scope.$watch('appDetails.app.url', (newVal, oldVal) => {
136 if(newVal.toLowerCase() !== oldVal.toLowerCase()) {
137 resetConflict('url');
144 this.saveChanges = () => {
145 if($scope.appForm.$invalid){
148 this.isSaving = true;
150 if (this.app.restrictedApp) {
151 this.app.restUrl = null;
152 this.app.isOpen = true;
153 this.app.username = null;
154 this.app.appPassword = null;
155 this.app.uebTopicName = null;
156 this.app.uebKey = null;
157 this.app.uebSecret = null;
160 applicationsService.updateOnboardingApp(this.app)
162 $log.debug('AppDetailsModalCtrl:updateOnboardingApp:: App update succeeded!');
163 $scope.closeThisDialog(true);
166 if(err.status === 409){
167 handleConflictErrors(err);
169 if(err.status === 500){
170 confirmBoxService.showInformation('There was a problem updating the application changes. ' +
171 'Please try again later.').then(isConfirmed => {});
173 if(err.status === 403){
174 confirmBoxService.showInformation('There was a problem updating the application changes. ' +
175 'Please try again. If the problem persists, then try again later.').then(isConfirmed => {});
177 $log.error('applicationsService:updateOnboardingApp error status:: '+ err.status);
178 $log.error('applicationsService:updateOnboardingApp error:: '+ JSON.stringify(err));
180 this.isSaving = false;
181 var objOffsetVersion = objAgent.indexOf("MSIE");
182 if (objOffsetVersion != -1) {
183 $log.debug('AppDetailsModalCtrl:updateOnboardingApp:: Browser is IE, forcing Refresh');
184 $window.location.reload();
188 applicationsService.addOnboardingApp(this.app)
190 $log.debug('App creation succeeded!');
191 $scope.closeThisDialog(true);
194 if(err.status === 409){
195 handleConflictErrors(err);
197 if(err.status === 500){
198 confirmBoxService.showInformation('There was a problem adding the application information. ' +
199 'Please try again later.').then(isConfirmed => {});
201 $log.error('applicationsService:addOnboardingApp error status:: '+ err.status);
202 $log.error('applicationsService:addOnboardingApp error:: '+ JSON.stringify(err));
204 this.isSaving = false;
205 var objOffsetVersion = objAgent.indexOf("MSIE");
206 if (objOffsetVersion != -1) {
207 $log.debug('applicationsService:addOnboardingApp:: Browser is IE, forcing Refresh');
208 $window.location.reload();
217 $scope.$watch('appDetails.originalImage', (newVal, oldVal) => {
218 if((!newVal || !newVal.resized) && !this.app.imageUrl){
220 $log.debug('applicationsService:$scope.$watch:: originalImage: newVal is null');
222 $log.debug('applicationsService:$scope.$watch:: originalImage: newVal is not resized and no imageUrl');
224 this.app.imageUrl = null;
225 this.app.thumbnail = emptyImg;
229 if(!(_.isEqual(newVal, oldVal))){
230 $log.debug('applicationsService:$scope.$watch:: thumbnail updated!');
231 this.app.imageUrl = null;
232 this.app.thumbnail = newVal.resized.dataURL;
236 $scope.$on('$stateChangeStart', e => {
241 AppDetailsModalCtrl.$inject = ['$scope', '$log', 'applicationsService', 'errorMessageByCode',
242 'ECOMP_URL_REGEX','userProfileService','$cookies', 'confirmBoxService'];
243 angular.module('ecompApp').controller('AppDetailsModalCtrl', AppDetailsModalCtrl);