2 * ================================================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ================================================================================
\r
22 function _classCallCheck(instance, Constructor) {
\r
23 if (!(instance instanceof Constructor)) {
\r
24 throw new TypeError('Cannot call a class as a function');
\r
29 var HTTP_PROTOCOL_RGX = /https?:\/\//;
\r
31 var DashboardCtrl = function DashboardCtrl(conf, applicationsService, $log,
\r
32 $window, userProfileService, $scope, $cookies, $timeout, $interval,
\r
33 $modal, $state, beReaderService, dashboardService, confirmBoxService,
\r
34 auditLogService,ngDialog, $compile, widgetsCatalogService) {
\r
39 _classCallCheck(this, DashboardCtrl);
\r
42 this.isLoading = true;
\r
43 this.isCommError = false;
\r
44 $scope.getUserAppsIsDone = false;
\r
45 this.userProfileService = userProfileService;
\r
47 $scope.event_content_show = false;
\r
48 $scope.widgetData = [];
\r
49 $scope.activateThis = function(ele){
\r
50 $compile(ele.contents())($scope);
\r
54 $scope.editWidgetModalPopup = function(availableData, resourceType) {
\r
55 $scope.editData = JSON.stringify(availableData);
\r
56 $scope.availableDataTemp = $scope.availableData;
\r
58 templateUrl : 'app/views/dashboard/dashboard-widget-manage.html',
\r
59 controller : 'CommonWidgetController',
\r
61 message : function message() {
\r
63 type : resourceType,
\r
64 availableData : $scope.editData
\r
69 }).closePromise.then(needUpdate => {
\r
70 if(resourceType=='NEWS'){
\r
71 $scope.updateNews();
\r
72 }else if(resourceType=='EVENTS'){
\r
73 $scope.updateEvents();
\r
74 }else if(resourceType=='IMPORTANTRESOURCES'){
\r
75 $scope.updateImportRes();
\r
80 $scope.editWidgetParameters = function(widgetId) {
\r
85 templateUrl : 'app/views/dashboard/dashboard-widget-parameter-manage.html',
\r
86 controller : 'WidgetParameterController',
\r
88 }).closePromise.then(needUpdate => {
\r
93 $scope.sort_options = [
\r
94 {index: 0, value: 'N', title: 'Name'},
\r
95 {index: 1, value: 'L', title: 'Last used'},
\r
96 {index: 2, value: 'F', title: 'Most used'},
\r
97 {index: 3, value: 'M', title: 'Manual'}
\r
100 $scope.selectedSortTypeChanged = function(userAppSortTypePref) {
\r
101 $scope.appsViewData = [];
\r
102 $scope.appsView = [];
\r
104 $scope.sort_type = userAppSortTypePref;
\r
106 applicationsService
\r
107 .getAppsOrderBySortPref(userAppSortTypePref)
\r
108 .then(function(res) {
\r
110 $scope.applyPresentationDetailsToApps(_this.apps);
\r
112 applicationsService
\r
113 .saveAppsSortTypePreference($scope.selectedSortType)
\r
114 .then(function(res) {
\r
119 $scope.$watch('selectedSortType.value', (newVal, oldVal) => {
\r
120 for(var i=0;i<$scope.sort_options.length;i++){
\r
121 if($scope.sort_options[i].value==newVal){
\r
122 $scope.selectedSortType=angular.copy($scope.sort_options[i]);;
\r
127 $scope.restoreSortSelected = function(){
\r
128 confirmBoxService.confirm("Restore the default size and position of all widgets?").then(
\r
129 function(confirmed){
\r
130 var checkConfirm = confirmed;
\r
131 if(checkConfirm === true){
\r
132 applicationsService
\r
133 .delWidgetsSortPref($scope.widgetsViewData).then(function(){
\r
138 /* if(confirm('Restore the default size and position of all widgets?') == true)
\r
140 applicationsService
\r
141 .delWidgetsSortPref($scope.widgetsViewData).then(function(){
\r
148 $scope.applyPresentationDetailsToApps = function(appsReturned) {
\r
150 for (var i = 0; i < _this.apps.length; i++) {
\r
151 $scope.appsView[i] = {
\r
155 subHeaderText : '',
\r
161 $scope.appsView[i].headerText = appsReturned[i].name;
\r
162 $scope.appsView[i].subHeaderText = appsReturned[i].notes;
\r
164 if (appsReturned[i].imageUrl)
\r
165 imgLnk = conf.api.appThumbnail.replace(':appId', appsReturned[i].id);
\r
166 //$log.debug('DashboardCtlr::applyPresn: imgLink = ' + imgLnk);
\r
167 $scope.appsView[i].imageLink = imgLnk;
\r
168 $scope.appsView[i].order = appsReturned[i].order;
\r
169 $scope.appsView[i].url = appsReturned[i].url;
\r
170 $scope.appsView[i].restrictedApp = appsReturned[i].restrictedApp;
\r
171 $scope.appsView[i].appid = appsReturned[i].id;
\r
173 $scope.appsView[_this.apps.length] = {
\r
174 addRemoveApps : true,
\r
177 headerText : 'Add/Remove Applications',
\r
178 subHeaderText : '',
\r
179 imageLink : 'assets/images/cloud.png',
\r
181 restrictedApp : false,
\r
184 if($scope.appsView.length>6){
\r
185 $(".dashboard-boarder").css({
\r
189 $(".dashboard-boarder").css({
\r
194 if ($scope.appsView != undefined
\r
195 && $scope.appsView != null
\r
196 && $scope.appsView.length > 0) {
\r
197 $scope.appsViewData = $scope.appsView;
\r
201 $scope.widgetsView = [];
\r
203 $scope.applyPresentationDetailsToWidgets = function(widgetsReturned){
\r
205 for (var i = 0; i < widgetsReturned.length; i++) {
\r
206 $scope.widgetsView[i] = {
\r
211 widgetIdentifier : '',
\r
218 $scope.widgetsView[i].widgetid = widgetsReturned[i].id;
\r
219 $scope.widgetsView[i].headerText = widgetsReturned[i].headerName;
\r
220 $scope.widgetsView[i].widgetText = widgetsReturned[i].name;
\r
222 if(widgetsReturned[i].headerName.toLowerCase() === 'news'){
\r
223 $scope.widgetsView[i].widgetIdentifier = 'NEWS';
\r
226 if(widgetsReturned[i].headerName.toLowerCase() === 'resources'){
\r
227 $scope.widgetsView[i].widgetIdentifier = 'IMPORTANTRESOURCES';
\r
230 if(widgetsReturned[i].headerName.toLowerCase() === 'events'){
\r
231 $scope.widgetsView[i].widgetIdentifier = 'EVENTS';
\r
234 $scope.widgetsView[i].url = widgetsReturned[i].url;
\r
235 $scope.widgetsView[i].attrb = widgetsReturned[i].attrs;
\r
236 if(widgetsReturned[i].width === null){
\r
237 $scope.widgetsView[i].sizeX = 2;
\r
239 $scope.widgetsView[i].sizeX = widgetsReturned[i].width;
\r
241 if(widgetsReturned[i].height === null){
\r
242 $scope.widgetsView[i].sizeY = 2;
\r
244 $scope.widgetsView[i].sizeY = widgetsReturned[i].height;
\r
246 $scope.widgetsView[i].row = widgetsReturned[i].x;
\r
247 $scope.widgetsView[i].col = widgetsReturned[i].y;
\r
249 if ($scope.widgetsView != undefined
\r
250 && $scope.widgetsView != null
\r
251 && $scope.widgetsView.length > 0) {
\r
252 $scope.widgetsViewData = $scope.widgetsView;
\r
256 applicationsService
\r
257 .getUserAppsSortTypePreference().then(function(res) {
\r
259 resJson.value = res;
\r
260 if (resJson.value==="N" || resJson.value==="") {
\r
262 resJson.title = 'Name';
\r
263 }else if (resJson.value==="L") {
\r
265 resJson.title = 'Last used';
\r
266 }else if(resJson.value==="F"){
\r
268 resJson.title = 'Most used';
\r
271 resJson.title = 'Manual';
\r
273 $scope.selectedSortType = resJson;
\r
274 $scope.selectedSortTypeChanged(res);
\r
279 $scope.widgetsList = [];
\r
281 let getUserWidgets = (loginName) => {
\r
282 var conf = this.conf;
\r
283 widgetsCatalogService.getUserWidgets(loginName).then(res => {
\r
284 if(!(res instanceof Array)){
\r
285 this.isCommError = true;
\r
288 for(var i = 0; i < res.length; i++){
\r
289 var widget_id = res[i][0];
\r
290 var widget_name = res[i][1];
\r
291 let url = this.conf.api.widgetCommon + "/" + widget_id + "/framework.js";
\r
292 var header_name = widget_name;
\r
293 if(res[i][7] == 1){
\r
294 header_name = (widget_name.length > 9) ?widget_name.substring(0, 8) + '...' : widget_name;
\r
296 if(res[i][4] === "S" || res[i][4] === null ){
\r
297 $scope.widgetsList.push({
\r
299 headerName: header_name,
\r
302 attrs: [{attr: 'data-' + res[i][0], value: ''}],
\r
309 var script = document
\r
310 .createElement('script');
\r
312 script.async = false;
\r
313 var entry = document
\r
314 .getElementsByTagName('script')[0];
\r
316 .insertBefore(script, entry);
\r
318 $scope.applyPresentationDetailsToWidgets($scope.widgetsList);
\r
320 $log.error('WidgetsHomeCtrl::getUserWidgets error: ' + err);
\r
326 userProfileService.getUserProfile().then(
\r
327 function(profile) {
\r
328 $scope.orgUserId = profile.orgUserId;
\r
329 getUserWidgets($scope.orgUserId);
\r
332 /* Widget Gridster Section */
\r
333 $scope.newsGridsterItem = {
\r
336 headerText : 'News',
\r
337 subHeaderText : '',
\r
343 $scope.eventsGridsterItem = {
\r
346 headerText : 'Events',
\r
347 subHeaderText : '',
\r
353 $scope.impoResGridsterItem = {
\r
356 headerText : 'Resources',
\r
357 subHeaderText : '',
\r
363 this.gridsterAppOpts = {
\r
367 margins : [ 20, 20 ],
\r
368 outerMargin : true,
\r
376 handle:'.icon-content-gridguide',
\r
377 stop: function stop() {
\r
378 $scope.defaultSortBy = function() {
\r
380 resJson.value = 'M';
\r
382 resJson.title = 'Manual';
\r
383 $scope.selectedSortType = resJson;
\r
384 applicationsService.saveAppsSortTypeManual($scope.appsViewData)
\r
385 applicationsService.saveAppsSortTypePreference($scope.selectedSortType)
\r
387 $scope.defaultSortBy();
\r
392 this.gridsterWidgetOpts = {
\r
396 margins : [ 20, 20 ],
\r
397 outerMargin : true,
\r
403 stop: function stop(event, uiWidget, $element){
\r
404 if($element.sizeX == 1)
\r
405 $element.headerText = ($element.widgetText.length > 9) ? $element.widgetText.substring(0, 8) + '...' : $element.widgetText;
\r
406 if($element.sizeX >= 2)
\r
407 $element.headerText = $element.widgetText;
\r
409 applicationsService
\r
410 .saveWidgetsSortManual($scope.widgetsViewData)
\r
415 handle:'.icon-content-gridguide',
\r
416 stop: function stop(){
\r
417 applicationsService
\r
418 .saveWidgetsSortManual($scope.widgetsViewData)
\r
424 this.goToCatalog = function(item) {
\r
425 $state.go('root.appCatalog');
\r
428 this.goToWidgetCatLog = function(item) {
\r
429 $state.go('root.widgetCatalog');
\r
432 // navigate to application url in new tab
\r
433 this.goToPortal = function(item) {
\r
435 $log.error('No URL found for this application, doing nothing!');
\r
438 if (item.restrictedApp) {
\r
439 // Link-based apps open in their own browser tab
\r
440 $window.open(item.url, '_blank');
\r
442 // cache control so browsers load app page every time
\r
443 var ccParam = 'cc=' + new Date().getTime();
\r
444 var urlParts = item.url.split('#');
\r
446 if (urlParts.length < 2) {
\r
448 let urlLastChar = item.url.charAt(item.url.length - 1);
\r
449 if (item.url.includes("?"))
\r
450 appUrl = (urlLastChar === '&' ? item.url + ccParam : item.url + '&' + ccParam);
\r
452 appUrl = item.url + '?' + ccParam;
\r
455 let urlLastChar = urlParts[0].charAt(urlParts[0].length - 1);
\r
456 if (item.url.includes("?"))
\r
457 appUrl = (urlLastChar === '&' ? urlParts[0] + ccParam + '#' + urlParts[1] : urlParts[0] + '&' + ccParam + '#' + urlParts[1]);
\r
459 appUrl = urlParts[0] + '?' + ccParam + "#" + urlParts[1];
\r
461 // $log.debug('DashboardCtrlr::goToPortal: opening tab with URL
\r
465 title: item.headerText,
\r
469 $cookies.putObject('addTab', tabContent);
\r
474 this.auditLog = function(app) {
\r
476 auditLogService.storeAudit(app.appid,'app',app.url);
\r
479 if (getParameterByName('noUserError') != null) {
\r
480 if (getParameterByName('noUserError') == "Show") {
\r
481 $("#errorInfo").show();
\r
486 DashboardCtrl.$inject = [ 'conf', 'applicationsService', '$log', '$window',
\r
487 'userProfileService', '$scope', '$cookies', '$timeout', '$interval',
\r
488 '$modal', '$state', 'beReaderService', 'dashboardService', 'confirmBoxService',
\r
489 'auditLogService', 'ngDialog', '$compile', 'widgetsCatalogService' ];
\r
490 angular.module('ecompApp').controller('DashboardCtrl', DashboardCtrl);
\r
493 function getParameterByName(name, url) {
\r
495 url = window.location.href;
\r
496 name = name.replace(/[\[\]]/g, "\\$&");
\r
497 var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), results = regex
\r
503 return results[2].replace(/\+/g, " ");
\r