From 1ab979b5b48062d138cd11eb932403788ecf785f Mon Sep 17 00:00:00 2001 From: Markus Brueckner Date: Sat, 8 Feb 2025 08:38:44 +0100 Subject: [PATCH] implement survey review mode Closes #19 --- src/lib/components/Button.svelte | 2 +- src/lib/components/Diagram.svelte | 26 +++-- src/lib/components/icons/Eye.svelte | 15 +++ src/lib/components/icons/EyeSlash.svelte | 14 +++ .../(app)/survey/[surveyId]/+page.svelte | 98 +++++++++++-------- 5 files changed, 103 insertions(+), 52 deletions(-) create mode 100644 src/lib/components/icons/Eye.svelte create mode 100644 src/lib/components/icons/EyeSlash.svelte diff --git a/src/lib/components/Button.svelte b/src/lib/components/Button.svelte index 3de5d61..d9ace36 100644 --- a/src/lib/components/Button.svelte +++ b/src/lib/components/Button.svelte @@ -11,7 +11,7 @@ primary: 'bg-sky-200 hover:bg-sky-300 text-black border border-black rounded', secondary: 'bg-slate-200 hover:bg-slate-300 text-black border border-black rounded', tertiary: 'bg-white hover:bg-slate-100 text-black border border-slate-500 rounded', - ghost: 'bg-white hover:bg-slate-100 text-sky-600' + ghost: 'bg-none hover:bg-slate-100 text-sky-600' }; diff --git a/src/lib/components/Diagram.svelte b/src/lib/components/Diagram.svelte index bcc5de3..1bc9456 100644 --- a/src/lib/components/Diagram.svelte +++ b/src/lib/components/Diagram.svelte @@ -4,11 +4,12 @@ import { flatGroup } from 'd3-array'; import { Axis, Chart, Points, Spline, Svg } from 'layerchart'; - const { - data - }: { + type Props = { + reviewMode: boolean; data: { skill: string; participant: number; rating: number | undefined }[]; - } = $props(); + }; + + const { data, reviewMode }: Props = $props(); const averageValues = flatGroup(data, (d) => d.skill) .map(([skill, ratings]) => { @@ -34,6 +35,15 @@ { stroke: 'stroke-cyan-300', fill: 'fill-cyan-400' }, { stroke: 'stroke-pink-300', fill: 'fill-pink-400' } ]; + + const anonymousColor = { stroke: 'stroke-slate-300', fill: 'fill-slate-400' }; + + function getColor(idx: number) { + if (reviewMode) { + return anonymousColor; + } + return colors[idx % colors.length]; + }
@@ -59,13 +69,9 @@ - + {/each} + + + diff --git a/src/lib/components/icons/EyeSlash.svelte b/src/lib/components/icons/EyeSlash.svelte new file mode 100644 index 0000000..2251ec3 --- /dev/null +++ b/src/lib/components/icons/EyeSlash.svelte @@ -0,0 +1,14 @@ + + + diff --git a/src/routes/(app)/survey/[surveyId]/+page.svelte b/src/routes/(app)/survey/[surveyId]/+page.svelte index 32e8383..4b6829b 100644 --- a/src/routes/(app)/survey/[surveyId]/+page.svelte +++ b/src/routes/(app)/survey/[surveyId]/+page.svelte @@ -17,6 +17,9 @@ import ShareIcon from '$lib/components/icons/ShareIcon.svelte'; import { checkAccess } from '$lib/helpers/shared/permissions'; import { AccessLevel, type ParticipantId } from '$lib/types'; + import Button from '$lib/components/Button.svelte'; + import EyeSlash from '$lib/components/icons/EyeSlash.svelte'; + import Eye from '$lib/components/icons/Eye.svelte'; let { data }: { data: PageData } = $props(); @@ -45,8 +48,7 @@ let deleteAnswersDialogRef: HTMLDialogElement | null = $state(null); let participantAnswersDeletionCandidateId = $state(null); - - $inspect(data); + let reviewMode = $state(false); async function deleteSurvey() { await fetch('', { @@ -61,6 +63,18 @@ + {#if checkAccess(data, AccessLevel.Clone)} {/if} -

Participants

-
    - {#each data.participants as participant} -
  • - - {participant.email} - {#if participant.answers.length > 0} - +{#if !reviewMode} +

    Participants

    +
      + {#each data.participants as participant} +
    • + + {participant.email} + {#if participant.answers.length > 0} + + {/if} + + {#if participant.accessToken} + {/if} - - {#if participant.accessToken} - - {/if} - {#if participant.answers.length > 0} - - {/if} -
    • - {/each} -
    + {#if participant.answers.length > 0} + + {/if} +
  • + {/each} +
+{/if} {#if checkAccess(data, AccessLevel.ReadResult)}
- +
{:else}
You do not have permission to see the survey results