Mercurial > code > home > repos > light9
annotate web/live/Light9DeviceControl.ts @ 2381:3a2e58725037
make bin/* match
author | drewp@bigasterisk.com |
---|---|
date | Sun, 12 May 2024 19:56:25 -0700 |
parents | 4556eebe5d73 |
children |
rev | line source |
---|---|
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
1 import debug from "debug"; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
2 import { css, html, LitElement } from "lit"; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
3 import { customElement, property } from "lit/decorators.js"; |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
4 import { NamedNode } from "n3"; |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
5 import { unique } from "underscore"; |
2372
06bf6dae8e64
reorg tools into light9/web/ and a single vite instance
drewp@bigasterisk.com
parents:
2258
diff
changeset
|
6 import { Patch } from "../patch"; |
06bf6dae8e64
reorg tools into light9/web/ and a single vite instance
drewp@bigasterisk.com
parents:
2258
diff
changeset
|
7 import { getTopGraph } from "../RdfdbSyncedGraph"; |
06bf6dae8e64
reorg tools into light9/web/ and a single vite instance
drewp@bigasterisk.com
parents:
2258
diff
changeset
|
8 import { SyncedGraph } from "../SyncedGraph"; |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
9 import { Choice } from "./Light9Listbox"; |
2246
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
10 import { Light9AttrControl } from "./Light9AttrControl"; |
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
11 import { Effect } from "./Effect"; |
2372
06bf6dae8e64
reorg tools into light9/web/ and a single vite instance
drewp@bigasterisk.com
parents:
2258
diff
changeset
|
12 export { ResourceDisplay } from "../ResourceDisplay"; |
2246
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
13 export { Light9AttrControl }; |
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
14 const log = debug("settings.dev"); |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
15 |
2087 | 16 export interface DeviceAttrRow { |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
17 uri: NamedNode; //devattr |
2246
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
18 device: NamedNode; |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
19 attrClasses: string; // the css kind |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
20 dataType: NamedNode; |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
21 choices: Choice[]; |
2248 | 22 // choiceSize: number; |
23 // max: number; | |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
24 } |
2081
c57cf4049004
dice up the live/ elements and code into ts files (no conversion yet except auto coffee->ts)
drewp@bigasterisk.com
parents:
diff
changeset
|
25 |
2246
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
26 // Widgets for one device with multiple Light9LiveControl rows for the attr(s). |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
27 @customElement("light9-device-control") |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
28 export class Light9DeviceControl extends LitElement { |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
29 graph!: SyncedGraph; |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
30 static styles = [ |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
31 css` |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
32 :host { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
33 display: inline-block; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
34 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
35 .device { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
36 border: 2px solid #151e2d; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
37 margin: 4px; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
38 padding: 1px; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
39 background: #171717; /* deviceClass gradient added later */ |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
40 break-inside: avoid-column; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
41 width: 335px; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
42 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
43 .deviceAttr { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
44 border-top: 1px solid #272727; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
45 padding-bottom: 2px; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
46 display: flex; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
47 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
48 .deviceAttr > span { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
49 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
50 .deviceAttr > light9-live-control { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
51 flex-grow: 1; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
52 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
53 h2 { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
54 font-size: 110%; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
55 padding: 4px; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
56 margin-top: 0; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
57 margin-bottom: 0; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
58 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
59 .device, |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
60 h2 { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
61 border-top-right-radius: 15px; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
62 } |
2081
c57cf4049004
dice up the live/ elements and code into ts files (no conversion yet except auto coffee->ts)
drewp@bigasterisk.com
parents:
diff
changeset
|
63 |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
64 #mainLabel { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
65 font-size: 120%; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
66 color: #9ab8fd; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
67 text-decoration: initial; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
68 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
69 .device.selected h2 { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
70 outline: 3px solid #ffff0047; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
71 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
72 .deviceAttr.selected { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
73 background: #cada1829; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
74 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
75 `, |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
76 ]; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
77 |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
78 render() { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
79 return html` |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
80 <div class="device ${this.devClasses}"> |
2248 | 81 <h2 style="${this._bgStyle(this.deviceClass)}" @click=${this.onClick}> |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
82 <resource-display id="mainLabel" .uri="${this.uri}"></resource-display> |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
83 a <resource-display minor .uri="${this.deviceClass}"></resource-display> |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
84 </h2> |
2238 | 85 |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
86 ${this.deviceAttrs.map( |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
87 (dattr: DeviceAttrRow) => html` |
2238 | 88 <div @click="onAttrClick" class="deviceAttr ${dattr.attrClasses}"> |
2246
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
89 <span> |
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
90 attr |
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
91 <resource-display minor .uri=${dattr.uri}></resource-display> |
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
92 </span> |
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
93 <light9-attr-control .deviceAttrRow=${dattr} .effect=${this.effect}> |
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
94 </light9-attr-control> |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
95 </div> |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
96 ` |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
97 )} |
2081
c57cf4049004
dice up the live/ elements and code into ts files (no conversion yet except auto coffee->ts)
drewp@bigasterisk.com
parents:
diff
changeset
|
98 </div> |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
99 `; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
100 } |
2081
c57cf4049004
dice up the live/ elements and code into ts files (no conversion yet except auto coffee->ts)
drewp@bigasterisk.com
parents:
diff
changeset
|
101 |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
102 @property() uri!: NamedNode; |
2246
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
103 @property() effect!: Effect; |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
104 |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
105 @property() devClasses: string = ""; // the css kind |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
106 @property() deviceAttrs: DeviceAttrRow[] = []; |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
107 @property() deviceClass: NamedNode | null = null; |
2087 | 108 @property() selectedAttrs: Set<NamedNode> = new Set(); |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
109 |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
110 constructor() { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
111 super(); |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
112 getTopGraph().then((g) => { |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
113 this.graph = g; |
2087 | 114 this.graph.runHandler(this.syncDeviceAttrsFromGraph.bind(this), `${this.uri.value} update`); |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
115 }); |
2087 | 116 this.selectedAttrs = new Set(); |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
117 } |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
118 |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
119 _bgStyle(deviceClass: NamedNode | null): string { |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
120 if (!deviceClass) return ""; |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
121 let hash = 0; |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
122 const u = deviceClass.value; |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
123 for (let i = u.length - 10; i < u.length; i++) { |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
124 hash += u.charCodeAt(i); |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
125 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
126 const hue = (hash * 8) % 360; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
127 const accent = `hsl(${hue}, 49%, 22%)`; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
128 return `background: linear-gradient(to right, rgba(31,31,31,0) 50%, ${accent} 100%);`; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
129 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
130 |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
131 setDeviceSelected(isSel: any) { |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
132 this.devClasses = isSel ? "selected" : ""; |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
133 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
134 |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
135 setAttrSelected(devAttr: NamedNode, isSel: boolean) { |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
136 if (isSel) { |
2087 | 137 this.selectedAttrs.add(devAttr); |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
138 } else { |
2087 | 139 this.selectedAttrs.delete(devAttr); |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
140 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
141 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
142 |
2087 | 143 syncDeviceAttrsFromGraph(patch?: Patch) { |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
144 const U = this.graph.U(); |
2258 | 145 if (patch && !patch.containsAnyPreds([U("rdf:type"), U(":deviceAttr"), U(":dataType"), U(":choice")])) { |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
146 return; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
147 } |
2087 | 148 try { |
2246
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
149 this.deviceClass = this.graph.uriValue(this.uri, U("rdf:type")); |
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
150 } catch (e) { |
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
151 // what's likely is we're going through a graph reload and the graph |
2087 | 152 // is gone but the controls remain |
153 } | |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
154 this.deviceAttrs = []; |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
155 Array.from(unique(this.graph.sortedUris(this.graph.objects(this.deviceClass, U(":deviceAttr"))))).map((da: NamedNode) => |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
156 this.deviceAttrs.push(this.attrRow(da)) |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
157 ); |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
158 this.requestUpdate(); |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
159 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
160 |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
161 attrRow(devAttr: NamedNode): DeviceAttrRow { |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
162 let x: NamedNode; |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
163 const U = (x: string) => this.graph.Uri(x); |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
164 const dataType = this.graph.uriValue(devAttr, U(":dataType")); |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
165 const daRow = { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
166 uri: devAttr, |
2246
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
167 device: this.uri, |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
168 dataType, |
2087 | 169 attrClasses: this.selectedAttrs.has(devAttr) ? "selected" : "", |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
170 choices: [] as Choice[], |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
171 choiceSize: 0, |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
172 max: 1, |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
173 }; |
2248 | 174 if (dataType.equals(U(":choice"))) { |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
175 const choiceUris = this.graph.sortedUris(this.graph.objects(devAttr, U(":choice"))); |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
176 daRow.choices = (() => { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
177 const result = []; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
178 for (x of Array.from(choiceUris)) { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
179 result.push({ uri: x.value, label: this.graph.labelOrTail(x) }); |
2081
c57cf4049004
dice up the live/ elements and code into ts files (no conversion yet except auto coffee->ts)
drewp@bigasterisk.com
parents:
diff
changeset
|
180 } |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
181 return result; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
182 })(); |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
183 daRow.choiceSize = Math.min(choiceUris.length + 1, 10); |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
184 } else { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
185 daRow.max = 1; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
186 if (dataType.equals(U(":angle"))) { |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
187 // varies |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
188 daRow.max = 1; |
2081
c57cf4049004
dice up the live/ elements and code into ts files (no conversion yet except auto coffee->ts)
drewp@bigasterisk.com
parents:
diff
changeset
|
189 } |
c57cf4049004
dice up the live/ elements and code into ts files (no conversion yet except auto coffee->ts)
drewp@bigasterisk.com
parents:
diff
changeset
|
190 } |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
191 return daRow; |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
192 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
193 |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
194 clear() { |
2087 | 195 // why can't we just set their values ? what's diff about |
196 // the clear state, and should it be represented with `null` value? | |
2246
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
197 throw new Error(); |
5c269c03863d
WIP device settings page can now load and save ok. Omitted GraphToControls for now
drewp@bigasterisk.com
parents:
2238
diff
changeset
|
198 // Array.from(this.shadowRoot!.querySelectorAll("light9-live-control")).map((lc: Element) => (lc as Light9LiveControl).clear()); |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
199 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
200 |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
201 onClick(ev: any) { |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
202 log("click", this.uri); |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
203 // select, etc |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
204 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
205 |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
206 onAttrClick(ev: { model: { dattr: { uri: any } } }) { |
2084
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
207 log("attr click", this.uri, ev.model.dattr.uri); |
c4eab47d3c83
WIP half-ported live/ page to working TS
drewp@bigasterisk.com
parents:
2083
diff
changeset
|
208 // select |
2083
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
209 } |
ad7ab7027907
clean up non-elements; get the lit elements at least to work with autoformat
drewp@bigasterisk.com
parents:
2081
diff
changeset
|
210 } |