Files
redash/client/app/components/app-view/index.js
koooge 2da511021e Frontend lint update (#3253)
* client: Add lint command

Signed-off-by: koooge <koooooge@gmail.com>

* client: Override eslint rule object-curly-newline to keep current style

Signed-off-by: koooge <koooooge@gmail.com>

* client: Override eslint rule no-else-return to keep current style

Signed-off-by: koooge <koooooge@gmail.com>

* client: Fix eslint import/named

Signed-off-by: koooge <koooooge@gmail.com>

* client: eslint-5

Signed-off-by: koooge <koooooge@gmail.com>

* codeclimate: Delete the old setting

Signed-off-by: koooge <koooooge@gmail.com>

* client: Downgrade eslint 5 to 4 in codeclimate

Signed-off-by: koooge <koooooge@gmail.com>

* client: npx install-peerdeps --dev eslint-config-airbnb

Signed-off-by: koooge <koooooge@gmail.com>

* client: Enbale .jsx lint

Signed-off-by: koooge <koooooge@gmail.com>

* client: Set warn

Signed-off-by: koooge <koooooge@gmail.com>

* client: Fix lint indent, implicit-arrow-linebreak, lines-between-class-members

Signed-off-by: koooge <koooooge@gmail.com>

* client: Disable eslint operator-linebreak

Signed-off-by: koooge <koooooge@gmail.com>

* Revert "client: Downgrade eslint 5 to 4 in codeclimate"

This reverts commit f0fb0f0059.

* client: Fix react/button-has-type

Signed-off-by: koooge <koooooge@gmail.com>

* client: Disable an eslint rule react/jsx-one-expression-per-line

Signed-off-by: koooge <koooooge@gmail.com>

* codeclimate: Disable no-multiple-empty-lines

Signed-off-by: koooge <koooooge@gmail.com>

* client: Disable eslint react/destructuring-assignment

Signed-off-by: koooge <koooooge@gmail.com>
2019-01-29 17:25:58 +02:00

99 lines
2.5 KiB
JavaScript

import debug from 'debug';
import PromiseRejectionError from '@/lib/promise-rejection-error';
import { ErrorHandler } from './error-handler';
import template from './template.html';
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] || layouts.default;
} else if (!route.authenticated) {
layout = layouts.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();
// In case we're handling $routeProvider.otherwise call, there will be no
// $$route.
const $$route = route.$$route || { authenticated: true };
if ($$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()) {
event.preventDefault();
// Auth.requireSession resolves only if session loaded
Auth.requireSession().then(() => {
this.applyLayout($$route);
$route.reload();
});
}
}
});
$rootScope.$on('$routeChangeSuccess', (event, route) => {
const $$route = route.$$route || { authenticated: true };
this.applyLayout($$route);
});
$rootScope.$on('$routeChangeError', (event, current, previous, rejection) => {
const $$route = current.$$route || { authenticated: true };
this.applyLayout($$route);
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);
},
);
ngModule.component('appView', {
template,
controller: AppViewComponent,
});
}
init.init = true;