Skip to content
Snippets Groups Projects
Commit 31001439 authored by scmoritz's avatar scmoritz
Browse files

inital studydocs

parent 145ed166
No related branches found
No related tags found
1 merge request!20inital studydocs
// src/index.js
import studydocList from './views/studydocList';
const m = require('mithril');
const Layout = require('./views/layout');
......@@ -42,4 +44,9 @@ m.route(document.body, '/', {
return m(Layout, m(amivLayout, m(board)));
},
},
'/studydocuments': {
render() {
return m(Layout, m(studydocList));
},
},
});
import { apiUrl } from './config';
import { log } from './log';
import { getToken } from './auth';
const m = require('mithril');
let querySaved = {};
export function getList() {
if (typeof this.list === 'undefined') {
return [];
}
return this.list;
}
export function load(query = {}) {
querySaved = query;
log('hallo');
const queryEncoded = m.buildQueryString(JSON.stringify(query));
return m.request({
method: 'GET',
url: `${apiUrl}/studydocuments?${queryEncoded}`,
headers: {
Authorization: `Token ${getToken()}`,
},
}).then((result) => {
this.list = result._items;
});
}
export function reload() {
return load(querySaved);
}
import * as studydocs from '../models/studydocs';
import { apiUrl } from '../models/config';
const m = require('mithril');
const tableHeadings = [
'title', 'lecture', 'professor', 'semester', 'author', 'download',
];
export default class studydocList {
constructor(vnode) {
this.vnode = vnode;
}
static oninit() {
studydocs.load();
}
static view() {
return m('div', [
m('table', [
m('thead', m('tr', tableHeadings.map(header => m('th', header)))),
m('tbody', studydocs.getList().map(doc => m('tr', [
m('td', doc.title),
m('td', doc.lecture),
m('td', doc.professor),
m('td', doc.semester),
m('td', doc.author),
m('td', m('a', { href: apiUrl + doc.files[0].file }, 'download')),
]))),
]),
]);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment