Skip to content

Commit

Permalink
work on data integration
Browse files Browse the repository at this point in the history
  • Loading branch information
MaHaWo committed Oct 22, 2024
1 parent 92537d3 commit e1e19d0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
6 changes: 5 additions & 1 deletion frontend/src/lib/components/DataInput/DataInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
export let textTrigger: string = 'noAdditionalText';
export let showTextField: boolean = false;
export let additionalInput: any = null;
export let disabled: boolean = false;
// data to display and event handlers for dynamcis.
export let properties: any = {};
Expand Down Expand Up @@ -53,6 +54,7 @@
$: valid = evalValid(value);
$: highlight = !valid && properties.required === true;
$: showTextField = checkShowTextfield(value);
$: console.log('disabled field: ', disabled);
</script>

{#if label}
Expand All @@ -62,8 +64,9 @@
<div class="space-y-4">
<svelte:component
this={component}
{disabled}
class={highlight
? 'rounded border-2 border-primary-600 dark:border-primary-600 ' + componentClass
? 'border-primary-600 dark:border-primary-600 rounded border-2 ' + componentClass
: componentClass}
bind:value
{...properties}
Expand All @@ -74,6 +77,7 @@

{#if showTextField === true}
<Textarea
{disabled}
bind:value={additionalInput}
on:blur={additionalEventHandlers['on:blur']}
on:change={additionalEventHandlers['on:change']}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/lib/components/DataInput/RadioList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
dispatch('click', { value: event.target.value });
}
export let value: any;
export let disabled: boolean = false;
let windowWidth = 1920;
$: smallScreen = windowWidth < 800;
</script>
Expand All @@ -27,6 +28,7 @@
{#each $$props.items as item, index}
<RadioButton
class="mx-2"
{disabled}
bind:group={value}
value={item.value}
on:change={handleChange}
Expand All @@ -38,6 +40,7 @@
{#each $$props.items as item, index}
<Radio
class="mx-2"
{disabled}
bind:group={value}
value={item.value}
on:change={handleChange}
Expand Down
26 changes: 20 additions & 6 deletions frontend/src/lib/components/UserDataInput.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@
// disable all elements to make editing a conscious choice
for (let element of data) {
element.props.disabled = true;
element.disabled = true;
}
currentDataSubmitted = true;
dataIsCurrent = true;
}
}
Expand All @@ -78,14 +78,16 @@
// flags for enabling and disabling visual hints
let showAlert: boolean = false;
let currentDataSubmitted: boolean = false;
let dataIsCurrent: boolean = false;
$: reload = false;
// what is shown in the alert if showAlert === true
let alertMessage: string = $_('userData.alertMessageMissing');
// load questions and current answers from server and put them into the data
// structure that the UserDataInput component understands
onMount(async () => {
console.log('onmount');
const currentUser = await usersCurrentUser();
if (currentUser.error) {
Expand Down Expand Up @@ -135,10 +137,20 @@
console.log('data from backend: ', 'currentAnswers: ', currentAnswers?.data);
for (let i = 0; i < data.length; i++) {
data[i].value = currentAnswers.data[i].answer;
data[i].disabled = true;
dataIsCurrent = true;
}
}
}
console.log('onmount done');
reload = true;
});
console.log(
'data: ',
data.map((e) => {
e.value;
})
);
</script>

<!-- Show big alert message when something is missing -->
Expand Down Expand Up @@ -182,17 +194,19 @@
}}
/>
{/each}
{#if currentDataSubmitted === true}
{#if dataIsCurrent === true}
<Button
type="button"
class="dark:bg-primay-700 bg-primary-700 hover:bg-primary-800 dark:hover:bg-primary-800 w-full text-center text-sm text-white hover:text-white"
on:click={() => {
console.log('dataiscurrent click');
for (let element of data) {
element.props.disabled = false;
element.disabled = false;
}
dataIsCurrent = false;
}}
>
<div class="flex items-center justify-center">$_('userData.changeData')</div>
<div class="flex items-center justify-center">{$_('userData.changeData')}</div>
</Button>
{:else}
<Button
Expand Down
16 changes: 14 additions & 2 deletions frontend/src/routes/userLand/userLandingpage/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
if (asItems) {
return values.map((v) => {
return { name: String(v), value: v };
return { name: String(v), value: String(v) };
});
} else {
return values;
Expand All @@ -25,7 +25,7 @@
if (asItems) {
return values.map((v) => {
return { name: String(v), value: v };
return { name: String(v), value: String(v) };
});
} else {
return values;
Expand All @@ -37,6 +37,8 @@
component: Select,
value: null,
additionalValue: null,
disabled: false,
showTextField: false,
props: {
name: $_('userData.yearOfBirth.label'),
items: numericalRange(60, 1960, 1, true),
Expand All @@ -50,6 +52,8 @@
component: RadioList,
value: null,
additionalValue: null,
disabled: false,
showTextField: false,
props: {
name: $_('userData.gender.label'),
items: [
Expand All @@ -72,6 +76,8 @@
component: Select,
value: null,
additionalValue: null,
disabled: false,
showTextField: false,
props: {
name: $_('userData.education.label'),
items: [
Expand All @@ -97,6 +103,8 @@
component: Select,
value: null,
additionalValue: null,
disabled: false,
showTextField: false,
props: {
name: $_('userData.workingHours.label'),
items: intervalRange(13, 0, 5, true),
Expand All @@ -111,6 +119,8 @@
component: Select,
value: null,
additionalValue: null,
disabled: false,
showTextField: false,
props: {
name: $_('userData.incomePerYear.label'),
items: intervalRange(23, 0, 5000, true),
Expand All @@ -125,6 +135,8 @@
component: Input,
value: null,
additionalValue: null,
disabled: false,
showTextField: false,
props: {
name: $_('userData.profession.label'),
type: 'text',
Expand Down

0 comments on commit e1e19d0

Please sign in to comment.