Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 7c01dce
Merge: 7ac5c7b 4e2a2ec
Author: Harald Mack <[email protected]>
Date:   Thu Nov 14 13:39:39 2024 +0100

    Merge branch 'integrate-milestones-userland-with-backend' of github.com:ssciwr/mondey into integrate-milestones-userland-with-backend

commit 7ac5c7b
Author: Harald Mack <[email protected]>
Date:   Thu Nov 14 13:39:35 2024 +0100

    remove debug output

commit 4e2a2ec
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Thu Nov 14 12:39:35 2024 +0000

    update openapi.json & openapi-ts client

commit c9e4d97
Author: Harald Mack <[email protected]>
Date:   Thu Nov 14 13:38:11 2024 +0100

    put progress computation into frontend

commit 44100b0
Author: Harald Mack <[email protected]>
Date:   Thu Nov 14 12:59:41 2024 +0100

    fix styling issue

commit e233c63
Author: Harald Mack <[email protected]>
Date:   Thu Nov 14 12:47:22 2024 +0100

    remove searchByMilestone

commit 670bf04
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Thu Nov 14 09:39:33 2024 +0000

    update openapi.json & openapi-ts client

commit 02841be
Author: Harald Mack <[email protected]>
Date:   Thu Nov 14 10:38:46 2024 +0100

    work on layout

commit 109ec0e
Author: Harald Mack <[email protected]>
Date:   Thu Nov 14 10:04:29 2024 +0100

    use tailwind for making labels visible/invisible

commit 42d239c
Author: Harald Mack <[email protected]>
Date:   Thu Nov 14 10:03:21 2024 +0100

    correct merge error

commit 1e481ac
Author: Harald Mack <[email protected]>
Date:   Wed Nov 13 16:17:06 2024 +0100

    fix tests

commit 6079925
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Wed Nov 13 15:06:43 2024 +0000

    update openapi.json & openapi-ts client

commit d207bab
Merge: 4b4a7e7 1496a3a
Author: Harald Mack <[email protected]>
Date:   Wed Nov 13 16:05:52 2024 +0100

    Merge branch 'main' into integrate-milestones-userland-with-backend

commit 4b4a7e7
Author: Harald Mack <[email protected]>
Date:   Wed Nov 13 15:42:41 2024 +0100

    adjust tests

commit 77ea2eb
Author: Harald Mack <[email protected]>
Date:   Wed Nov 13 15:24:26 2024 +0100

    fix backend error

commit 036f4ce
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Wed Nov 13 13:14:35 2024 +0000

    update openapi.json & openapi-ts client

commit 2f64c56
Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date:   Wed Nov 13 13:13:52 2024 +0000

    [pre-commit.ci] auto fixes from pre-commit.com hooks

    for more information, see https://pre-commit.ci

commit ef560b7
Merge: 8fad755 43bf1b3
Author: Harald Mack <[email protected]>
Date:   Wed Nov 13 14:13:26 2024 +0100

    Merge branch 'main' into integrate-milestones-userland-with-backend

commit 8fad755
Author: Harald Mack <[email protected]>
Date:   Wed Nov 13 14:06:02 2024 +0100

    fix child data loading bug, adjust breadcrumb navigation

commit b6e1452
Author: Harald Mack <[email protected]>
Date:   Wed Nov 13 13:47:15 2024 +0100

    work on styling, change navigation to something hopefully more intuitive, make more use of localization

commit 3012086
Author: Harald Mack <[email protected]>
Date:   Tue Nov 12 19:00:06 2024 +0100

    adjust styling

commit eb136b3
Author: Harald Mack <[email protected]>
Date:   Tue Nov 12 14:38:56 2024 +0100

    simplify progress computation, include milestone completion feedback

commit efae46f
Author: Harald Mack <[email protected]>
Date:   Tue Nov 12 13:28:56 2024 +0100

    modify progress reporting to be only a userland feature

commit 1dd97f7
Author: Harald Mack <[email protected]>
Date:   Tue Nov 12 11:46:21 2024 +0100

    add completion status to the milestone models

commit 06b6a2a
Author: Harald Mack <[email protected]>
Date:   Tue Nov 12 11:41:54 2024 +0100

    fix card styling, error message

commit 4e58cf8
Author: Harald Mack <[email protected]>
Date:   Mon Nov 11 16:56:51 2024 +0100

    integrate milestone

commit 166c18f
Author: Harald Mack <[email protected]>
Date:   Mon Nov 11 15:44:20 2024 +0100

    get milestone loading right

commit 7db9480
Author: Harald Mack <[email protected]>
Date:   Mon Nov 11 11:10:51 2024 +0100

    adjust milestonegroup to backend data

commit e7709d5
Author: Harald Mack <[email protected]>
Date:   Mon Nov 11 09:53:32 2024 +0100

    make use of states

commit 84c3f17
Author: Harald Mack <[email protected]>
Date:   Mon Nov 11 09:03:59 2024 +0100

    Squashed commit of the following:

    commit 43bf1b3
    Author: Liam Keegan <[email protected]>
    Date:   Mon Nov 11 08:17:47 2024 +0100

        Add admin option to delete milestone images (#150)

        * Add admin option to delete milestone images

        - add delete button below existing milestone images in admin interface
        - add delete /milestone-images endpoint
        - restate /admin route for convenience during development, can be removed again later
        - resolves #98

        * update openapi.json & openapi-ts client

        ---------

        Co-authored-by: Harald Mack <[email protected]>
        Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

    commit 33d4f17
    Author: Harald Mack <[email protected]>
    Date:   Fri Nov 8 17:23:58 2024 +0100

        Add childquestions backend integration and refactor datainput datastructure (#138)

        * add childanswers and base answer model

        * add child question models

        * add question admin endpoints

        * make current tests work again

        * adjust imports, add test skeleton

        * add dummy questions to test fixtures

        * start working on backend tests

        * work more on backend tests and model inheritance

        * fix errors in test data

        * try to get sqlmodel inheritnace to work

        * get rid of inheritance in question models for now

        * finish user question tests

        * finish python test draft

commit d900c19
Author: Harald Mack <[email protected]>
Date:   Mon Nov 11 08:56:33 2024 +0100

    work on localization, add setup-await pattern to milestoneoverview

commit be2393d
Author: Harald Mack <[email protected]>
Date:   Fri Nov 8 15:30:24 2024 +0100

    make data a member of currentChild for now, start integrating backend calls

commit 2254332
Author: Harald Mack <[email protected]>
Date:   Fri Nov 8 14:51:20 2024 +0100

    merge add-childquestion_backend-integration until
    32304c9
  • Loading branch information
MaHaWo committed Nov 14, 2024
1 parent 4509b2e commit d5109d5
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 116 deletions.
4 changes: 2 additions & 2 deletions frontend/src/lib/components/ChildrenGallery.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import CardDisplay from "$lib/components/DataDisplay/CardDisplay.svelte";
import GalleryDisplay from "$lib/components/DataDisplay/GalleryDisplay.svelte";
import { currentChild } from "$lib/stores/childrenStore.svelte";
import { activeTabChildren } from "$lib/stores/componentStore";
import { Heading } from "flowbite-svelte";
import { Heading, Spinner } from "flowbite-svelte";
import { _ } from "svelte-i18n";
import AlertMessage from "./AlertMessage.svelte";
Expand Down Expand Up @@ -126,7 +126,7 @@ const searchData = [
</script>

{#await promise}
<p>{"Waiting for server response"}</p>
<Spinner /> <p>{$_("userData.loadingMessage")}</p>
{:then data}
{#if showAlert}
<AlertMessage
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/components/Milestone.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ const breadcrumbdata = $derived([
<Breadcrumbs data={breadcrumbdata} />

<div class="flex w-full flex-col md:flex-row">
<div>
<div class = "relative w-full h-48 md:h-96 md:w-48 lg:w-72 xl:w-96 overflow-hidden">
{#each currentMilestone.images as image, imageIndex}
<img
class={`h-48 w-full object-cover transition pb-4 mb-4 duration-1000 ease-in-out md:h-96 md:w-48 md:rounded-bl-lg lg:w-72 xl:w-96 ${imageIndex === currentImageIndex ? 'opacity-100' : 'opacity-0'}`}
class={`absolute top-0 left-0 w-full h-full object-cover transition duration-1000 ease-in-out ${imageIndex === currentImageIndex ? 'opacity-100' : 'opacity-0'}`}
src={`${import.meta.env.VITE_MONDEY_API_URL}/static/${image.filename}`}
alt=""
/>
Expand Down
117 changes: 74 additions & 43 deletions frontend/src/lib/components/MilestoneGroup.svelte
Original file line number Diff line number Diff line change
@@ -1,32 +1,75 @@
<svelte:options runes={true} />
<script lang="ts">
import { getMilestoneGroups } from "$lib/client";
import {
type MilestoneAnswerSessionPublic,
type MilestonePublic,
getCurrentMilestoneAnswerSession,
getMilestoneGroups,
} from "$lib/client";
import CardDisplay from "$lib/components/DataDisplay/CardDisplay.svelte";
import GalleryDisplay from "$lib/components/DataDisplay/GalleryDisplay.svelte";
import Breadcrumbs from "$lib/components/Navigation/Breadcrumbs.svelte";
import { currentChild } from "$lib/stores/childrenStore.svelte";
import { activeTabChildren } from "$lib/stores/componentStore";
import { contentStore } from "$lib/stores/contentStore.svelte";
import { Spinner } from "flowbite-svelte";
import {
RectangleListOutline,
UserSettingsOutline,
} from "flowbite-svelte-icons";
import { _, locale } from "svelte-i18n";
import AlertMessage from "./AlertMessage.svelte";
let showAlert = $state(false);
let alertMessage = $state("");
let promise = $state(setup());
let data: any[] = $state([]);
function computeProgress(
milestones: MilestonePublic[],
answerSession: MilestoneAnswerSessionPublic,
): number {
if (milestones.length === 0) {
return 0;
} else {
const progress = milestones.reduce((p, item) => {
if (
answerSession.answers[item.id] !== undefined &&
answerSession.answers[item.id].answer !== null &&
answerSession.answers[item.id].answer >= 0
) {
console.log(
" found answer: ",
item.id,
answerSession.answers[item.id].answer,
);
return p + 1.0;
} else {
return p;
}
}, 0.0);
if (progress < 0.01) {
return 0.01;
} else {
return progress / milestones.length;
}
}
}
async function setup(): Promise<any> {
await currentChild.load_data();
console.log("currentChild", currentChild);
console.log("child data: ", currentChild.name);
const milestonegroups = await getMilestoneGroups({
path: { child_id: currentChild.id },
});
const answerSession = await getCurrentMilestoneAnswerSession({
path: { child_id: currentChild.id },
});
if (answerSession.error) {
console.log("Error when retrieving answer data");
showAlert = true;
alertMessage =
$_("milestone.alertMessageRetrieving") + answerSession.error.detail;
data = [];
return data;
}
if (milestonegroups.error) {
console.log("Error when retrieving milestone group data");
showAlert = true;
Expand All @@ -46,7 +89,7 @@ async function setup(): Promise<any> {
header: item.text[$locale].title,
summary: item.text[$locale].desc,
image: null,
progress: item.progress < 0.01 ? 0.01 : item.progress,
progress: computeProgress(item.milestones, answerSession.data),
events: {
onclick: () => {
activeTabChildren.set("milestoneOverview");
Expand Down Expand Up @@ -112,28 +155,39 @@ function searchBySurveyTitle(data: any[], key: string): any[] {
}
}
function searchByMilestone(data: any[], key: string): any[] {
if (key === "") {
return data;
} else {
return data.filter((item) => {
return true; // TODO: implement search by milestone
});
}
}
// README: this is slow and quite a bit of work because a lot of text has to be searched. Kill it?
function searchAll(data: any[], key: string): any[] {
return [
...new Set([
...searchByStatus(data, key),
...searchBySurveyTitle(data, key),
...searchByMilestone(data, key),
...searchBySurveyDescription(data, key),
]),
];
}
export function createStyle(data: any[]) {
return data.map((item) => {
return {
card: {
class:
"m-2 max-w-prose dark:text-white text-white hover:cursor-pointer bg-primary-700 dark:bg-primary-900 hover:bg-primary-800 dark:hover:bg-primary-700",
},
progress: {
labelInside: true,
size: "h-4",
divClass: `h-full rounded-full w-${100 * item.progress}`,
color: "red",
completeColor: "green",
},
};
});
}
let showAlert = $state(false);
let alertMessage = $state("");
let promise = $state(setup());
let data: any[] = $state([]);
const searchData: any[] = [
{
label: $_("search.allLabel"),
Expand All @@ -150,39 +204,16 @@ const searchData: any[] = [
placeholder: $_("search.surveyPlaceholder"),
filterFunction: searchBySurveyTitle,
},
{
label: $_("search.milestoneLabel"),
placeholder: $_("search.milestonePlaceholder"),
filterFunction: searchByMilestone,
},
{
label: $_("search.statusLabel"),
placeholder: $_("search.statusPlaceholder"),
filterFunction: searchByStatus,
},
];
export function createStyle(data: any[]) {
return data.map((item) => {
return {
card: {
class:
"m-2 max-w-prose dark:text-white text-white hover:cursor-pointer bg-primary-700 dark:bg-primary-900 hover:bg-primary-800 dark:hover:bg-primary-700",
},
progress: {
labelInside: true,
size: "h-4",
divClass: `h-full rounded-full w-${100 * item.progress}`,
color: "red",
completeColor: "green",
},
};
});
}
</script>

{#await promise}
<p>{"Waiting for setup to finish"}</p>
<Spinner /> <p>{$_("userData.loadingMessage")}</p>
{:then data}
<div class="flex flex-col md:rounded-t-lg">
<Breadcrumbs data={breadcrumbdata} />
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/lib/components/MilestoneOverview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ function searchStatus(data: any[], key: string): any[] {
} else {
return data.filter((item) => {
// button label contains info about completion status => use for search
if (key === $_("milestone.complete")) {
} else if (key === $_("milestone.incomplete")) {
if (key === $_("milestone.complete").toLowerCase()) {
return item.complete === true;
} else {
return item.complete === false;
}
});
}
Expand Down Expand Up @@ -83,9 +85,12 @@ async function setup(): Promise<void> {
!contentStore.milestoneGroupData.milestones ||
contentStore.milestoneGroupData.milestones.length === 0
) {
console.log("Error when retrieving milestone groups");
console.log(
"Error when retrieving milestone groups ",
contentStore.milestoneGroupData,
);
showAlert = true;
alertMessage = $_("milestoneGroup.alertMessageRetrieving");
alertMessage = $_("milestone.alertMessageRetrieving");
} else {
let milestoneAnswerSession = undefined;
const response = await getCurrentMilestoneAnswerSession({
Expand Down
16 changes: 4 additions & 12 deletions frontend/src/lib/components/Navigation/Breadcrumbs.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import { Breadcrumb, BreadcrumbItem } from "flowbite-svelte";
import { PlayOutline } from "flowbite-svelte-icons";
let { data }: { data: any[] } = $props();
let windowWidth = $state(1920);
let smallScreen = $derived(windowWidth < 800);
</script>
<svelte:window bind:innerWidth={windowWidth} />

Expand All @@ -22,22 +19,17 @@ let smallScreen = $derived(windowWidth < 800);
>
<div class="flex items-center justify-center">
{#if item.href}
{#if smallScreen === true}
<svelte:component this = {item?.symbol ?? PlayOutline} size = "xl" />
{:else}
{item.label}
{/if}
<svelte:component this = {item?.symbol ?? PlayOutline} size = "xl" />
<span class="hidden md:inline">{item.label} </span>
{:else}
<button
class="text-lg ms-1 font-medium text-gray-700 hover:text-gray-900 md:ms-2 dark:text-gray-400 dark:hover:text-white"
onclick={item.onclick}
>
<div class="flex items-center justify-center">
{#if smallScreen === true}
<svelte:component this = {item?.symbol ?? PlayOutline} size = "xl" />
{:else}
{item.label}
{/if}
<span class="hidden md:inline">{item.label}</span>
</div>
</button>
{/if}
</div>
Expand Down
19 changes: 4 additions & 15 deletions frontend/src/lib/components/UserLandingPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import AdminPage from "./AdminPage.svelte";
import UserDataInput from "./UserDataInput.svelte";
onMount(user.load);
let windowWidth = $state(1920);
let smallScreen = $derived(windowWidth < 800);
</script>
<svelte:window bind:innerWidth={windowWidth} />

{#if user.data}
{#if user.data?.is_verified === true}
Expand All @@ -27,9 +24,7 @@ let smallScreen = $derived(windowWidth < 800);
<TabItem open={true}>
<div slot="title" class="flex items-center gap-2 text-lg">
<ProfileCardSolid size="lg" />
{#if smallScreen === false}
{$_("userData.label")}
{/if}
<span class="hidden md:inline">{$_("userData.label")}</span>
</div>
<UserDataInput />
</TabItem>
Expand All @@ -38,9 +33,7 @@ let smallScreen = $derived(windowWidth < 800);
}}>
<div slot="title" class="flex items-center gap-2 text-lg">
<GridPlusSolid size="lg" />
{#if smallScreen === false}
{$_("childData.overviewLabel")}
{/if}
<span class="hidden md:inline">{$_("childData.overviewLabel")}</span>
</div>
<svelte:component
this={componentTable[$activeTabChildren]}
Expand All @@ -54,9 +47,7 @@ let smallScreen = $derived(windowWidth < 800);
class="flex items-center gap-2 text-lg"
>
<CogSolid size="lg" />
{#if smallScreen === false}
{$_("admin.label")}
{/if}
<span class="hidden md:inline">{$_("admin.label")}</span>
</div>
<AdminPage />
</TabItem>
Expand All @@ -68,9 +59,7 @@ let smallScreen = $derived(windowWidth < 800);
class="flex items-center gap-2 text-lg"
>
<AtomOutline size="lg" />
{#if smallScreen === false}
{$_("researcher.label")}
{/if}
<span class="hidden md:inline">{$_("researcher.label")}</span>
</div>
<Card />
</TabItem>
Expand Down
38 changes: 1 addition & 37 deletions mondey_backend/src/mondey_backend/routers/milestones.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from .utils import get
from .utils import get_child_age_in_months
from .utils import get_db_child
from .utils import get_or_create_current_milestone_answer_session


def create_router() -> APIRouter:
Expand Down Expand Up @@ -71,41 +70,6 @@ def get_milestone_groups(
)
).all()

# compute progress from milestone answers. While this is not
# the most efficient way, it is the least intrusive and concentrates
# progress reporting in the least amount of code - this function and the
# MilestonAnswerPublic model.
# The actual database does not need to know about progress - it's
# a derived value only for being displayed to the user.

answer_session = get_or_create_current_milestone_answer_session(
session, current_active_user, child_id
)

milestone_groups_public = []
for mgroup in milestone_groups:
mgroup_public = MilestoneGroupPublic(
id=mgroup.id,
order=mgroup.order,
text=mgroup.text,
milestones=mgroup.milestones,
)
mgroup_public.progress = 0.0

if len(mgroup.milestones) > 0:
for milestone in mgroup.milestones:
if milestone.id is None:
continue

answer = answer_session.answers.get(milestone.id)

if answer is not None and answer.answer >= 0:
mgroup_public.progress += 1.0

mgroup_public.progress /= len(mgroup.milestones)

milestone_groups_public.append(mgroup_public)

return milestone_groups_public
return milestone_groups

return router
1 change: 0 additions & 1 deletion mondey_backend/tests/routers/test_milestones.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ def test_get_milestone_groups_child2(
assert len(response.json()) == 2
# child 2 age is 20 months old, so first milestone from group1 (18m):
milestone_group1["milestones"] = milestone_group1["milestones"][0:1]
milestone_group1["progress"] = 0.0

# and first milestone from group2 (24m):
milestone_group2["milestones"] = milestone_group2["milestones"][0:1]
Expand Down

0 comments on commit d5109d5

Please sign in to comment.