Skip to content

Commit

Permalink
Fix interventions to incorporate schemedId
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter York committed Nov 3, 2023
1 parent 68bcb74 commit 11623a4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
26 changes: 25 additions & 1 deletion src/lib/forms/PipelineForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,22 @@
SecondaryButton,
TextArea,
} from "lib/govuk";
import Select from "lib/govuk/Select.svelte";
import { prettyPrintMeters } from "lib/maplibre";
import { routeTool } from "stores";
import { gjScheme, routeTool } from "stores";
import type { InterventionProps } from "types";
import ATF4Type from "./ATF4Type.svelte";
export let id: number;
export let props: InterventionProps;
const mappedChoices: [string, string][] | undefined =
$gjScheme.subschemes?.map((subscheme) => {
return [subscheme.id.toString(), subscheme.name];
});
const schemeChoices: [string, string][] = mappedChoices ? mappedChoices : [];
props.pipeline ||= {
atf4_type: "",
accuracy: "",
Expand All @@ -22,6 +30,11 @@
// Guaranteed to exist
let pipelineProps = props.pipeline;
let selectedSchemeIdString =
pipelineProps?.schemeId == 0 || pipelineProps?.schemeId
? pipelineProps?.schemeId.toString()
: "";
// Sets the intervention name to "From {road1 and road2} to {road3 and
// road4}". Only meant to be useful for routes currently.
function autoFillName() {
Expand All @@ -31,6 +44,10 @@
window.alert(`Couldn't auto-name route: ${e}`);
}
}
function schemeSelectionChanged() {
pipelineProps.schemeId = parseInt(selectedSchemeIdString);
}
</script>

<FormElement label="Name" id={"name-" + id}>
Expand All @@ -43,6 +60,13 @@
{/if}
</FormElement>

<Select
label="Scheme"
choices={schemeChoices}
bind:value={selectedSchemeIdString}
on:change={schemeSelectionChanged}
/>

<TextArea label="Description" bind:value={props.description} />

{#if props.length_meters}
Expand Down
13 changes: 5 additions & 8 deletions src/lib/sidebar/EntireSubscheme.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,23 @@
export let getSubschemeNameUpdater: Function;
let displayDeleteConfirmation = false;
let features: FeatureUnion[] = [];
let features: FeatureUnion[] = superscheme.features.filter((feature) => {
return feature.properties.pipeline?.schemeId === subscheme.id;
});
// @ts-ignore we know subschemes exists because otherwise this wouldn't be rendered
$: disabledSubschemeDeletion = $gjScheme.subschemes?.length < 2;
let numErrors = 0;
onMount(async () => {
features = superscheme.features.filter((feature) => {
return feature.properties.pipelineIntervention?.schemeId === subscheme.id;
});
});
function deleteSubscheme() {
displayDeleteConfirmation = false;
const clonedScheme = JSON.parse(JSON.stringify($gjScheme));
clonedScheme.features = clonedScheme.features.filter(
(feature: FeatureUnion) => {
return (
feature.properties.pipelineIntervention?.schemeId !== subscheme.id
feature.properties.pipeline?.schemeId !== subscheme.id
);
}
);
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Scheme {
// types are encoded as "".
export interface PipelineScheme {
id: number;
name: string;
// TODO "intersection" is unclear
scheme_type:
| "cycling route"
Expand Down

0 comments on commit 11623a4

Please sign in to comment.