2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ================================================================================
\r
22 class WidgetOnboardingDetailsModalCtrl {
\r
23 constructor($scope, $log, $interval, applicationsService, adminsService, microserviceService, widgetsCatalogService, errorMessageByCode, ECOMP_URL_REGEX, $window,userProfileService, confirmBoxService, $cookies) {
\r
25 this.appUpdate = function(){
\r
26 this.hasSelectedApp = false;
\r
27 this.appCounter = 0;
\r
28 for(var i = 0; i < this.availableApps.length; i++){
\r
29 if(this.availableApps[i].isSelected){
\r
31 if(!this.hasSelectedApp)
\r
32 this.hasSelectedApp = true;
\r
34 if(this.availableApps[i].isSelected
\r
35 && this.availableApps[i].roles.length == 0){
\r
37 this.availableRoles = [];
\r
38 adminsService.getRolesByApp(this.availableApps[i].id).then(roles => {
\r
39 for(var i = 0; i < roles.length; i++){
\r
40 this.availableRoles.push({
\r
42 name: roles[i].name,
\r
46 this.availableApps[index].roles = this.availableRoles;
\r
50 this.allRoleSelected = true;
\r
51 this.checkRoleSelected();
\r
54 this.roleUpdate = function(app){
\r
55 this.allRoleSelected = true;
\r
56 for(var i = 0; i < app.roles.length; i++){
\r
57 if(app.roles[i].isSelected){
\r
58 app.roleSelected = true;
\r
59 this.checkRoleSelected();
\r
63 app.roleSelected = false;
\r
64 this.checkRoleSelected();
\r
67 this.checkRoleSelected = function(){
\r
68 for(var i = 0; i < this.availableApps.length; i++){
\r
69 if(this.availableApps[i].isSelected
\r
70 && !this.availableApps[i].roleSelected){
\r
71 this.allRoleSelected = false;
\r
77 this.getAppName = function(appId){
\r
78 for(var i = 0; i < this.availableApps.length; i++){
\r
79 if(this.availableApps[i].id == appId){
\r
80 return this.availableApps[i].name;
\r
85 let newWidgetModel = {
\r
92 showAppOptions: false,
\r
93 showRoleOptions: false,
\r
94 hasSelectedApp: false
\r
97 let getAvailableApps = () => {
\r
99 if(this.isEditMode == false){
\r
100 applicationsService.getAppsForSuperAdminAndAccountAdmin().then(apps => {
\r
101 this.availableApps=[];
\r
102 for(var i=0;i<apps.length;i++) {
\r
103 if (!apps[i].restrictedApp) {
\r
104 this.availableApps.push({
\r
106 name: apps[i].name,
\r
108 roleSelected: false,
\r
117 else if(this.isEditMode == true){
\r
118 if(this.widget.allowAllUser == "Y")
\r
119 this.widget.allUser = true;
\r
120 applicationsService.getAppsForSuperAdminAndAccountAdmin().then(apps => {
\r
121 this.availableApps=[];
\r
122 let selectedApps = {};
\r
123 var availableApps = this.availableApps;
\r
124 this.allRoleSelected = true;
\r
125 for(var i=0; i < this.widget.widgetRoles.length; i++){
\r
126 if(selectedApps[this.widget.widgetRoles[i].app.appId] != undefined)
\r
127 selectedApps[this.widget.widgetRoles[i].app.appId] += this.widget.widgetRoles[i].roleId + ";" + this.widget.widgetRoles[i].roleName + ";";
\r
129 selectedApps[this.widget.widgetRoles[i].app.appId] = this.widget.widgetRoles[i].roleId + ";" + this.widget.widgetRoles[i].roleName + ";";
\r
133 apps.forEach(function(app, index){
\r
134 availableApps.push({
\r
138 roleSelected: false,
\r
141 if(selectedApps[app.id] != undefined){
\r
142 adminsService.getRolesByApp(app.id).then(roles => {
\r
143 var role = selectedApps[app.id].split(';');
\r
144 var selectedRoles = [];
\r
146 while((n+1) < role.length){
\r
147 selectedRoles.push({
\r
153 for(var m = 0; m < roles.length; m++){
\r
154 var hasSelected = true;
\r
155 for(var n = 0; n < selectedRoles.length; n++){
\r
156 if(selectedRoles[n].id == roles[m].id){
\r
157 hasSelected = false;
\r
162 selectedRoles.push({
\r
164 name: roles[m].name,
\r
169 availableApps[index].roleSelected = true;
\r
170 availableApps[index].isSelected = true;
\r
171 availableApps[index].roles = selectedRoles;
\r
179 let getAvailableServices = () =>{
\r
180 microserviceService.getServiceList().then(services => {
\r
181 this.availableServices = [];
\r
182 for(var i = 0; i < services.length; i++){
\r
183 this.availableServices.push({
\r
184 id: services[i].id,
\r
185 name: services[i].name,
\r
186 option: services[i].name + ": " + services[i].url
\r
189 if(this.widget.service != null && this.widget.service.id == services[i].id){
\r
190 this.widget.serviceURL = this.availableServices[i];
\r
200 $log.info('WidgetOnboardingDetailsModalCtrl::init');
\r
201 this.widgetsList = [];
\r
202 this.duplicatedName = true;
\r
203 this.allRoleSelected = false;
\r
204 this.appCounter = 0;
\r
205 this.isSaving = false;
\r
206 this.allUser = false;
\r
207 this.emptyWidgetName = false;
\r
209 if ($scope.ngDialogData && $scope.ngDialogData.widget) {
\r
210 this.isEditMode = true;
\r
211 this.allRoleSelected = true;
\r
212 this.widget = _.clone($scope.ngDialogData.widget);
\r
214 this.isEditMode = false;
\r
215 this.widget = _.clone(newWidgetModel);
\r
218 widgetsCatalogService.getManagedWidgets().then(res => {
\r
219 for(var i = 0; i < res.length; i++){
\r
220 this.widgetsList.push(res[i].name);
\r
223 $log.error('WidgetOnboardingDetailsModalCtrl::init error: ' + err);
\r
225 this.isLoadingTable = false;
\r
227 getAvailableApps();
\r
228 getAvailableServices();
\r
230 this.ECOMP_URL_REGEX = ECOMP_URL_REGEX;
\r
231 this.conflictMessages = {};
\r
232 this.scrollApi = {};
\r
234 let resetConflict = fieldName => {
\r
235 delete this.conflictMessages[fieldName];
\r
236 if($scope.widgetForm[fieldName]){
\r
237 $scope.widgetForm[fieldName].$setValidity('conflict', true);
\r
241 this.updateSelectedRole = () => {
\r
242 if (!this.selectedRole) {
\r
245 this.widget.RoleId = this.selectedRole.id;
\r
246 this.widget.RoleName = this.selectedRole.name;
\r
249 let emptyCookies = () => {
\r
250 userProfileService.getUserProfile()
\r
252 $log.info('AppDetailsModalCtrl::emptyCookies profile: ', profile);
\r
253 $scope.orgUserId = profile.orgUserId;
\r
254 $log.info('user has the following orgUserId: ' + profile.orgUserId);
\r
255 if ($cookies.getObject($scope.orgUserId + '_widget') != undefined && $cookies.getObject($scope.orgUserId + '_widget') != null) {
\r
256 $cookies.remove($scope.orgUserId + '_widget');
\r
261 this.updateWidgetName = () => {
\r
262 for(var i = 0; i < this.widgetsList.length; i++){
\r
263 if(this.widget.name.toUpperCase() == this.widgetsList[i].toUpperCase()){
\r
264 this.duplicatedName = false;
\r
268 this.duplicatedName = true;
\r
271 this.saveChanges = () => {
\r
273 if(!this.isEditMode)
\r
274 this.updateWidgetName();
\r
276 if(this.duplicatedName == false
\r
277 || this.widget.name == ''
\r
278 || this.widget.name == undefined){
\r
279 this.emptyWidgetName = true;
\r
283 if((this.widget.file == undefined && !this.isEditMode) ||
\r
284 (!this.widget.allUser && this.appCounter == 0) ||
\r
285 this.widget.name == null ||
\r
286 (!this.widget.allUser && !this.allRoleSelected) ||
\r
287 this.widget.saving == true)
\r
291 this.widget.saving = true;
\r
292 var selectedRoles = [];
\r
293 if(!this.widget.allUser){
\r
294 for(var i = 0; i < this.availableApps.length; i++){
\r
295 if(this.availableApps[i].isSelected){
\r
296 for(var n = 0; n < this.availableApps[i].roles.length; n++) {
\r
297 if(this.availableApps[i].roles[n].isSelected){
\r
300 appId: this.availableApps[i].id
\r
302 roleId: this.availableApps[i].roles[n].id,
\r
303 roleName: this.availableApps[i].roles[n].name,
\r
305 selectedRoles.push(role);
\r
312 var allowAllUser = 0;
\r
313 if(this.widget.allUser)
\r
316 var serviceId = null;
\r
317 if(this.widget.serviceURL != null &&
\r
318 this.widget.serviceURL != undefined){
\r
319 serviceId = this.widget.serviceURL.id;
\r
323 var file_loc = this.widget.name + ".zip";
\r
325 name: this.widget.name,
\r
326 desc: this.widget.desc,
\r
327 widgetRoles: selectedRoles,
\r
328 fileLocation: file_loc,
\r
329 allowAllUser: allowAllUser,
\r
330 serviceId: serviceId
\r
333 if(this.isEditMode){
\r
335 if(this.widget.file != undefined){
\r
336 widgetsCatalogService.updateWidgetWithFile(this.widget.file, this.widget.id, newWidget).then(res => {
\r
339 confirmBoxService.showInformation("Could not save. Please retry.");
\r
340 this.widget.saving = false;
\r
343 confirmBoxService.showInformation(res.error);
\r
344 this.widget.saving = false;
\r
347 $scope.closeThisDialog(true);
\r
348 this.widget.saving = false;
\r
352 widgetsCatalogService.updateWidget(this.widget.id, newWidget)
\r
354 $scope.closeThisDialog(true);
\r
359 widgetsCatalogService.createWidget(newWidget, this.widget.file).then(res => {
\r
362 confirmBoxService.showInformation("Could not save. Please retry.");
\r
364 confirmBoxService.showInformation(res.error);
\r
365 this.widget.saving = false;
\r
368 $scope.closeThisDialog(true);
\r
369 this.widget.saving = false;
\r
374 $scope.$on('$stateChangeStart', e => {
\r
375 e.preventDefault();
\r
379 WidgetOnboardingDetailsModalCtrl.$inject = ['$scope', '$log', '$interval', 'applicationsService', 'adminsService', 'microserviceService', 'widgetsCatalogService', 'errorMessageByCode', 'ECOMP_URL_REGEX', '$window','userProfileService', 'confirmBoxService', '$cookies'];
\r
380 angular.module('ecompApp').controller('WidgetOnboardingDetailsModalCtrl', WidgetOnboardingDetailsModalCtrl);
\r