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 WidgetOnboardingCtrl {
41 constructor($log, applicationsService, widgetsCatalogService, ngDialog, confirmBoxService,
42 userProfileService, $cookies, $scope,$modal) {
43 $scope.infoMessage = true;
45 let populateAvailableApps = widgets => {
46 let allPortalsFilterObject = {index: 0, title: 'All Applications', value: ''};
47 this.availableApps = [allPortalsFilterObject];
48 this.filterByApp = this.availableApps[0];
49 applicationsService.getAppsForSuperAdminAndAccountAdmin().then(myApps => {
50 var reSortedApp = myApps.sort(getSortOrder("name"));
52 for (let i = 1; i <= reSortedApp.length; i++) {
53 if (!reSortedApp[i-1].restrictedApp) {
54 this.availableApps.push({
56 title: reSortedApp[i - 1].name,
57 value: reSortedApp[i - 1].name
59 realAppIndex = realAppIndex + 1;
63 $log.error('WidgetOnboardingCtrl:getAppsForSuperAdmin failed', err);
67 let getOnboardingWidgets = () => {
68 this.isLoadingTable = true;
69 this.isCommError = false;
70 widgetsCatalogService.getManagedWidgets().then(res => {
71 if(!(res instanceof Array)){
72 this.isCommError = true;
76 var reSortedWidget = res.sort(getSortOrder("name"));
77 $scope.widgetsList = reSortedWidget;
78 for(var i = 0; i < $scope.widgetsList.length; i++){
83 for(var n = 0; n < $scope.widgetsList[i].widgetRoles.length; n++){
84 set.add($scope.widgetsList[i].widgetRoles[n].app.appName);
86 if($scope.widgetsList[i].allowAllUser == "Y"){
87 info = "All Applications";
88 appContent.push("All Applications");
89 appName.push("All Applications");
92 set.forEach(function (item) {
93 info = item.toString() + " - ";
94 for(var n = 0; n < $scope.widgetsList[i].widgetRoles.length; n++){
95 if(item.toString() == $scope.widgetsList[i].widgetRoles[n].app.appName){
96 info += $scope.widgetsList[i].widgetRoles[n].roleName + "; ";
99 appContent.push(info);
100 appName.push(item.toString());
102 $scope.widgetsList[i].appContent = appContent;
103 $scope.widgetsList[i].appName = appName;
105 populateAvailableApps(reSortedWidget);
107 // Land here when the micro service is down
108 $log.error('WidgetOnboardingCtrl::getOnboardingWidgets caught error', err);
110 this.isLoadingTable = false;
116 // Refactor this into a directive
117 let getSortOrder = (prop) => {
118 return function(a, b) {
119 if (a[prop].toLowerCase() > b[prop].toLowerCase()) {
121 } else if (a[prop].toLowerCase() < b[prop].toLowerCase()) {
128 $scope.hideMe = function () {
129 $scope.infoMessage = false;
133 this.isLoadingTable = false;
134 getOnboardingWidgets();
135 this.searchString = '';
136 this.widgetsTableHeaders = [
137 {name: 'Widget Name', value: 'name', isSortable: false}
139 $scope.widgetsList = [];
142 this.filterByDropdownValue = item => {
143 if(this.filterByApp.value === '' || this.filterByApp.value === 'All Applications')
146 for(var i = 0; i < item.appName.length; i++){
147 if(item.appName[i] == this.filterByApp.value
148 || item.appName[i] == 'All Applications'){
155 this.openWidgetCatalogDetailsModal = (selectedWidget) => {
158 if(!selectedWidget.id){
159 $log.error('WidgetOnboardingCtrl:openWidgetCatalogDetailModal: widget id not found');
163 widget: selectedWidget
166 var modalInstance = $modal.open({
167 templateUrl: 'app/views/widget-onboarding/widget-details-dialog/widget-details.modal.html',
168 controller: 'WidgetOnboardingDetailsModalCtrl as widgetOnboardingDetails',
169 sizeClass: 'modal-medium',
177 modalInstance.result.finally(function () {
178 getOnboardingWidgets();
182 this.deleteWidget = widget => {
184 confirmBoxService.deleteItem(widget.name).then(isConfirmed => {
186 if(!widget || !widget.id){
187 $log.error('WidgetOnboardingCtrl::deleteWidget: No widget or ID... cannot delete');
190 widgetsCatalogService.deleteWidget(widget.id).then(() => {
191 $scope.widgetsList.splice($scope.widgetsList.indexOf(widget), 1);
193 $log.error('WidgetOnboardingCtrl::deleteWidget error:',err);
197 $log.error('WidgetOnboardingCtrl::deleteWidget error:',err);
203 this.downloadWidget = widget => {
204 widgetsCatalogService.downloadWidgetFile(widget.id).then(res => {
206 var filename = widget.name + ".zip";
208 if (data == undefined || data == null){
209 confirmBoxService.showInformation("Could not download. Please retry.");
212 var a = document.createElement('a');
213 var blob = new Blob([data], {type: 'application/octet-stream'});
214 var url = window.URL.createObjectURL(blob);
216 a.download = filename;
217 document.body.appendChild(a);
220 setTimeout(function(){
221 document.body.removeChild(a);
222 window.URL.revokeObjectURL(url);
231 WidgetOnboardingCtrl.$inject = ['$log', 'applicationsService', 'widgetsCatalogService', 'ngDialog', 'confirmBoxService',
232 'userProfileService','$cookies', '$scope','$modal'];
233 angular.module('ecompApp').controller('WidgetOnboardingCtrl', WidgetOnboardingCtrl);