summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-FE/client/app/views/dashboard/dashboard.controller.js
blob: 3228f6368e2cd5e7448b806125f3eff0428d70f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*-
 * ================================================================================
 * eCOMP Portal
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ================================================================================
 */
'use strict';

function _classCallCheck(instance, Constructor) {
	if (!(instance instanceof Constructor)) {
		throw new TypeError('Cannot call a class as a function');
	}
}

(function() {
	var HTTP_PROTOCOL_RGX = /https?:\/\//;

	var DashboardCtrl = function DashboardCtrl(applicationsService, $log,
			$window, userProfileService, $scope, $cookies, $timeout, $interval,
			$modal, $state, dashboardService,ngDialog) {

		var _this = this;

		_classCallCheck(this, DashboardCtrl);

		// activate spinner
		this.isLoading = true;
		$scope.getUserAppsIsDone = false;
		this.userProfileService = userProfileService;
		$scope.demoNum = 1;
		$scope.event_content_show = false;
		$scope.widgetData = [];

		$scope.editWidgetModalPopup = function(availableData, resourceType) {
			$scope.editData = JSON.stringify(availableData);
			$scope.availableDataTemp = $scope.availableData;
			ngDialog.open({
					templateUrl : 'app/views/dashboard/dashboard-widget-manage.html',
					controller : 'CommonWidgetController',
					resolve : {
						message : function message() {
							var message = {
								type : resourceType,
								availableData : $scope.editData
							};
							return message;
						}
					}
				}).closePromise.then(needUpdate => {	
					if(resourceType=='NEWS'){
						$scope.updateNews();
					}else if(resourceType=='EVENTS'){
						$scope.updateEvents();
					}else if(resourceType=='IMPORTANTRESOURCES'){
						$scope.updateImportRes();
					}
	          });		
		};

		userProfileService.getUserProfile()
			.then(
				function(profile) {
					// $log.info(profile);
					$scope.attuid = profile.attuid;
					// $log.info('user has the following attuid: ' +
					// profile.attuid);
					$scope.appsView = [];
					
					applicationsService.getPersUserApps()
						.then(
							function(res) {
							// $log.info(res);
							_this.apps = res;
							
							for (var i = 0; i < _this.apps.length; i++) {
								$scope.appsView[i] = {
									sizeX 			: 2,
									sizeY 			: 2,
									headerText 		: _this.apps[i].name,
									subHeaderText 	: _this.apps[i].notes,
									imageLink 		: _this.apps[i].thumbnail || _this.apps[i].imageUrl,
									order 			: _this.apps[i].order,
									restrictedApp	: _this.apps[i].restrictedApp,
									url 			: _this.apps[i].url
								};
							}
							
							// Append the show add/remove applications tile
							$scope.appsView[_this.apps.length] = {
									addRemoveApps : true,
									sizeX : 2,
									sizeY : 2,
									headerText : 'Add/Remove Applications',
									subHeaderText : '',
									imageLink : 'assets/images/cloud.png',
									order : '',
									restrictedApp : false,
									url : ''
							};
		
							// $log.info('getUserApps apps count : ' +
							// $scope.appsView.length);
							// Show 2 rows in the gridster if needed
							if ($scope.appsView.length > 6) {													
								$(".dashboard-boarder").css({
				    				"height" : "400px"
									});
								}else{
									$(".dashboard-boarder").css({
					    				"height" : "210px"
					    			});
								}
								_this.isLoading = false;
								$scope.getUserAppsIsDone = true;																									
							})['catch']
					(function(err) {
						$log.error('DashboardCtlr: failed to get applications list', err);
						_this.isLoading = false;
						$scope.getUserAppsIsDone = true;
					});
		});


		/* Widget Gridster Section */
		$scope.newsGridsterItem = {
			sizeX : 4,
			sizeY : 4,
			headerText : 'News',
			subHeaderText : '',
			imageLink : '',
			order : '',
			url : ''
		};

		$scope.eventsGridsterItem = {
			sizeX : 4,
			sizeY : 4,
			headerText : 'Calendar Events',
			subHeaderText : '',
			imageLink : '',
			order : '',
			url : ''
		};

		$scope.impoResGridsterItem = {
			sizeX : 4,
			sizeY : 4,
			headerText : 'Resources',
			subHeaderText : '',
			imageLink : '',
			order : '',
			url : ''
		};
		this.gridsterOpts = {
			columns : 12,
			colWidth : 95,
			rowHeight : 95,
			margins : [ 20, 20 ],
			outerMargin : true,
			pushing : true,
			floating : true,
			swapping : true,
			draggable : {
				handle: 'img'
			}
		};
		
		this.emptyGridsterOpts = {
				columns : 24,
				colWidth : 190,
				rowHeight : 190,
				margins : [ 20, 20 ],
				outerMargin : true,
				pushing : true,
				floating : true,
				swapping : true,
				draggable : {
					handle: 'img'
				}
			};

		this.goToCatalog = function(item) {
			$state.go('root.appCatalog');
		} 
		
		// navigate to application url in new tab
		this.goToPortal = function(item) {
			if (!item.url) {
				$log.error('No URL found for this application, doing nothing!');
				return;
			}
			if (item.restrictedApp) {
				// Link-based apps open in their own browser tab
				$window.open(item.url, '_blank');
			} else {
				// cache control so browsers load app page every time
				var ccParam = '?cc=' + new Date().getTime();
				var appUrl = null;
				var urlParts = item.url.split('#');
				if (urlParts.length < 2)
					appUrl = item.url + ccParam;
				else
					appUrl = urlParts[0] + ccParam + "#" + urlParts[1];
				// $log.debug('DashboardCtrlr::goToPortal: opening tab with URL
				// ' + appUrl);
				var tabContent = {
					id : new Date(),
					title : item.headerText,
					url : appUrl
				};
				$cookies.putObject('addTab', tabContent);
			}
		};
		
		/* News data */
		$scope.newsData = [];
		$scope.updateNews = function() {
			$scope.newsData.length=0;
			dashboardService.getCommonWidgetData('NEWS').then(function(res) {
				// $log.info(res.message);
				var newsDataJsonArray = res.response.items;
				for (var i = 0; i < newsDataJsonArray.length; i++) {
					$scope.newsData.push(newsDataJsonArray[i]);
				}
			})['catch'](function(err) {
				$log.error('dashboard controller: failed to get news list', err);
				_this.isLoading = false;
			});
		}
		$scope.updateNews();
		
		/* Events data */
		$scope.eventData = [];
		$scope.updateEvents = function() {
			$scope.eventData.length=0;
			dashboardService.getCommonWidgetData('EVENTS').then(function(res) {
				var eventDataJsonArray = res.response.items;	
				for (var i = 0; i < eventDataJsonArray.length; i++) {
					if(eventDataJsonArray[i].eventDate !=null) {
						// yyyy-mm-dd
						eventDataJsonArray[i].year = eventDataJsonArray[i].eventDate.substring(2,4);
						eventDataJsonArray[i].mon  = eventDataJsonArray[i].eventDate.substring(5,7);
						eventDataJsonArray[i].day  = eventDataJsonArray[i].eventDate.substring(8,10);
					}
					$scope.eventData.push(eventDataJsonArray[i]);
				}
			})['catch'](function(err) {
				$log.error('dashboard controller: failed to get Events list', err);
				_this.isLoading = false;
			});
		}
		$scope.updateEvents();
		
		/* Important Resources data */
		$scope.importResData = [];
		$scope.updateImportRes = function() {
			$scope.importResData.length=0;
			dashboardService.getCommonWidgetData('IMPORTANTRESOURCES').then(
					function(res) {
						// $log.error('couldnt get important list...',
						// res.response.dataBlob);
						// $log.info(res);
						var importResDataJSONArray = res.response.items;
						for (var i = 0; i < importResDataJSONArray.length; i++) {
							$scope.importResData.push(importResDataJSONArray[i]);
						}
					})['catch'](function(err) {
				$log.error('dashboard controller: failed to get resources list...', err);
				_this.isLoading = false;
			});
		}
		$scope.updateImportRes();

		if (getParameterByName('noUserError') != null) {
			if (getParameterByName('noUserError') == "Show") {
				$("#errorInfo").show();
			}
		}
		
	};

	DashboardCtrl.$inject = [ 'applicationsService', '$log', '$window',
			'userProfileService', '$scope', '$cookies', '$timeout',
			'$interval', '$modal',  '$state', 'dashboardService','ngDialog'];
	angular.module('ecompApp').controller('DashboardCtrl', DashboardCtrl);
})();

function getParameterByName(name, url) {
	if (!url)
		url = window.location.href;
	name = name.replace(/[\[\]]/g, "\\$&");
	var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex
			.exec(url);
	if (!results)
		return '';
	if (!results[2])
		return '';
	return results[2].replace(/\+/g, " ");
}