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 WidgetOnboardingCtrl {
\r
23 constructor($log, applicationsService, widgetsCatalogService, ngDialog, confirmBoxService,
\r
24 userProfileService, $cookies, $scope) {
\r
25 $scope.infoMessage = true;
\r
27 let populateAvailableApps = widgets => {
\r
28 let allPortalsFilterObject = {index: 0, title: 'All applications', value: ''};
\r
29 this.availableApps = [allPortalsFilterObject];
\r
30 this.filterByApp = this.availableApps[0];
\r
31 applicationsService.getAppsForSuperAdminAndAccountAdmin().then(myApps => {
\r
32 var reSortedApp = myApps.sort(getSortOrder("name"));
\r
33 var realAppIndex = 1;
\r
34 for (let i = 1; i <= reSortedApp.length; i++) {
\r
35 if (!reSortedApp[i-1].restrictedApp) {
\r
36 this.availableApps.push({
\r
37 index: realAppIndex,
\r
38 title: reSortedApp[i - 1].name,
\r
39 value: reSortedApp[i - 1].name
\r
41 realAppIndex = realAppIndex + 1;
\r
45 $log.error('WidgetOnboardingCtrl:getAppsForSuperAdmin failed', err);
\r
49 let getOnboardingWidgets = () => {
\r
50 this.isLoadingTable = true;
\r
51 this.isCommError = false;
\r
52 widgetsCatalogService.getManagedWidgets().then(res => {
\r
53 if(!(res instanceof Array)){
\r
54 this.isCommError = true;
\r
58 var reSortedWidget = res.sort(getSortOrder("name"));
\r
59 $scope.widgetsList = reSortedWidget;
\r
60 for(var i = 0; i < $scope.widgetsList.length; i++){
\r
61 let set = new Set();
\r
63 var appContent = [];
\r
65 for(var n = 0; n < $scope.widgetsList[i].widgetRoles.length; n++){
\r
66 set.add($scope.widgetsList[i].widgetRoles[n].app.appName);
\r
68 if($scope.widgetsList[i].allowAllUser == "Y"){
\r
69 info = "All Applications";
\r
70 appContent.push("All Applications");
\r
71 appName.push("All Applications");
\r
74 set.forEach(function (item) {
\r
75 info = item.toString() + " - ";
\r
76 for(var n = 0; n < $scope.widgetsList[i].widgetRoles.length; n++){
\r
77 if(item.toString() == $scope.widgetsList[i].widgetRoles[n].app.appName){
\r
78 info += $scope.widgetsList[i].widgetRoles[n].roleName + "; ";
\r
81 appContent.push(info);
\r
82 appName.push(item.toString());
\r
84 $scope.widgetsList[i].appContent = appContent;
\r
85 $scope.widgetsList[i].appName = appName;
\r
87 populateAvailableApps(reSortedWidget);
\r
89 // Land here when the micro service is down
\r
90 $log.error('WidgetOnboardingCtrl::getOnboardingWidgets caught error', err);
\r
92 this.isLoadingTable = false;
\r
98 // Refactor this into a directive
\r
99 let getSortOrder = (prop) => {
\r
100 return function(a, b) {
\r
101 if (a[prop].toLowerCase() > b[prop].toLowerCase()) {
\r
103 } else if (a[prop].toLowerCase() < b[prop].toLowerCase()) {
\r
110 $scope.hideMe = function () {
\r
111 $scope.infoMessage = false;
\r
115 this.isLoadingTable = false;
\r
116 getOnboardingWidgets();
\r
117 this.searchString = '';
\r
118 this.widgetsTableHeaders = [
\r
119 {name: 'Widget Name', value: 'name', isSortable: false}
\r
121 $scope.widgetsList = [];
\r
124 this.filterByDropdownValue = item => {
\r
125 if(this.filterByApp.value === '')
\r
128 for(var i = 0; i < item.appName.length; i++){
\r
129 if(item.appName[i] == this.filterByApp.value
\r
130 || item.appName[i] == 'All Applications'){
\r
137 this.openWidgetCatalogDetailsModal = (selectedWidget) => {
\r
139 if(selectedWidget){
\r
140 if(!selectedWidget.id){
\r
141 $log.error('WidgetOnboardingCtrl:openWidgetCatalogDetailModal: widget id not found');
\r
145 widget: selectedWidget
\r
149 templateUrl: 'app/views/widget-onboarding/widget-details-dialog/widget-details.modal.html',
\r
150 controller: 'WidgetOnboardingDetailsModalCtrl',
\r
151 controllerAs: 'widgetOnboardingDetails',
\r
153 }).closePromise.then(needUpdate => {
\r
154 if(needUpdate.value === true){
\r
155 getOnboardingWidgets();
\r
160 this.deleteWidget = widget => {
\r
162 confirmBoxService.deleteItem(widget.name).then(isConfirmed => {
\r
164 if(!widget || !widget.id){
\r
165 $log.error('WidgetOnboardingCtrl::deleteWidget: No widget or ID... cannot delete');
\r
168 widgetsCatalogService.deleteWidget(widget.id).then(() => {
\r
169 $scope.widgetsList.splice($scope.widgetsList.indexOf(widget), 1);
\r
171 $log.error('WidgetOnboardingCtrl::deleteWidget error:',err);
\r
175 $log.error('WidgetOnboardingCtrl::deleteWidget error:',err);
\r
181 this.downloadWidget = widget => {
\r
182 widgetsCatalogService.downloadWidgetFile(widget.id).then(res => {
\r
184 var filename = widget.name + ".zip";
\r
186 if (data == undefined || data == null){
\r
187 confirmBoxService.showInformation("Could not download. Please retry.");
\r
190 var a = document.createElement('a');
\r
191 var blob = new Blob([data], {type: 'application/octet-stream'});
\r
192 a.href = URL.createObjectURL(blob);
\r
193 a.download = filename;
\r
201 WidgetOnboardingCtrl.$inject = ['$log', 'applicationsService', 'widgetsCatalogService', 'ngDialog', 'confirmBoxService',
\r
202 'userProfileService','$cookies', '$scope'];
\r
203 angular.module('ecompApp').controller('WidgetOnboardingCtrl', WidgetOnboardingCtrl);
\r