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