|
| 1 | +<template> |
| 2 | + <section v-if="isAdmin" style="margin-bottom: 10px"> |
| 3 | + <Toolbar |
| 4 | + :title="exclusionTitle" |
| 5 | + :menu-items="toolbarMenuItems" |
| 6 | + @title-clicked="toggleSection" |
| 7 | + /> |
| 8 | + <v-divider /> |
| 9 | + <Container v-if="sectionExpanded"> |
| 10 | + <v-list> |
| 11 | + <ListItem |
| 12 | + v-for="genre in exclusions" |
| 13 | + :key="genre.item_id" |
| 14 | + show-menu-btn |
| 15 | + @menu.stop="(evt) => onMenu(evt, genre)" |
| 16 | + > |
| 17 | + <template #prepend> |
| 18 | + <div |
| 19 | + style=" |
| 20 | + width: 30px; |
| 21 | + margin-left: 10px; |
| 22 | + margin-right: 10px; |
| 23 | + display: flex; |
| 24 | + align-items: center; |
| 25 | + " |
| 26 | + > |
| 27 | + <Compass :size="30" /> |
| 28 | + </div> |
| 29 | + </template> |
| 30 | + <template #title>{{ |
| 31 | + getGenreDisplayName(genre.name, genre.translation_key, t, te) |
| 32 | + }}</template> |
| 33 | + </ListItem> |
| 34 | + </v-list> |
| 35 | + </Container> |
| 36 | + </section> |
| 37 | +</template> |
| 38 | + |
| 39 | +<script setup lang="ts"> |
| 40 | +import Container from "@/components/Container.vue"; |
| 41 | +import ListItem from "@/components/ListItem.vue"; |
| 42 | +import Toolbar, { ToolBarMenuItem } from "@/components/Toolbar.vue"; |
| 43 | +import { getGenreDisplayName } from "@/helpers/utils"; |
| 44 | +import { api } from "@/plugins/api"; |
| 45 | +import { Genre, MediaType } from "@/plugins/api/interfaces"; |
| 46 | +import { authManager } from "@/plugins/auth"; |
| 47 | +import { eventbus } from "@/plugins/eventbus"; |
| 48 | +import { computed, onBeforeUnmount, onMounted, ref, watch } from "vue"; |
| 49 | +import { useI18n } from "vue-i18n"; |
| 50 | +import { Compass, ChevronUp, ChevronDown } from "lucide-vue-next"; |
| 51 | +
|
| 52 | +interface Props { |
| 53 | + mediaType: MediaType; |
| 54 | + mediaId: string; |
| 55 | +} |
| 56 | +
|
| 57 | +const props = defineProps<Props>(); |
| 58 | +
|
| 59 | +const { t, te } = useI18n(); |
| 60 | +
|
| 61 | +const isAdmin = computed(() => authManager.isAdmin()); |
| 62 | +const sectionExpanded = ref(false); |
| 63 | +const operationInProgress = ref(false); |
| 64 | +const exclusions = ref<Genre[]>([]); |
| 65 | +
|
| 66 | +const exclusionTitle = computed( |
| 67 | + () => `${t("genre_exclusions")} (${exclusions.value.length})`, |
| 68 | +); |
| 69 | +
|
| 70 | +const toolbarMenuItems = computed<ToolBarMenuItem[]>(() => [ |
| 71 | + { |
| 72 | + label: "tooltip.collapse_expand", |
| 73 | + icon: sectionExpanded.value ? ChevronUp : ChevronDown, |
| 74 | + action: toggleSection, |
| 75 | + overflowAllowed: false, |
| 76 | + }, |
| 77 | +]); |
| 78 | +
|
| 79 | +const loadExclusions = async () => { |
| 80 | + try { |
| 81 | + exclusions.value = await api.getGenreExclusionsForItem( |
| 82 | + props.mediaType, |
| 83 | + props.mediaId, |
| 84 | + ); |
| 85 | + } catch { |
| 86 | + exclusions.value = []; |
| 87 | + } |
| 88 | +}; |
| 89 | +
|
| 90 | +const removeExclusion = async (genre: Genre) => { |
| 91 | + operationInProgress.value = true; |
| 92 | + try { |
| 93 | + await api.removeGenreExclusion( |
| 94 | + genre.item_id, |
| 95 | + props.mediaType, |
| 96 | + props.mediaId, |
| 97 | + ); |
| 98 | + exclusions.value = exclusions.value.filter( |
| 99 | + (g) => g.item_id !== genre.item_id, |
| 100 | + ); |
| 101 | + } finally { |
| 102 | + operationInProgress.value = false; |
| 103 | + } |
| 104 | +}; |
| 105 | +
|
| 106 | +const onMenu = (evt: Event, genre: Genre) => { |
| 107 | + const mouseEvt = evt as MouseEvent; |
| 108 | + eventbus.emit("contextmenu", { |
| 109 | + items: [ |
| 110 | + { |
| 111 | + label: "remove_genre_exclusion", |
| 112 | + icon: "mdi-delete", |
| 113 | + action: () => removeExclusion(genre), |
| 114 | + disabled: operationInProgress.value, |
| 115 | + }, |
| 116 | + ], |
| 117 | + posX: mouseEvt.clientX, |
| 118 | + posY: mouseEvt.clientY, |
| 119 | + }); |
| 120 | +}; |
| 121 | +
|
| 122 | +const toggleSection = () => { |
| 123 | + sectionExpanded.value = !sectionExpanded.value; |
| 124 | +}; |
| 125 | +
|
| 126 | +onMounted(() => { |
| 127 | + loadExclusions(); |
| 128 | + eventbus.on("genreExcluded", loadExclusions); |
| 129 | +}); |
| 130 | +
|
| 131 | +onBeforeUnmount(() => { |
| 132 | + eventbus.off("genreExcluded", loadExclusions); |
| 133 | +}); |
| 134 | +
|
| 135 | +watch( |
| 136 | + () => props.mediaId, |
| 137 | + () => loadExclusions(), |
| 138 | +); |
| 139 | +</script> |
0 commit comments