Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add childquestions backend integration and refactor datainput datastructure #138

Merged
merged 103 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
9f71832
add childanswers and base answer model
MaHaWo Oct 29, 2024
4e0311d
add child question models
MaHaWo Oct 29, 2024
6c29ad0
add question admin endpoints
MaHaWo Oct 29, 2024
9c226d5
make current tests work again
MaHaWo Oct 29, 2024
13e8ea9
adjust imports, add test skeleton
MaHaWo Oct 29, 2024
ebf850f
add dummy questions to test fixtures
MaHaWo Oct 29, 2024
c001d85
start working on backend tests
MaHaWo Oct 29, 2024
2866ab9
work more on backend tests and model inheritance
MaHaWo Oct 29, 2024
a5cd5a1
fix errors in test data
MaHaWo Oct 29, 2024
e8772fd
try to get sqlmodel inheritnace to work
MaHaWo Oct 29, 2024
608dc8c
get rid of inheritance in question models for now
MaHaWo Oct 29, 2024
1dbd66b
finish user question tests
MaHaWo Oct 29, 2024
344baca
finish python test draft
MaHaWo Oct 29, 2024
ce18e01
Squashed commit of the following:
MaHaWo Oct 29, 2024
1ea0183
Merge branch 'main' into add-childquestions_backend-integration
MaHaWo Oct 29, 2024
36edc35
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 29, 2024
1c9ded1
update openapi.json & openapi-ts client, run pnpm format
github-actions[bot] Oct 29, 2024
f48067a
refactor away DataInput from user registry and login
MaHaWo Oct 29, 2024
e55df55
Merge branch 'add-childquestions_backend-integration' of github.com:s…
MaHaWo Oct 29, 2024
7cb32f3
update openapi.json & openapi-ts client, run pnpm format
github-actions[bot] Oct 29, 2024
d4334ce
Merge branch 'main' into add-childquestions_backend-integration
MaHaWo Oct 30, 2024
28432c6
update openapi.json & openapi-ts client
github-actions[bot] Oct 30, 2024
09c29c0
fix mistake in register submit function
MaHaWo Oct 30, 2024
e335991
rework UserDataInput to work with backend datastructure
MaHaWo Oct 30, 2024
d444682
Merge branch 'add-childquestions_backend-integration' of github.com:s…
MaHaWo Oct 30, 2024
692d6e9
add childquestion support to admin interface
MaHaWo Oct 30, 2024
fa27752
refactor childrenregistration
MaHaWo Oct 30, 2024
e1d5b39
fix error in question kind prop
MaHaWo Oct 30, 2024
4b537cb
fix childquestion interaction
MaHaWo Oct 30, 2024
2497cc7
change backend childrenanswers to have child_id
MaHaWo Oct 30, 2024
13f4869
update openapi.json & openapi-ts client
github-actions[bot] Oct 30, 2024
5924aed
work on tests for new child answer model
MaHaWo Nov 4, 2024
05c89b5
update openapi.json & openapi-ts client
github-actions[bot] Nov 4, 2024
b46f55c
fix tests
MaHaWo Nov 4, 2024
760a713
Merge branch 'add-childquestions_backend-integration' of github.com:s…
MaHaWo Nov 4, 2024
529479a
remove children backend mock, add backend connection to childrenoverv…
MaHaWo Nov 4, 2024
fb7cd17
update openapi.json & openapi-ts client
github-actions[bot] Nov 4, 2024
8fcd594
fix bug in datainput, add date input
MaHaWo Nov 4, 2024
46b8357
fix python tests
MaHaWo Nov 4, 2024
ce71c8c
Merge branch 'add-childquestions_backend-integration' of github.com:s…
MaHaWo Nov 4, 2024
362b2b1
work on localization, fix search in childrenoverview, add datetime up…
MaHaWo Nov 4, 2024
ae46a4f
fix potential error when json is empty
MaHaWo Nov 5, 2024
fe95e7e
add default questions
MaHaWo Nov 5, 2024
44de62e
work on making image upload and retrieval work
MaHaWo Nov 5, 2024
476fe23
use runes mode for card
MaHaWo Nov 5, 2024
e3977dc
add gitignore element
MaHaWo Nov 5, 2024
519e48a
make image display work
MaHaWo Nov 5, 2024
347eb4c
add comment
MaHaWo Nov 5, 2024
7fa6b8d
add localizations
MaHaWo Nov 5, 2024
48b3dcf
undo accidental deletion
MaHaWo Nov 6, 2024
91051d3
Merge branch 'add-childquestions_backend-integration' of github.com:s…
MaHaWo Nov 6, 2024
0a9cfd1
use childname as heading
MaHaWo Nov 6, 2024
d322d22
fix error when there is already an image for a child
MaHaWo Nov 6, 2024
f161695
simplify setup in overview
MaHaWo Nov 6, 2024
1b4296c
remove superfluous breadcrumbs
MaHaWo Nov 6, 2024
7c6d181
undo some renaming to reduce changes
MaHaWo Nov 6, 2024
1464918
Merge branch 'main' into add-childquestions_backend-integration
MaHaWo Nov 6, 2024
c9cdebf
ajust existing testes
MaHaWo Nov 6, 2024
4dd8b69
update openapi.json & openapi-ts client
github-actions[bot] Nov 6, 2024
a4ff972
work on reducing code duplication
MaHaWo Nov 6, 2024
8e0a0d8
Merge branch 'add-childquestions_backend-integration' of github.com:s…
MaHaWo Nov 6, 2024
97b0072
Merge branch 'main' into add-childquestions_backend-integration
MaHaWo Nov 6, 2024
59f7c61
make default questions uneditable
MaHaWo Nov 6, 2024
bdaa4e7
remove some output, refactor tests to reduce repetition
MaHaWo Nov 6, 2024
aafcaa6
rename children datainput, add delete button for children
MaHaWo Nov 6, 2024
bdb291f
add child questions backend code from pr 138
MaHaWo Nov 6, 2024
4312006
update openapi.json & openapi-ts client
github-actions[bot] Nov 6, 2024
fe73ea3
add get_child and tests
MaHaWo Nov 6, 2024
c9f261f
update openapi.json & openapi-ts client
github-actions[bot] Nov 6, 2024
92e4d62
add tests
MaHaWo Nov 6, 2024
6bb422d
Merge branch 'add-childrenquestion-backend' of github.com:ssciwr/mond…
MaHaWo Nov 6, 2024
3eebee9
start unifying data models for questions, answers
MaHaWo Nov 6, 2024
b73dd50
unify class hierarchy of question, answer models
MaHaWo Nov 6, 2024
2fb4aa7
update openapi.json & openapi-ts client
github-actions[bot] Nov 6, 2024
ef8abed
Merge branch 'add-childrenquestion-backend' into add-childquestions_b…
MaHaWo Nov 6, 2024
ba1e9f7
remove remark from child
MaHaWo Nov 6, 2024
b066c5a
work on making child elements read-only
MaHaWo Nov 6, 2024
ee61263
update openapi.json & openapi-ts client
github-actions[bot] Nov 6, 2024
e5b6fae
put logic form frontend to backend
MaHaWo Nov 7, 2024
7580602
Merge branch 'add-childquestions_backend-integration' of github.com:s…
MaHaWo Nov 7, 2024
4c2d9e9
make tests work
MaHaWo Nov 7, 2024
4e1b779
update openapi.json & openapi-ts client
github-actions[bot] Nov 7, 2024
b832f79
Merge branch 'main' into add-childquestions_backend-integration
MaHaWo Nov 7, 2024
e1a6f5d
make the child data members explicit in frontend
MaHaWo Nov 7, 2024
9a2a60d
make submission work again
MaHaWo Nov 7, 2024
104d8e9
add update option for child
MaHaWo Nov 7, 2024
fd21a4b
update openapi.json & openapi-ts client
github-actions[bot] Nov 7, 2024
0756b35
undo unnecessary changes
MaHaWo Nov 8, 2024
3a046a5
Merge branch 'add-childquestions_backend-integration' of github.com:s…
MaHaWo Nov 8, 2024
f906194
correct answer augmentation
MaHaWo Nov 8, 2024
72bc04f
add sonarcloud, undo backend reset
MaHaWo Nov 8, 2024
d1c7737
try to reduce clutter
MaHaWo Nov 8, 2024
660f066
work on child image retrieval and retention
MaHaWo Nov 8, 2024
3dcb73a
add image deletion logic
MaHaWo Nov 8, 2024
217d349
change var name
MaHaWo Nov 8, 2024
0404618
change image varialbe working
MaHaWo Nov 8, 2024
367d272
correct some mistakes, reduce changes
MaHaWo Nov 8, 2024
32304c9
Merge branch 'main' into add-childquestions_backend-integration
MaHaWo Nov 8, 2024
cfc08cc
fix wrong function ordering
MaHaWo Nov 8, 2024
7eef02c
add corrections
MaHaWo Nov 8, 2024
e8c12e9
remove test of branch that no longer exists
MaHaWo Nov 8, 2024
cc6b817
add dummy image file and respective changes to how images are treated
MaHaWo Nov 8, 2024
926b612
make tests work again
MaHaWo Nov 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ services:
volumes:
- ${STATIC_FILES_PATH:-./static}:/app/static
- ${DATABASE_PATH:-./db}:/app/db
- ${PRIVATE_FILES_PATH:-./private}:/app/private
MaHaWo marked this conversation as resolved.
Show resolved Hide resolved
environment:
- SECRET=${SECRET:-}
- DATA_FILES_PATH=/app/data
- STATIC_FILES_PATH=/app/static
MaHaWo marked this conversation as resolved.
Show resolved Hide resolved
- PRIVATE_FILES_PATH=/app/private
- DATABASE_PATH=/app/db
- ENABLE_CORS=${ENABLE_CORS:-false}
- HOST=${HOST:-backend}
Expand Down
21 changes: 17 additions & 4 deletions frontend/src/lib/admin.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import {
authCookieLogin,
getChildQuestionsAdmin,
getMilestoneGroupsAdmin,
getUserQuestionsAdmin,
usersCurrentUser,
} from "$lib/client/services.gen";
import type {
Body_auth_cookie_login_auth_login_post,
GetLanguagesResponse,
MilestoneGroupAdmin,
UserQuestionAdmin,
UserRead,
} from "$lib/client/types.gen";
import { milestoneGroups, userQuestions } from "$lib/stores/adminStore";
import {
childQuestions,
milestoneGroups,
userQuestions,
} from "$lib/stores/adminStore";

function AdminUser() {
let user = $state(null as UserRead | null);
Expand Down Expand Up @@ -70,3 +72,14 @@ export async function refreshUserQuestions() {
userQuestions.set(data);
}
}

export async function refreshChildQuestions() {
console.log("refreshQuestions...");
const { data, error } = await getChildQuestionsAdmin();
if (error || data === undefined) {
console.log("Failed to get child questions");
childQuestions.set([]);
} else {
childQuestions.set(data);
}
}
10 changes: 9 additions & 1 deletion frontend/src/lib/client/services.gen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file is auto-generated by @hey-api/openapi-ts

import { createClient, createConfig, type Options, formDataBodySerializer, urlSearchParamsBodySerializer } from '@hey-api/client-fetch';
import type { GetLanguagesError, GetLanguagesResponse, GetMilestonesError, GetMilestonesResponse, GetMilestoneData, GetMilestoneError, GetMilestoneResponse, GetMilestoneGroupsData, GetMilestoneGroupsError, GetMilestoneGroupsResponse, GetUserQuestionsError, GetUserQuestionsResponse, GetChildQuestionsError, GetChildQuestionsResponse, CreateLanguageData, CreateLanguageError, CreateLanguageResponse, DeleteLanguageData, DeleteLanguageError, DeleteLanguageResponse, UpdateI18NData, UpdateI18NError, UpdateI18NResponse, GetMilestoneGroupsAdminError, GetMilestoneGroupsAdminResponse, CreateMilestoneGroupAdminError, CreateMilestoneGroupAdminResponse, UpdateMilestoneGroupAdminData, UpdateMilestoneGroupAdminError, UpdateMilestoneGroupAdminResponse, DeleteMilestoneGroupAdminData, DeleteMilestoneGroupAdminError, DeleteMilestoneGroupAdminResponse, UploadMilestoneGroupImageData, UploadMilestoneGroupImageError, UploadMilestoneGroupImageResponse, CreateMilestoneData, CreateMilestoneError, CreateMilestoneResponse, UpdateMilestoneData, UpdateMilestoneError, UpdateMilestoneResponse, DeleteMilestoneData, DeleteMilestoneError, DeleteMilestoneResponse, UploadMilestoneImageData, UploadMilestoneImageError, UploadMilestoneImageResponse, GetUserQuestionsAdminError, GetUserQuestionsAdminResponse, UpdateUserQuestionData, UpdateUserQuestionError, UpdateUserQuestionResponse, CreateUserQuestionError, CreateUserQuestionResponse, DeleteUserQuestionData, DeleteUserQuestionError, DeleteUserQuestionResponse, GetChildQuestionsAdminError, GetChildQuestionsAdminResponse, UpdateChildQuestionData, UpdateChildQuestionError, UpdateChildQuestionResponse, CreateChildQuestionError, CreateChildQuestionResponse, DeleteChildQuestionData, DeleteChildQuestionError, DeleteChildQuestionResponse, UsersCurrentUserError, UsersCurrentUserResponse, UsersPatchCurrentUserData, UsersPatchCurrentUserError, UsersPatchCurrentUserResponse, UsersUserData, UsersUserError, UsersUserResponse, UsersPatchUserData, UsersPatchUserError, UsersPatchUserResponse, UsersDeleteUserData, UsersDeleteUserError, UsersDeleteUserResponse, GetChildrenError, GetChildrenResponse, UpdateChildData, UpdateChildError, UpdateChildResponse, CreateChildData, CreateChildError, CreateChildResponse, GetChildData, GetChildError, GetChildResponse, DeleteChildData, DeleteChildError, DeleteChildResponse, GetChildImageData, GetChildImageError, GetChildImageResponse, UploadChildImageData, UploadChildImageError, UploadChildImageResponse, GetCurrentMilestoneAnswerSessionData, GetCurrentMilestoneAnswerSessionError, GetCurrentMilestoneAnswerSessionResponse, UpdateMilestoneAnswerData, UpdateMilestoneAnswerError, UpdateMilestoneAnswerResponse, GetCurrentUserAnswersError, GetCurrentUserAnswersResponse, UpdateCurrentUserAnswersData, UpdateCurrentUserAnswersError, UpdateCurrentUserAnswersResponse, GetCurrentChildAnswersData, GetCurrentChildAnswersError, GetCurrentChildAnswersResponse, UpdateCurrentChildAnswersData, UpdateCurrentChildAnswersError, UpdateCurrentChildAnswersResponse, AuthCookieLoginData, AuthCookieLoginError, AuthCookieLoginResponse, AuthCookieLogoutError, AuthCookieLogoutResponse, RegisterRegisterData, RegisterRegisterError, RegisterRegisterResponse, ResetForgotPasswordData, ResetForgotPasswordError, ResetForgotPasswordResponse, ResetResetPasswordData, ResetResetPasswordError, ResetResetPasswordResponse, VerifyRequestTokenData, VerifyRequestTokenError, VerifyRequestTokenResponse, VerifyVerifyData, VerifyVerifyError, VerifyVerifyResponse, AuthError, AuthResponse } from './types.gen';
import type { GetLanguagesError, GetLanguagesResponse, GetMilestonesError, GetMilestonesResponse, GetMilestoneData, GetMilestoneError, GetMilestoneResponse, GetMilestoneGroupsData, GetMilestoneGroupsError, GetMilestoneGroupsResponse, GetUserQuestionsError, GetUserQuestionsResponse, GetChildQuestionsError, GetChildQuestionsResponse, CreateLanguageData, CreateLanguageError, CreateLanguageResponse, DeleteLanguageData, DeleteLanguageError, DeleteLanguageResponse, UpdateI18NData, UpdateI18NError, UpdateI18NResponse, GetMilestoneGroupsAdminError, GetMilestoneGroupsAdminResponse, CreateMilestoneGroupAdminError, CreateMilestoneGroupAdminResponse, UpdateMilestoneGroupAdminData, UpdateMilestoneGroupAdminError, UpdateMilestoneGroupAdminResponse, DeleteMilestoneGroupAdminData, DeleteMilestoneGroupAdminError, DeleteMilestoneGroupAdminResponse, UploadMilestoneGroupImageData, UploadMilestoneGroupImageError, UploadMilestoneGroupImageResponse, CreateMilestoneData, CreateMilestoneError, CreateMilestoneResponse, UpdateMilestoneData, UpdateMilestoneError, UpdateMilestoneResponse, DeleteMilestoneData, DeleteMilestoneError, DeleteMilestoneResponse, UploadMilestoneImageData, UploadMilestoneImageError, UploadMilestoneImageResponse, GetUserQuestionsAdminError, GetUserQuestionsAdminResponse, UpdateUserQuestionData, UpdateUserQuestionError, UpdateUserQuestionResponse, CreateUserQuestionError, CreateUserQuestionResponse, DeleteUserQuestionData, DeleteUserQuestionError, DeleteUserQuestionResponse, GetChildQuestionsAdminError, GetChildQuestionsAdminResponse, UpdateChildQuestionData, UpdateChildQuestionError, UpdateChildQuestionResponse, CreateChildQuestionError, CreateChildQuestionResponse, DeleteChildQuestionData, DeleteChildQuestionError, DeleteChildQuestionResponse, UsersCurrentUserError, UsersCurrentUserResponse, UsersPatchCurrentUserData, UsersPatchCurrentUserError, UsersPatchCurrentUserResponse, UsersUserData, UsersUserError, UsersUserResponse, UsersPatchUserData, UsersPatchUserError, UsersPatchUserResponse, UsersDeleteUserData, UsersDeleteUserError, UsersDeleteUserResponse, GetChildrenError, GetChildrenResponse, UpdateChildData, UpdateChildError, UpdateChildResponse, CreateChildData, CreateChildError, CreateChildResponse, GetChildData, GetChildError, GetChildResponse, DeleteChildData, DeleteChildError, DeleteChildResponse, GetChildImageData, GetChildImageError, GetChildImageResponse, UploadChildImageData, UploadChildImageError, UploadChildImageResponse, DeleteChildImageData, DeleteChildImageError, DeleteChildImageResponse, GetCurrentMilestoneAnswerSessionData, GetCurrentMilestoneAnswerSessionError, GetCurrentMilestoneAnswerSessionResponse, UpdateMilestoneAnswerData, UpdateMilestoneAnswerError, UpdateMilestoneAnswerResponse, GetCurrentUserAnswersError, GetCurrentUserAnswersResponse, UpdateCurrentUserAnswersData, UpdateCurrentUserAnswersError, UpdateCurrentUserAnswersResponse, GetCurrentChildAnswersData, GetCurrentChildAnswersError, GetCurrentChildAnswersResponse, UpdateCurrentChildAnswersData, UpdateCurrentChildAnswersError, UpdateCurrentChildAnswersResponse, AuthCookieLoginData, AuthCookieLoginError, AuthCookieLoginResponse, AuthCookieLogoutError, AuthCookieLogoutResponse, RegisterRegisterData, RegisterRegisterError, RegisterRegisterResponse, ResetForgotPasswordData, ResetForgotPasswordError, ResetForgotPasswordResponse, ResetResetPasswordData, ResetResetPasswordError, ResetResetPasswordResponse, VerifyRequestTokenData, VerifyRequestTokenError, VerifyRequestTokenResponse, VerifyVerifyData, VerifyVerifyError, VerifyVerifyResponse, AuthError, AuthResponse } from './types.gen';

export const client = createClient(createConfig());

Expand Down Expand Up @@ -324,6 +324,14 @@ export const uploadChildImage = <ThrowOnError extends boolean = false>(options:
url: '/users/children-images/{child_id}'
}); };

/**
* Delete Child Image
*/
export const deleteChildImage = <ThrowOnError extends boolean = false>(options: Options<DeleteChildImageData, ThrowOnError>) => { return (options?.client ?? client).delete<DeleteChildImageResponse, DeleteChildImageError, ThrowOnError>({
...options,
url: '/users/children-images/{child_id}'
}); };

/**
* Get Current Milestone Answer Session
*/
Expand Down
18 changes: 16 additions & 2 deletions frontend/src/lib/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,16 @@ export type UploadChildImageResponse = (unknown);

export type UploadChildImageError = (HTTPValidationError);

export type DeleteChildImageData = {
path: {
child_id: number;
};
};

export type DeleteChildImageResponse = (unknown);

export type DeleteChildImageError = (HTTPValidationError);

export type GetCurrentMilestoneAnswerSessionData = {
path: {
child_id: number;
Expand Down Expand Up @@ -608,12 +618,16 @@ export type GetCurrentChildAnswersData = {
};
};

export type GetCurrentChildAnswersResponse = (Array<ChildAnswerPublic>);
export type GetCurrentChildAnswersResponse = ({
[key: string]: ChildAnswerPublic;
});

export type GetCurrentChildAnswersError = (HTTPValidationError);

export type UpdateCurrentChildAnswersData = {
body: Array<ChildAnswerPublic>;
body: {
[key: string]: ChildAnswerPublic;
};
path: {
child_id: number;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<svelte:options runes={true} />

<script lang="ts">
import { refreshUserQuestions } from "$lib/admin.svelte";
import { updateUserQuestion } from "$lib/client/services.gen";
import type { UserQuestionAdmin } from "$lib/client/types.gen";
import { refreshChildQuestions, refreshUserQuestions } from "$lib/admin.svelte";
import {
updateChildQuestion,
updateUserQuestion,
} from "$lib/client/services.gen";
import type {
ChildQuestionAdmin,
UserQuestionAdmin,
} from "$lib/client/types.gen";
import CancelButton from "$lib/components/Admin/CancelButton.svelte";
import InputPreview from "$lib/components/Admin/InputPreview.svelte";
import SaveButton from "$lib/components/Admin/SaveButton.svelte";
Expand All @@ -24,13 +30,31 @@ import { _, locales } from "svelte-i18n";

let {
open = $bindable(false),
userQuestion,
}: { open: boolean; userQuestion: UserQuestionAdmin | undefined } = $props();

question,
kind,
}: {
open: boolean;
question: UserQuestionAdmin | ChildQuestionAdmin | undefined;
kind: string;
} = $props();
let preview_lang = $state("de");
let preview_answer = $state("");
let update: any;
let refresh: any;

if (kind === "user") {
update = updateUserQuestion;
refresh = refreshUserQuestions;
} else if (kind === "child") {
update = updateChildQuestion;
refresh = refreshChildQuestions;
} else {
console.log(
"Error, kind must be either 'user' or 'child', currently is: ",
kind,
);
}

// FIXME: use the componentTable here
const inputTypes: Array<SelectOptionType<string>> = [
{ value: "textarea", name: "text" },
{ value: "select", name: "select" },
Expand All @@ -39,48 +63,50 @@ const inputTypes: Array<SelectOptionType<string>> = [
];

function updateOptionsJson() {
if (!userQuestion) {
if (!question) {
return;
}
const values = userQuestion.options.split(";");
const values = question.options.split(";");
for (const lang_id of $locales) {
const items = userQuestion.text[lang_id].options.split(";");
userQuestion.text[lang_id].options_json = JSON.stringify(
values.map((value, index) => ({ value: value, name: items[index] })),
const items = question.text[lang_id].options.split(";");
question.text[lang_id].options_json = JSON.stringify(
values.map((value, index) => ({
value: value,
name: items[index],
})),
);
}
}

async function saveChanges() {
if (!userQuestion) {
if (!question) {
return;
}
const { data, error } = await updateUserQuestion({ body: userQuestion });
const { data, error } = await update({
body: question,
});
if (error) {
console.log(error);
} else {
console.log(data);
await refreshUserQuestions();
await refresh();
}
}
</script>

<Modal title="Edit user question" bind:open autoclose size="xl">
{#if userQuestion}
{#if question}
<div class="flex flex-row items-center">
<div class="mr-5 grow">
<div class="mb-5">
<Label class="mb-2">{$_('admin.question')}</Label>
{#each Object.values(userQuestion.text) as text}
<Label class="mb-2">{$_("admin.question")}</Label>
{#each Object.values(question.text) as text}
<div class="mb-1">
<ButtonGroup class="w-full">
<InputAddon>{text.lang_id}</InputAddon>
<Input
bind:value={text.question}
on:input={() => {
userQuestion = userQuestion;
}}
placeholder={$_('admin.placeholder')}
placeholder={$_("admin.placeholder")}
/>
</ButtonGroup>
</div>
Expand All @@ -91,25 +117,24 @@ async function saveChanges() {
<Select
class="mt-2"
items={inputTypes}
bind:value={userQuestion.component}
bind:value={question.component}
placeholder=""
/>
</div>
{#if userQuestion.component === 'select'}
{#if question.component === "select"}
<div class="mb-5">
<Label class="mb-2">Options</Label>
<div class="mb-1">
<ButtonGroup class="w-full">
<InputAddon>Option values</InputAddon>
<Textarea
bind:value={userQuestion.options}
bind:value={question.options}
on:input={updateOptionsJson}
placeholder="Option values"
/>
</ButtonGroup>
</div>
{#each Object.values(userQuestion.text) as text}
{console.log('text: ', text)}
{#each Object.values(question.text) as text}
<div class="mb-1">
<ButtonGroup class="w-full">
<InputAddon>{text.lang_id}</InputAddon>
Expand All @@ -125,7 +150,7 @@ async function saveChanges() {
<div class="mb-1">
<ButtonGroup class="w-full">
<Textarea
bind:value={userQuestion.additional_option}
bind:value={question.additional_option}
placeholder="Displayed additional option"
/>
</ButtonGroup>
Expand All @@ -151,10 +176,11 @@ async function saveChanges() {
</ButtonGroup>
</div>
<Card class="mb-4 bg-blue-300">
<InputPreview data={userQuestion} lang={preview_lang} bind:answer={preview_answer} />
<InputPreview data={question} lang={preview_lang} bind:answer={preview_answer} />
</Card>
<Label class="mb-2">Generated answer:</Label>
<Badge large border color="dark">{preview_answer}</Badge>
<Badge large border color="dark">{preview_answer}</Badge
>
</div>
</Card>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/components/Admin/InputPreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Input, Label, Select, type SelectOptionType } from "flowbite-svelte";
let {
data,
lang,
answer,
answer = $bindable(),
}: { data: UserQuestionAdmin; lang: string; answer: string } = $props();
let items: Array<SelectOptionType<string>> = $derived(parse_options_json());

Expand Down
Loading