From 47af95d3ed2d12cc7c1e94f102e0f2b87d4b2257 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Thu, 5 Jul 2018 18:37:09 +0300 Subject: [PATCH] Dashboard load improvements. --- ui/src/app/api/dashboard.service.js | 2 +- ui/src/app/api/user.service.js | 7 ++++--- ui/src/app/app.run.js | 7 +++++-- .../app/components/widget/widget.controller.js | 6 +++++- ui/src/app/dashboard/dashboard.controller.js | 11 ++++++++++- ui/src/app/dashboard/dashboard.routes.js | 18 ++++++++++++++++++ ui/src/app/dashboard/dashboard.tpl.html | 2 +- 7 files changed, 44 insertions(+), 9 deletions(-) diff --git a/ui/src/app/api/dashboard.service.js b/ui/src/app/api/dashboard.service.js index 507fe9767a..adab48fb46 100644 --- a/ui/src/app/api/dashboard.service.js +++ b/ui/src/app/api/dashboard.service.js @@ -252,7 +252,7 @@ function DashboardService($rootScope, $http, $q, $location, $filter) { if (port != 80 && port != 443) { url += ":" + port; } - url += "/dashboards/" + dashboard.id.id + "?publicId=" + dashboard.publicCustomerId; + url += "/dashboard/" + dashboard.id.id + "?publicId=" + dashboard.publicCustomerId; return url; } diff --git a/ui/src/app/api/user.service.js b/ui/src/app/api/user.service.js index cb85709384..48c811bb8d 100644 --- a/ui/src/app/api/user.service.js +++ b/ui/src/app/api/user.service.js @@ -488,7 +488,8 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, logi } else { return true; } - } else if (to.name === 'home.dashboards.dashboard' && allowedDashboardIds.indexOf(params.dashboardId) > -1) { + } else if ((to.name === 'home.dashboards.dashboard' || to.name === 'dashboard') + && allowedDashboardIds.indexOf(params.dashboardId) > -1) { return false; } else { return true; @@ -504,10 +505,10 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, logi var place = 'home.links'; if (currentUser.authority === 'TENANT_ADMIN' || currentUser.authority === 'CUSTOMER_USER') { if (userHasDefaultDashboard()) { - place = 'home.dashboards.dashboard'; + place = $rootScope.forceFullscreen ? 'dashboard' : 'home.dashboards.dashboard'; params = {dashboardId: currentUserDetails.additionalInfo.defaultDashboardId}; } else if (isPublic()) { - place = 'home.dashboards.dashboard'; + place = 'dashboard'; params = {dashboardId: lastPublicDashboardId}; } } else if (currentUser.authority === 'SYS_ADMIN') { diff --git a/ui/src/app/app.run.js b/ui/src/app/app.run.js index f3886b8dec..4667b09e06 100644 --- a/ui/src/app/app.run.js +++ b/ui/src/app/app.run.js @@ -113,7 +113,10 @@ export default function AppRun($rootScope, $window, $injector, $location, $log, showForbiddenDialog(); } else if (to.redirectTo) { evt.preventDefault(); - $state.go(to.redirectTo, params) + $state.go(to.redirectTo, params); + } else if (to.name === 'home.dashboards.dashboard' && $rootScope.forceFullscreen) { + evt.preventDefault(); + $state.go('dashboard', params); } } } else { @@ -138,7 +141,7 @@ export default function AppRun($rootScope, $window, $injector, $location, $log, $rootScope.pageTitle = 'ThingsBoard'; $rootScope.stateChangeSuccessHandle = $rootScope.$on('$stateChangeSuccess', function (evt, to, params) { - if (userService.isPublic() && to.name === 'home.dashboards.dashboard') { + if (userService.isPublic() && to.name === 'dashboard') { $location.search('publicId', userService.getPublicId()); userService.updateLastPublicDashboardId(params.dashboardId); } diff --git a/ui/src/app/components/widget/widget.controller.js b/ui/src/app/components/widget/widget.controller.js index 9feb40d7b5..36e5bee1cc 100644 --- a/ui/src/app/components/widget/widget.controller.js +++ b/ui/src/app/components/widget/widget.controller.js @@ -479,7 +479,11 @@ export default function WidgetController($scope, $state, $timeout, $window, $ele dashboardId: targetDashboardId, state: utils.objToBase64([ stateObject ]) } - $state.go('home.dashboards.dashboard', stateParams); + if ($state.current.name === 'dashboard') { + $state.go('dashboard', stateParams); + } else { + $state.go('home.dashboards.dashboard', stateParams); + } break; case types.widgetActionTypes.custom.value: var customFunction = descriptor.customFunction; diff --git a/ui/src/app/dashboard/dashboard.controller.js b/ui/src/app/dashboard/dashboard.controller.js index f672f3f03b..6df48df032 100644 --- a/ui/src/app/dashboard/dashboard.controller.js +++ b/ui/src/app/dashboard/dashboard.controller.js @@ -196,6 +196,7 @@ export default function DashboardController(types, utils, dashboardUtils, widget vm.displayDashboardTimewindow = displayDashboardTimewindow; vm.displayDashboardsSelect = displayDashboardsSelect; vm.displayEntitiesSelect = displayEntitiesSelect; + vm.hideFullscreenButton = hideFullscreenButton; vm.widgetsBundle; @@ -258,7 +259,11 @@ export default function DashboardController(types, utils, dashboardUtils, widget dashboardId: vm.currentDashboardId }); } else { - $state.go('home.dashboards.dashboard', {dashboardId: vm.currentDashboardId}); + if ($state.current.name === 'dashboard') { + $state.go('dashboard', {dashboardId: vm.currentDashboardId}); + } else { + $state.go('home.dashboards.dashboard', {dashboardId: vm.currentDashboardId}); + } } } }); @@ -805,6 +810,10 @@ export default function DashboardController(types, utils, dashboardUtils, widget } } + function hideFullscreenButton() { + return vm.widgetEditMode || vm.iframeMode || $rootScope.forceFullscreen || $state.current.name === 'dashboard'; + } + function onRevertWidgetEdit(widgetForm) { if (widgetForm.$dirty) { widgetForm.$setPristine(); diff --git a/ui/src/app/dashboard/dashboard.routes.js b/ui/src/app/dashboard/dashboard.routes.js index ccb43c708f..4572ac38f7 100644 --- a/ui/src/app/dashboard/dashboard.routes.js +++ b/ui/src/app/dashboard/dashboard.routes.js @@ -86,6 +86,24 @@ export default function DashboardRoutes($stateProvider) { label: '{"icon": "dashboard", "label": "{{ vm.dashboard.title }}", "translate": "false"}' } }) + .state('dashboard', { + url: '/dashboard/:dashboardId?state', + reloadOnSearch: false, + module: 'private', + auth: ['TENANT_ADMIN', 'CUSTOMER_USER'], + views: { + "@": { + templateUrl: dashboardTemplate, + controller: 'DashboardController', + controllerAs: 'vm' + } + }, + data: { + widgetEditMode: false, + searchEnabled: false, + pageTitle: 'dashboard.dashboard' + } + }) .state('home.customers.dashboards.dashboard', { url: '/:dashboardId?state', reloadOnSearch: false, diff --git a/ui/src/app/dashboard/dashboard.tpl.html b/ui/src/app/dashboard/dashboard.tpl.html index 9626509a51..829f174fe7 100644 --- a/ui/src/app/dashboard/dashboard.tpl.html +++ b/ui/src/app/dashboard/dashboard.tpl.html @@ -16,7 +16,7 @@ --> + hide-expand-button="vm.hideFullscreenButton()" expand-tooltip-direction="bottom" ng-if="vm.dashboard">