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 = [
94 {index: 0, value: 'N', title: 'Name'},
95 {index: 1, value: 'L', title: 'Last used'},
96 {index: 2, value: 'F', title: 'Most used'},
97 {index: 3, value: 'M', title: 'Manual'}
100 $scope.selectedSortTypeChanged = function(userAppSortTypePref) {
101 $scope.appsViewData = [];
102 $scope.appsView = [];
104 $scope.sort_type = userAppSortTypePref;
107 .getAppsOrderBySortPref(userAppSortTypePref)
108 .then(function(res) {
110 $scope.applyPresentationDetailsToApps(_this.apps);
113 .saveAppsSortTypePreference($scope.selectedSortType)
114 .then(function(res) {
119 $scope.$watch('selectedSortType.value', (newVal, oldVal) => {
120 for(var i=0;i<$scope.sort_options.length;i++){
121 if($scope.sort_options[i].value==newVal){
122 $scope.selectedSortType=angular.copy($scope.sort_options[i]);;
127 $scope.restoreSortSelected = function(){
128 confirmBoxService.confirm("Restore the default size and position of all widgets?").then(
130 var checkConfirm = confirmed;
131 if(checkConfirm === true){
133 .delWidgetsSortPref($scope.widgetsViewData).then(function(){
138 /* if(confirm('Restore the default size and position of all widgets?') == true)
141 .delWidgetsSortPref($scope.widgetsViewData).then(function(){
148 $scope.applyPresentationDetailsToApps = function(appsReturned) {
150 for (var i = 0; i < _this.apps.length; i++) {
151 $scope.appsView[i] = {
161 $scope.appsView[i].headerText = appsReturned[i].name;
162 $scope.appsView[i].subHeaderText = appsReturned[i].notes;
164 if (appsReturned[i].imageUrl)
165 imgLnk = conf.api.appThumbnail.replace(':appId', appsReturned[i].id);
166 //$log.debug('DashboardCtlr::applyPresn: imgLink = ' + imgLnk);
167 $scope.appsView[i].imageLink = imgLnk;
168 $scope.appsView[i].order = appsReturned[i].order;
169 $scope.appsView[i].url = appsReturned[i].url;
170 $scope.appsView[i].restrictedApp = appsReturned[i].restrictedApp;
171 $scope.appsView[i].appid = appsReturned[i].id;
173 $scope.appsView[_this.apps.length] = {
174 addRemoveApps : true,
177 headerText : 'Add/Remove Applications',
179 imageLink : 'assets/images/cloud.png',
181 restrictedApp : false,
184 if($scope.appsView.length>6){
185 $(".dashboard-boarder").css({
189 $(".dashboard-boarder").css({
194 if ($scope.appsView != undefined
195 && $scope.appsView != null
196 && $scope.appsView.length > 0) {
197 $scope.appsViewData = $scope.appsView;
201 $scope.widgetsView = [];
203 $scope.applyPresentationDetailsToWidgets = function(widgetsReturned){
205 for (var i = 0; i < widgetsReturned.length; i++) {
206 $scope.widgetsView[i] = {
211 widgetIdentifier : '',
218 $scope.widgetsView[i].widgetid = widgetsReturned[i].id;
219 $scope.widgetsView[i].headerText = widgetsReturned[i].headerName;
220 $scope.widgetsView[i].widgetText = widgetsReturned[i].name;
222 if(widgetsReturned[i].headerName.toLowerCase() === 'news'){
223 $scope.widgetsView[i].widgetIdentifier = 'NEWS';
226 if(widgetsReturned[i].headerName.toLowerCase() === 'resources'){
227 $scope.widgetsView[i].widgetIdentifier = 'IMPORTANTRESOURCES';
230 if(widgetsReturned[i].headerName.toLowerCase() === 'events'){
231 $scope.widgetsView[i].widgetIdentifier = 'EVENTS';
234 $scope.widgetsView[i].url = widgetsReturned[i].url;
235 $scope.widgetsView[i].attrb = widgetsReturned[i].attrs;
236 if(widgetsReturned[i].width === null){
237 $scope.widgetsView[i].sizeX = 2;
239 $scope.widgetsView[i].sizeX = widgetsReturned[i].width;
241 if(widgetsReturned[i].height === null){
242 $scope.widgetsView[i].sizeY = 2;
244 $scope.widgetsView[i].sizeY = widgetsReturned[i].height;
246 $scope.widgetsView[i].row = widgetsReturned[i].x;
247 $scope.widgetsView[i].col = widgetsReturned[i].y;
249 if ($scope.widgetsView != undefined
250 && $scope.widgetsView != null
251 && $scope.widgetsView.length > 0) {
252 $scope.widgetsViewData = $scope.widgetsView;
257 .getUserAppsSortTypePreference().then(function(res) {
260 if (resJson.value==="N" || resJson.value==="") {
262 resJson.title = 'Name';
263 }else if (resJson.value==="L") {
265 resJson.title = 'Last used';
266 }else if(resJson.value==="F"){
268 resJson.title = 'Most used';
271 resJson.title = 'Manual';
273 $scope.selectedSortType = resJson;
274 $scope.selectedSortTypeChanged(res);
279 $scope.widgetsList = [];
281 let getUserWidgets = (loginName) => {
282 var conf = this.conf;
283 widgetsCatalogService.getUserWidgets(loginName).then(res => {
284 if(!(res instanceof Array)){
285 this.isCommError = true;
288 for(var i = 0; i < res.length; i++){
289 var widget_id = res[i][0];
290 var widget_name = res[i][1];
291 let url = this.conf.api.widgetCommon + "/" + widget_id + "/framework.js";
292 var header_name = widget_name;
294 header_name = (widget_name.length > 9) ?widget_name.substring(0, 8) + '...' : widget_name;
296 if(res[i][4] === "S" || res[i][4] === null ){
297 $scope.widgetsList.push({
299 headerName: header_name,
302 attrs: [{attr: 'data-' + res[i][0], value: ''}],
309 var script = document
310 .createElement('script');
312 script.async = false;
314 .getElementsByTagName('script')[0];
316 .insertBefore(script, entry);
318 $scope.applyPresentationDetailsToWidgets($scope.widgetsList);
320 $log.error('WidgetsHomeCtrl::getUserWidgets error: ' + err);
326 userProfileService.getUserProfile().then(
328 $scope.orgUserId = profile.orgUserId;
329 getUserWidgets($scope.orgUserId);
332 /* Widget Gridster Section */
333 $scope.newsGridsterItem = {
343 $scope.eventsGridsterItem = {
346 headerText : 'Events',
353 $scope.impoResGridsterItem = {
356 headerText : 'Resources',
363 this.gridsterAppOpts = {
367 margins : [ 20, 20 ],
376 handle:'.icon-content-gridguide',
377 stop: function stop() {
378 $scope.defaultSortBy = function() {
382 resJson.title = 'Manual';
383 $scope.selectedSortType = resJson;
384 applicationsService.saveAppsSortTypeManual($scope.appsViewData)
385 applicationsService.saveAppsSortTypePreference($scope.selectedSortType)
387 $scope.defaultSortBy();
392 this.gridsterWidgetOpts = {
396 margins : [ 20, 20 ],
403 stop: function stop(event, uiWidget, $element){
404 if($element.sizeX == 1)
405 $element.headerText = ($element.widgetText.length > 9) ? $element.widgetText.substring(0, 8) + '...' : $element.widgetText;
406 if($element.sizeX >= 2)
407 $element.headerText = $element.widgetText;
410 .saveWidgetsSortManual($scope.widgetsViewData)
415 handle:'.icon-content-gridguide',
416 stop: function stop(){
418 .saveWidgetsSortManual($scope.widgetsViewData)
424 this.goToCatalog = function(item) {
425 $state.go('root.appCatalog');
428 this.goToWidgetCatLog = function(item) {
429 $state.go('root.widgetCatalog');
432 // navigate to application url in new tab
433 this.goToPortal = function(item) {
434 userProfileService.getUserRolesForApplication($scope.orgUserId,item.appid)
437 for(var i=0;i<res.length;i++){
438 if(!res[i].isApplied)
443 if((count>0 && res.length == count)||res.length==0)
445 confirmBoxService.showInformation('You have no roles assigned to this application to access.').then(isConfirmed => {});
450 $log.error('No URL found for this application, doing nothing!');
453 if (item.restrictedApp) {
454 // Link-based apps open in their own browser tab
455 $window.open(item.url, '_blank');
457 // cache control so browsers load app page every time
458 var ccParam = 'cc=' + new Date().getTime();
459 var urlParts = item.url.split('#');
461 if (urlParts.length < 2) {
463 let urlLastChar = item.url.charAt(item.url.length - 1);
464 if (item.url.includes("?"))
465 appUrl = (urlLastChar === '&' ? item.url + ccParam : item.url + '&' + ccParam);
467 appUrl = item.url + '?' + ccParam;
470 let urlLastChar = urlParts[0].charAt(urlParts[0].length - 1);
471 if (item.url.includes("?"))
472 appUrl = (urlLastChar === '&' ? urlParts[0] + ccParam + '#' + urlParts[1] : urlParts[0] + '&' + ccParam + '#' + urlParts[1]);
474 appUrl = urlParts[0] + '?' + ccParam + "#" + urlParts[1];
476 // $log.debug('DashboardCtrlr::goToPortal: opening tab with URL
480 title: item.headerText,
484 $cookies.putObject('addTab', tabContent);
495 this.auditLog = function(app) {
497 auditLogService.storeAudit(app.appid,'app',app.url);
500 if (getParameterByName('noUserError') != null) {
501 if (getParameterByName('noUserError') == "Show") {
502 $("#errorInfo").show();
507 DashboardCtrl.$inject = [ 'conf', 'applicationsService', '$log', '$window',
508 'userProfileService', '$scope', '$cookies', '$timeout', '$interval',
509 '$modal', '$state', 'beReaderService', 'dashboardService', 'confirmBoxService',
510 'auditLogService', 'ngDialog', '$compile', 'widgetsCatalogService' ];
511 angular.module('ecompApp').controller('DashboardCtrl', DashboardCtrl);
514 function getParameterByName(name, url) {
516 url = window.location.href;
517 name = name.replace(/[\[\]]/g, "\\$&");
518 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex
524 return results[2].replace(/\+/g, " ");