forked from MapComplete/MapComplete
refactoring: Fix generate:layeroverview
This commit is contained in:
parent
41e6a2c760
commit
9b2f92dedc
25 changed files with 194 additions and 216 deletions
56
UI/InputElement/Validator.ts
Normal file
56
UI/InputElement/Validator.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
import BaseUIElement from "../BaseUIElement"
|
||||
import { Translation } from "../i18n/Translation"
|
||||
import Translations from "../i18n/Translations"
|
||||
|
||||
/**
|
||||
* A 'TextFieldValidator' contains various methods to check and cleanup an entered value or to give feedback.
|
||||
* They also double as an index of supported types for textfields in MapComplete
|
||||
*/
|
||||
export abstract class Validator {
|
||||
public readonly name: string
|
||||
/*
|
||||
* An explanation for the theme builder.
|
||||
* This can indicate which special input element is used, ...
|
||||
* */
|
||||
public readonly explanation: string
|
||||
/**
|
||||
* What HTML-inputmode to use
|
||||
*/
|
||||
public readonly inputmode?: string
|
||||
|
||||
constructor(name: string, explanation: string | BaseUIElement, inputmode?: string) {
|
||||
this.name = name
|
||||
this.inputmode = inputmode
|
||||
if (this.name.endsWith("textfield")) {
|
||||
this.name = this.name.substr(0, this.name.length - "TextField".length)
|
||||
}
|
||||
if (this.name.endsWith("textfielddef")) {
|
||||
this.name = this.name.substr(0, this.name.length - "TextFieldDef".length)
|
||||
}
|
||||
if (typeof explanation === "string") {
|
||||
this.explanation = explanation
|
||||
} else {
|
||||
this.explanation = explanation.AsMarkdown()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a piece of feedback. By default, validation.<type> will be used, resulting in a generic 'not a valid <type>'.
|
||||
* However, inheritors might overwrite this to give more specific feedback
|
||||
* @param s
|
||||
*/
|
||||
public getFeedback(s: string): Translation {
|
||||
const tr = Translations.t.validation[this.name]
|
||||
if (tr !== undefined) {
|
||||
return tr["feedback"]
|
||||
}
|
||||
}
|
||||
|
||||
public isValid(string: string, requestCountry: () => string): boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
public reformat(s: string, country?: () => string): string {
|
||||
return s
|
||||
}
|
||||
}
|
|
@ -1,77 +1,23 @@
|
|||
import BaseUIElement from "../BaseUIElement"
|
||||
import Combine from "../Base/Combine"
|
||||
import Title from "../Base/Title"
|
||||
import Translations from "../i18n/Translations"
|
||||
import { Translation } from "../i18n/Translation"
|
||||
import WikidataValidator from "./Validators/WikidataValidator"
|
||||
import { Validator } from "./Validator"
|
||||
import StringValidator from "./Validators/StringValidator"
|
||||
import TextValidator from "./Validators/TextValidator"
|
||||
import DateValidator from "./Validators/DateValidator"
|
||||
import LengthValidator from "./Validators/LengthValidator"
|
||||
import IntValidator from "./Validators/IntValidator"
|
||||
import EmailValidator from "./Validators/EmailValidator"
|
||||
import DirectionValidator from "./Validators/DirectionValidator"
|
||||
import NatValidator from "./Validators/NatValidator"
|
||||
import OpeningHoursValidator from "./Validators/OpeningHoursValidator"
|
||||
import PFloatValidator from "./Validators/PFloatValidator"
|
||||
import ColorValidator from "./Validators/ColorValidator"
|
||||
import PhoneValidator from "./Validators/PhoneValidator"
|
||||
import UrlValidator from "./Validators/UrlValidator"
|
||||
import FloatValidator from "./Validators/FloatValidator"
|
||||
import IntValidator from "./Validators/IntValidator"
|
||||
import LengthValidator from "./Validators/LengthValidator"
|
||||
import DirectionValidator from "./Validators/DirectionValidator"
|
||||
import WikidataValidator from "./Validators/WikidataValidator"
|
||||
import PNatValidator from "./Validators/PNatValidator"
|
||||
|
||||
/**
|
||||
* A 'TextFieldValidator' contains various methods to check and cleanup an entered value or to give feedback.
|
||||
* They also double as an index of supported types for textfields in MapComplete
|
||||
*/
|
||||
export abstract class Validator {
|
||||
public readonly name: string
|
||||
/*
|
||||
* An explanation for the theme builder.
|
||||
* This can indicate which special input element is used, ...
|
||||
* */
|
||||
public readonly explanation: string
|
||||
/**
|
||||
* What HTML-inputmode to use
|
||||
*/
|
||||
public readonly inputmode?: string
|
||||
|
||||
constructor(name: string, explanation: string | BaseUIElement, inputmode?: string) {
|
||||
this.name = name
|
||||
this.inputmode = inputmode
|
||||
if (this.name.endsWith("textfield")) {
|
||||
this.name = this.name.substr(0, this.name.length - "TextField".length)
|
||||
}
|
||||
if (this.name.endsWith("textfielddef")) {
|
||||
this.name = this.name.substr(0, this.name.length - "TextFieldDef".length)
|
||||
}
|
||||
if (typeof explanation === "string") {
|
||||
this.explanation = explanation
|
||||
} else {
|
||||
this.explanation = explanation.AsMarkdown()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a piece of feedback. By default, validation.<type> will be used, resulting in a generic 'not a valid <type>'.
|
||||
* However, inheritors might overwrite this to give more specific feedback
|
||||
* @param s
|
||||
*/
|
||||
public getFeedback(s: string): Translation {
|
||||
const tr = Translations.t.validation[this.name]
|
||||
if (tr !== undefined) {
|
||||
return tr["feedback"]
|
||||
}
|
||||
}
|
||||
|
||||
public isValid(string: string, requestCountry: () => string): boolean {
|
||||
return true
|
||||
}
|
||||
|
||||
public reformat(s: string, country?: () => string): string {
|
||||
return s
|
||||
}
|
||||
}
|
||||
import FloatValidator from "./Validators/FloatValidator"
|
||||
import PFloatValidator from "./Validators/PFloatValidator"
|
||||
import EmailValidator from "./Validators/EmailValidator"
|
||||
import UrlValidator from "./Validators/UrlValidator"
|
||||
import PhoneValidator from "./Validators/PhoneValidator"
|
||||
import OpeningHoursValidator from "./Validators/OpeningHoursValidator"
|
||||
import ColorValidator from "./Validators/ColorValidator"
|
||||
import BaseUIElement from "../BaseUIElement"
|
||||
import Combine from "../Base/Combine"
|
||||
import Title from "../Base/Title"
|
||||
|
||||
export default class Validators {
|
||||
private static readonly AllValidators: ReadonlyArray<Validator> = [
|
|
@ -1,4 +1,4 @@
|
|||
import { Validator } from "../ValidatedTextField"
|
||||
import { Validator } from "../Validator"
|
||||
|
||||
export default class ColorValidator extends Validator {
|
||||
constructor() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Validator } from "../ValidatedTextField"
|
||||
import { Validator } from "../Validator"
|
||||
|
||||
export default class DateValidator extends Validator {
|
||||
constructor() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Validator } from "../ValidatedTextField"
|
||||
import IntValidator from "./IntValidator";
|
||||
import IntValidator from "./IntValidator"
|
||||
import { Validator } from "../Validator"
|
||||
|
||||
export default class DirectionValidator extends IntValidator {
|
||||
constructor() {
|
||||
|
@ -13,5 +13,4 @@ export default class DirectionValidator extends IntValidator {
|
|||
const n = Number(str) % 360
|
||||
return "" + n
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Validator } from "../ValidatedTextField.js"
|
||||
import { Translation } from "../../i18n/Translation.js"
|
||||
import Translations from "../../i18n/Translations.js"
|
||||
import * as emailValidatorLibrary from "email-validator"
|
||||
import { Validator } from "../Validator"
|
||||
export default class EmailValidator extends Validator {
|
||||
constructor() {
|
||||
super("email", "An email adress", "email")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Translation } from "../../i18n/Translation"
|
||||
import Translations from "../../i18n/Translations"
|
||||
import { Validator } from "../ValidatedTextField"
|
||||
import { Validator } from "../Validator"
|
||||
|
||||
export default class FloatValidator extends Validator {
|
||||
inputmode = "decimal"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Translation } from "../../i18n/Translation"
|
||||
import Translations from "../../i18n/Translations"
|
||||
import { Validator } from "../ValidatedTextField"
|
||||
import { Validator } from "../Validator"
|
||||
|
||||
export default class IntValidator extends Validator {
|
||||
constructor(name?: string, explanation?: string) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Validator } from "../ValidatedTextField"
|
||||
import { Validator } from "../Validator"
|
||||
|
||||
export default class LengthValidator extends Validator {
|
||||
constructor() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Validator } from "../ValidatedTextField"
|
||||
import Combine from "../../Base/Combine"
|
||||
import Title from "../../Base/Title"
|
||||
import Table from "../../Base/Table"
|
||||
import { Validator } from "../Validator"
|
||||
|
||||
export default class OpeningHoursValidator extends Validator {
|
||||
constructor() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Translation } from "../../i18n/Translation"
|
||||
import Translations from "../../i18n/Translations"
|
||||
import { Validator } from "../ValidatedTextField"
|
||||
import { Validator } from "../Validator"
|
||||
|
||||
export default class PFloatValidator extends Validator {
|
||||
constructor() {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Validator } from "../ValidatedTextField"
|
||||
import { parsePhoneNumberFromString } from "libphonenumber-js"
|
||||
import { Validator } from "../Validator"
|
||||
|
||||
export default class PhoneValidator extends Validator {
|
||||
constructor() {
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import { Validator } from "../ValidatedTextField"
|
||||
import { Validator } from "../Validator"
|
||||
|
||||
export default class StringValidator extends Validator {
|
||||
constructor() {
|
||||
super("string", "A simple piece of text")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Validator } from "../ValidatedTextField"
|
||||
import { Validator } from "../Validator"
|
||||
|
||||
export default class TextValidator extends Validator {
|
||||
constructor() {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Validator } from "../ValidatedTextField"
|
||||
import { Validator } from "../Validator"
|
||||
|
||||
export default class UrlValidator extends Validator {
|
||||
constructor() {
|
||||
|
|
|
@ -6,7 +6,7 @@ import { UIEventSource } from "../../../Logic/UIEventSource"
|
|||
import Locale from "../../i18n/Locale"
|
||||
import { Utils } from "../../../Utils"
|
||||
import WikidataSearchBox from "../../Wikipedia/WikidataSearchBox"
|
||||
import { Validator } from "../ValidatedTextField"
|
||||
import { Validator } from "../Validator"
|
||||
|
||||
export default class WikidataValidator extends Validator {
|
||||
constructor() {
|
||||
|
|
|
@ -1,47 +1,49 @@
|
|||
import BaseUIElement from "../BaseUIElement";
|
||||
import { SubtleButton } from "../Base/SubtleButton";
|
||||
import { UIEventSource } from "../../Logic/UIEventSource";
|
||||
import Combine from "../Base/Combine";
|
||||
import { VariableUiElement } from "../Base/VariableUIElement";
|
||||
import Translations from "../i18n/Translations";
|
||||
import Toggle from "../Input/Toggle";
|
||||
import CreateNewNodeAction from "../../Logic/Osm/Actions/CreateNewNodeAction";
|
||||
import Loading from "../Base/Loading";
|
||||
import { OsmConnection } from "../../Logic/Osm/OsmConnection";
|
||||
import Lazy from "../Base/Lazy";
|
||||
import ConfirmLocationOfPoint from "../NewPoint/ConfirmLocationOfPoint";
|
||||
import Img from "../Base/Img";
|
||||
import FilteredLayer from "../../Models/FilteredLayer";
|
||||
import { FixedUiElement } from "../Base/FixedUiElement";
|
||||
import Svg from "../../Svg";
|
||||
import { Utils } from "../../Utils";
|
||||
import StaticFeatureSource from "../../Logic/FeatureSource/Sources/StaticFeatureSource";
|
||||
import CreateWayWithPointReuseAction, { MergePointConfig } from "../../Logic/Osm/Actions/CreateWayWithPointReuseAction";
|
||||
import OsmChangeAction, { OsmCreateAction } from "../../Logic/Osm/Actions/OsmChangeAction";
|
||||
import FeatureSource from "../../Logic/FeatureSource/FeatureSource";
|
||||
import { OsmObject, OsmWay } from "../../Logic/Osm/OsmObject";
|
||||
import { PresetInfo } from "../BigComponents/SimpleAddUI";
|
||||
import { TagUtils } from "../../Logic/Tags/TagUtils";
|
||||
import { And } from "../../Logic/Tags/And";
|
||||
import ReplaceGeometryAction from "../../Logic/Osm/Actions/ReplaceGeometryAction";
|
||||
import CreateMultiPolygonWithPointReuseAction from "../../Logic/Osm/Actions/CreateMultiPolygonWithPointReuseAction";
|
||||
import { Tag } from "../../Logic/Tags/Tag";
|
||||
import TagApplyButton from "./TagApplyButton";
|
||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig";
|
||||
import conflation_json from "../../assets/layers/conflation/conflation.json";
|
||||
import { GeoOperations } from "../../Logic/GeoOperations";
|
||||
import { LoginToggle } from "./LoginButton";
|
||||
import { AutoAction } from "./AutoApplyButton";
|
||||
import Hash from "../../Logic/Web/Hash";
|
||||
import { PreciseInput } from "../../Models/ThemeConfig/PresetConfig";
|
||||
import { SpecialVisualization, SpecialVisualizationState } from "../SpecialVisualization";
|
||||
import Maproulette from "../../Logic/Maproulette";
|
||||
import { Feature, Point } from "geojson";
|
||||
import { LayerConfigJson } from "../../Models/ThemeConfig/Json/LayerConfigJson";
|
||||
import ShowDataLayer from "../Map/ShowDataLayer";
|
||||
import { MapLibreAdaptor } from "../Map/MapLibreAdaptor";
|
||||
import SvelteUIElement from "../Base/SvelteUIElement";
|
||||
import MaplibreMap from "../Map/MaplibreMap.svelte";
|
||||
import BaseUIElement from "../BaseUIElement"
|
||||
import { SubtleButton } from "../Base/SubtleButton"
|
||||
import { UIEventSource } from "../../Logic/UIEventSource"
|
||||
import Combine from "../Base/Combine"
|
||||
import { VariableUiElement } from "../Base/VariableUIElement"
|
||||
import Translations from "../i18n/Translations"
|
||||
import Toggle from "../Input/Toggle"
|
||||
import CreateNewNodeAction from "../../Logic/Osm/Actions/CreateNewNodeAction"
|
||||
import Loading from "../Base/Loading"
|
||||
import { OsmConnection } from "../../Logic/Osm/OsmConnection"
|
||||
import Lazy from "../Base/Lazy"
|
||||
import ConfirmLocationOfPoint from "../NewPoint/ConfirmLocationOfPoint"
|
||||
import Img from "../Base/Img"
|
||||
import FilteredLayer from "../../Models/FilteredLayer"
|
||||
import { FixedUiElement } from "../Base/FixedUiElement"
|
||||
import Svg from "../../Svg"
|
||||
import { Utils } from "../../Utils"
|
||||
import StaticFeatureSource from "../../Logic/FeatureSource/Sources/StaticFeatureSource"
|
||||
import CreateWayWithPointReuseAction, {
|
||||
MergePointConfig,
|
||||
} from "../../Logic/Osm/Actions/CreateWayWithPointReuseAction"
|
||||
import OsmChangeAction, { OsmCreateAction } from "../../Logic/Osm/Actions/OsmChangeAction"
|
||||
import FeatureSource from "../../Logic/FeatureSource/FeatureSource"
|
||||
import { OsmObject, OsmWay } from "../../Logic/Osm/OsmObject"
|
||||
import { PresetInfo } from "../BigComponents/SimpleAddUI"
|
||||
import { TagUtils } from "../../Logic/Tags/TagUtils"
|
||||
import { And } from "../../Logic/Tags/And"
|
||||
import ReplaceGeometryAction from "../../Logic/Osm/Actions/ReplaceGeometryAction"
|
||||
import CreateMultiPolygonWithPointReuseAction from "../../Logic/Osm/Actions/CreateMultiPolygonWithPointReuseAction"
|
||||
import { Tag } from "../../Logic/Tags/Tag"
|
||||
import TagApplyButton from "./TagApplyButton"
|
||||
import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
|
||||
import conflation_json from "../../assets/layers/conflation/conflation.json"
|
||||
import { GeoOperations } from "../../Logic/GeoOperations"
|
||||
import { LoginToggle } from "./LoginButton"
|
||||
import { AutoAction } from "./AutoApplyButton"
|
||||
import Hash from "../../Logic/Web/Hash"
|
||||
import { PreciseInput } from "../../Models/ThemeConfig/PresetConfig"
|
||||
import { SpecialVisualization, SpecialVisualizationState } from "../SpecialVisualization"
|
||||
import Maproulette from "../../Logic/Maproulette"
|
||||
import { Feature, Point } from "geojson"
|
||||
import { LayerConfigJson } from "../../Models/ThemeConfig/Json/LayerConfigJson"
|
||||
import ShowDataLayer from "../Map/ShowDataLayer"
|
||||
import { MapLibreAdaptor } from "../Map/MapLibreAdaptor"
|
||||
import SvelteUIElement from "../Base/SvelteUIElement"
|
||||
import MaplibreMap from "../Map/MaplibreMap.svelte"
|
||||
|
||||
/**
|
||||
* A helper class for the various import-flows.
|
||||
|
@ -377,13 +379,6 @@ export class ConflateButton extends AbstractImportButton {
|
|||
)
|
||||
}
|
||||
|
||||
getLayerDependencies(argsRaw: string[]): string[] {
|
||||
const deps = super.getLayerDependencies(argsRaw)
|
||||
// Force 'type_node' as dependency
|
||||
deps.push("type_node")
|
||||
return deps
|
||||
}
|
||||
|
||||
constructElement(
|
||||
state: SpecialVisualizationState,
|
||||
args: {
|
||||
|
@ -543,12 +538,6 @@ export class ImportWayButton extends AbstractImportButton implements AutoAction
|
|||
return type === "LineString" || type === "Polygon"
|
||||
}
|
||||
|
||||
getLayerDependencies(argsRaw: string[]): string[] {
|
||||
const deps = super.getLayerDependencies(argsRaw)
|
||||
deps.push("type_node")
|
||||
return deps
|
||||
}
|
||||
|
||||
constructElement(
|
||||
state: SpecialVisualizationState,
|
||||
args,
|
||||
|
@ -565,7 +554,7 @@ export class ImportWayButton extends AbstractImportButton implements AutoAction
|
|||
|
||||
// Upload the way to OSM
|
||||
const mergeConfigs = this.GetMergeConfig(args)
|
||||
let action: OsmCreateAction & {getPreview?: any} = ImportWayButton.CreateAction(
|
||||
let action: OsmCreateAction & { getPreview?: any } = ImportWayButton.CreateAction(
|
||||
feature,
|
||||
args,
|
||||
state,
|
||||
|
@ -751,7 +740,7 @@ export class ImportPointButton extends AbstractImportButton {
|
|||
boundsFactor: 3,
|
||||
}
|
||||
|
||||
const [lon, lat] = <[number,number]> feature.geometry.coordinates
|
||||
const [lon, lat] = <[number, number]>feature.geometry.coordinates
|
||||
return new ConfirmLocationOfPoint(
|
||||
state,
|
||||
state.guistate.filterViewIsOpened,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue