You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.1 KiB
45 lines
1.1 KiB
import m from 'mithril'; |
|
import { Page } from 'components/page'; |
|
import { MonitorApi, Status } from 'monitor-api'; |
|
|
|
import { Clock } from 'components/widgets/clock'; |
|
import { GaugeLinear } from 'components/widgets/gauge-linear'; |
|
|
|
require('./dashboard-page.css'); |
|
|
|
export class DashboardPage extends Page { |
|
status: Status = null; |
|
autoRefresh = true; |
|
|
|
oninit() { |
|
this.status = MonitorApi.get().getStatus(); |
|
this.refresh(); |
|
} |
|
|
|
onbeforeremove(vnode: m.Vnode<{}, {}>) { |
|
this.autoRefresh = false; |
|
} |
|
|
|
async refresh() { |
|
let newStatus = await MonitorApi.get().fetchStatus(); |
|
if(this.status == null) |
|
m.redraw(); |
|
this.status = newStatus; |
|
// todo: update widgets (avoiding to use m.redraw which is a bit costly on CPU) |
|
if(this.autoRefresh) |
|
setTimeout(() => { if(this.autoRefresh) this.refresh(); }, 500); |
|
} |
|
|
|
view() { |
|
return this.status |
|
? <div class="dashboard-page"> |
|
<div class="widgets-row"> |
|
<Clock/> |
|
</div> |
|
<div class="widgets-row" style="height: 40%"> |
|
<GaugeLinear widgetWidth={0.2} /> |
|
</div> |
|
</div> |
|
: <p>Chargement...</p>; |
|
} |
|
}
|
|
|