diff --git a/app/index.html b/app/index.html index 3998055..7a353f9 100644 --- a/app/index.html +++ b/app/index.html @@ -13,6 +13,7 @@ /> + diff --git a/app/src/router/index.ts b/app/src/router/index.ts index 7712f0a..3a37c39 100644 --- a/app/src/router/index.ts +++ b/app/src/router/index.ts @@ -4,10 +4,10 @@ import { RouteRecordRaw } from 'vue-router'; import PitcherList from '../views/PitcherList.vue' import LoginView from '../views/LoginView.vue' import HomeView from '../views/HomeView.vue' -import PreparePitch from "@/views/PreparePitch.vue"; -import FinalizePitch from "@/views/FinalizePitch.vue"; -import BullpenStats from "@/views/BullpenStats.vue"; +import BullpenView from "@/views/BullpenView.vue"; +import BullpenSummaryView from "@/views/BullpenSummaryView.vue"; import SetupView from '@/views/SetupView.vue'; +import backendService from '@/services/BackendService' const routes: Array = [ { path: '/', redirect: '/login' }, @@ -15,10 +15,8 @@ const routes: Array = [ { path: '/setup', component: SetupView }, { path: '/home', component: HomeView }, { path: '/pitchers', component: PitcherList }, - { path: '/bullpen', component: PreparePitch }, - { path: '/prepare', component: PreparePitch }, - { path: '/finalize', component: FinalizePitch }, - { path: '/stats', component: BullpenStats } + { path: '/bullpen', component: BullpenView }, + { path: '/summary', component: BullpenSummaryView } ] const router = createRouter({ @@ -28,20 +26,19 @@ const router = createRouter({ router.beforeEach((to, from, next) => { const store = useStore(); - const serverAddress = localStorage.getItem('serverAddress'); const isAuthenticated = store.state.auth.isAuthenticated; if (to.meta.requiresAuth && !isAuthenticated) { return next('/login'); } - if (!serverAddress && to.path !== '/setup') { + if (!backendService.hasServer() && to.path !== '/setup') { return next('/setup'); } - if (serverAddress && to.path === '/setup') { - return next('/login'); - } + // if (serverAddress && to.path === '/setup') { + // return next('/login'); + // } next(); }); diff --git a/app/src/services/Api.ts b/app/src/services/Api.ts index 775a4f0..25ab1c0 100644 --- a/app/src/services/Api.ts +++ b/app/src/services/Api.ts @@ -1,7 +1,9 @@ import axios from "axios"; +const server = JSON.parse(localStorage.getItem("server") || '""'); + const instance = axios.create({ - baseURL: "http://localhost:8080/api", + baseURL: `${server.protocol}://${server.host}:${server.port}/api`, headers: { "Content-Type": "application/json", }, diff --git a/app/src/services/BackendService.ts b/app/src/services/BackendService.ts new file mode 100644 index 0000000..477206b --- /dev/null +++ b/app/src/services/BackendService.ts @@ -0,0 +1,15 @@ +import Server from "@/types/Server"; + +class BackendService { + hasServer(): boolean { + return localStorage.getItem("server") !== null; + } + getServer(): Server { + return JSON.parse(localStorage.getItem("server") || '{"protocol":"https","host":"localhost","port":8080}'); + } + updateServer(server: Server): void { + localStorage.setItem("server", JSON.stringify(server)); + } +} + +export default new BackendService(); diff --git a/app/src/services/BullpenSessionService.ts b/app/src/services/BullpenSessionService.ts index 1da0c34..3452bc1 100644 --- a/app/src/services/BullpenSessionService.ts +++ b/app/src/services/BullpenSessionService.ts @@ -1,7 +1,6 @@ import Pitch from "@/types/Pitch"; import User from "@/types/User"; import Bullpen from '@/types/Bullpen'; -import PitchTypeService from '@/services/PitchTypeService'; import api from '@/services/Api'; export class BullpenSessionService { @@ -18,10 +17,9 @@ export class BullpenSessionService { public save(bullpen: Bullpen): Promise { console.log(JSON.stringify(bullpen, null, 2)); return api - .post('/bullpen_session', { - bullpen - }) + .post('/bullpen_session', bullpen) .then(response => { + console.log(JSON.stringify(response.data, null, 2)); return response.data; }, (error) => { console.log(JSON.stringify(error, null, 2)); @@ -30,9 +28,9 @@ export class BullpenSessionService { public createPitch(): Pitch { return { - id: 0, + id: undefined, pitchTime: new Date(), - pitchTypeId: PitchTypeService.getLocalPitchTypes()[0].id, + pitchTypeId: 0, aimedArea: 0, hitArea: 0 } diff --git a/app/src/types/Pitch.ts b/app/src/types/Pitch.ts index e2d63fa..7d9409d 100644 --- a/app/src/types/Pitch.ts +++ b/app/src/types/Pitch.ts @@ -1,5 +1,5 @@ export default interface Pitch { - id: number, + id: number | undefined, pitchTime: Date, pitchTypeId: number, aimedArea: number, diff --git a/app/src/types/Server.ts b/app/src/types/Server.ts new file mode 100644 index 0000000..8f56683 --- /dev/null +++ b/app/src/types/Server.ts @@ -0,0 +1,5 @@ +export default interface Server { + protocol: string, + host: string, + port: number +} diff --git a/app/src/views/BullpenStats.vue b/app/src/views/BullpenSummaryView.vue similarity index 61% rename from app/src/views/BullpenStats.vue rename to app/src/views/BullpenSummaryView.vue index 9bd32c2..afe1b74 100644 --- a/app/src/views/BullpenStats.vue +++ b/app/src/views/BullpenSummaryView.vue @@ -16,6 +16,7 @@ import { IonTitle, IonToolbar } from '@ionic/vue'; +import PitchType from "@/types/PitchType"; import {useRouter} from 'vue-router'; import {computed} from 'vue'; import {useStore} from 'vuex'; @@ -23,23 +24,36 @@ import {useStore} from 'vuex'; const router = useRouter(); const store = useStore(); +const isAuthenticated = computed(() => store.state.auth.isAuthenticated); const pitcher = computed(() => store.state.auth.user); -const bullpen = computed(() => store.state.bullpen.bullpen); +const pitchTypes = computed(() => store.state.pitchTypes.pitchTypes); +const bullpen = computed(() => store.state.bullpen); + +console.log(JSON.stringify(bullpen.value.bullpen, null, 2)); + +const determinePitchTypeName = (id: number): string => { + const pitchType = pitchTypes.value.find((pitchType: PitchType) => pitchType.id === id); + + return pitchType?.name ?? 'Unknown'; +} const gotoHome = () => { - router.push('/home'); -}; + store.dispatch("bullpen/finish", bullpen.value.bullpen); + router.push({path: '/home'}); +} + - Bullpen Stats for {{ pitcher.firstName }} {{ pitcher.lastName }} + Bullpen Summary {{ pitcher.firstName }} {{ pitcher.lastName }} + Bullpen Summary - + Pitch {{index+1}} @@ -47,7 +61,7 @@ const gotoHome = () => { Pitch Type - {{pitch.pitchType.name}} + {{determinePitchTypeName(pitch.pitchTypeId)}} Planned Pitch Area diff --git a/app/src/views/PreparePitch.vue b/app/src/views/BullpenView.vue similarity index 93% rename from app/src/views/PreparePitch.vue rename to app/src/views/BullpenView.vue index 2556ab5..6cff5a9 100644 --- a/app/src/views/PreparePitch.vue +++ b/app/src/views/BullpenView.vue @@ -44,20 +44,20 @@ const gotoFinalizePitch = () => { currentStep.value = BullpenStep.Finish; } -const finalizeAndNextPitch = () => { - store.commit("bullpen/addPitch", pitch.value); - pitch.value = BullpenSessionService.createPitch(); - currentStep.value = BullpenStep.Prepare; +const nextPitch = () => { + storePitch(); } -const finalizeAndEndBullpen = () => { +const finishBullpen = () => { + storePitch(); + bullpen.value.bullpen.finishedAt = new Date(); + router.push({ path: '/summary' }); +} + +const storePitch = () => { store.commit("bullpen/addPitch", pitch.value); pitch.value = BullpenSessionService.createPitch(); currentStep.value = BullpenStep.Prepare; - const bp = bullpen.value.bullpen; - bp.finishedAt = new Date(); - store.dispatch("bullpen/finish", bp); - router.push({ name: 'BullpenStats' }); } const setPlannedPitchArea = (hitArea: number) => { @@ -96,7 +96,7 @@ const pitchAreaCssClasses = (area: number, name: string) => { Select Pitch type - + {{pitchType.abbreviation}} @@ -180,10 +180,10 @@ const pitchAreaCssClasses = (area: number, name: string) => { - Save Pitch&Next Pitch + Next Pitch - Save Pitch&End Session + Finish Session diff --git a/app/src/views/FinalizePitch.vue b/app/src/views/FinalizePitch.vue deleted file mode 100644 index 3adeb4c..0000000 --- a/app/src/views/FinalizePitch.vue +++ /dev/null @@ -1,159 +0,0 @@ - - - - - - - Finalize Pitch for {{ bps.getPitcher().firstName }} {{ bps.getPitcher().lastName }} - - - - - - Select Real Pitch Hit Area - - - - - - - - - - - - - 21 - 22 - 23 - 24 - 25 - 26 - 27 - 28 - - - - - - - - - - - 11 - 12 - 13 - 14 - 15 - 16 - 17 - 18 - - - - - - - - - - - - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - - - - - - - - Save Pitch&Next Pitch - Save Pitch&End Session - - - - - - - diff --git a/app/src/views/HomeView.vue b/app/src/views/HomeView.vue index 78b0478..9876670 100644 --- a/app/src/views/HomeView.vue +++ b/app/src/views/HomeView.vue @@ -22,7 +22,7 @@ if (pitcher.value === undefined || pitcher.value === null || pitcher.value === ' const startBullpen = () => { console.log('Starting bullpen session'); - router.push({ path: '/prepare' }); + router.push({ path: '/bullpen' }); }; const showStats = () => { diff --git a/app/src/views/LoginView.vue b/app/src/views/LoginView.vue index a59657f..5a6663f 100644 --- a/app/src/views/LoginView.vue +++ b/app/src/views/LoginView.vue @@ -3,6 +3,7 @@ import { computed, ref, onMounted } from "vue"; import { IonPage, IonIcon, + IonLabel, IonButton, IonContent, IonInput @@ -22,6 +23,7 @@ import { useStore } from 'vuex' import * as yup from 'yup'; const loading = ref(false); +const server = JSON.parse(localStorage.getItem("server") || '""'); const schema = yup.object({ email: yup.string().email('Invalid email address').required('Email is required'), @@ -29,7 +31,7 @@ const schema = yup.object({ .string() .min(8, 'Minimum 8 characters') .matches(/\d/, 'Must include a number') - .matches(/[^A-Za-z\d]/, 'Must include a special character') + // .matches(/[^A-Za-z\d]/, 'Must include a special character') .required('Password is required'), }); @@ -63,10 +65,6 @@ const submit = handleSubmit((values, { resetForm }) => { error => { loading.value = false; console.log(error); - // message.value = - // (error.response && error.response.data && error.response.data.message) || - // error.message || - // error.toString(); } ); }, ({errors}) => { @@ -83,6 +81,11 @@ const onLogin = () => { console.log(error); }); } + +const changeServer = () => { + router.push({ path: '/setup'}); +} + @@ -95,6 +98,7 @@ const onLogin = () => { + {{server.protocol}}://{{server.host}}:{{server.port}} @@ -136,9 +140,8 @@ const onLogin = () => { - - Login - + Login + Change Server diff --git a/app/src/views/PitcherList.vue b/app/src/views/PitcherList.vue index e28d675..dcfd618 100644 --- a/app/src/views/PitcherList.vue +++ b/app/src/views/PitcherList.vue @@ -18,7 +18,7 @@ onMounted(async () => { const goToPreparePitch = (pitcher: User) => { bps.value.startSession( pitcher ); - router.push({ name: 'PreparePitch' }); + router.push({ path: '/bullpen' }); }; diff --git a/app/src/views/SetupView.vue b/app/src/views/SetupView.vue index 70f054b..a1f315c 100644 --- a/app/src/views/SetupView.vue +++ b/app/src/views/SetupView.vue @@ -1,13 +1,17 @@ @@ -23,8 +27,15 @@ const saveServerAddress = () => { - + + + + + Use SSL + + + Save