Lots of refactoring, first version of the import helper

This commit is contained in:
Pieter Vander Vennet 2022-01-19 20:34:04 +01:00
parent 612b8136ad
commit 3402ac0954
54 changed files with 1104 additions and 315 deletions

View file

@ -137,10 +137,10 @@ export default class AutoApplyButton implements SpecialVisualization {
new ShowDataLayer({
leafletMap: previewMap.leafletMap,
enablePopups: false,
popup: undefined,
zoomToFeatures: true,
features: new StaticFeatureSource(features, false),
allElements: state.allElements,
state,
layerToShow: layer.layerDef,
})

View file

@ -1,5 +1,4 @@
import {VariableUiElement} from "../Base/VariableUIElement";
import State from "../../State";
import Toggle from "../Input/Toggle";
import Translations from "../i18n/Translations";
import Svg from "../../Svg";
@ -17,6 +16,10 @@ import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
import {AndOrTagConfigJson} from "../../Models/ThemeConfig/Json/TagConfigJson";
import DeleteConfig from "../../Models/ThemeConfig/DeleteConfig";
import {OsmObject} from "../../Logic/Osm/OsmObject";
import {ElementStorage} from "../../Logic/ElementStorage";
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
import {Changes} from "../../Logic/Osm/Changes";
import {OsmConnection} from "../../Logic/Osm/OsmConnection";
export default class DeleteWizard extends Toggle {
/**
@ -35,13 +38,21 @@ export default class DeleteWizard extends Toggle {
* (Note that _delete_reason is used as trigger to do actual deletion - setting such a tag WILL delete from the database with that as changeset comment)
*
* @param id: The id of the element to remove
* @param state: the state of the application
* @param options softDeletionTags: the tags to apply if the user doesn't have permission to delete, e.g. 'disused:amenity=public_bookcase', 'amenity='. After applying, the element should not be picked up on the map anymore. If undefined, the wizard will only show up if the point can be (hard) deleted
*/
constructor(id: string,
state: {
osmConnection: OsmConnection;
allElements: ElementStorage,
layoutToUse?: LayoutConfig,
changes?: Changes
},
options: DeleteConfig) {
const deleteAbility = new DeleteabilityChecker(id, options.neededChangesets)
const tagsSource = State.state.allElements.getEventSourceById(id)
const deleteAbility = new DeleteabilityChecker(id, state, options.neededChangesets)
const tagsSource = state.allElements.getEventSourceById(id)
const isDeleted = new UIEventSource(false)
const allowSoftDeletion = !!options.softDeletionTags
@ -59,12 +70,12 @@ export default class DeleteWizard extends Toggle {
const deleteAction = new DeleteAction(id,
options.softDeletionTags,
{
theme: State.state?.layoutToUse?.id ?? "unkown",
theme: state?.layoutToUse?.id ?? "unkown",
specialMotivation: deleteReasonMatch[0]?.v
},
deleteAbility.canBeDeleted.data.canBeDeleted
)
State.state.changes.applyAction(deleteAction)
state.changes?.applyAction(deleteAction)
isDeleted.setData(true)
}
@ -77,6 +88,7 @@ export default class DeleteWizard extends Toggle {
return new TagRenderingQuestion(
tagsSource,
config,
state,
{
cancelButton: cancelButton,
/*Using a custom save button constructor erases all logic to actually save, so we have to listen for the click!*/
@ -112,7 +124,7 @@ export default class DeleteWizard extends Toggle {
new Toggle(
question,
new SubtleButton(Svg.envelope_ui(), t.readMessages.Clone()),
State.state.osmConnection.userDetails.map(ud => ud.csCount > Constants.userJourney.addNewPointWithUnreadMessagesUnlock || ud.unreadMessages == 0)
state.osmConnection.userDetails.map(ud => ud.csCount > Constants.userJourney.addNewPointWithUnreadMessagesUnlock || ud.unreadMessages == 0)
),
deleteButton,
@ -131,8 +143,8 @@ export default class DeleteWizard extends Toggle {
,
deleteAbility.canBeDeleted.map(cbd => allowSoftDeletion || cbd.canBeDeleted !== false)),
t.loginToDelete.Clone().onClick(State.state.osmConnection.AttemptLogin),
State.state.osmConnection.isLoggedIn
t.loginToDelete.Clone().onClick(state.osmConnection.AttemptLogin),
state.osmConnection.isLoggedIn
),
isDeleted),
undefined,
@ -275,11 +287,16 @@ class DeleteabilityChecker {
public readonly canBeDeleted: UIEventSource<{ canBeDeleted?: boolean, reason: Translation }>;
private readonly _id: string;
private readonly _allowDeletionAtChangesetCount: number;
private readonly _state: {
osmConnection: OsmConnection
};
constructor(id: string,
state: {osmConnection: OsmConnection},
allowDeletionAtChangesetCount?: number) {
this._id = id;
this._state = state;
this._allowDeletionAtChangesetCount = allowDeletionAtChangesetCount ?? Number.MAX_VALUE;
this.canBeDeleted = new UIEventSource<{ canBeDeleted?: boolean; reason: Translation }>({
@ -299,6 +316,7 @@ class DeleteabilityChecker {
const t = Translations.t.delete;
const id = this._id;
const state = this.canBeDeleted
const self = this;
if (!id.startsWith("node")) {
this.canBeDeleted.setData({
canBeDeleted: false,
@ -308,8 +326,7 @@ class DeleteabilityChecker {
}
// Does the currently logged in user have enough experience to delete this point?
const deletingPointsOfOtherAllowed = State.state.osmConnection.userDetails.map(ud => {
const deletingPointsOfOtherAllowed = this._state.osmConnection.userDetails.map(ud => {
if (ud === undefined) {
return undefined;
}
@ -320,15 +337,14 @@ class DeleteabilityChecker {
})
const previousEditors = new UIEventSource<number[]>(undefined)
const allByMyself = previousEditors.map(previous => {
if (previous === null || previous === undefined) {
// Not yet downloaded
return null;
}
const userId = State.state.osmConnection.userDetails.data.uid;
const userId = self._state.osmConnection.userDetails.data.uid;
return !previous.some(editor => editor !== userId)
}, [State.state.osmConnection.userDetails])
}, [self._state.osmConnection.userDetails])
// User allowed OR only edited by self?

View file

@ -3,19 +3,20 @@ import TagRenderingQuestion from "./TagRenderingQuestion";
import Translations from "../i18n/Translations";
import Combine from "../Base/Combine";
import TagRenderingAnswer from "./TagRenderingAnswer";
import State from "../../State";
import Svg from "../../Svg";
import Toggle from "../Input/Toggle";
import BaseUIElement from "../BaseUIElement";
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig";
import {Unit} from "../../Models/Unit";
import Lazy from "../Base/Lazy";
import {OsmConnection} from "../../Logic/Osm/OsmConnection";
export default class EditableTagRendering extends Toggle {
constructor(tags: UIEventSource<any>,
configuration: TagRenderingConfig,
units: Unit [],
state,
options: {
editMode?: UIEventSource<boolean>,
innerElementClasses?: string
@ -32,7 +33,7 @@ export default class EditableTagRendering extends Toggle {
super(
new Lazy(() => {
const editMode = options.editMode ?? new UIEventSource<boolean>(false)
const rendering = EditableTagRendering.CreateRendering(tags, configuration, units, editMode);
const rendering = EditableTagRendering.CreateRendering(state, tags, configuration, units, editMode);
rendering.SetClass(options.innerElementClasses)
return rendering
}),
@ -41,12 +42,12 @@ export default class EditableTagRendering extends Toggle {
)
}
private static CreateRendering(tags: UIEventSource<any>, configuration: TagRenderingConfig, units: Unit[], editMode: UIEventSource<boolean>): BaseUIElement {
const answer: BaseUIElement = new TagRenderingAnswer(tags, configuration, State.state)
private static CreateRendering(state: {featureSwitchUserbadge?: UIEventSource<boolean>, osmConnection: OsmConnection}, tags: UIEventSource<any>, configuration: TagRenderingConfig, units: Unit[], editMode: UIEventSource<boolean>): BaseUIElement {
const answer: BaseUIElement = new TagRenderingAnswer(tags, configuration, state)
answer.SetClass("w-full")
let rendering = answer;
if (configuration.question !== undefined && State.state?.featureSwitchUserbadge?.data) {
if (configuration.question !== undefined && state?.featureSwitchUserbadge?.data) {
// We have a question and editing is enabled
const answerWithEditButton = new Combine([answer,
new Toggle(new Combine([Svg.pencil_ui()]).SetClass("block relative h-10 w-10 p-2 float-right").SetStyle("border: 1px solid black; border-radius: 0.7em")
@ -54,12 +55,12 @@ export default class EditableTagRendering extends Toggle {
editMode.setData(true);
}),
undefined,
State.state.osmConnection.isLoggedIn)
state.osmConnection.isLoggedIn)
]).SetClass("flex justify-between w-full")
const question = new Lazy(() =>
new TagRenderingQuestion(tags, configuration,
new TagRenderingQuestion(tags, configuration,state,
{
units: units,
cancelButton: Translations.t.general.cancel.Clone()

View file

@ -3,7 +3,6 @@ import EditableTagRendering from "./EditableTagRendering";
import QuestionBox from "./QuestionBox";
import Combine from "../Base/Combine";
import TagRenderingAnswer from "./TagRenderingAnswer";
import State from "../../State";
import ScrollableFullScreen from "../Base/ScrollableFullScreen";
import Constants from "../../Models/Constants";
import SharedTagRenderings from "../../Customizations/SharedTagRenderings";
@ -16,18 +15,41 @@ import LayerConfig from "../../Models/ThemeConfig/LayerConfig";
import {Utils} from "../../Utils";
import MoveWizard from "./MoveWizard";
import Toggle from "../Input/Toggle";
import {OsmConnection} from "../../Logic/Osm/OsmConnection";
import {Changes} from "../../Logic/Osm/Changes";
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
import {ElementStorage} from "../../Logic/ElementStorage";
import FilteredLayer from "../../Models/FilteredLayer";
import BaseLayer from "../../Models/BaseLayer";
import Lazy from "../Base/Lazy";
export default class FeatureInfoBox extends ScrollableFullScreen {
public constructor(
tags: UIEventSource<any>,
layerConfig: LayerConfig,
state: {
filteredLayers: UIEventSource<FilteredLayer[]>;
backgroundLayer: UIEventSource<BaseLayer>;
featureSwitchIsTesting: UIEventSource<boolean>;
featureSwitchIsDebugging: UIEventSource<boolean>;
featureSwitchShowAllQuestions: UIEventSource<boolean>;
osmConnection: OsmConnection,
featureSwitchUserbadge: UIEventSource<boolean>,
changes: Changes,
layoutToUse: LayoutConfig,
allElements: ElementStorage
},
hashToShow?: string,
isShown?: UIEventSource<boolean>
isShown?: UIEventSource<boolean>,
) {
super(() => FeatureInfoBox.GenerateTitleBar(tags, layerConfig),
() => FeatureInfoBox.GenerateContent(tags, layerConfig),
hashToShow ?? tags.data.id,
if (state === undefined) {
throw "State is undefined!"
}
super(() => FeatureInfoBox.GenerateTitleBar(tags, layerConfig, state),
() => FeatureInfoBox.GenerateContent(tags, layerConfig, state),
hashToShow ?? tags.data.id ?? "item",
isShown);
if (layerConfig === undefined) {
@ -37,11 +59,12 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
}
private static GenerateTitleBar(tags: UIEventSource<any>,
layerConfig: LayerConfig): BaseUIElement {
const title = new TagRenderingAnswer(tags, layerConfig.title ?? new TagRenderingConfig("POI"), State.state)
layerConfig: LayerConfig,
state: {}): BaseUIElement {
const title = new TagRenderingAnswer(tags, layerConfig.title ?? new TagRenderingConfig("POI"), state)
.SetClass("break-words font-bold sm:p-0.5 md:p-1 sm:p-1.5 md:p-2");
const titleIcons = new Combine(
layerConfig.titleIcons.map(icon => new TagRenderingAnswer(tags, icon, State.state,
layerConfig.titleIcons.map(icon => new TagRenderingAnswer(tags, icon, state,
"block w-8 h-8 max-h-8 align-baseline box-content sm:p-0.5 w-10",)
))
.SetClass("flex flex-row flex-wrap pt-0.5 sm:pt-1 items-center mr-2")
@ -52,20 +75,32 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
}
private static GenerateContent(tags: UIEventSource<any>,
layerConfig: LayerConfig): BaseUIElement {
layerConfig: LayerConfig,
state: {
filteredLayers: UIEventSource<FilteredLayer[]>;
backgroundLayer: UIEventSource<BaseLayer>;
featureSwitchIsTesting: UIEventSource<boolean>;
featureSwitchIsDebugging: UIEventSource<boolean>;
featureSwitchShowAllQuestions: UIEventSource<boolean>;
osmConnection: OsmConnection,
featureSwitchUserbadge: UIEventSource<boolean>,
changes: Changes,
layoutToUse: LayoutConfig,
allElements: ElementStorage
}): BaseUIElement {
let questionBoxes: Map<string, QuestionBox> = new Map<string, QuestionBox>();
const allGroupNames = Utils.Dedup(layerConfig.tagRenderings.map(tr => tr.group))
if (State.state.featureSwitchUserbadge.data) {
if (state?.featureSwitchUserbadge?.data ?? true) {
const questionSpecs = layerConfig.tagRenderings.filter(tr => tr.id === "questions")
for (const groupName of allGroupNames) {
const questions = layerConfig.tagRenderings.filter(tr => tr.group === groupName)
const questionSpec = questionSpecs.filter(tr => tr.group === groupName)[0]
const questionBox = new QuestionBox({
const questionBox = new QuestionBox(state, {
tagsSource: tags,
tagRenderings: questions,
units: layerConfig.units,
showAllQuestionsAtOnce: questionSpec?.freeform?.helperArgs["showAllQuestions"] ?? State.state.featureSwitchShowAllQuestions
showAllQuestionsAtOnce: questionSpec?.freeform?.helperArgs["showAllQuestions"] ?? state.featureSwitchShowAllQuestions
});
questionBoxes.set(groupName, questionBox)
}
@ -86,10 +121,10 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
if (tr.render !== undefined) {
questionBox.SetClass("text-sm")
const renderedQuestion = new TagRenderingAnswer(tags, tr,State.state,
const renderedQuestion = new TagRenderingAnswer(tags, tr, state,
tr.group + " questions", "", {
specialViz: new Map<string, BaseUIElement>([["questions", questionBox]])
})
specialViz: new Map<string, BaseUIElement>([["questions", questionBox]])
})
const possiblyHidden = new Toggle(
renderedQuestion,
undefined,
@ -109,7 +144,7 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
classes = ""
}
const etr = new EditableTagRendering(tags, tr, layerConfig.units, {
const etr = new EditableTagRendering(tags, tr, layerConfig.units, state, {
innerElementClasses: innerClasses
})
if (isHeader) {
@ -121,8 +156,29 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
allRenderings.push(...renderingsForGroup)
}
allRenderings.push(
new Toggle(
new Lazy(() => FeatureInfoBox.createEditElements(questionBoxes, layerConfig, tags, state)),
undefined,
state.featureSwitchUserbadge
))
return new Combine(allRenderings).SetClass("block")
}
/**
* All the edit elements, together (note that the question boxes are passed though)
* @param questionBoxes
* @param layerConfig
* @param tags
* @param state
* @private
*/
private static createEditElements(questionBoxes: Map<string, QuestionBox>,
layerConfig: LayerConfig,
tags: UIEventSource<any>,
state: { filteredLayers: UIEventSource<FilteredLayer[]>; backgroundLayer: UIEventSource<BaseLayer>; featureSwitchIsTesting: UIEventSource<boolean>; featureSwitchIsDebugging: UIEventSource<boolean>; featureSwitchShowAllQuestions: UIEventSource<boolean>; osmConnection: OsmConnection; featureSwitchUserbadge: UIEventSource<boolean>; changes: Changes; layoutToUse: LayoutConfig; allElements: ElementStorage })
: BaseUIElement {
let editElements: BaseUIElement[] = []
questionBoxes.forEach(questionBox => {
editElements.push(questionBox);
@ -131,10 +187,13 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
if (layerConfig.allowMove) {
editElements.push(
new VariableUiElement(tags.map(tags => tags.id).map(id => {
const feature = State.state.allElements.ContainingFeatures.get(id)
const feature = state.allElements.ContainingFeatures.get(id)
if (feature === undefined) {
return "This feature is not register in the state.allElements and cannot be moved"
}
return new MoveWizard(
feature,
State.state,
state,
layerConfig.allowMove
);
})
@ -147,6 +206,7 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
new VariableUiElement(tags.map(tags => tags.id).map(id =>
new DeleteWizard(
id,
state,
layerConfig.deletion
))
).SetClass("text-base"))
@ -155,59 +215,45 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
if (layerConfig.allowSplit) {
editElements.push(
new VariableUiElement(tags.map(tags => tags.id).map(id =>
new SplitRoadWizard(id))
new SplitRoadWizard(id, state))
).SetClass("text-base"))
}
editElements.push(
new VariableUiElement(
State.state.osmConnection.userDetails
state.osmConnection.userDetails
.map(ud => ud.csCount)
.map(csCount => {
if (csCount <= Constants.userJourney.historyLinkVisible
&& State.state.featureSwitchIsDebugging.data == false
&& State.state.featureSwitchIsTesting.data === false) {
&& state.featureSwitchIsDebugging.data == false
&& state.featureSwitchIsTesting.data === false) {
return undefined
}
return new TagRenderingAnswer(tags, SharedTagRenderings.SharedTagRendering.get("last_edit"), State.state);
return new TagRenderingAnswer(tags, SharedTagRenderings.SharedTagRendering.get("last_edit"), state);
}, [State.state.featureSwitchIsDebugging, State.state.featureSwitchIsTesting])
}, [state.featureSwitchIsDebugging, state.featureSwitchIsTesting])
)
)
editElements.push(
new VariableUiElement(
State.state.featureSwitchIsDebugging.map(isDebugging => {
state.featureSwitchIsDebugging.map(isDebugging => {
if (isDebugging) {
const config_all_tags: TagRenderingConfig = new TagRenderingConfig({render: "{all_tags()}"}, "");
const config_download: TagRenderingConfig = new TagRenderingConfig({render: "{export_as_geojson()}"}, "");
const config_id: TagRenderingConfig = new TagRenderingConfig({render: "{open_in_iD()}"}, "");
return new Combine([new TagRenderingAnswer(tags, config_all_tags, State.state),
new TagRenderingAnswer(tags, config_download, State.state),
new TagRenderingAnswer(tags, config_id, State.state)])
return new Combine([new TagRenderingAnswer(tags, config_all_tags, state),
new TagRenderingAnswer(tags, config_download, state),
new TagRenderingAnswer(tags, config_id, state)])
}
})
)
)
const editors = new VariableUiElement(State.state.featureSwitchUserbadge.map(
userbadge => {
if (!userbadge) {
return undefined
}
return new Combine(editElements).SetClass("flex flex-col")
}
))
allRenderings.push(editors)
return new Combine(allRenderings).SetClass("block")
return new Combine(editElements).SetClass("flex flex-col")
}
}

View file

@ -246,10 +246,10 @@ ${Utils.special_visualizations_importRequirementDocs}
// SHow all relevant data - including (eventually) the way of which the geometry will be replaced
new ShowDataMultiLayer({
leafletMap: confirmationMap.leafletMap,
enablePopups: false,
popup: undefined,
zoomToFeatures: true,
features: new StaticFeatureSource([feature], false),
allElements: state.allElements,
state: state,
layers: state.filteredLayers
})
@ -257,10 +257,10 @@ ${Utils.special_visualizations_importRequirementDocs}
action.getPreview().then(changePreview => {
new ShowDataLayer({
leafletMap: confirmationMap.leafletMap,
enablePopups: false,
popup: undefined,
zoomToFeatures: false,
features: changePreview,
allElements: state.allElements,
state,
layerToShow: new LayerConfig(conflation_json, "all_known_layers", true)
})
})

View file

@ -16,7 +16,7 @@ export default class QuestionBox extends VariableUiElement {
public readonly skippedQuestions: UIEventSource<number[]>;
public readonly restingQuestions: UIEventSource<BaseUIElement[]>;
constructor(options: {
constructor(state, options: {
tagsSource: UIEventSource<any>,
tagRenderings: TagRenderingConfig[], units: Unit[],
showAllQuestionsAtOnce?: boolean | UIEventSource<boolean>
@ -34,7 +34,7 @@ export default class QuestionBox extends VariableUiElement {
const tagRenderingQuestions = tagRenderings
.map((tagRendering, i) =>
new Lazy(() => new TagRenderingQuestion(tagsSource, tagRendering,
new Lazy(() => new TagRenderingQuestion(tagsSource, tagRendering, state,
{
units: units,
afterSave: () => {

View file

@ -3,7 +3,6 @@ import Svg from "../../Svg";
import {UIEventSource} from "../../Logic/UIEventSource";
import {SubtleButton} from "../Base/SubtleButton";
import Minimap from "../Base/Minimap";
import State from "../../State";
import ShowDataLayer from "../ShowDataLayer/ShowDataLayer";
import {GeoOperations} from "../../Logic/GeoOperations";
import {LeafletMouseEvent} from "leaflet";
@ -17,6 +16,12 @@ import ShowDataMultiLayer from "../ShowDataLayer/ShowDataMultiLayer";
import LayerConfig from "../../Models/ThemeConfig/LayerConfig";
import {BBox} from "../../Logic/BBox";
import * as split_point from "../../assets/layers/split_point/split_point.json"
import {OsmConnection} from "../../Logic/Osm/OsmConnection";
import {Changes} from "../../Logic/Osm/Changes";
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig";
import {ElementStorage} from "../../Logic/ElementStorage";
import BaseLayer from "../../Models/BaseLayer";
import FilteredLayer from "../../Models/FilteredLayer";
export default class SplitRoadWizard extends Toggle {
// @ts-ignore
@ -28,8 +33,19 @@ export default class SplitRoadWizard extends Toggle {
* A UI Element used for splitting roads
*
* @param id: The id of the road to remove
* @param state: the state of the application
*/
constructor(id: string) {
constructor(id: string, state: {
filteredLayers: UIEventSource<FilteredLayer[]>;
backgroundLayer: UIEventSource<BaseLayer>;
featureSwitchIsTesting: UIEventSource<boolean>;
featureSwitchIsDebugging: UIEventSource<boolean>;
featureSwitchShowAllQuestions: UIEventSource<boolean>;
osmConnection: OsmConnection,
featureSwitchUserbadge: UIEventSource<boolean>,
changes: Changes,
layoutToUse: LayoutConfig,
allElements: ElementStorage}) {
const t = Translations.t.split;
@ -41,12 +57,12 @@ export default class SplitRoadWizard extends Toggle {
// Toggle variable between show split button and map
const splitClicked = new UIEventSource<boolean>(false);
// Load the road with given id on the minimap
const roadElement = State.state.allElements.ContainingFeatures.get(id)
const roadElement = state.allElements.ContainingFeatures.get(id)
// Minimap on which you can select the points to be splitted
const miniMap = Minimap.createMiniMap(
{
background: State.state.backgroundLayer,
background: state.backgroundLayer,
allowMoving: true,
leafletOptions: {
minZoom: 14
@ -62,19 +78,20 @@ export default class SplitRoadWizard extends Toggle {
// Datalayer displaying the road and the cut points (if any)
new ShowDataMultiLayer({
features: new StaticFeatureSource([roadElement], false),
layers: State.state.filteredLayers,
layers: state.filteredLayers,
leafletMap: miniMap.leafletMap,
enablePopups: false,
popup: undefined,
zoomToFeatures: true,
allElements: State.state.allElements,
state
})
new ShowDataLayer({
features: new StaticFeatureSource(splitPoints, true),
leafletMap: miniMap.leafletMap,
zoomToFeatures: false,
enablePopups: false,
popup: undefined,
layerToShow: SplitRoadWizard.splitLayerStyling,
state
})
@ -127,15 +144,15 @@ export default class SplitRoadWizard extends Toggle {
// Only show the splitButton if logged in, else show login prompt
const loginBtn = t.loginToSplit.Clone()
.onClick(() => State.state.osmConnection.AttemptLogin())
.onClick(() => state.osmConnection.AttemptLogin())
.SetClass("login-button-friendly");
const splitToggle = new Toggle(splitButton, loginBtn, State.state.osmConnection.isLoggedIn)
const splitToggle = new Toggle(splitButton, loginBtn, state.osmConnection.isLoggedIn)
// Save button
const saveButton = new Button(t.split.Clone(), () => {
hasBeenSplit.setData(true)
State.state.changes.applyAction(new SplitAction(id, splitPoints.data.map(ff => ff.feature.geometry.coordinates), {
theme: State.state?.layoutToUse?.id
state.changes.applyAction(new SplitAction(id, splitPoints.data.map(ff => ff.feature.geometry.coordinates), {
theme: state?.layoutToUse?.id
}))
})

View file

@ -8,7 +8,6 @@ import {Utils} from "../../Utils";
import CheckBoxes from "../Input/Checkboxes";
import InputElementMap from "../Input/InputElementMap";
import {SaveButton} from "./SaveButton";
import State from "../../State";
import {VariableUiElement} from "../Base/VariableUIElement";
import Translations from "../i18n/Translations";
import {FixedUiElement} from "../Base/FixedUiElement";
@ -36,6 +35,7 @@ export default class TagRenderingQuestion extends Combine {
constructor(tags: UIEventSource<any>,
configuration: TagRenderingConfig,
state,
options?: {
units?: Unit[],
afterSave?: () => void,
@ -71,23 +71,23 @@ export default class TagRenderingQuestion extends Combine {
}
options = options ?? {}
const applicableUnit = (options.units ?? []).filter(unit => unit.isApplicableToKey(configuration.freeform?.key))[0];
const question = new SubstitutedTranslation(configuration.question, tags, State.state)
const question = new SubstitutedTranslation(configuration.question, tags, state)
.SetClass("question-text");
const inputElement: InputElement<TagsFilter> =
new VariableInputElement(applicableMappingsSrc.map(applicableMappings =>
TagRenderingQuestion.GenerateInputElement(configuration, applicableMappings, applicableUnit, tags)
TagRenderingQuestion.GenerateInputElement(state, configuration, applicableMappings, applicableUnit, tags)
))
const save = () => {
const selection = inputElement.GetValue().data;
if (selection) {
(State.state?.changes)
(state?.changes)
.applyAction(new ChangeTagAction(
tags.data.id, selection, tags.data, {
theme: State.state?.layoutToUse?.id ?? "unkown",
theme: state?.layoutToUse?.id ?? "unkown",
changeType: "answer",
}
)).then(_ => {
@ -101,13 +101,13 @@ export default class TagRenderingQuestion extends Combine {
if (options.saveButtonConstr === undefined) {
options.saveButtonConstr = v => new SaveButton(v,
State.state?.osmConnection)
state?.osmConnection)
.onClick(save)
}
const saveButton = new Combine([
options.saveButtonConstr(inputElement.GetValue()),
new Toggle(Translations.t.general.testing.SetClass("alert"), undefined, State.state.featureSwitchIsTesting)
new Toggle(Translations.t.general.testing.SetClass("alert"), undefined, state.featureSwitchIsTesting)
])
let bottomTags: BaseUIElement;
@ -117,7 +117,7 @@ export default class TagRenderingQuestion extends Combine {
bottomTags = new VariableUiElement(
inputElement.GetValue().map(
(tagsFilter: TagsFilter) => {
const csCount = State.state?.osmConnection?.userDetails?.data?.csCount ?? 1000;
const csCount = state?.osmConnection?.userDetails?.data?.csCount ?? 1000;
if (csCount < Constants.userJourney.tagsVisibleAt) {
return "";
}
@ -145,14 +145,16 @@ export default class TagRenderingQuestion extends Combine {
}
private static GenerateInputElement(configuration: TagRenderingConfig,
applicableMappings: { if: TagsFilter, then: any, ifnot?: TagsFilter, addExtraTags: Tag[] }[],
applicableUnit: Unit,
tagsSource: UIEventSource<any>)
private static GenerateInputElement(
state,
configuration: TagRenderingConfig,
applicableMappings: { if: TagsFilter, then: any, ifnot?: TagsFilter, addExtraTags: Tag[] }[],
applicableUnit: Unit,
tagsSource: UIEventSource<any>)
: InputElement<TagsFilter> {
// FreeForm input will be undefined if not present; will already contain a special input element if applicable
const ff = TagRenderingQuestion.GenerateFreeform(configuration, applicableUnit, tagsSource);
const ff = TagRenderingQuestion.GenerateFreeform(state, configuration, applicableUnit, tagsSource);
const hasImages = applicableMappings.filter(mapping => mapping.then.ExtractImages().length > 0).length > 0
@ -188,7 +190,7 @@ export default class TagRenderingQuestion extends Combine {
if (applicableMappings.length < 8 || configuration.multiAnswer || hasImages || ifNotsPresent) {
inputEls = (applicableMappings ?? []).map((mapping, i) => TagRenderingQuestion.GenerateMappingElement(tagsSource, mapping, allIfNotsExcept(i)));
inputEls = (applicableMappings ?? []).map((mapping, i) => TagRenderingQuestion.GenerateMappingElement(state, tagsSource, mapping, allIfNotsExcept(i)));
inputEls = Utils.NoNull(inputEls);
} else {
const dropdown: InputElement<TagsFilter> = new DropDown("",
@ -336,6 +338,7 @@ export default class TagRenderingQuestion extends Combine {
* Returns: [the element itself, the value to select if not selected. The contents of this UIEventSource might swap to undefined if the conditions to show the answer are unmet]
*/
private static GenerateMappingElement(
state,
tagsSource: UIEventSource<any>,
mapping: {
if: TagsFilter,
@ -352,12 +355,12 @@ export default class TagRenderingQuestion extends Combine {
}
return new FixedInputElement(
new SubstitutedTranslation(mapping.then, tagsSource, State.state),
new SubstitutedTranslation(mapping.then, tagsSource, state),
tagging,
(t0, t1) => t1.isEquivalent(t0));
}
private static GenerateFreeform(configuration: TagRenderingConfig, applicableUnit: Unit, tags: UIEventSource<any>): InputElement<TagsFilter> {
private static GenerateFreeform(state, configuration: TagRenderingConfig, applicableUnit: Unit, tags: UIEventSource<any>): InputElement<TagsFilter> {
const freeform = configuration.freeform;
if (freeform === undefined) {
return undefined;
@ -397,12 +400,12 @@ export default class TagRenderingQuestion extends Combine {
}
const tagsData = tags.data;
const feature = State.state.allElements.ContainingFeatures.get(tagsData.id)
const feature = state.allElements.ContainingFeatures.get(tagsData.id)
const input: InputElement<string> = ValidatedTextField.InputForType(configuration.freeform.type, {
isValid: (str) => (str.length <= 255),
country: () => tagsData._country,
location: [tagsData._lat, tagsData._lon],
mapBackgroundLayer: State.state.backgroundLayer,
mapBackgroundLayer: state.backgroundLayer,
unit: applicableUnit,
args: configuration.freeform.helperArgs,
feature: feature
@ -418,7 +421,7 @@ export default class TagRenderingQuestion extends Combine {
if (freeform.inline) {
inputTagsFilter.SetClass("w-16-imp")
inputTagsFilter = new InputElementWrapper(inputTagsFilter, configuration.render, freeform.key, tags, State.state)
inputTagsFilter = new InputElementWrapper(inputTagsFilter, configuration.render, freeform.key, tags, state)
inputTagsFilter.SetClass("block")
}