Replace the course profile filter pills with a dropdown

This commit is contained in:
Ramon Wenger 2024-07-31 15:20:07 +02:00 committed by Christian Cueni
parent 17b466ea29
commit bf5482e39c
3 changed files with 31 additions and 27 deletions

View File

@ -5,17 +5,14 @@ import { computed } from "vue"; // https://stackoverflow.com/questions/64775876/
// https://stackoverflow.com/questions/64775876/vue-3-pass-reactive-object-to-component-with-two-way-binding // https://stackoverflow.com/questions/64775876/vue-3-pass-reactive-object-to-component-with-two-way-binding
interface Props { interface Props {
modelValue?: { modelValue?: DropdownSelectable;
id: string | number;
name: string;
};
items?: DropdownSelectable[]; items?: DropdownSelectable[];
borderless?: boolean; borderless?: boolean;
placeholderText?: string | null; placeholderText?: string | null;
} }
const emit = defineEmits<{ const emit = defineEmits<{
(e: "update:modelValue", data: object): void; (e: "update:modelValue", data: DropdownSelectable): void;
}>(); }>();
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {

View File

@ -1,35 +1,44 @@
<script lang="ts" setup> <script lang="ts" setup>
import { COURSE_PROFILE_ALL_FILTER } from "@/constants"; import ItDropdownSelect from "@/components/ui/ItDropdownSelect.vue";
import type { DropdownSelectable } from "@/types";
import { useTranslation } from "i18next-vue";
import { computed } from "vue";
interface Props { interface Props {
profiles?: string[]; profiles?: string[];
selected?: string; selected?: string;
} }
const allProfile = COURSE_PROFILE_ALL_FILTER;
defineProps<Props>(); const props = defineProps<Props>();
defineEmits(["select"]); const emit = defineEmits(["select"]);
const { t } = useTranslation();
const items = computed(() => {
return props.profiles?.map((p) => ({ id: p, name: t(`profile.${p}`) })) || [];
});
const selectedItem = computed(() => {
if (props.selected) {
return { id: props.selected || "", name: t(`profile.${props.selected}`) };
}
return { id: "", name: "" };
});
const updateFilter = (e: DropdownSelectable) => {
emit("select", e.id);
};
</script> </script>
<template> <template>
<div class="flex-grow"> <div class="flex-grow">
<h5 class="mb-4">Zulassungsprofil:</h5> <h5 class="mb-4">Zulassungsprofil:</h5>
<div class="mb-4 flex gap-4"> <div class="mb-4 flex gap-4">
<button <ItDropdownSelect
v-for="profile in profiles" :items="items"
:key="profile" class="min-w-[18rem]"
:class=" :model-value="selectedItem"
selected == profile || !selected || selected === allProfile @update:model-value="updateFilter"
? 'tag-active' />
: 'tag-inactive'
"
@click="$emit('select', profile)"
>
{{ $t(`profile.${profile}`) }}
</button>
</div> </div>
<a class="link" @click="$emit('select', allProfile)">
Alle anzeigen ({{ $t(`profile.${allProfile}`) }})
</a>
</div> </div>
</template> </template>

View File

@ -136,9 +136,7 @@ class CourseObjectType(DjangoObjectType):
@staticmethod @staticmethod
def resolve_profiles(root: Course, info, **kwargs): def resolve_profiles(root: Course, info, **kwargs):
if root.configuration.is_vv: if root.configuration.is_vv:
return CourseProfile.objects.exclude(id=COURSE_PROFILE_ALL_ID).values_list( return CourseProfile.objects.values_list("code", flat=True)
"code", flat=True
)
return [] return []
@staticmethod @staticmethod