Make boolean item property display/edit metadata-driven
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
// Maintainer-controlled web client version.
|
// Maintainer-controlled web client version.
|
||||||
// Format: YYYY.MM.DD Rn (example: 2026.02.20 R2)
|
// Format: YYYY.MM.DD Rn (example: 2026.02.20 R2)
|
||||||
window.CHGRID_WEB_VERSION = "2026.02.25 R272";
|
window.CHGRID_WEB_VERSION = "2026.02.25 R273";
|
||||||
// Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid.
|
// Optional display timezone for timestamps. Falls back to America/Detroit if unset/invalid.
|
||||||
window.CHGRID_TIME_ZONE = "America/Detroit";
|
window.CHGRID_TIME_ZONE = "America/Detroit";
|
||||||
|
|||||||
@@ -117,10 +117,7 @@ export function createItemPropertyEditor(deps: EditorDeps): {
|
|||||||
}
|
}
|
||||||
const metadata = deps.getItemPropertyMetadata(item.type, selectedKey);
|
const metadata = deps.getItemPropertyMetadata(item.type, selectedKey);
|
||||||
if (metadata?.valueType === 'boolean') {
|
if (metadata?.valueType === 'boolean') {
|
||||||
let current = item.params[selectedKey];
|
const current = deps.getItemPropertyValue(item, selectedKey).toLowerCase() === 'on';
|
||||||
if (typeof current !== 'boolean') {
|
|
||||||
current = item.params[selectedKey] === true;
|
|
||||||
}
|
|
||||||
const nextValue = !current;
|
const nextValue = !current;
|
||||||
deps.suppressItemPropertyEchoMs(600);
|
deps.suppressItemPropertyEchoMs(600);
|
||||||
deps.signalingSend({ type: 'item_update', itemId, params: { [selectedKey]: nextValue } });
|
deps.signalingSend({ type: 'item_update', itemId, params: { [selectedKey]: nextValue } });
|
||||||
@@ -169,8 +166,8 @@ export function createItemPropertyEditor(deps: EditorDeps): {
|
|||||||
}
|
}
|
||||||
const metadata = deps.getItemPropertyMetadata(item.type, selectedKey);
|
const metadata = deps.getItemPropertyMetadata(item.type, selectedKey);
|
||||||
if (metadata?.valueType === 'boolean') {
|
if (metadata?.valueType === 'boolean') {
|
||||||
const current = item.params[selectedKey];
|
const current = deps.getItemPropertyValue(item, selectedKey).toLowerCase() === 'on';
|
||||||
const nextValue = typeof current === 'boolean' ? !current : deps.getItemPropertyValue(item, selectedKey).toLowerCase() !== 'on';
|
const nextValue = !current;
|
||||||
deps.signalingSend({ type: 'item_update', itemId, params: { [selectedKey]: nextValue } });
|
deps.signalingSend({ type: 'item_update', itemId, params: { [selectedKey]: nextValue } });
|
||||||
deps.onPreviewPropertyChange?.(item, selectedKey, nextValue);
|
deps.onPreviewPropertyChange?.(item, selectedKey, nextValue);
|
||||||
deps.updateStatus(`${deps.itemPropertyLabel(selectedKey)}: ${nextValue ? 'on' : 'off'}`);
|
deps.updateStatus(`${deps.itemPropertyLabel(selectedKey)}: ${nextValue ? 'on' : 'off'}`);
|
||||||
@@ -188,7 +185,7 @@ export function createItemPropertyEditor(deps: EditorDeps): {
|
|||||||
selectedKey === 'title'
|
selectedKey === 'title'
|
||||||
? item.title
|
? item.title
|
||||||
: selectedMetadata?.valueType === 'boolean'
|
: selectedMetadata?.valueType === 'boolean'
|
||||||
? item.params[selectedKey] === true
|
? deps.getItemPropertyValue(item, selectedKey).toLowerCase() === 'on'
|
||||||
? 'on'
|
? 'on'
|
||||||
: 'off'
|
: 'off'
|
||||||
: String(item.params[selectedKey] ?? '');
|
: String(item.params[selectedKey] ?? '');
|
||||||
|
|||||||
@@ -48,16 +48,7 @@ export function createItemPropertyPresentation(deps: PresentationDeps): {
|
|||||||
if (key === 'capabilities') return item.capabilities.join(', ') || 'none';
|
if (key === 'capabilities') return item.capabilities.join(', ') || 'none';
|
||||||
if (key === 'useSound') return toSoundDisplayName(item.params.useSound ?? item.useSound);
|
if (key === 'useSound') return toSoundDisplayName(item.params.useSound ?? item.useSound);
|
||||||
if (key === 'emitSound') return toSoundDisplayName(item.params.emitSound ?? item.emitSound);
|
if (key === 'emitSound') return toSoundDisplayName(item.params.emitSound ?? item.emitSound);
|
||||||
if (key === 'enabled') return item.params.enabled === false ? 'off' : 'on';
|
|
||||||
if (key === 'directional') {
|
|
||||||
if (typeof item.params.directional === 'boolean') {
|
|
||||||
return item.params.directional ? 'on' : 'off';
|
|
||||||
}
|
|
||||||
return getItemTypeGlobalProperties(item.type).directional === true ? 'on' : 'off';
|
|
||||||
}
|
|
||||||
if (key === 'timeZone') return String(item.params.timeZone ?? getDefaultClockTimeZone());
|
if (key === 'timeZone') return String(item.params.timeZone ?? getDefaultClockTimeZone());
|
||||||
if (key === 'use24Hour') return item.params.use24Hour === true ? 'on' : 'off';
|
|
||||||
if (key === 'topOfHourAnnounce') return item.params.topOfHourAnnounce === true ? 'on' : 'off';
|
|
||||||
if (key === 'mediaChannel') return normalizeRadioChannel(item.params.mediaChannel);
|
if (key === 'mediaChannel') return normalizeRadioChannel(item.params.mediaChannel);
|
||||||
if (key === 'mediaEffect') return normalizeRadioEffect(item.params.mediaEffect);
|
if (key === 'mediaEffect') return normalizeRadioEffect(item.params.mediaEffect);
|
||||||
if (key === 'mediaEffectValue') return String(normalizeRadioEffectValue(item.params.mediaEffectValue));
|
if (key === 'mediaEffectValue') return String(normalizeRadioEffectValue(item.params.mediaEffectValue));
|
||||||
@@ -73,9 +64,18 @@ export function createItemPropertyPresentation(deps: PresentationDeps): {
|
|||||||
if (!Number.isFinite(parsed)) return '15';
|
if (!Number.isFinite(parsed)) return '15';
|
||||||
return String(Math.round(parsed));
|
return String(Math.round(parsed));
|
||||||
}
|
}
|
||||||
const paramValue = item.params[key];
|
const metadata = getItemPropertyMetadata(item.type, key);
|
||||||
if (paramValue !== undefined) return String(paramValue);
|
|
||||||
const globalValue = getItemTypeGlobalProperties(item.type)?.[key];
|
const globalValue = getItemTypeGlobalProperties(item.type)?.[key];
|
||||||
|
const paramValue = item.params[key];
|
||||||
|
const rawValue = paramValue !== undefined ? paramValue : globalValue;
|
||||||
|
if (metadata?.valueType === 'boolean') {
|
||||||
|
if (rawValue === undefined && key === 'enabled') return 'on';
|
||||||
|
return rawValue === true ? 'on' : 'off';
|
||||||
|
}
|
||||||
|
if (metadata?.valueType === 'sound') {
|
||||||
|
return toSoundDisplayName(rawValue);
|
||||||
|
}
|
||||||
|
if (paramValue !== undefined) return String(paramValue);
|
||||||
if (globalValue !== undefined) return String(globalValue);
|
if (globalValue !== undefined) return String(globalValue);
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user