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

Frontend: progress on creating lectures and courses

parent ee90eeec
......@@ -2,8 +2,9 @@
const m = require('mithril');
const { lectures } = require('./backend.js');
const currentCourse = {
courseList: ['Hermann', 'Alex', 'Eppi'],
assistantList: ['Mathis', 'Sandro', 'Celina'],
spots: '42',
assistant: 'Mo',
......@@ -19,6 +20,12 @@ const currentCourse = {
};
function assistantList() {
if (!currentCourse.lecture) { return []; }
return lectures.list.find(({ _id }) =>
_id === currentCourse.lecture).assistants;
}
function bind(obj, prop, type = 'text') {
return {
value: obj[prop],
......@@ -60,11 +67,16 @@ const timespanView = {
const chosenLecture = {
view() {
return [
m('select', [
currentCourse.courseList.map((_, index) => [
m('option', currentCourse.courseList[index]),
]),
]),
m(
'select',
{
onchange: m.withAttr('selectedIndex', (index) => {
currentCourse.lecture = lectures.list[index]._id;
}),
},
lectures.list.map(lecture =>
m('option', lecture.title)),
),
];
},
};
......@@ -73,8 +85,8 @@ const chosenAssistant = {
view() {
return [
m('select', [
currentCourse.assistantList.map((_, index) => [
m('option', currentCourse.assistantList[index]),
assistantList().map(assistant => [
m('option', assistant),
]),
]),
];
......@@ -107,12 +119,22 @@ const courseRoom = {
},
};
function addDatetime() {
currentCourse.datetimes.push('');
}
function removeDatetime(index) {
currentCourse.datetimes.splice(index, 1);
}
module.exports = {
oninit() { lectures.get(); },
view() {
return [
m('div', 'As Admin, you can add Courses'),
m('div', 'Choose Course'),
m('div', 'Choose Lecture'),
m(chosenLecture),
m('div', 'Choose Assistant'),
m(chosenAssistant),
......@@ -123,9 +145,25 @@ module.exports = {
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 })),
m('div', 'What time does the ourcse start and end?'),
currentCourse.datetimes.map((timespan, index) => [
m(timespanView, { timespan }),
m(
'button',
{
onclick() {
removeDatetime(index);
},
},
'Remove course time',
),
m('div'),
]),
m(
'button',
{ onclick: addDatetime },
'Add other course time',
),
];
},
};
......@@ -6,17 +6,17 @@ const { lectures } = require('./backend.js');
const currentLecture = {
title: 'Hallo',
department: 'Alex',
year: '42',
assistant: ['rcelina', 'rstadler', 'troll'],
department: 'itet',
year: '2',
assistants: ['rcelina', 'rstadler', 'troll'],
};
function addAssistant() {
currentLecture.assistant.push('');
function addAssistants() {
currentLecture.assistants.push('');
}
function removeAssistant(index) {
currentLecture.assistant.splice(index, 1);
function removeAssistants(index) {
currentLecture.assistants.splice(index, 1);
}
function bind(obj, prop) {
......@@ -45,28 +45,28 @@ const enterField = {
m('input', bind(currentLecture, 'department')),
m('div', 'Year: '),
m('input', bind(currentLecture, 'year')),
m('div', 'Assistant: '),
currentLecture.assistant.map((_, index) => [
m('div', 'Assistants: '),
currentLecture.assistants.map((_, index) => [
m('div', [
m(
'input',
bind(currentLecture.assistant, index),
bind(currentLecture.assistants, index),
),
m(
'button',
{
onclick() {
removeAssistant(index);
removeAssistants(index);
},
},
'Remove Assistant',
'Remove Assistants',
),
]),
]),
m(
'button',
{ onclick: addAssistant },
'Add Assistant',
{ onclick: addAssistants },
'Add Assistants',
),
];
},
......@@ -101,8 +101,17 @@ module.exports = {
{ onclick: createLecture },
'Create Lecture',
),
m('div', lectures.list.map(({ title }) =>
m('div', title))),
m('div', lectures.list.map(({ title, _id }) => [
m(
'div',
title,
m(
'button',
{ onclick() { lectures.deleteItem(_id); } },
'Delete',
),
),
])),
];
},
};
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