Skip to content

Commit

Permalink
add semester and year option for api function and state store
Browse files Browse the repository at this point in the history
  • Loading branch information
syzygy608 committed Jul 5, 2024
1 parent feab94b commit ca98d78
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 26 deletions.
30 changes: 18 additions & 12 deletions src/components/pages/main/inputArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<div class="flex flex-row py-1 w-40">
<select
class="mx-1 py-1 rounded-md text-center"
v-model="searchSem">
<option selected>選擇課表學期</option>
v-model="searchSem" v-if = "searchType != '自定義新增課程'">
<option disabled>選擇課表學期</option>
<option v-for="item in semList" :key="item" :value="item">
{{ item.year }} - {{ item.semester }}
</option>
Expand All @@ -24,10 +24,10 @@
</select>
</div>
<div class="flex flex-col py-1 mx-auto">
<CourseName v-if="searchType == '以課程名稱搜尋'" />
<Teacher v-if="searchType == '以教師名稱搜尋'" />
<Department v-if="searchType == '以系所年級搜尋'" />
<Time v-if="searchType == '以時間區間搜尋'" />
<CourseName v-if="searchType == '以課程名稱搜尋'" :year="selectedYear" :sem="selectedSem" />
<Teacher v-if="searchType == '以教師名稱搜尋'" :year="selectedYear" :sem="selectedSem" />
<Department v-if="searchType == '以系所年級搜尋'" :year="selectedYear" :sem="selectedSem" />
<Time v-if="searchType == '以時間區間搜尋'" :year="selectedYear" :sem="selectedSem" />
<Custom v-if="searchType == '自定義新增課程'" />
</div>
<hr class="mx-3 my-3 text-slate-300" />
Expand Down Expand Up @@ -181,14 +181,15 @@ let courseList = computed(() => store.state.course.classListStorage);
let credit = computed(() => store.state.course.credit);
const searchSem = ref("選擇課表學期");
const semList = ref([]);
const selectedYear = ref(null);
const selectedSem = ref(null);
watch(searchSem, async (inputValue) => {
if (inputValue != "選擇課表學期") {
// 這邊要去抓取課表
console.log("searchSem", inputValue);
}
selectedYear.value = inputValue.year;
selectedSem.value = inputValue.semester;
console.log(selectedYear.value, selectedSem.value);
store.dispatch("set_yearNsemester", [selectedYear.value, selectedSem.value]);
});
const toggleActive1 = ref(false);
Expand Down Expand Up @@ -245,6 +246,8 @@ let show = computed(() => store.state.course.showTable);
let opened = computed(() => store.state.course.timeSearchMode);
onMounted(async () => {
semList.value = await searchSemster();
searchSem.value = semList.value[semList.value.length - 1];
let temp_list = _.cloneDeep(courseList.value);
let update = false;
for (let i = 0; i < temp_list.length; i++) {
Expand Down Expand Up @@ -278,6 +281,8 @@ onMounted(async () => {
obj["Teacher"],
obj["classroom"],
obj["Credit"],
selectedYear.value,
selectedSem.value,
);
obj["department"] = result[0].department;
update = true;
Expand All @@ -289,6 +294,8 @@ onMounted(async () => {
obj["Teacher"],
obj["classroom"],
obj["Credit"],
selectedYear.value,
selectedSem.value,
);
obj["grade"] = result[0].grade;
update = true;
Expand All @@ -299,7 +306,6 @@ onMounted(async () => {
console.log("update", temp_list);
store.dispatch("updateCourseList", temp_list);
}
semList.value = await searchSemster();
});
watch(searchType, async (inputValue) => {
Expand Down
20 changes: 18 additions & 2 deletions src/components/pages/main/serach_modes/course_name.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
GetCourseTable,
} from "@functions/general";
import {
recordcourse,
searchCourse,
} from "@functions/course_search.ts";
import { splittime } from "@functions/tool.ts";
Expand All @@ -54,6 +53,7 @@ import {
watch,
reactive,
computed,
watchEffect,
} from "vue";
import { useStore } from "vuex";
import { v4 as uuidv4 } from "uuid";
Expand All @@ -75,12 +75,28 @@ let cleanInputArea = function () {
searchInput.value = "";
};
const props = defineProps({
year: Number,
sem: Number,
})
const selectedYear = ref(props.year);
const selectedSemester = ref(props.sem);
watchEffect(() => {
selectedYear.value = props.year;
selectedSemester.value = props.sem;
isLoading.value = false;
show_search_box.value = false;
searchInput.value = "";
});
watch(searchInput, async (inputValue) => {
show_search_box.value = true;
if (inputValue != "") {
isLoading.value = true;
show_search_box.value = true;
data.value = await searchCourse(inputValue);
data.value = await searchCourse(inputValue, selectedYear.value, selectedSemester.value);
// console.log(data.value);
data.value = data.value.map((temp) => {
temp["conflict"] = classconflict(temp);
Expand Down
23 changes: 19 additions & 4 deletions src/components/pages/main/serach_modes/department.vue
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import {
push_to_table,
} from "@functions/course_add.ts";
import "animate.css";
import { onMounted, ref, watch, computed } from "vue";
import { onMounted, ref, watch, computed, watchEffect } from "vue";
import { useStore } from "vuex";
const env = import.meta.env;
Expand All @@ -110,6 +110,21 @@ const gradeList = ref();
const courseList = ref([]);
const gradeSelection = ref();
const props = defineProps({
year: Number,
sem: Number,
})
const selectedYear = ref(props.year);
const selectedSemester = ref(props.sem);
watchEffect(async () => {
selectedYear.value = props.year;
selectedSemester.value = props.sem;
departmentInput.value = "";
departmentList = await getDepartment(selectedYear.value, selectedSemester.value);
});
const filteredClassList = computed(() => {
if (departmentInput.value == "") return [];
if (gradeSelection.value == "all") return courseList.value;
Expand Down Expand Up @@ -160,13 +175,13 @@ watch(departmentInput, async (inputValue) => {
async function clickDepartment() {
gradeList.value = [];
getGradeByDepartment(departmentInput.value).then((data) => {
getGradeByDepartment(departmentInput.value, selectedYear.value, selectedSemester.value).then((data) => {
if (data.length == 1) data = [];
gradeList.value = data;
gradeList.value.unshift({ grade: "all" });
gradeSelection.value = "all";
});
let coursedata = await getCourseByDepartment(departmentInput.value);
let coursedata = await getCourseByDepartment(departmentInput.value, selectedYear.value, selectedSemester.value);
courseList.value = coursedata;
// department 給 1
setConflictState(1);
Expand All @@ -181,7 +196,7 @@ onMounted(async () => {
department_search_list.value.style.maxHeight =
(2 * env.VITE_UL_ROW).toString() + "rem";
}
departmentList = await getDepartment();
departmentList = await getDepartment(selectedYear.value, selectedSemester.value);
setSearchTimeMode(false);
});
</script>
20 changes: 19 additions & 1 deletion src/components/pages/main/serach_modes/teacher.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import {
watch,
reactive,
computed,
watchEffect,
} from "vue";
import { useStore } from "vuex";
import { v4 as uuidv4 } from "uuid";
Expand All @@ -70,17 +71,34 @@ const show_search_box = ref(false);
const data = ref([]);
const searchList = ref(null);
const props = defineProps({
year: Number,
sem: Number,
});
const selectedYear = ref(props.year);
const selectedSem = ref(props.sem);
let cleanInputArea = function () {
console.log(48763);
show_search_box.value = !show_search_box.value;
searchInput.value = "";
};
watchEffect(() => {
selectedYear.value = props.year;
selectedSem.value = props.sem;
show_search_box.value = false;
cleanInputArea();
});
watch(searchInput, async (inputValue) => {
show_search_box.value = true;
if (inputValue != "") {
isLoading.value = true;
show_search_box.value = true;
data.value = await searchByTeacher(inputValue);
data.value = await searchByTeacher(inputValue, selectedYear.value, selectedSem.value);
data.value = data.value.map((temp) => {
temp["conflict"] = classconflict(temp);
return temp;
Expand Down
5 changes: 5 additions & 0 deletions src/components/pages/main/timeSelection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ const selectedCoursesearchtime = ref({});
const out = ref();
const toggle = ref(0);
const selectedYear = computed(() => store.state.course.selectedYear);
const selectedSemester = computed(() => store.state.course.selectedSemester);
const filteredClassList = computed(() => {
if(toggle.value == 0) // 顯示全部課程
return search_class_list_in_timemode.value;
Expand Down Expand Up @@ -171,6 +174,8 @@ watch(searchTimeArgument, async () => {
searchTimeArgument.value[0],
searchTimeArgument.value[1],
searchTimeArgument.value[2],
selectedYear.value,
selectedSemester.value,
);
search_class_list_in_timemode.value = [];
for (let i = 0; i < data.length; i++) {
Expand Down
Loading

0 comments on commit ca98d78

Please sign in to comment.