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) {
25 $log.info('WidgetsCtrl::init: Starting Up');
26 $scope.infoMessage = true;
28 let populateAvailableApps = widgets => {
29 let allPortalsFilterObject = {index: 0, title: 'All applications', value: ''};
30 this.availableApps = [allPortalsFilterObject];
31 this.filterByApp = this.availableApps[0];
32 applicationsService.getAppsForSuperAdminAndAccountAdmin().then(myApps => {
33 var reSortedApp = myApps.sort(getSortOrder("name"));
35 for (let i = 1; i <= reSortedApp.length; i++) {
36 if (!reSortedApp[i-1].restrictedApp) {
37 $log.debug('WidgetsCtrl::populateAvailableApps: pushing {index: ', realAppIndex, 'title: ', reSortedApp[i - 1].name,
38 'value: ', reSortedApp[i - 1].name, '}');
39 this.availableApps.push({
41 title: reSortedApp[i - 1].name,
42 value: reSortedApp[i - 1].name
44 realAppIndex = realAppIndex + 1;
52 let getOnboardingWidgets = () => {
53 this.isLoadingTable = true;
54 widgetsService.getManagedWidgets().then(res => {
55 var reSortedWidget = res.sort(getSortOrder("name"));
56 this.widgetsList = reSortedWidget;
57 populateAvailableApps(reSortedWidget);
59 $log.error('WidgetsCtrl::getOnboardingWidgets error: ' + err);
61 this.isLoadingTable = false;
65 let getSortOrder = (prop) => {
66 return function(a, b) {
67 if (a[prop].toLowerCase() > b[prop].toLowerCase()) {
69 } else if (a[prop].toLowerCase() < b[prop].toLowerCase()) {
76 $scope.hideMe = function () {
77 $scope.infoMessage = false;
81 this.isLoadingTable = false;
82 getOnboardingWidgets();
85 this.searchString = '';
87 this.widgetsTableHeaders = [
88 {name: 'Widget Name', value: 'name', isSortable: false},
89 {name: 'Application', value: 'appName', isSortable: true},
90 {name: 'Width', value: 'width', isSortable: false},
91 {name: 'Height', value: 'height', isSortable: false}
93 this.widgetsList = [];
96 this.filterByDropdownValue = item => {
97 if(this.filterByApp.value === ''){
100 return item.appName === this.filterByApp.value;
103 this.openWidgetDetailsModal = (selectedWidget) => {
106 if(!selectedWidget.id){
107 $log.error('Widget id not found');
111 widget: selectedWidget
115 templateUrl: 'app/views/widgets/widget-details-dialog/widget-details.modal.html',
116 controller: 'WidgetDetailsModalCtrl',
117 controllerAs: 'widgetDetails',
119 }).closePromise.then(needUpdate => {
120 if(needUpdate.value === true){
121 $log.debug('WidgetsCtrl::openWidgetDetailsModal: updating table data...');
122 getOnboardingWidgets();
127 this.deleteWidget = widget => {
128 confirmBoxService.deleteItem(widget.name).then(isConfirmed => {
130 if(!widget || !widget.id){
131 $log.error('WidgetsCtrl::deleteWidget: No widget or ID... cannot delete');
134 widgetsService.deleteWidget(widget.id).then(() => {
135 this.widgetsList.splice(this.widgetsList.indexOf(widget), 1);
137 $log.error('WidgetsCtrl::deleteWidget error:',err);
141 $log.error('WidgetsCtrl::deleteWidget error:',err);
148 WidgetsCtrl.$inject = ['$log', 'applicationsService', 'widgetsService', 'ngDialog', 'confirmBoxService',
149 'userProfileService','$cookies', '$scope'];
150 angular.module('ecompApp').controller('WidgetsCtrl', WidgetsCtrl);