Commit 3baaf2c3 by Torkel Ödegaard

Added handling of kiosk mode

parent fdeea914
...@@ -15,6 +15,7 @@ import sortByKeys from 'app/core/utils/sort_by_keys'; ...@@ -15,6 +15,7 @@ import sortByKeys from 'app/core/utils/sort_by_keys';
import { PanelModel } from './PanelModel'; import { PanelModel } from './PanelModel';
import { DashboardMigrator } from './DashboardMigrator'; import { DashboardMigrator } from './DashboardMigrator';
import { TimeRange } from '@grafana/ui/src'; import { TimeRange } from '@grafana/ui/src';
import { UrlQueryValue } from 'app/types';
export class DashboardModel { export class DashboardModel {
id: any; id: any;
...@@ -867,11 +868,7 @@ export class DashboardModel { ...@@ -867,11 +868,7 @@ export class DashboardModel {
return !_.isEqual(updated, this.originalTemplating); return !_.isEqual(updated, this.originalTemplating);
} }
autoFitPanels(viewHeight: number) { autoFitPanels(viewHeight: number, kioskMode?: UrlQueryValue) {
if (!this.meta.autofitpanels) {
return;
}
const currentGridHeight = Math.max( const currentGridHeight = Math.max(
...this.panels.map(panel => { ...this.panels.map(panel => {
return panel.gridPos.h + panel.gridPos.y; return panel.gridPos.h + panel.gridPos.y;
...@@ -885,12 +882,12 @@ export class DashboardModel { ...@@ -885,12 +882,12 @@ export class DashboardModel {
let visibleHeight = viewHeight - navbarHeight - margin; let visibleHeight = viewHeight - navbarHeight - margin;
// Remove submenu height if visible // Remove submenu height if visible
if (this.meta.submenuEnabled && !this.meta.kiosk) { if (this.meta.submenuEnabled && !kioskMode) {
visibleHeight -= submenuHeight; visibleHeight -= submenuHeight;
} }
// add back navbar height // add back navbar height
if (this.meta.kiosk === 'b') { if (kioskMode === 'tv') {
visibleHeight += 55; visibleHeight += 55;
} }
......
...@@ -56,10 +56,6 @@ export function initDashboard({ ...@@ -56,10 +56,6 @@ export function initDashboard({
try { try {
switch (routeInfo) { switch (routeInfo) {
// handle old urls with no uid // handle old urls with no uid
case DashboardRouteInfo.Old: {
redirectToNewUrl(urlSlug, dispatch);
return;
}
case DashboardRouteInfo.Home: { case DashboardRouteInfo.Home: {
// load home dash // load home dash
dashDTO = await getBackendSrv().get('/api/dashboards/home'); dashDTO = await getBackendSrv().get('/api/dashboards/home');
...@@ -78,20 +74,27 @@ export function initDashboard({ ...@@ -78,20 +74,27 @@ export function initDashboard({
break; break;
} }
case DashboardRouteInfo.Normal: { case DashboardRouteInfo.Normal: {
// for old db routes we redirect
if (urlType === 'db') {
redirectToNewUrl(urlSlug, dispatch);
return;
}
const loaderSrv = $injector.get('dashboardLoaderSrv'); const loaderSrv = $injector.get('dashboardLoaderSrv');
dashDTO = await loaderSrv.loadDashboard(urlType, urlSlug, urlUid); dashDTO = await loaderSrv.loadDashboard(urlType, urlSlug, urlUid);
// check if the current url is correct (might be old slug) if (dashDTO.meta.url) {
const dashboardUrl = locationUtil.stripBaseFromUrl(dashDTO.meta.url); // check if the current url is correct (might be old slug)
const currentPath = getState().location.path; const dashboardUrl = locationUtil.stripBaseFromUrl(dashDTO.meta.url);
console.log('loading dashboard: currentPath', currentPath); const currentPath = getState().location.path;
console.log('loading dashboard: dashboardUrl', dashboardUrl);
if (dashboardUrl !== currentPath) { if (dashboardUrl !== currentPath) {
// replace url to not create additional history items and then return so that initDashboard below isn't executed multiple times. // replace url to not create additional history items and then return so that initDashboard below isn't executed multiple times.
dispatch(updateLocation({ path: dashboardUrl, partial: true, replace: true })); dispatch(updateLocation({ path: dashboardUrl, partial: true, replace: true }));
return; return;
}
} }
break; break;
} }
case DashboardRouteInfo.New: { case DashboardRouteInfo.New: {
...@@ -129,7 +132,6 @@ export function initDashboard({ ...@@ -129,7 +132,6 @@ export function initDashboard({
const variableSrv: VariableSrv = $injector.get('variableSrv'); const variableSrv: VariableSrv = $injector.get('variableSrv');
const keybindingSrv: KeybindingSrv = $injector.get('keybindingSrv'); const keybindingSrv: KeybindingSrv = $injector.get('keybindingSrv');
const unsavedChangesSrv = $injector.get('unsavedChangesSrv'); const unsavedChangesSrv = $injector.get('unsavedChangesSrv');
const viewStateSrv = $injector.get('dashboardViewStateSrv');
const dashboardSrv: DashboardSrv = $injector.get('dashboardSrv'); const dashboardSrv: DashboardSrv = $injector.get('dashboardSrv');
timeSrv.init(dashboard); timeSrv.init(dashboard);
...@@ -147,14 +149,16 @@ export function initDashboard({ ...@@ -147,14 +149,16 @@ export function initDashboard({
try { try {
dashboard.processRepeats(); dashboard.processRepeats();
dashboard.updateSubmenuVisibility(); dashboard.updateSubmenuVisibility();
dashboard.autoFitPanels(window.innerHeight);
// handle auto fix experimental feature
const queryParams = getState().location.query;
if (queryParams.autofitpanels) {
dashboard.autoFitPanels(window.innerHeight, queryParams.kiosk);
}
// init unsaved changes tracking // init unsaved changes tracking
unsavedChangesSrv.init(dashboard, $scope); unsavedChangesSrv.init(dashboard, $scope);
$scope.dashboard = dashboard;
viewStateSrv.create($scope);
// dashboard keybindings should not live in core, this needs a bigger refactoring // dashboard keybindings should not live in core, this needs a bigger refactoring
// So declaring this here so it can depend on the removePanel util function // So declaring this here so it can depend on the removePanel util function
// Long term onRemovePanel should be handled via react prop callback // Long term onRemovePanel should be handled via react prop callback
......
...@@ -62,7 +62,7 @@ export function setupAngularRoutes($routeProvider, $locationProvider) { ...@@ -62,7 +62,7 @@ export function setupAngularRoutes($routeProvider, $locationProvider) {
.when('/dashboard/:type/:slug', { .when('/dashboard/:type/:slug', {
template: '<react-container />', template: '<react-container />',
pageClass: 'page-dashboard', pageClass: 'page-dashboard',
routeInfo: DashboardRouteInfo.Old, routeInfo: DashboardRouteInfo.Normal,
reloadOnSearch: false, reloadOnSearch: false,
resolve: { resolve: {
component: () => DashboardPage, component: () => DashboardPage,
...@@ -88,7 +88,7 @@ export function setupAngularRoutes($routeProvider, $locationProvider) { ...@@ -88,7 +88,7 @@ export function setupAngularRoutes($routeProvider, $locationProvider) {
.when('/dashboard-solo/:type/:slug', { .when('/dashboard-solo/:type/:slug', {
template: '<react-container />', template: '<react-container />',
pageClass: 'dashboard-solo', pageClass: 'dashboard-solo',
routeInfo: DashboardRouteInfo.Old, routeInfo: DashboardRouteInfo.Normal,
resolve: { resolve: {
component: () => SoloPanelPage, component: () => SoloPanelPage,
}, },
......
...@@ -8,10 +8,10 @@ export interface MutableDashboard { ...@@ -8,10 +8,10 @@ export interface MutableDashboard {
} }
export enum DashboardRouteInfo { export enum DashboardRouteInfo {
Old = 'old-dashboard',
Home = 'home-dashboard', Home = 'home-dashboard',
New = 'new-dashboard', New = 'new-dashboard',
Normal = 'normal-dashboard', Normal = 'normal-dashboard',
Scripted = 'scripted-dashboard',
} }
export enum DashboardLoadingState { export enum DashboardLoadingState {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment