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============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
41 class WidgetCatalogCtrl {
42 constructor(widgetsService, $log, $cookies, $scope, conf, beReaderService, widgetsCatalogService, userProfileService,dashboardService,$compile, ngDialog) {
44 $scope.editWidgetModalPopup = function(availableData, resourceType) {
45 $scope.editData = JSON.stringify(availableData);
46 $scope.availableDataTemp = $scope.availableData;
48 templateUrl : 'app/views/dashboard/dashboard-widget-manage.html',
49 controller : 'CommonWidgetController',
51 message : function message() {
54 availableData : $scope.editData
59 }).closePromise.then(needUpdate => {
60 if(resourceType=='NEWS'){
62 }else if(resourceType=='EVENTS'){
63 $scope.updateEvents();
64 }else if(resourceType=='IMPORTANTRESOURCES'){
65 $scope.updateImportRes();
70 $scope.WidgetCatView = [];
71 $scope.applyPresentationDetailsToWidgetsCatalog = function(widgetsReturned){
73 for (var i = 0; i < widgetsReturned.length; i++) {
74 $scope.WidgetCatView[i] = {
78 widgetIdentifier : '',
84 $scope.WidgetCatView[i].widgetid = widgetsReturned[i].id;
85 $scope.WidgetCatView[i].headerText = widgetsReturned[i].headerName;
87 if(widgetsReturned[i].headerName === 'widget-news'){
88 $scope.WidgetCatView[i].widgetIdentifier = 'NEWS';
91 if(widgetsReturned[i].headerName === 'widget-resources'){
92 $scope.WidgetCatView[i].widgetIdentifier = 'IMPORTANTRESOURCES';
95 if(widgetsReturned[i].headerName === 'widget-events'){
96 $scope.WidgetCatView[i].widgetIdentifier = 'EVENTS';
99 $scope.WidgetCatView[i].url = widgetsReturned[i].url;
100 $scope.WidgetCatView[i].attrb = widgetsReturned[i].attrs;
101 $scope.WidgetCatView[i].select = widgetsReturned[i].select;
104 $scope.widgetViewData = $scope.WidgetCatView;
108 /** Widget code starts */
109 let getUserWidgets = (loginName) => {
111 this.isCommError = false;
112 var conf = this.conf;
113 widgetsCatalogService.getUserWidgets(loginName).then(res => {
115 if(!(res instanceof Array)){
116 this.isCommError = true;
119 for(var i = 0; i < res.length; i++){
120 var widget_id = res[i][0];
121 var widget_name = res[i][1];
122 let url = this.conf.api.widgetCommon + "/" + widget_id + "/framework.js";
123 $scope.widgetsList.push({
126 headerName: widget_name,
128 attrs: [{attr: 'data-' + widget_id, value: ''}],
130 select: (res[i][4] == 'S' || res[i][4] === null) ? true : false
132 var script = document
133 .createElement('script');
137 .getElementsByTagName('script')[0];
139 .insertBefore(script, entry);
141 $scope.applyPresentationDetailsToWidgetsCatalog($scope.widgetsList);
143 $log.error('WidgetCatalogCtrl::getUserWidgets caught error', err);
150 userProfileService.getUserProfile()
152 // $log.info('WidgetCatalogCtrl::getUserProfile: ',
154 $scope.orgUserId = profile.orgUserId;
155 $scope.widgetsViewData = [];
156 $scope.widgetsView = [];
157 getUserWidgets($scope.orgUserId);
160 $scope.widgetsList = [];
163 /** Widget code ends */
165 $scope.activateThis = function(ele){
166 $compile(ele.contents())($scope);
169 $scope.setCommonWidget = function() {
170 /* News Events Resources */
171 var widgetLength = ($scope.widgetsViewData==null || $scope.widgetsViewData.length==0) ? 0:$scope.widgetsViewData.length;
172 $scope.widgetsViewData[widgetLength] = {
181 $scope.widgetsViewData[widgetLength+1] = {
184 headerText: 'Calendar Events',
190 $scope.widgetsViewData[widgetLength+2] = {
193 headerText: 'Resources',
200 /* Setting News data */
201 $scope.newsData = [];
202 $scope.updateNews = function() {
203 $scope.newsData.length=0;
204 dashboardService.getCommonWidgetData('NEWS').then(function(res) {
205 // $log.info(res.message);
206 var newsDataJsonArray = res.response.items;
207 for (var i = 0; i < newsDataJsonArray.length; i++) {
208 $scope.newsData.push(newsDataJsonArray[i]);
210 })['catch'](function(err) {
211 $log.error('dashboard controller: failed to get news list', err);
215 /* Setting Events data */
217 $scope.eventData = [];
219 $scope.updateEvents = function() {
220 $scope.eventData.length=0;
221 dashboardService.getCommonWidgetData('EVENTS').then(function(res) {
222 var eventDataJsonArray = res.response.items;
223 for (var i = 0; i < eventDataJsonArray.length; i++) {
224 if(eventDataJsonArray[i].eventDate !=null) {
226 eventDataJsonArray[i].year = eventDataJsonArray[i].eventDate.substring(2,4);
227 eventDataJsonArray[i].mon = eventDataJsonArray[i].eventDate.substring(5,7);
228 eventDataJsonArray[i].day = eventDataJsonArray[i].eventDate.substring(8,10);
230 $scope.eventData.push(eventDataJsonArray[i]);
232 })['catch'](function(err) {
233 $log.error('dashboard controller: failed to get Events list', err);
236 $scope.updateEvents();
237 /* Setting Important Resources data */
239 $scope.importResData = [];
240 $scope.updateImportRes = function() {
241 $scope.importResData.length=0;
242 dashboardService.getCommonWidgetData('IMPORTANTRESOURCES').then(
245 var importResDataJSONArray = res.response.items;
246 for (var i = 0; i < importResDataJSONArray.length; i++) {
247 $scope.importResData.push(importResDataJSONArray[i]);
249 })['catch'](function(err) {
250 $log.error('dashboard controller: failed to get resources list...', err);
253 $scope.updateImportRes();
255 /** ******End hardcoded news events and resources*************** */
259 $scope.newsGridsterItem = {
264 $scope.newsGridsterItem = {
269 $scope.eventsGridsterItem = {
270 headerText : 'Events',
274 $scope.impoResGridsterItem = {
275 headerText : 'Resources',
279 this.gridsterOpts = {
289 handle: '.icon-content-gridguide'
293 // Run this function when user clicks on checkbox.
294 $scope.storeSelection = function(widget) {
296 // not needed as only 'SHOW' and 'HIDE' status_cd is expected from the micro service now
297 /*var pendingFlag = false;
301 pendingFlag = widget.pending; */
304 widgetId: widget.widgetid,
305 select : widget.select,
306 // pending : pendingFlag
309 widgetsCatalogService.updateWidgetCatalog(appData).then(
311 // $log.debug('CatalogCtrl:storeSelection result is ', result);
312 })['catch'](function(err) {
313 $log.error('CatalogCtrl:storeSelection: exception: ', err);
323 WidgetCatalogCtrl.$inject = ['widgetsService', '$log', '$cookies', '$scope', 'conf', 'beReaderService', 'widgetsCatalogService', 'userProfileService','dashboardService','$compile','ngDialog'];
324 angular.module('ecompApp').controller('WidgetCatalogCtrl', WidgetCatalogCtrl);
326 angular.module('ecompApp').constant('refreshInterval', '30000');
328 angular.module('ecompApp').directive('refreshIframe', ['$interval', 'refreshInterval', function ($interval, refreshInterval) {
330 function link(scope, element, attrs) {
333 function updateIframe() {
334 if(attrs.isEnlarged == "false")
336 element.attr('src', element.attr('src'));
340 element.on('$destroy', function () {
341 $interval.cancel(timeoutId);
344 // start the UI update process; save the timeoutId for cancelling
346 * timeoutId = $interval(function () { updateIframe(); // update DOM },
359 app.directive('dynAttr', function() {
361 scope: { list: '=dynAttr' },
362 link: function(scope, elem, attrs){
363 for(var attr in scope.list){
364 elem.attr(scope.list[attr].attr, scope.list[attr].value);