forked from MapComplete/MapComplete
Themes(toilets): add an allowed range to some freeform inputs, allow to specify 'units' in the freeform, add the possibility to convert units
This commit is contained in:
parent
32cb8f489f
commit
fb8ead2a2c
16 changed files with 270 additions and 103 deletions
|
|
@ -16,7 +16,12 @@ export class Denomination {
|
|||
public readonly alternativeDenominations: string[]
|
||||
public readonly human: TypedTranslation<{ quantity: string }>
|
||||
public readonly humanSingular?: Translation
|
||||
private readonly _validator: Validator
|
||||
public readonly validator: Validator
|
||||
/**
|
||||
* IF a conversion to the canonical value is possible, this is the factor.
|
||||
* E.g. for "cm", the factor is 0.01, as "1cm = 0.01m"
|
||||
*/
|
||||
public readonly factorToCanonical?: number
|
||||
|
||||
private constructor(
|
||||
canonical: string,
|
||||
|
|
@ -27,7 +32,8 @@ export class Denomination {
|
|||
alternativeDenominations: string[],
|
||||
_human: TypedTranslation<{ quantity: string }>,
|
||||
_humanSingular: Translation,
|
||||
validator: Validator
|
||||
validator: Validator,
|
||||
factorToCanonical: number
|
||||
) {
|
||||
this.canonical = canonical
|
||||
this._canonicalSingular = _canonicalSingular
|
||||
|
|
@ -37,7 +43,8 @@ export class Denomination {
|
|||
this.alternativeDenominations = alternativeDenominations
|
||||
this.human = _human
|
||||
this.humanSingular = _humanSingular
|
||||
this._validator = validator
|
||||
this.validator = validator
|
||||
this.factorToCanonical = factorToCanonical
|
||||
}
|
||||
|
||||
public static fromJson(json: DenominationConfigJson, validator: Validator, context: string) {
|
||||
|
|
@ -73,7 +80,8 @@ export class Denomination {
|
|||
json.alternativeDenomination?.map((v) => v.trim()) ?? [],
|
||||
humanTexts,
|
||||
Translations.T(json.humanSingular, context + "humanSingular"),
|
||||
validator
|
||||
validator,
|
||||
json.factorToCanonical
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +95,8 @@ export class Denomination {
|
|||
this.alternativeDenominations,
|
||||
this.human,
|
||||
this.humanSingular,
|
||||
this._validator
|
||||
this.validator,
|
||||
this.factorToCanonical
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -101,7 +110,8 @@ export class Denomination {
|
|||
[this.canonical, ...this.alternativeDenominations],
|
||||
this.human,
|
||||
this.humanSingular,
|
||||
this._validator
|
||||
this.validator,
|
||||
this.factorToCanonical
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -217,10 +227,10 @@ export class Denomination {
|
|||
return null
|
||||
}
|
||||
|
||||
if (!this._validator.isValid(value.trim())) {
|
||||
if (!this.validator.isValid(value.trim())) {
|
||||
return null
|
||||
}
|
||||
return this._validator.reformat(value.trim())
|
||||
return this.validator.reformat(value.trim())
|
||||
}
|
||||
|
||||
withValidator(validator: Validator) {
|
||||
|
|
@ -233,7 +243,8 @@ export class Denomination {
|
|||
this.alternativeDenominations,
|
||||
this.human,
|
||||
this.humanSingular,
|
||||
validator
|
||||
validator,
|
||||
this.factorToCanonical
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue