From 2853835d31e0b4c9b0ffdefcfa25356e2d215f9d Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Mon, 23 Dec 2024 14:00:32 +0100 Subject: [PATCH] template usage to modules --- .../templateUsage/TemplateUsageListItem.vue | 105 ++++++++++++++++++ src/router/adminGuard.ts | 2 +- src/router/index.ts | 7 ++ src/stores/admin/navigation.ts | 12 +- src/stores/admin/template.ts | 8 +- src/stores/admin/templateUsage.ts | 37 ++++++ src/types/permissionTypes.ts | 5 +- src/viewmodels/admin/templateUsage.models.ts | 15 +++ .../settings/templateUsage/TemplateUsage.vue | 37 ++++++ 9 files changed, 221 insertions(+), 7 deletions(-) create mode 100644 src/components/admin/settings/templateUsage/TemplateUsageListItem.vue create mode 100644 src/stores/admin/templateUsage.ts create mode 100644 src/viewmodels/admin/templateUsage.models.ts create mode 100644 src/views/admin/settings/templateUsage/TemplateUsage.vue diff --git a/src/components/admin/settings/templateUsage/TemplateUsageListItem.vue b/src/components/admin/settings/templateUsage/TemplateUsageListItem.vue new file mode 100644 index 0000000..7eb24de --- /dev/null +++ b/src/components/admin/settings/templateUsage/TemplateUsageListItem.vue @@ -0,0 +1,105 @@ + + + + + diff --git a/src/router/adminGuard.ts b/src/router/adminGuard.ts index 27a1c27..33909b5 100644 --- a/src/router/adminGuard.ts +++ b/src/router/adminGuard.ts @@ -19,7 +19,7 @@ export async function abilityAndNavUpdate(to: any, from: any, next: any) { next(); } else { NProgress.done(); - next(false); + next({ name: "admin-default" }); } } diff --git a/src/router/index.ts b/src/router/index.ts index b520eeb..dcf35ef 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -431,6 +431,13 @@ const router = createRouter({ }, ], }, + { + path: "template-usage", + name: "admin-settings-template_usage", + component: () => import("@/views/admin/settings/templateUsage/TemplateUsage.vue"), + meta: { type: "read", section: "settings", module: "template_usage" }, + beforeEnter: [abilityAndNavUpdate], + }, ], }, { diff --git a/src/stores/admin/navigation.ts b/src/stores/admin/navigation.ts index 4385a8f..7cd4604 100644 --- a/src/stores/admin/navigation.ts +++ b/src/stores/admin/navigation.ts @@ -77,8 +77,10 @@ export const useNavigationStore = defineStore("navigation", { ] : []), ]; - if (this.topLevel.findIndex((e) => e.key == this.activeNavigation) == -1 && !first) + if (this.topLevel.findIndex((e) => e.key == this.activeNavigation) == -1) { + this.activeNavigation = this.topLevel[0]?.key ?? "club"; router.push({ name: `admin-${this.topLevel[0]?.key ?? "club"}-default` }); + } }, updateNavigation(first: boolean = false) { const abilityStore = useAbilityStore(); @@ -113,7 +115,10 @@ export const useNavigationStore = defineStore("navigation", { ? [{ key: "calendar_type", title: "Terminarten" }] : []), ...(abilityStore.can("read", "settings", "query") ? [{ key: "query_store", title: "Query Store" }] : []), - ...(true ? [{ key: "template", title: "Templates" }] : []), + ...(abilityStore.can("read", "settings", "template") ? [{ key: "template", title: "Templates" }] : []), + ...(abilityStore.can("read", "settings", "template_usage") + ? [{ key: "template_usage", title: "Template-Verwendung" }] + : []), ], }, user: { @@ -124,8 +129,9 @@ export const useNavigationStore = defineStore("navigation", { ], }, } as navigationModel; - if (this.activeNavigationObject.main.findIndex((e) => e.key == this.activeLink) == -1 && !first) + if (this.activeNavigationObject.main.findIndex((e) => e.key == this.activeLink) == -1) { router.push({ name: `admin-${this.activeNavigation}-default` }); + } }, }, }); diff --git a/src/stores/admin/template.ts b/src/stores/admin/template.ts index 58ef452..13c85bb 100644 --- a/src/stores/admin/template.ts +++ b/src/stores/admin/template.ts @@ -1,12 +1,16 @@ import { defineStore } from "pinia"; import { http } from "@/serverCom"; import type { AxiosResponse } from "axios"; -import type { CreateTemplateViewModel, UpdateTemplateViewModel } from "../../viewmodels/admin/template.models"; +import type { + CreateTemplateViewModel, + TemplateViewModel, + UpdateTemplateViewModel, +} from "../../viewmodels/admin/template.models"; export const useTemplateStore = defineStore("template", { state: () => { return { - templates: [] as Array, + templates: [] as Array, loading: "loading" as "loading" | "fetched" | "failed", }; }, diff --git a/src/stores/admin/templateUsage.ts b/src/stores/admin/templateUsage.ts new file mode 100644 index 0000000..2221bbe --- /dev/null +++ b/src/stores/admin/templateUsage.ts @@ -0,0 +1,37 @@ +import { defineStore } from "pinia"; +import { http } from "@/serverCom"; +import type { AxiosResponse } from "axios"; +import type { CreateTemplateViewModel, UpdateTemplateViewModel } from "../../viewmodels/admin/template.models"; +import type { TemplateUsageViewModel, UpdateTemplateUsageViewModel } from "../../viewmodels/admin/templateUsage.models"; + +export const useTemplateUsageStore = defineStore("templateUsage", { + state: () => { + return { + templateUsages: [] as Array, + loading: "loading" as "loading" | "fetched" | "failed", + }; + }, + actions: { + fetchTemplateUsages() { + this.loading = "loading"; + http + .get("/admin/templateusage") + .then((result) => { + this.templateUsages = result.data; + this.loading = "fetched"; + }) + .catch((err) => { + this.loading = "failed"; + }); + }, + async updateTemplateUsage(templateUsage: UpdateTemplateUsageViewModel): Promise> { + const result = await http.patch(`/admin/templateusage/${templateUsage.scope}`, { + headerId: templateUsage.headerId, + bodyId: templateUsage.bodyId, + footerId: templateUsage.footerId, + }); + this.fetchTemplateUsages(); + return result; + }, + }, +}); diff --git a/src/types/permissionTypes.ts b/src/types/permissionTypes.ts index 62fbc51..34e2be9 100644 --- a/src/types/permissionTypes.ts +++ b/src/types/permissionTypes.ts @@ -15,7 +15,8 @@ export type PermissionModule = | "role" | "query" | "query_store" - | "template"; + | "template" + | "template_usage"; export type PermissionType = "read" | "create" | "update" | "delete"; @@ -55,6 +56,7 @@ export const permissionModules: Array = [ "query", "query_store", "template", + "template_usage", ]; export const permissionTypes: Array = ["read", "create", "update", "delete"]; export const sectionsAndModules: SectionsAndModulesObject = { @@ -68,6 +70,7 @@ export const sectionsAndModules: SectionsAndModulesObject = { "calendar_type", "query_store", "template", + "template_usage", ], user: ["user", "role"], }; diff --git a/src/viewmodels/admin/templateUsage.models.ts b/src/viewmodels/admin/templateUsage.models.ts new file mode 100644 index 0000000..1dabb87 --- /dev/null +++ b/src/viewmodels/admin/templateUsage.models.ts @@ -0,0 +1,15 @@ +import type { PermissionModule } from "../../types/permissionTypes"; + +export interface TemplateUsageViewModel { + scope: PermissionModule; + header: { id: number; template: string } | null; + body: { id: number; template: string } | null; + footer: { id: number; template: string } | null; +} + +export interface UpdateTemplateUsageViewModel { + scope: PermissionModule; + headerId: number | null; + bodyId: number | null; + footerId: number | null; +} diff --git a/src/views/admin/settings/templateUsage/TemplateUsage.vue b/src/views/admin/settings/templateUsage/TemplateUsage.vue new file mode 100644 index 0000000..3b6921e --- /dev/null +++ b/src/views/admin/settings/templateUsage/TemplateUsage.vue @@ -0,0 +1,37 @@ + + + + +