-
Notifications
You must be signed in to change notification settings - Fork 0
/
heisswolf.html
129 lines (127 loc) · 4.05 KB
/
heisswolf.html
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
<html>
<head>
<title>Heisswolf-Einstellungen</title>
<meta charset="UTF-8">
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
</head>
<body>
</body>
<script>
$(document).ready(() => {
//HTML aufbauen
let titleRow = $('<div>').addClass('row')
.append($('<h1>').addClass('mx-auto mb-4').append('Heisswolf-Einstellungen'));
let tableRow = $('<div>').addClass('row');
let table = $('<table>').addClass('table table-sm table-striped');
let thead = $('<thead>');
thead.append(
$('<tr>')
.append($('<th>').attr('scope', 'col').append('Nr'))
.append($('<th>').attr('scope', 'col').append('Bezeichnung'))
.append($('<th>').attr('scope', 'col').append('Uo'))
.append($('<th>').attr('scope', 'col').append('Ui'))
.append($('<th>').attr('scope', 'col').append('Fu'))
.append($('<th>').attr('scope', 'col').append('Fo')));
let tbody = $('<tbody>');
let errorRow = $('<div>').addClass('row d-print-none d-none');
let errorNode = $('<div>').addClass('col alert alert-danger');
$('body').addClass('container')
.append(titleRow)
.append(tableRow
.append($('<div>').addClass('col')
.append(table.append(thead).append(tbody))))
.append(errorRow.append(errorNode));
let errorMsg = msg => {
errorRow.removeClass('d-none');
errorNode.append($('<p>').addClass('mb-0').append(msg));
};
let promises = [];
for (let i=1; i<=99; i++) {
let nr = i.toString();
if (nr.length < 2)
nr = '0' + nr;
let filename = `heisswolf/${nr}`;
promises.push(new Promise((resolve, reject) => {
let req = new XMLHttpRequest();
req.open('GET', filename);
req.onload = () => {
if (req.status == 200)
resolve(req.response);
else if (req.status == 404)
resolve(undefined);
else
reject(Error(`Konnte ${filename} nicht laden`));
};
req.onerror = () => reject(Error('Netzwerk-Problem'));
req.send();
}).then(response => {
let result = {
nr
};
if (response !== undefined)
response.split(/\n/).forEach(str => {
if (/^\s*$/.test(str))
return;
let keyvalue = str.split(/=/, 2);
if (!/^(name|Uo|Ui|Fo|Fu)$/.test(keyvalue[0]))
throw Error(`${nr}: Couldn\'t parse ${str}`);
result[keyvalue[0]] = keyvalue[1];
});
let tr = $('<tr>');
if (response === undefined)
tr.addClass('table-warning d-print-none');
['nr', 'name', 'Uo', 'Ui', 'Fu', 'Fo'].forEach(id => {
let text = (id in result) ? result[id] : '';
if (id == 'name') {
let td = $('<td>');
text.split(/,/).forEach((t, i) => {
if (i > 0)
td.append($('<br>'));
td.append(t);
});
tr.append(td);
}
else
tr.append($('<td>').append(text));
});
tbody.append(tr);
}, e => {
errorMsg(e.message);
})
.catch(e => {
errorMsg(e.message);
}));
}
Promise.all(promises).then(() => {
let rows = [];
tbody.children().each((i, tr) => {
let value = $(tr).children().first().text();
if (value !== undefined)
value = +value;
rows.push({
id: value,
row: $(tr)
});
});
rows.sort((a, b) => {
if (!a.row.hasClass('table-warning') &&
b.row.hasClass('table-warning'))
return 1;
if (a.row.hasClass('table-warning') &&
!b.row.hasClass('table-warning'))
return -1;
return (a.id < b.id) ? 1 : (a.id > b.id) ? -1 : 0;
});
let prevSibling = undefined;
rows.forEach(row => {
if (prevSibling === undefined)
tbody.prepend(row.row);
else
row.row.insertAfter(prevSibling);
});
});
});
</script>
</html>