Refactored Calibration Wizard: Add way to move forward and backward through tasks and sub-steps in tasks

This commit is contained in:
Julian Stirling 2025-10-22 18:18:19 +01:00
parent fd1e5a5bc0
commit 00f0fe664c
3 changed files with 164 additions and 82 deletions

View file

@ -3,45 +3,24 @@
<div class="uk-modal-dialog uk-modal-body"> <div class="uk-modal-dialog uk-modal-body">
<h2 class="uk-modal-title">Microscope Calibration</h2> <h2 class="uk-modal-title">Microscope Calibration</h2>
<component
v-if="currentTask"
:is="currentTask"
:key="taskIndex"
:num="taskIndex"
:first="isFirstTask"
:final="isFinalTask"
:startOnLast="movingBackward"
@next="nextTask"
@back="previousTask"
/>
<p class="uk-text-right">
<button
v-show="stepValue == 0"
class="uk-button uk-button-default uk-modal-close"
type="button"
>
Cancel
</button>
<button
v-show="stepValue == 4"
class="uk-button uk-button-default"
type="button"
@click="restart()"
>
Restart
</button>
<button
v-show="stepValue < 4"
class="uk-button uk-button-primary uk-margin-left"
type="button"
@click="increment()"
>
Next
</button>
<button
v-show="stepValue == 4"
class="uk-button uk-button-primary uk-margin-left"
type="button"
@click="hide()"
>
Finish
</button>
</p>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import calibrationWizardTask from "./calibrationWizardComponents/calibrationWizardTask.vue";
export default { export default {
name: "calibrationWizard", name: "calibrationWizard",
@ -50,12 +29,26 @@ export default {
data: function() { data: function() {
return { return {
stepValue: 0,
isNeeded: undefined, isNeeded: undefined,
calibrateableThings: [] calibrateableThings: [],
tasks: [],
taskIndex: 0,
movingBackward: false
}; };
}, },
computed: {
currentTask() {
return this.tasks[this.taskIndex] || null;
},
isFirstTask() {
return this.taskIndex === 0;
},
isFinalTask() {
return this.taskIndex === this.tasks.length - 1;
}
},
mounted() { mounted() {
this.$refs["calibrationModalEl"].addEventListener("hidden", this.onHide); this.$refs["calibrationModalEl"].addEventListener("hidden", this.onHide);
// Check which Things are available on mount. // Check which Things are available on mount.
@ -64,11 +57,12 @@ export default {
"camera_stage_mapping" "camera_stage_mapping"
]; ];
this.calibrateableThings = thingsToCheck.filter(name => this.thingAvailable(name)); this.calibrateableThings = thingsToCheck.filter(name => this.thingAvailable(name));
this.tasks = [calibrationWizardTask, calibrationWizardTask, calibrationWizardTask];
}, },
methods: { methods: {
/** /**
* Checks all calibratable things to see if any require calibration. * Check all calibratable Things to see if any require calibration.
* *
* Iterates over `this.calibrateableThings` (set during mounted()) and reads the * Iterates over `this.calibrateableThings` (set during mounted()) and reads the
* `calibration_required` property. * `calibration_required` property.
@ -95,34 +89,31 @@ export default {
return wizardNeeded; return wizardNeeded;
}, },
resetData: function() {
this.movingBackward = false;
this.taskIndex = 0;
},
show_if_needed: async function() { show_if_needed: async function() {
// Check if the camera and stage are calibrated, if they can be // Check if the camera and stage are calibrated, if they can be
let needed = await this.check_if_needed() let needed = await this.check_if_needed()
// Check if this calibration wizard can actually do anything useful // Check if this calibration wizard can actually do anything useful
if (needed) { if (needed) {
this.stepValue = 0; this.resetData();
this.show() this.show();
} else { } else {
// If not useful, we just return the onClose event immediately // If not needed, we just return the onClose event immediately
this.onHide(); this.onHide();
} }
}, },
// Forces modal to show on button press // Forces modal to show on button press
force_show: function() { force_show: function() {
this.stepValue = 1; this.resetData();
this.force = true this.show();
this.show()
}, },
restart: function() {
if (this.force == true){
this.stepValue = 1
} else {
this.stepValue = 0
}
},
show: function() { show: function() {
// Show the modal element // Show the modal element
@ -140,43 +131,29 @@ export default {
this.$emit("onClose"); this.$emit("onClose");
}, },
decrement: function() { /*
if (this.stepValue > 0) { * Move to the previous task.
this.stepValue = this.stepValue - 1; */
previousTask: function() {
this.movingBackward = true;
if (this.taskIndex > 0) {
this.taskIndex = this.taskIndex - 1;
} }
}, },
increment: function() { /*
// Upper bound on section number * Move to the next task or close the modal if this is the final task.
if (this.stepValue < 4) { */
this.stepValue = this.stepValue + 1; nextTask: function() {
this.movingBackward = false;
if (this.taskIndex < this.tasks.length - 1) {
this.taskIndex = this.taskIndex + 1;
return true; return true;
} }
else {
this.hide();
}
} }
} }
}; };
</script> </script>
<style scoped>
.mini-preview {
width: 75%;
margin-left: auto;
margin-right: auto;
}
.action-button-container {
display: flex;
flex-direction: row; /* Stack vertically */
justify-content: center; /* Left align */
gap: 8px; /* Small space between buttons */
margin-top: 4px; /* Gap from image */
}
>>> .moveZ .uk-button.uk-width-1-1 {
line-height: 50px;
font-size: 50px !important;
height: 60px;
padding-bottom: 46px;
margin: 0; /* Remove default margin */
width: 120px;
min-width: 80px;
}
</style>

View file

@ -165,3 +165,26 @@ export default {
}, },
} }
</script> </script>
<style scoped>
.mini-preview {
width: 75%;
margin-left: auto;
margin-right: auto;
}
.action-button-container {
display: flex;
flex-direction: row; /* Stack vertically */
justify-content: center; /* Left align */
gap: 8px; /* Small space between buttons */
margin-top: 4px; /* Gap from image */
}
>>> .moveZ .uk-button.uk-width-1-1 {
line-height: 50px;
font-size: 50px !important;
height: 60px;
padding-bottom: 46px;
margin: 0; /* Remove default margin */
width: 120px;
min-width: 80px;
}
</style>

View file

@ -0,0 +1,82 @@
<template>
<div>
<p>{{num}}.{{stepIndex}}</p>
<p class="uk-text-right">
<button
v-if="showBackButton"
class="uk-button uk-button-default"
type="button"
@click="previousStep"
>
Back
</button>
<button
class="uk-button uk-button-primary uk-margin-left"
type="button"
@click="nextStep"
>
{{ nextButtonText }}
</button>
</p>
</div>
</template>
<script>
export default {
name: "calibrationWizardTask",
props: {
num: Number,
first: Boolean,
final: Boolean,
startOnLast: {
type: Boolean,
default: false
},
steps: {
type: Number,
default: 2
}
},
data() {
return {
stepIndex: this.startOnLast ? this.steps-1 : 0
};
},
computed: {
showBackButton() {
return !this.first || this.stepIndex > 0;
},
nextButtonText() {
return this.final && this.stepIndex === this.steps - 1 ? "Finish" : "Next";
}
},
methods: {
/*
* Move to the previous step in this task, or the previous task if first step.
*/
previousStep: function() {
if (this.stepIndex > 0) {
this.stepIndex = this.stepIndex - 1;
} else {
this.$emit("back");
}
},
/*
* Move to the next step in this task, or the next task if final step.
*/
nextStep: function() {
if (this.stepIndex < this.steps - 1) {
this.stepIndex = this.stepIndex + 1;
return true;
} else {
this.$emit("next");
}
}
}
}
</script>