freifunkmanager/webroot/js/view/list.js

243 lines
7.0 KiB
JavaScript
Raw Normal View History

import * as domlib from '../domlib';
import * as gui from '../gui';
import * as lib from '../lib';
import * as socket from '../socket';
import * as store from '../store';
2018-08-10 11:52:46 +02:00
import * as V from 'superfine';
import Table from '../table';
import config from '../config';
import View from '../view';
import {FromNowAgo} from '../lib';
export class ListView extends View {
constructor () {
super();
2018-08-10 11:52:46 +02:00
this.debouncer = new lib.Debouncer(1000, "list render");
2018-08-10 11:52:46 +02:00
this.filter = domlib.newAt(this.el, 'input', {
'placeholder': 'Search',
'style': 'width: 100%;border: 0px; border-bottom: 2px inset;',
});
2018-08-10 11:52:46 +02:00
this.filter.addEventListener('keyup', () => {
this.render();
});
2018-08-10 11:52:46 +02:00
this.table = new Table(domlib.newAt(this.el, 'div'),{
class: 'nodes',
},[
{
name:'Lastseen',
sort: (a, b) => new Date(a.lastseen) - new Date(b.lastseen),
reverse: false
},
{
name:'NodeID',
sort: (a, b) => a.node_id.localeCompare(b.node_id),
reverse: false
},
{
name:'Hostname',
sort: (a, b) => a.hostname.localeCompare(b.hostname),
reverse: false
},
{ name:'Freq' },
{
name:'CurCh',
2018-08-10 13:46:18 +02:00
sort: (a, b) => (a.wireless_respondd ? a.wireless_respondd.channel24 : 0) - (b.wireless_respondd ? b.wireless_respondd.channel24 : 0),
2018-08-10 11:52:46 +02:00
reverse: false
},
{
name:'Channel',
sort: (a, b) => a.wireless.channel24 - b.wireless.channel24,
reverse: false
},
{
name:'CurPW',
2018-08-10 13:46:18 +02:00
sort: (a, b) => (a.wireless_respondd ? a.wireless_respondd.txpower24 : 0) - (b.wireless_respondd ? b.wireless_respondd.txpower24 : 0),
2018-08-10 11:52:46 +02:00
reverse: false
},
{
name:'Power',
sort: (a, b) => a.wireless.txpower24 - b.wireless.txpower24,
reverse: false
},
{
name:'Clients',
2018-08-10 13:46:18 +02:00
sort: (a, b) => a.statistics_respondd.clients.wifi24 - b.statistics_respondd.clients.wifi24,
2018-08-10 11:52:46 +02:00
reverse: false
},
{
name:'ChanUtil',
2018-08-10 13:46:18 +02:00
sort: (a, b) => (a.statistics_respondd.wireless ? a.statistics_respondd.wireless.filter((d) => d.frequency < 5000)[0].ChanUtil || 0 : 0) - (b.statistics_respondd.wireless ? b.statistics_respondd.wireless.filter((d) => d.frequency < 5000)[0].ChanUtil || 0 : 0),
2018-08-10 11:52:46 +02:00
reverse: false
},
{ name:'Options' }
], 1, this.renderRow.bind(this));
2017-05-16 19:18:35 +02:00
}
renderRow (node) {
2017-05-16 19:18:35 +02:00
const startdate = new Date(),
2018-08-10 11:52:46 +02:00
channel24Options = [],
channel5Options = [];
2017-07-06 14:25:24 +02:00
startdate.setMinutes(startdate.getMinutes() - config.node.offline);
2017-05-16 19:18:35 +02:00
2018-07-28 12:27:26 +02:00
let i = 0;
for (i = 0; i < store.channelsWifi24.length; i++) {
2018-08-10 11:52:46 +02:00
channel24Options.push(V.h('option', {
2018-07-28 12:27:26 +02:00
'value': store.channelsWifi24[i],
2018-08-10 11:52:46 +02:00
'selected': (store.channelsWifi24[i] === node.wireless.channel24),
}, store.channelsWifi24[i]));
2018-07-28 12:27:26 +02:00
}
for (i = 0; i < store.channelsWifi5.length; i++) {
2018-08-10 11:52:46 +02:00
channel5Options.push(V.h('option', {
2018-07-28 12:27:26 +02:00
'value': store.channelsWifi5[i],
2018-08-10 11:52:46 +02:00
'selected': (store.channelsWifi5[i] === node.wireless.channel5),
}, store.channelsWifi5[i]));
}
return V.h('tr', {},[
V.h('td', {
2018-08-10 13:46:18 +02:00
'class':(new Date(node.lastseen) < startdate)?'offline':(!node.wireless_respondd)?'unseen':''
2018-08-10 11:52:46 +02:00
}, FromNowAgo(node.lastseen)),
V.h('td', {}, node.node_id),
V.h('td', {}, V.h('input',{
'value': this._hostname || node.hostname,
'oninput':(e) => {
this._hostname = e.target.value;
},
'onfocusout':(e) => {
delete this._hostname;
const old = node.hostname;
node.hostname = e.target.value;
socket.sendnode(node, (msg)=>{
if (!msg.body) {
node.hostname = old;
e.target.value = old;
}
});
}
})),
V.h('td', {}, [
V.h('span', {},'2.4 GHz'),
V.h('span', {},'5 GHz')
]),
V.h('td', {}, [
2018-08-10 13:46:18 +02:00
V.h('span', {}, node.wireless_respondd ? node.wireless_respondd.channel24 || '-':'-'),
V.h('span', {}, node.wireless_respondd ? node.wireless_respondd.channel5 || '-':'-')
2018-08-10 11:52:46 +02:00
]),
V.h('td', {}, [
V.h('span', {}, V.h('select',{
'onfocusout':(e) => {
const old = node.wireless.channel24;
node.wireless.channel24 = parseInt(e.target.value, 10);
socket.sendnode(node, (msg)=>{
if (!msg.body) {
node.wireless.channel24 = old;
e.target.value = old;
}
});
}
}, channel24Options)),
V.h('span', {}, V.h('select',{
'onfocusout':(e) => {
const old = node.wireless.channel5;
node.wireless.channel5 = parseInt(e.target.value, 10);
socket.sendnode(node, (msg)=>{
if (!msg.body) {
node.wireless.channel5 = old;
e.target.value = old;
}
});
}
}, channel5Options))
]),
V.h('td', {}, [
2018-08-10 13:46:18 +02:00
V.h('span', {}, node.wireless_respondd ? node.wireless_respondd.txpower24 || '-':'-'),
V.h('span', {}, node.wireless_respondd ? node.wireless_respondd.txpower5 || '-':'-')
2018-08-10 11:52:46 +02:00
]),
V.h('td', {}, [
V.h('span', {}, V.h('input',{
'type': 'number',
'min': 0,
'max': 23,
'value': this._txpower24 || node.wireless.txpower24,
'oninput':(e) => {
this._txpower24 = e.target.value;
},
'onfocusout':(e) => {
delete this._txpower24;
const old = node.wireless.txpower24;
node.wireless.txpower24 = parseInt(e.target.value, 10);
socket.sendnode(node, (msg)=>{
if (!msg.body) {
node.wireless.txpower24 = old;
e.target.value = old;
}
});
}
})),
V.h('span', {}, V.h('input',{
'type': 'number',
'min': 0,
'max': 23,
'value': this._txpower5 || node.wireless.txpower5,
'oninput':(e) => {
this._txpower5 = e.target.value;
},
'onfocusout':(e) => {
delete this._txpower5;
const old = node.wireless.txpower5;
node.wireless.txpower5 = parseInt(e.target.value, 10);
socket.sendnode(node, (msg)=>{
if (!msg.body) {
node.wireless.txpower5 = old;
e.target.value = old;
}
});
}
}))
]),
V.h('td', {}, [
2018-08-10 13:46:18 +02:00
V.h('span', {}, node.statistics_respondd.clients.wifi24),
V.h('span', {}, node.statistics_respondd.clients.wifi5)
2018-08-10 11:52:46 +02:00
]),
V.h('td', {}, [
2018-08-10 13:46:18 +02:00
V.h('span', {}, node.statistics_respondd.wireless ? (node.statistics_respondd.wireless.filter((d) => d.frequency < 5000)[0] || {ChanUtil: '-'}).ChanUtil : '-'),
V.h('span', {}, node.statistics_respondd.wireless ? (node.statistics_respondd.wireless.filter((d) => d.frequency > 5000)[0] || {ChanUtil: '-'}).ChanUtil : '-'),
2018-08-10 11:52:46 +02:00
]),
V.h('td', {}, [
V.h('a',{
'class':'btn',
'href':gui.router.generate('node', {'nodeID': node.node_id})
}, 'Edit')
]),
]);
2017-05-16 19:18:35 +02:00
}
render () {
this.debouncer.run(() => { this.renderView(); });
}
renderView () {
let nodes = store.getNodes();
2017-05-16 19:18:35 +02:00
2018-08-10 11:52:46 +02:00
if (this.filter && this.filter.value !== '') {
// eslint-disable-next-line id-length
2018-08-10 11:52:46 +02:00
nodes = nodes.filter((d) => {
return d.node_id.toLowerCase().indexOf(this.filter.value.toLowerCase()) > -1 ||
d.hostname.toLowerCase().indexOf(this.filter.value.toLowerCase()) > -1 ||
d.owner.toLowerCase().indexOf(this.filter.value.toLowerCase()) > -1
});
}
2018-08-10 11:52:46 +02:00
this.table.setData(nodes);
}
}