Add linting rules
This commit is contained in:
1 parent
75a5a42296
commit
c702003c32
43 files changed
+705
-576
No files matched your search
@@ -12,7 +12,7 @@ const component = {
|
||||
view: vnode => {
|
||||
const device = vnode.attrs.device;
|
||||
|
||||
let search = m("input", {
|
||||
const search = m("input", {
|
||||
type: "text",
|
||||
placeholder: "Search parameters",
|
||||
oninput: e => {
|
||||
@@ -20,10 +20,10 @@ const component = {
|
||||
}
|
||||
});
|
||||
|
||||
let instanceRegex = /\.[0-9]+$/;
|
||||
const instanceRegex = /\.[0-9]+$/;
|
||||
let re;
|
||||
if (vnode.state.searchString) {
|
||||
let keywords = vnode.state.searchString.split(" ").filter(s => s);
|
||||
const keywords = vnode.state.searchString.split(" ").filter(s => s);
|
||||
if (keywords.length)
|
||||
re = new RegExp(keywords.map(s => escapeRegExp(s)).join(".*"), "i");
|
||||
}
|
||||
@@ -31,22 +31,22 @@ const component = {
|
||||
const rows = Object.keys(device)
|
||||
.sort()
|
||||
.map(k => {
|
||||
let p = device[k];
|
||||
let val = [];
|
||||
let attrs = {};
|
||||
const p = device[k];
|
||||
const val = [];
|
||||
const attrs = {};
|
||||
if (re) {
|
||||
let str = p.value && p.value[0] ? `${k} ${p.value[0]}` : k;
|
||||
const str = p.value && p.value[0] ? `${k} ${p.value[0]}` : k;
|
||||
if (!re.test(str)) attrs.style = "display: none;";
|
||||
}
|
||||
|
||||
if (p.object === false)
|
||||
if (p.object === false) {
|
||||
val.push(
|
||||
m(
|
||||
components.get("parameter"),
|
||||
Object.assign({ device: device, parameter: k })
|
||||
)
|
||||
);
|
||||
else if (p.object && p.writable)
|
||||
} else if (p.object && p.writable) {
|
||||
if (instanceRegex.test(k)) {
|
||||
val.push(
|
||||
m(
|
||||
@@ -82,6 +82,7 @@ const component = {
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
val.push(
|
||||
m(
|
||||
|
||||
@@ -12,10 +12,10 @@ const component = {
|
||||
view: vnode => {
|
||||
if (vnode.attrs.filter) {
|
||||
const filter = memoizedParse(vnode.attrs.filter);
|
||||
if (!store.evaluateExpression(filter, vnode.attrs.device)) return;
|
||||
if (!store.evaluateExpression(filter, vnode.attrs.device)) return null;
|
||||
}
|
||||
|
||||
let children = Object.values(vnode.attrs.components).map(c => {
|
||||
const children = Object.values(vnode.attrs.components).map(c => {
|
||||
if (typeof c !== "object") return `${c}`;
|
||||
const attrs = Object.assign({}, vnode.attrs, c);
|
||||
return m(components.get(attrs.type), attrs);
|
||||
|
||||
@@ -20,7 +20,7 @@ const component = {
|
||||
const thead = m("thead", m("tr", headers));
|
||||
|
||||
const rows = [];
|
||||
for (let f of faults.value)
|
||||
for (const f of faults.value) {
|
||||
rows.push([
|
||||
m("td", f["channel"]),
|
||||
m("td", f["code"]),
|
||||
@@ -51,14 +51,17 @@ const component = {
|
||||
)
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
let tbody;
|
||||
if (rows.length) tbody = m("tbody", rows.map(r => m("tr", r)));
|
||||
else
|
||||
if (rows.length) {
|
||||
tbody = m("tbody", rows.map(r => m("tr", r)));
|
||||
} else {
|
||||
tbody = m(
|
||||
"tbody",
|
||||
m("tr.empty", m("td", { colspan: headers.length }, "No faults"))
|
||||
);
|
||||
}
|
||||
|
||||
return m("table.table", thead, tbody);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ const component = {
|
||||
view: vnode => {
|
||||
const device = vnode.attrs.device;
|
||||
const chart = CHARTS[vnode.attrs.chart];
|
||||
for (let slice of Object.values(chart.slices)) {
|
||||
for (const slice of Object.values(chart.slices)) {
|
||||
const filter = memoizedParse(slice.filter);
|
||||
if (store.evaluateExpression(filter, device)) {
|
||||
const dot = m(
|
||||
@@ -35,6 +35,7 @@ const component = {
|
||||
return m("span.overview-dot", dot, `${slice.label}`);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import * as expressionParser from "../../common/expression-parser";
|
||||
|
||||
const component = {
|
||||
oninit: vnode => {
|
||||
let obj = expression.parse(vnode.attrs.parameter);
|
||||
const obj = expression.parse(vnode.attrs.parameter);
|
||||
if (!Array.isArray(obj) || !obj[0] === "PARAM")
|
||||
throw new Error("Object must be a parameter path");
|
||||
vnode.state.object = obj[1];
|
||||
@@ -30,19 +30,20 @@ const component = {
|
||||
|
||||
const instances = new Set();
|
||||
const prefix = `${object}.`;
|
||||
for (let p in device)
|
||||
for (const p in device) {
|
||||
if (p.startsWith(prefix)) {
|
||||
let i = p.indexOf(".", prefix.length);
|
||||
const 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 rows = [];
|
||||
for (let i of instances) {
|
||||
for (const i of instances) {
|
||||
const row = parameters.map(p => {
|
||||
const param = expressionParser.map(p.parameter, e => {
|
||||
if (Array.isArray(e) && e[0] === "PARAM")
|
||||
@@ -62,7 +63,7 @@ const component = {
|
||||
);
|
||||
});
|
||||
|
||||
if (device[i].writable === true)
|
||||
if (device[i].writable === true) {
|
||||
row.push(
|
||||
m(
|
||||
"td",
|
||||
@@ -82,15 +83,17 @@ const component = {
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
rows.push(m("tr", row));
|
||||
}
|
||||
|
||||
if (!rows.length)
|
||||
if (!rows.length) {
|
||||
rows.push(
|
||||
m("tr.empty", m("td", { colspan: headers.length }, "No instances"))
|
||||
);
|
||||
}
|
||||
|
||||
if (device[object].writable === true)
|
||||
if (device[object].writable === true) {
|
||||
rows.push(
|
||||
m(
|
||||
"tr",
|
||||
@@ -114,6 +117,7 @@ const component = {
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
let label;
|
||||
if (vnode.attrs.label) label = m("h2", vnode.attrs.label);
|
||||
|
||||
@@ -11,27 +11,22 @@ const memoizedParse = memoize(expression.parse);
|
||||
|
||||
const evaluateParam = memoize((exp, obj, now) => {
|
||||
let timestamp = now;
|
||||
let params = new Set();
|
||||
let value = expression.evaluate(
|
||||
memoizedParse(exp),
|
||||
obj,
|
||||
now,
|
||||
e => {
|
||||
if (Array.isArray(e)) {
|
||||
if (e[0] === "PARAM") {
|
||||
params.add(e[1]);
|
||||
if (!Array.isArray(e[1])) {
|
||||
let p = obj[e[1]];
|
||||
if (p && p.valueTimestamp)
|
||||
timestamp = Math.min(timestamp, p.valueTimestamp);
|
||||
}
|
||||
const params = new Set();
|
||||
const value = expression.evaluate(memoizedParse(exp), obj, now, e => {
|
||||
if (Array.isArray(e)) {
|
||||
if (e[0] === "PARAM") {
|
||||
params.add(e[1]);
|
||||
if (!Array.isArray(e[1])) {
|
||||
const p = obj[e[1]];
|
||||
if (p && p.valueTimestamp)
|
||||
timestamp = Math.min(timestamp, p.valueTimestamp);
|
||||
}
|
||||
if (e[0] === "FUNC" && e[1] === "DATE_STRING" && !Array.isArray(e[2]))
|
||||
return new Date(e[2]).toLocaleString();
|
||||
}
|
||||
return e;
|
||||
if (e[0] === "FUNC" && e[1] === "DATE_STRING" && !Array.isArray(e[2]))
|
||||
return new Date(e[2]).toLocaleString();
|
||||
}
|
||||
);
|
||||
return e;
|
||||
});
|
||||
|
||||
let parameter = params.size === 1 ? params.values().next().value : null;
|
||||
if (Array.isArray(parameter)) parameter = null;
|
||||
@@ -42,7 +37,7 @@ const component = {
|
||||
view: vnode => {
|
||||
const device = vnode.attrs.device;
|
||||
|
||||
let { value, timestamp, parameter } = evaluateParam(
|
||||
const { value, timestamp, parameter } = evaluateParam(
|
||||
vnode.attrs.parameter,
|
||||
vnode.attrs.device,
|
||||
store.getTimestamp()
|
||||
@@ -51,7 +46,7 @@ const component = {
|
||||
if (value == null) return null;
|
||||
|
||||
let edit;
|
||||
if (device[parameter] && device[parameter].writable)
|
||||
if (device[parameter] && device[parameter].writable) {
|
||||
edit = m(
|
||||
"button",
|
||||
{
|
||||
@@ -72,6 +67,7 @@ const component = {
|
||||
},
|
||||
"✎"
|
||||
);
|
||||
}
|
||||
|
||||
return m(
|
||||
"span.parameter-value",
|
||||
|
||||
@@ -13,7 +13,7 @@ const component = {
|
||||
vnode.state.timeout = null;
|
||||
},
|
||||
view: vnode => {
|
||||
let refresh = () => {
|
||||
const refresh = () => {
|
||||
const device = vnode.attrs.device;
|
||||
let param =
|
||||
device["InternetGatewayDevice.ManagementServer.ConnectionRequestURL"];
|
||||
@@ -34,20 +34,22 @@ const component = {
|
||||
});
|
||||
};
|
||||
|
||||
let t = vnode.state.timestamp + REFRESH_INTERVAL - Date.now();
|
||||
const t = vnode.state.timestamp + REFRESH_INTERVAL - Date.now();
|
||||
clearTimeout(vnode.state.timeout);
|
||||
if (t <= 0) refresh();
|
||||
else vnode.state.timeout = setTimeout(refresh, t);
|
||||
|
||||
if (vnode.state.host) {
|
||||
let status = "";
|
||||
if (vnode.state.ping)
|
||||
if (vnode.state.ping) {
|
||||
if (vnode.state.ping.avg != null)
|
||||
status = `${Math.trunc(vnode.state.ping.avg)} ms`;
|
||||
else status = "Unreachable";
|
||||
}
|
||||
|
||||
return m("div", `Pinging ${vnode.state.host}: ${status}`);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ const singular = {
|
||||
|
||||
function createField(current, attr, focus) {
|
||||
if (attr.type === "combo") {
|
||||
let options = [m("option", { value: "" }, "--Please choose--")];
|
||||
for (let op of attr.options) options.push(m("option", { value: op }, op));
|
||||
const options = [m("option", { value: "" }, "--Please choose--")];
|
||||
for (const op of attr.options) options.push(m("option", { value: op }, op));
|
||||
|
||||
let selected = "";
|
||||
if (attr.options.includes(current.object[attr.id]))
|
||||
@@ -40,7 +40,7 @@ function createField(current, attr, focus) {
|
||||
name: attr.id,
|
||||
value: current.object[attr.id],
|
||||
oncreate: _vnode => {
|
||||
let editor = codeMirror.fromTextArea(_vnode.dom, {
|
||||
const editor = codeMirror.fromTextArea(_vnode.dom, {
|
||||
mode: "javascript",
|
||||
lineNumbers: true
|
||||
});
|
||||
@@ -87,21 +87,22 @@ function createField(current, attr, focus) {
|
||||
|
||||
const component = {
|
||||
view: vnode => {
|
||||
let actionHandler = vnode.attrs.actionHandler;
|
||||
let attributes = vnode.attrs.attributes;
|
||||
let resource = vnode.attrs.resource;
|
||||
let base = vnode.attrs.base || {};
|
||||
if (!vnode.state.current)
|
||||
const actionHandler = vnode.attrs.actionHandler;
|
||||
const attributes = vnode.attrs.attributes;
|
||||
const resource = vnode.attrs.resource;
|
||||
const base = vnode.attrs.base || {};
|
||||
if (!vnode.state.current) {
|
||||
vnode.state.current = {
|
||||
isNew: !base["_id"],
|
||||
object: Object.assign({}, base)
|
||||
};
|
||||
}
|
||||
|
||||
let current = vnode.state.current;
|
||||
const current = vnode.state.current;
|
||||
|
||||
let form = [];
|
||||
const form = [];
|
||||
let focused = false;
|
||||
for (let attr of attributes) {
|
||||
for (const attr of attributes) {
|
||||
let focus = false;
|
||||
if (!focused && (current.isNew || attr.id !== "_id"))
|
||||
focus = focused = true;
|
||||
@@ -117,9 +118,9 @@ const component = {
|
||||
}
|
||||
|
||||
const submit = m("button.primary", { type: "submit" }, "Save");
|
||||
let buttons = [submit];
|
||||
const buttons = [submit];
|
||||
|
||||
if (!current.isNew)
|
||||
if (!current.isNew) {
|
||||
buttons.push(
|
||||
m(
|
||||
"button.primary",
|
||||
@@ -135,10 +136,11 @@ const component = {
|
||||
"Delete"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
form.push(m(".actions-bar", buttons));
|
||||
|
||||
let children = [
|
||||
const children = [
|
||||
m("h1", `${current.isNew ? "New" : "Editing"} ${singular[resource]}`),
|
||||
m(
|
||||
"form",
|
||||
@@ -147,7 +149,7 @@ const component = {
|
||||
e.redraw = false;
|
||||
e.target.onsubmit = null;
|
||||
e.preventDefault();
|
||||
for (let elem of e.target.elements) elem.disabled = true;
|
||||
for (const elem of e.target.elements) elem.disabled = true;
|
||||
submit.dom.textContent = "Loading ...";
|
||||
actionHandler("save", current.object);
|
||||
}
|
||||
|
||||
@@ -37,28 +37,29 @@ const component = {
|
||||
.commit(
|
||||
[task],
|
||||
(deviceId, err, connectionRequestStatus, tasks2) => {
|
||||
if (err)
|
||||
return notifications.push(
|
||||
"error",
|
||||
`${deviceId}: ${err.message}`
|
||||
);
|
||||
if (err) {
|
||||
notifications.push("error", `${deviceId}: ${err.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
for (let t of tasks2)
|
||||
for (const t of tasks2)
|
||||
if (t.status === "stale") taskQueue.deleteTask(t);
|
||||
|
||||
if (connectionRequestStatus !== "OK")
|
||||
if (connectionRequestStatus !== "OK") {
|
||||
notifications.push(
|
||||
"error",
|
||||
`${deviceId}: ${connectionRequestStatus}`
|
||||
);
|
||||
else if (tasks2[0].status === "stale")
|
||||
} else if (tasks2[0].status === "stale") {
|
||||
notifications.push(
|
||||
"error",
|
||||
`${deviceId}: No contact from device`
|
||||
);
|
||||
else if (tasks2[0].status === "fault")
|
||||
} else if (tasks2[0].status === "fault") {
|
||||
notifications.push("error", `${deviceId}: Refresh faulted`);
|
||||
else notifications.push("success", `${deviceId}: Summoned`);
|
||||
} else {
|
||||
notifications.push("success", `${deviceId}: Summoned`);
|
||||
}
|
||||
}
|
||||
)
|
||||
.then(() => {
|
||||
|
||||
@@ -11,7 +11,7 @@ const component = {
|
||||
if (vnode.attrs.writable != null) writable = vnode.attrs.writable;
|
||||
|
||||
const tags = [];
|
||||
for (let p of Object.keys(device))
|
||||
for (const p of Object.keys(device))
|
||||
if (p.startsWith("Tags.")) tags.push(p.slice(5));
|
||||
|
||||
tags.sort();
|
||||
|
||||
Reference in new issue
Block a user