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 * ================================================================================
23 constructor($log, applicationsService, widgetsService, ngDialog, confirmBoxService,
24 userProfileService, $cookies, $scope, $rootScope) {
25 //$log.info('WidgetsCtrl::init: Starting Up');
26 $scope.infoMessage = true;
27 $rootScope.noWidgets = false;
29 let populateAvailableApps = widgets => {
30 let allPortalsFilterObject = {index: 0, title: 'All applications', value: ''};
31 this.availableApps = [allPortalsFilterObject];
32 this.filterByApp = this.availableApps[0];
33 applicationsService.getAppsForSuperAdminAndAccountAdmin().then(myApps => {
34 var reSortedApp = myApps.sort(getSortOrder("name"));
36 for (let i = 1; i <= reSortedApp.length; i++) {
37 if (!reSortedApp[i-1].restrictedApp) {
38 $log.debug('WidgetsCtrl::populateAvailableApps: pushing {index: ', realAppIndex, 'title: ', reSortedApp[i - 1].name,
39 'value: ', reSortedApp[i - 1].name, '}');
40 this.availableApps.push({
42 title: reSortedApp[i - 1].name,
43 value: reSortedApp[i - 1].name
45 realAppIndex = realAppIndex + 1;
53 let getOnboardingWidgets = () => {
54 this.isLoadingTable = true;
55 widgetsService.getManagedWidgets().then(res => {
56 $log.debug('WidgetsCtrl.getOnboardingWidgets:: ' + JSON.stringify(res));
57 // if (JSON.stringify(res) === '[]') {
58 // confirmBoxService.showInformation('There are currently no Widgets. ').then(isConfirmed => {});
60 var reSortedWidget = res.sort(getSortOrder("name"));
61 this.widgetsList = reSortedWidget;
62 populateAvailableApps(reSortedWidget);
63 // $log.info('WidgetsHomeCtrl::getUserWidgets count : ' + $scope.widgetsList.length);
64 if (Object.keys(res).length === 0 ) {
65 $rootScope.noWidgets = true;
66 $scope.isLoadingTable = false;
67 $log.info('WidgetsHomeCtrl::getUserWidgets: There are no available Widgets');
70 confirmBoxService.showInformation('There was a problem retrieving the Widgets. ' +
71 'Please try again later.').then(isConfirmed => {});
72 $log.error('WidgetsCtrl::getOnboardingWidgets error: ' + err);
74 this.isLoadingTable = false;
78 // Refactor this into a directive
79 let getSortOrder = (prop) => {
80 return function(a, b) {
81 // $log.debug('a = ' + JSON.stringify(a) + "| b = " + JSON.stringify(b));
82 if (a[prop].toLowerCase() > b[prop].toLowerCase()) {
84 } else if (a[prop].toLowerCase() < b[prop].toLowerCase()) {
91 $scope.hideMe = function () {
92 $scope.infoMessage = false;
96 this.isLoadingTable = false;
97 getOnboardingWidgets();
99 /*Table general configuration params*/
100 this.searchString = '';
102 this.widgetsTableHeaders = [
103 {name: 'Widget Name', value: 'name', isSortable: false},
104 {name: 'Application', value: 'appName', isSortable: true},
105 {name: 'Width', value: 'width', isSortable: false},
106 {name: 'Height', value: 'height', isSortable: false}
108 this.widgetsList = [];
111 this.filterByDropdownValue = item => {
112 if(this.filterByApp.value === ''){
115 return item.appName === this.filterByApp.value;
118 this.openWidgetDetailsModal = (selectedWidget) => {
121 if(!selectedWidget.id){
122 $log.error('Widget id not found');
126 widget: selectedWidget
130 templateUrl: 'app/views/widgets/widget-details-dialog/widget-details.modal.html',
131 controller: 'WidgetDetailsModalCtrl',
132 controllerAs: 'widgetDetails',
134 }).closePromise.then(needUpdate => {
135 if(needUpdate.value === true){
136 $log.debug('WidgetsCtrl::openWidgetDetailsModal: updating table data...');
137 getOnboardingWidgets();
142 this.deleteWidget = widget => {
143 confirmBoxService.deleteItem(widget.name).then(isConfirmed => {
145 if(!widget || !widget.id){
146 $log.error('WidgetsCtrl::deleteWidget: No widget or ID... cannot delete');
149 widgetsService.deleteWidget(widget.id).then(() => {
150 this.widgetsList.splice(this.widgetsList.indexOf(widget), 1);
152 $log.error('WidgetsCtrl::deleteWidget error:',err);
153 confirmBoxService.showInformation('There was a problem deleting the Widget. ' +
154 'Please try again later.').then(isConfirmed => {});
158 $log.error('WidgetsCtrl::deleteWidget error:',err);
165 WidgetsCtrl.$inject = ['$log', 'applicationsService', 'widgetsService', 'ngDialog', 'confirmBoxService',
166 'userProfileService','$cookies', '$scope', '$rootScope'];
167 angular.module('ecompApp').controller('WidgetsCtrl', WidgetsCtrl);