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