mirror of
https://gitlab.dit.htwk-leipzig.de/htwk-software/htwkalender.git
synced 2025-08-09 13:17:46 +02:00
feat:#26 added semester to fetched groups
This commit is contained in:
4677
frontend/package-lock.json
generated
Normal file
4677
frontend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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,
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user