2017-11-30 17:35:51 +01:00
|
|
|
import { withComponent, props } from 'skatejs';
|
|
|
|
|
|
|
|
const Component = withComponent();
|
|
|
|
class CurrentState extends Component {
|
|
|
|
static props = {
|
|
|
|
timeseries: props.string,
|
2017-12-05 14:43:07 +01:00
|
|
|
trueword: props.string,
|
|
|
|
falseword: props.string,
|
|
|
|
unknownword: props.string,
|
2017-11-30 17:35:51 +01:00
|
|
|
status: props.boolean,
|
|
|
|
statusknown: props.boolean,
|
|
|
|
interval: props.number,
|
|
|
|
};
|
|
|
|
|
|
|
|
connected() {
|
|
|
|
if (!this.timeseries) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.fetchData();
|
|
|
|
if (!this.interval) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.runInterval = window.setInterval(() => {
|
|
|
|
this.fetchData();
|
|
|
|
}, this.interval * 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
disconnecting() {
|
|
|
|
if (this.runInterval) {
|
|
|
|
window.clearInterval(this.runInterval);
|
|
|
|
delete this.runInterval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fetchData() {
|
|
|
|
const url = `http://openmct.cbrp3.c-base.org/telemetry/latest/${this.timeseries}`;
|
|
|
|
fetch(url)
|
|
|
|
.then(data => data.json())
|
|
|
|
.then((data) => {
|
|
|
|
if (data === null) {
|
|
|
|
this.statusknown = false;
|
|
|
|
this.status = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.status = data;
|
|
|
|
this.statusknown = true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer(renderRoot, render) {
|
|
|
|
const root = renderRoot;
|
|
|
|
while (root.firstChild) {
|
|
|
|
root.removeChild(root.firstChild);
|
|
|
|
}
|
|
|
|
root.appendChild(render());
|
|
|
|
}
|
|
|
|
|
2017-12-05 14:43:07 +01:00
|
|
|
render({ status, statusknown, trueword, falseword, unknownword }) {
|
2017-11-30 17:35:51 +01:00
|
|
|
const el = document.createElement('div');
|
|
|
|
el.style.width = '100%';
|
|
|
|
el.style.height = '100%';
|
2017-12-05 14:43:07 +01:00
|
|
|
let content = '<slot></slot>';
|
2017-11-30 17:35:51 +01:00
|
|
|
if (!statusknown) {
|
|
|
|
el.style.backgroundColor = '#555753';
|
2017-12-05 14:43:07 +01:00
|
|
|
if (unknownword) {
|
|
|
|
content = `${content} ${unknownword}`;
|
|
|
|
}
|
|
|
|
el.innerHTML = content;
|
2017-11-30 17:35:51 +01:00
|
|
|
return el;
|
|
|
|
}
|
|
|
|
if (status) {
|
|
|
|
el.style.backgroundColor = '#73d216';
|
2017-12-05 14:43:07 +01:00
|
|
|
if (trueword) {
|
|
|
|
content = `${content} ${trueword}`;
|
|
|
|
}
|
2017-11-30 17:35:51 +01:00
|
|
|
} else {
|
|
|
|
el.style.backgroundColor = '#cc0000';
|
2017-12-05 14:43:07 +01:00
|
|
|
if (falseword) {
|
|
|
|
content = `${content} ${falseword}`;
|
|
|
|
}
|
2017-11-30 17:35:51 +01:00
|
|
|
}
|
2017-12-05 14:43:07 +01:00
|
|
|
el.innerHTML = content;
|
2017-11-30 17:35:51 +01:00
|
|
|
return el;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define('cbase-currentstate', CurrentState);
|