From b9646be0ea736c5f805b5455939a240ce9c12072 Mon Sep 17 00:00:00 2001 From: wvffle Date: Sun, 13 Nov 2022 15:06:50 +0000 Subject: [PATCH] Resolve issues in Application Form --- front/src/components/auth/ApplicationForm.vue | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/front/src/components/auth/ApplicationForm.vue b/front/src/components/auth/ApplicationForm.vue index 3255778a8..d48efd096 100644 --- a/front/src/components/auth/ApplicationForm.vue +++ b/front/src/components/auth/ApplicationForm.vue @@ -2,7 +2,7 @@ import type { BackendError, Application } from '~/types' import axios from 'axios' -import { ref, reactive, computed } from 'vue' +import { ref, reactive, computed, watchEffect } from 'vue' import { computedEager } from '@vueuse/core' import { useGettext } from 'vue3-gettext' import { uniq } from 'lodash-es' @@ -59,8 +59,32 @@ const submit = async () => { } const scopeArray = computed({ - get: () => fields.scopes.split(' '), - set: (scopes: string[]) => uniq(scopes).join(' ') + get: () => fields.scopes.trim().split(' '), + set: (scopes: string[]) => (fields.scopes = uniq(scopes).join(' ')) +}) + +const allScopesSelected = (parent: typeof allScopes['value'][number]) => { + const scopes = new Set(scopeArray.value) + return parent.children.every(child => scopes.has(child.id)) +} + +const toggleAllScopes = (parent: typeof allScopes['value'][number]) => { + const scopes = new Set(scopeArray.value) + + const allScopesSelected = parent.children.every(child => scopes.has(child.id)) + for (const child of parent.children) { + const action = allScopesSelected + ? 'delete' + : 'add' + + scopes[action](child.id) + } + + scopeArray.value = [...scopes] +} + +watchEffect(() => { + console.log(scopeArray.value) }) const scopeParents = computedEager(() => [ @@ -153,9 +177,9 @@ const allScopes = computed(() => {