To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit bfa9c001 authored by Alexander Dietmüller's avatar Alexander Dietmüller
Browse files

Frontend: Switch to ES6 imports ands classes

parent 5a05be2b
// Nothing yet
// Placeholder
const m = require('mithril');
import m from 'mithril';
module.exports = {
view() {
export default class AdminSidebar {
static view() {
return [
m('h2', 'Administration'),
m('a', { href: '/admin', oncreate: m.route.link }, 'Course Overview'),
];
},
};
}
}
const m = require('mithril');
const { courses, userCourses } = require('./backend.js');
import m from 'mithril';
import { courses, userCourses } from './backend';
function isSelectedOrReserved(course) {
return userCourses.selected.some(sel => sel.course === course._id) ||
userCourses.signups.some(signup => signup.course === course._id);
}
module.exports = {
oninit() { courses.get().then((d) => { console.log(d); }); },
export default class CourseList {
static oninit() { courses.get(); }
view() {
static view() {
return m('table', [
m('thead', [
m('tr', [
......@@ -54,5 +54,5 @@ module.exports = {
),
]))),
]);
},
};
}
}
const m = require('mithril');
import m from 'mithril';
module.exports = {
view() {
export default class CourseOverview {
static view() {
return m('div', 'You are an admin. Nice!');
},
};
}
}
/* eslint-disable no-param-reassign */
const m = require('mithril');
import m from 'mithril';
const { lectures } = require('./backend.js');
import { lectures } from './backend';
const currentCourse = {
assistantList: ['Mathis', 'Sandro', 'Celina'],
......@@ -36,8 +36,8 @@ function bind(obj, prop, type = 'text') {
};
}
const timespanView = {
view({ attrs: { timespan } }) {
class TimespanView {
static view({ attrs: { timespan } }) {
return [
m('div', 'start: '),
m(
......@@ -60,12 +60,12 @@ const timespanView = {
'end',
),
];
},
};
}
}
const chosenLecture = {
view() {
class chosenLecture {
static view() {
return [
m(
'select',
......@@ -78,11 +78,11 @@ const chosenLecture = {
m('option', lecture.title)),
),
];
},
};
}
}
const chosenAssistant = {
view() {
class chosenAssistant {
static view() {
return [
m('select', [
assistantList().map(assistant => [
......@@ -90,11 +90,11 @@ const chosenAssistant = {
]),
]),
];
},
};
}
}
const participantNumber = {
view() {
class participantNumber {
static view() {
return [
'How many Students may choose the Course? ',
m('div'),
......@@ -103,11 +103,11 @@ const participantNumber = {
bind(currentCourse, 'spots', 'number'),
),
];
},
};
}
}
const courseRoom = {
view() {
class courseRoom {
static view() {
return [
'What room will the course take place in? ',
m('div'),
......@@ -116,8 +116,8 @@ const courseRoom = {
bind(currentCourse, 'room'),
),
];
},
};
}
}
function addDatetime() {
currentCourse.datetimes.push('');
......@@ -128,10 +128,10 @@ function removeDatetime(index) {
}
module.exports = {
oninit() { lectures.get(); },
export default class CourseCreationView {
static oninit() { lectures.get(); }
view() {
static view() {
return [
m('div', 'As Admin, you can add Courses'),
m('div', 'Choose Lecture'),
......@@ -144,10 +144,10 @@ module.exports = {
m(courseRoom),
m('div', 'What time does the course signup start and end?'),
m('div'),
m(timespanView, { timespan: currentCourse.signup }),
m(TimespanView, { timespan: currentCourse.signup }),
m('div', 'What time does the ourcse start and end?'),
currentCourse.datetimes.map((timespan, index) => [
m(timespanView, { timespan }),
m(TimespanView, { timespan }),
m(
'button',
{
......@@ -165,5 +165,5 @@ module.exports = {
'Add other course time',
),
];
},
};
}
}
/* eslint-disable no-param-reassign */
const m = require('mithril');
import m from 'mithril';
const { lectures } = require('./backend.js');
import { lectures } from './backend';
const currentLecture = {
title: 'Hallo',
......@@ -36,8 +36,8 @@ function createLecture() {
});
}
const enterField = {
view() {
class Form {
static view() {
return [
m('div', 'Title: '),
m('input', bind(currentLecture, 'title')),
......@@ -69,11 +69,11 @@ const enterField = {
'Add Assistants',
),
];
},
};
}
}
const listLecture = {
view() {
class LectureList {
static view() {
return [
m('div', 'Folgender Kurs wurde eingegeben:'),
m('div'),
......@@ -83,18 +83,18 @@ const listLecture = {
m('div'),
`year: ${currentLecture.year}`,
];
},
};
}
}
module.exports = {
oninit() { lectures.get(); },
view() {
export default class LectureCreationView {
static oninit() { lectures.get(); }
static view() {
return [
m('div', 'You are an admin. Niceooo!'),
m('div', 'enter the following fields for the new Lecture'),
m(enterField),
m(listLecture),
m(Form),
m(LectureList),
m('div'),
m(
'button',
......@@ -113,5 +113,5 @@ module.exports = {
),
])),
];
},
};
}
}
......@@ -3,8 +3,8 @@
//
// Includes the generic login / logout
const m = require('mithril');
const session = require('./session.js');
import m from 'mithril';
import session from './session';
let nethz = '';
let password = '';
......@@ -38,8 +38,8 @@ function logout() {
});
}
const LoginPage = {
view() {
class LoginPage {
static view() {
return [
m('h1', 'PVK Tool Demo'),
m('div', error),
......@@ -73,15 +73,14 @@ const LoginPage = {
'',
),
];
},
};
}
}
const SidebarHeader = {
view() {
class SidebarHeader {
static view() {
return [
m('header', m('img', { src: '/home/alex/contractor/contractor/static/logo.svg' })),
// m('h1', 'PVK Tool Demo'),
m('h1', 'PVK Tool Demo'),
m('p', `Hello, ${session.user.name}`),
m('button', { onclick: logout }, 'Logout'),
session.admin ? [
......@@ -91,15 +90,15 @@ const SidebarHeader = {
m('a', { href: '/admin', oncreate: m.route.link }, 'Admin Tools'),
] : [],
];
},
};
}
}
module.exports = {
view(vnode) {
export default class Layout {
static view(vnode) {
return session.active() ? m('', [
m('aside', [m(SidebarHeader), m(vnode.attrs.sidebar)]),
m('main', m(vnode.attrs.content)),
]) : m(LoginPage);
},
};
}
}
// User Sidebar
const m = require('mithril');
const { userCourses, courses } = require('./backend.js');
import m from 'mithril';
import { userCourses, courses } from './backend';
const courseView = {
view({ attrs: { _id, courseId, remove } }) {
class CourseView {
static view({ attrs: { _id, courseId, remove } }) {
// Get Lecture of Course
const course = courses.list.find(item => item._id === courseId);
// Otherwise display loading
......@@ -13,20 +13,20 @@ const courseView = {
// so a delete button does not make any sense
m('button', { onclick: remove, disabled: !_id }, 'X'),
]);
},
};
}
}
module.exports = {
oninit() { userCourses.get(); },
export default class UserSidebar {
static oninit() { userCourses.get(); }
view() {
static view() {
return [
m('h1', 'Selected Courses'),
userCourses.selected.length ? [
userCourses.selected.map(({ _id, course: courseId }) =>
m(
courseView,
CourseView,
{ _id, courseId, remove() { userCourses.deselect(_id); } },
)),
m('button', { onclick() { userCourses.reserve(); } }, 'reserve'),
......@@ -36,7 +36,7 @@ module.exports = {
userCourses.reserved.length ? [
userCourses.reserved.map(({ _id, course: courseId }) =>
m(
courseView,
CourseView,
{ _id, courseId, remove() { userCourses.free(_id); } },
)),
// m('button', { onclick() { userCourses.pay(); } }, 'Pay'),
......@@ -45,12 +45,12 @@ module.exports = {
m('h4', 'Waiting'),
userCourses.waiting.map(({ _id, course: courseId }) =>
m(
courseView,
CourseView,
{ _id, courseId, remove() { userCourses.free(_id); } },
)),
] : [],
m('h1', 'Accepted Courses'),
m('p', 'No courses accepted.'), // TODO: Implement
];
},
};
}
}
// Api calls
const m = require('mithril');
const session = require('./session.js');
import m from 'mithril';
import session from './session';
const pvkApiUrl = `//${window.location.hostname}/api`;
// Helper to filter temp out of list
function withoutTemp(list, temp) { return list.filter(item => item !== temp); }
......@@ -175,8 +173,7 @@ class Resource {
}
}
const userCourses = {
export const userCourses = {
resources: {
selections: new Resource(
'selections',
......@@ -257,11 +254,5 @@ const userCourses = {
pay() {},
};
const courses = new Resource('courses', { embedded: { lecture: 1 } });
const lectures = new Resource('lectures');
module.exports = {
userCourses,
courses,
lectures,
};
export const courses = new Resource('courses', { embedded: { lecture: 1 } });
export const lectures = new Resource('lectures');
const m = require('mithril');
const session = require('./session.js');
import m from 'mithril';
const Layout = require('./Layout.js');
const UserSidebar = require('./UserSidebar.js');
const AdminSidebar = require('./AdminSidebar.js');
const CourseList = require('./CourseList.js');
const CourseOverview = require('./CourseOverview.js');
const CreateLecture = require('./CreateLecture.js');
const CreateCourse = require('./CreateCourse.js');
import session from './session';
import Layout from './Layout';
import UserSidebar from './UserSidebar';
import AdminSidebar from './AdminSidebar';
import CourseList from './CourseList';
import CourseOverview from './CourseOverview';
import CreateLecture from './CreateLecture';
import CreateCourse from './CreateCourse';
m.route(document.body, '/courses', {
'/courses': {
......
// Session with AMIVAPI
const m = require('mithril');
const ls = require('local-storage');
import m from 'mithril';
import ls from 'local-storage';
const adminGroupName = 'PVK Admins';
const amivApiUrl = 'https://amiv-api.ethz.ch';
const storedSession = ls('session');
module.exports = {
export default {
// Quick check if session exists
active() { return this.data.token; },
......
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