From d34994bd945b46f72eb98bf04afc7d6afb953a94 Mon Sep 17 00:00:00 2001 From: Jeffrey Hsu Date: Mon, 24 Mar 2025 22:18:22 +0800 Subject: [PATCH] changes --- .../assessment/CourseGoalDisplay.vue | 4 +- src/renderer/src/models/Goal.ts | 25 ++++++++++- src/renderer/src/types/apidef.ts | 45 +++++++++++++++++++ 3 files changed, 71 insertions(+), 3 deletions(-) create mode 100644 src/renderer/src/types/apidef.ts diff --git a/src/renderer/src/components/assessment/CourseGoalDisplay.vue b/src/renderer/src/components/assessment/CourseGoalDisplay.vue index 66d4ad6..1dc6918 100644 --- a/src/renderer/src/components/assessment/CourseGoalDisplay.vue +++ b/src/renderer/src/components/assessment/CourseGoalDisplay.vue @@ -27,7 +27,7 @@ import { storeToRefs } from 'pinia' const store = useGlobalStore() const { goals } = storeToRefs(store) const showEditor = ref(false) -const tempGoal = ref(Goal.factory()) +const tempGoal = ref(Goal.factoryToImpl()) const canSubmit = computed(() => !Object.values(tempGoal.value).every((v) => v)) @@ -46,7 +46,7 @@ function handleShowEditor() { } function handleGoalListEdit(idx: number) { - tempGoal.value = goals.value[idx] + tempGoal.value = Goal.fac handleShowEditor() } diff --git a/src/renderer/src/models/Goal.ts b/src/renderer/src/models/Goal.ts index ffddfdb..56a61df 100644 --- a/src/renderer/src/models/Goal.ts +++ b/src/renderer/src/models/Goal.ts @@ -19,6 +19,7 @@ import { IGoal, IGoalWeight } from '@renderer/types' import { AssessmentData } from '@renderer/models/Assessment' +import { BaseFactoryClass } from '@renderer/types/apidef' export class GoalWeight implements IGoalWeight { private _stage: AssessmentData @@ -46,7 +47,7 @@ export class GoalWeight implements IGoalWeight { } } -export class Goal implements IGoal { +export class Goal implements IGoal, BaseFactoryClass { private _importance: 'H' | 'M' | 'L' private _indicator: string private _target: string @@ -68,6 +69,28 @@ export class Goal implements IGoal { return new Goal('H', '', '', []) } + public static factoryFromImpl(impl: IGoal): Goal { + return new Goal(impl.importance, impl.indicator, impl.target, []) + } + + public static factoryToImpl(): IGoal { + return { + importance: 'H', + indicator: '', + target: '', + weight: [] + } + } + + getCurrentImpl(): IGoal { + return { + importance: this._importance, + indicator: this._indicator, + target: this._target, + weight: this._weight + } + } + get importance(): 'H' | 'M' | 'L' { return this._importance } diff --git a/src/renderer/src/types/apidef.ts b/src/renderer/src/types/apidef.ts new file mode 100644 index 0000000..cb2c4fc --- /dev/null +++ b/src/renderer/src/types/apidef.ts @@ -0,0 +1,45 @@ +/* + * + * Copyright (c) 2025. Jeffery Hsu - Achievement Report Generator + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +export abstract class BaseFactoryClass { + public static factory() { + throw new Error('Method not implemented.') + } + + public static factoryToImpl(): T { + throw new Error('Method not implemented.') + } + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public static factoryFromImpl(_impl: T): T { + throw new Error('Method not implemented.') + } +} + +export abstract class ExposeImplGetter { + getCurrentImpl(): T { + throw new Error('Method not implemented.') + } +} + +export abstract class ExposeImplSetter { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + public setFromImpl(_impl: T): void { + throw new Error('Method not implemented.') + } +}