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 ee90eeec authored by rcelina's avatar rcelina Committed by Alexander Dietmüller
Browse files

Frontend: add first version of lecture and course creation

parent a23da0fe
/* eslint-disable no-param-reassign */
const m = require('mithril');
const currentCourse = {
courseList: ['Hermann', 'Alex', 'Eppi'],
assistantList: ['Mathis', 'Sandro', 'Celina'],
spots: '42',
assistant: 'Mo',
room: 'CAB E37',
signup: {
start: '',
end: '',
},
datetimes: [{
start: '2017-12-02T22:26',
end: '',
}],
};
function bind(obj, prop, type = 'text') {
return {
value: obj[prop],
onchange(e) {
obj[prop] = e.target.value;
},
type,
};
}
const timespanView = {
view({ attrs: { timespan } }) {
return [
m('div', 'start: '),
m(
'input',
bind(
timespan,
'start',
'datetime-local',
),
'start',
),
m('div', 'end: '),
m(
'input',
bind(
timespan,
'end',
'datetime-local',
),
'end',
),
];
},
};
const chosenLecture = {
view() {
return [
m('select', [
currentCourse.courseList.map((_, index) => [
m('option', currentCourse.courseList[index]),
]),
]),
];
},
};
const chosenAssistant = {
view() {
return [
m('select', [
currentCourse.assistantList.map((_, index) => [
m('option', currentCourse.assistantList[index]),
]),
]),
];
},
};
const participantNumber = {
view() {
return [
'How many Students may choose the Course? ',
m('div'),
m(
'input',
bind(currentCourse, 'spots', 'number'),
),
];
},
};
const courseRoom = {
view() {
return [
'What room will the course take place in? ',
m('div'),
m(
'input',
bind(currentCourse, 'room'),
),
];
},
};
module.exports = {
view() {
return [
m('div', 'As Admin, you can add Courses'),
m('div', 'Choose Course'),
m(chosenLecture),
m('div', 'Choose Assistant'),
m(chosenAssistant),
m('div'),
m(participantNumber),
m('div'),
m(courseRoom),
m('div', 'What time does the course signup start and end?'),
m('div'),
m(timespanView, { timespan: currentCourse.signup }),
m('div', 'What time does the course start and end?'),
currentCourse.datetimes.map(timespan =>
m(timespanView, { timespan })),
];
},
};
/* eslint-disable no-param-reassign */
const m = require('mithril');
const { lectures } = require('./backend.js');
const currentLecture = {
title: 'Hallo',
department: 'Alex',
year: '42',
assistant: ['rcelina', 'rstadler', 'troll'],
};
function addAssistant() {
currentLecture.assistant.push('');
}
function removeAssistant(index) {
currentLecture.assistant.splice(index, 1);
}
function bind(obj, prop) {
return {
value: obj[prop],
onchange(e) {
obj[prop] = e.target.value;
},
};
}
function createLecture() {
lectures.post(currentLecture).then((response) => {
console.log(response);
}).catch((error) => {
console.log(error);
});
}
const enterField = {
view() {
return [
m('div', 'Title: '),
m('input', bind(currentLecture, 'title')),
m('div', 'Department: '),
m('input', bind(currentLecture, 'department')),
m('div', 'Year: '),
m('input', bind(currentLecture, 'year')),
m('div', 'Assistant: '),
currentLecture.assistant.map((_, index) => [
m('div', [
m(
'input',
bind(currentLecture.assistant, index),
),
m(
'button',
{
onclick() {
removeAssistant(index);
},
},
'Remove Assistant',
),
]),
]),
m(
'button',
{ onclick: addAssistant },
'Add Assistant',
),
];
},
};
const listLecture = {
view() {
return [
m('div', 'Folgender Kurs wurde eingegeben:'),
m('div'),
`Coursetitle: ${currentLecture.title}`,
m('div'),
`Department: ${currentLecture.department}`,
m('div'),
`year: ${currentLecture.year}`,
];
},
};
module.exports = {
oninit() { lectures.get(); },
view() {
return [
m('div', 'You are an admin. Niceooo!'),
m('div', 'enter the following fields for the new Lecture'),
m(enterField),
m(listLecture),
m('div'),
m(
'button',
{ onclick: createLecture },
'Create Lecture',
),
m('div', lectures.list.map(({ title }) =>
m('div', title))),
];
},
};
......@@ -6,7 +6,8 @@ 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');
m.route(document.body, '/courses', {
'/courses': {
......@@ -27,4 +28,24 @@ m.route(document.body, '/courses', {
});
},
},
'/new-lecture': {
render() {
// If not admin, redirect to Courses
if (!session.admin) { m.route.set('/course'); }
return m(Layout, {
sidebar: AdminSidebar,
content: CreateLecture,
});
},
},
'/new-course': {
render() {
// If not admin, redirect to Courses
if (!session.admin) { m.route.set('/course'); }
return m(Layout, {
sidebar: AdminSidebar,
content: CreateCourse,
});
},
},
});
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