Skip to content

Commit

Permalink
#330 frontend: use enum for the exercise status
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolkenfarmer committed Sep 1, 2024
1 parent 6433e44 commit 78e6c1e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 37 deletions.
20 changes: 7 additions & 13 deletions frontend/src/components/screensPatient/ScreenWaiting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,23 @@
const title = computed(() => {
switch (exerciseStore.status) {
case 'running':
case ExerciseStatus.RUNNING:
return patientStore.relocatingInfo
case 'not-started':
case ExerciseStatus.NOT_STARTED:
return 'Warte, bis die Übung beginnt'
case 'paused':
case ExerciseStatus.PAUSED:
return 'Übung pausiert'
case 'ended':
case ExerciseStatus.ENDED:
return 'Übung beendet'
default:
return 'Warte auf Übung'
}
})
const info = computed(() => {
switch (exerciseStore.status) {
case 'running':
return new Date(new Date(0).setSeconds(patientStore.timeUntilBack)).toISOString().substring(12, 19)
case 'not-started':
case 'paused':
case 'ended':
default:
return 'Bereich: '+ exerciseStore.getAreaName(patientStore.areaId)
}
if (exerciseStore.status == ExerciseStatus.RUNNING) {
return new Date(new Date(0).setSeconds(patientStore.timeUntilBack)).toISOString().substring(12, 19)
} else return 'Bereich: '+ exerciseStore.getAreaName(patientStore.areaId)
})
</script>

Expand Down
24 changes: 12 additions & 12 deletions frontend/src/components/widgets/ExerciseControlPanel.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<script setup lang="ts">
import { svg } from "@/assets/Svg"
import { ref, computed, watch } from "vue"
import {svg} from "@/assets/Svg"
import {computed, ref, watch} from "vue"
import socketTrainer from "@/sockets/SocketTrainer"
import { useExerciseStore } from "@/stores/Exercise"
import {useExerciseStore} from "@/stores/Exercise"
import ButtonPopup from "./ButtonPopup.vue"
import SpeedSelectorPopup from "./SpeedSelectorPopup.vue"
import { useAvailablesStore } from "@/stores/Availables"
import { useLogStore } from "@/stores/Log"
import { Modules, setModule } from "@/App.vue"
import {CustomList, ListItem, ListItemButton, ListItemName, ListItemAddButton, ListItemRight, ListItemLeft} from "@/components/widgets/List"
import {useAvailablesStore} from "@/stores/Availables"
import {useLogStore} from "@/stores/Log"
import {Modules, setModule} from "@/App.vue"
import {ListItem, ListItemLeft, ListItemName, ListItemRight} from "@/components/widgets/List"
const exerciseStore = useExerciseStore()
const status = ref('')
const status = ref(ExerciseStatus.UNKNOWN)
const speed = ref(1)
status.value = exerciseStore.status
Expand All @@ -28,13 +28,13 @@
const info = computed(() => {
switch (status.value) {
case "not-started":
case ExerciseStatus.NOT_STARTED:
return "Die Übung wurde noch nicht gestartet"
case "running":
case ExerciseStatus.RUNNING:
return "Die Übung läuft"
case "paused":
case ExerciseStatus.PAUSED:
return "Die Übung ist pausiert"
case "ended":
case ExerciseStatus.ENDED:
return "Die Übung ist beendet"
default:
return "Fehler"
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/sockets/MessageData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,19 @@ interface MessageData {

interface Exercise {
exerciseId: string
status: string
status: ExerciseStatus
speed: number
areas: Area[]
}

enum ExerciseStatus {
RUNNING = "running",
PAUSED = "paused",
ENDED = "ended",
NOT_STARTED = "not-started",
UNKNOWN = "unknown",
}

interface Area {
areaId: number
areaName: string
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/sockets/SocketPatient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,21 @@ class SocketPatient {
patientStore.initializePatientFromExercise()
break
case 'exercise-start':
exerciseStore.status = 'running'
exerciseStore.status = ExerciseStatus.RUNNING
setScreen(Screens.STATUS, ScreenPosition.LEFT)
setScreen(Screens.ACTIONS, ScreenPosition.RIGHT)
break
case 'exercise-pause':
exerciseStore.status = 'paused'
exerciseStore.status = ExerciseStatus.PAUSED
setScreen(Screens.WAITING, ScreenPosition.FULL)
break
case 'exercise-resume':
exerciseStore.status = 'running'
exerciseStore.status = ExerciseStatus.RUNNING
setScreen(Screens.STATUS, ScreenPosition.LEFT)
setScreen(Screens.ACTIONS, ScreenPosition.RIGHT)
break
case 'exercise-end':
exerciseStore.status = 'ended'
exerciseStore.status = ExerciseStatus.ENDED
setScreen(Screens.ENDED, ScreenPosition.FULL)
break
case 'delete':
Expand Down
12 changes: 6 additions & 6 deletions frontend/src/sockets/SocketTrainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,22 @@ class SocketTrainer {
break
case 'exercise':
useExerciseStore().createFromJSON(data.exercise as Exercise)
if (exerciseStore.status == '') {
exerciseStore.status = 'not-started'
if (exerciseStore.status == ExerciseStatus.UNKNOWN) {
exerciseStore.status = ExerciseStatus.NOT_STARTED
setModule(Modules.TRAINER)
}
break
case 'exercise-start':
exerciseStore.status = 'running'
exerciseStore.status = ExerciseStatus.RUNNING
break
case 'exercise-pause':
exerciseStore.status = 'paused'
exerciseStore.status = ExerciseStatus.PAUSED
break
case 'exercise-resume':
exerciseStore.status = 'running'
exerciseStore.status = ExerciseStatus.RUNNING
break
case 'exercise-end':
exerciseStore.status = 'ended'
exerciseStore.status = ExerciseStatus.ENDED
break
case 'log-update':
useLogStore().addLogEntries(data.logEntries as LogEntry[])
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/stores/Exercise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {defineStore} from 'pinia'
export const useExerciseStore = defineStore('exercise', {
state: (): Exercise => ({
exerciseId: "",
status: "",
status: ExerciseStatus.RUNNING,
speed: 1,
areas: [],
}),
Expand Down

0 comments on commit 78e6c1e

Please sign in to comment.