Generalise server specified action buttons.

This commit is contained in:
Julian Stirling 2025-07-27 15:39:38 +01:00
parent 0794d4777f
commit 3651013440
4 changed files with 86 additions and 41 deletions

View file

@ -791,6 +791,8 @@ class StreamingPiCamera2(BaseCamera):
"Start recalibration? This may take a while, and the microscope "
"will be locked during this time."
),
notify_on_success=True,
success_message="Finished recalibration.",
),
action_button_for(
self.auto_expose_from_minimum,

View file

@ -23,19 +23,33 @@ class ActionButton(BaseModel):
thing: str
"""The Thing "path" for the Thing instance."""
action: str
"""The name of the action to be triggered."""
poll_interval: int = 1
"""The interval for polling in seconds."""
submit_label: str = "Submit"
"""The label for the action button."""
can_terminate: bool = True
"""Specify whether the action can be terminated."""
requires_confirmation: bool = False
"""Specify whether a confirmation modal is needed."""
confirmation_message: str = "Start task?"
"""The message for the confirmation modal."""
button_primary: bool = True
"""Specify whether the button is styled as a primary button."""
modal_progress: bool = False
"""Specify whether to show a progress modal."""
notify_on_success: bool = False
"""Specify whether to a notification on successful completion."""
success_message: str = "Success!"
"""The message to show on successful completion."""

View file

@ -0,0 +1,46 @@
<template>
<action-button
:thing="actionData.thing"
:action="actionData.action"
:poll-interval="actionData.poll_interval"
:submit-label="actionData.submit_label"
:can-terminate="actionData.can_terminate"
:requires-confirmation="actionData.requires_confirmation"
:confirmation-message="actionData.confirmation_message"
:button-primary="actionData.button_primary"
:modal-progress="actionData.modal_progress"
@response="actionResponse"
@error="modalError"
/>
</template>
<script>
import ActionButton from "./actionButton.vue";
// Export main app
export default {
name: "ServerSpecifiedActionButton",
components: {
ActionButton
},
props: {
actionData: {
type: Object,
required: true,
}
},
methods: {
actionResponse: function() {
if (this.actionData.notify_on_success) {
this.modalNotify(this.actionData.success_message);
}
}
}
};
</script>
<style lang="less"></style>

View file

@ -1,58 +1,34 @@
<template>
<div>
<!--Show auto calibrate if default plugin is enabled-->
<div
<!--Show calibration actions as specified by the camera.-->
<div
v-for="(action, index) in secondaryCalibrationActions"
:key="'primary_cal' + index"
class="uk-child-width-expand"
:key = "'primary_cal' + index"
>
<action-button
:can-terminate="action.can_terminate"
:requires-confirmation="action.requires_confirmation"
:thing="action.thing"
:action="action.action"
:submit-label="action.submit_label"
@response="onRecalibrateResponse"
@error="modalError"
/>
<server-specified-action-button :action-data="action" />
</div>
<div v-if="showExtraSettings">
<div
<div
v-for="(action, index) in primaryCalibrationActions"
:key="'secondary_cal' + index"
class="uk-child-width-expand"
:key = "'secondary_cal' + index"
>
<action-button
:can-terminate="action.can_terminate"
:requires-confirmation="action.requires_confirmation"
:thing="action.thing"
:action="action.action"
:submit-label="action.submit_label"
@response="onRecalibrateResponse"
@error="modalError"
/>
<server-specified-action-button :action-data="action" />
</div>
</div>
</div>
</template>
<script>
import ActionButton from "../../../labThingsComponents/actionButton.vue";
import ServerSpecifiedActionButton from "../../../labThingsComponents/serverSpecifiedActionButton.vue";
// Export main app
export default {
name: "CameraCalibrationSettings",
components: {
ActionButton
},
data() {
return {
primaryCalibrationActions: [],
secondaryCalibrationActions: []
};
ServerSpecifiedActionButton
},
props: {
@ -67,6 +43,13 @@ export default {
}
},
data() {
return {
primaryCalibrationActions: [],
secondaryCalibrationActions: []
};
},
computed: {
actions() {
return this.$store.getters["wot/thingDescription"]("camera").actions;
@ -74,14 +57,14 @@ export default {
},
async created() {
this.primaryCalibrationActions = await this.readThingProperty("camera", "primary_calibration_actions");
this.secondaryCalibrationActions = await this.readThingProperty("camera", "secondary_calibration_actions");
},
methods: {
onRecalibrateResponse: function() {
this.modalNotify("Finished recalibration.");
}
this.primaryCalibrationActions = await this.readThingProperty(
"camera",
"primary_calibration_actions"
);
this.secondaryCalibrationActions = await this.readThingProperty(
"camera",
"secondary_calibration_actions"
);
}
};
</script>