Evaluate component attrs before use
This commit is contained in:
1 parent
73baffc3b9
commit
88a84788a5
7 files changed
+26
-16
No files matched your search
@@ -23,6 +23,7 @@ import * as taskQueue from "../task-queue";
|
|||||||
import { parse } from "../../lib/common/expression-parser";
|
import { parse } from "../../lib/common/expression-parser";
|
||||||
import memoize from "../../lib/common/memoize";
|
import memoize from "../../lib/common/memoize";
|
||||||
import { getIcon } from "../icons";
|
import { getIcon } from "../icons";
|
||||||
|
import { evaluateExpression } from "../store";
|
||||||
|
|
||||||
const memoizedParse = memoize(parse);
|
const memoizedParse = memoize(parse);
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ const component: ClosureComponent = (): Component => {
|
|||||||
view: (vnode) => {
|
view: (vnode) => {
|
||||||
const device = vnode.attrs["device"];
|
const device = vnode.attrs["device"];
|
||||||
|
|
||||||
const limit = vnode.attrs["limit"] > 0 ? vnode.attrs["limit"] : 100;
|
const limit = evaluateExpression(vnode.attrs["limit"], device) || 100;
|
||||||
|
|
||||||
const search = m("input", {
|
const search = m("input", {
|
||||||
type: "text",
|
type: "text",
|
||||||
|
|||||||
@@ -19,18 +19,22 @@
|
|||||||
|
|
||||||
import { ClosureComponent, Component } from "mithril";
|
import { ClosureComponent, Component } from "mithril";
|
||||||
import { m } from "../components";
|
import { m } from "../components";
|
||||||
|
import { evaluateExpression } from "../store";
|
||||||
|
|
||||||
const component: ClosureComponent = (): Component => {
|
const component: ClosureComponent = (): Component => {
|
||||||
return {
|
return {
|
||||||
view: (vnode) => {
|
view: (vnode) => {
|
||||||
let deviceId;
|
let deviceId;
|
||||||
if (vnode.attrs["device"])
|
const device = vnode.attrs["device"];
|
||||||
deviceId = vnode.attrs["device"]["DeviceID.ID"].value[0];
|
if (device) deviceId = device["DeviceID.ID"].value[0];
|
||||||
|
|
||||||
const children = Object.values(vnode.attrs["components"]).map((c) => {
|
const children = Object.values(vnode.attrs["components"]).map((c) => {
|
||||||
|
if (Array.isArray(c)) c = evaluateExpression(c, device || {});
|
||||||
if (typeof c !== "object") return `${c}`;
|
if (typeof c !== "object") return `${c}`;
|
||||||
|
const type = evaluateExpression(c["type"], device || {});
|
||||||
|
if (!type) return null;
|
||||||
const attrs = Object.assign({}, vnode.attrs, c);
|
const attrs = Object.assign({}, vnode.attrs, c);
|
||||||
return m(attrs["type"], attrs);
|
return m(type as string, attrs);
|
||||||
});
|
});
|
||||||
if (deviceId) {
|
if (deviceId) {
|
||||||
return m(
|
return m(
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
import { ClosureComponent, Component } from "mithril";
|
import { ClosureComponent, Component } from "mithril";
|
||||||
import { m } from "../components";
|
import { m } from "../components";
|
||||||
import config from "../config";
|
import config from "../config";
|
||||||
import * as store from "../store";
|
import { evaluateExpression } from "../store";
|
||||||
|
|
||||||
const CHARTS = config.ui.overview.charts;
|
const CHARTS = config.ui.overview.charts;
|
||||||
|
|
||||||
@@ -28,11 +28,12 @@ const component: ClosureComponent = (): Component => {
|
|||||||
return {
|
return {
|
||||||
view: (vnode) => {
|
view: (vnode) => {
|
||||||
const device = vnode.attrs["device"];
|
const device = vnode.attrs["device"];
|
||||||
const chart = CHARTS[vnode.attrs["chart"]] as Record<string, unknown>;
|
const chartName = evaluateExpression(vnode.attrs["chart"], device || {});
|
||||||
|
const chart = CHARTS[chartName as string] as Record<string, unknown>;
|
||||||
if (!chart) return null;
|
if (!chart) return null;
|
||||||
for (const slice of Object.values(chart.slices)) {
|
for (const slice of Object.values(chart.slices)) {
|
||||||
const filter = slice["filter"];
|
const filter = slice["filter"];
|
||||||
if (store.evaluateExpression(filter, device)) {
|
if (evaluateExpression(filter, device || {})) {
|
||||||
const dot = m(
|
const dot = m(
|
||||||
"svg",
|
"svg",
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
import { ClosureComponent, Component, VnodeDOM } from "mithril";
|
import { ClosureComponent, Component, VnodeDOM } from "mithril";
|
||||||
import { m } from "../components";
|
import { m } from "../components";
|
||||||
|
import { evaluateExpression } from "../store";
|
||||||
|
|
||||||
const component: ClosureComponent = (): Component => {
|
const component: ClosureComponent = (): Component => {
|
||||||
return {
|
return {
|
||||||
@@ -26,12 +27,13 @@ const component: ClosureComponent = (): Component => {
|
|||||||
const device = vnode.attrs["device"];
|
const device = vnode.attrs["device"];
|
||||||
|
|
||||||
const rows = Object.values(vnode.attrs["parameters"]).map((parameter) => {
|
const rows = Object.values(vnode.attrs["parameters"]).map((parameter) => {
|
||||||
|
const type = evaluateExpression(parameter["type"], device);
|
||||||
const p = m.context(
|
const p = m.context(
|
||||||
{
|
{
|
||||||
device: device,
|
device: device,
|
||||||
parameter: parameter["parameter"],
|
parameter: parameter["parameter"],
|
||||||
},
|
},
|
||||||
parameter["type"] || "parameter",
|
(type as string) || "parameter",
|
||||||
parameter
|
parameter
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
import { ClosureComponent, Component } from "mithril";
|
import { ClosureComponent, Component } from "mithril";
|
||||||
import { m } from "../components";
|
import { m } from "../components";
|
||||||
import * as taskQueue from "../task-queue";
|
import * as taskQueue from "../task-queue";
|
||||||
import * as store from "../store";
|
import { evaluateExpression } from "../store";
|
||||||
import * as expressionParser from "../../lib/common/expression-parser";
|
import * as expressionParser from "../../lib/common/expression-parser";
|
||||||
import { getIcon } from "../icons";
|
import { getIcon } from "../icons";
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ const component: ClosureComponent = (): Component => {
|
|||||||
},
|
},
|
||||||
view: (vnode) => {
|
view: (vnode) => {
|
||||||
const device = vnode.attrs["device"];
|
const device = vnode.attrs["device"];
|
||||||
const object = store.evaluateExpression(vnode.state["object"], device);
|
const object = evaluateExpression(vnode.state["object"], device);
|
||||||
const parameters = vnode.state["parameters"];
|
const parameters = vnode.state["parameters"];
|
||||||
|
|
||||||
if (typeof object !== "string" || !device[object]) return null;
|
if (typeof object !== "string" || !device[object]) return null;
|
||||||
@@ -56,8 +56,7 @@ const component: ClosureComponent = (): Component => {
|
|||||||
|
|
||||||
const rows = [];
|
const rows = [];
|
||||||
for (const i of instances) {
|
for (const i of instances) {
|
||||||
let filter =
|
let filter = "filter" in vnode.attrs ? vnode.attrs["filter"] : true;
|
||||||
vnode.attrs["filter"] != null ? vnode.attrs["filter"] : true;
|
|
||||||
|
|
||||||
filter = expressionParser.map(filter, (e) => {
|
filter = expressionParser.map(filter, (e) => {
|
||||||
if (Array.isArray(e) && e[0] === "PARAM")
|
if (Array.isArray(e) && e[0] === "PARAM")
|
||||||
@@ -65,7 +64,7 @@ const component: ClosureComponent = (): Component => {
|
|||||||
return e;
|
return e;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!store.evaluateExpression(filter, device)) continue;
|
if (!evaluateExpression(filter, device)) continue;
|
||||||
|
|
||||||
const row = parameters.map((p) => {
|
const row = parameters.map((p) => {
|
||||||
const param = expressionParser.map(p.parameter, (e) => {
|
const param = expressionParser.map(p.parameter, (e) => {
|
||||||
@@ -147,7 +146,9 @@ const component: ClosureComponent = (): Component => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let label;
|
let label;
|
||||||
if (vnode.attrs["label"]) label = m("h2", vnode.attrs["label"]);
|
|
||||||
|
const l = evaluateExpression(vnode.attrs["label"], device);
|
||||||
|
if (l != null) label = m("h2", l);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
label,
|
label,
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ const component: ClosureComponent = (): Component => {
|
|||||||
|
|
||||||
const { value, timestamp, parameter } = evaluateParam(
|
const { value, timestamp, parameter } = evaluateParam(
|
||||||
vnode.attrs["parameter"],
|
vnode.attrs["parameter"],
|
||||||
vnode.attrs["device"],
|
device,
|
||||||
store.getTimestamp() + store.getClockSkew()
|
store.getTimestamp() + store.getClockSkew()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ const component: ClosureComponent = (): Component => {
|
|||||||
view: (vnode) => {
|
view: (vnode) => {
|
||||||
const device = vnode.attrs["device"];
|
const device = vnode.attrs["device"];
|
||||||
let writable = true;
|
let writable = true;
|
||||||
if (vnode.attrs["writable"] != null) writable = vnode.attrs["writable"];
|
if ("writable" in vnode.attrs)
|
||||||
|
writable = !!store.evaluateExpression(vnode.attrs["writable"], device);
|
||||||
|
|
||||||
const tags = [];
|
const tags = [];
|
||||||
for (const p of Object.keys(device))
|
for (const p of Object.keys(device))
|
||||||
|
|||||||
Reference in new issue
Block a user