diff --git a/frontend/src/lib/components/ChildrenRegistration.svelte b/frontend/src/lib/components/ChildrenRegistration.svelte index cb4c6824..1b87d617 100644 --- a/frontend/src/lib/components/ChildrenRegistration.svelte +++ b/frontend/src/lib/components/ChildrenRegistration.svelte @@ -3,6 +3,7 @@ import { base } from '$app/paths'; import AlertMessage from '$lib/components/AlertMessage.svelte'; import DataInput from '$lib/components/DataInput/DataInput.svelte'; + import NavigationButtons from '$lib/components/Navigation/NavigationButtons.svelte'; import { children, @@ -14,161 +15,10 @@ import { hash, users } from '$lib/stores/userStore'; - import { - Button, - Card, - Fileupload, - Heading, - Input, - MultiSelect, - Select, - Textarea - } from 'flowbite-svelte'; + import { Card, Heading } from 'flowbite-svelte'; import { onDestroy, onMount } from 'svelte'; - // this can be supplied from the database - export let data = [ - { - component: Input, - value: null, - props: { - type: 'text', - - label: 'Name', - placeholder: 'Bitte eintragen', - key: 'name', - required: true - } - }, - { - component: Input, - value: null, - props: { - type: 'date', - - label: 'Geburtsdatum', - placeholder: 'Bitte eintragen', - key: 'dateOfBirth', - required: true - } - }, - { - component: Select, - value: null, - props: { - label: 'Frühgeburt', - items: ['nein', '0-2 Monate', '2-4 Monate', '4-6 Monate'].map((v) => { - return { name: String(v), value: v }; - }), - placeholder: 'Bitte auswählen', - key: 'bornEarly', - required: true - } - }, - { - component: Select, - value: null, - props: { - label: 'Geschlecht', - items: ['männlich', 'weiblich'].map((v) => { - return { name: String(v), value: v }; - }), - placeholder: 'Bitte auswählen', - key: 'gender', - required: true - } - }, - { - component: MultiSelect, - value: [], - props: { - label: 'Nationalität', - items: ['Andere', 'Deutschland', 'Grossbritannien', 'USA', 'China'].map((v) => { - return { name: String(v), value: v }; - }), - placeholder: 'Bitte auswählen', - key: 'nationality', - required: true, - textTrigger: 'Andere' - } - }, - { - component: MultiSelect, - value: [], - props: { - label: 'Sprache', - items: ['Andere', 'Deutsch', 'Englisch (UK)', 'Englisch (Us)', 'Mandarin', 'Arabisch'].map( - (v) => { - return { name: String(v), value: v }; - } - ), - placeholder: 'Bitte auswählen', - key: 'language', - required: true, - textTrigger: 'Andere' - } - }, - { - component: Select, - value: null, - props: { - label: 'Verhältnis zum Kind', - key: 'relationship', - items: [ - 'Anderes', - 'Kind', - 'Enkelkind', - 'Neffe/Nichte', - 'Pflegekind', - 'Adoptivkind', - 'Betreuung extern', - 'Betreuung zu Hause' - ].map((v) => { - return { name: String(v), value: v }; - }), - placeholder: 'Bitte auswählen', - required: true, - textTrigger: 'Anderes' - } - }, - { - component: MultiSelect, - value: [], - props: { - label: 'Entwicklungsauffälligkeiten', - items: ['keine', 'Hörprobleme', 'Fehlsichtigkeit', 'Sprachfehler', 'Andere'].map((v) => { - return { name: String(v), value: v }; - }), - placeholder: 'Bitte auswählen', - key: 'developmentalIssues', - required: true, - textTrigger: 'Andere' - } - }, - { - component: Textarea, - value: null, - props: { - label: 'Anmerkungen', - placeholder: 'Weitere Bemerkungen', - key: 'remarks', - required: false - } - }, - { - component: Fileupload, - value: null, - props: { - label: 'Foto', - placeholder: 'Bitte wählen sie ein Bild aus falls gewünscht', - key: 'image', - required: false, - accept: ['png', 'jpg', 'svg', 'webp'] - } - } - ]; - // event handlers and verification function export async function submitData() { const verified = await verifyInput(); @@ -182,7 +32,6 @@ current: await createDummyCurrent() }); - console.log(childData); await children.save(); await goto(nextpage as string); } else { @@ -195,6 +44,11 @@ childData = data.reduce((dict: any, curr) => { dict[curr.props.key] = curr.value; + + if (curr.additionalValue !== null) { + dict[curr.props.key + '_additional'] = curr.additionalValue; + } + required[curr.props.key] = curr.props.required; return dict; }, {}); @@ -232,6 +86,8 @@ let unsubscribe: unknown = children.subscribe((childrenlist) => { children.save(); }); + // this can be supplied from the database + export let data: any[]; // rerender page if missing values or showAlert changes $: missingValues = []; @@ -256,6 +112,13 @@ await children.save(); await (unsubscribe as Function)(); }); + + const buttons = [ + { + label: 'Abschließen', + onclick: submitData + } + ]; @@ -287,55 +150,33 @@ {/if} - - {#if heading} - {heading} - {/if} - -
- {#each data as element, i} - {#if element.props.key === 'image'} +
+ + {#if heading} + {heading} + {/if} + + + {#each data as element} { - if (!(event.target === null)) { - const image = event.target.files[0]; - // use https://svelte.dev/repl/b17c13d4f1bb40799ccf09e0841ddd90?version=4.2.19 - let reader = new FileReader(); - reader.readAsDataURL(image); - reader.onload = (e) => { - element.value = e.target.result; - }; - } - } - } - }} - /> - {:else} - - {/if} - {/each} - - - - + {/each} + + + +
diff --git a/frontend/src/lib/components/Childrenpage.svelte b/frontend/src/lib/components/Childrenpage.svelte index f2e523e5..ca34b83b 100644 --- a/frontend/src/lib/components/Childrenpage.svelte +++ b/frontend/src/lib/components/Childrenpage.svelte @@ -31,7 +31,7 @@ 'm-2 max-w-prose bg-primary-700 dark:bg-primary-600 hover:bg-primary-800 dark:hover:bg-primary-700', horizontal: false } - : { horizontal: item.image ? true : false }, + : { horizontal: false }, header: item.header == 'Neu' ? { diff --git a/frontend/src/lib/components/DataInput/DataInput.svelte b/frontend/src/lib/components/DataInput/DataInput.svelte index 9ff2a9c5..386825df 100644 --- a/frontend/src/lib/components/DataInput/DataInput.svelte +++ b/frontend/src/lib/components/DataInput/DataInput.svelte @@ -7,12 +7,12 @@ // variables export let component: any; - export let value: any = null; - export let label: string | null = null; + export let value: any; + export let label: string = null; export let componentClass: string = ''; export let textTrigger: string = 'noAdditionalText'; export let showTextField: boolean = false; - let additionalInput: any = value; + export let additionalInput: any = null; // data to display and event handlers for dynamcis. export let properties: any = {}; @@ -26,51 +26,28 @@ return true; }; - // internal functionality for managing additional information given via textfield - function replaceValue(arrayvalue: any[], target: any, element: any): void { - for (let i = 0; i < arrayvalue.length; i++) { - if (arrayvalue[i] === target && element) { - arrayvalue[i] = element; - } - } - } - - function updateValue(toupdate: any, additionalInput: string): any { - if (showTextField) { - if (toupdate instanceof Array) { - replaceValue(toupdate, textTrigger, additionalInput); - return toupdate; - } else { - return additionalInput as typeof value; - } + // functionality for showing the textfield when the trigger is selected + function checkShowTextfield(v: any): boolean { + if (v instanceof Array) { + return v.includes(textTrigger); } else { - return toupdate; + return v === textTrigger; } } - // functionality for showing the textfield when the trigger is selected - function checkShowTextfield(v: any, trigger: string) { - if (v instanceof Array) { - return v.includes(trigger); - } else { - return v === trigger; + function evalValid(v: any): boolean { + let result = true; + if (Array.isArray(v)) { + result = v.length > 0; } + + return result && value !== undefined && value !== null && value !== '' && checkValid(); } // reactive statement that makes sure 'valid' updates the page - $: valid = value !== undefined && value !== null && value !== '' && checkValid(); + $: valid = evalValid(value); $: highlight = !valid && properties.required === true; - $: showTextField = showTextField || checkShowTextfield(value, textTrigger); - // Flag to track initialization - let initialized = false; - - // Reactive statement to initialize additionalInput based on value - $: { - if (!initialized && value !== null) { - additionalInput = value; - initialized = true; - } - } + $: showTextField = checkShowTextfield(value); {#if label} @@ -81,7 +58,7 @@ {#if showTextField === true} -