Commit 3aa66cf1 authored by Sandro Lutz's avatar Sandro Lutz
Browse files

Update routing (See discussions in !55)

parent 2d5e2851
......@@ -31,182 +31,123 @@ if (verbose !== true) {
m.route.prefix('');
}
function onmatch(args, requestedPath, component) {
if (isLanguageValid(args.language)) {
changeLanguage(args.language);
return component;
}
return {
view() {
return m(layout, m(Error404));
},
};
}
function onmatchAuthenticated(args, requestedPath, component) {
if (!isLoggedIn()) {
// m.route.set(`/${currentLanguage()}/login`);
return {
view() {
return m(layout, m(Error401));
},
};
}
return onmatch(args, requestedPath, component);
}
m.route(document.body, '/', {
'/': {
onmatch() {
m.route.set(`/${currentLanguage()}/`);
},
// routes which require authentication
const routesAuth = [
{
url: '/:language/studydocuments',
view: () => m(studydocList),
},
'/:language': {
onmatch(args, requestedPath) {
return onmatch(args, requestedPath, {
view() {
return m(layout, m(amivLayout, m(frontpage)));
},
});
},
{
url: '/:language/studydocuments/new',
view: () => m(studydocNew),
},
'/:language/amiv/statuten': {
onmatch(args, requestedPath) {
return onmatch(args, requestedPath, {
view() {
return m(layout, m(amivLayout, m(statuten)));
},
});
},
{
url: '/:language/profile',
view: vnode => m(profile, vnode.attrs),
},
'/:language/contact': {
onmatch(args, requestedPath) {
return onmatch(args, requestedPath, {
view() {
return m(layout, m(contact));
},
});
},
];
// routes without restrictions
const routes = [
{
url: '/:language',
view: () => m(amivLayout, m(frontpage)),
},
'/:language/amiv/aufenthaltsraum': {
onmatch(args, requestedPath) {
return onmatch(args, requestedPath, {
view() {
return m(layout, m(amivLayout, m(aufenthaltsraum)));
},
});
},
{
url: '/:language/amiv/statuten',
view: () => m(amivLayout, m(statuten)),
},
'/:language/login': {
onmatch(args, requestedPath) {
return onmatch(args, requestedPath, {
view() {
return m(layout, m(login));
},
});
},
{
url: '/:language/amiv/board',
view: () => m(amivLayout, m(board)),
},
'/:language/logout': {
onmatch(args, requestedPath) {
return onmatch(args, requestedPath, {
view() {
return m(layout, m(logout));
},
});
},
},
'/:language/amiv/board': {
onmatch(args, requestedPath) {
return onmatch(args, requestedPath, {
view() {
return m(layout, m(amivLayout, m(board)));
},
});
},
{
url: '/:language/amiv/aufenthaltsraum',
view: () => m(amivLayout, m(aufenthaltsraum)),
},
'/:language/studydocuments': {
onmatch(args, requestedPath) {
return onmatchAuthenticated(args, requestedPath, {
view() {
return m(layout, m(studydocList));
},
});
},
{
url: '/:language/contact',
view: () => m(contact),
},
'/:language/studydocuments/new': {
onmatch(args, requestedPath) {
return onmatchAuthenticated(args, requestedPath, {
view() {
return m(layout, m(studydocNew));
},
});
},
{
url: '/:language/login',
view: () => m(login),
},
'/:language/events': {
onmatch(args, requestedPath) {
return onmatch(args, requestedPath, {
view() {
return m(layout, m(eventList));
},
});
},
{
url: '/:language/logout',
view: () => m(logout),
},
'/:language/events/:eventId': {
onmatch(args, requestedPath) {
return onmatch(args, requestedPath, {
view(vnode) {
return m(layout, m(eventDetails, vnode.attrs));
},
});
},
{
url: '/:language/events',
view: () => m(eventList),
},
'/:language/jobs': {
onmatch(args, requestedPath) {
return onmatch(args, requestedPath, {
view() {
return m(layout, m(jobOfferList));
},
});
},
{
url: '/:language/events/:eventId',
view: vnode => m(eventDetails, vnode.attrs),
},
'/:language/jobs/:jobId': {
onmatch(args, requestedPath) {
return onmatch(args, requestedPath, {
view(vnode) {
return m(layout, m(jobOfferDetails, vnode.attrs));
},
});
},
{
url: '/:language/jobs',
view: () => m(jobOfferList),
},
'/:language/profile': {
onmatch(args, requestedPath) {
return onmatchAuthenticated(args, requestedPath, {
view(vnode) {
return m(layout, m(profile, vnode.attrs));
},
});
},
{
url: '/:language/jobs/:jobId',
view: vnode => m(jobOfferDetails, vnode.attrs),
},
'/:language/companies': {
onmatch(args, requestedPath) {
return onmatch(args, requestedPath, {
view() {
return m(layout, m(companyList));
},
});
},
{
url: '/:language/companies',
view: () => m(companyList),
},
'/:language/companies/:companyId': {
onmatch(args, requestedPath) {
return onmatch(args, requestedPath, {
view(vnode) {
return m(layout, m(companyDetail, vnode.attrs));
},
});
},
{
url: '/:language/companies/:companyId',
view: vnode => m(companyDetail, vnode.attrs),
},
'/:404...': {
];
function onmatch(args, route) {
if (isLanguageValid(args.language)) {
changeLanguage(args.language);
return { view: vnode => m(layout, route.view(vnode)) };
}
return {
view() {
return m(layout, m(Error404));
},
},
});
};
}
function generateRoutes() {
const result = {
'/': {
onmatch() {
m.route.set(`/${currentLanguage()}/`);
},
},
};
routes.forEach(r => {
result[r.url] = {
onmatch: args => onmatch(args, r),
};
});
routesAuth.forEach(r => {
result[r.url] = {
onmatch(args) {
if (!isLoggedIn()) {
// m.route.set(`/${currentLanguage()}/login`);
return {
view() {
return m(layout, m(Error401));
},
};
}
return onmatch(args, r);
},
};
});
m.route(document.body, '/', result);
}
generateRoutes();
......@@ -5,7 +5,8 @@
"Studienunterlagen": "Studienunterlagen",
"Jobs": "Jobs",
"Login": "Login",
"Profil": "Profil",
"Logout": "Logout",
"Profile": "Profil",
"example content": "beispiel Inhalte",
"Vorstand": "Vorstand",
"Aufenthaltsraum": "Aufenthaltsraum",
......
......@@ -3,9 +3,10 @@
"AMIV": "AMIV",
"Events": "Events",
"Studienunterlagen": "Study Documents",
"Jobs": "Jobbies",
"Jobs": "Jobs",
"Login": "Login",
"Profil": "Profile",
"Logout": "Logout",
"Profile": "Profile",
"example content": "blablabla",
"Vorstand": "Board Members",
"Aufenthaltsraum": "Aufenthaltsraum in englisch",
......
import m from 'mithril';
import { checkLogin, isLoggedIn } from '../models/auth';
import { currentLanguage } from './language';
import { currentLanguage, i18n } from './language';
const defaultTabs = ['AMIV', 'Events', 'Studienunterlagen', 'Jobs'];
const tabsLoggedOut = ['Login'];
......@@ -52,7 +52,7 @@ export default class Navigation {
this._tabOptions.tabs = [];
this._tabs.forEach(tab => {
this._tabOptions.tabs.push({
label: tab,
label: i18n(tab),
url: tabToUrl()[tab],
});
});
......
import m from 'mithril';
import { logout } from '../models/auth';
import { currentLanguage } from '../models/language';
module.exports = {
oninit() {
logout();
m.route.set('/');
m.route.set(`/${currentLanguage()}/`);
},
view() {
return m('');
......
Supports Markdown
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