Merge branch 'verify-ui-elements' into 'v3'

Verify properties and actions exist before making controls and buttons.

Closes #640

See merge request openflexure/openflexure-microscope-server!556
This commit is contained in:
Joe Knapper 2026-05-15 15:11:52 +00:00
commit 336e052fce
6 changed files with 57 additions and 3 deletions

View file

@ -214,6 +214,9 @@ class ActionButton(BaseModel):
Downstream components can subscribe to this and request an update.
"""
broken: bool = False
"""If True the action button is broken. There is no corresponding action."""
def action_button_for(thing: lt.Thing, action_name: str, **kwargs: Any) -> ActionButton:
"""Create a ActionButton data for the specified Thing Action.
@ -224,6 +227,9 @@ def action_button_for(thing: lt.Thing, action_name: str, **kwargs: Any) -> Actio
:return: An ActionButton (Pydantic Model) object with all the information the
webapp needs to create the action button.
"""
if action_name not in thing.actions:
thing.logger.error(f"{thing.name} has no action {action_name}")
kwargs["broken"] = True
return ActionButton(thing=thing.name, action=action_name, **kwargs)
@ -270,6 +276,9 @@ class PropertyControl(BaseModel):
used.
"""
broken: bool = False
"""If True the property control is broken. There is no corresponding property."""
def property_control_for(
thing: lt.Thing, property_name: str, **kwargs: Any
@ -283,6 +292,9 @@ def property_control_for(
"""
if "label" not in kwargs:
kwargs["label"] = property_name
if property_name not in thing.properties:
thing.logger.error(f"{thing.name} has no property {property_name}")
kwargs["broken"] = True
return PropertyControl(thing=thing.name, property_name=property_name, **kwargs)

View file

@ -387,4 +387,16 @@ html {
padding: 0;
height: 100%;
}
.ui-element-error-icon {
vertical-align: middle;
padding-right: 10px;
color: #a00;
}
.ui-element-broken {
border-color: #a00 !important;
color: #a00 !important;
cursor: not-allowed;
}
</style>

View file

@ -3,13 +3,15 @@
<button
ref="actionButton"
type="button"
:title="tooltipText"
:disabled="buttonDisabled"
class="uk-button uk-width-1-1 uk-position-relative"
:class="buttonClasses"
@click="handleClick"
>
<action-progress-bar :progress="progress" :task-status="taskStatus" :in-button="true" />
{{ buttonLabel }}
<span v-if="isBroken" class="material-symbols-outlined ui-element-error-icon"> error </span
>{{ buttonLabel }}
</button>
<action-status-modal
@ -112,6 +114,11 @@ export default {
required: false,
default: false,
},
isBroken: {
type: Boolean,
required: false,
default: false,
},
streamWithModal: {
type: Boolean,
required: false,
@ -148,7 +155,7 @@ export default {
computed: {
buttonDisabled() {
return this.isDisabled || (this.taskRunning && !this.canTerminate);
return this.isDisabled || this.isBroken || (this.taskRunning && !this.canTerminate);
},
buttonLabel() {
return this.taskRunning && this.canTerminate ? "Cancel" : this.submitLabel;
@ -158,6 +165,9 @@ export default {
if (this.buttonDisabled) {
classes.push("uk-button-disabled");
}
if (this.isBroken) {
classes.push("ui-element-broken");
}
if (this.taskRunning && this.canTerminate) {
classes.push("uk-button-danger");
} else if (this.buttonPrimary) {
@ -167,6 +177,9 @@ export default {
}
return classes.join(" ");
},
tooltipText() {
return this.isBroken ? `${this.thing} has no action "${this.action}".` : "";
},
},
watch: {
@ -232,7 +245,7 @@ export default {
methods: {
handleShortcutTrigger() {
if (this.isDisabled) return;
if (this.isDisabled || this.isBroken) return;
this.bootstrapTask();
},
handleClick() {
@ -257,6 +270,7 @@ export default {
*
*/
async checkExistingTasks() {
if (this.isBroken) return;
const ongoingTask = await this.getOngoingAction(this.thing, this.action);
if (ongoingTask) {
// There is a started task

View file

@ -1,5 +1,6 @@
<template>
<input-from-schema
v-if="!isBroken"
v-model="modelValue"
:data-schema="propertyDescription"
:label="label"
@ -10,6 +11,13 @@
@send-value="writeProperty"
@animation-shown="resetAnimate"
/>
<div
v-else
class="ui-element-broken"
:title="`${thingName} has no property &quot;${propertyName}&quot;.`"
>
<span class="material-symbols-outlined ui-element-error-icon"> error </span> {{ label }}
</div>
</template>
<script>
@ -56,6 +64,11 @@ export default {
default: null,
required: false,
},
isBroken: {
type: Boolean,
required: false,
default: false,
},
},
data() {
@ -93,6 +106,7 @@ export default {
methods: {
readProperty: async function () {
if (this.isBroken) return;
let data = await this.readThingProperty(this.thingName, this.propertyName);
this.modelValue = data;
return data;

View file

@ -11,6 +11,7 @@
:is-disabled="actionData.disabled"
:modal-progress="actionData.modal_progress"
:stream-with-modal="actionData.stream_with_modal"
:is-broken="actionData.broken"
@response="actionResponse"
@error="modalError"
@finished="actionFinished"

View file

@ -8,6 +8,7 @@
:read-back-delay="propertyData.read_back_delay"
:options="propertyData.options"
:step="propertyData.step"
:is-broken="propertyData.broken"
/>
</template>