forked from MapComplete/MapComplete
Full code cleanup
This commit is contained in:
parent
3a4a2a2016
commit
fa971ffbbf
300 changed files with 16352 additions and 19284 deletions
|
@ -60,13 +60,24 @@ export default class AutoApplyButton implements SpecialVisualization {
|
|||
this.docs = AutoApplyButton.generateDocs(allSpecialVisualisations.filter(sv => sv["supportsAutoAction"] === true).map(sv => sv.funcName))
|
||||
}
|
||||
|
||||
private static generateDocs(supportedActions: string[]) {
|
||||
return [
|
||||
"A button to run many actions for many features at once.\n",
|
||||
"To effectively use this button, you'll need some ingredients:\n" +
|
||||
"- A target layer with features for which an action is defined in a tag rendering. The following special visualisations support an autoAction: " + supportedActions.join(", "),
|
||||
"- A host feature to place the auto-action on. This can be a big outline (such as a city). Another good option for this is the [current_view](./BuiltinLayers.md#current_view)",
|
||||
"- Then, use a calculated tag on the host feature to determine the overlapping object ids",
|
||||
"- At last, add this component"
|
||||
].join("\n")
|
||||
}
|
||||
|
||||
constr(state: FeaturePipelineState, tagSource: UIEventSource<any>, argument: string[], guistate: DefaultGuiState): BaseUIElement {
|
||||
|
||||
if (!state.layoutToUse.official && !(state.featureSwitchIsTesting.data || state.osmConnection._oauth_config.url === OsmConnection.oauth_configs["osm-test"].url)) {
|
||||
const t = Translations.t.general.add.import;
|
||||
return new Combine([new FixedUiElement("The auto-apply button is only available in official themes (or in testing mode)").SetClass("alert"), t.howToTest])
|
||||
}
|
||||
|
||||
|
||||
const to_parse = tagSource.data[argument[1]]
|
||||
if (to_parse === undefined) {
|
||||
return new Loading("Gathering which elements support auto-apply... ")
|
||||
|
@ -76,11 +87,11 @@ export default class AutoApplyButton implements SpecialVisualization {
|
|||
|
||||
const target_layer_id = argument[0]
|
||||
const target_feature_ids = <string[]>JSON.parse(to_parse)
|
||||
|
||||
if(target_feature_ids.length === 0){
|
||||
|
||||
if (target_feature_ids.length === 0) {
|
||||
return new FixedUiElement("No elements found to perform action")
|
||||
}
|
||||
|
||||
|
||||
const targetTagRendering = argument[2]
|
||||
const text = argument[3]
|
||||
const icon = argument[4]
|
||||
|
@ -93,7 +104,7 @@ export default class AutoApplyButton implements SpecialVisualization {
|
|||
return new FixedUiElement("Target tagrendering " + targetTagRendering + " not found").SetClass("alert")
|
||||
}
|
||||
|
||||
const buttonState = new UIEventSource<"idle" | "running" | "done" | {error: string}>("idle")
|
||||
const buttonState = new UIEventSource<"idle" | "running" | "done" | { error: string }>("idle")
|
||||
|
||||
const button = new SubtleButton(
|
||||
new Img(icon),
|
||||
|
@ -154,10 +165,10 @@ export default class AutoApplyButton implements SpecialVisualization {
|
|||
return new FixedUiElement("All done!").SetClass("thanks")
|
||||
}
|
||||
if (st === "running") {
|
||||
return new Loading("Applying changes...")
|
||||
return new Loading("Applying changes...")
|
||||
}
|
||||
const error =st.error
|
||||
return new Combine([new FixedUiElement("Something went wrong...").SetClass("alert"), new FixedUiElement(error).SetClass("subtle")]).SetClass("flex flex-col")
|
||||
const error = st.error
|
||||
return new Combine([new FixedUiElement("Something went wrong...").SetClass("alert"), new FixedUiElement(error).SetClass("subtle")]).SetClass("flex flex-col")
|
||||
}
|
||||
))
|
||||
|
||||
|
@ -172,16 +183,5 @@ export default class AutoApplyButton implements SpecialVisualization {
|
|||
return [args[0]]
|
||||
}
|
||||
|
||||
private static generateDocs(supportedActions: string[]) {
|
||||
return [
|
||||
"A button to run many actions for many features at once.\n",
|
||||
"To effectively use this button, you'll need some ingredients:\n" +
|
||||
"- A target layer with features for which an action is defined in a tag rendering. The following special visualisations support an autoAction: " + supportedActions.join(", "),
|
||||
"- A host feature to place the auto-action on. This can be a big outline (such as a city). Another good option for this is the [current_view](./BuiltinLayers.md#current_view)",
|
||||
"- Then, use a calculated tag on the host feature to determine the overlapping object ids",
|
||||
"- At last, add this component"
|
||||
].join("\n")
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -50,7 +50,7 @@ export default class DeleteWizard extends Toggle {
|
|||
},
|
||||
options: DeleteConfig) {
|
||||
|
||||
|
||||
|
||||
const deleteAbility = new DeleteabilityChecker(id, state, options.neededChangesets)
|
||||
const tagsSource = state.allElements.getEventSourceById(id)
|
||||
|
||||
|
@ -293,7 +293,7 @@ class DeleteabilityChecker {
|
|||
|
||||
|
||||
constructor(id: string,
|
||||
state: {osmConnection: OsmConnection},
|
||||
state: { osmConnection: OsmConnection },
|
||||
allowDeletionAtChangesetCount?: number) {
|
||||
this._id = id;
|
||||
this._state = state;
|
||||
|
@ -316,7 +316,7 @@ class DeleteabilityChecker {
|
|||
const t = Translations.t.delete;
|
||||
const id = this._id;
|
||||
const state = this.canBeDeleted
|
||||
const self = this;
|
||||
const self = this;
|
||||
if (!id.startsWith("node")) {
|
||||
this.canBeDeleted.setData({
|
||||
canBeDeleted: false,
|
||||
|
|
|
@ -42,7 +42,7 @@ export default class EditableTagRendering extends Toggle {
|
|||
)
|
||||
}
|
||||
|
||||
private static CreateRendering(state: {featureSwitchUserbadge?: UIEventSource<boolean>, osmConnection: OsmConnection}, tags: UIEventSource<any>, configuration: TagRenderingConfig, units: Unit[], editMode: UIEventSource<boolean>): BaseUIElement {
|
||||
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;
|
||||
|
@ -60,7 +60,7 @@ export default class EditableTagRendering extends Toggle {
|
|||
|
||||
|
||||
const question = new Lazy(() =>
|
||||
new TagRenderingQuestion(tags, configuration,state,
|
||||
new TagRenderingQuestion(tags, configuration, state,
|
||||
{
|
||||
units: units,
|
||||
cancelButton: Translations.t.general.cancel.Clone()
|
||||
|
|
|
@ -139,7 +139,7 @@ export default class MoveWizard extends Toggle {
|
|||
minZoom: reason.minZoom,
|
||||
centerLocation: loc,
|
||||
mapBackground: new UIEventSource<BaseLayer>(preferredBackground) // We detach the layer
|
||||
|
||||
|
||||
})
|
||||
|
||||
if (reason.lockBounds) {
|
||||
|
|
|
@ -60,7 +60,6 @@ export default class NewNoteUi extends Toggle {
|
|||
|
||||
super(
|
||||
new Toggle(
|
||||
|
||||
new Combine(
|
||||
[
|
||||
t.noteLayerHasFilters.SetClass("alert"),
|
||||
|
|
|
@ -70,15 +70,15 @@ export default class NoteCommentElement extends Combine {
|
|||
|
||||
}
|
||||
|
||||
public static addCommentTo(txt: string, tags: UIEventSource<any>, state: {osmConnection: OsmConnection}){
|
||||
public static addCommentTo(txt: string, tags: UIEventSource<any>, state: { osmConnection: OsmConnection }) {
|
||||
const comments: any[] = JSON.parse(tags.data["comments"])
|
||||
const username = state.osmConnection.userDetails.data.name
|
||||
|
||||
var urlRegex = /(https?:\/\/[^\s]+)/g;
|
||||
const html = txt.replace(urlRegex, function(url) {
|
||||
const html = txt.replace(urlRegex, function (url) {
|
||||
return '<a href="' + url + '">' + url + '</a>';
|
||||
})
|
||||
|
||||
|
||||
comments.push({
|
||||
"date": new Date().toISOString(),
|
||||
"uid": state.osmConnection.userDetails.data.uid,
|
||||
|
@ -91,5 +91,5 @@ export default class NoteCommentElement extends Combine {
|
|||
tags.data["comments"] = JSON.stringify(comments)
|
||||
tags.ping()
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -45,7 +45,8 @@ export default class SplitRoadWizard extends Toggle {
|
|||
featureSwitchUserbadge: UIEventSource<boolean>,
|
||||
changes: Changes,
|
||||
layoutToUse: LayoutConfig,
|
||||
allElements: ElementStorage}) {
|
||||
allElements: ElementStorage
|
||||
}) {
|
||||
|
||||
const t = Translations.t.split;
|
||||
|
||||
|
@ -84,7 +85,7 @@ export default class SplitRoadWizard extends Toggle {
|
|||
zoomToFeatures: true,
|
||||
state
|
||||
})
|
||||
|
||||
|
||||
new ShowDataLayer({
|
||||
features: new StaticFeatureSource(splitPoints, true),
|
||||
leafletMap: miniMap.leafletMap,
|
||||
|
@ -94,7 +95,6 @@ export default class SplitRoadWizard extends Toggle {
|
|||
state
|
||||
})
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handles a click on the overleaf map.
|
||||
|
|
|
@ -38,6 +38,7 @@ export default class TagApplyButton implements AutoAction {
|
|||
doc: "If specified, applies the the tags onto _another_ object. The id will be read from properties[id_of_object_to_apply_this_one] of the selected object. The tags are still calculated based on the tags of the _selected_ element"
|
||||
}
|
||||
];
|
||||
public readonly example = "`{tag_apply(survey_date=$_now:date, Surveyed today!)}`, `{tag_apply(addr:street=$addr:street, Apply the address, apply_icon.svg, _closest_osm_id)";
|
||||
|
||||
public static generateTagsToApply(spec: string, tagSource: UIEventSource<any>): UIEventSource<Tag[]> {
|
||||
|
||||
|
@ -79,12 +80,10 @@ export default class TagApplyButton implements AutoAction {
|
|||
|
||||
}
|
||||
|
||||
public readonly example = "`{tag_apply(survey_date=$_now:date, Surveyed today!)}`, `{tag_apply(addr:street=$addr:street, Apply the address, apply_icon.svg, _closest_osm_id)";
|
||||
|
||||
async applyActionOn(state: {
|
||||
layoutToUse: LayoutConfig,
|
||||
changes: Changes
|
||||
}, tags: UIEventSource<any>, args: string[]) : Promise<void>{
|
||||
}, tags: UIEventSource<any>, args: string[]): Promise<void> {
|
||||
const tagsToApply = TagApplyButton.generateTagsToApply(args[0], tags)
|
||||
const targetIdKey = args[3]
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ export default class TagRenderingAnswer extends VariableUiElement {
|
|||
|
||||
constructor(tagsSource: UIEventSource<any>, configuration: TagRenderingConfig,
|
||||
state: any,
|
||||
contentClasses: string = "", contentStyle: string = "", options?:{
|
||||
specialViz: Map<string, BaseUIElement>
|
||||
}) {
|
||||
contentClasses: string = "", contentStyle: string = "", options?: {
|
||||
specialViz: Map<string, BaseUIElement>
|
||||
}) {
|
||||
if (configuration === undefined) {
|
||||
throw "Trying to generate a tagRenderingAnswer without configuration..."
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue