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 class WidgetCatalogCtrl {
24 constructor(widgetsService, $log, $cookies, $scope, conf, beReaderService, widgetsCatalogService, userProfileService,dashboardService,$compile, ngDialog) {
26 $scope.editWidgetModalPopup = function(availableData, resourceType) {
27 $scope.editData = JSON.stringify(availableData);
28 $scope.availableDataTemp = $scope.availableData;
30 templateUrl : 'app/views/dashboard/dashboard-widget-manage.html',
31 controller : 'CommonWidgetController',
33 message : function message() {
36 availableData : $scope.editData
41 }).closePromise.then(needUpdate => {
42 if(resourceType=='NEWS'){
44 }else if(resourceType=='EVENTS'){
45 $scope.updateEvents();
46 }else if(resourceType=='IMPORTANTRESOURCES'){
47 $scope.updateImportRes();
52 $scope.WidgetCatView = [];
53 $scope.applyPresentationDetailsToWidgetsCatalog = function(widgetsReturned){
55 for (var i = 0; i < widgetsReturned.length; i++) {
56 $scope.WidgetCatView[i] = {
60 widgetIdentifier : '',
66 $scope.WidgetCatView[i].widgetid = widgetsReturned[i].id;
67 $scope.WidgetCatView[i].headerText = widgetsReturned[i].headerName;
69 if(widgetsReturned[i].headerName === 'widget-news'){
70 $scope.WidgetCatView[i].widgetIdentifier = 'NEWS';
73 if(widgetsReturned[i].headerName === 'widget-resources'){
74 $scope.WidgetCatView[i].widgetIdentifier = 'IMPORTANTRESOURCES';
77 if(widgetsReturned[i].headerName === 'widget-events'){
78 $scope.WidgetCatView[i].widgetIdentifier = 'EVENTS';
81 $scope.WidgetCatView[i].url = widgetsReturned[i].url;
82 $scope.WidgetCatView[i].attrb = widgetsReturned[i].attrs;
83 $scope.WidgetCatView[i].select = widgetsReturned[i].select;
86 $scope.widgetViewData = $scope.WidgetCatView;
90 /** Widget code starts */
91 let getUserWidgets = (loginName) => {
93 this.isCommError = false;
95 widgetsCatalogService.getUserWidgets(loginName).then(res => {
97 if(!(res instanceof Array)){
98 this.isCommError = true;
101 for(var i = 0; i < res.length; i++){
102 var widget_id = res[i][0];
103 var widget_name = res[i][1];
104 let url = this.conf.api.widgetCommon + "/" + widget_id + "/framework.js";
105 $scope.widgetsList.push({
108 headerName: widget_name,
110 attrs: [{attr: 'data-' + widget_id, value: ''}],
112 select: (res[i][4] == 'S' || res[i][4] === null) ? true : false
114 var script = document
115 .createElement('script');
119 .getElementsByTagName('script')[0];
121 .insertBefore(script, entry);
123 $scope.applyPresentationDetailsToWidgetsCatalog($scope.widgetsList);
125 $log.error('WidgetCatalogCtrl::getUserWidgets caught error', err);
132 userProfileService.getUserProfile()
134 // $log.info('WidgetCatalogCtrl::getUserProfile: ',
136 $scope.orgUserId = profile.orgUserId;
137 $scope.widgetsViewData = [];
138 $scope.widgetsView = [];
139 getUserWidgets($scope.orgUserId);
142 $scope.widgetsList = [];
145 /** Widget code ends */
147 $scope.activateThis = function(ele){
148 $compile(ele.contents())($scope);
151 $scope.setCommonWidget = function() {
152 /* News Events Resources */
153 var widgetLength = ($scope.widgetsViewData==null || $scope.widgetsViewData.length==0) ? 0:$scope.widgetsViewData.length;
154 $scope.widgetsViewData[widgetLength] = {
163 $scope.widgetsViewData[widgetLength+1] = {
166 headerText: 'Calendar Events',
172 $scope.widgetsViewData[widgetLength+2] = {
175 headerText: 'Resources',
182 /* Setting News data */
183 $scope.newsData = [];
184 $scope.updateNews = function() {
185 $scope.newsData.length=0;
186 dashboardService.getCommonWidgetData('NEWS').then(function(res) {
187 // $log.info(res.message);
188 var newsDataJsonArray = res.response.items;
189 for (var i = 0; i < newsDataJsonArray.length; i++) {
190 $scope.newsData.push(newsDataJsonArray[i]);
192 })['catch'](function(err) {
193 $log.error('dashboard controller: failed to get news list', err);
197 /* Setting Events data */
199 $scope.eventData = [];
201 $scope.updateEvents = function() {
202 $scope.eventData.length=0;
203 dashboardService.getCommonWidgetData('EVENTS').then(function(res) {
204 var eventDataJsonArray = res.response.items;
205 for (var i = 0; i < eventDataJsonArray.length; i++) {
206 if(eventDataJsonArray[i].eventDate !=null) {
208 eventDataJsonArray[i].year = eventDataJsonArray[i].eventDate.substring(2,4);
209 eventDataJsonArray[i].mon = eventDataJsonArray[i].eventDate.substring(5,7);
210 eventDataJsonArray[i].day = eventDataJsonArray[i].eventDate.substring(8,10);
212 $scope.eventData.push(eventDataJsonArray[i]);
214 })['catch'](function(err) {
215 $log.error('dashboard controller: failed to get Events list', err);
218 $scope.updateEvents();
219 /* Setting Important Resources data */
221 $scope.importResData = [];
222 $scope.updateImportRes = function() {
223 $scope.importResData.length=0;
224 dashboardService.getCommonWidgetData('IMPORTANTRESOURCES').then(
227 var importResDataJSONArray = res.response.items;
228 for (var i = 0; i < importResDataJSONArray.length; i++) {
229 $scope.importResData.push(importResDataJSONArray[i]);
231 })['catch'](function(err) {
232 $log.error('dashboard controller: failed to get resources list...', err);
235 $scope.updateImportRes();
237 /** ******End hardcoded news events and resources*************** */
241 $scope.newsGridsterItem = {
246 $scope.newsGridsterItem = {
251 $scope.eventsGridsterItem = {
252 headerText : 'Events',
256 $scope.impoResGridsterItem = {
257 headerText : 'Resources',
261 this.gridsterOpts = {
271 handle: '.icon-content-gridguide'
275 // Run this function when user clicks on checkbox.
276 $scope.storeSelection = function(widget) {
278 // not needed as only 'SHOW' and 'HIDE' status_cd is expected from the micro service now
279 /*var pendingFlag = false;
283 pendingFlag = widget.pending; */
286 widgetId: widget.widgetid,
287 select : widget.select,
288 // pending : pendingFlag
291 widgetsCatalogService.updateWidgetCatalog(appData).then(
293 // $log.debug('CatalogCtrl:storeSelection result is ', result);
294 })['catch'](function(err) {
295 $log.error('CatalogCtrl:storeSelection: exception: ', err);
305 WidgetCatalogCtrl.$inject = ['widgetsService', '$log', '$cookies', '$scope', 'conf', 'beReaderService', 'widgetsCatalogService', 'userProfileService','dashboardService','$compile','ngDialog'];
306 angular.module('ecompApp').controller('WidgetCatalogCtrl', WidgetCatalogCtrl);
308 angular.module('ecompApp').constant('refreshInterval', '30000');
310 angular.module('ecompApp').directive('refreshIframe', ['$interval', 'refreshInterval', function ($interval, refreshInterval) {
312 function link(scope, element, attrs) {
315 function updateIframe() {
316 if(attrs.isEnlarged == "false")
318 element.attr('src', element.attr('src'));
322 element.on('$destroy', function () {
323 $interval.cancel(timeoutId);
326 // start the UI update process; save the timeoutId for cancelling
328 * timeoutId = $interval(function () { updateIframe(); // update DOM },
341 app.directive('dynAttr', function() {
343 scope: { list: '=dynAttr' },
344 link: function(scope, elem, attrs){
345 for(var attr in scope.list){
346 elem.attr(scope.list[attr].attr, scope.list[attr].value);