diff --git a/components/KeycloakAuth.vue b/components/KeycloakAuth.vue index 82fdf67..86e6012 100644 --- a/components/KeycloakAuth.vue +++ b/components/KeycloakAuth.vue @@ -1,4 +1,4 @@ - diff --git a/components/analysis/AnalysisControlButtons.vue b/components/analysis/AnalysisControlButtons.vue index f68a6fb..c6c8cb6 100644 --- a/components/analysis/AnalysisControlButtons.vue +++ b/components/analysis/AnalysisControlButtons.vue @@ -7,18 +7,34 @@ import { } from "~/composables/useAPIFetch"; const props = defineProps({ - // Have to use null since [String, null] gives an error: "No overload matches this call" - analysisStatus: { type: null }, + analysisStatus: String, analysisId: String, projectId: String, }); const toast = useToast(); -const analysisRunning = ref(isRunning()); +const playButtonActiveStates = [null, "stopped", "stopping"]; +const rerunButtonActiveStates = ["failed", "finished"]; +const stopButtonActiveStates = ["running", "starting", "started"]; +const deleteButtonActiveStates = [ + "failed", + "finished", + "stopping", + "stopped", + "running", + "starting", + "started", +]; -function isRunning(): boolean { - const analysisIsRunning = ["running", "starting", "started"]; - return analysisIsRunning.includes(props.analysisStatus); +const buttonStatuses = ref(setButtonStatuses(props.analysisStatus!)); + +function setButtonStatuses(podStatus: string) { + return { + playActive: playButtonActiveStates.includes(podStatus), + rerunActive: rerunButtonActiveStates.includes(podStatus), + stopActive: stopButtonActiveStates.includes(podStatus), + deleteActive: deleteButtonActiveStates.includes(podStatus), + }; } const showFailStart = () => { @@ -36,21 +52,31 @@ async function onStartAnalysis() { analysisProps.project_id = props.projectId!; const { data: response, status } = await startAnalysis(analysisProps); if (status.value === "success") { - console.log(response.value!.run_status); + const currentRunStatus = response.value!.status; + console.log(currentRunStatus); + buttonStatuses.value = setButtonStatuses(currentRunStatus); } else { showFailStart(); } - analysisRunning.value = !analysisRunning.value; } -function onStopAnalysis() { - stopAnalysis(props.analysisId!); - analysisRunning.value = !analysisRunning; +async function onStopAnalysis() { + const { data: response } = await stopAnalysis(props.analysisId!); + const podStatuses = response.value!.status; + for (const podName in podStatuses) { + setButtonStatuses(podStatuses[podName]); + } } -function onDeleteAnalysis() { - deleteAnalysis(props.analysisId!); - analysisRunning.value = !analysisRunning; +async function onDeleteAnalysis() { + const { data: response } = await deleteAnalysis(props.analysisId!); + const podStatuses = response.value!.status; + for (const podName in podStatuses) { + const pp = podStatuses[podName]; + console.log(pp); + setButtonStatuses(pp); + } + console.log(buttonStatuses); } @@ -59,10 +85,21 @@ function onDeleteAnalysis() {