2018-06-30 16:20:54 +02:00
|
|
|
import * as V from 'superfine';
|
|
|
|
import * as domlib from '../domlib';
|
|
|
|
import * as socket from '../socket';
|
|
|
|
import * as store from '../store';
|
|
|
|
import View from '../view';
|
|
|
|
import {singelton as notify} from './notify';
|
|
|
|
import {render} from '../gui';
|
|
|
|
|
|
|
|
export const WINDOW_HEIGHT_MENU = 50;
|
|
|
|
|
|
|
|
export class MenuView extends View {
|
|
|
|
constructor () {
|
|
|
|
super();
|
|
|
|
this.el = document.createElement('header');
|
|
|
|
const menuContainer = domlib.newAt(this.el, 'nav');
|
|
|
|
this.menuList = domlib.newAt(menuContainer, 'ul');
|
|
|
|
|
|
|
|
const aList = domlib.newAt(this.menuList, 'li', {'class':'item-1'});
|
|
|
|
domlib.newAt(aList, 'a', {'href':'#/list'}, 'List');
|
|
|
|
|
|
|
|
const aMap = domlib.newAt(this.menuList, 'li', {'class':'item-2'});
|
|
|
|
domlib.newAt(aMap, 'a', {'href':'#/map'}, 'Map');
|
|
|
|
|
|
|
|
const aStatistics= domlib.newAt(this.menuList, 'li', {'class':'item-3'});
|
2018-07-16 22:23:44 +02:00
|
|
|
domlib.newAt(aStatistics, 'a', {'href':'#/statistics'}, 'Stats');
|
2018-06-30 16:20:54 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
loginTyping(e) {
|
|
|
|
this._loginInput = e.target.value;
|
|
|
|
}
|
|
|
|
login() {
|
|
|
|
socket.sendjson({'subject': 'login', 'body': this._loginInput}, (msg) => {
|
|
|
|
if (msg.body) {
|
2018-08-24 23:34:02 +02:00
|
|
|
store.settings = msg.body;
|
2018-06-30 16:20:54 +02:00
|
|
|
store.isLogin = true;
|
|
|
|
render();
|
|
|
|
}else {
|
|
|
|
notify.send({
|
|
|
|
'header': 'Anmeldung ist fehlgeschlagen',
|
|
|
|
'type': 'error'
|
|
|
|
}, 'Login');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this._loginInput = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
logout() {
|
|
|
|
socket.sendjson({'subject': 'logout'}, (msg) => {
|
|
|
|
if (msg.body) {
|
|
|
|
store.isLogin = false;
|
|
|
|
render();
|
|
|
|
} else {
|
|
|
|
notify.send({
|
|
|
|
'header': 'Abmeldung ist fehlgeschlagen',
|
|
|
|
'type': 'error'
|
|
|
|
}, 'Logout');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const socketStatus = socket.getStatus();
|
|
|
|
let statusClass = 'status ',
|
2018-08-24 23:34:02 +02:00
|
|
|
vLogin = [V.h('li', {
|
2018-06-30 16:20:54 +02:00
|
|
|
'class': 'login',
|
|
|
|
}, [
|
|
|
|
V.h('input', {
|
|
|
|
'type': 'password',
|
|
|
|
'value': this._loginInput,
|
|
|
|
'oninput': this.loginTyping.bind(this),
|
|
|
|
}),
|
|
|
|
V.h('a', {
|
|
|
|
'onclick': this.login.bind(this)
|
2018-08-24 23:34:02 +02:00
|
|
|
}, 'Login')
|
|
|
|
])];
|
2018-06-30 16:20:54 +02:00
|
|
|
|
|
|
|
if (store.isLogin) {
|
2018-08-24 23:34:02 +02:00
|
|
|
vLogin = [
|
|
|
|
V.h('li', {
|
|
|
|
'class': 'login',
|
|
|
|
},[
|
|
|
|
V.h('a', {
|
|
|
|
'onclick': this.logout.bind(this)
|
|
|
|
}, 'Logout')
|
|
|
|
]),
|
|
|
|
V.h('li', {
|
|
|
|
'class':'right item-3'
|
|
|
|
},[V.h('a', {
|
|
|
|
'href': '#/settings'
|
|
|
|
}, 'Settings')])
|
|
|
|
];
|
2018-06-30 16:20:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (socketStatus !== 1) {
|
|
|
|
// eslint-disable-next-line no-magic-numbers
|
|
|
|
if (socketStatus === 0 || socketStatus === 2) {
|
|
|
|
statusClass += 'connecting';
|
|
|
|
} else {
|
|
|
|
statusClass += 'offline';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
V.render(this.vMenu, this.vMenu = V.h('span',{},[V.h('li', {
|
|
|
|
'class': statusClass,
|
|
|
|
'onclick': () => location.reload(true)
|
2018-08-24 23:34:02 +02:00
|
|
|
})].concat(vLogin)), this.menuList);
|
2018-06-30 16:20:54 +02:00
|
|
|
}
|
|
|
|
}
|