template usage to modules

This commit is contained in:
Julian Krauser 2024-12-23 14:00:32 +01:00
parent 600bb47260
commit 2853835d31
9 changed files with 221 additions and 7 deletions

View file

@ -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` });
}
},
},
});

View file

@ -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<any>,
templates: [] as Array<TemplateViewModel>,
loading: "loading" as "loading" | "fetched" | "failed",
};
},

View file

@ -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<TemplateUsageViewModel>,
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<AxiosResponse<any, any>> {
const result = await http.patch(`/admin/templateusage/${templateUsage.scope}`, {
headerId: templateUsage.headerId,
bodyId: templateUsage.bodyId,
footerId: templateUsage.footerId,
});
this.fetchTemplateUsages();
return result;
},
},
});