Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (42 sloc) 1.34 KB
import {dispatch} from '~/index';
import state from './state';
import {Layout, ErrorReport, Login, WidgetsOverview, WidgetDetail} from './views';
function loggedin(fn) {
return function(state, task) {
if (!state.user) {
m.route.set('/login');
} else {
return fn(state, task);
}
};
}
dispatch(document.getElementById('root'), '/error', state, {
'/': () => Login,
'/login': () => Login,
'/error': () => ErrorReport,
'/:tenant/widgets': loggedin((app, task) => {
task(() => app.selectTenant(app.spaRequest.tenant))
.then(() => task(app.loadWidgetListing))
.then(() => {
return Promise.race([
task(() => app.computeAnalytics(0)),
task(() => app.computeAnalytics(1)),
task(() => app.computeAnalytics(2)),
]);
});
return {
layout: Layout,
comp: WidgetsOverview
};
}),
'/:tenant/widgets/:id': loggedin((app, task) => {
const {id, tenant} = app.spaRequest;
app.focusedWidget = null;
task(() => app.selectTenant(app.spaRequest.tenant)
.then(() => app.loadWidget(id)));
return {
layout: Layout,
comp: WidgetDetail
};
}),
});