From 4206fcffb385f218fccf23410fb84fbfc839d1af Mon Sep 17 00:00:00 2001 From: Henrik Meyer Date: Wed, 27 Nov 2024 13:59:01 +0100 Subject: [PATCH 1/4] Implement possibility to edit person lock --- src/components/admin/personen/PersonLock.vue | 93 ++++++++++++++++++-- src/locales/de-DE.json | 2 + src/views/admin/PersonDetailsView.vue | 8 +- 3 files changed, 93 insertions(+), 10 deletions(-) diff --git a/src/components/admin/personen/PersonLock.vue b/src/components/admin/personen/PersonLock.vue index c534e97c..4a21a839 100644 --- a/src/components/admin/personen/PersonLock.vue +++ b/src/components/admin/personen/PersonLock.vue @@ -19,6 +19,7 @@ const { mdAndDown }: { mdAndDown: Ref } = useDisplay(); const dialogIsActive: Ref = ref(false); + const isEditMode: Ref = ref(false); type Props = { errorCode: string; @@ -65,7 +66,7 @@ ] = formContext.defineField('selectedBefristung', vuetifyConfig); type Emits = { - (event: 'onLockUser', schule: string, date: string | undefined): void; + (event: 'onLockUser', schule: string, date: string | undefined, isExistingLockToBeEdited: boolean): void; }; const props: Props = defineProps(); const emit: Emits = defineEmits(); @@ -107,6 +108,7 @@ function closeLockPersonDialog(): void { resetBefristungFields(); dialogIsActive.value = false; + isEditMode.value = false; } async function handleOnLockUser(): Promise { @@ -124,7 +126,9 @@ // Format date if provided const dateISO: string | undefined = formatDateToISO(selectedBefristung.value); - emit('onLockUser', lockingOrgId, dateISO); + const isExistingLockToBeEdited: boolean = isEditMode.value; + + emit('onLockUser', lockingOrgId, dateISO, isExistingLockToBeEdited); closeLockPersonDialog(); } @@ -186,7 +190,7 @@ {{ !person.person.isLocked ? $t('person.lockUser') : $t('person.unlockUser') }} - + --> + + + {{ + person.person.userLock?.some((lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT) + ? $t('admin.person.editLock') + : $t('person.lockUser') + }} + - + @@ -240,7 +265,8 @@ @@ -286,6 +312,7 @@ class="justify-center w-full" v-if=" !props.person.person.userLock?.some((lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT) + || props.person.person.userLock?.some((lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT) && isEditMode " > lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT, - ) + ) || props.person.person.userLock?.some((lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT) && isEditMode ? $t('person.lockUserInfoText') : $t('person.unLockUserInfoText') }} @@ -352,6 +379,56 @@ cols="12" sm="6" md="4" + > + + {{ $t('admin.person.editLock') }} + + + + {{ $t('person.lockUser') }} + + + lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT, ) - ? $t('person.unlockUser') + ? $t('admin.person.removeLock') : $t('person.lockUser') }} diff --git a/src/locales/de-DE.json b/src/locales/de-DE.json index c17b43ce..8f85010e 100644 --- a/src/locales/de-DE.json +++ b/src/locales/de-DE.json @@ -163,6 +163,8 @@ "deletePersonSuccessMessage": "{firstname} {lastname} wurde erfolgreich gelöscht.", "discard": "Benutzer verwerfen", "disableUser": "Benutzer sperren", + "editLock": "Sperre bearbeiten", + "removeLock": "Sperre aufheben", "edit": "Benutzer bearbeiten", "editPersonalInfo": "Persönliche Informationen bearbeiten", "errors": { diff --git a/src/views/admin/PersonDetailsView.vue b/src/views/admin/PersonDetailsView.vue index 661dd2b3..9a28e72a 100644 --- a/src/views/admin/PersonDetailsView.vue +++ b/src/views/admin/PersonDetailsView.vue @@ -147,11 +147,15 @@ password.value = personStore.newPassword || ''; } - async function onLockUser(lockedBy: string, date: string | undefined): Promise { + async function onLockUser(lockedBy: string, date: string | undefined, isExistingLockToBeEdited: boolean): Promise { if (!personStore.currentPerson) return; + let lock: boolean; + if (isExistingLockToBeEdited) lock = isManuallyLocked.value; + else lock = !isManuallyLocked.value; + let bodyParams: LockUserBodyParams = { - lock: !isManuallyLocked.value, + lock: lock, locked_by: lockedBy, locked_until: date, }; From b793076cf815e9cc169d2f574d0455c2b0f4d34d Mon Sep 17 00:00:00 2001 From: Henrik Meyer Date: Thu, 28 Nov 2024 10:30:58 +0100 Subject: [PATCH 2/4] Correct format --- src/views/admin/PersonDetailsView.vue | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/views/admin/PersonDetailsView.vue b/src/views/admin/PersonDetailsView.vue index 9a28e72a..c798bcaa 100644 --- a/src/views/admin/PersonDetailsView.vue +++ b/src/views/admin/PersonDetailsView.vue @@ -147,7 +147,11 @@ password.value = personStore.newPassword || ''; } - async function onLockUser(lockedBy: string, date: string | undefined, isExistingLockToBeEdited: boolean): Promise { + async function onLockUser( + lockedBy: string, + date: string | undefined, + isExistingLockToBeEdited: boolean, + ): Promise { if (!personStore.currentPerson) return; let lock: boolean; From 9da0d4c659c3b3e4f12d6dad20b108128025d5b1 Mon Sep 17 00:00:00 2001 From: Henrik Meyer Date: Tue, 3 Dec 2024 10:19:49 +0100 Subject: [PATCH 3/4] Remove comments --- src/components/admin/personen/PersonLock.vue | 29 -------------------- 1 file changed, 29 deletions(-) diff --git a/src/components/admin/personen/PersonLock.vue b/src/components/admin/personen/PersonLock.vue index 4a21a839..37d49504 100644 --- a/src/components/admin/personen/PersonLock.vue +++ b/src/components/admin/personen/PersonLock.vue @@ -190,27 +190,6 @@ {{ !person.person.isLocked ? $t('person.lockUser') : $t('person.unlockUser') }} - - {{ $t('person.lockUser') }} From f9f0daf50e9b70d90b13f70dd6e10259898281b3 Mon Sep 17 00:00:00 2001 From: Henrik Meyer Date: Thu, 12 Dec 2024 09:46:16 +0100 Subject: [PATCH 4/4] Use computed ref --- src/components/admin/personen/PersonLock.vue | 61 ++++++-------------- 1 file changed, 18 insertions(+), 43 deletions(-) diff --git a/src/components/admin/personen/PersonLock.vue b/src/components/admin/personen/PersonLock.vue index 37d49504..54b711ad 100644 --- a/src/components/admin/personen/PersonLock.vue +++ b/src/components/admin/personen/PersonLock.vue @@ -100,6 +100,14 @@ return organisation ? organisation.id : null; }); + const isManuallyLocked: ComputedRef = computed(() => { + return ( + props.person.person.userLock?.some( + (lock: UserLock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT, + ) ?? false // Default to false if userLock is undefined; + ); + }); + function resetBefristungFields(): void { isUnbefristet.value = true; formContext.resetField('selectedBefristung'); @@ -217,11 +225,7 @@ @@ -243,10 +247,7 @@ {{ - !props.person.person.userLock?.some( - (lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT, - ) || props.person.person.userLock?.some((lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT) && isEditMode + !isManuallyLocked || isManuallyLocked && isEditMode ? $t('person.lockUserInfoText') : $t('person.unLockUserInfoText') }} @@ -360,9 +356,7 @@ md="4" > lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT) - || props.person.person.userLock?.some((lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT) && isEditMode - " + v-if="!isManuallyLocked || isManuallyLocked && isEditMode" :block="mdAndDown" class="primary button" - :disabled=" - !props.person.person.userLock?.some( - (lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT, - ) && !selectedOrganisation - " + :disabled="!isManuallyLocked && !selectedOrganisation" @click.stop="onSubmit" data-testid="lock-user-button" > @@ -394,9 +381,7 @@ - {{ - props.person.person.userLock?.some( - (lock) => lock.lock_occasion === PersonLockOccasion.MANUELL_GESPERRT, - ) - ? $t('admin.person.removeLock') - : $t('person.lockUser') - }} + {{ isManuallyLocked ? $t('admin.person.removeLock') : $t('person.lockUser') }}