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:
commit
336e052fce
6 changed files with 57 additions and 3 deletions
|
|
@ -214,6 +214,9 @@ class ActionButton(BaseModel):
|
||||||
Downstream components can subscribe to this and request an update.
|
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:
|
def action_button_for(thing: lt.Thing, action_name: str, **kwargs: Any) -> ActionButton:
|
||||||
"""Create a ActionButton data for the specified Thing Action.
|
"""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
|
:return: An ActionButton (Pydantic Model) object with all the information the
|
||||||
webapp needs to create the action button.
|
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)
|
return ActionButton(thing=thing.name, action=action_name, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -270,6 +276,9 @@ class PropertyControl(BaseModel):
|
||||||
used.
|
used.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
broken: bool = False
|
||||||
|
"""If True the property control is broken. There is no corresponding property."""
|
||||||
|
|
||||||
|
|
||||||
def property_control_for(
|
def property_control_for(
|
||||||
thing: lt.Thing, property_name: str, **kwargs: Any
|
thing: lt.Thing, property_name: str, **kwargs: Any
|
||||||
|
|
@ -283,6 +292,9 @@ def property_control_for(
|
||||||
"""
|
"""
|
||||||
if "label" not in kwargs:
|
if "label" not in kwargs:
|
||||||
kwargs["label"] = property_name
|
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)
|
return PropertyControl(thing=thing.name, property_name=property_name, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -387,4 +387,16 @@ html {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
height: 100%;
|
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>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,15 @@
|
||||||
<button
|
<button
|
||||||
ref="actionButton"
|
ref="actionButton"
|
||||||
type="button"
|
type="button"
|
||||||
|
:title="tooltipText"
|
||||||
:disabled="buttonDisabled"
|
:disabled="buttonDisabled"
|
||||||
class="uk-button uk-width-1-1 uk-position-relative"
|
class="uk-button uk-width-1-1 uk-position-relative"
|
||||||
:class="buttonClasses"
|
:class="buttonClasses"
|
||||||
@click="handleClick"
|
@click="handleClick"
|
||||||
>
|
>
|
||||||
<action-progress-bar :progress="progress" :task-status="taskStatus" :in-button="true" />
|
<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>
|
</button>
|
||||||
|
|
||||||
<action-status-modal
|
<action-status-modal
|
||||||
|
|
@ -112,6 +114,11 @@ export default {
|
||||||
required: false,
|
required: false,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
isBroken: {
|
||||||
|
type: Boolean,
|
||||||
|
required: false,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
streamWithModal: {
|
streamWithModal: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
required: false,
|
required: false,
|
||||||
|
|
@ -148,7 +155,7 @@ export default {
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
buttonDisabled() {
|
buttonDisabled() {
|
||||||
return this.isDisabled || (this.taskRunning && !this.canTerminate);
|
return this.isDisabled || this.isBroken || (this.taskRunning && !this.canTerminate);
|
||||||
},
|
},
|
||||||
buttonLabel() {
|
buttonLabel() {
|
||||||
return this.taskRunning && this.canTerminate ? "Cancel" : this.submitLabel;
|
return this.taskRunning && this.canTerminate ? "Cancel" : this.submitLabel;
|
||||||
|
|
@ -158,6 +165,9 @@ export default {
|
||||||
if (this.buttonDisabled) {
|
if (this.buttonDisabled) {
|
||||||
classes.push("uk-button-disabled");
|
classes.push("uk-button-disabled");
|
||||||
}
|
}
|
||||||
|
if (this.isBroken) {
|
||||||
|
classes.push("ui-element-broken");
|
||||||
|
}
|
||||||
if (this.taskRunning && this.canTerminate) {
|
if (this.taskRunning && this.canTerminate) {
|
||||||
classes.push("uk-button-danger");
|
classes.push("uk-button-danger");
|
||||||
} else if (this.buttonPrimary) {
|
} else if (this.buttonPrimary) {
|
||||||
|
|
@ -167,6 +177,9 @@ export default {
|
||||||
}
|
}
|
||||||
return classes.join(" ");
|
return classes.join(" ");
|
||||||
},
|
},
|
||||||
|
tooltipText() {
|
||||||
|
return this.isBroken ? `${this.thing} has no action "${this.action}".` : "";
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
|
|
@ -232,7 +245,7 @@ export default {
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
handleShortcutTrigger() {
|
handleShortcutTrigger() {
|
||||||
if (this.isDisabled) return;
|
if (this.isDisabled || this.isBroken) return;
|
||||||
this.bootstrapTask();
|
this.bootstrapTask();
|
||||||
},
|
},
|
||||||
handleClick() {
|
handleClick() {
|
||||||
|
|
@ -257,6 +270,7 @@ export default {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
async checkExistingTasks() {
|
async checkExistingTasks() {
|
||||||
|
if (this.isBroken) return;
|
||||||
const ongoingTask = await this.getOngoingAction(this.thing, this.action);
|
const ongoingTask = await this.getOngoingAction(this.thing, this.action);
|
||||||
if (ongoingTask) {
|
if (ongoingTask) {
|
||||||
// There is a started task
|
// There is a started task
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<input-from-schema
|
<input-from-schema
|
||||||
|
v-if="!isBroken"
|
||||||
v-model="modelValue"
|
v-model="modelValue"
|
||||||
:data-schema="propertyDescription"
|
:data-schema="propertyDescription"
|
||||||
:label="label"
|
:label="label"
|
||||||
|
|
@ -10,6 +11,13 @@
|
||||||
@send-value="writeProperty"
|
@send-value="writeProperty"
|
||||||
@animation-shown="resetAnimate"
|
@animation-shown="resetAnimate"
|
||||||
/>
|
/>
|
||||||
|
<div
|
||||||
|
v-else
|
||||||
|
class="ui-element-broken"
|
||||||
|
:title="`${thingName} has no property "${propertyName}".`"
|
||||||
|
>
|
||||||
|
<span class="material-symbols-outlined ui-element-error-icon"> error </span> {{ label }}
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
@ -56,6 +64,11 @@ export default {
|
||||||
default: null,
|
default: null,
|
||||||
required: false,
|
required: false,
|
||||||
},
|
},
|
||||||
|
isBroken: {
|
||||||
|
type: Boolean,
|
||||||
|
required: false,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
|
|
@ -93,6 +106,7 @@ export default {
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
readProperty: async function () {
|
readProperty: async function () {
|
||||||
|
if (this.isBroken) return;
|
||||||
let data = await this.readThingProperty(this.thingName, this.propertyName);
|
let data = await this.readThingProperty(this.thingName, this.propertyName);
|
||||||
this.modelValue = data;
|
this.modelValue = data;
|
||||||
return data;
|
return data;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
:is-disabled="actionData.disabled"
|
:is-disabled="actionData.disabled"
|
||||||
:modal-progress="actionData.modal_progress"
|
:modal-progress="actionData.modal_progress"
|
||||||
:stream-with-modal="actionData.stream_with_modal"
|
:stream-with-modal="actionData.stream_with_modal"
|
||||||
|
:is-broken="actionData.broken"
|
||||||
@response="actionResponse"
|
@response="actionResponse"
|
||||||
@error="modalError"
|
@error="modalError"
|
||||||
@finished="actionFinished"
|
@finished="actionFinished"
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
:read-back-delay="propertyData.read_back_delay"
|
:read-back-delay="propertyData.read_back_delay"
|
||||||
:options="propertyData.options"
|
:options="propertyData.options"
|
||||||
:step="propertyData.step"
|
:step="propertyData.step"
|
||||||
|
:is-broken="propertyData.broken"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue