Skip to content

Commit

Permalink
feat(analysis): update button statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
brucetony committed Aug 12, 2024
1 parent 30af915 commit a072b8e
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions components/analysis/AnalysisControlButtons.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@ import {
} from "~/composables/useAPIFetch";
const props = defineProps({
analysisStatus: String,
analysisRunStatus: String,
analysisId: String,
projectId: String,
nodeId: String,
});
const toast = useToast();
const playButtonActiveStates = [null, "stopped", "stopping"];
const rerunButtonActiveStates = ["failed", "finished"];
const loading = ref(false);
const playButtonActiveStates = [null, ""];
const rerunButtonActiveStates = ["failed", "finished", "stopped", "stopping"];
const stopButtonActiveStates = ["running", "starting", "started"];
const deleteButtonActiveStates = [
"failed",
Expand All @@ -27,7 +30,7 @@ const deleteButtonActiveStates = [
"started",
];
const buttonStatuses = ref(setButtonStatuses(props.analysisStatus!));
const buttonStatuses = ref(setButtonStatuses(props.analysisRunStatus!));
function setButtonStatuses(podStatus: string) {
return {
Expand Down Expand Up @@ -56,7 +59,12 @@ const showSuccess = (summary: string, msg: string) => {
});
};
// async function updateHubAnalysisRunStatus(update: string) {
// await updateAnalysis(props.analysisId!, { run_status: update });
// }
async function onStartAnalysis() {
loading.value = true;
const analysisProps = {} as BodyCreateAnalysisPoPost;
analysisProps.analysis_id = props.analysisId!;
analysisProps.project_id = props.projectId!;
Expand All @@ -66,36 +74,39 @@ async function onStartAnalysis() {
const currentRunStatus = response.value!.status;
buttonStatuses.value = setButtonStatuses(currentRunStatus);
showSuccess("Start success", "Successfully started the container");
// await updateHubAnalysisRunStatus("running");
} else {
showFailure("Start failure", "Failed to start the analysis");
}
loading.value = false;
}
async function onStopAnalysis() {
loading.value = true;
const { data: response, status } = await stopAnalysis(props.analysisId!);
const podStatuses = response.value!.status;
if (status.value === "success") {
for (const podName in podStatuses) {
buttonStatuses.value = setButtonStatuses(podStatuses[podName]);
showSuccess("Stop success", "Successfully stopped the container");
}
// await updateHubAnalysisRunStatus("stopped");
} else {
showFailure("Stop failure", "Failed to stop the analysis container");
}
loading.value = false;
}
async function onDeleteAnalysis() {
const { data: response, status } = await deleteAnalysis(props.analysisId!);
const podStatuses = response.value!.status;
loading.value = true;
const { status } = await deleteAnalysis(props.analysisId!);
if (status.value === "success") {
for (const podName in podStatuses) {
const pp = podStatuses[podName];
buttonStatuses.value = setButtonStatuses(pp);
showSuccess("Delete success", "Successfully removed the container");
}
buttonStatuses.value = setButtonStatuses("");
showSuccess("Delete success", "Successfully removed the container");
} else {
showFailure("Delete failure", "Failed to delete the analysis container");
}
loading.value = false;
}
</script>

Expand All @@ -104,21 +115,23 @@ async function onDeleteAnalysis() {
<Button
icon="pi pi-play"
aria-label="Start"
v-if="buttonStatuses.rerunActive"
v-if="buttonStatuses.playActive"
v-tooltip="'Start the analysis'"
severity="success"
style="margin-right: 10px"
:disabled="!buttonStatuses.playActive"
:loading="loading"
@click="onStartAnalysis()"
/>
<Button
icon="pi pi-play"
aria-label="Start"
icon="pi pi-replay"
aria-label="Rerun"
v-else
v-tooltip="'Start the analysis'"
v-tooltip="'Rerun the analysis'"
severity="success"
style="margin-right: 10px"
:disabled="!buttonStatuses.playActive"
:disabled="!buttonStatuses.rerunActive"
:loading="loading"
@click="onStartAnalysis()"
/>
<Button
Expand All @@ -128,6 +141,7 @@ async function onDeleteAnalysis() {
severity="warn"
style="margin-right: 10px"
:disabled="!buttonStatuses.stopActive"
:loading="loading"
@click="onStopAnalysis()"
/>
<Button
Expand All @@ -136,6 +150,7 @@ async function onDeleteAnalysis() {
v-tooltip="'Delete the analysis container'"
severity="danger"
:disabled="!buttonStatuses.deleteActive"
:loading="loading"
@click="onDeleteAnalysis()"
/>
</div>
Expand Down

0 comments on commit a072b8e

Please sign in to comment.