From 8c89c2d7524730fb18da890d529ae76e0c086915 Mon Sep 17 00:00:00 2001 From: Jeffrey Hsu Date: Fri, 21 Feb 2025 01:28:52 +0800 Subject: [PATCH] add some class --- src/renderer/src/models/Assessment.ts | 115 ++++++++++++++++++++++ src/renderer/src/models/Course.ts | 107 ++++++++++++++++++++ src/renderer/src/models/ReportDocument.ts | 62 ++++++++++++ src/renderer/src/models/Student.ts | 86 ++++++++++++++++ src/renderer/src/types/share.ts | 20 ++++ 5 files changed, 390 insertions(+) create mode 100644 src/renderer/src/models/Assessment.ts create mode 100644 src/renderer/src/models/Course.ts create mode 100644 src/renderer/src/models/ReportDocument.ts create mode 100644 src/renderer/src/models/Student.ts create mode 100644 src/renderer/src/types/share.ts diff --git a/src/renderer/src/models/Assessment.ts b/src/renderer/src/models/Assessment.ts new file mode 100644 index 0000000..b4bd976 --- /dev/null +++ b/src/renderer/src/models/Assessment.ts @@ -0,0 +1,115 @@ +/* + * + * 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 . + * + */ + +import { IAssessment, IAssessmentMethod } from '@renderer/types' + +export class AssessmentData implements IAssessment { + private readonly _method: IAssessmentMethod[] + private _stage: string + private _weight: number + + constructor(stage: string, weight: number | string, method?: IAssessmentMethod[]) { + this._method = method ?? [] + this._stage = stage + this._weight = Number(weight) + } + + get method(): IAssessmentMethod[] { + return this._method + } + + get stage(): string { + return this._stage + } + + set stage(value: string) { + this._stage = value + } + + get weight(): number { + return this._weight + } + + set weight(value: number | string) { + this._weight = Number(value) + } + + public addMethod(method: IAssessmentMethod) { + this._method.push({ ...method, weight: Number(method.weight) }) + } + + public modifyMethod(method: IAssessmentMethod, idx: number) { + if (idx < 0 || idx >= this._method.length) { + return + } + this._method[idx] = { ...method, weight: Number(method.weight) } + } + + public removeMethod(idx: number) { + this.method.splice(idx, 1) + } + + public static factory() { + return new AssessmentData('', 0, []) + } +} + +export class Assessment { + private _daily: AssessmentData + private _progress: AssessmentData + private _final: AssessmentData + + constructor(daily: AssessmentData, progress: AssessmentData, final: AssessmentData) { + this._daily = daily + this._progress = progress + this._final = final + } + + public static factory() { + return new Assessment( + AssessmentData.factory(), + AssessmentData.factory(), + AssessmentData.factory() + ) + } + + get daily(): AssessmentData { + return this._daily + } + + set daily(value: AssessmentData) { + this._daily = value + } + + get progress(): AssessmentData { + return this._progress + } + + set progress(value: AssessmentData) { + this._progress = value + } + + get final(): AssessmentData { + return this._final + } + + set final(value: AssessmentData) { + this._final = value + } +} diff --git a/src/renderer/src/models/Course.ts b/src/renderer/src/models/Course.ts new file mode 100644 index 0000000..f3cb72f --- /dev/null +++ b/src/renderer/src/models/Course.ts @@ -0,0 +1,107 @@ +/* + * + * 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 . + * + */ + +import { ICourse } from '@renderer/types' + +export class Course implements ICourse { + private _campus: string + private _className: string + private _credit: number + private _id: string + private _master: string + private _name: string + private _teacher: string + + constructor( + campus: string, + className: string, + credit: number | string, + id: string, + master: string, + name: string, + teacher: string + ) { + this._campus = campus + this._className = className + this._credit = Number(credit) + this._id = id + this._master = master + this._name = name + this._teacher = teacher + } + + public static factory() { + return new Course('', '', 0, '', '', '', '') + } + + set campus(value: string) { + this._campus = value + } + + set className(value: string) { + this._className = value + } + + set credit(value: number | string) { + this._credit = Number(value) + } + + set id(value: string) { + this._id = value + } + + set master(value: string) { + this._master = value + } + + set name(value: string) { + this._name = value + } + + set teacher(value: string) { + this._teacher = value + } + get campus(): string { + return this._campus + } + + get className(): string { + return this._className + } + + get credit(): number { + return this._credit + } + + get id(): string { + return this._id + } + + get master(): string { + return this._master + } + + get name(): string { + return this._name + } + + get teacher(): string { + return this._teacher + } +} diff --git a/src/renderer/src/models/ReportDocument.ts b/src/renderer/src/models/ReportDocument.ts new file mode 100644 index 0000000..2c26db6 --- /dev/null +++ b/src/renderer/src/models/ReportDocument.ts @@ -0,0 +1,62 @@ +/* + * + * 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 . + * + */ + +import { Course } from '@renderer/models/Course' +import { Assessment } from '@renderer/models/Assessment' +import { Student } from '@renderer/models/Student' + +export class ReportDocument { + private _course: Course + private _assessment: Assessment + private _students: Student[] + + constructor(course: Course, assessment: Assessment, students: Student[]) { + this._course = course + this._assessment = assessment + this._students = students + } + + public static factory() { + return new ReportDocument(Course.factory(), Assessment.factory(), []) + } + + get course(): Course { + return this._course + } + + set course(value: Course) { + this._course = value + } + + get assessment(): Assessment { + return this._assessment + } + + set assessment(value: Assessment) { + this._assessment = value + } + + get students(): Student[] { + return this._students + } + + set students(value: Student[]) { + this._students = value + } +} diff --git a/src/renderer/src/models/Student.ts b/src/renderer/src/models/Student.ts new file mode 100644 index 0000000..188d725 --- /dev/null +++ b/src/renderer/src/models/Student.ts @@ -0,0 +1,86 @@ +/* + * + * 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 . + * + */ + +import { IStudent } from '@renderer/types' + +export class Student implements IStudent { + private _className: string + private _major: string + private _name: string + private _resitTag: boolean + private _serialNumber: string + + constructor( + className: string, + major: string, + name: string, + resitTag: boolean, + serialNumber: string + ) { + this._className = className + this._major = major + this._name = name + this._resitTag = resitTag + this._serialNumber = serialNumber + } + + public static factory() { + return new Student('', '', '', false, '') + } + + get className(): string { + return this._className + } + + set className(value: string) { + this._className = value + } + + get major(): string { + return this._major + } + + set major(value: string) { + this._major = value + } + + get name(): string { + return this._name + } + + set name(value: string) { + this._name = value + } + + get resitTag(): boolean { + return this._resitTag + } + + set resitTag(value: boolean) { + this._resitTag = value + } + + get serialNumber(): string { + return this._serialNumber + } + + set serialNumber(value: string) { + this._serialNumber = value + } +} diff --git a/src/renderer/src/types/share.ts b/src/renderer/src/types/share.ts new file mode 100644 index 0000000..4b7ee8d --- /dev/null +++ b/src/renderer/src/types/share.ts @@ -0,0 +1,20 @@ +/* + * + * 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 type Operation = 'save' | 'cancel' | 'modify'