From dc822cab9b81ad84be3dfd25d80c455b44832d9c Mon Sep 17 00:00:00 2001 From: Zaid Abdulla Date: Wed, 3 Oct 2018 18:47:08 -0700 Subject: [PATCH] Make serial in device list into a link --- client/components.js | 2 ++ client/components/device-link.js | 29 +++++++++++++++++++++++++++++ config.json | 8 +++++++- 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 client/components/device-link.js diff --git a/client/components.js b/client/components.js index 458ed66..492fa92 100644 --- a/client/components.js +++ b/client/components.js @@ -11,6 +11,7 @@ import allParameters from "./components/all-parameters"; import deviceActions from "./components/device-actions"; import tags from "./components/tags"; import ping from "./components/ping"; +import deviceLink from "./components/device-link"; function get(name) { if (name === "parameter") return parameter; @@ -24,6 +25,7 @@ function get(name) { else if (name === "device-actions") return deviceActions; else if (name === "tags") return tags; else if (name === "ping") return ping; + else if (name === "device-link") return deviceLink; else throw new Error(`No such component '${name}'`); } diff --git a/client/components/device-link.js b/client/components/device-link.js new file mode 100644 index 0000000..6cf9f76 --- /dev/null +++ b/client/components/device-link.js @@ -0,0 +1,29 @@ +"use strict"; + +import m from "mithril"; +import * as components from "../components"; + +const component = { + view: vnode => { + let deviceId; + if (vnode.attrs.device) + deviceId = vnode.attrs.device["DeviceID.ID"].value[0]; + + 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); + }); + if (deviceId) { + return m( + "a", + { href: `#!/devices/${encodeURIComponent(deviceId)}` }, + children + ); + } else { + return children; + } + } +}; + +export default component; diff --git a/config.json b/config.json index 7d09554..4a7bc42 100644 --- a/config.json +++ b/config.json @@ -107,7 +107,13 @@ "index": [ { "label": "Serial number", - "parameter": "DeviceID.SerialNumber" + "parameter": "DeviceID.SerialNumber", + "type": "device-link", + "components": [ + { + "type": "parameter" + } + ] }, { "label": "Product class",