diff --git a/client/app/components/app-view/index.js b/client/app/components/app-view/index.js index cb1e53b2..d37e1a81 100644 --- a/client/app/components/app-view/index.js +++ b/client/app/components/app-view/index.js @@ -7,6 +7,73 @@ const logger = debug('redash:app-view'); const handler = new ErrorHandler(); +const layouts = { + default: { + showHeader: true, + showFooter: true, + bodyClass: false, + }, + fixed: { + showHeader: true, + showFooter: false, + bodyClass: 'fixed-layout', + }, + defaultSignedOut: { + showHeader: false, + showFooter: false, + }, +}; + +function selectLayout(route) { + let layout = layouts.default; + if (route.layout) { + layout = layouts[route.layout]; + } else if (!route.authenticated) { + layout = layout.defaultSignedOut; + } + return layout; +} + +class AppViewComponent { + constructor($rootScope, $route, Auth) { + this.$rootScope = $rootScope; + this.showHeaderAndFooter = false; + this.layout = layouts.defaultSignedOut; + this.handler = handler; + + $rootScope.$on('$routeChangeStart', (event, route) => { + this.handler.reset(); + + if (route.$$route.authenticated) { + // For routes that need authentication, check if session is already + // loaded, and load it if not. + logger('Requested authenticated route: ', route); + if (Auth.isAuthenticated()) { + this.applyLayout(route.$$route); + } else { + event.preventDefault(); + // Auth.requireSession resolves only if session loaded + Auth.requireSession().then(() => { + this.applyLayout(route.$$route); + $route.reload(); + }); + } + } else { + this.applyLayout(route.$$route); + } + }); + + $rootScope.$on('$routeChangeError', (event, current, previous, rejection) => { + throw new PromiseRejectionError(rejection); + }); + } + + applyLayout(route) { + this.layout = selectLayout(route); + this.$rootScope.bodyClass = this.layout.bodyClass; + } +} + export default function init(ngModule) { ngModule.factory('$exceptionHandler', () => function exceptionHandler(exception) { handler.process(exception); @@ -14,35 +81,6 @@ export default function init(ngModule) { ngModule.component('appView', { template, - controller($rootScope, $route, Auth) { - this.showHeaderAndFooter = false; - - this.handler = handler; - - $rootScope.$on('$routeChangeStart', (event, route) => { - this.handler.reset(); - if (route.$$route.authenticated) { - // For routes that need authentication, check if session is already - // loaded, and load it if not. - logger('Requested authenticated route: ', route); - if (Auth.isAuthenticated()) { - this.showHeaderAndFooter = true; - } else { - event.preventDefault(); - // Auth.requireSession resolves only if session loaded - Auth.requireSession().then(() => { - this.showHeaderAndFooter = true; - $route.reload(); - }); - } - } else { - this.showHeaderAndFooter = false; - } - }); - - $rootScope.$on('$routeChangeError', (event, current, previous, rejection) => { - throw new PromiseRejectionError(rejection); - }); - }, + controller: AppViewComponent, }); } diff --git a/client/app/components/app-view/template.html b/client/app/components/app-view/template.html index ae5ddcdb..549b2cea 100644 --- a/client/app/components/app-view/template.html +++ b/client/app/components/app-view/template.html @@ -1,6 +1,6 @@ - +
{{ $ctrl.handler.error.message }}
- + \ No newline at end of file diff --git a/client/app/index.html b/client/app/index.html index e071538b..7e76d957 100644 --- a/client/app/index.html +++ b/client/app/index.html @@ -11,7 +11,7 @@ - +
diff --git a/client/app/multi_org.html b/client/app/multi_org.html index 8a7cbff5..f8de8da8 100644 --- a/client/app/multi_org.html +++ b/client/app/multi_org.html @@ -11,7 +11,7 @@ - +
diff --git a/client/app/pages/queries/source-view.js b/client/app/pages/queries/source-view.js index b703fa35..ec416e35 100644 --- a/client/app/pages/queries/source-view.js +++ b/client/app/pages/queries/source-view.js @@ -112,6 +112,7 @@ export default function init(ngModule) { return { '/queries/new': { template, + layout: 'fixed', controller: 'QuerySourceCtrl', reloadOnSearch: false, resolve: { @@ -129,6 +130,7 @@ export default function init(ngModule) { }, '/queries/:queryId/source': { template, + layout: 'fixed', controller: 'QuerySourceCtrl', reloadOnSearch: false, resolve: { diff --git a/client/app/pages/queries/view.js b/client/app/pages/queries/view.js index 836739e9..57eac6b2 100644 --- a/client/app/pages/queries/view.js +++ b/client/app/pages/queries/view.js @@ -424,6 +424,7 @@ export default function init(ngModule) { return { '/queries/:queryId': { template, + layout: 'fixed', controller: 'QueryViewCtrl', reloadOnSearch: false, resolve: {