# HG changeset patch # User drewp@bigasterisk.com # Date 2023-05-27 09:05:27 # Node ID 75dfd7eb1e77714e9409d5623798e34e66b1f4fe # Parent f5e4aa36985d4371e7a48021f5adaf0acd48e838 clean up. still seems to work diff --git a/light9/live/Effect.ts b/light9/live/Effect.ts --- a/light9/live/Effect.ts +++ b/light9/live/Effect.ts @@ -31,13 +31,11 @@ function valuePred(graph: SyncedGraph, a // effect settings data; r/w sync with the graph export class Effect { private settings: Array<{ device: NamedNode; deviceAttr: NamedNode; setting: NamedNode; value: ControlValue }> = []; - private ctxForEffect: NamedNode - settingsChanged:SubEvent=new SubEvent() + private ctxForEffect: NamedNode; + settingsChanged: SubEvent = new SubEvent(); constructor( public graph: SyncedGraph, - public uri: NamedNode, - // called if the graph changes our values and not when the caller uses edit() - // private onValuesChanged: (values: void) => void + public uri: NamedNode // called if the graph changes our values and not when the caller uses edit() ) { this.ctxForEffect = this.graph.Uri(this.uri.value.replace("light9.bigasterisk.com/effect", `light9.bigasterisk.com/show/${shortShow}/effect`)); graph.runHandler(this.rebuildSettingsFromGraph.bind(this), `effect sync ${uri.value}`); @@ -65,15 +63,13 @@ export class Effect { // return; } - log("syncFromGraph", this.uri); + // log("syncFromGraph", this.uri); // this repeats work- it gathers all settings when really some values changed (and we might even know about them). maybe push the value-fetching into a secnod phase of the run, and have the 1st phase drop out early const newSettings = []; - const seenDevAttrPairs: Set = new Set(); - for (let setting of Array.from(this.graph.objects(this.uri, U(":setting")))) { - log(` setting ${setting.value}`); + // log(` setting ${setting.value}`); if (!isUri(setting)) throw new Error(); let value: ControlValue; const device = this.graph.uriValue(setting, U(":device")); @@ -96,10 +92,9 @@ export class Effect { newSettings.push({ device, deviceAttr, setting, value }); } - log(newSettings) this.settings = newSettings; log(`rebuild to ${this.settings.length}`); - this.settingsChanged.emit() + this.settingsChanged.emit(); // maybe one emitter per dev+attr? // this.onValuesChanged(); } @@ -122,7 +117,7 @@ export class Effect { if (existingSetting !== null) { // this is corrupt. There was only supposed to be one setting per (dev,attr) pair. But we can fix it because we're going to update existingSetting to the user's requested value. log(`${this.uri.value} had two settings for ${device.value} - ${deviceAttr.value} - deleting ${s.setting}`); - patchUpdate(result, this._removeEffectSetting(s.setting)); + patchUpdate(result, this._removeEffectSetting(s.setting)); } existingSetting = s.setting; } diff --git a/light9/live/Light9AttrControl.ts b/light9/live/Light9AttrControl.ts --- a/light9/live/Light9AttrControl.ts +++ b/light9/live/Light9AttrControl.ts @@ -3,15 +3,13 @@ import { css, html, LitElement, Property import { customElement, property, state } from "lit/decorators.js"; import { Literal, NamedNode } from "n3"; import { SubEvent } from "sub-events"; +import { getTopGraph } from "../web/RdfdbSyncedGraph"; import { SyncedGraph } from "../web/SyncedGraph"; import { ControlValue, Effect } from "./Effect"; -import { GraphToControls } from "./GraphToControls"; import { DeviceAttrRow } from "./Light9DeviceControl"; -import { Choice } from "./Light9Listbox"; -import { getTopGraph } from "../web/RdfdbSyncedGraph"; export { Slider } from "@material/mwc-slider"; export { Light9ColorPicker } from "../web/light9-color-picker"; - +export { Light9Listbox } from "./Light9Listbox"; const log = debug("settings.dev.attr"); type DataTypeNames = "scalar" | "color" | "choice"; @@ -32,7 +30,6 @@ export class Light9AttrControl extends L margin: 0 3px; } :host { - border: 2px solid white; } mwc-slider { width: 250px; @@ -42,70 +39,46 @@ export class Light9AttrControl extends L @property() deviceAttrRow: DeviceAttrRow | null = null; @state() dataType: DataTypeNames = "scalar"; - @property() effect: Effect | null = null; - // we'll connect to this and receive graphValueChanged and send uiValueChanged - // @property() graphToControls!: GraphToControls; - @property() enableChange: boolean = false; @property() value: ControlValue | null = null; // e.g. color string - // slider mode - // @property() sliderValue: number = 0; - - // color mode - - // choice mode - // @property() pickedChoice: Choice | null = null; - // @property() choiceValue: Choice | null = null; - - valueChanged: SubEvent = new SubEvent(); - constructor() { super(); getTopGraph().then((g) => { this.graph = g; if (this.deviceAttrRow === null) throw new Error(); - // this.graph.runHandler(this.graphReads.bind(this), `${this.deviceAttrRow.device} ${this.deviceAttrRow.uri} reads`); }); } connectedCallback(): void { super.connectedCallback(); + setTimeout(() => { + // only needed once per page layout + this.shadowRoot?.querySelector("mwc-slider")?.layout(/*skipUpdateUI=*/ false); + }, 1); } render() { if (this.deviceAttrRow === null) throw new Error(); - const dbg = html` live-control ${this.dataType} ]`; if (this.dataType == "scalar") { const v = this.value || 0; - return html`${dbg} `; + return html` `; } else if ((this.dataType = "color")) { - const v = this.value || '#000' + const v = this.value || "#000"; return html` - ${dbg}
- - + +
`; } else if (this.dataType == "choice") { - return html`${dbg} `; + return html` `; } } - // graphReads() { - // if (this.deviceAttrRow === null) throw new Error(); - // const U = this.graph.U(); - // this.effect?.currentValue(this.deviceAttrRow.device, this.deviceAttrRow.uri); - // } - updated(changedProperties: PropertyValues) { super.updated(changedProperties); - // if (changedProperties.has("graphToControls")) { - // // this.graphToControls.register(this.device, this.deviceAttrRow.uri, this.onGraphValueChanged.bind(this)); - // this.enableChange = true; - // } if (changedProperties.has("deviceAttrRow")) { this.onDeviceAttrRowProperty(); @@ -122,8 +95,8 @@ export class Light9AttrControl extends L if (this.deviceAttrRow === null) throw new Error(); if (this.effect !== null && this.graph !== undefined) { const p = this.effect.edit(this.deviceAttrRow.device, this.deviceAttrRow.uri, this.value); - log("patch", p, "to", this.graph); if (p.adds.length || p.dels.length) { + log("Effect told us to graph.patch", p, "to", this.graph); this.graph.applyAndSendPatch(p); } } @@ -139,12 +112,11 @@ export class Light9AttrControl extends L } private effectSettingsChanged() { - // anything in the settings graph is new - log("i check the effect current value"); + // something in the settings graph is new if (this.deviceAttrRow === null) throw new Error(); if (this.effect === null) throw new Error(); - log("graph->ui on ", this.deviceAttrRow.device, this.deviceAttrRow.uri); - const v=this.effect.currentValue(this.deviceAttrRow.device, this.deviceAttrRow.uri); + // log("graph->ui on ", this.deviceAttrRow.device, this.deviceAttrRow.uri); + const v = this.effect.currentValue(this.deviceAttrRow.device, this.deviceAttrRow.uri); this.onGraphValueChanged(v); } @@ -160,7 +132,7 @@ export class Light9AttrControl extends L } } - onSliderInput(ev: CustomEvent) { + onValueInput(ev: CustomEvent) { if (ev.detail === undefined) { // not sure what this is, but it seems to be followed by good events return; @@ -170,50 +142,19 @@ export class Light9AttrControl extends L // this.graphToControls.controlChanged(this.device, this.deviceAttrRow.uri, ev.detail.value); } -onColorInput(ev: CustomEvent) { - this.value = ev.detail.value; -} - onGraphValueChanged(v: ControlValue | null) { if (this.deviceAttrRow === null) throw new Error(); - log("change: control must display", v, "for", this.deviceAttrRow.device.value, this.deviceAttrRow.uri.value); + // log("change: control must display", v, "for", this.deviceAttrRow.device.value, this.deviceAttrRow.uri.value); // this.enableChange = false; if (this.dataType == "scalar") { if (v !== null) { - setTimeout(() => { - // only needed once per page layout - this.shadowRoot?.querySelector("mwc-slider")?.layout(/*skipUpdateUI=*/ false); - }, 1); this.value = v; } else { - this.value = 0; + this.value = 0; } } else if (this.dataType == "color") { - log('graph sets coolor', v) - this.value=v; + this.value = v; } - // if (v === null) { - // this.clear(); - // } else { - // this.value = v; - // } - // if (this.deviceAttrRow.useChoice) { - // this.choiceValue = v === null ? v : v.value; - // } - // this.enableChange = true; - } - - graphToColor(v: ControlValue | null) { - this.value = v === null ? "#000" : v; - return; - // const cp = this.shadowRoot?.querySelector("light9-color-picker") as Light9ColorPicker | null; - // if (cp) { - // if (typeof v != "string") throw new Error("type v is " + typeof v); - // if (v === null) { - // v = "#000"; - // } - // cp.setColor(v as string); - // } } goBlack() { @@ -221,21 +162,14 @@ onColorInput(ev: CustomEvent) { } onChoice(value: any) { - // if (this.graphToControls == null || !this.enableChange) { - // return; - // } // if (value != null) { // value = this.graph.Uri(value); // } else { // value = null; // } - // this.graphToControls.controlChanged(this.device, this.deviceAttrRow.uri, value); } onChange(value: any) { - // if (this.graphToControls == null || !this.enableChange) { - // return; - // } // if (typeof value === "number" && isNaN(value)) { // return; // } // let onChoice do it @@ -243,18 +177,5 @@ onColorInput(ev: CustomEvent) { // if (value === undefined) { // value = null; // } - // this.graphToControls.controlChanged(this.device, this.deviceAttrRow.uri, value); } - - // clear() { - // this.pickedChoice = null; - // this.sliderWriteValue = 0; - // if (this.deviceAttrRow.useColor) { - // return (this.value = "#000000"); - // } else if (this.deviceAttrRow.useChoice) { - // return (this.value = this.pickedChoice = null); - // } else { - // return (this.value = this.sliderValue = 0); - // } - // } } diff --git a/light9/live/Light9DeviceControl.ts b/light9/live/Light9DeviceControl.ts --- a/light9/live/Light9DeviceControl.ts +++ b/light9/live/Light9DeviceControl.ts @@ -6,7 +6,6 @@ import { unique } from "underscore"; import { Patch, patchContainsPreds } from "../web/patch"; import { getTopGraph } from "../web/RdfdbSyncedGraph"; import { SyncedGraph } from "../web/SyncedGraph"; -import { GraphToControls } from "./GraphToControls"; import { Choice } from "./Light9Listbox"; import { Light9AttrControl } from "./Light9AttrControl"; import { Effect } from "./Effect"; @@ -19,13 +18,9 @@ export interface DeviceAttrRow { device: NamedNode; attrClasses: string; // the css kind dataType: NamedNode; - showColorPicker: boolean; - useColor: boolean; - useChoice: boolean; choices: Choice[]; - choiceSize: number; - useSlider: boolean; - max: number; + // choiceSize: number; + // max: number; } // Widgets for one device with multiple Light9LiveControl rows for the attr(s). @@ -83,7 +78,7 @@ export class Light9DeviceControl extends render() { return html`
-

+

a

@@ -96,7 +91,6 @@ export class Light9DeviceControl extends - .graphToControls={this.graphToControls}
` @@ -107,7 +101,6 @@ export class Light9DeviceControl extends @property() uri!: NamedNode; @property() effect!: Effect; - // @property() graphToControls!: GraphToControls; @property() devClasses: string = ""; // the css kind @property() deviceAttrs: DeviceAttrRow[] = []; @@ -145,7 +138,6 @@ export class Light9DeviceControl extends } else { this.selectedAttrs.delete(devAttr); } - // this.syncDeviceAttrsFromGraph(); } syncDeviceAttrsFromGraph(patch?: Patch) { @@ -174,19 +166,12 @@ export class Light9DeviceControl extends uri: devAttr, device: this.uri, dataType, - showColorPicker: dataType.equals(U(":color")), attrClasses: this.selectedAttrs.has(devAttr) ? "selected" : "", - useColor: false, - useChoice: false, choices: [] as Choice[], choiceSize: 0, - useSlider: false, max: 1, }; - if (dataType.equals(U(":color"))) { - daRow.useColor = true; - } else if (dataType.equals(U(":choice"))) { - daRow.useChoice = true; + if (dataType.equals(U(":choice"))) { const choiceUris = this.graph.sortedUris(this.graph.objects(devAttr, U(":choice"))); daRow.choices = (() => { const result = []; @@ -197,7 +182,6 @@ export class Light9DeviceControl extends })(); daRow.choiceSize = Math.min(choiceUris.length + 1, 10); } else { - daRow.useSlider = true; daRow.max = 1; if (dataType.equals(U(":angle"))) { // varies diff --git a/light9/live/Light9DeviceSettings.ts b/light9/live/Light9DeviceSettings.ts --- a/light9/live/Light9DeviceSettings.ts +++ b/light9/live/Light9DeviceSettings.ts @@ -3,10 +3,9 @@ import { css, html, LitElement, Property import { customElement, property } from "lit/decorators.js"; import { NamedNode } from "n3"; import { sortBy, uniq } from "underscore"; -import { Patch, patchContainsPreds } from "../web/patch"; +import { Patch } from "../web/patch"; import { getTopGraph } from "../web/RdfdbSyncedGraph"; import { SyncedGraph } from "../web/SyncedGraph"; -import { GraphToControls } from "./GraphToControls"; import { Effect } from "./Effect"; export { EditChoice } from "../web/EditChoice"; export { Light9DeviceControl as Light9LiveDeviceControl } from "./Light9DeviceControl"; @@ -32,10 +31,11 @@ export class Light9DeviceSettings extend overflow-y: auto; } - light9-live-device-control > div { + light9-device-control > div { break-inside: avoid-column; } - light9-live-device-control { + light9-device-control { + vertical-align: top; } `, ]; @@ -65,10 +65,7 @@ export class Light9DeviceSettings extend } devices: Array = []; - // uri of the effect being edited, or null. This is the - // master value; GraphToControls follows. @property() currentEffect: Effect | null = null; - // graphToControls!: GraphToControls; okToWriteUrl: boolean = false; constructor() { @@ -77,11 +74,10 @@ export class Light9DeviceSettings extend getTopGraph().then((g) => { this.graph = g; this.graph.runHandler(this.findDevices.bind(this), "findDevices"); - // this.graphToControls = new GraphToControls(this.graph); - // this.graph.runHandler(this.update.bind(this), "Light9LiveControls update"); this.setEffectFromUrl(); }); } + onEffectChoice2(ev: CustomEvent) { const uri = ev.detail.newValue as NamedNode; if (uri === null) { @@ -90,17 +86,18 @@ export class Light9DeviceSettings extend this.currentEffect = new Effect(this.graph, uri); } } + updated(changedProperties: PropertyValues) { log("ctls udpated", changedProperties); if (changedProperties.has("currentEffect")) { log(`effectChoice to ${this.currentEffect?.uri?.value}`); - this.onEffectChoice(); + this.writeToUrl(this.currentEffect?.uri); } // this.graphToControls?.debugDump(); } // Note that this doesn't fetch setting values, so it only should get rerun - // upon (rarer) changes to the devices etc. + // upon (rarer) changes to the devices etc. todo: make that be true findDevices(patch?: Patch) { const U = this.graph.U(); // if (patch && !patchContainsPreds(patch, [U("rdf:type")])) { @@ -112,7 +109,6 @@ export class Light9DeviceSettings extend log(`found ${classes.length} device classes`); uniq(sortBy(classes, "value"), true).forEach((dc) => { sortBy(this.graph.subjects(U("rdf:type"), dc), "value").forEach((dev) => { - log(`found dev ${dev.value}`); this.devices.push(dev as NamedNode); }); }); @@ -124,7 +120,6 @@ export class Light9DeviceSettings extend // the url when the page loads. const effect = new URL(window.location.href).searchParams.get("effect"); if (effect != null) { - log(`found effect in url ${effect}`); this.currentEffect = new Effect(this.graph, this.graph.Uri(effect)); } this.okToWriteUrl = true; @@ -148,61 +143,8 @@ export class Light9DeviceSettings extend // this.effectChoice = this.graphToControls.newEffect(); } - onEffectChoice() { - const U = (x: any) => this.graph.Uri(x); - // if (this.effectChoice == null) { - // // unlink - // log("onEffectChoice unlink"); - // if (this.graphToControls != null) { - // this.graphToControls.setEffect(null); - // } - // } else { - // if (this.graphToControls != null) { - // this.graphToControls.setEffect(this.effectChoice); - // } else { - // throw new Error("graphToControls not set"); - // } - // } - this.writeToUrl(this.currentEffect?.uri); - } - clearAll() { // clears the effect! return; //this.graphToControls.emptyEffect(); } - - // configureFromGraph() { - // const U = (x: string) => this.graph.Uri(x); - - // const newDevs: NamedNode[] = []; - // for (let dc of Array.from(this.graph.sortedUris(this.graph.subjects(U("rdf:type"), U(":DeviceClass"))))) { - // for (let dev of Array.from(this.graph.sortedUris(this.graph.subjects(U("rdf:type"), dc)))) { - // if (this.graph.contains(dev, U(":hideInLiveUi"), null)) { - // continue; - // } - // if (newDevs.length == 0) newDevs.push(dev); - // } - // } - // log("is this called?"); - // log(`controls update now has ${newDevs.length} devices`); - // this.devices = newDevs; - // this.requestUpdate(); - - // return; - - // // Tried css columns- big slowdown from relayout as I'm scrolling. - // // Tried isotope- seems to only scroll to the right. - // // Tried columnize- fails in jquery maybe from weird elements. - - // // not sure how to get this run after the children are created - // return setTimeout( - // () => - // $("#deviceControls").isotope({ - // // fitColumns would be nice, but it doesn't scroll vertically - // layoutMode: "masonry", - // containerStyle: null, - // }), - // 2000 - // ); - // } }