feat:#26 added semester to fetched groups

This commit is contained in:
Elmar Kresse
2024-02-02 00:25:26 +01:00
parent 116a8dc37e
commit 25a7464e41
12 changed files with 5365 additions and 45 deletions

4677
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -20,6 +20,24 @@ export async function fetchCourse(): Promise<string[]> {
return courses;
}
export async function fetchCourseBySemester(semester: string): Promise<string[]> {
const courses: string[] = [];
await fetch("/api/courses?semester=" + semester)
.then((response) => {
//check if response type is json
const contentType = response.headers.get("content-type");
if (contentType && contentType.indexOf("application/json") !== -1) {
return response.json();
} else {
return [];
}
})
.then((coursesResponse) => {
coursesResponse.forEach((course: string) => courses.push(course));
});
return courses;
}
export async function fetchModulesByCourseAndSemester(
course: string,
semester: string,

View File

@@ -1,8 +1,7 @@
<script lang="ts" setup>
import { computed, ComputedRef, Ref, ref, watch } from "vue";
import {
fetchCourse,
fetchModulesByCourseAndSemester,
import { fetchCourseBySemester,
fetchModulesByCourseAndSemester
} from "../api/fetchCourse";
import DynamicPage from "./DynamicPage.vue";
import ModuleSelection from "../components/ModuleSelection.vue";
@@ -11,15 +10,28 @@ import { useI18n } from "vue-i18n";
import moduleStore from "../store/moduleStore";
import router from "../router";
async function getModules() {
modules.value = await fetchModulesByCourseAndSemester(
selectedCourse.value.name,
selectedSemester.value.value,
);
}
async function getCourses() {
courses.value = await fetchCourseBySemester(selectedSemester.value.value).then((data) => {
return data.map((course) => {
return { name: course };
});
});
}
const store = moduleStore();
const { t } = useI18n({ useScope: "global" });
const courses = async () => {
return await fetchCourse();
};
const selectedCourse: Ref<{ name: string }> = ref({ name: "" });
const countries: Ref<{ name: string }[]> = ref([]);
const courses: Ref<{ name: string; }[]> = ref([]);
const modules: Ref<Module[]> = ref([]);
const semesters: ComputedRef<{ name: string; value: string }[]> = computed(
() => [
{ name: t("courseSelection.winterSemester"), value: "ws" },
@@ -39,21 +51,10 @@ watch(
newValue[selectedSemester.value.value === "ws" ? 0 : 1]),
);
courses().then(
(data) =>
(countries.value = data.map((course) => {
return { name: course };
})),
);
// init the courses dropdown with the first semester that is default selected
getCourses();
const modules: Ref<Module[]> = ref([]);
async function getModules() {
modules.value = await fetchModulesByCourseAndSemester(
selectedCourse.value.name,
selectedSemester.value.value,
);
}
</script>
<template>
@@ -70,9 +71,17 @@ async function getModules() {
}"
>
<template #selection="{ flexSpecs }">
<Dropdown
v-model="selectedSemester"
:options="semesters"
:class="flexSpecs"
option-label="name"
:placeholder="$t('courseSelection.semesterDropDown')"
@change="getCourses()"
></Dropdown>
<Dropdown
v-model="selectedCourse"
:options="countries"
:options="courses"
:class="flexSpecs"
filter
option-label="name"
@@ -81,14 +90,6 @@ async function getModules() {
:auto-filter-focus="true"
@change="getModules()"
></Dropdown>
<Dropdown
v-model="selectedSemester"
:options="semesters"
:class="flexSpecs"
option-label="name"
:placeholder="$t('courseSelection.semesterDropDown')"
@change="getModules()"
></Dropdown>
</template>
<template #content>
<ModuleSelection