From 98befa9eccda4cef77e2003cfbd1a95bc34f1d93 Mon Sep 17 00:00:00 2001
From: Nhat-Original
Date: Fri, 10 May 2024 21:59:13 +0700
Subject: [PATCH 1/2] chore: small rewrite in course view
---
.../course/components/CreateModal.vue | 31 +++++++++----------
.../course/components/EditModal.vue | 14 ++++++++-
2 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/src/renderer/views/training-department/course/components/CreateModal.vue b/src/renderer/views/training-department/course/components/CreateModal.vue
index 10fa163..4624e67 100644
--- a/src/renderer/views/training-department/course/components/CreateModal.vue
+++ b/src/renderer/views/training-department/course/components/CreateModal.vue
@@ -1,4 +1,3 @@
-// TODO: fix the select field
Date: Sat, 11 May 2024 01:24:20 +0700
Subject: [PATCH 2/2] feat: added program view, missing add program item
feature
---
src/renderer/router/index.ts | 5 +
.../student/stores/student.ts | 12 +-
.../TrainingDepartment.vue | 1 +
.../course/components/EditModal.vue | 28 ++--
.../training-department/program/Program.vue | 17 +++
.../components/AddProgramItemModal.vue | 118 +++++++++++++++
.../components/EditProgramItemModal.vue | 117 +++++++++++++++
.../program/components/FunctionBar.vue | 16 +++
.../program/components/MajorList.vue | 24 ++++
.../program/components/ProgramItemTable.vue | 47 ++++++
.../program/stores/program.ts | 135 ++++++++++++++++++
11 files changed, 497 insertions(+), 23 deletions(-)
create mode 100644 src/renderer/views/training-department/program/Program.vue
create mode 100644 src/renderer/views/training-department/program/components/AddProgramItemModal.vue
create mode 100644 src/renderer/views/training-department/program/components/EditProgramItemModal.vue
create mode 100644 src/renderer/views/training-department/program/components/FunctionBar.vue
create mode 100644 src/renderer/views/training-department/program/components/MajorList.vue
create mode 100644 src/renderer/views/training-department/program/components/ProgramItemTable.vue
create mode 100644 src/renderer/views/training-department/program/stores/program.ts
diff --git a/src/renderer/router/index.ts b/src/renderer/router/index.ts
index 96e770e..6b55cfd 100644
--- a/src/renderer/router/index.ts
+++ b/src/renderer/router/index.ts
@@ -7,6 +7,7 @@ import FinanceDepartment from '../views/finance-department/FinanceDepartment.vue
import Course from '../views/training-department/course/Course.vue';
import StudentDepartment from '../views/student-department/StudentDepartment.vue';
import Student from '../views/student-department/student/Student.vue';
+import Program from '../views/training-department/program/Program.vue';
import resolveDepartmentRoute from '../../utils/resolveDepartmentRoute';
import getSession from '../../utils/getSession';
@@ -43,6 +44,10 @@ const routes: Array = [
path: 'course',
component: Course,
},
+ {
+ path: 'program',
+ component: Program,
+ },
],
},
{
diff --git a/src/renderer/views/student-department/student/stores/student.ts b/src/renderer/views/student-department/student/stores/student.ts
index 84c3596..8239749 100644
--- a/src/renderer/views/student-department/student/stores/student.ts
+++ b/src/renderer/views/student-department/student/stores/student.ts
@@ -1,6 +1,7 @@
import { defineStore } from 'pinia';
import { axiosClient } from '../../../../../api/axiosClient';
import { toast } from '../../../../../utils/toast';
+import { arrayToObject } from '../../../../../utils/arrayToObject';
type Faculty = {
id: number;
@@ -47,17 +48,6 @@ enum TypeQuery {
mssv = 'mssv',
}
-function arrayToObject(array: string[]) {
- const result: Record = {};
-
- array.forEach((item) => {
- const [key, ...value] = item.split(' ');
- result[key] = value.join(' ');
- });
-
- return result;
-}
-
export const useStudentStore = defineStore('student', {
state: () => ({
currentStudent: null as Student | null,
diff --git a/src/renderer/views/training-department/TrainingDepartment.vue b/src/renderer/views/training-department/TrainingDepartment.vue
index bd2e560..777502b 100644
--- a/src/renderer/views/training-department/TrainingDepartment.vue
+++ b/src/renderer/views/training-department/TrainingDepartment.vue
@@ -5,6 +5,7 @@
:routes="[
{ name: 'bảng điều khiển', path: '/training-department' },
{ name: 'môn học', path: '/training-department/course' },
+ { name: 'chương trình học', path: '/training-department/program' },
]"
/>
diff --git a/src/renderer/views/training-department/course/components/EditModal.vue b/src/renderer/views/training-department/course/components/EditModal.vue
index 8941a6c..d463f0d 100644
--- a/src/renderer/views/training-department/course/components/EditModal.vue
+++ b/src/renderer/views/training-department/course/components/EditModal.vue
@@ -87,18 +87,22 @@
{{ courseStore.errorMessages['courseTypeId'] }}
-
- Lưu lại
-
-
- Xóa
-
+
+
+ Lưu lại
+
+
+
+ Xóa
+
+
diff --git a/src/renderer/views/training-department/program/Program.vue b/src/renderer/views/training-department/program/Program.vue
new file mode 100644
index 0000000..c23eeb9
--- /dev/null
+++ b/src/renderer/views/training-department/program/Program.vue
@@ -0,0 +1,17 @@
+
+
+
+
+
diff --git a/src/renderer/views/training-department/program/components/AddProgramItemModal.vue b/src/renderer/views/training-department/program/components/AddProgramItemModal.vue
new file mode 100644
index 0000000..e820455
--- /dev/null
+++ b/src/renderer/views/training-department/program/components/AddProgramItemModal.vue
@@ -0,0 +1,118 @@
+// TODO: handle add program item logic
+
+
+ Thêm môn học vào chương trình
+
+
+
+
+
diff --git a/src/renderer/views/training-department/program/components/EditProgramItemModal.vue b/src/renderer/views/training-department/program/components/EditProgramItemModal.vue
new file mode 100644
index 0000000..068ab2b
--- /dev/null
+++ b/src/renderer/views/training-department/program/components/EditProgramItemModal.vue
@@ -0,0 +1,117 @@
+
+
+
+
+
diff --git a/src/renderer/views/training-department/program/components/FunctionBar.vue b/src/renderer/views/training-department/program/components/FunctionBar.vue
new file mode 100644
index 0000000..7c82918
--- /dev/null
+++ b/src/renderer/views/training-department/program/components/FunctionBar.vue
@@ -0,0 +1,16 @@
+
+
+
+
+ Ngành học:
+ {{ programStore.currentProgram?.major.name }}
+
+
+
+
+
diff --git a/src/renderer/views/training-department/program/components/MajorList.vue b/src/renderer/views/training-department/program/components/MajorList.vue
new file mode 100644
index 0000000..cf50a83
--- /dev/null
+++ b/src/renderer/views/training-department/program/components/MajorList.vue
@@ -0,0 +1,24 @@
+
+
+
+
+
diff --git a/src/renderer/views/training-department/program/components/ProgramItemTable.vue b/src/renderer/views/training-department/program/components/ProgramItemTable.vue
new file mode 100644
index 0000000..791e931
--- /dev/null
+++ b/src/renderer/views/training-department/program/components/ProgramItemTable.vue
@@ -0,0 +1,47 @@
+
+
+
+
+
+ Mã môn học |
+ Tên môn học |
+ Học kì |
+ Ghi chú |
+
+
+
+ handleRowClick(programItem)"
+ >
+ {{ programItem.course?.id }} |
+ {{ programItem.course?.name }} |
+
+ {{
+ programItem.term === 'first'
+ ? 'học kì 1'
+ : programStore.term === 'second'
+ ? 'học kì 2'
+ : 'học kì hè'
+ }}
+ |
+ {{ programItem.note }} |
+
+
+
+
+
+
+
diff --git a/src/renderer/views/training-department/program/stores/program.ts b/src/renderer/views/training-department/program/stores/program.ts
new file mode 100644
index 0000000..f1ddd48
--- /dev/null
+++ b/src/renderer/views/training-department/program/stores/program.ts
@@ -0,0 +1,135 @@
+import { defineStore } from 'pinia';
+import { axiosClient } from '../../../../../api/axiosClient';
+import { toast } from '../../../../../utils/toast';
+import { arrayToObject } from '../../../../../utils/arrayToObject';
+
+enum Term {
+ FIRST = 'first',
+ SECOND = 'second',
+ THIRD = 'third',
+}
+
+type Course = {
+ id: number;
+ name: string;
+ numberOfPeriods: number;
+ courseTypeId: number;
+ facultyId: number;
+};
+
+type ProgramItem = {
+ id: number;
+ programId: number;
+ courseId: number;
+ term: Term;
+ note: string;
+ course: Course;
+};
+
+type Major = {
+ id: number;
+ name: string;
+ facultyId: number;
+};
+
+type Program = {
+ id: number;
+ majorId: number;
+ major: Major;
+ programItems: ProgramItem[];
+};
+
+type State = {
+ majors: Major[];
+ courses: Course[];
+ currentProgram: Program | null;
+ currentProgramItem: ProgramItem | null;
+ errorMessages: Record;
+ searchQuery: string;
+};
+
+const useProgramStore = defineStore('program', {
+ state: (): State => ({
+ majors: [],
+ courses: [],
+ currentProgram: null,
+ currentProgramItem: null,
+ errorMessages: {},
+ searchQuery: '',
+ }),
+ actions: {
+ async getMajors() {
+ const response = await axiosClient.get('/major');
+ this.majors = response.data;
+ await this.getProgramByMajorId(this.majors[0].id);
+ },
+
+ async getCourses() {
+ const response = await axiosClient.get(
+ `/course?search=${this.searchQuery}`,
+ {
+ id: `list-course`,
+ cache: {
+ update: {
+ [`list-course`]: 'delete',
+ },
+ },
+ }
+ );
+ this.courses = response.data;
+ },
+
+ async getProgramByMajorId(majorId: number) {
+ const response = await axiosClient.get(`/major/${majorId}/program`, {
+ id: `program-major-${majorId}`,
+ cache: {
+ update: {
+ [`program-major-${majorId}`]: 'delete',
+ },
+ },
+ });
+ this.currentProgram = response.data;
+ },
+
+ async updateProgramItem(programItem: Partial) {
+ try {
+ await axiosClient.patch(
+ `/program-item/${this.currentProgramItem?.id}`,
+ programItem
+ );
+ this.clearErrorMessages();
+ this.getProgramByMajorId(this.currentProgram?.majorId);
+ toast('Cập nhật môn chương trình học thành công', 'success');
+ } catch (error) {
+ this.errorMessages = arrayToObject(error.response.data.message) || {};
+ toast('Cập nhật môn chương trình học thất bại', 'error');
+ }
+ },
+
+ async deleteProgramItem(id: number | string) {
+ try {
+ await axiosClient.delete(`/program-item/${id}`);
+ this.currentProgramItem = null;
+ this.getProgramByMajorId(this.currentProgram?.majorId);
+ toast('Xóa môn chương trình học thành công', 'success');
+ } catch (error) {
+ toast('Xóa môn chương trình học thất bại', 'error');
+ }
+ },
+
+ updateSearchQuery(value: string) {
+ this.searchQuery = value;
+ this.getCourses();
+ },
+
+ clearErrorMessages() {
+ this.errorMessages = {};
+ },
+
+ setCurrentProgramItem(programItem: ProgramItem) {
+ this.currentProgramItem = programItem;
+ },
+ },
+});
+
+export { useProgramStore };