Full code cleanup

This commit is contained in:
Pieter Vander Vennet 2022-01-26 21:40:38 +01:00
parent 3a4a2a2016
commit fa971ffbbf
300 changed files with 16352 additions and 19284 deletions

View file

@ -12,7 +12,7 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
*/
private readonly _includeClosedNotesDays: number;
constructor(includeClosedNotesDays= 0) {
constructor(includeClosedNotesDays = 0) {
super([
"Advanced conversion which deducts a layer showing all notes that are 'importable' (i.e. a note that contains a link to some MapComplete theme, with hash '#import').",
"The import buttons and matches will be based on the presets of the given theme",
@ -24,55 +24,55 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
const errors = []
const warnings = []
const t = Translations.t.importLayer;
/**
* The note itself will contain `tags=k=v;k=v;k=v;...
* This must be matched with a regex.
* This is a simple JSON-object as how it'll be put into the layerConfigJson directly
*/
const isShownIfAny : any[] = []
const isShownIfAny: any[] = []
const layer = new LayerConfig(layerJson, "while constructing a note-import layer")
for (const preset of layer.presets) {
const mustMatchAll = []
for (const tag of preset.tags) {
const key = tag.key
const value = tag.value
const condition = "_tags~(^|.*;)"+key+"\="+value+"($|;.*)"
const condition = "_tags~(^|.*;)" + key + "\=" + value + "($|;.*)"
mustMatchAll.push(condition)
}
isShownIfAny.push({and:mustMatchAll})
isShownIfAny.push({and: mustMatchAll})
}
const pointRenderings = (layerJson.mapRendering??[]).filter(r => r!== null && r["location"] !== undefined);
const firstRender = <PointRenderingConfigJson>(pointRenderings [0])
const pointRenderings = (layerJson.mapRendering ?? []).filter(r => r !== null && r["location"] !== undefined);
const firstRender = <PointRenderingConfigJson>(pointRenderings [0])
const icon = firstRender.icon
const iconBadges = []
const title = layer.presets[0].title
if(icon !== undefined){
if (icon !== undefined) {
iconBadges.push({
if: {and:[]},
then:icon
if: {and: []},
then: icon
})
}
const importButton = {}
{
const translations = t.importButton.Subs({layerId: layer.id, title: layer.presets[0].title}).translations
const translations = t.importButton.Subs({layerId: layer.id, title: layer.presets[0].title}).translations
for (const key in translations) {
importButton[key] = "{"+translations[key]+"}"
}
importButton[key] = "{" + translations[key] + "}"
}
}
function embed(prefix, translation: Translation, postfix){
function embed(prefix, translation: Translation, postfix) {
const result = {}
for (const language in translation.translations) {
result[language] = prefix+translation.translations[language] + postfix
result[language] = prefix + translation.translations[language] + postfix
}
return result
}
const result : LayerConfigJson = {
"id": "note_import_"+layer.id,
const result: LayerConfigJson = {
"id": "note_import_" + layer.id,
// By disabling the name, the import-layers won't pollute the filter view "name": t.layerName.Subs({title: layer.title.render}).translations,
"description": t.description.Subs({title: layer.title.render}).translations,
"source": {
@ -81,7 +81,7 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
"id~*"
]
},
"geoJson": "https://api.openstreetmap.org/api/0.6/notes.json?limit=10000&closed="+this._includeClosedNotesDays+"&bbox={x_min},{y_min},{x_max},{y_max}",
"geoJson": "https://api.openstreetmap.org/api/0.6/notes.json?limit=10000&closed=" + this._includeClosedNotesDays + "&bbox={x_min},{y_min},{x_max},{y_max}",
"geoJsonZoomLevel": 10,
"maxCacheAge": 0
},
@ -101,13 +101,15 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
"mappings": [
{
"if": "comments!~.*https://mapcomplete.osm.be.*",
"then":"no"
"then": "no"
},
{
"if": {and:
"if": {
and:
["_trigger_index~*",
{or: isShownIfAny}
]},
]
},
"then": "yes"
}
]
@ -135,12 +137,12 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
{
"id": "close_note_",
"render": embed(
"{close_note(", t.notFound.Subs({title}),", ./assets/svg/close.svg, id, This feature does not exist)}" ),
"{close_note(", t.notFound.Subs({title}), ", ./assets/svg/close.svg, id, This feature does not exist)}"),
condition: "closed_at="
},
{
"id": "close_note_mapped",
"render": embed("{close_note(",t.alreadyMapped.Subs({title}), ", ./assets/svg/checkmark.svg, id, Already mapped)}"),
"render": embed("{close_note(", t.alreadyMapped.Subs({title}), ", ./assets/svg/checkmark.svg, id, Already mapped)}"),
condition: "closed_at="
},
{
@ -164,9 +166,9 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
],
"icon": {
"render": "circle:white;help:black",
mappings:[{
if: {or:["closed_at~*","_imported=yes"]},
then:"circle:white;checkmark:black"
mappings: [{
if: {or: ["closed_at~*", "_imported=yes"]},
then: "circle:white;checkmark:black"
}]
},
iconBadges,
@ -174,8 +176,8 @@ export default class CreateNoteImportLayer extends Conversion<LayerConfigJson, L
}
]
}
return {
result,
errors, warnings