aboutsummaryrefslogtreecommitdiff
path: root/src_js/vt.js
blob: 1f390ab807f11683aa77a4d9523fd6fcf7ff542d (plain) (blame)
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
import r from '@hat-core/renderer';
import * as u from '@hat-core/util';

import * as common from './common';


export function main() {
    const entries = r.get('entries');

    return ['div.main',
        ['table',
            ['thead',
                ['tr',
                    ['th.col-id', 'ID'],
                    ['th.col-time', 'Time'],
                    ['th.col-address', 'Address'],
                    ['th.col-source', 'Source'],
                    ['th.col-type', 'Type'],
                    ['th.col-data', 'Data']
                ]
            ],
            ['tbody', entries.map(entry =>
                ['tr',
                    ['td.col-id', String(entry.entry_id)],
                    ['td.col-time', common.timestampToString(entry.timestamp)],
                    ['td.col-address', String(entry.address)],
                    ['td.col-source', String(entry.source)],
                    ['td.col-type', String(entry.type)],
                    ['td.col-data', data(entry.type, entry.data)]
                ]
            )]
        ]
    ];
}


function data(type, data) {
    if (type == 'builtin.status.linux')
        return builtinStatusLinux(data);

    return JSON.stringify(data);
}


function builtinStatusLinux(data) {
    const timestamp = u.get('timestamp', data);
    const uptime = u.get('uptime', data);
    const thermal = u.get('thermal', data) || [];
    const disks = u.get('disks', data) || [];

    return ['div.data',
        ['label', 'Time:'],
        ['span', common.timestampToString(timestamp)],
        ['label', 'Uptime:'],
        ['span', `${uptime}s`],
        thermal.map(i => [
            ['label', `Temp - ${i.type}:`],
            ['span', `${i.temp}°C`]
        ]),
        disks.map(i => [
            ['label', `Disk - ${i.name}:`],
            ['span', `${i.percent} (${i.used}/${i.size})`]
        ]),
    ];
}