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 $scope.sort_type = userAppSortTypePref;
152 .getAppsOrderBySortPref(userAppSortTypePref)
153 .then(function(res) {
155 $scope.applyPresentationDetailsToApps(_this.apps);
158 .saveAppsSortTypePreference($scope.selectedSortType)
159 .then(function(res) {
164 $scope.$watch('selectedSortType.value', (newVal, oldVal) => {
165 for (var i = 0; i < $scope.sort_options.length; i++) {
166 if ($scope.sort_options[i].value == newVal) {
167 $scope.selectedSortType = angular.copy($scope.sort_options[i]);;
172 $scope.restoreSortSelected = function() {
173 confirmBoxService.confirm("Restore the default size and position of all widgets?").then(
174 function(confirmed) {
175 var checkConfirm = confirmed;
176 if (checkConfirm === true) {
178 .delWidgetsSortPref($scope.widgetsViewData).then(function() {
184 * if(confirm('Restore the default size and position of all widgets?') ==
185 * true) { applicationsService
186 * .delWidgetsSortPref($scope.widgetsViewData).then(function(){
187 * $state.reload(); }) }
192 $scope.applyPresentationDetailsToApps = function(appsReturned) {
194 for (var i = 0; i < _this.apps.length; i++) {
195 $scope.appsView[i] = {
205 $scope.appsView[i].headerText = appsReturned[i].name;
206 $scope.appsView[i].subHeaderText = appsReturned[i].notes;
208 if (appsReturned[i].imageUrl)
209 imgLnk = conf.api.appThumbnail.replace(':appId', appsReturned[i].id);
210 // $log.debug('DashboardCtlr::applyPresn: imgLink = ' + imgLnk);
211 $scope.appsView[i].imageLink = imgLnk;
212 $scope.appsView[i].order = appsReturned[i].order;
213 $scope.appsView[i].url = appsReturned[i].url;
214 $scope.appsView[i].restrictedApp = appsReturned[i].restrictedApp;
215 $scope.appsView[i].appid = appsReturned[i].id;
217 $scope.appsView[_this.apps.length] = {
221 headerText: 'Add/Remove Applications',
223 imageLink: 'assets/images/cloud.png',
225 restrictedApp: false,
228 if ($scope.appsView.length > 6) {
229 $(".dashboard-boarder").css({
233 $(".dashboard-boarder").css({
238 if ($scope.appsView != undefined &&
239 $scope.appsView != null &&
240 $scope.appsView.length > 0) {
241 $scope.appsViewData = $scope.appsView;
245 $scope.widgetsView = [];
247 $scope.applyPresentationDetailsToWidgets = function(widgetsReturned) {
249 for (var i = 0; i < widgetsReturned.length; i++) {
250 $scope.widgetsView[i] = {
255 widgetIdentifier: '',
262 $scope.widgetsView[i].widgetid = widgetsReturned[i].id;
263 $scope.widgetsView[i].headerText = widgetsReturned[i].headerName;
264 $scope.widgetsView[i].widgetText = widgetsReturned[i].name;
266 if (widgetsReturned[i].headerName.toLowerCase() === 'news') {
267 $scope.widgetsView[i].widgetIdentifier = 'NEWS';
269 if (widgetsReturned[i].headerName.toLowerCase() === 'resources') {
270 $scope.widgetsView[i].widgetIdentifier = 'IMPORTANTRESOURCES';
272 if (widgetsReturned[i].headerName.toLowerCase() === 'events') {
273 $scope.widgetsView[i].widgetIdentifier = 'EVENTS';
276 $scope.widgetsView[i].url = widgetsReturned[i].url;
277 $scope.widgetsView[i].attrb = widgetsReturned[i].attrs;
278 if (widgetsReturned[i].width === null) {
279 $scope.widgetsView[i].sizeX = 2;
281 $scope.widgetsView[i].sizeX = widgetsReturned[i].width;
283 if (widgetsReturned[i].height === null) {
284 $scope.widgetsView[i].sizeY = 2;
286 $scope.widgetsView[i].sizeY = widgetsReturned[i].height;
288 $scope.widgetsView[i].row = widgetsReturned[i].x;
289 $scope.widgetsView[i].col = widgetsReturned[i].y;
291 if ($scope.widgetsView != undefined &&
292 $scope.widgetsView != null &&
293 $scope.widgetsView.length > 0) {
294 $scope.widgetsViewData = $scope.widgetsView;
299 .getUserAppsSortTypePreference().then(function(res) {
302 if (resJson.value === "N" || resJson.value === "") {
304 resJson.title = 'Name';
305 } else if (resJson.value === "L") {
307 resJson.title = 'Last used';
308 } else if (resJson.value === "F") {
310 resJson.title = 'Most used';
313 resJson.title = 'Manual';
315 $scope.selectedSortType = resJson;
316 $scope.selectedSortTypeChanged(res);
321 $scope.widgetsList = [];
323 let getUserWidgets = (loginName) => {
324 var conf = this.conf;
325 widgetsCatalogService.getUserWidgets(loginName).then(res => {
326 if (!(res instanceof Array)) {
327 this.isCommError = true;
330 for (var i = 0; i < res.length; i++) {
331 var widget_id = res[i][0];
332 var widget_name = res[i][1];
333 let url = this.conf.api.widgetCommon + "/" + widget_id + "/framework.js";
334 var header_name = widget_name;
335 if (res[i][7] == 1) {
336 header_name = (widget_name.length > 9) ? widget_name.substring(0, 8) + '...' : widget_name;
338 if (res[i][4] === "S" || res[i][4] === null) {
339 $scope.widgetsList.push({
341 headerName: header_name,
345 attr: 'data-' + res[i][0],
354 var script = document
355 .createElement('script');
357 script.async = false;
359 .getElementsByTagName('script')[0];
361 .insertBefore(script, entry);
363 $scope.applyPresentationDetailsToWidgets($scope.widgetsList);
365 $log.error('WidgetsHomeCtrl::getUserWidgets error: ' + err);
371 userProfileService.getUserProfile().then(
373 $scope.orgUserId = profile.orgUserId;
374 getUserWidgets($scope.orgUserId);
377 /* Widget Gridster Section */
378 $scope.newsGridsterItem = {
388 $scope.eventsGridsterItem = {
391 headerText: 'Events',
398 $scope.impoResGridsterItem = {
401 headerText: 'Resources',
408 this.gridsterAppOpts = {
421 handle: '.icon-content-gridguide',
422 stop: function stop() {
423 $scope.defaultSortBy = function() {
427 resJson.title = 'Manual';
428 $scope.selectedSortType = resJson;
429 applicationsService.saveAppsSortTypeManual($scope.appsViewData)
430 applicationsService.saveAppsSortTypePreference($scope.selectedSortType)
432 $scope.defaultSortBy();
437 this.gridsterWidgetOpts = {
448 stop: function stop(event, uiWidget, $element) {
449 if ($element.sizeX == 1)
450 $element.headerText = ($element.widgetText.length > 9) ? $element.widgetText.substring(0, 8) + '...' : $element.widgetText;
451 if ($element.sizeX >= 2)
452 $element.headerText = $element.widgetText;
455 .saveWidgetsSortManual($scope.widgetsViewData)
460 handle: '.icon-content-gridguide',
461 stop: function stop() {
463 .saveWidgetsSortManual($scope.widgetsViewData)
469 this.goToCatalog = function(item) {
470 $state.go('root.appCatalog');
473 this.goToWidgetCatLog = function(item) {
474 $state.go('root.widgetCatalog');
477 // navigate to application url in new tab
478 this.goToPortal = function(item) {
481 $log.error('No URL found for this application, doing nothing!');
484 if (item.restrictedApp) {
485 // Link-based apps open in their own browser tab
486 $window.open(item.url, '_blank');
488 // cache control so browsers load app page every
490 var ccParam = 'cc=' + new Date().getTime();
491 var urlParts = item.url.split('#');
493 if (urlParts.length < 2) {
495 let urlLastChar = item.url.charAt(item.url.length - 1);
496 if (item.url.includes("?"))
497 appUrl = (urlLastChar === '&' ? item.url + ccParam : item.url + '&' + ccParam);
499 appUrl = item.url + '?' + ccParam;
502 let urlLastChar = urlParts[0].charAt(urlParts[0].length - 1);
503 if (item.url.includes("?"))
504 appUrl = (urlLastChar === '&' ? urlParts[0] + ccParam + '#' + urlParts[1] : urlParts[0] + '&' + ccParam + '#' + urlParts[1]);
506 appUrl = urlParts[0] + '?' + ccParam + "#" + urlParts[1];
508 // $log.debug('DashboardCtrlr::goToPortal: opening
513 title: item.headerText,
517 $cookies.putObject('addTab', tabContent);
524 this.auditLog = function(app) {
526 auditLogService.storeAudit(app.appid, 'app', app.url);
529 if (getParameterByName('noUserError') != null) {
530 if (getParameterByName('noUserError') == "Show") {
531 $("#errorInfo").show();
536 DashboardCtrl.$inject = ['conf', 'applicationsService', '$log', '$window',
537 'userProfileService', '$scope', '$cookies', '$timeout', '$interval',
538 '$modal', '$state', 'beReaderService', 'dashboardService', 'confirmBoxService',
539 'auditLogService', 'ngDialog', '$compile', 'widgetsCatalogService'
541 angular.module('ecompApp').controller('DashboardCtrl', DashboardCtrl);
544 function getParameterByName(name, url) {
546 url = window.location.href;
547 name = name.replace(/[\[\]]/g, "\\$&");
548 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
555 return results[2].replace(/\+/g, " ");