Skip to content

Commit

Permalink
put radio just on modal, and make it include _all relevant_ guidance)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter York committed Aug 6, 2024
1 parent adc7d4d commit 83d749f
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 138 deletions.
199 changes: 168 additions & 31 deletions src/routes/route_check/jat_check/guidance/Guidance.svelte
Original file line number Diff line number Diff line change
@@ -1,47 +1,184 @@
<script lang="ts">
import { Radio } from "govuk-svelte";
import { pairs } from "$lib";
import MovementAssesment from "./MovementAssessment.svelte";
import { guidance } from "./data.ts";
import { Radio, SecondaryButton } from "govuk-svelte";
import { pairs, Modal } from "$lib";
import { guidance, type GuidanceObject } from "./data.ts";
let junctionTypes: string[] = Object.keys(guidance);
let selectedJunctionType: string = junctionTypes[0];
let movementTypes: string[] = [];
let selectedMovementType: string = "";
$: {
movementTypes = Object.keys(guidance[selectedJunctionType]).filter(
(key) => key !== "summary",
);
movementTypes = getMovementTypes(selectedJunctionType);
if (movementTypes.length === 1) {
selectedMovementType = movementTypes[0];
}
}
$: guidanceObject = getGuidanceObject(
selectedJunctionType,
selectedMovementType,
);
function getMovementTypes(junctionType: string): string[] {
let result = Object.keys(guidance[junctionType]).filter(
(key) => key !== "summary" && key !== "otherJunctionTypeWhichApplies",
);
let otherJunctionTypeWhichApplies =
guidance[junctionType].otherJunctionTypeWhichApplies;
if (otherJunctionTypeWhichApplies) {
result = result.concat(
Object.keys(guidance[otherJunctionTypeWhichApplies]).filter(
(key) => key !== "summary" && key !== "otherJunctionTypeWhichApplies",
),
);
}
return result;
}
function getGuidanceObject(
junctionType: string,
movementType: string,
): GuidanceObject {
if (!movementTypes.includes(movementType)) {
selectedMovementType = movementTypes[0];
movementType = movementTypes[0];
}
let specificGuidance = guidance[junctionType][movementType];
let otherJunctionTypeWhichApplies =
guidance[junctionType].otherJunctionTypeWhichApplies;
if (!specificGuidance && guidance[otherJunctionTypeWhichApplies]) {
specificGuidance = guidance[otherJunctionTypeWhichApplies][movementType];
}
let result = JSON.parse(
JSON.stringify(guidance["Any type of junction"]["All movements"]),
);
if (
junctionType !== "Any type of junction" &&
movementType !== "All movements" &&
guidance[junctionType]["All movements"]
) {
let guidanceToAdd = guidance[junctionType]["All movements"];
result.scoreZero = result.scoreZero.concat(guidanceToAdd.scoreZero);
result.scoreOne = result.scoreOne.concat(guidanceToAdd.scoreOne);
result.scoreTwo = result.scoreTwo.concat(guidanceToAdd.scoreTwo);
}
if (specificGuidance) {
result.scoreZero = result.scoreZero.concat(specificGuidance.scoreZero);
result.scoreOne = result.scoreOne.concat(specificGuidance.scoreOne);
result.scoreTwo = result.scoreTwo.concat(specificGuidance.scoreTwo);
}
return result;
}
let showModal = false;
function openModal() {
showModal = true;
}
</script>

<Radio
label="What type of junction do you need guidance for"
choices={pairs(junctionTypes)}
bind:value={selectedJunctionType}
/>
{#if movementTypes.length > 1}
<div>
<SecondaryButton on:click={openModal}>Display guidance</SecondaryButton>
</div>
<Modal title={`Guidance`} bind:open={showModal}>
<Radio
label="What type of movement do you need guidance for"
choices={pairs(movementTypes)}
bind:value={selectedMovementType}
/>
{/if}

{#if guidance[selectedJunctionType][selectedMovementType]}
<MovementAssesment
junctionType={selectedJunctionType}
cycleMovement={selectedMovementType}
summary={guidance[selectedJunctionType].summary}
scoreZeroBullets={guidance[selectedJunctionType][selectedMovementType]
.scoreZero}
scoreOneBullets={guidance[selectedJunctionType][selectedMovementType]
.scoreOne}
scoreTwoBullets={guidance[selectedJunctionType][selectedMovementType]
.scoreTwo}
label="What type of junction do you need guidance for"
choices={pairs(junctionTypes)}
bind:value={selectedJunctionType}
/>
{/if}
{#if movementTypes.length > 1}
<Radio
label="What type of movement do you need guidance for"
choices={pairs(movementTypes)}
bind:value={selectedMovementType}
/>
{/if}
{#if guidanceObject}
<h3>{`${selectedJunctionType}: ${selectedMovementType}`}</h3>
{#if guidance[selectedJunctionType].summary}
<p>{guidance[selectedJunctionType].summary}</p>
{/if}
<table>
<tr>
<th class="score-zero-header">
Score = 0
<br />
Suitable only for confident existing cyclists, and may be avoided by some
experienced cyclists Conditions are most likely to give rise to the most
common collision types
</th>
<th class="score-one-header">
Score = 1
<br />
Likely to be more acceptable to most cyclists, but may still pose problems
for less confident or new cyclists The risk of collisions has been reduced
by design layout or traffic management interventions
</th>
<th class="has-hover score-two-header">
Score = 2
<br />
Suitable for all potential and existing cyclists The potential for collisions
has been removed, or managed to a high standard of safety for cyclists
</th>
</tr>
<tr>
<td class="score-zero">
<ul>
{#each guidanceObject.scoreZero as bulletPoint}
<li>{bulletPoint}</li>
{/each}
</ul>
</td>
<td class="score-one">
<ul>
{#each guidanceObject.scoreOne as bulletPoint}
<li>{bulletPoint}</li>
{/each}
</ul>
</td>
<td class="score-two">
<ul>
{#each guidanceObject.scoreTwo as bulletPoint}
<li>{bulletPoint}</li>
{/each}
</ul>
</td>
</tr>
</table>
{/if}
</Modal>

<style>
.score-zero-header {
color: white;
background-color: #e40521;
}
.score-one-header {
color: white;
background-color: #c89213;
}
.score-two-header {
color: white;
background-color: #61a730;
}
.score-zero {
background-color: #fbd9ce;
}
.score-one {
background-color: #f5e8d3;
}
.score-two {
background-color: #e5edd8;
}
td,
th {
padding: 0.25em;
}
</style>
103 changes: 0 additions & 103 deletions src/routes/route_check/jat_check/guidance/MovementAssessment.svelte

This file was deleted.

19 changes: 15 additions & 4 deletions src/routes/route_check/jat_check/guidance/data.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
export const guidance = {
"Any type of junction": {
"Any movement": {
otherJunctionTypeWhichApplies: "",
"All movements": {
scoreZero: [
"Cycle movement in potential conflict with heavy motor traffic flow",
"Cycle movement mixed with or crossing traffic with 85th percentile speed exceeding 60kph, or where vehicles accelerate rapidly.",
"Necessary to cross more than one traffic lane (without refuge or protection) to complete cycle movement unless traffic flows are low.",
"Cycle movementcrosses wide junctionentry or exit: e.g. withmerge or diverge taper or slip lane.",
"Cycle movement crosses wide junction entry or exit: e.g. with merge or diverge taper or slip lane.",
"Pinch points on junction entry or exit (lane width 3.2m-3.9m).",
"Cycle movement affected by very poor surface quality utility reinstatement, gully positioning, debris.",
],
Expand All @@ -25,6 +26,7 @@ export const guidance = {
"Simple priority T-junction": {
summary:
"This guidance is in addition to and notwithstanding any of the above “any junction” conditions.",
otherJunctionTypeWhichApplies: "",
"Right turn from minor arm": {
scoreZero: [
"Heavy traffic movements and/or high bus and HGV flows in potential conflict with cycle movement, with no physical refuge in the centre of the major road (including ghost island junction).",
Expand Down Expand Up @@ -70,6 +72,7 @@ export const guidance = {
Crossroads: {
summary:
"This guidance is in addition to and notwithstanding any of the above “any junction” and T junction conditions.",
otherJunctionTypeWhichApplies: "Simple priority T-junction",
"Ahead from minor arm": {
scoreZero: [
"Heavy opposing traffic movements with no physical refuge (including ghost island junction).",
Expand All @@ -85,6 +88,7 @@ export const guidance = {
"Traffic Signals": {
summary:
"This guidance is in addition to and notwithstanding any of the above “any junction” conditions.",
otherJunctionTypeWhichApplies: "",
"All movements": {
scoreZero: [
"Single or multiple queuing lanes with no cycle lanes or tracks on approaches.",
Expand All @@ -103,7 +107,7 @@ export const guidance = {
"Right turn": {
scoreZero: [],
scoreOne: [
"Two-stage right turn viaASL or marked area in front of stop line.",
"Two-stage right turn via ASL or marked area in front of stop line.",
],
scoreTwo: [
"Two-stage right turn with physically protected waiting area.",
Expand All @@ -113,9 +117,10 @@ export const guidance = {
Roundabout: {
summary:
"This guidance is in addition to and notwithstanding any of the above “any junction” conditions.",
otherJunctionTypeWhichApplies: "",
"All movements": {
scoreZero: [
"a Any type of roundabout with high traffic throughput.",
"Any type of roundabout with high traffic throughput.",
"Normal roundabout with multi-lane flared approaches.",
"Any type of roundabout with annular cycle lane marked on the circulatory carriageway.",
],
Expand All @@ -130,3 +135,9 @@ export const guidance = {
},
},
};

export interface GuidanceObject {
scoreZero: string[];
scoreOne: string[];
scoreTwo: string[];
}

0 comments on commit 83d749f

Please sign in to comment.