-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
39 lines (31 loc) · 1.01 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
/* global m */
// Resource list
var db = {};
m.request('db').then(function (data) {
db = data;
});
m.mount(document.getElementById('resources'), {
view: function view() {
var keys = Object.keys(db);
var resourceList = m('ul', keys.map(function (key) {
return m('li', [m('a', { href: key }, '/' + key), m('sup', Array.isArray(db[key]) ? ' ' + db[key].length + 'x' : ' object')]);
}).concat([m('a', { href: 'db' }, '/db'), m('sup', m('em', ' state'))]));
return [m('h4', 'Resources'), keys.length ? resourceList : m('p', 'No resources found')];
}
});
// Custom routes
var customRoutes = {};
m.request('__rules').then(function (data) {
customRoutes = data;
});
m.mount(document.getElementById('custom-routes'), {
view: function view() {
var rules = Object.keys(customRoutes);
if (rules.length) {
return [m('h4', 'Custom routes'), m('table', rules.map(function (rule) {
return m('tr', [m('td', rule), m('td', '⇢ ' + customRoutes[rule])]);
}))];
}
}
});