-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.mjs
68 lines (54 loc) · 2 KB
/
test.mjs
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
import { MAContainer } from './Magritte/descriptions/MAContainer.js';
import { MAIntDescription } from './Magritte/descriptions/MAIntDescription.js';
import { MAStringDescription } from './Magritte/descriptions/MAStringDescription.js';
import { MADateAndTimeDescription } from './Magritte/descriptions/MADateAndTimeDescription.js';
import data from './test-data.json' assert { type: 'json' }
const description = new MAContainer()
const descriptionChilds = data.descriptionChilds
for (const child of descriptionChilds) {
description.append(getClassInstance(Object.keys(child)[0], Object.values(child)[0]))
}
viewGenerator(data.object, description)
function getClassInstance(className, args) {
switch (className) {
case 'MAIntDescription':
return new MAIntDescription(args)
break;
case 'MAStringDescription':
return new MAStringDescription(args)
break;
case 'MADateAndTimeDescription':
return new MADateAndTimeDescription(args)
break;
}
}
function viewGenerator(object, description) {
//const view = document.getElementById('view')
const childSorted = [...description.children].sort((a, b) => Number(a.priority) - Number(b.priority))
for (const child of childSorted) {
if (child.visible) {
printRow(child, object[child.name])
}
}
function printRow(child, value)
{
console.log(`value=${value}, \t label=${child.label}, \t comment=${child.comment}`);
}
function printRow_html(child, objectName) {
const row = document.createElement('p')
const label = document.createElement('b')
const name = document.createElement('span')
const hint = child.comment ? document.createElement('span') : null
label.innerHTML = `${child.label || child.undefined}: `
name.innerHTML = objectName
row.appendChild(label)
row.appendChild(name)
if (hint) {
hint.innerHTML = ' \u24D8'
hint.classList.add('hint')
hint.setAttribute('title', child.comment)
row.appendChild(hint)
}
view.appendChild(row)
}
}