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============================================
40 function _classCallCheck(instance, Constructor) {
41 if (!(instance instanceof Constructor)) {
42 throw new TypeError('Cannot call a class as a function');
47 var HTTP_PROTOCOL_RGX = /https?:\/\//;
49 var DashboardCtrl = function DashboardCtrl(conf, applicationsService, $log,
50 $window, userProfileService, $scope, $cookies, $timeout, $interval,
51 $modal, $state, beReaderService, dashboardService, confirmBoxService,
52 auditLogService, ngDialog, $compile, widgetsCatalogService) {
57 _classCallCheck(this, DashboardCtrl);
60 this.isLoading = true;
61 this.isCommError = false;
62 $scope.getUserAppsIsDone = false;
63 this.userProfileService = userProfileService;
65 $scope.event_content_show = false;
66 $scope.widgetData = [];
67 $scope.activateThis = function(ele) {
68 $compile(ele.contents())($scope);
72 $scope.editWidgetModalPopup = function(availableData, resourceType) {
73 $scope.editData = JSON.stringify(availableData);
74 $scope.availableDataTemp = $scope.availableData;
75 var modalInstance = $modal.open({
76 templateUrl: 'app/views/dashboard/dashboard-widget-manage.html',
77 controller: 'CommonWidgetController',
78 windowClass: 'modal-docked',
80 message: function message() {
83 availableData: $scope.editData
90 modalInstance.result.finally(function (needUpdate){
91 if (resourceType == 'NEWS') {
93 } else if (resourceType == 'EVENTS') {
94 $scope.updateEvents();
95 } else if (resourceType == 'IMPORTANTRESOURCES') {
96 $scope.updateImportRes();
101 $scope.editWidgetParameters = function(widgetId) {
105 var modalInstance = $modal.open({
106 templateUrl: 'app/views/dashboard/dashboard-widget-parameter-manage.html',
107 controller: 'WidgetParameterController',
108 windowClass: 'modal-docked',
117 modalInstance.result.then(function (needUpdate) {
123 $scope.sort_options = [{
145 $scope.selectedSortTypeChanged = function(userAppSortTypePref) {
146 $scope.appsViewData = [];
147 $scope.appsView = [];
149 if(userAppSortTypePref == ""){
150 $scope.selectedSortType = $scope.sort_options[0];
152 angular.forEach($scope.sort_options, function(sort_type, key){
153 if(sort_type.value == userAppSortTypePref)
154 $scope.selectedSortType = sort_type;
159 .getAppsOrderBySortPref(userAppSortTypePref)
160 .then(function(res) {
162 $scope.applyPresentationDetailsToApps(_this.apps);
165 .saveAppsSortTypePreference($scope.selectedSortType)
166 .then(function(res) {
171 $scope.$watch('selectedSortType.value', (newVal, oldVal) => {
172 for (var i = 0; i < $scope.sort_options.length; i++) {
173 if ($scope.sort_options[i].value == newVal) {
174 $scope.selectedSortType = angular.copy($scope.sort_options[i]);;
179 $scope.restoreSortSelected = function() {
180 confirmBoxService.confirm("Restore the default size and position of all widgets?").then(
181 function(confirmed) {
182 var checkConfirm = confirmed;
183 if (checkConfirm === true) {
185 .delWidgetsSortPref($scope.widgetsViewData).then(function() {
191 * if(confirm('Restore the default size and position of all widgets?') ==
192 * true) { applicationsService
193 * .delWidgetsSortPref($scope.widgetsViewData).then(function(){
194 * $state.reload(); }) }
199 $scope.applyPresentationDetailsToApps = function(appsReturned) {
201 for (var i = 0; i < _this.apps.length; i++) {
202 $scope.appsView[i] = {
212 $scope.appsView[i].headerText = appsReturned[i].name;
213 $scope.appsView[i].subHeaderText = appsReturned[i].notes;
215 if (appsReturned[i].imageUrl)
216 imgLnk = conf.api.appThumbnail.replace(':appId', appsReturned[i].id);
217 // $log.debug('DashboardCtlr::applyPresn: imgLink = ' + imgLnk);
218 $scope.appsView[i].imageLink = imgLnk;
219 $scope.appsView[i].order = appsReturned[i].order;
220 $scope.appsView[i].url = appsReturned[i].url;
221 $scope.appsView[i].restrictedApp = appsReturned[i].restrictedApp;
222 $scope.appsView[i].appid = appsReturned[i].id;
224 $scope.appsView[_this.apps.length] = {
228 headerText: 'Add/Remove Applications',
230 imageLink: 'assets/images/cloud.png',
232 restrictedApp: false,
235 if ($scope.appsView.length > 6) {
236 $(".dashboard-boarder").css({
240 $(".dashboard-boarder").css({
245 if ($scope.appsView != undefined &&
246 $scope.appsView != null &&
247 $scope.appsView.length > 0) {
248 $scope.appsViewData = $scope.appsView;
252 $scope.widgetsView = [];
254 $scope.applyPresentationDetailsToWidgets = function(widgetsReturned) {
256 for (var i = 0; i < widgetsReturned.length; i++) {
257 $scope.widgetsView[i] = {
262 widgetIdentifier: '',
269 $scope.widgetsView[i].widgetid = widgetsReturned[i].id;
270 $scope.widgetsView[i].headerText = widgetsReturned[i].headerName;
271 $scope.widgetsView[i].widgetText = widgetsReturned[i].name;
273 if (widgetsReturned[i].headerName.toLowerCase() === 'news') {
274 $scope.widgetsView[i].widgetIdentifier = 'NEWS';
276 if (widgetsReturned[i].headerName.toLowerCase() === 'resources') {
277 $scope.widgetsView[i].widgetIdentifier = 'IMPORTANTRESOURCES';
279 if (widgetsReturned[i].headerName.toLowerCase() === 'events') {
280 $scope.widgetsView[i].widgetIdentifier = 'EVENTS';
283 $scope.widgetsView[i].url = widgetsReturned[i].url;
284 $scope.widgetsView[i].attrb = widgetsReturned[i].attrs;
285 if (widgetsReturned[i].width === null) {
286 $scope.widgetsView[i].sizeX = 2;
288 $scope.widgetsView[i].sizeX = widgetsReturned[i].width;
290 if (widgetsReturned[i].height === null) {
291 $scope.widgetsView[i].sizeY = 2;
293 $scope.widgetsView[i].sizeY = widgetsReturned[i].height;
295 $scope.widgetsView[i].row = widgetsReturned[i].x;
296 $scope.widgetsView[i].col = widgetsReturned[i].y;
298 if ($scope.widgetsView != undefined &&
299 $scope.widgetsView != null &&
300 $scope.widgetsView.length > 0) {
301 $scope.widgetsViewData = $scope.widgetsView;
306 .getUserAppsSortTypePreference().then(function(res) {
309 if (resJson.value === "N" || resJson.value === "") {
311 resJson.title = 'Name';
312 } else if (resJson.value === "L") {
314 resJson.title = 'Last used';
315 } else if (resJson.value === "F") {
317 resJson.title = 'Most used';
320 resJson.title = 'Manual';
322 $scope.selectedSortType = resJson;
323 $scope.selectedSortTypeChanged(res);
328 $scope.widgetsList = [];
330 let getUserWidgets = (loginName) => {
331 var conf = this.conf;
332 widgetsCatalogService.getUserWidgets(loginName).then(res => {
333 if (!(res instanceof Array)) {
334 this.isCommError = true;
337 for (var i = 0; i < res.length; i++) {
338 var widget_id = res[i][0];
339 var widget_name = res[i][1];
340 let url = this.conf.api.widgetCommon + "/" + widget_id + "/framework.js";
341 var header_name = widget_name;
342 if (res[i][7] == 1) {
343 header_name = (widget_name.length > 9) ? widget_name.substring(0, 8) + '...' : widget_name;
345 if (res[i][4] === "S" || res[i][4] === null) {
346 $scope.widgetsList.push({
348 headerName: header_name,
352 attr: 'data-' + res[i][0],
361 var script = document
362 .createElement('script');
364 script.async = false;
366 .getElementsByTagName('script')[0];
368 .insertBefore(script, entry);
370 $scope.applyPresentationDetailsToWidgets($scope.widgetsList);
372 $log.error('WidgetsHomeCtrl::getUserWidgets error: ' + err);
378 userProfileService.getUserProfile().then(
380 $scope.orgUserId = profile.orgUserId;
381 getUserWidgets($scope.orgUserId);
384 /* Widget Gridster Section */
385 $scope.newsGridsterItem = {
395 $scope.eventsGridsterItem = {
398 headerText: 'Events',
405 $scope.impoResGridsterItem = {
408 headerText: 'Resources',
415 this.gridsterAppOpts = {
428 handle: '.icon-content-gridguide',
429 stop: function stop() {
430 $scope.defaultSortBy = function() {
434 resJson.title = 'Manual';
435 $scope.selectedSortType = resJson;
436 applicationsService.saveAppsSortTypeManual($scope.appsViewData)
437 applicationsService.saveAppsSortTypePreference($scope.selectedSortType)
439 $scope.defaultSortBy();
444 this.gridsterWidgetOpts = {
455 stop: function stop(event, uiWidget, $element) {
456 if ($element.sizeX == 1)
457 $element.headerText = ($element.widgetText.length > 9) ? $element.widgetText.substring(0, 8) + '...' : $element.widgetText;
458 if ($element.sizeX >= 2)
459 $element.headerText = $element.widgetText;
462 .saveWidgetsSortManual($scope.widgetsViewData)
467 handle: '.icon-content-gridguide',
468 stop: function stop() {
470 .saveWidgetsSortManual($scope.widgetsViewData)
476 this.goToCatalog = function(item) {
477 $state.go('root.appCatalog');
480 this.goToWidgetCatLog = function(item) {
481 $state.go('root.widgetCatalog');
484 // navigate to application url in new tab
485 this.goToPortal = function(item) {
488 $log.error('No URL found for this application, doing nothing!');
491 if (item.restrictedApp) {
492 // Link-based apps open in their own browser tab
493 $window.open(item.url, '_blank');
495 // cache control so browsers load app page every
497 var ccParam = 'cc=' + new Date().getTime();
498 var urlParts = item.url.split('#');
500 if (urlParts.length < 2) {
502 let urlLastChar = item.url.charAt(item.url.length - 1);
503 if (item.url.includes("?"))
504 appUrl = (urlLastChar === '&' ? item.url + ccParam : item.url + '&' + ccParam);
506 appUrl = item.url + '?' + ccParam;
509 let urlLastChar = urlParts[0].charAt(urlParts[0].length - 1);
510 if (item.url.includes("?"))
511 appUrl = (urlLastChar === '&' ? urlParts[0] + ccParam + '#' + urlParts[1] : urlParts[0] + '&' + ccParam + '#' + urlParts[1]);
513 appUrl = urlParts[0] + '?' + ccParam + "#" + urlParts[1];
515 // $log.debug('DashboardCtrlr::goToPortal: opening
520 title: item.headerText,
524 $cookies.putObject('addTab', tabContent);
531 this.auditLog = function(app) {
533 auditLogService.storeAudit(app.appid, 'app', app.url);
536 if (getParameterByName('noUserError') != null) {
537 if (getParameterByName('noUserError') == "Show") {
538 $("#errorInfo").show();
543 DashboardCtrl.$inject = ['conf', 'applicationsService', '$log', '$window',
544 'userProfileService', '$scope', '$cookies', '$timeout', '$interval',
545 '$modal', '$state', 'beReaderService', 'dashboardService', 'confirmBoxService',
546 'auditLogService', 'ngDialog', '$compile', 'widgetsCatalogService'
548 angular.module('ecompApp').controller('DashboardCtrl', DashboardCtrl);
551 function getParameterByName(name, url) {
553 url = window.location.href;
554 name = name.replace(/[\[\]]/g, "\\$&");
555 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
562 return results[2].replace(/\+/g, " ");