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(conf, applicationsService, $log,
32 $window, userProfileService, $scope, $cookies, $timeout, $interval,
33 $modal, $state, beReaderService, dashboardService, confirmBoxService,
34 auditLogService, ngDialog, $compile, widgetsCatalogService) {
39 _classCallCheck(this, DashboardCtrl);
42 this.isLoading = true;
43 this.isCommError = false;
44 $scope.getUserAppsIsDone = false;
45 this.userProfileService = userProfileService;
47 $scope.event_content_show = false;
48 $scope.widgetData = [];
49 $scope.activateThis = function(ele) {
50 $compile(ele.contents())($scope);
54 $scope.editWidgetModalPopup = function(availableData, resourceType) {
55 $scope.editData = JSON.stringify(availableData);
56 $scope.availableDataTemp = $scope.availableData;
57 var modalInstance = $modal.open({
58 templateUrl: 'app/views/dashboard/dashboard-widget-manage.html',
59 controller: 'CommonWidgetController',
60 windowClass: 'modal-docked',
62 message: function message() {
65 availableData: $scope.editData
72 modalInstance.result.finally(function (needUpdate){
73 if (resourceType == 'NEWS') {
75 } else if (resourceType == 'EVENTS') {
76 $scope.updateEvents();
77 } else if (resourceType == 'IMPORTANTRESOURCES') {
78 $scope.updateImportRes();
83 $scope.editWidgetParameters = function(widgetId) {
87 var modalInstance = $modal.open({
88 templateUrl: 'app/views/dashboard/dashboard-widget-parameter-manage.html',
89 controller: 'WidgetParameterController',
90 windowClass: 'modal-docked',
99 modalInstance.result.then(function (needUpdate) {
105 $scope.sort_options = [{
127 $scope.selectedSortTypeChanged = function(userAppSortTypePref) {
128 $scope.appsViewData = [];
129 $scope.appsView = [];
131 $scope.sort_type = userAppSortTypePref;
134 .getAppsOrderBySortPref(userAppSortTypePref)
135 .then(function(res) {
137 $scope.applyPresentationDetailsToApps(_this.apps);
140 .saveAppsSortTypePreference($scope.selectedSortType)
141 .then(function(res) {
146 $scope.$watch('selectedSortType.value', (newVal, oldVal) => {
147 for (var i = 0; i < $scope.sort_options.length; i++) {
148 if ($scope.sort_options[i].value == newVal) {
149 $scope.selectedSortType = angular.copy($scope.sort_options[i]);;
154 $scope.restoreSortSelected = function() {
155 confirmBoxService.confirm("Restore the default size and position of all widgets?").then(
156 function(confirmed) {
157 var checkConfirm = confirmed;
158 if (checkConfirm === true) {
160 .delWidgetsSortPref($scope.widgetsViewData).then(function() {
166 * if(confirm('Restore the default size and position of all widgets?') ==
167 * true) { applicationsService
168 * .delWidgetsSortPref($scope.widgetsViewData).then(function(){
169 * $state.reload(); }) }
174 $scope.applyPresentationDetailsToApps = function(appsReturned) {
176 for (var i = 0; i < _this.apps.length; i++) {
177 $scope.appsView[i] = {
187 $scope.appsView[i].headerText = appsReturned[i].name;
188 $scope.appsView[i].subHeaderText = appsReturned[i].notes;
190 if (appsReturned[i].imageUrl)
191 imgLnk = conf.api.appThumbnail.replace(':appId', appsReturned[i].id);
192 // $log.debug('DashboardCtlr::applyPresn: imgLink = ' + imgLnk);
193 $scope.appsView[i].imageLink = imgLnk;
194 $scope.appsView[i].order = appsReturned[i].order;
195 $scope.appsView[i].url = appsReturned[i].url;
196 $scope.appsView[i].restrictedApp = appsReturned[i].restrictedApp;
197 $scope.appsView[i].appid = appsReturned[i].id;
199 $scope.appsView[_this.apps.length] = {
203 headerText: 'Add/Remove Applications',
205 imageLink: 'assets/images/cloud.png',
207 restrictedApp: false,
210 if ($scope.appsView.length > 6) {
211 $(".dashboard-boarder").css({
215 $(".dashboard-boarder").css({
220 if ($scope.appsView != undefined &&
221 $scope.appsView != null &&
222 $scope.appsView.length > 0) {
223 $scope.appsViewData = $scope.appsView;
227 $scope.widgetsView = [];
229 $scope.applyPresentationDetailsToWidgets = function(widgetsReturned) {
231 for (var i = 0; i < widgetsReturned.length; i++) {
232 $scope.widgetsView[i] = {
237 widgetIdentifier: '',
244 $scope.widgetsView[i].widgetid = widgetsReturned[i].id;
245 $scope.widgetsView[i].headerText = widgetsReturned[i].headerName;
246 $scope.widgetsView[i].widgetText = widgetsReturned[i].name;
248 if (widgetsReturned[i].headerName.toLowerCase() === 'news') {
249 $scope.widgetsView[i].widgetIdentifier = 'NEWS';
251 if (widgetsReturned[i].headerName.toLowerCase() === 'resources') {
252 $scope.widgetsView[i].widgetIdentifier = 'IMPORTANTRESOURCES';
254 if (widgetsReturned[i].headerName.toLowerCase() === 'events') {
255 $scope.widgetsView[i].widgetIdentifier = 'EVENTS';
258 $scope.widgetsView[i].url = widgetsReturned[i].url;
259 $scope.widgetsView[i].attrb = widgetsReturned[i].attrs;
260 if (widgetsReturned[i].width === null) {
261 $scope.widgetsView[i].sizeX = 2;
263 $scope.widgetsView[i].sizeX = widgetsReturned[i].width;
265 if (widgetsReturned[i].height === null) {
266 $scope.widgetsView[i].sizeY = 2;
268 $scope.widgetsView[i].sizeY = widgetsReturned[i].height;
270 $scope.widgetsView[i].row = widgetsReturned[i].x;
271 $scope.widgetsView[i].col = widgetsReturned[i].y;
273 if ($scope.widgetsView != undefined &&
274 $scope.widgetsView != null &&
275 $scope.widgetsView.length > 0) {
276 $scope.widgetsViewData = $scope.widgetsView;
281 .getUserAppsSortTypePreference().then(function(res) {
284 if (resJson.value === "N" || resJson.value === "") {
286 resJson.title = 'Name';
287 } else if (resJson.value === "L") {
289 resJson.title = 'Last used';
290 } else if (resJson.value === "F") {
292 resJson.title = 'Most used';
295 resJson.title = 'Manual';
297 $scope.selectedSortType = resJson;
298 $scope.selectedSortTypeChanged(res);
303 $scope.widgetsList = [];
305 let getUserWidgets = (loginName) => {
306 var conf = this.conf;
307 widgetsCatalogService.getUserWidgets(loginName).then(res => {
308 if (!(res instanceof Array)) {
309 this.isCommError = true;
312 for (var i = 0; i < res.length; i++) {
313 var widget_id = res[i][0];
314 var widget_name = res[i][1];
315 let url = this.conf.api.widgetCommon + "/" + widget_id + "/framework.js";
316 var header_name = widget_name;
317 if (res[i][7] == 1) {
318 header_name = (widget_name.length > 9) ? widget_name.substring(0, 8) + '...' : widget_name;
320 if (res[i][4] === "S" || res[i][4] === null) {
321 $scope.widgetsList.push({
323 headerName: header_name,
327 attr: 'data-' + res[i][0],
336 var script = document
337 .createElement('script');
339 script.async = false;
341 .getElementsByTagName('script')[0];
343 .insertBefore(script, entry);
345 $scope.applyPresentationDetailsToWidgets($scope.widgetsList);
347 $log.error('WidgetsHomeCtrl::getUserWidgets error: ' + err);
353 userProfileService.getUserProfile().then(
355 $scope.orgUserId = profile.orgUserId;
356 getUserWidgets($scope.orgUserId);
359 /* Widget Gridster Section */
360 $scope.newsGridsterItem = {
370 $scope.eventsGridsterItem = {
373 headerText: 'Events',
380 $scope.impoResGridsterItem = {
383 headerText: 'Resources',
390 this.gridsterAppOpts = {
403 handle: '.icon-content-gridguide',
404 stop: function stop() {
405 $scope.defaultSortBy = function() {
409 resJson.title = 'Manual';
410 $scope.selectedSortType = resJson;
411 applicationsService.saveAppsSortTypeManual($scope.appsViewData)
412 applicationsService.saveAppsSortTypePreference($scope.selectedSortType)
414 $scope.defaultSortBy();
419 this.gridsterWidgetOpts = {
430 stop: function stop(event, uiWidget, $element) {
431 if ($element.sizeX == 1)
432 $element.headerText = ($element.widgetText.length > 9) ? $element.widgetText.substring(0, 8) + '...' : $element.widgetText;
433 if ($element.sizeX >= 2)
434 $element.headerText = $element.widgetText;
437 .saveWidgetsSortManual($scope.widgetsViewData)
442 handle: '.icon-content-gridguide',
443 stop: function stop() {
445 .saveWidgetsSortManual($scope.widgetsViewData)
451 this.goToCatalog = function(item) {
452 $state.go('root.appCatalog');
455 this.goToWidgetCatLog = function(item) {
456 $state.go('root.widgetCatalog');
459 // navigate to application url in new tab
460 this.goToPortal = function(item) {
463 $log.error('No URL found for this application, doing nothing!');
466 if (item.restrictedApp) {
467 // Link-based apps open in their own browser tab
468 $window.open(item.url, '_blank');
470 // cache control so browsers load app page every
472 var ccParam = 'cc=' + new Date().getTime();
473 var urlParts = item.url.split('#');
475 if (urlParts.length < 2) {
477 let urlLastChar = item.url.charAt(item.url.length - 1);
478 if (item.url.includes("?"))
479 appUrl = (urlLastChar === '&' ? item.url + ccParam : item.url + '&' + ccParam);
481 appUrl = item.url + '?' + ccParam;
484 let urlLastChar = urlParts[0].charAt(urlParts[0].length - 1);
485 if (item.url.includes("?"))
486 appUrl = (urlLastChar === '&' ? urlParts[0] + ccParam + '#' + urlParts[1] : urlParts[0] + '&' + ccParam + '#' + urlParts[1]);
488 appUrl = urlParts[0] + '?' + ccParam + "#" + urlParts[1];
490 // $log.debug('DashboardCtrlr::goToPortal: opening
495 title: item.headerText,
499 $cookies.putObject('addTab', tabContent);
506 this.auditLog = function(app) {
508 auditLogService.storeAudit(app.appid, 'app', app.url);
511 if (getParameterByName('noUserError') != null) {
512 if (getParameterByName('noUserError') == "Show") {
513 $("#errorInfo").show();
518 DashboardCtrl.$inject = ['conf', 'applicationsService', '$log', '$window',
519 'userProfileService', '$scope', '$cookies', '$timeout', '$interval',
520 '$modal', '$state', 'beReaderService', 'dashboardService', 'confirmBoxService',
521 'auditLogService', 'ngDialog', '$compile', 'widgetsCatalogService'
523 angular.module('ecompApp').controller('DashboardCtrl', DashboardCtrl);
526 function getParameterByName(name, url) {
528 url = window.location.href;
529 name = name.replace(/[\[\]]/g, "\\$&");
530 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
537 return results[2].replace(/\+/g, " ");