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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
'use strict';
'require uci';
'require view';
'require poll';
'require ui';
'require rpc';
'require olsr-viz as olsrviz';
return view.extend({
callGetOlsrVizData: rpc.declare({
object: 'olsrvizinfo',
method: 'getolsrvizdata'
}),
fetch_jsoninfo() {
let json;
let data;
let self = this;
return new Promise(function (resolve, reject) {
L.resolveDefault(self.callGetOlsrVizData(), {})
.then(function (res) {
json = res;
data = json.jsonreq4;
resolve([data]);
})
.catch(function (err) {
console.error(err);
reject([null]);
});
});
},
action_olsr_viz() {
let self = this;
return new Promise(function (resolve, reject) {
self
.fetch_jsoninfo()
.then(function ([data]) {
const result = { viz_data: data };
resolve(result);
})
.catch(function (err) {
reject(err);
});
});
},
load() {
document.querySelector('head').appendChild(E('style', { 'type': 'text/css' }, [
'.label {color:black;background-color:white}',
'.olsr_viz_main {width: 100%; height: 93%; border: 1px solid #ccc; margin-left:auto; margin-right:auto; text-align:center; overflow: scroll}'
]));
return new Promise(function (resolve, reject) {
const script = E('script', { 'type': 'text/javascript' });
script.onload = resolve;
script.onerror = reject;
script.src = L.resource('olsr-viz.js');
document.querySelector('head').appendChild(script);
});
},
render() {
let viz_res;
return this.action_olsr_viz()
.then(function (result) {
viz_res = result.viz_data;
const nodeDiv = E('div', { 'id': 'nodes', 'style': 'width: 1px; height: 1px; position: relative; z-index:4' });
const edgeDiv = E('div', { 'id': 'edges', 'style': 'width: 1px; height: 1px; position: relative; z-index:2' });
const mainDiv = E('div', {
'id': 'main',
'class': 'olsr_viz_main'
}, [nodeDiv, edgeDiv]);
const zoomInput = E('input', {
'id': 'zoom',
'name': 'zoom',
'type': 'text',
'value': '2.0',
'size': '5',
'style': 'min-width: unset !important;',
'onchange': 'set_scale()'
});
const metricInput = E('input', {
'id': 'maxmetric',
'name': 'maxmetric',
'type': 'text',
'value': '3',
'size': '4',
'style': 'min-width: unset !important;',
'change': (ev)=>olsrviz.set_maxmetric(ev.target.value)
});
const autoOptimizationCheckbox = E('input', {
'id': 'auto_declump',
'name': 'auto_declump',
'type': 'checkbox',
'change': (ev) => olsrviz.set_autodeclump(ev.target.checked),
'checked': 'checked'
});
const hostnamesCheckbox = E('input', {
'id': 'show_hostnames',
'name': 'show_hostnames',
'type': 'checkbox',
'change': (ev) => olsrviz.set_showdesc(ev.target.checked),
'checked': 'checked'
});
const form = E('form', { 'action': '' }, [
E('p', {}, [
E('b', { 'title': 'Bestimmt die Vergrößerungsstufe.' }, 'Zoom '),
E('a', { 'href': '#', 'click': () =>olsrviz.set_scale(scale+0.1) }, '+ '),
E('a', { 'href': '#', 'click': () =>olsrviz.set_scale(scale-0.1) }, '\u2212 '),
zoomInput,
E('b', { 'title': 'Beschränkt die Anzeige auf eine maximale Hop-Entfernung.' }, ' Metrik'),
E('a', { 'href': '#', 'click': () => olsrviz.set_maxmetric(maxmetric+1) }, '+ '),
E('a', { 'href': '#', 'click': () => olsrviz.set_maxmetric(Math.max(maxmetric, 1) - 1) }, '\u2212'),
metricInput,
E('b', { 'title': 'Schaltet die automatischen Layout-Optimierung ein.' }, ' Optimierung'),
autoOptimizationCheckbox,
E('b', { 'title': 'Zeige Hostnamen an.' }, ' | Hostnamen'),
hostnamesCheckbox,
E('a', { 'href': '#', 'click': olsrviz.viz_save, 'title': 'Speichert die aktuellen Einstellungen in einem Cookie.', 'style': 'font-weight:700;' }, ' | Speichern'),
E('a', { 'href': '#', 'click': olsrviz.viz_reset, 'title': 'Startet das Viz-Skriptprogramm neu.', 'style': 'font-weight:700;' }, ' | Zurücksetzen')
])
]);
const debugSpan = E('span', { 'id': 'debug', 'style': 'visibility:hidden;' });
const vizDiv = E('div', { 'id': 'RSIFrame', 'name': 'RSIFrame', 'style': 'border:0px; width:0px; height:0px; visibility:hidden;' });
olsrviz.viz_setup(vizDiv, mainDiv, nodeDiv, edgeDiv, debugSpan, zoomInput, metricInput); olsrviz.viz_update();
function setInnerHTML(elm, html) {
elm.innerHTML = html;
Array.from(elm.querySelectorAll("script"))
.forEach(oldScriptEl => {
const newScriptEl = document.createElement("script");
Array.from(oldScriptEl.attributes).forEach(attr => {
newScriptEl.setAttribute(attr.name, attr.value)
});
const scriptText = document.createTextNode(oldScriptEl.innerHTML);
newScriptEl.appendChild(scriptText);
oldScriptEl.parentNode.replaceChild(newScriptEl, oldScriptEl);
});
};
setInnerHTML(vizDiv, viz_res);
const renderDiv = E('div', { 'style': 'width:100%; height:640px; border:none', 'scrolling': 'no' }, [mainDiv]);
const fresult = E([], {}, [form, debugSpan, renderDiv, vizDiv]);
return fresult;
})
.catch(function (error) {
console.error(error);
});
},
handleSaveApply: null,
handleSave: null,
handleReset: null,
});
|