Implement task queue and notifications

This commit is contained in:
Zaid Abdulla committed 2018-12-26 00:22:07 -08:00
1 parent 9b827c5f5e
commit b24c3626ac
20 files changed
+1000 -88

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
"use strict";
import m from "mithril";
import * as components from "../components";
const component = {
view: vnode => {
let children = Object.values(vnode.attrs.components).map(c => {
const attrs = Object.assign({}, vnode.attrs, c);
return m(components.get(attrs.type), attrs);
});
if (vnode.attrs.element) return m(vnode.attrs.element, children);
else return children;
}
};
export default component;
+4 -1
View File
@@ -16,7 +16,10 @@ const component = {
m("th", p.label),
m(
"td",
m(components.get("parameter"), Object.assign({ device: device }, p))
m(
components.get(p.type || "parameter"),
Object.assign({ device: device }, p)
)
)
)
);
+53 -6
View File
@@ -2,6 +2,7 @@
import m from "mithril";
import * as components from "../components";
import * as taskQueue from "../task-queue";
const component = {
view: vnode => {
@@ -12,14 +13,18 @@ const component = {
if (!device[object]) return null;
const instances = new Set();
const prefix = `${object}.`;
for (let p in device)
if (p.startsWith(object))
instances.add(p.slice(0, p.indexOf(".", object.length + 1)));
if (p.startsWith(prefix)) {
let i = p.indexOf(".", prefix.length);
if (i === -1) instances.add(p);
else instances.add(p.slice(0, i));
}
const headers = Object.values(parameters).map(p => m("th", p.label));
const thead = m("thead", m("tr", headers));
const thead = m(
"thead",
m("tr", Object.values(parameters).map(p => m("th", p.label)))
);
const rows = [];
for (let i of instances) {
const row = Object.values(parameters).map(p =>
@@ -33,8 +38,50 @@ const component = {
)
)
);
if (device[i].writable === true)
row.push(
m(
"td",
m(
"a.delete",
{
onclick: () => {
taskQueue.queueTask({
name: "deleteObject",
device: device["DeviceID.ID"].value[0],
objectName: i
});
}
},
"−"
)
)
);
rows.push(m("tr", row));
}
if (device[object].writable === true)
rows.push(
m(
"tr",
m("td", { colspan: headers.length }),
m(
"td",
m(
"a.add",
{
onclick: () => {
taskQueue.queueTask({
name: "addObject",
device: device["DeviceID.ID"].value[0],
objectName: object
});
}
},
"+"
)
)
)
);
return m("table.parameter-table", thead, m("tbody", rows));
}
};
+24 -13
View File
@@ -1,7 +1,7 @@
"use strict";
import m from "mithril";
import * as components from "../components";
import * as taskQueue from "../task-queue";
const component = {
view: vnode => {
@@ -11,19 +11,30 @@ const component = {
if (param.value[1] === "xsd:dateTime")
value = new Date(value).toISOString();
let meta;
if (vnode.attrs.meta) {
const metaAttrs = Object.assign(
{ device: vnode.attrs.device, parameter: vnode.attrs.parameter },
vnode.attrs.meta
let edit;
if (param.writable)
edit = m(
"a.edit",
{
onclick: () => {
taskQueue.stageSpv({
name: "setParameterValues",
device: vnode.attrs.device["DeviceID.ID"].value[0],
parameterValues: [
[vnode.attrs.parameter, param.value[0], param.value[1]]
]
});
}
},
"✎"
);
meta = m("span", [
" (",
m(components.get(metaAttrs.type), metaAttrs),
")"
]);
}
return [m("span", { title: param.valueTimestamp }, value), meta];
return m(
"span.parameter-value",
{ title: param.valueTimestamp },
value,
edit
);
}
};
+49
View File
@@ -0,0 +1,49 @@
"use strict";
import m from "mithril";
import * as taskQueue from "../task-queue";
import * as store from "../store";
import * as notifications from "../notifications";
const component = {
view: vnode => {
return m(
"a.summon",
{
onclick: () => {
const params = Object.values(vnode.attrs.parameters);
const task = {
name: "getParameterValues",
parameterNames: params,
device: vnode.attrs.device["DeviceID.ID"].value[0]
};
taskQueue
.commit([task], (deviceId, connectionRequestStatus, tasks2) => {
for (let t of tasks2)
if (t.status === "stale") taskQueue.deleteTask(t);
if (connectionRequestStatus !== "OK")
notifications.push(
"error",
`${deviceId}: ${connectionRequestStatus}`
);
else if (tasks2[0].status === "stale")
notifications.push(
"error",
`${deviceId}: No contact from device`
);
else if (tasks2[0].status === "fault")
notifications.push("error", `${deviceId}: Refresh faulted`);
else notifications.push("success", `${deviceId}: Summoned`);
})
.then(() => {
store.fulfill(Date.now(), Date.now());
});
}
},
"Summon"
);
}
};
export default component;