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;
58 templateUrl: 'app/views/dashboard/dashboard-widget-manage.html',
59 controller: 'CommonWidgetController',
61 message: function message() {
64 availableData: $scope.editData
69 }).closePromise.then(needUpdate => {
70 if (resourceType == 'NEWS') {
72 } else if (resourceType == 'EVENTS') {
73 $scope.updateEvents();
74 } else if (resourceType == 'IMPORTANTRESOURCES') {
75 $scope.updateImportRes();
80 $scope.editWidgetParameters = function(widgetId) {
85 templateUrl: 'app/views/dashboard/dashboard-widget-parameter-manage.html',
86 controller: 'WidgetParameterController',
88 }).closePromise.then(needUpdate => {
93 $scope.sort_options = [{
115 $scope.selectedSortTypeChanged = function(userAppSortTypePref) {
116 $scope.appsViewData = [];
117 $scope.appsView = [];
119 $scope.sort_type = userAppSortTypePref;
122 .getAppsOrderBySortPref(userAppSortTypePref)
123 .then(function(res) {
125 $scope.applyPresentationDetailsToApps(_this.apps);
128 .saveAppsSortTypePreference($scope.selectedSortType)
129 .then(function(res) {
134 $scope.$watch('selectedSortType.value', (newVal, oldVal) => {
135 for (var i = 0; i < $scope.sort_options.length; i++) {
136 if ($scope.sort_options[i].value == newVal) {
137 $scope.selectedSortType = angular.copy($scope.sort_options[i]);;
142 $scope.restoreSortSelected = function() {
143 confirmBoxService.confirm("Restore the default size and position of all widgets?").then(
144 function(confirmed) {
145 var checkConfirm = confirmed;
146 if (checkConfirm === true) {
148 .delWidgetsSortPref($scope.widgetsViewData).then(function() {
154 * if(confirm('Restore the default size and position of all widgets?') ==
155 * true) { applicationsService
156 * .delWidgetsSortPref($scope.widgetsViewData).then(function(){
157 * $state.reload(); }) }
162 $scope.applyPresentationDetailsToApps = function(appsReturned) {
164 for (var i = 0; i < _this.apps.length; i++) {
165 $scope.appsView[i] = {
175 $scope.appsView[i].headerText = appsReturned[i].name;
176 $scope.appsView[i].subHeaderText = appsReturned[i].notes;
178 if (appsReturned[i].imageUrl)
179 imgLnk = conf.api.appThumbnail.replace(':appId', appsReturned[i].id);
180 // $log.debug('DashboardCtlr::applyPresn: imgLink = ' + imgLnk);
181 $scope.appsView[i].imageLink = imgLnk;
182 $scope.appsView[i].order = appsReturned[i].order;
183 $scope.appsView[i].url = appsReturned[i].url;
184 $scope.appsView[i].restrictedApp = appsReturned[i].restrictedApp;
185 $scope.appsView[i].appid = appsReturned[i].id;
187 $scope.appsView[_this.apps.length] = {
191 headerText: 'Add/Remove Applications',
193 imageLink: 'assets/images/cloud.png',
195 restrictedApp: false,
198 if ($scope.appsView.length > 6) {
199 $(".dashboard-boarder").css({
203 $(".dashboard-boarder").css({
208 if ($scope.appsView != undefined &&
209 $scope.appsView != null &&
210 $scope.appsView.length > 0) {
211 $scope.appsViewData = $scope.appsView;
215 $scope.widgetsView = [];
217 $scope.applyPresentationDetailsToWidgets = function(widgetsReturned) {
219 for (var i = 0; i < widgetsReturned.length; i++) {
220 $scope.widgetsView[i] = {
225 widgetIdentifier: '',
232 $scope.widgetsView[i].widgetid = widgetsReturned[i].id;
233 $scope.widgetsView[i].headerText = widgetsReturned[i].headerName;
234 $scope.widgetsView[i].widgetText = widgetsReturned[i].name;
236 if (widgetsReturned[i].headerName.toLowerCase() === 'news') {
237 $scope.widgetsView[i].widgetIdentifier = 'NEWS';
239 if (widgetsReturned[i].headerName.toLowerCase() === 'resources') {
240 $scope.widgetsView[i].widgetIdentifier = 'IMPORTANTRESOURCES';
242 if (widgetsReturned[i].headerName.toLowerCase() === 'events') {
243 $scope.widgetsView[i].widgetIdentifier = 'EVENTS';
246 $scope.widgetsView[i].url = widgetsReturned[i].url;
247 $scope.widgetsView[i].attrb = widgetsReturned[i].attrs;
248 if (widgetsReturned[i].width === null) {
249 $scope.widgetsView[i].sizeX = 2;
251 $scope.widgetsView[i].sizeX = widgetsReturned[i].width;
253 if (widgetsReturned[i].height === null) {
254 $scope.widgetsView[i].sizeY = 2;
256 $scope.widgetsView[i].sizeY = widgetsReturned[i].height;
258 $scope.widgetsView[i].row = widgetsReturned[i].x;
259 $scope.widgetsView[i].col = widgetsReturned[i].y;
261 if ($scope.widgetsView != undefined &&
262 $scope.widgetsView != null &&
263 $scope.widgetsView.length > 0) {
264 $scope.widgetsViewData = $scope.widgetsView;
269 .getUserAppsSortTypePreference().then(function(res) {
272 if (resJson.value === "N" || resJson.value === "") {
274 resJson.title = 'Name';
275 } else if (resJson.value === "L") {
277 resJson.title = 'Last used';
278 } else if (resJson.value === "F") {
280 resJson.title = 'Most used';
283 resJson.title = 'Manual';
285 $scope.selectedSortType = resJson;
286 $scope.selectedSortTypeChanged(res);
291 $scope.widgetsList = [];
293 let getUserWidgets = (loginName) => {
294 var conf = this.conf;
295 widgetsCatalogService.getUserWidgets(loginName).then(res => {
296 if (!(res instanceof Array)) {
297 this.isCommError = true;
300 for (var i = 0; i < res.length; i++) {
301 var widget_id = res[i][0];
302 var widget_name = res[i][1];
303 let url = this.conf.api.widgetCommon + "/" + widget_id + "/framework.js";
304 var header_name = widget_name;
305 if (res[i][7] == 1) {
306 header_name = (widget_name.length > 9) ? widget_name.substring(0, 8) + '...' : widget_name;
308 if (res[i][4] === "S" || res[i][4] === null) {
309 $scope.widgetsList.push({
311 headerName: header_name,
315 attr: 'data-' + res[i][0],
324 var script = document
325 .createElement('script');
327 script.async = false;
329 .getElementsByTagName('script')[0];
331 .insertBefore(script, entry);
333 $scope.applyPresentationDetailsToWidgets($scope.widgetsList);
335 $log.error('WidgetsHomeCtrl::getUserWidgets error: ' + err);
341 userProfileService.getUserProfile().then(
343 $scope.orgUserId = profile.orgUserId;
344 getUserWidgets($scope.orgUserId);
347 /* Widget Gridster Section */
348 $scope.newsGridsterItem = {
358 $scope.eventsGridsterItem = {
361 headerText: 'Events',
368 $scope.impoResGridsterItem = {
371 headerText: 'Resources',
378 this.gridsterAppOpts = {
391 handle: '.icon-content-gridguide',
392 stop: function stop() {
393 $scope.defaultSortBy = function() {
397 resJson.title = 'Manual';
398 $scope.selectedSortType = resJson;
399 applicationsService.saveAppsSortTypeManual($scope.appsViewData)
400 applicationsService.saveAppsSortTypePreference($scope.selectedSortType)
402 $scope.defaultSortBy();
407 this.gridsterWidgetOpts = {
418 stop: function stop(event, uiWidget, $element) {
419 if ($element.sizeX == 1)
420 $element.headerText = ($element.widgetText.length > 9) ? $element.widgetText.substring(0, 8) + '...' : $element.widgetText;
421 if ($element.sizeX >= 2)
422 $element.headerText = $element.widgetText;
425 .saveWidgetsSortManual($scope.widgetsViewData)
430 handle: '.icon-content-gridguide',
431 stop: function stop() {
433 .saveWidgetsSortManual($scope.widgetsViewData)
439 this.goToCatalog = function(item) {
440 $state.go('root.appCatalog');
443 this.goToWidgetCatLog = function(item) {
444 $state.go('root.widgetCatalog');
447 // navigate to application url in new tab
448 this.goToPortal = function(item) {
451 $log.error('No URL found for this application, doing nothing!');
454 if (item.restrictedApp) {
455 // Link-based apps open in their own browser tab
456 $window.open(item.url, '_blank');
458 // cache control so browsers load app page every
460 var ccParam = 'cc=' + new Date().getTime();
461 var urlParts = item.url.split('#');
463 if (urlParts.length < 2) {
465 let urlLastChar = item.url.charAt(item.url.length - 1);
466 if (item.url.includes("?"))
467 appUrl = (urlLastChar === '&' ? item.url + ccParam : item.url + '&' + ccParam);
469 appUrl = item.url + '?' + ccParam;
472 let urlLastChar = urlParts[0].charAt(urlParts[0].length - 1);
473 if (item.url.includes("?"))
474 appUrl = (urlLastChar === '&' ? urlParts[0] + ccParam + '#' + urlParts[1] : urlParts[0] + '&' + ccParam + '#' + urlParts[1]);
476 appUrl = urlParts[0] + '?' + ccParam + "#" + urlParts[1];
478 // $log.debug('DashboardCtrlr::goToPortal: opening
483 title: item.headerText,
487 $cookies.putObject('addTab', tabContent);
493 this.auditLog = function(app) {
495 auditLogService.storeAudit(app.appid, 'app', app.url);
498 if (getParameterByName('noUserError') != null) {
499 if (getParameterByName('noUserError') == "Show") {
500 $("#errorInfo").show();
505 DashboardCtrl.$inject = ['conf', 'applicationsService', '$log', '$window',
506 'userProfileService', '$scope', '$cookies', '$timeout', '$interval',
507 '$modal', '$state', 'beReaderService', 'dashboardService', 'confirmBoxService',
508 'auditLogService', 'ngDialog', '$compile', 'widgetsCatalogService'
510 angular.module('ecompApp').controller('DashboardCtrl', DashboardCtrl);
513 function getParameterByName(name, url) {
515 url = window.location.href;
516 name = name.replace(/[\[\]]/g, "\\$&");
517 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
524 return results[2].replace(/\+/g, " ");