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 WidgetOnboardingDetailsModalCtrl {
41 constructor($scope, $log, $interval, applicationsService, adminsService, microserviceService, widgetsCatalogService, errorMessageByCode, ECOMP_URL_REGEX, $window,userProfileService, confirmBoxService, $cookies,items) {
43 this.appUpdate = function(){
44 this.hasSelectedApp = false;
46 for(var i = 0; i < this.availableApps.length; i++){
47 if(this.availableApps[i].isSelected){
49 if(!this.hasSelectedApp)
50 this.hasSelectedApp = true;
52 if(this.availableApps[i].isSelected
53 && this.availableApps[i].roles.length == 0){
55 this.availableRoles = [];
56 adminsService.getRolesByApp(this.availableApps[i].id).then(roles => {
57 for(var i = 0; i < roles.length; i++){
58 this.availableRoles.push({
64 this.availableApps[index].roles = this.availableRoles;
68 this.allRoleSelected = true;
69 this.checkRoleSelected();
72 this.roleUpdate = function(app){
73 this.allRoleSelected = true;
74 for(var i = 0; i < app.roles.length; i++){
75 if(app.roles[i].isSelected){
76 app.roleSelected = true;
77 this.checkRoleSelected();
81 app.roleSelected = false;
82 this.checkRoleSelected();
85 this.checkRoleSelected = function(){
86 for(var i = 0; i < this.availableApps.length; i++){
87 if(this.availableApps[i].isSelected
88 && !this.availableApps[i].roleSelected){
89 this.allRoleSelected = false;
95 this.getAppName = function(appId){
96 for(var i = 0; i < this.availableApps.length; i++){
97 if(this.availableApps[i].id == appId){
98 return this.availableApps[i].name;
103 let newWidgetModel = {
110 showAppOptions: false,
111 showRoleOptions: false,
112 hasSelectedApp: false
115 let getAvailableApps = () => {
117 if(this.isEditMode == false){
118 applicationsService.getAppsForSuperAdminAndAccountAdmin().then(apps => {
119 this.availableApps=[];
120 for(var i=0;i<apps.length;i++) {
121 if (!apps[i].restrictedApp) {
122 this.availableApps.push({
135 else if(this.isEditMode == true){
136 if(this.widget.allowAllUser == "Y")
137 this.widget.allUser = true;
138 applicationsService.getAppsForSuperAdminAndAccountAdmin().then(apps => {
139 this.availableApps=[];
140 let selectedApps = {};
141 var availableApps = this.availableApps;
142 this.allRoleSelected = true;
143 for(var i=0; i < this.widget.widgetRoles.length; i++){
144 if(selectedApps[this.widget.widgetRoles[i].app.appId] != undefined)
145 selectedApps[this.widget.widgetRoles[i].app.appId] += this.widget.widgetRoles[i].roleId + ";" + this.widget.widgetRoles[i].roleName + ";";
147 selectedApps[this.widget.widgetRoles[i].app.appId] = this.widget.widgetRoles[i].roleId + ";" + this.widget.widgetRoles[i].roleName + ";";
151 apps.forEach(function(app, index){
159 if(selectedApps[app.id] != undefined){
160 adminsService.getRolesByApp(app.id).then(roles => {
161 var role = selectedApps[app.id].split(';');
162 var selectedRoles = [];
164 while((n+1) < role.length){
171 for(var m = 0; m < roles.length; m++){
172 var hasSelected = true;
173 for(var n = 0; n < selectedRoles.length; n++){
174 if(selectedRoles[n].id == roles[m].id){
187 availableApps[index].roleSelected = true;
188 availableApps[index].isSelected = true;
189 availableApps[index].roles = selectedRoles;
197 let getAvailableServices = () =>{
198 microserviceService.getServiceList().then(services => {
199 this.availableServices = [];
200 for(var i = 0; i < services.length; i++){
201 this.availableServices.push({
203 name: services[i].name,
204 option: services[i].name + ": " + services[i].url
207 if(this.widget.serviceId != null && this.widget.serviceId == services[i].id){
208 this.widget.serviceURL = this.availableServices[i];
218 $log.info('WidgetOnboardingDetailsModalCtrl::init');
219 this.widgetsList = [];
220 this.duplicatedName = true;
221 this.allRoleSelected = false;
223 this.isSaving = false;
224 this.allUser = false;
225 this.emptyWidgetName = false;
227 if (items && items.widget) {
228 this.isEditMode = true;
229 this.allRoleSelected = true;
230 this.widget = _.clone(items.widget);
232 this.isEditMode = false;
233 this.widget = _.clone(newWidgetModel);
236 widgetsCatalogService.getManagedWidgets().then(res => {
237 for(var i = 0; i < res.length; i++){
238 this.widgetsList.push(res[i].name);
241 $log.error('WidgetOnboardingDetailsModalCtrl::init error: ' + err);
243 this.isLoadingTable = false;
246 widgetsCatalogService.getUploadFlag().then(res => {
249 $log.error('WidgetOnboardingDetailsModalCtrl::init error: ' + err);
254 getAvailableServices();
256 this.ECOMP_URL_REGEX = ECOMP_URL_REGEX;
257 this.conflictMessages = {};
260 let resetConflict = fieldName => {
261 delete this.conflictMessages[fieldName];
262 if($scope.widgetForm[fieldName]){
263 $scope.widgetForm[fieldName].$setValidity('conflict', true);
267 this.updateSelectedRole = () => {
268 if (!this.selectedRole) {
271 this.widget.RoleId = this.selectedRole.id;
272 this.widget.RoleName = this.selectedRole.name;
275 let emptyCookies = () => {
276 userProfileService.getUserProfile()
278 $log.info('AppDetailsModalCtrl::emptyCookies profile: ', profile);
279 $scope.orgUserId = profile.orgUserId;
280 $log.info('user has the following orgUserId: ' + profile.orgUserId);
281 if ($cookies.getObject($scope.orgUserId + '_widget') != undefined && $cookies.getObject($scope.orgUserId + '_widget') != null) {
282 $cookies.remove($scope.orgUserId + '_widget');
287 this.updateWidgetName = () => {
288 for(var i = 0; i < this.widgetsList.length; i++){
289 if(this.widget.name.toUpperCase() == this.widgetsList[i].toUpperCase()){
290 this.duplicatedName = false;
294 this.duplicatedName = true;
297 this.saveChanges = () => {
300 this.updateWidgetName();
302 if(this.duplicatedName == false
303 || this.widget.name == ''
304 || this.widget.name == undefined){
305 this.emptyWidgetName = true;
309 if((this.widget.file == undefined && !this.isEditMode) ||
310 (!this.widget.allUser && this.appCounter == 0) ||
311 this.widget.name == null ||
312 (!this.widget.allUser && !this.allRoleSelected) ||
313 this.widget.saving == true)
317 this.widget.saving = true;
318 var selectedRoles = [];
319 if(!this.widget.allUser){
320 for(var i = 0; i < this.availableApps.length; i++){
321 if(this.availableApps[i].isSelected){
322 for(var n = 0; n < this.availableApps[i].roles.length; n++) {
323 if(this.availableApps[i].roles[n].isSelected){
326 appId: this.availableApps[i].id
328 roleId: this.availableApps[i].roles[n].id,
329 roleName: this.availableApps[i].roles[n].name,
331 selectedRoles.push(role);
338 var allowAllUser = 0;
339 if(this.widget.allUser)
342 var serviceId = null;
343 if(this.widget.serviceURL != null &&
344 this.widget.serviceURL != undefined){
345 serviceId = parseInt(this.widget.serviceURL);
349 var file_loc = this.widget.name + ".zip";
351 name: this.widget.name,
352 desc: this.widget.desc,
353 widgetRoles: selectedRoles,
354 fileLocation: file_loc,
355 allowAllUser: allowAllUser,
361 if(this.widget.file != undefined){
362 widgetsCatalogService.updateWidgetWithFile(this.widget.file, this.widget.id, newWidget).then(res => {
365 confirmBoxService.showInformation("Could not save. Please retry.");
366 this.widget.saving = false;
369 confirmBoxService.showInformation(res.error);
370 this.widget.saving = false;
373 $scope.$dismiss('cancel');
374 this.widget.saving = false;
378 widgetsCatalogService.updateWidget(this.widget.id, newWidget)
380 $scope.$dismiss('cancel');
386 widgetsCatalogService.createWidget(newWidget, this.widget.file).then(res => {
389 confirmBoxService.showInformation("Could not save. Please retry.");
391 confirmBoxService.showInformation(res.error);
392 this.widget.saving = false;
395 $scope.$dismiss('cancel');
397 this.widget.saving = false;
402 $scope.$on('$stateChangeStart', e => {
407 WidgetOnboardingDetailsModalCtrl.$inject = ['$scope', '$log', '$interval', 'applicationsService', 'adminsService', 'microserviceService', 'widgetsCatalogService', 'errorMessageByCode', 'ECOMP_URL_REGEX', '$window','userProfileService', 'confirmBoxService', '$cookies','items'];
408 angular.module('ecompApp').controller('WidgetOnboardingDetailsModalCtrl', WidgetOnboardingDetailsModalCtrl);