Skip to content

Commit

Permalink
Merge branch 'main' into improve/guide-hygiene-detail
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-intuitem committed Dec 8, 2024
2 parents 4473dea + 7fe81bc commit 62eba5e
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions frontend/src/lib/components/Forms/Score.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,15 @@
export let scores_definition: ScoresDefinition[] = [];
const tables = {};
export let form: SuperForm<Record<string, any>>;
const { value, errors, constraints } = formFieldProxy(form, field);
let isScoredField = formFieldProxy(form, `is_scored`)['value'];
let isScored: boolean;
if ($isScoredField === undefined) {
isScored = $value !== null;
} else {
isScored = $isScoredField;
$value = $value ?? min_score;
}
const isScored = formFieldProxy(form, `is_scored`)['value'];
function handleIsScoredChange() {
if ($isScoredField === undefined) {
$value = isScored ? $value || min_score : null;
} else {
$isScoredField = isScored;
}
}
$: $value = $isScored ? ($value ?? min_score) : $value;
if (always_enabled) {
isScored = true;
$isScored = true;
}
$: if (max_score === 100) score_step = 5;
Expand Down Expand Up @@ -93,21 +78,20 @@
max={max_score}
step={score_step}
ticked
disabled={!isScored}
disabled={!$isScored}
>
<div class="flex justify-between space-x-8 items-center">
{#if !always_enabled}
<SlideToggle
bind:checked={isScored}
on:change={handleIsScoredChange}
bind:checked={$isScored}
class="shrink-0"
active="bg-primary-500"
name="score-slider"
>
<p class="text-sm text-gray-500">{m.scoringHelpText()}</p></SlideToggle
>
{/if}
{#if isScored && scores_definition && $value !== null}
{#if $isScored && scores_definition && $value !== null}
{#each scores_definition as definition}
{#if definition.score === $value}
<p class="w-full max-w-[80ch]">
Expand All @@ -120,20 +104,20 @@
<ProgressRadial
stroke={100}
meter={displayScoreColor($value, max_score, inversedColors)}
value={isScored ? formatScoreValue($value, max_score, fullDonut) : min_score}
value={$isScored ? formatScoreValue($value, max_score, fullDonut) : min_score}
font={115}
class="shrink-0"
width={'w-12'}
>{securityObjectiveDisplay($value) ?? (isScored ? $value : '--')}</ProgressRadial
>{securityObjectiveDisplay($value) ?? ($isScored ? $value : '--')}</ProgressRadial
>
{:else}
<ProgressRadial
stroke={100}
meter={displayScoreColor($value, max_score, inversedColors)}
value={isScored ? formatScoreValue($value, max_score, fullDonut) : min_score}
value={$isScored ? formatScoreValue($value, max_score, fullDonut) : min_score}
font={150}
class="shrink-0"
width={'w-12'}>{isScored ? $value : '--'}</ProgressRadial
width={'w-12'}>{$isScored ? $value : '--'}</ProgressRadial
>
{/if}
</div>
Expand Down

0 comments on commit 62eba5e

Please sign in to comment.