# HG changeset patch
# User drewp@bigasterisk.com
# Date 2022-05-21 22:54:35
# Node ID 6fbc1853c0b1679488141868d182ebcde23d0559
# Parent 412f798baf0cbca0701465e332ed50c010de84e3
split collector elements to ts files, minor porting
diff --git a/light9/collector/web/Light9CollectorDevice.ts b/light9/collector/web/Light9CollectorDevice.ts
new file mode 100644
--- /dev/null
+++ b/light9/collector/web/Light9CollectorDevice.ts
@@ -0,0 +1,71 @@
+import * as debug from "debug";
+import { css, html, LitElement } from "lit";
+import { customElement, property } from "lit/decorators.js";
+debug.enable("*");
+
+@customElement("light9-collector-device")
+export class Light9CollectorDevice extends LitElement {
+ static styles = [
+ css`
+ :host {
+ display: block;
+ break-inside: avoid-column;
+ font-size: 80%;
+ }
+ h3 {
+ margin-top: 12px;
+ margin-bottom: 0;
+ }
+ td {
+ white-space: nowrap;
+ }
+
+ td.nonzero {
+ background: #310202;
+ color: #e25757;
+ }
+ td.full {
+ background: #2b0000;
+ color: red;
+ font-weight: bold;
+ }
+ `,
+ ];
+
+ render() {
+ return html`
+
+
+
+ out attr |
+ value |
+ chan |
+
+
+
+ {{item.attr}} |
+ {{item.val}} → |
+ {{item.chan}} |
+
+
+
+ `;
+ }
+ @property() graph: Object = {};
+ @property() uri: Object = {};
+ @property() attrs: Array = [];
+
+ // observers: [
+ // "initUpdates(updates)",
+ // ],
+ initUpdates(updates) {
+ updates.addListener(function (msg) {
+ if (msg.outputAttrsSet && msg.outputAttrsSet.dev == this.uri.value) {
+ this.set("attrs", msg.outputAttrsSet.attrs);
+ this.attrs.forEach(function (row) {
+ row.valClass = row.val == 255 ? "full" : row.val ? "nonzero" : "";
+ });
+ }
+ });
+ }
+}
diff --git a/light9/collector/web/Light9CollectorUi.ts b/light9/collector/web/Light9CollectorUi.ts
new file mode 100644
--- /dev/null
+++ b/light9/collector/web/Light9CollectorUi.ts
@@ -0,0 +1,73 @@
+import { sortBy, uniq } from "underscore";
+import * as debug from "debug";
+import { html, LitElement } from "lit";
+import { customElement, property } from "lit/decorators.js";
+debug.enable("*");
+
+class Updates {
+ constructor() {
+ this.listeners = [];
+ }
+ addListener(cb) {
+ this.listeners.push(cb);
+ }
+ onMessage(msg) {
+ this.listeners.forEach(function (lis) {
+ lis(msg);
+ });
+ }
+}
+
+@customElement("light9-collector-ui")
+export class Light9CollectorUi extends LitElement {
+ static styles = [];
+ render() {
+ return html`
+
+
+
+
+ Devices
+
+
+
+
+
+ `;
+ }
+
+ @property() graph: Object = {};
+ @property() updates: Object = {};
+ @property() devices: Array = [];
+ // observers: [
+ // 'onGraph(graph)',
+ // ],
+
+ ready() {
+ this.updates = new Updates();
+ reconnectingWebSocket(
+ "updates",
+ function (msg) {
+ this.updates.onMessage(msg);
+ }.bind(this)
+ );
+ }
+
+ onGraph(graph) {
+ this.graph.runHandler(this.findDevices.bind(this), "findDevices");
+ }
+
+ findDevices() {
+ var U = function (x) {
+ return this.graph.Uri(x);
+ };
+ this.set("devices", []);
+
+ let classes = this.graph.subjects(U("rdf:type"), U(":DeviceClass"));
+ uniq(sortBy(classes, "value"), true).forEach((dc) => {
+ sortBy(this.graph.subjects(U("rdf:type"), dc), "value").forEach((dev) => {
+ this.push("devices", dev);
+ });
+ });
+ }
+}
diff --git a/light9/collector/web/index.html b/light9/collector/web/index.html
--- a/light9/collector/web/index.html
+++ b/light9/collector/web/index.html
@@ -1,167 +1,19 @@
-
+
collector
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
-
-
-
-
-
-
-
- out attr |
- value |
- chan |
-
-
-
- {{item.attr}} |
- {{item.val}} → |
- {{item.chan}} |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Devices
-
-
-
-
-
-
-
-
-
-
+