Skip to content

Commit

Permalink
Leave scores initially unset, and show progress of filling out. Layout
Browse files Browse the repository at this point in the history
is questionable.
  • Loading branch information
dabreegster committed Mar 12, 2024
1 parent e53fc23 commit 614fcb9
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 73 deletions.
7 changes: 2 additions & 5 deletions src/routes/area_check/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,8 @@ export function emptyState(): State {
schemeAreaSizeKm2: "",
notes: "",
},
// The default settings for the radio buttons go from worst to best case
existingScores: Array(13).fill("0"),
proposedScores: [4, 4, 4, 4, 4, 4, 4, 4, 8, 16, 12, 16, 16].map((x) =>
x.toString(),
),
existingScores: Array(13).fill(""),
proposedScores: Array(13).fill(""),
existingScoreNotes: Array(13).fill(""),
proposedScoreNotes: Array(13).fill(""),
};
Expand Down
41 changes: 2 additions & 39 deletions src/routes/area_check/scorecard/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,37 +1,9 @@
<script lang="ts">
import { Breadcrumbs, ExternalLink } from "$lib";
import Question from "./Question.svelte";
import { base } from "$app/paths";
import Progress from "./Progress.svelte";
import { state } from "../data";
// TODO Include bold in the choices
$: totalExisting = sum($state.existingScores.map((x) => parseInt(x)));
$: totalProposed = sum($state.proposedScores.map((x) => parseInt(x)));
function sum(list: number[]): number {
return list.reduce((total, x) => total + x, 0);
}
let questions = [
"Porosity - Walking and Wheeling",
"Porosity - Cycling",
"Crossings - Walking and Wheeling",
"Crossings - Cycling",
"Permeability - Walking and Wheeling",
"Permeability - Cycling",
"Mesh Density - Walking and Wheeling",
"Mesh Density - Cycling",
"Motorised Through-Traffic",
"Perimeter Treatment Design",
"Green Infrastructure Design",
"Other Internal Treatment Design",
"Engagement Practice",
];
function formatIndex(idx: number): string {
return (idx + 1).toString().padStart(2, "0");
}
</script>

<div class="govuk-prose">
Expand All @@ -43,14 +15,5 @@
current="Area Scorecard"
/>

<p>Total existing score: {totalExisting}</p>
<p>Total proposed score: {totalProposed}</p>

<ol>
{#each questions as label, idx}
<li>
<a href="{base}/area_check/scorecard/q{formatIndex(idx)}">{label}</a>
</li>
{/each}
</ol>
<Progress />
</div>
57 changes: 57 additions & 0 deletions src/routes/area_check/scorecard/Progress.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<script lang="ts">
import { state, type State } from "../data";
import { base } from "$app/paths";
let questions = [
"Porosity - Walking and Wheeling",
"Porosity - Cycling",
"Crossings - Walking and Wheeling",
"Crossings - Cycling",
"Permeability - Walking and Wheeling",
"Permeability - Cycling",
"Mesh Density - Walking and Wheeling",
"Mesh Density - Cycling",
"Motorised Through-Traffic",
"Perimeter Treatment Design",
"Green Infrastructure Design",
"Other Internal Treatment Design",
"Engagement Practice",
];
function formatIndex(idx: number): string {
return (idx + 1).toString().padStart(2, "0");
}
$: completed = getCompleted($state);
function getCompleted(_: State): boolean[] {
return Array.from(Array(questions.length).keys()).map(
(idx) =>
$state.existingScores[idx] != "" && $state.proposedScores[idx] != "",
);
}
$: totalExisting = sum($state.existingScores.map((x) => parseInt(x || "0")));
$: totalProposed = sum($state.proposedScores.map((x) => parseInt(x || "0")));
function sum(list: number[]): number {
return list.reduce((total, x) => total + x, 0);
}
</script>

<p>Total existing score: {totalExisting}</p>
<p>Total proposed score: {totalProposed}</p>

<ol>
{#each questions as label, idx}
<li>
<div style="display: flex; justify-content: space-between">
<a href="{base}/area_check/scorecard/q{formatIndex(idx)}">{label}</a>
{#if completed[idx]}
<strong class="govuk-tag govuk-tag--green">Done</strong>
{:else}
<strong class="govuk-tag govuk-tag--red">Incomplete</strong>
{/if}
</div>
</li>
{/each}
</ol>
66 changes: 37 additions & 29 deletions src/routes/area_check/scorecard/Question.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Breadcrumbs } from "$lib";
import PrevNext from "./PrevNext.svelte";
import FancyRadio from "./FancyRadio.svelte";
import Progress from "./Progress.svelte";
import { TextArea } from "govuk-svelte";
import { state } from "../data";
Expand All @@ -26,36 +27,43 @@
current={label}
/>

<div class="govuk-width-container">
<PrevNext {idx} />
<h2>{label}</h2>
<slot />

<div class="govuk-grid-row">
<div class="govuk-grid-column-one-half">
<FancyRadio
legend="Existing"
{choices}
bind:value={$state.existingScores[idx - 1]}
/>
<TextArea
label="Notes"
bind:value={$state.existingScoreNotes[idx - 1]}
/>
</div>
<div class="govuk-grid-column-one-half">
<FancyRadio
legend="Proposed"
{choices}
bind:value={$state.proposedScores[idx - 1]}
/>
<TextArea
label="Notes"
bind:value={$state.proposedScoreNotes[idx - 1]}
/>
</div>
<PrevNext {idx} />
<h2>{label}</h2>
<slot />

<div class="three-columns">
<div>
<Progress />
</div>

<PrevNext {idx} />
<div>
<FancyRadio
legend="Existing"
{choices}
bind:value={$state.existingScores[idx - 1]}
/>
<TextArea label="Notes" bind:value={$state.existingScoreNotes[idx - 1]} />
</div>
<div>
<FancyRadio
legend="Proposed"
{choices}
bind:value={$state.proposedScores[idx - 1]}
/>
<TextArea label="Notes" bind:value={$state.proposedScoreNotes[idx - 1]} />
</div>
</div>

<PrevNext {idx} />
</div>

<style>
.three-columns {
display: flex;
column-gap: 2rem;
}
.three-columns > * {
width: calc((100% - 4rem) / 3);
}
</style>

0 comments on commit 614fcb9

Please sign in to comment.