4 class WidgetsHomeCtrl {
5 constructor(widgetsService, $log, $cookies, $scope, userProfileService,dashboardService) {
6 this.userProfileService = userProfileService;
9 userProfileService.getUserProfile()
11 $log.info('WidgetsHomeCtrl::getUserProfile: ', profile);
12 $scope.attuid = profile.attuid;
13 $log.info('WidgetsHomeCtrl::getUserProfile: user has the following attuid: ' + profile.attuid);
14 $scope.widgetsViewData = [];
15 $scope.widgetsView = [];
17 widgetsService.getUserWidgets()
19 $log.info('WidgetsHomeCtrl::getUserWidgets', widgets);
20 this.widgets = widgets;
22 this.isEnlarged = false;
24 for (let i = 0; i < this.widgets.length; i++) {
25 $scope.widgetsView[i] = {
34 $scope.widgetsView[i].headerText = this.widgets[i].name;
35 $scope.widgetsView[i].url = this.widgets[i].url;
36 //$scope.widgetsView[i].width = this.widgets[i].width;
37 //$scope.widgetsView[i].height = this.widgets[i].height;
38 //$scope.widgetsView[i].sizeX = this.widgets[i].width/180;
39 //$scope.widgetsView[i].sizeY = this.widgets[i].height/150;
41 /*News Events Resources*/
42 $scope.widgetsView[this.widgets.length] = {
51 $scope.widgetsView[this.widgets.length+1] = {
60 $scope.widgetsView[this.widgets.length+2] = {
63 headerText: 'Resources',
72 $scope.updateNews = function() {
73 $scope.newsData.length=0;
74 dashboardService.getCommonWidgetData('NEWS').then(function(res) {
75 // $log.info(res.message);
76 var newsDataJsonArray = res.response.items;
77 for (var i = 0; i < newsDataJsonArray.length; i++) {
78 $scope.newsData.push(newsDataJsonArray[i]);
80 })['catch'](function(err) {
81 $log.error('dashboard controller: failed to get news list', err);
82 _this.isLoading = false;
86 /*Setting Events data*/
88 $scope.eventData = [];
90 $scope.updateEvents = function() {
91 $scope.eventData.length=0;
92 dashboardService.getCommonWidgetData('EVENTS').then(function(res) {
93 var eventDataJsonArray = res.response.items;
94 for (var i = 0; i < eventDataJsonArray.length; i++) {
95 if(eventDataJsonArray[i].eventDate !=null) {
97 eventDataJsonArray[i].year = eventDataJsonArray[i].eventDate.substring(2,4);
98 eventDataJsonArray[i].mon = eventDataJsonArray[i].eventDate.substring(5,7);
99 eventDataJsonArray[i].day = eventDataJsonArray[i].eventDate.substring(8,10);
101 $scope.eventData.push(eventDataJsonArray[i]);
103 })['catch'](function(err) {
104 $log.error('dashboard controller: failed to get Events list', err);
105 _this.isLoading = false;
108 $scope.updateEvents();
109 /*Setting Important Resources data*/
111 $scope.importResData = [];
112 $scope.updateImportRes = function() {
113 $scope.importResData.length=0;
114 dashboardService.getCommonWidgetData('IMPORTANTRESOURCES').then(
116 // $log.error('couldnt get important list...', res.response.dataBlob);
118 var importResDataJSONArray = res.response.items;
119 for (var i = 0; i < importResDataJSONArray.length; i++) {
120 $scope.importResData.push(importResDataJSONArray[i]);
122 })['catch'](function(err) {
123 $log.error('dashboard controller: failed to get resources list...', err);
124 _this.isLoading = false;
127 $scope.updateImportRes();
129 /********End hardcoded news events and resources****************/
132 $log.info('WidgetsHomeCtrl::getUserWidgets count : ' + $scope.widgetsView.length);
134 if ($cookies.getObject($scope.attuid + '_widget') == undefined || $cookies.getObject($scope.attuid + '_widget') == null || $cookies.getObject($scope.attuid + '_widget').length == 0) {
135 if (($scope.widgetsView != undefined) && ($scope.widgetsView != null) && ($scope.widgetsView.length > 0)) {
136 $scope.widgetsViewData = $scope.widgetsView;
137 //$cookies.putObject($scope.attuid + '_widget', $scope.widgetsView);
141 this.listChanged = false;
142 this.listFromCookie = $cookies.getObject($scope.attuid + '_widget');
145 // If a widget is still valid for this user from backend and
146 // it was in the cookie already, put it in the list in the same order
147 // it was in within the cookie.
150 for (let i = 0; i < this.listFromCookie.length; i++) {
151 this.foundInListFromBackend = false;
152 for (let j = 0; j < $scope.widgetsView.length; j++) {
153 if ((this.listFromCookie[i].url == $scope.widgetsView[j].url) &&
154 (this.listFromCookie[i].headerText == $scope.widgetsView[j].headerText)) {
155 this.finalList[finalCount] = {
164 this.finalList[finalCount].headerText = this.listFromCookie[i].headerText;
165 //this.finalList[finalCount].width = this.listFromCookie[i].width;
166 //this.finalList[finalCount].height = this.listFromCookie[i].height;
167 this.finalList[finalCount].url = this.listFromCookie[i].url;
168 //this.finalList[finalCount].sizeX = this.listFromCookie[i].width/180;
169 //this.finalList[finalCount].sizeY = this.listFromCookie[i].height/150;
171 this.foundInListFromBackend = true;
175 if (this.foundInListFromBackend == false) {
176 this.listChanged = true;
181 // Fill in the rest of the list with the widgets retrieved from the backend that we did
182 // not already add. There could have been
183 // new widgets configured for the user that are not in the cookie.
185 for (let i = 0; i < $scope.widgetsView.length; i++) {
187 for (let j = 0; j < this.finalList.length; j++) {
188 if (($scope.widgetsView[i].url == this.finalList[j].url) &&
189 ($scope.widgetsView[i].headerText == this.finalList[j].headerText)){
195 if (this.found == false) {
196 this.finalList[finalCount] = {
205 this.finalList[finalCount].headerText = $scope.widgetsView[i].headerText;
206 //this.finalList[finalCount].width = $scope.widgetsView[i].width;
207 //this.finalList[finalCount].height = $scope.widgetsView[i].height;
208 this.finalList[finalCount].url = $scope.widgetsView[i].url;
209 //this.finalList[finalCount].sizeX = $scope.widgetsView[i].width/180;
210 //this.finalList[finalCount].sizeY = $scope.widgetsView[i].height/150;
212 this.listChanged = true;
216 if ((this.finalList != undefined) && (this.finalList != null) && (this.finalList.length > 0)) {
217 if (this.listChanged) {
218 $scope.widgetsViewData = this.finalList;
219 $cookies.putObject($scope.attuid + '_widget', this.finalList);
221 $scope.widgetsViewData = $cookies.getObject($scope.attuid + '_widget');
224 this.isLoading = false;
227 $log.error('WidgetsHomeCtrl::getUserWidgets: oh no! couldnt get widgets list...', err);
228 this.isLoading = false;
233 this.gridsterOpts = {
245 $cookies.putObject($scope.attuid + '_widget', $scope.widgetsViewData);
252 WidgetsHomeCtrl.$inject = ['widgetsService', '$log', '$cookies', '$scope', 'userProfileService','dashboardService'];
253 angular.module('ecompApp').controller('WidgetsHomeCtrl', WidgetsHomeCtrl);
255 angular.module('ecompApp').constant('refreshInterval', '30000');
257 angular.module('ecompApp').directive('refreshIframe', ['$interval', 'refreshInterval', function ($interval, refreshInterval) {
259 function link(scope, element, attrs) {
262 function updateIframe() {
263 if(attrs.isEnlarged == "false")
265 element.attr('src', element.attr('src'));
269 element.on('$destroy', function () {
270 $interval.cancel(timeoutId);
273 // start the UI update process; save the timeoutId for cancelling
274 /*timeoutId = $interval(function () {
275 updateIframe(); // update DOM
276 }, refreshInterval);*/