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 * ================================================================================
22 function _classCallCheck(instance, Constructor) {
23 if (!(instance instanceof Constructor)) {
24 throw new TypeError('Cannot call a class as a function');
29 var HTTP_PROTOCOL_RGX = /https?:\/\//;
31 var DashboardCtrl = function DashboardCtrl(applicationsService, $log,
32 $window, userProfileService, $scope, $cookies, $timeout, $interval,
33 $modal, $state, dashboardService,ngDialog) {
37 _classCallCheck(this, DashboardCtrl);
40 this.isLoading = true;
41 $scope.getUserAppsIsDone = false;
42 this.userProfileService = userProfileService;
44 $scope.event_content_show = false;
45 $scope.widgetData = [];
47 $scope.editWidgetModalPopup = function(availableData, resourceType) {
48 $scope.editData = JSON.stringify(availableData);
49 $scope.availableDataTemp = $scope.availableData;
51 templateUrl : 'app/views/dashboard/dashboard-widget-manage.html',
52 controller : 'CommonWidgetController',
54 message : function message() {
57 availableData : $scope.editData
62 }).closePromise.then(needUpdate => {
63 if(resourceType=='NEWS'){
65 }else if(resourceType=='EVENTS'){
66 $scope.updateEvents();
67 }else if(resourceType=='IMPORTANTRESOURCES'){
68 $scope.updateImportRes();
73 userProfileService.getUserProfile()
76 // $log.info(profile);
77 $scope.attuid = profile.attuid;
78 // $log.info('user has the following attuid: ' +
82 applicationsService.getPersUserApps()
88 for (var i = 0; i < _this.apps.length; i++) {
89 $scope.appsView[i] = {
92 headerText : _this.apps[i].name,
93 subHeaderText : _this.apps[i].notes,
94 imageLink : _this.apps[i].thumbnail || _this.apps[i].imageUrl,
95 order : _this.apps[i].order,
96 restrictedApp : _this.apps[i].restrictedApp,
97 url : _this.apps[i].url
101 // Append the show add/remove applications tile
102 $scope.appsView[_this.apps.length] = {
103 addRemoveApps : true,
106 headerText : 'Add/Remove Applications',
108 imageLink : 'assets/images/cloud.png',
110 restrictedApp : false,
114 // $log.info('getUserApps apps count : ' +
115 // $scope.appsView.length);
116 // Show 2 rows in the gridster if needed
117 if ($scope.appsView.length > 6) {
118 $(".dashboard-boarder").css({
122 $(".dashboard-boarder").css({
126 _this.isLoading = false;
127 $scope.getUserAppsIsDone = true;
130 $log.error('DashboardCtlr: failed to get applications list', err);
131 _this.isLoading = false;
132 $scope.getUserAppsIsDone = true;
137 /* Widget Gridster Section */
138 $scope.newsGridsterItem = {
148 $scope.eventsGridsterItem = {
151 headerText : 'Calendar Events',
158 $scope.impoResGridsterItem = {
161 headerText : 'Resources',
167 this.gridsterOpts = {
171 margins : [ 20, 20 ],
181 this.emptyGridsterOpts = {
185 margins : [ 20, 20 ],
195 this.goToCatalog = function(item) {
196 $state.go('root.appCatalog');
199 // navigate to application url in new tab
200 this.goToPortal = function(item) {
202 $log.error('No URL found for this application, doing nothing!');
205 if (item.restrictedApp) {
206 // Link-based apps open in their own browser tab
207 $window.open(item.url, '_blank');
209 // cache control so browsers load app page every time
210 var ccParam = '?cc=' + new Date().getTime();
212 var urlParts = item.url.split('#');
213 if (urlParts.length < 2)
214 appUrl = item.url + ccParam;
216 appUrl = urlParts[0] + ccParam + "#" + urlParts[1];
217 // $log.debug('DashboardCtrlr::goToPortal: opening tab with URL
221 title : item.headerText,
224 $cookies.putObject('addTab', tabContent);
229 $scope.newsData = [];
230 $scope.updateNews = function() {
231 $scope.newsData.length=0;
232 dashboardService.getCommonWidgetData('NEWS').then(function(res) {
233 // $log.info(res.message);
234 var newsDataJsonArray = res.response.items;
235 for (var i = 0; i < newsDataJsonArray.length; i++) {
236 $scope.newsData.push(newsDataJsonArray[i]);
238 })['catch'](function(err) {
239 $log.error('dashboard controller: failed to get news list', err);
240 _this.isLoading = false;
246 $scope.eventData = [];
247 $scope.updateEvents = function() {
248 $scope.eventData.length=0;
249 dashboardService.getCommonWidgetData('EVENTS').then(function(res) {
250 var eventDataJsonArray = res.response.items;
251 for (var i = 0; i < eventDataJsonArray.length; i++) {
252 if(eventDataJsonArray[i].eventDate !=null) {
254 eventDataJsonArray[i].year = eventDataJsonArray[i].eventDate.substring(2,4);
255 eventDataJsonArray[i].mon = eventDataJsonArray[i].eventDate.substring(5,7);
256 eventDataJsonArray[i].day = eventDataJsonArray[i].eventDate.substring(8,10);
258 $scope.eventData.push(eventDataJsonArray[i]);
260 })['catch'](function(err) {
261 $log.error('dashboard controller: failed to get Events list', err);
262 _this.isLoading = false;
265 $scope.updateEvents();
267 /* Important Resources data */
268 $scope.importResData = [];
269 $scope.updateImportRes = function() {
270 $scope.importResData.length=0;
271 dashboardService.getCommonWidgetData('IMPORTANTRESOURCES').then(
273 // $log.error('couldnt get important list...',
274 // res.response.dataBlob);
276 var importResDataJSONArray = res.response.items;
277 for (var i = 0; i < importResDataJSONArray.length; i++) {
278 $scope.importResData.push(importResDataJSONArray[i]);
280 })['catch'](function(err) {
281 $log.error('dashboard controller: failed to get resources list...', err);
282 _this.isLoading = false;
285 $scope.updateImportRes();
287 if (getParameterByName('noUserError') != null) {
288 if (getParameterByName('noUserError') == "Show") {
289 $("#errorInfo").show();
295 DashboardCtrl.$inject = [ 'applicationsService', '$log', '$window',
296 'userProfileService', '$scope', '$cookies', '$timeout',
297 '$interval', '$modal', '$state', 'dashboardService','ngDialog'];
298 angular.module('ecompApp').controller('DashboardCtrl', DashboardCtrl);
301 function getParameterByName(name, url) {
303 url = window.location.href;
304 name = name.replace(/[\[\]]/g, "\\$&");
305 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex
311 return results[2].replace(/\+/g, " ");