Skip to content

Commit

Permalink
Merge pull request #38 from maikusobu/feature/program-view
Browse files Browse the repository at this point in the history
Feature/program view
  • Loading branch information
Nhat-Original authored May 10, 2024
2 parents 4369a6e + 05128eb commit 0f6d58f
Show file tree
Hide file tree
Showing 12 changed files with 524 additions and 41 deletions.
5 changes: 5 additions & 0 deletions src/renderer/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -43,6 +44,10 @@ const routes: Array<RouteRecordRaw> = [
path: 'course',
component: Course,
},
{
path: 'program',
component: Program,
},
],
},
{
Expand Down
12 changes: 1 addition & 11 deletions src/renderer/views/student-department/student/stores/student.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -47,17 +48,6 @@ enum TypeQuery {
mssv = 'mssv',
}

function arrayToObject(array: string[]) {
const result: Record<string, any> = {};

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
]"
/>
<div class="flex flex-col grow">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO: fix the select field
<template>
<button
class="btn bg-secondary-400 text-base-white hover:bg-secondary-300"
Expand Down Expand Up @@ -48,41 +47,39 @@
</label>
<label class="flex flex-col">
Khoa
<Field
v-slot="{ value }"
as="select"
class="select select-bordered"
name="facultyId"
>
<Field as="select" class="select select-bordered" name="facultyId">
<option
v-for="(faculty, index) in courseStore.faculties"
:key="faculty.id"
:value="faculty.id"
:selected="index === 0"
v-bind="value"
>
{{ faculty.name }}
</option>
</Field>
<p
v-if="courseStore.errorMessages['facultyId']"
class="text-red-700 text-[12px]"
>
{{ courseStore.errorMessages['facultyId'] }}
</p>
</label>
<label class="flex flex-col">
Loại môn học
<Field
v-slot="{ value }"
as="select"
class="select select-bordered"
name="courseTypeId"
>
<Field as="select" class="select select-bordered" name="courseTypeId">
<option
v-for="(courseType, index) in courseStore.courseTypes"
:key="courseType.id"
:value="courseType.id"
:selected="index === 0"
v-bind="value"
>
{{ courseType.name }}
</option>
</Field>
<p
v-if="courseStore.errorMessages['courseTypeId']"
class="text-red-700 text-[12px]"
>
{{ courseStore.errorMessages['courseTypeId'] }}
</p>
</label>
<button
class="row-start-4 btn w-[200px] bg-secondary-400 text-base-white hover:bg-secondary-300"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
v-if="courseStore.errorMessages['numberOfPeriods']"
class="text-red-700 text-[12px]"
>
{{ courseStore.errorMessages['name'] }}
{{ courseStore.errorMessages['numberOfPeriods'] }}
</p>
</label>
<label class="flex flex-col">
Expand All @@ -57,6 +57,12 @@
{{ faculty.name }}
</option>
</Field>
<p
v-if="courseStore.errorMessages['facultyId']"
class="text-red-700 text-[12px]"
>
{{ courseStore.errorMessages['facultyId'] }}
</p>
</label>
<label class="flex flex-col">
loại môn học
Expand All @@ -74,19 +80,29 @@
{{ courseType.name }}
</option>
</Field>
<p
v-if="courseStore.errorMessages['courseTypeId']"
class="text-red-700 text-[12px]"
>
{{ courseStore.errorMessages['courseTypeId'] }}
</p>
</label>
<button
class="row-start-4 btn w-[200px] bg-secondary-400 text-base-white hover:bg-secondary-300"
type="submit"
>
Lưu lại
</button>
<button
class="row-start-4 btn w-[200px] bg-error-text text-base-white hover:bg-delete-button-hover"
@click="handleDelete"
>
Xóa
</button>
<div class="col-span-3 flex gap-10">
<button
class="row-start-4 btn w-[200px] bg-secondary-400 text-base-white hover:bg-secondary-300"
type="submit"
>
Lưu lại
</button>

<button
class="row-start-4 btn w-[200px] bg-error-text text-base-white hover:bg-delete-button-hover"
type="button"
@click="handleDelete"
>
Xóa
</button>
</div>
</Form>
</div>
</dialog>
Expand Down
17 changes: 17 additions & 0 deletions src/renderer/views/training-department/program/Program.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<div class="grow flex flex-col gap-8 items-center p-[40px]">
<FunctionBar />
<div class="flex h-[calc(100vh-300px)] w-full">
<MajorList />
<ProgramItemTable />
</div>
<EditProgramItemModal />
</div>
</template>

<script setup>
import FunctionBar from './components/FunctionBar.vue';
import MajorList from './components/MajorList.vue';
import ProgramItemTable from './components/ProgramItemTable.vue';
import EditProgramItemModal from './components/EditProgramItemModal.vue';
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// TODO: handle add program item logic
<template>
<button
class="btn bg-secondary-400 text-base-white hover:bg-secondary-300"
onclick="add_program_item_modal.showModal()"
>
Thêm môn học vào chương trình
</button>
<dialog id="add_program_item_modal" class="modal">
<div class="modal-box min-w-[900px] w p-20">
<form method="dialog">
<button
class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"
@click="handleCloseModal"
>
</button>
</form>
<h1 class="font-semibold text-3xl">Thêm môn học vào chương trình</h1>
<button class="flex items-center gap-2">
<img :src="plusCircleIcon" alt="add icon" />
<p>Nhập từ CSV</p>
</button>
<Form class="mt-8 grid grid-cols-4 gap-10" @submit="handleSubmit">
<label>
Học kì
<Field as="select" class="select select-bordered" name="term">
<option value="first">học kì 1</option>
<option value="second">học kì 2</option>
<option value="third">học kì hè</option>
</Field>

<p
v-if="programStore.errorMessages['term']"
class="text-red-700 text-[12px]"
>
{{ programStore.errorMessages['term'] }}
</p>
</label>

<label class="flex flex-col col-span-3">
Ghi chú
<Field class="input input-bordered" name="note" type="text" />
<p
v-if="programStore.errorMessages['note']"
class="text-red-700 text-[12px]"
>
{{ programStore.errorMessages['note'] }}
</p>
</label>
<label class="row-start-2 col-span-4">
Môn học
<div class="overflow-x-auto w-full h-[300px] border">
<table class="table table-zebra">
<thead>
<tr>
<th>Mã môn học</th>
<th>Tên môn học</th>
<th>Số tiết</th>
<th>Khoa</th>
<th>Loại môn học</th>
</tr>
</thead>
<tbody>
<tr
v-for="course in programStore.courses"
:key="course.id"
class="hover:!bg-secondary-100"
:class="{ 'bg-secondary-100': course.id === localCourseId }"
@click="() => handleRowClick(course)"
>
<td>{{ course.id }}</td>
<td>{{ course.name }}</td>
<td>{{ course.numberOfPeriods }}</td>
<td>{{ course.faculty.name }}</td>
<td>{{ course.courseType.name }}</td>
</tr>
</tbody>
</table>
</div>
</label>
<button
class="btn w-[200px] bg-secondary-400 text-base-white hover:bg-secondary-300"
type="submit"
>
Lưu lại
</button>
</Form>
</div>
</dialog>
</template>

<script setup>
import plusCircleIcon from '../../../../../assets/images/plusCircleIcon.svg';
import { useProgramStore } from '../stores/program';
import { Form, Field } from 'vee-validate';
import { ref } from 'vue';
const programStore = useProgramStore();
programStore.getCourses();
const handleCloseModal = () => {
programStore.clearErrorMessages();
document.getElementById('add_program_item_modal').close();
};
const handleSubmit = async (value, { resetForm }) => {
if (Object.keys(courseStore.errorMessages).length === 0) {
resetForm();
handleCloseModal();
}
};
const handleRowClick = (course) => {
localCourseId.value = course.id;
};
const localCourseId = ref(null);
</script>
Loading

0 comments on commit 0f6d58f

Please sign in to comment.