2024-09-02 15:57:03 +02:00
|
|
|
<template>
|
|
|
|
<MainTemplate>
|
|
|
|
<template #headerInsert>
|
|
|
|
<RouterLink to="../" class="text-primary">zurück zur Liste</RouterLink>
|
|
|
|
</template>
|
|
|
|
<template #topBar>
|
|
|
|
<div class="flex flex-row items-center justify-between pt-5 pb-3 px-7">
|
|
|
|
<h1 class="font-bold text-xl h-8">Nutzer {{ user?.username }} - Berechtigungen bearbeiten</h1>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<template #main>
|
2024-09-15 13:52:54 +02:00
|
|
|
<Spinner v-if="loading == 'loading'" class="mx-auto" />
|
|
|
|
<p v-else-if="loading == 'failed'">laden fehlgeschlagen</p>
|
2024-09-02 15:57:03 +02:00
|
|
|
<Permission
|
2024-09-15 13:52:54 +02:00
|
|
|
v-else-if="user != null"
|
|
|
|
:permissions="user.permissions"
|
|
|
|
:status="status"
|
|
|
|
@savePermissions="triggerUpdate"
|
2024-09-02 15:57:03 +02:00
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</MainTemplate>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { defineComponent } from "vue";
|
|
|
|
import { mapState, mapActions } from "pinia";
|
|
|
|
import MainTemplate from "@/templates/Main.vue";
|
|
|
|
import Permission from "@/components/admin/Permission.vue";
|
|
|
|
import Spinner from "@/components/Spinner.vue";
|
|
|
|
import { useUserStore } from "@/stores/admin/user";
|
|
|
|
import type { PermissionObject } from "@/types/permissionTypes";
|
2024-09-15 13:52:54 +02:00
|
|
|
import type { UserViewModel } from "@/viewmodels/admin/user.models";
|
2024-09-02 15:57:03 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
export default defineComponent({
|
|
|
|
props: {
|
|
|
|
id: String,
|
|
|
|
},
|
2024-09-15 13:52:54 +02:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
loading: "loading" as "loading" | "fetched" | "failed",
|
|
|
|
status: null as null | "loading" | { status: "success" | "failed"; reason?: string },
|
|
|
|
user: null as null | UserViewModel,
|
|
|
|
timeout: null as any,
|
|
|
|
};
|
2024-09-02 15:57:03 +02:00
|
|
|
},
|
|
|
|
mounted() {
|
2024-09-15 13:52:54 +02:00
|
|
|
this.fetchItem();
|
|
|
|
},
|
|
|
|
beforeUnmount() {
|
|
|
|
try {
|
|
|
|
clearTimeout(this.timeout);
|
|
|
|
} catch (error) {}
|
2024-09-02 15:57:03 +02:00
|
|
|
},
|
|
|
|
methods: {
|
2024-09-15 13:52:54 +02:00
|
|
|
...mapActions(useUserStore, ["fetchUserById", "updateActiveUserPermissions"]),
|
|
|
|
fetchItem() {
|
|
|
|
this.fetchUserById(parseInt(this.id ?? ""))
|
|
|
|
.then((result) => {
|
|
|
|
this.user = result.data;
|
|
|
|
this.loading = "fetched";
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
this.loading = "failed";
|
|
|
|
});
|
|
|
|
},
|
|
|
|
triggerUpdate(e: PermissionObject) {
|
|
|
|
if (this.user == null) return;
|
|
|
|
this.status = "loading";
|
|
|
|
this.updateActiveUserPermissions(this.user.id, e)
|
|
|
|
.then(() => {
|
|
|
|
this.fetchItem();
|
|
|
|
this.status = { status: "success" };
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
this.status = { status: "failed" };
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.timeout = setTimeout(() => {
|
|
|
|
this.status = null;
|
|
|
|
}, 2000);
|
|
|
|
});
|
2024-09-02 15:57:03 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|