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============================================
41 constructor($log, applicationsService, widgetsService, ngDialog, confirmBoxService,
42 userProfileService, $cookies, $scope, $rootScope) {
43 //$log.info('WidgetsCtrl::init: Starting Up');
44 $scope.infoMessage = true;
45 $rootScope.noWidgets = false;
47 let populateAvailableApps = widgets => {
48 let allPortalsFilterObject = {index: 0, title: 'All applications', value: ''};
49 this.availableApps = [allPortalsFilterObject];
50 this.filterByApp = this.availableApps[0];
51 applicationsService.getAppsForSuperAdminAndAccountAdmin().then(myApps => {
52 var reSortedApp = myApps.sort(getSortOrder("name"));
54 for (let i = 1; i <= reSortedApp.length; i++) {
55 if (!reSortedApp[i-1].restrictedApp) {
56 $log.debug('WidgetsCtrl::populateAvailableApps: pushing {index: ', realAppIndex, 'title: ', reSortedApp[i - 1].name,
57 'value: ', reSortedApp[i - 1].name, '}');
58 this.availableApps.push({
60 title: reSortedApp[i - 1].name,
61 value: reSortedApp[i - 1].name
63 realAppIndex = realAppIndex + 1;
71 let getOnboardingWidgets = () => {
72 this.isLoadingTable = true;
73 widgetsService.getManagedWidgets().then(res => {
74 $log.debug('WidgetsCtrl.getOnboardingWidgets:: ' + JSON.stringify(res));
75 // if (JSON.stringify(res) === '[]') {
76 // confirmBoxService.showInformation('There are currently no Widgets. ').then(isConfirmed => {});
78 var reSortedWidget = res.sort(getSortOrder("name"));
79 this.widgetsList = reSortedWidget;
80 populateAvailableApps(reSortedWidget);
81 // $log.info('WidgetsHomeCtrl::getUserWidgets count : ' + $scope.widgetsList.length);
82 if (Object.keys(res).length === 0 ) {
83 $rootScope.noWidgets = true;
84 $scope.isLoadingTable = false;
85 $log.info('WidgetsHomeCtrl::getUserWidgets: There are no available Widgets');
88 confirmBoxService.showInformation('There was a problem retrieving the Widgets. ' +
89 'Please try again later.').then(isConfirmed => {});
90 $log.error('WidgetsCtrl::getOnboardingWidgets error: ' + err);
92 this.isLoadingTable = false;
96 // Refactor this into a directive
97 let getSortOrder = (prop) => {
98 return function(a, b) {
99 // $log.debug('a = ' + JSON.stringify(a) + "| b = " + JSON.stringify(b));
100 if (a[prop].toLowerCase() > b[prop].toLowerCase()) {
102 } else if (a[prop].toLowerCase() < b[prop].toLowerCase()) {
109 $scope.hideMe = function () {
110 $scope.infoMessage = false;
114 this.isLoadingTable = false;
115 getOnboardingWidgets();
117 /*Table general configuration params*/
118 this.searchString = '';
120 this.widgetsTableHeaders = [
121 {name: 'Widget Name', value: 'name', isSortable: false},
122 {name: 'Application', value: 'appName', isSortable: true},
123 {name: 'Width', value: 'width', isSortable: false},
124 {name: 'Height', value: 'height', isSortable: false}
126 this.widgetsList = [];
129 this.filterByDropdownValue = item => {
130 if(this.filterByApp.value === ''){
133 return item.appName === this.filterByApp.value;
136 this.openWidgetDetailsModal = (selectedWidget) => {
139 if(!selectedWidget.id){
140 $log.error('Widget id not found');
144 widget: selectedWidget
148 templateUrl: 'app/views/widgets/widget-details-dialog/widget-details.modal.html',
149 controller: 'WidgetDetailsModalCtrl',
150 controllerAs: 'widgetDetails',
152 }).closePromise.then(needUpdate => {
153 if(needUpdate.value === true){
154 $log.debug('WidgetsCtrl::openWidgetDetailsModal: updating table data...');
155 getOnboardingWidgets();
160 this.deleteWidget = widget => {
161 confirmBoxService.deleteItem(widget.name).then(isConfirmed => {
163 if(!widget || !widget.id){
164 $log.error('WidgetsCtrl::deleteWidget: No widget or ID... cannot delete');
167 widgetsService.deleteWidget(widget.id).then(() => {
168 this.widgetsList.splice(this.widgetsList.indexOf(widget), 1);
170 $log.error('WidgetsCtrl::deleteWidget error:',err);
171 confirmBoxService.showInformation('There was a problem deleting the Widget. ' +
172 'Please try again later.').then(isConfirmed => {});
176 $log.error('WidgetsCtrl::deleteWidget error:',err);
183 WidgetsCtrl.$inject = ['$log', 'applicationsService', 'widgetsService', 'ngDialog', 'confirmBoxService',
184 'userProfileService','$cookies', '$scope', '$rootScope'];
185 angular.module('ecompApp').controller('WidgetsCtrl', WidgetsCtrl);