From 5e50b85631cfbf6f0f80fb68e89fde8375baa373 Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Tue, 10 Sep 2024 17:11:51 +0200 Subject: [PATCH] cancel changes sometimes resets new entry --- src/components/admin/Permission.vue | 24 ++++++++++++-- .../admin/user/role/RoleListItem.vue | 2 +- .../admin/user/user/UserListItem.vue | 2 +- src/main.css | 4 ++- src/stores/admin/award.ts | 4 ++- src/stores/admin/communicationType.ts | 4 ++- src/stores/admin/executivePosition.ts | 4 ++- src/stores/admin/membershipStatus.ts | 4 ++- src/stores/admin/qualification.ts | 4 ++- src/stores/admin/role.ts | 8 +++-- src/stores/admin/user.ts | 12 +++++-- src/views/admin/settings/AwardEdit.vue | 18 +++++++++-- .../admin/settings/CommunicationTypeEdit.vue | 31 ++++++++++++++----- .../admin/settings/ExecutivePositionEdit.vue | 24 ++++++++++++-- .../admin/settings/MembershipStatusEdit.vue | 18 +++++++++-- .../admin/settings/QualificationEdit.vue | 20 +++++++++--- src/views/admin/user/RoleEdit.vue | 20 +++++++++--- src/views/admin/user/RoleEditPermission.vue | 4 +-- src/views/admin/user/UserEdit.vue | 21 ++++++++----- src/views/admin/user/UserEditPermission.vue | 2 +- src/views/admin/user/UserEditRoles.vue | 16 ++++++++-- 21 files changed, 193 insertions(+), 53 deletions(-) diff --git a/src/components/admin/Permission.vue b/src/components/admin/Permission.vue index 39325f8..3fa54e1 100644 --- a/src/components/admin/Permission.vue +++ b/src/components/admin/Permission.vue @@ -66,8 +66,8 @@
- - + + @@ -111,13 +111,14 @@ export default defineComponent({ default: null, }, }, - emits: ["savePermissions", "abortPermissions"], + emits: ["savePermissions", "resetStatus"], data() { return { isAdmin: false, sections: [] as Array, permissionStructure: {} as SectionsAndModulesObject, permissionUpdate: {} as PermissionObject, + detect_change: false as boolean, }; }, computed: { @@ -132,11 +133,17 @@ export default defineComponent({ }, methods: { toggleAdmin(e: Event) { + this.detect_change = true; + this.$emit("resetStatus"); + const target = e.target as HTMLInputElement; this.isAdmin = target.checked ?? false; this.permissionUpdate.admin = this.isAdmin; }, togglePermission(type: PermissionType, section: PermissionSection, modul?: PermissionModule) { + this.detect_change = true; + this.$emit("resetStatus"); + let permissions = [] as Array | "*"; if (!modul) { permissions = this.permissionUpdate[section]?.all ?? []; @@ -169,6 +176,17 @@ export default defineComponent({ this.permissionUpdate[section][modul] = permissions; } }, + reset() { + this.detect_change = false; + + this.permissionUpdate = _cloneDeep(this.permissions); + this.isAdmin = this.permissions.admin ?? false; + }, + submit() { + this.$emit("savePermissions", this.permissionUpdate); + + this.detect_change = false; + }, }, }); diff --git a/src/components/admin/user/role/RoleListItem.vue b/src/components/admin/user/role/RoleListItem.vue index 33e81fd..1040cea 100644 --- a/src/components/admin/user/role/RoleListItem.vue +++ b/src/components/admin/user/role/RoleListItem.vue @@ -4,7 +4,7 @@

{{ role.role }} (Admin)

diff --git a/src/components/admin/user/user/UserListItem.vue b/src/components/admin/user/user/UserListItem.vue index b175cb5..cf44898 100644 --- a/src/components/admin/user/user/UserListItem.vue +++ b/src/components/admin/user/user/UserListItem.vue @@ -10,7 +10,7 @@ diff --git a/src/main.css b/src/main.css index 6d54f3e..0596a2e 100644 --- a/src/main.css +++ b/src/main.css @@ -71,7 +71,9 @@ a[button][primary-outline]:not([primary-outline="false"]) { @apply border-2 border-primary text-black hover:bg-primary; } -button:disabled { +button:disabled, +a[button]:disabled, +a[button].disabled { @apply opacity-75 pointer-events-none; } diff --git a/src/stores/admin/award.ts b/src/stores/admin/award.ts index 5e45adb..1228150 100644 --- a/src/stores/admin/award.ts +++ b/src/stores/admin/award.ts @@ -61,13 +61,15 @@ export const useAwardStore = defineStore("award", { }, updateActiveAward(award: CreateOrUpdateAwardViewModel) { if (this.award == null) return; + let id = this.award.id; this.updateStatus = "loading"; http - .patch(`/admin/award/${this.award.id}`, { + .patch(`/admin/award/${id}`, { award: award.award, }) .then((result) => { this.updateStatus = { status: "success" }; + this.fetchAwardById(id); this.fetchAwards(); }) .catch((err) => { diff --git a/src/stores/admin/communicationType.ts b/src/stores/admin/communicationType.ts index b3d7af7..ee1345c 100644 --- a/src/stores/admin/communicationType.ts +++ b/src/stores/admin/communicationType.ts @@ -79,14 +79,16 @@ export const useCommunicationTypeStore = defineStore("communicationType", { }, updateActiveCommunicationType(communicationType: CreateOrUpdateCommunicationTypeViewModel) { if (this.communicationType == null) return; + let id = this.communicationType.id; this.updateStatus = "loading"; http - .patch(`/admin/communicationType/${this.communicationType.id}`, { + .patch(`/admin/communicationType/${id}`, { communicationType: communicationType.type, fields: communicationType.fields, }) .then((result) => { this.updateStatus = { status: "success" }; + this.fetchCommunicationTypeById(id); this.fetchCommunicationTypes(); }) .catch((err) => { diff --git a/src/stores/admin/executivePosition.ts b/src/stores/admin/executivePosition.ts index 5115915..5487651 100644 --- a/src/stores/admin/executivePosition.ts +++ b/src/stores/admin/executivePosition.ts @@ -64,13 +64,15 @@ export const useExecutivePositionStore = defineStore("executivePosition", { }, updateActiveExecutivePosition(executivePosition: CreateOrUpdateExecutivePositionViewModel) { if (this.executivePosition == null) return; + let id = this.executivePosition.id; this.updateStatus = "loading"; http - .patch(`/admin/executivePosition/${this.executivePosition.id}`, { + .patch(`/admin/executivePosition/${id}`, { executivePosition: executivePosition.position, }) .then((result) => { this.updateStatus = { status: "success" }; + this.fetchExecutivePositionById(id); this.fetchExecutivePositions(); }) .catch((err) => { diff --git a/src/stores/admin/membershipStatus.ts b/src/stores/admin/membershipStatus.ts index e5696b1..be3c74e 100644 --- a/src/stores/admin/membershipStatus.ts +++ b/src/stores/admin/membershipStatus.ts @@ -64,13 +64,15 @@ export const useMembershipStatusStore = defineStore("membershipStatus", { }, updateActiveMembershipStatus(membershipStatus: CreateOrUpdateMembershipStatusViewModel) { if (this.membershipStatus == null) return; + let id = this.membershipStatus.id; this.updateStatus = "loading"; http - .patch(`/admin/membershipStatus/${this.membershipStatus.id}`, { + .patch(`/admin/membershipStatus/${id}`, { membershipStatus: membershipStatus.status, }) .then((result) => { this.updateStatus = { status: "success" }; + this.fetchMembershipStatusById(id); this.fetchMembershipStatuss(); }) .catch((err) => { diff --git a/src/stores/admin/qualification.ts b/src/stores/admin/qualification.ts index ca27f40..cdd4a64 100644 --- a/src/stores/admin/qualification.ts +++ b/src/stores/admin/qualification.ts @@ -65,14 +65,16 @@ export const useQualificationStore = defineStore("qualification", { }, updateActiveQualification(qualification: CreateOrUpdateQualificationViewModel) { if (this.qualification == null) return; + let id = this.qualification.id; this.updateStatus = "loading"; http - .patch(`/admin/qualification/${this.qualification.id}`, { + .patch(`/admin/qualification/${id}`, { qualification: qualification.qualification, description: qualification.description, }) .then((result) => { this.updateStatus = { status: "success" }; + this.fetchQualificationById(id); this.fetchQualifications(); }) .catch((err) => { diff --git a/src/stores/admin/role.ts b/src/stores/admin/role.ts index d255ffd..3b95f75 100644 --- a/src/stores/admin/role.ts +++ b/src/stores/admin/role.ts @@ -62,13 +62,15 @@ export const useRoleStore = defineStore("role", { }, updateActiveRole(role: string) { if (this.role == null) return; + let id = this.role.id; this.updateStatus = "loading"; http - .patch(`/admin/role/${this.role.id}`, { + .patch(`/admin/role/${id}`, { role: role, }) .then((result) => { this.updateStatus = { status: "success" }; + this.fetchRoleById(id); this.fetchRoles(); }) .catch((err) => { @@ -77,13 +79,15 @@ export const useRoleStore = defineStore("role", { }, updateActiveRolePermissions(permission: PermissionObject) { if (this.role == null) return; + let id = this.role.id; this.updateStatus = "loading"; http - .patch(`/admin/role/${this.role.id}/permissions`, { + .patch(`/admin/role/${id}/permissions`, { permissions: permission, }) .then((result) => { this.updateStatus = { status: "success" }; + this.fetchRoleById(id); this.fetchRoles(); }) .catch((err) => { diff --git a/src/stores/admin/user.ts b/src/stores/admin/user.ts index a6905fd..2022f75 100644 --- a/src/stores/admin/user.ts +++ b/src/stores/admin/user.ts @@ -48,9 +48,10 @@ export const useUserStore = defineStore("user", { }, updateActiveUser(user: CreateOrUpdateUserViewModel) { if (this.user == null) return; + let id = this.user.id; this.updateStatus = "loading"; http - .patch(`/admin/user/${this.user.id}`, { + .patch(`/admin/user/${id}`, { username: user.username, firstname: user.firstname, lastname: user.lastname, @@ -58,6 +59,7 @@ export const useUserStore = defineStore("user", { }) .then((result) => { this.updateStatus = { status: "success" }; + this.fetchUserById(id); this.fetchUsers(); }) .catch((err) => { @@ -66,13 +68,15 @@ export const useUserStore = defineStore("user", { }, updateActiveUserPermissions(permission: PermissionObject) { if (this.user == null) return; + let id = this.user.id; this.updateStatus = "loading"; http - .patch(`/admin/user/${this.user.id}/permissions`, { + .patch(`/admin/user/${id}/permissions`, { permissions: permission, }) .then((result) => { this.updateStatus = { status: "success" }; + this.fetchUserById(id); this.fetchUsers(); }) .catch((err) => { @@ -81,13 +85,15 @@ export const useUserStore = defineStore("user", { }, updateActiveUserRoles(roles: Array) { if (this.user == null) return; + let id = this.user.id; this.updateStatus = "loading"; http - .patch(`/admin/user/${this.user.id}/roles`, { + .patch(`/admin/user/${id}/roles`, { roleIds: roles, }) .then((result) => { this.updateStatus = { status: "success" }; + this.fetchUserById(id); this.fetchUsers(); }) .catch((err) => { diff --git a/src/views/admin/settings/AwardEdit.vue b/src/views/admin/settings/AwardEdit.vue index 619f413..ef62fff 100644 --- a/src/views/admin/settings/AwardEdit.vue +++ b/src/views/admin/settings/AwardEdit.vue @@ -1,7 +1,7 @@