Commit 00ae4b6e authored by lic's avatar lic
Browse files

Merge remote-tracking branch 'origin/master' into profile

parents b4468c47 2b199ced
import m from 'mithril';
import { Checkbox } from 'polythene-mithril';
// import { CheckboxCSS } from 'polythene-css';
// CheckboxCSS.addStyle('.my-checkbox', {});
export default class CheckboxComponent {
constructor() {
this.defaultProps = {
// className: 'my-checkbox',
// label: 'Unnamed checkbox',
};
}
view(vnode) {
return m(Checkbox, { ...this.defaultProps, ...vnode.attrs });
}
}
import m from 'mithril';
import { RadioGroup } from 'polythene-mithril';
// import { RadioGroupCSS } from 'polythene-css';
// RadioGroupCSS.addStyle('', {})
export default class RadioGroupComponent {
constructor() {
this.defaultProps = {
// className: 'blue-RadioGroup',
};
}
view(vnode) {
return m(RadioGroup, { ...this.defaultProps, ...vnode.attrs });
}
}
import m from 'mithril';
import { TextField } from 'polythene-mithril';
import { TextFieldCSS } from 'polythene-css';
TextFieldCSS.addStyle('.my-TextField', {});
export default class TextFieldComponent {
constructor() {
this.defaultProps = {
className: 'my-TextField',
label: 'Unnamed TextField',
};
}
onbeforeupdate(vnode) {
this.defaultProps.disabled = vnode.attrs.active === false;
}
view(vnode) {
return m(TextField, { ...this.defaultProps, ...vnode.attrs });
}
}
export { default as Button } from './Button';
export { default as Checkbox } from './Checkbox';
export { default as RadioGroup } from './RadioGroup';
export { default as Tabs } from './Tabs';
export { default as TextField } from './TextField';
// src/index.js
import m from 'mithril';
import { getLang } from './models/language';
import studydocList from './views/studydocs/studydocList';
import studydocNew from './views/studydocs/studydocNew';
import eventList from './views/events/eventList';
......@@ -19,6 +20,8 @@ import companyList from './views/companies/companyList';
import companyDetail from './views/companies/companyDetail';
import './views/styles/base.less';
getLang();
m.route(document.body, '/', {
'/': {
render() {
......
{
"values": {
"AMIV": "AMIV",
"Events": "Events",
"Studienunterlagen": "Studienunterlagen",
"Jobs": "Jobs",
"Login": "Login",
"Profil": "Profil",
"example content": "beispiel Inhalte",
"Vorstand": "Vorstand",
"Aufenthaltsraum": "Aufenthaltsraum",
"Statuten": "Statuten",
"Kommissionen": "Kommissionen",
"Protokolle": "Protokolle",
"language_button": "EN",
"event.title": "TItel",
"event.start_time": "Start Zeit",
"event.signup_count": "Anmeldungen",
"event.spots": "Freie Plätze"
}
}
{
"values": {
"AMIV": "AMIV",
"Events": "Events",
"Studienunterlagen": "Study Documents",
"Jobs": "Jobbies",
"Login": "Login",
"Profil": "Profile",
"example content": "blablabla",
"Vorstand": "Board Members",
"Aufenthaltsraum": "Aufenthaltsraum in englisch",
"Statuten": "Statuten in english",
"Kommissionen": "Commissions",
"Protokolle": "Protocols",
"language_button": "DE",
"event.title": "Title",
"event.start_time": "Starting time",
"event.signup_count": "Signup count",
"event.spots": "Spots"
}
}
import i18n from 'i18n4v';
import german from '../languages/de.json';
import english from '../languages/en.json';
let currentLang;
function changeLanguage(lang) {
i18n.translator.reset();
if (lang === 'de') {
currentLang = 'de';
i18n.translator.add(german);
} else {
currentLang = 'en';
i18n.translator.add(english);
}
localStorage.setItem('lanuage', currentLang);
}
function getLang() {
let lang = localStorage.getItem('lanuage');
if (!lang) {
if (navigator.languages !== undefined) {
lang = navigator.languages.toString();
} else {
lang = navigator.language;
}
}
if (lang.indexOf('de') !== -1) {
changeLanguage('de');
} else {
changeLanguage('en');
}
}
function switchLanguage() {
if (currentLang === 'en') {
changeLanguage('de');
} else {
changeLanguage('en');
}
}
function currentLanguage() {
return currentLang;
}
export { i18n, changeLanguage, switchLanguage, currentLanguage, getLang };
import m from 'mithril';
import { i18n } from '../../models/language';
module.exports = {
view(vnode) {
return m('div', [
m('ul', [
m('li', m('a', { href: '/amiv/board', oncreate: m.route.link }, 'Vorstand')),
m(
'li',
m('a', { href: '/amiv/aufenthaltsraum', oncreate: m.route.link }, 'Aufenthaltsraum')
m(
'a',
{
href: '/amiv/board',
oncreate: m.route.link,
},
i18n('Vorstand')
)
),
m(
'li',
m(
'a',
{
href: '/amiv/aufenthaltsraum',
oncreate: m.route.link,
},
i18n('Aufenthaltsraum')
)
),
m(
'li',
m(
'a',
{
href: '/amiv/statuten',
oncreate: m.route.link,
},
i18n('Statuten')
)
),
m(
'li',
m(
'a',
{
href: '/amiv/comissions',
oncreate: m.route.link,
},
i18n('Kommissionen')
)
),
m(
'li',
m(
'a',
{
href: '/amiv/protocols',
oncreate: m.route.link,
},
i18n('Protokolle')
)
),
m('li', m('a', { href: '/amiv/statuten', oncreate: m.route.link }, 'Statuten')),
m('li', m('a', { href: '/amiv/comissions', oncreate: m.route.link }, 'Kommissionen')),
m('li', m('a', { href: '/amiv/protocols', oncreate: m.route.link }, 'Protokolle')),
]),
m('main', vnode.children),
]);
......
import m from 'mithril';
import { i18n } from '../../models/language';
import * as events from '../../models/events';
const date = `${new Date().toISOString().split('.')[0]}Z`;
......@@ -26,10 +27,10 @@ export default class EventList {
return m('table', [
m('thead', [
m('tr', [
m('th', 'Title'),
m('th', 'Starting time'),
m('th', 'Signup count'),
m('th', 'Spots'),
m('th', i18n('event.title')),
m('th', i18n('event.start_time')),
m('th', i18n('event.signup_count')),
m('th', i18n('event.spots')),
]),
]),
m(
......
import m from 'mithril';
import { apiUrl } from '../models/config';
import * as events from '../models/events';
const date = `${new Date().toISOString().split('.')[0]}Z`;
// Render the frontpage cards, with href and imageurl
const renderCards = item => {
const { title, href } = item;
return m('div.frontpage-card', m('a', { href }, title));
const imageurl = item.img_infoscreen ? `${apiUrl}${item.img_infoscreen.file}` : '';
return m(
'div.frontpage-card',
{ style: `background-image: url(${imageurl})` },
m('a', { href }, title)
);
};
// Render the Hot Cards, with link and imageurl
const renderHotCards = (item, index) => {
const { title } = item;
if (index === 0) return m('div.hot-first-card', title);
return m('div.hot-card', title);
const { title, href } = item;
const imageurl = item.img_infoscreen ? `${apiUrl}${item.img_infoscreen.file}` : '';
if (index === 0) {
return m(
'div.hot-first-card',
{
style: `background-image: url(${imageurl})`,
},
m('a', { href }, title)
);
}
return m(
'div.hot-card',
{ style: `background-image: url(${imageurl})` },
m('a', { href }, title)
);
};
export default class Frontpage {
......@@ -28,12 +49,33 @@ export default class Frontpage {
this.events = events.getList().slice(0, 3);
// MOCKDATA
this.hot = [{ title: 'super hot' }, { title: 'also pretty hot' }, { title: 'kinda hot' }];
this.jobs = [{ title: 'google' }, { title: 'abb' }, { title: 'accenture' }];
this.hot = [
{
title: 'super hot',
imageurl: 'http://www.heilpraxisnet.de/wp-content/uploads/2016/04/bier-lagern-1024x724.jpg',
},
{ title: 'also pretty hot' },
{ title: 'kinda hot' },
];
this.jobs = [{ title: 'Google' }, { title: 'ABB' }, { title: 'Accenture' }];
this.socialmedia = [
{ title: 'Facebook', href: 'https://www.facebook.com/AMIV.ETHZ/' },
{ title: 'Instagram', href: 'https://www.instagram.com/amiv_eth/?hl=de' },
{ title: 'Twitter', href: 'https://twitter.com/amiv_ethz?lang=de' },
{
title: 'Facebook',
href: 'https://www.facebook.com/AMIV.ETHZ/',
imageurl: 'https://upload.wikimedia.org/wikipedia/commons/c/c2/F_icon.svg',
},
{
title: 'Instagram',
href: 'https://www.instagram.com/amiv_eth/?hl=de',
imageurl:
'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Instagram_logo_2016.svg/2000px-Instagram_logo_2016.svg.png',
},
{
title: 'Twitter',
href: 'https://twitter.com/amiv_ethz?lang=de',
imageurl:
'https://upload.wikimedia.org/wikipedia/de/thumb/9/9f/Twitter_bird_logo_2012.svg/1200px-Twitter_bird_logo_2012.svg.png',
},
];
}
......@@ -43,9 +85,13 @@ export default class Frontpage {
view() {
return m('div#frontpage-container', [
m('h2', "What's HOT right now?"),
m('div.hot-row', this.hot.map((item, index) => renderHotCards(item, index))),
m('h2', 'Events'),
m('div.frontpage-row', this.events.map(item => renderCards(item))),
m('h2', 'Jobs'),
m('div.frontpage-row', this.jobs.map(item => renderCards(item))),
m('h2', 'Join us on social media!'),
m('div.frontpage-row', this.socialmedia.map(item => renderCards(item))),
]);
}
......
import m from 'mithril';
import { i18n, switchLanguage } from '../models/language';
import { Tabs, Button } from '../components';
import { checkLogin, isLoggedIn, logout } from '../models/auth';
import { Tabs } from '../components';
const defaultTabs = ['AMIV', 'Events', 'Studienunterlagen', 'Jobs'];
const tabsLoggedOut = ['Login'];
......@@ -72,6 +73,10 @@ export default class Layout {
tabs: this.tabs.map(tab => ({ label: tab })),
selectedTab: this.selectedTabIndex,
}),
m(Button, {
label: i18n('language_button'),
events: { onclick: () => switchLanguage() },
}),
m('main', vnode.children),
]);
}
......
......@@ -3,81 +3,146 @@ import * as studydocs from '../../models/studydocs';
import { apiUrl } from '../../models/config';
import { isLoggedIn } from '../../models/auth';
import { Error401 } from '../errors';
import { Button } from '../../components';
import { Button, Checkbox, TextField } from '../../components';
const tableHeadings = ['title', 'lecture', 'professor', 'semester', 'author', 'download'];
const tableHeadings = ['title', 'type'];
export default class studydocList {
constructor(vnode) {
this.vnode = vnode;
this.doc = {};
}
static oninit() {
studydocs.load();
this.search = '';
this.filter = {
department: {},
type: {},
semester: {},
};
}
static selectDocument(doc) {
this.doc = doc;
}
static changeFilter(filterKey, filterValue, checked) {
this.filter[filterKey][filterValue] = checked;
const query = {};
Object.keys(this.filter).forEach(key => {
let queryValue = '';
Object.keys(this.filter[key]).forEach(subKey => {
if (this.filter[key][subKey]) {
queryValue += `${subKey}|`;
}
});
if (queryValue.length > 0) {
queryValue = queryValue.substring(0, queryValue.length - 1);
query[key] = { $regex: `^(?i).*${queryValue}.*` };
}
});
studydocs.load(query);
}
static view() {
if (!isLoggedIn()) return m(Error401);
return m('div#studydoc-list', [
m(
'form',
{
onsubmit: e => {
e.preventDefault();
const query = {
$or: [
{ title: { $regex: `^(?i).*${this.search}.*` } },
{ lecture: { $regex: `^(?i).*${this.search}.*` } },
{ professor: { $regex: `^(?i).*${this.search}.*` } },
{ author: { $regex: `^(?i).*${this.search}.*` } },
],
};
studydocs.load(query);
},
},
[
m(
'input',
{
type: 'text',
oninput: m.withAttr('value', value => {
this.search = value;
}),
},
''
),
m(Button, { label: 'Search' }),
]
),
m(Button, {
label: 'Add new',
events: { onclick: () => m.route.set('/studydocuments/new') },
}),
m('table', [
m('thead', m('tr', tableHeadings.map(header => m('th', header)))),
m('div.filter', [
m(
'tbody',
'form',
{
onsubmit: e => {
e.preventDefault();
const query = {
$or: [
{ title: { $regex: `^(?i).*${this.search}.*` } },
{ lecture: { $regex: `^(?i).*${this.search}.*` } },
{ professor: { $regex: `^(?i).*${this.search}.*` } },
{ author: { $regex: `^(?i).*${this.search}.*` } },
],
};
studydocs.load(query);
},
},
[
m(
TextField,
{
label: 'Enter search...',
onChange: state => {
this.search = state.value;
},
},
''
),
m(Button, { label: 'Search' }),
]
),
m('div.department-check', [
m(Checkbox, {
label: 'D-ITET',
onChange: state => this.changeFilter('department', 'itet', state.checked),
}),
m(Checkbox, {
label: 'D-MAVT',
onChange: state => this.changeFilter('department', 'mavt', state.checked),
}),
]),
m('div.type-check', [
m(Checkbox, {
label: 'Zusammenfassung',
onChange: state => this.changeFilter('type', 'cheat sheets', state.checked),
}),
m(Checkbox, {
label: 'Alte Prüfungen',
onChange: state => this.changeFilter('type', 'exams', state.checked),
}),
m(Checkbox, {
label: 'Unterichts Unterlagen',
onChange: state => this.changeFilter('type', 'lecture documents', state.checked),
}),
m(Checkbox, {
label: 'Übungsserien',
onChange: state => this.changeFilter('type', 'exercises', state.checked),
}),
]),
m(Button, {
label: 'Add new',
events: { onclick: () => m.route.set('/studydocuments/new') },
}),
]),
m('div.content', [
m('div.content-grid', [
tableHeadings.map(header => m('div.list-header', header)),
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',
doc.files.map(item =>
m('a', { href: `${apiUrl}${item.file}`, target: '_blank' }, item.name)
)
),
])
)
),
.map(doc => [
m('div.list-item', { onclick: () => this.selectDocument(doc) }, doc.title),
m('div.list-item', { onclick: () => this.selectDocument(doc) }, doc.type),
]),
]),
]),
this.doc
? m('div.details', [
m('table', [
m('tr', this.doc.title),
m('tr', this.doc.lecture),
m('tr', this.doc.professor),
m('tr', this.doc.semester),
m('tr', this.doc.author),
m(Button, {
label: 'Download',
events: {
onclick: () => window.open(`${apiUrl}${this.doc.files[0].file}`, '_blank'),
},
}),
]),
])
: null,
]);
}