forked from MapComplete/MapComplete
Fix questions: applicable mappings are now calculated dynamically; charging station theme now only shows applicable plugs based on the allowed vehicle types
This commit is contained in:
parent
bedc576313
commit
df34239256
14 changed files with 3677 additions and 3359 deletions
|
@ -31,6 +31,8 @@ Strict not equals
|
|||
To check if a key does _not_ equal a certain value, use `key!=value`. This is converted behind the scenes
|
||||
to `key!~^value$`
|
||||
|
||||
If `key` is not present or empty, this will match too.
|
||||
|
||||
### If key is present
|
||||
|
||||
This implies that, to check if a key is present, `key!=` can be used. This will only match if the key is present and not
|
||||
|
|
|
@ -480,8 +480,11 @@ export class InitUiElements {
|
|||
|
||||
|
||||
const bounds = State.state.currentBounds.data
|
||||
const tilebbox = BBox.fromTileIndex(source.tileIndex)
|
||||
if (!tilebbox.overlapsWith(bounds)) {
|
||||
if(bounds === undefined){
|
||||
// Map is not yet displayed
|
||||
return false;
|
||||
}
|
||||
if (!source.bbox.overlapsWith(bounds)) {
|
||||
// Not within range
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -141,18 +141,25 @@ export default class FeaturePipeline {
|
|||
|
||||
if (source.geojsonZoomLevel === undefined) {
|
||||
// This is a 'load everything at once' geojson layer
|
||||
// We split them up into tiles anyway
|
||||
const src = new GeoJsonSource(filteredLayer)
|
||||
TiledFeatureSource.createHierarchy(src, {
|
||||
layer: src.layer,
|
||||
minZoomLevel: 14,
|
||||
dontEnforceMinZoom: true,
|
||||
registerTile: (tile) => {
|
||||
new RegisteringAllFromFeatureSourceActor(tile)
|
||||
perLayerHierarchy.get(id).registerTile(tile)
|
||||
tile.features.addCallbackAndRunD(_ => self.newDataLoadedSignal.setData(tile))
|
||||
}
|
||||
})
|
||||
|
||||
if (source.isOsmCacheLayer) {
|
||||
// We split them up into tiles anyway as it is an OSM source
|
||||
TiledFeatureSource.createHierarchy(src, {
|
||||
layer: src.layer,
|
||||
minZoomLevel: 14,
|
||||
dontEnforceMinZoom: true,
|
||||
registerTile: (tile) => {
|
||||
new RegisteringAllFromFeatureSourceActor(tile)
|
||||
perLayerHierarchy.get(id).registerTile(tile)
|
||||
tile.features.addCallbackAndRunD(_ => self.newDataLoadedSignal.setData(tile))
|
||||
}
|
||||
})
|
||||
}else{
|
||||
new RegisteringAllFromFeatureSourceActor(src)
|
||||
perLayerHierarchy.get(id).registerTile(src)
|
||||
src.features.addCallbackAndRunD(_ => self.newDataLoadedSignal.setData(src))
|
||||
}
|
||||
} else {
|
||||
new DynamicGeoJsonTileSource(
|
||||
filteredLayer,
|
||||
|
@ -312,9 +319,9 @@ export default class FeaturePipeline {
|
|||
if (zoom < 8) {
|
||||
zoom = zoom + 2
|
||||
}
|
||||
|
||||
|
||||
const range = bbox.containingTileRange(zoom)
|
||||
if(range.total > 100){
|
||||
if (range.total > 100) {
|
||||
return false
|
||||
}
|
||||
const self = this;
|
||||
|
|
|
@ -68,6 +68,50 @@ export class UIEventSource<T> {
|
|||
return src
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a UIEVentSource with a list, returns a new UIEventSource which is only updated if the _contents_ of the list are different.
|
||||
* E.g.
|
||||
* const src = new UIEventSource([1,2,3])
|
||||
* const stable = UIEventSource.ListStabilized(src)
|
||||
* src.addCallback(_ => console.log("src pinged"))
|
||||
* stable.addCallback(_ => console.log("stable pinged))
|
||||
* src.setDate([...src.data])
|
||||
*
|
||||
* This will only trigger 'src pinged'
|
||||
*
|
||||
* @param src
|
||||
* @constructor
|
||||
*/
|
||||
public static ListStabilized<T>(src: UIEventSource<T[]>) : UIEventSource<T[]>{
|
||||
|
||||
const stable = new UIEventSource<T[]>(src.data)
|
||||
src.addCallback(list => {
|
||||
if(list === undefined){
|
||||
stable.setData(undefined)
|
||||
return;
|
||||
}
|
||||
const oldList = stable.data
|
||||
if(oldList === list){
|
||||
return;
|
||||
}
|
||||
if(oldList.length !== list.length){
|
||||
stable.setData(list);
|
||||
return;
|
||||
}
|
||||
|
||||
for (let i = 0; i < list.length; i++) {
|
||||
if(oldList[i] !== list[i]){
|
||||
stable.setData(list);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// No actual changes, so we don't do anything
|
||||
return;
|
||||
})
|
||||
return stable
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a callback
|
||||
*
|
||||
|
@ -88,7 +132,7 @@ export class UIEventSource<T> {
|
|||
|
||||
public addCallbackAndRun(callback: ((latestData: T) => (boolean | void | any))): UIEventSource<T> {
|
||||
const doDeleteCallback = callback(this.data);
|
||||
if (!doDeleteCallback) {
|
||||
if (doDeleteCallback !== true) {
|
||||
this.addCallback(callback);
|
||||
}
|
||||
return this;
|
||||
|
|
0
Logic/Web/Wikipedia.ts
Normal file
0
Logic/Web/Wikipedia.ts
Normal file
|
@ -11,11 +11,15 @@ export class FixedInputElement<T> extends InputElement<T> {
|
|||
private readonly _el: HTMLElement;
|
||||
|
||||
constructor(rendering: BaseUIElement | string,
|
||||
value: T,
|
||||
value: T | UIEventSource<T>,
|
||||
comparator: ((t0: T, t1: T) => boolean) = undefined) {
|
||||
super();
|
||||
this._comparator = comparator ?? ((t0, t1) => t0 == t1);
|
||||
this.value = new UIEventSource<T>(value);
|
||||
if(value instanceof UIEventSource){
|
||||
this.value = value
|
||||
}else{
|
||||
this.value = new UIEventSource<T>(value);
|
||||
}
|
||||
|
||||
const selected = this.IsSelected;
|
||||
this._el = document.createElement("span")
|
||||
|
|
|
@ -179,26 +179,4 @@ export class RadioButton<T> extends InputElement<T> {
|
|||
return form;
|
||||
}
|
||||
|
||||
/*
|
||||
public ShowValue(t: T): boolean {
|
||||
if (t === undefined) {
|
||||
return false;
|
||||
}
|
||||
if (!this.IsValid(t)) {
|
||||
return false;
|
||||
}
|
||||
// We check that what is selected matches the previous rendering
|
||||
for (let i = 0; i < this._elements.length; i++) {
|
||||
const e = this._elements[i];
|
||||
if (e.IsValid(t)) {
|
||||
this._selectedElementIndex.setData(i);
|
||||
e.GetValue().setData(t);
|
||||
const radio = document.getElementById(this.IdFor(i));
|
||||
// @ts-ignore
|
||||
radio?.checked = true;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
|
|
@ -18,41 +18,53 @@ export default class EditableTagRendering extends Toggle {
|
|||
units: Unit [],
|
||||
editMode = new UIEventSource<boolean>(false)
|
||||
) {
|
||||
|
||||
// The tagrendering is hidden if:
|
||||
// The answer is unknown. The questionbox will then show the question
|
||||
// There is a condition hiding the answer
|
||||
const renderingIsShown = tags.map(tags =>
|
||||
configuration.IsKnown(tags) &&
|
||||
(configuration?.condition?.matchesProperties(tags) ?? true))
|
||||
super(
|
||||
new Lazy(() => EditableTagRendering.CreateRendering(tags, configuration, units, editMode)),
|
||||
undefined,
|
||||
renderingIsShown
|
||||
)
|
||||
}
|
||||
|
||||
private static CreateRendering(tags: UIEventSource<any>, configuration: TagRenderingConfig, units: Unit[], editMode: UIEventSource<boolean>) : BaseUIElement{
|
||||
const answer: BaseUIElement = new TagRenderingAnswer(tags, configuration)
|
||||
answer.SetClass("w-full")
|
||||
let rendering = answer;
|
||||
|
||||
if (configuration.question !== undefined && State.state?.featureSwitchUserbadge?.data) {
|
||||
// We have a question and editing is enabled
|
||||
const editButton =
|
||||
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")
|
||||
.onClick(() => {
|
||||
editMode.setData(true);
|
||||
});
|
||||
|
||||
|
||||
const answerWithEditButton = new Combine([answer,
|
||||
new Toggle(editButton,
|
||||
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")
|
||||
.onClick(() => {
|
||||
editMode.setData(true);
|
||||
}),
|
||||
undefined,
|
||||
State.state.osmConnection.isLoggedIn)
|
||||
]).SetClass("flex justify-between w-full")
|
||||
|
||||
|
||||
const cancelbutton =
|
||||
Translations.t.general.cancel.Clone()
|
||||
.SetClass("btn btn-secondary mr-3")
|
||||
.onClick(() => {
|
||||
editMode.setData(false)
|
||||
});
|
||||
const question = new Lazy(() => {
|
||||
return new TagRenderingQuestion(tags, configuration,
|
||||
{
|
||||
units: units,
|
||||
cancelButton: Translations.t.general.cancel.Clone()
|
||||
.SetClass("btn btn-secondary mr-3")
|
||||
.onClick(() => {
|
||||
editMode.setData(false)
|
||||
}),
|
||||
afterSave: () => {
|
||||
editMode.setData(false)
|
||||
}
|
||||
})
|
||||
|
||||
const question = new Lazy(() => new TagRenderingQuestion(tags, configuration,
|
||||
{
|
||||
units: units,
|
||||
cancelButton: cancelbutton,
|
||||
afterSave: () => {
|
||||
editMode.setData(false)
|
||||
}
|
||||
}))
|
||||
|
||||
})
|
||||
|
||||
|
||||
rendering = new Toggle(
|
||||
|
@ -62,17 +74,7 @@ export default class EditableTagRendering extends Toggle {
|
|||
)
|
||||
}
|
||||
rendering.SetClass("block w-full break-word text-default m-1 p-1 border-b border-gray-200 mb-2 pb-2")
|
||||
// The tagrendering is hidden if:
|
||||
// The answer is unknown. The questionbox will then show the question
|
||||
// There is a condition hiding the answer
|
||||
const renderingIsShown = tags.map(tags =>
|
||||
configuration.IsKnown(tags) &&
|
||||
(configuration?.condition?.matchesProperties(tags) ?? true))
|
||||
super(
|
||||
rendering,
|
||||
undefined,
|
||||
renderingIsShown
|
||||
)
|
||||
return rendering;
|
||||
}
|
||||
|
||||
}
|
|
@ -31,7 +31,7 @@ import {Unit} from "../../Models/Unit";
|
|||
* Shows the question element.
|
||||
* Note that the value _migh_ already be known, e.g. when selected or when changing the value
|
||||
*/
|
||||
export default class TagRenderingQuestion extends Combine {
|
||||
export default class TagRenderingQuestion extends VariableUiElement {
|
||||
|
||||
constructor(tags: UIEventSource<any>,
|
||||
configuration: TagRenderingConfig,
|
||||
|
@ -43,6 +43,46 @@ export default class TagRenderingQuestion extends Combine {
|
|||
bottomText?: (src: UIEventSource<TagsFilter>) => BaseUIElement
|
||||
}
|
||||
) {
|
||||
|
||||
|
||||
const applicableMappings =
|
||||
UIEventSource.ListStabilized(tags.map(tags => {
|
||||
const applicableMappings : {if: TagsFilter, then: any, ifnot?: TagsFilter}[] = []
|
||||
for (const mapping of configuration.mappings) {
|
||||
if (mapping.hideInAnswer === true) {
|
||||
continue
|
||||
}
|
||||
if (mapping.hideInAnswer === false || mapping.hideInAnswer === undefined) {
|
||||
applicableMappings.push(mapping)
|
||||
continue
|
||||
}
|
||||
const condition = <TagsFilter> mapping.hideInAnswer;
|
||||
const isShown = !condition.matchesProperties(tags)
|
||||
if(isShown){
|
||||
applicableMappings.push(mapping)
|
||||
}
|
||||
}
|
||||
return applicableMappings
|
||||
}));
|
||||
|
||||
super(
|
||||
applicableMappings.map(applicableMappings => {
|
||||
return TagRenderingQuestion.GenerateFullQuestion(tags, applicableMappings, configuration, options)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
private static GenerateFullQuestion(tags: UIEventSource<any>,
|
||||
applicableMappings: {if: TagsFilter, then: any, ifnot?: TagsFilter}[],
|
||||
configuration: TagRenderingConfig,
|
||||
options?: {
|
||||
units?: Unit[],
|
||||
afterSave?: () => void,
|
||||
cancelButton?: BaseUIElement,
|
||||
saveButtonConstr?: (src: UIEventSource<TagsFilter>) => BaseUIElement,
|
||||
bottomText?: (src: UIEventSource<TagsFilter>) => BaseUIElement
|
||||
}
|
||||
) {
|
||||
if (configuration === undefined) {
|
||||
throw "A question is needed for a question visualization"
|
||||
}
|
||||
|
@ -52,7 +92,7 @@ export default class TagRenderingQuestion extends Combine {
|
|||
.SetClass("question-text");
|
||||
|
||||
|
||||
const inputElement: InputElement<TagsFilter> = TagRenderingQuestion.GenerateInputElement(configuration, applicableUnit, tags)
|
||||
const inputElement: InputElement<TagsFilter> = TagRenderingQuestion.GenerateInputElement(configuration, applicableMappings, applicableUnit, tags)
|
||||
|
||||
if (inputElement === undefined) {
|
||||
console.error("MultiAnswer failed - probably not a single option was possible", configuration)
|
||||
|
@ -61,7 +101,7 @@ export default class TagRenderingQuestion extends Combine {
|
|||
const save = async () => {
|
||||
const selection = inputElement.GetValue().data;
|
||||
if (selection) {
|
||||
await (State.state?.changes ?? new Changes())
|
||||
await (State.state?.changes ?? new Changes())
|
||||
.applyAction(new ChangeTagAction(
|
||||
tags.data.id, selection, tags.data
|
||||
))
|
||||
|
@ -103,52 +143,77 @@ export default class TagRenderingQuestion extends Combine {
|
|||
)
|
||||
).SetClass("block break-all")
|
||||
}
|
||||
super([
|
||||
return new Combine([
|
||||
question,
|
||||
inputElement,
|
||||
options.cancelButton,
|
||||
saveButton,
|
||||
bottomTags]
|
||||
)
|
||||
this.SetClass("question")
|
||||
).SetClass("question")
|
||||
|
||||
}
|
||||
|
||||
private static GenerateInputElement(configuration: TagRenderingConfig, applicableUnit: Unit, tagsSource: UIEventSource<any>): InputElement<TagsFilter> {
|
||||
private static GenerateInputElement(configuration: TagRenderingConfig,
|
||||
applicableMappings: {if: TagsFilter, then: any, ifnot?: TagsFilter}[],
|
||||
applicableUnit: Unit, tagsSource: UIEventSource<any>): InputElement<TagsFilter> {
|
||||
let inputEls: InputElement<TagsFilter>[];
|
||||
|
||||
const mappings = (configuration.mappings ?? [])
|
||||
.filter(mapping => {
|
||||
if (mapping.hideInAnswer === true) {
|
||||
return false;
|
||||
}
|
||||
return !(typeof (mapping.hideInAnswer) !== "boolean" && mapping.hideInAnswer.matchesProperties(tagsSource.data));
|
||||
|
||||
})
|
||||
const ifNotsPresent = applicableMappings.some(mapping => mapping.ifnot !== undefined)
|
||||
|
||||
|
||||
function allIfNotsExcept(excludeIndex: number): TagsFilter[] {
|
||||
if (configuration.mappings === undefined) {
|
||||
return []
|
||||
function allIfNotsExcept(excludeIndex: number): UIEventSource<TagsFilter[]> {
|
||||
if (configuration.mappings === undefined || configuration.mappings.length === 0) {
|
||||
return undefined
|
||||
}
|
||||
if (!ifNotsPresent) {
|
||||
return undefined
|
||||
}
|
||||
if (configuration.multiAnswer) {
|
||||
// The multianswer will do the ifnot configuration themself
|
||||
return []
|
||||
return undefined
|
||||
}
|
||||
return Utils.NoNull(configuration.mappings?.map((m, i) => excludeIndex === i ? undefined : m.ifnot))
|
||||
return tagsSource.map(currentTags => {
|
||||
const negativeMappings = []
|
||||
|
||||
for (let i = 0; i < configuration.mappings.length; i++) {
|
||||
const mapping = configuration.mappings[i];
|
||||
if (i === excludeIndex || mapping.ifnot === undefined) {
|
||||
continue
|
||||
}
|
||||
|
||||
const hidden = mapping.hideInAnswer
|
||||
if (hidden === undefined) {
|
||||
negativeMappings.push(mapping.ifnot)
|
||||
continue
|
||||
}
|
||||
if (hidden === true) {
|
||||
continue
|
||||
}
|
||||
|
||||
if ((<TagsFilter>hidden).matchesProperties(currentTags)) {
|
||||
// This option is currently hidden
|
||||
continue
|
||||
}
|
||||
negativeMappings.push(mapping.ifnot)
|
||||
|
||||
}
|
||||
|
||||
return Utils.NoNull(negativeMappings)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
const ff = TagRenderingQuestion.GenerateFreeform(configuration, applicableUnit, tagsSource);
|
||||
const hasImages = mappings.filter(mapping => mapping.then.ExtractImages().length > 0).length > 0
|
||||
const hasImages = applicableMappings.filter(mapping => mapping.then.ExtractImages().length > 0).length > 0
|
||||
|
||||
if (mappings.length < 8 || configuration.multiAnswer || hasImages) {
|
||||
inputEls = (mappings ?? []).map((mapping, i) => TagRenderingQuestion.GenerateMappingElement(tagsSource, mapping, allIfNotsExcept(i)));
|
||||
if (applicableMappings.length < 8 || configuration.multiAnswer || hasImages || ifNotsPresent) {
|
||||
inputEls = (applicableMappings ?? []).map((mapping, i) => TagRenderingQuestion.GenerateMappingElement(tagsSource, mapping, allIfNotsExcept(i)));
|
||||
inputEls = Utils.NoNull(inputEls);
|
||||
} else {
|
||||
const dropdown: InputElement<TagsFilter> = new DropDown("",
|
||||
mappings.map((mapping, i) => {
|
||||
applicableMappings.map((mapping, i) => {
|
||||
return {
|
||||
value: new And([mapping.if, ...allIfNotsExcept(i)]),
|
||||
value: new And([mapping.if, ...allIfNotsExcept(i).data]),
|
||||
shown: Translations.WT(mapping.then).Clone()
|
||||
}
|
||||
})
|
||||
|
@ -178,6 +243,7 @@ export default class TagRenderingQuestion extends Combine {
|
|||
|
||||
}
|
||||
|
||||
|
||||
private static GenerateMultiAnswer(
|
||||
configuration: TagRenderingConfig,
|
||||
elements: InputElement<TagsFilter>[], freeformField: InputElement<TagsFilter>, ifNotSelected: TagsFilter[]): InputElement<TagsFilter> {
|
||||
|
@ -278,17 +344,23 @@ export default class TagRenderingQuestion extends Combine {
|
|||
return inputEl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates a (Fixed) input element for this mapping.
|
||||
* Note that the mapping might hide itself if the condition is not met anymore.
|
||||
*
|
||||
* 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(
|
||||
tagsSource: UIEventSource<any>,
|
||||
mapping: {
|
||||
if: TagsFilter,
|
||||
then: Translation,
|
||||
hideInAnswer: boolean | TagsFilter
|
||||
}, ifNot?: TagsFilter[]): InputElement<TagsFilter> {
|
||||
}, ifNot?: UIEventSource<TagsFilter[]>): InputElement<TagsFilter> {
|
||||
|
||||
let tagging = mapping.if;
|
||||
if (ifNot.length > 0) {
|
||||
tagging = new And([tagging, ...ifNot])
|
||||
let tagging: TagsFilter | UIEventSource<TagsFilter> = mapping.if;
|
||||
if (ifNot !== undefined) {
|
||||
tagging = ifNot.map(ifNots => new And([mapping.if, ...ifNots]))
|
||||
}
|
||||
|
||||
return new FixedInputElement(
|
||||
|
|
|
@ -16,4 +16,20 @@ AT this point, most of the work should be done; feel free to send a PR. If you w
|
|||
- Run 'ts-node csvToJson.ts' which will generate a new charging_station.json based on the protojson
|
||||
- Run`npm run query:licenses` to get an interactive program to add the license of your artwork, followed by `npm run generate:licenses`
|
||||
- Run `npm run generate:layeroverview` to generate the layer files
|
||||
- Run `npm run start` to run the instance
|
||||
- Run `npm run start` to run the instance
|
||||
|
||||
The CSV File
|
||||
------------
|
||||
|
||||
The columns in the CSV file are:
|
||||
|
||||
- key: the key as described on the wiki, starts with `socket:`
|
||||
- image: The associated image (a .svg)
|
||||
- description:en A description in english
|
||||
- description:nl A description in english
|
||||
- countryWhiteList: Only show this plug type in these countries
|
||||
- countryBlackList: Don't show this plug type in these countries. NOt compatibel with the whiteList
|
||||
- commonVoltages, commonCurrents, commonOutputs: common values for these tags
|
||||
- associatedVehicleTypes and neverAssociatedWith: these work in tandem to hide options.
|
||||
If every associated vehicle type is `no`, then the option is hidden
|
||||
If at least one `neverAssociatedVehicleType` is `yes` and none of the associated types is yes, then the option is hidden too
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -18,7 +18,8 @@ function loadCsv(file): {
|
|||
commonVoltages?: number[],
|
||||
commonCurrents?: number[],
|
||||
commonOutputs?: string[],
|
||||
associatedVehicleTypes?:string[]
|
||||
associatedVehicleTypes?: string[],
|
||||
neverAssociatedWith?: string[]
|
||||
}[] {
|
||||
const entries: string[] = Utils.NoNull(readFileSync(file, "utf8").split("\n").map(str => str.trim()))
|
||||
const header = entries.shift().split(",")
|
||||
|
@ -30,7 +31,7 @@ function loadCsv(file): {
|
|||
}
|
||||
|
||||
const v = {}
|
||||
const colonSeperated = ["commonVoltages", "commonOutputs", "commonCurrents", "countryWhiteList","countryBlackList","associatedVehicleTypes"]
|
||||
const colonSeperated = ["commonVoltages", "commonOutputs", "commonCurrents", "countryWhiteList", "countryBlackList", "associatedVehicleTypes", "neverAssociatedWith"]
|
||||
const descriptionTranslations = new Map<string, string>()
|
||||
for (let j = 0; j < header.length; j++) {
|
||||
const key = header[j];
|
||||
|
@ -54,7 +55,7 @@ function loadCsv(file): {
|
|||
function run(file, protojson) {
|
||||
|
||||
const overview_question_answers = []
|
||||
const questions: (TagRenderingConfigJson & {"id": string})[] = []
|
||||
const questions: (TagRenderingConfigJson & { "id": string })[] = []
|
||||
const filterOptions: { question: any, osmTags?: string } [] = [
|
||||
{
|
||||
question: {
|
||||
|
@ -65,7 +66,7 @@ function run(file, protojson) {
|
|||
]
|
||||
|
||||
const entries = loadCsv(file)
|
||||
for (let i = 0; i < entries.length; i++){
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
const e = entries[i];
|
||||
const txt = {
|
||||
en: `<div class='flex'><img class='w-12 mx-4' src='./assets/layers/charging_station/${e.image}'/> <span>${e.description.get("en")}</span></div>`,
|
||||
|
@ -77,28 +78,43 @@ function run(file, protojson) {
|
|||
then: txt,
|
||||
}
|
||||
|
||||
if(e.countryWhiteList.length > 0 && e.countryBlackList.length > 0){
|
||||
throw "Error for type "+e.key+": don't defined both a whitelist and a blacklist"
|
||||
if (e.countryWhiteList.length > 0 && e.countryBlackList.length > 0) {
|
||||
throw "Error for type " + e.key + ": don't defined both a whitelist and a blacklist"
|
||||
}
|
||||
if (e.countryWhiteList.length > 0) {
|
||||
// This is a 'hideInAnswer', thus _reverse_ logic!
|
||||
const countries = e.countryWhiteList.map(country => "_country!=" + country) //HideInAnswer if it is in the wrong country
|
||||
json["hideInAnswer"] = {or: countries}
|
||||
}else if (e.countryBlackList .length > 0) {
|
||||
} else if (e.countryBlackList.length > 0) {
|
||||
const countries = e.countryBlackList.map(country => "_country=" + country) //HideInAnswer if it is in the wrong country
|
||||
json["hideInAnswer"] = {or: countries}
|
||||
}
|
||||
|
||||
if(e.associatedVehicleTypes?.length > 0 && e.associatedVehicleTypes.indexOf("*") < 0){
|
||||
|
||||
if (e.associatedVehicleTypes?.length > 0 && e.associatedVehicleTypes.indexOf("*") < 0 && e.neverAssociatedWith?.length > 0) {
|
||||
// This plug only occurs if some vehicle specific vehicle type is present.
|
||||
// IF all of the needed vehicle types are explicitly NO, then we hide this type as well
|
||||
let hideInAnswer : any = {and: [].concat(...e.associatedVehicleTypes.map(neededVehicle => [neededVehicle+"~*", neededVehicle+"!=yes"]))}
|
||||
if(json["hideInAnswer"] !== undefined){
|
||||
hideInAnswer = {or: [json["hideInAnswer"], hideInAnswer]}
|
||||
let associatedWith = {and: [].concat(...e.associatedVehicleTypes.map(neededVehicle => [neededVehicle + "=no"]))}
|
||||
|
||||
// We also hide if:
|
||||
// - One of the neverAssociatedVehiclesTYpes is set to 'yes' AND none of the associated types are set/yes
|
||||
let neverAssociatedIsSet = {
|
||||
and: [{
|
||||
or: e.neverAssociatedWith.map(vehicleType => vehicleType + "=yes")
|
||||
},
|
||||
...e.associatedVehicleTypes.map(associated => associated + "!=yes")
|
||||
]
|
||||
}
|
||||
json["hideInAnswer"] = hideInAnswer
|
||||
|
||||
let conditions = [associatedWith, neverAssociatedIsSet]
|
||||
if (json["hideInAnswer"] !== undefined) {
|
||||
conditions.push(json["hideInAnswer"])
|
||||
}
|
||||
json["hideInAnswer"] = {or: conditions}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
overview_question_answers.push(json)
|
||||
|
||||
// We add a second time for any amount to trigger a visualisation; but this is not an answer option
|
||||
|
@ -115,7 +131,7 @@ function run(file, protojson) {
|
|||
const descrWithImage_nl = `<b>${e.description.get("nl")}</b> <img style='width:1rem;' src='./assets/layers/charging_station/${e.image}'/>`
|
||||
|
||||
questions.push({
|
||||
"id":"plugs-"+i,
|
||||
"id": "plugs-" + i,
|
||||
question: {
|
||||
en: `How much plugs of type ${descrWithImage_en} are available here?`,
|
||||
nl: `Hoeveel stekkers van type ${descrWithImage_nl} heeft dit oplaadpunt?`,
|
||||
|
@ -134,7 +150,7 @@ function run(file, protojson) {
|
|||
})
|
||||
|
||||
questions.push({
|
||||
"id":"voltage-"+i,
|
||||
"id": "voltage-" + i,
|
||||
question: {
|
||||
en: `What voltage do the plugs with ${descrWithImage_en} offer?`,
|
||||
nl: `Welke spanning levert de stekker van type ${descrWithImage_nl}`
|
||||
|
@ -163,7 +179,7 @@ function run(file, protojson) {
|
|||
|
||||
|
||||
questions.push({
|
||||
"id":"current-"+i,
|
||||
"id": "current-" + i,
|
||||
question: {
|
||||
en: `What current do the plugs with ${descrWithImage_en} offer?`,
|
||||
nl: `Welke stroom levert de stekker van type ${descrWithImage_nl}?`,
|
||||
|
@ -192,7 +208,7 @@ function run(file, protojson) {
|
|||
|
||||
|
||||
questions.push({
|
||||
"id":"power-output-"+i,
|
||||
"id": "power-output-" + i,
|
||||
question: {
|
||||
en: `What power output does a single plug of type ${descrWithImage_en} offer?`,
|
||||
nl: `Welk vermogen levert een enkele stekker van type ${descrWithImage_nl}?`,
|
||||
|
@ -229,7 +245,7 @@ function run(file, protojson) {
|
|||
}
|
||||
|
||||
const toggles = {
|
||||
"id":"Available_charging_stations (generated)",
|
||||
"id": "Available_charging_stations (generated)",
|
||||
"question": {
|
||||
"en": "Which charging stations are available here?"
|
||||
},
|
||||
|
@ -242,30 +258,29 @@ function run(file, protojson) {
|
|||
let protoString = readFileSync(protojson, "utf8")
|
||||
|
||||
protoString = protoString.replace("{\"id\": \"$$$\"}", stringified.join(",\n"))
|
||||
const proto = <LayerConfigJson> JSON.parse(protoString)
|
||||
const proto = <LayerConfigJson>JSON.parse(protoString)
|
||||
proto.tagRenderings.forEach(tr => {
|
||||
if(typeof tr === "string"){
|
||||
if (typeof tr === "string") {
|
||||
return;
|
||||
}
|
||||
if(tr["id"] === undefined || typeof tr["id"] !== "string"){
|
||||
if (tr["id"] === undefined || typeof tr["id"] !== "string") {
|
||||
console.error(tr)
|
||||
throw "Every tagrendering should have an id, acting as comment"
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
proto["filter"].push({
|
||||
id:"connection_type",
|
||||
id: "connection_type",
|
||||
options: filterOptions
|
||||
})
|
||||
|
||||
|
||||
|
||||
const extraUnits = [
|
||||
{
|
||||
appliesToKey: entries.map(e => e.key + ":voltage"),
|
||||
applicableUnits: [{
|
||||
canonicalDenomination: 'V',
|
||||
alternativeDenomination: ["v", "volt", "voltage",'V','Volt'],
|
||||
alternativeDenomination: ["v", "volt", "voltage", 'V', 'Volt'],
|
||||
human: {
|
||||
en: "Volts",
|
||||
nl: "volt"
|
||||
|
@ -277,7 +292,7 @@ function run(file, protojson) {
|
|||
appliesToKey: entries.map(e => e.key + ":current"),
|
||||
applicableUnits: [{
|
||||
canonicalDenomination: 'A',
|
||||
alternativeDenomination: ["a", "amp", "amperage",'A'],
|
||||
alternativeDenomination: ["a", "amp", "amperage", 'A'],
|
||||
human: {
|
||||
en: "A",
|
||||
nl: "A"
|
||||
|
@ -307,7 +322,7 @@ function run(file, protojson) {
|
|||
},
|
||||
];
|
||||
|
||||
if(proto["units"] == undefined){
|
||||
if (proto["units"] == undefined) {
|
||||
proto["units"] = []
|
||||
}
|
||||
proto["units"].push(...extraUnits)
|
||||
|
@ -348,22 +363,22 @@ async function queryTagInfo(file, type, clean: ((s: string) => string)) {
|
|||
* @param origPath
|
||||
* @param newConfig
|
||||
*/
|
||||
function mergeTranslations(origPath, newConfig: LayerConfigJson){
|
||||
const oldFile = <LayerConfigJson> JSON.parse(readFileSync(origPath, "utf-8"))
|
||||
const newFile =<LayerConfigJson> newConfig
|
||||
function mergeTranslations(origPath, newConfig: LayerConfigJson) {
|
||||
const oldFile = <LayerConfigJson>JSON.parse(readFileSync(origPath, "utf-8"))
|
||||
const newFile = <LayerConfigJson>newConfig
|
||||
const renderingsOld = oldFile.tagRenderings
|
||||
delete oldFile.tagRenderings
|
||||
const newRenderings = newFile.tagRenderings
|
||||
Utils.Merge(oldFile, newFile)
|
||||
|
||||
for (const oldRendering of renderingsOld) {
|
||||
|
||||
|
||||
const oldRenderingName = oldRendering["id"]
|
||||
if(oldRenderingName === undefined){
|
||||
if (oldRenderingName === undefined) {
|
||||
continue
|
||||
}
|
||||
const applicable = newRenderings.filter(r => r["id"] === oldRenderingName)[0]
|
||||
if(applicable === undefined){
|
||||
if (applicable === undefined) {
|
||||
continue;
|
||||
}
|
||||
Utils.Merge(oldRendering, applicable)
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
key,image,description:en,countryWhiteList,countryBlackList,commonVoltages,commonCurrents,commonOutputs,description:nl,associatedVehicleTypes
|
||||
socket:schuko,CEE7_4F.svg,<b>Schuko wall plug</b> without ground pin (CEE7/4 type F),be;fr;ma;tn;pl;cs;sk;mo,,230,16,3.6 kW,<b>Schuko stekker</b> zonder aardingspin (CEE7/4 type F),*
|
||||
socket:typee,TypeE.svg,<b>European wall plug</b> with ground pin (CEE7/4 type E),,,230,16,3 kW;22 kW;,<b>Europese stekker</b> met aardingspin (CEE7/4 type E),*
|
||||
socket:chademo,Chademo_type4.svg,<b>Chademo</b>,,,500,120,50 kW,<b>Chademo</b>,car;motorcar;hgv;bus
|
||||
socket:type1_cable,Type1_J1772.svg,<b>Type 1 with cable</b> (J1772),,,200;240,32,3.7 kW;7 kW,<b>Type 1 met kabel</b> (J1772),car;motorcar;hgv;bus
|
||||
socket:type1,Type1_J1772.svg,<b>Type 1 <i>without</i> cable</b> (J1772),,,200;240,32,3.7 kW;6.6 kW;7 kW;7.2 kW,<b>Type 1 <i>zonder</i> kabel</b> (J1772),car;motorcar;hgv;bus
|
||||
socket:type1_combo,Type1-ccs.svg,<b>Type 1 CCS</b> (aka Type 1 Combo),,,400;1000,50;125,50 kW;62.5 kW;150 kW;350 kW;,<b>Type 1 CCS</b> (ook gekend als Type 1 Combo),car;motorcar;hgv;bus
|
||||
socket:tesla_supercharger,Tesla-hpwc-model-s.svg,<b>Tesla Supercharger</b>,,,480,125;350,120 kW;150 kW;250 kW,<b>Tesla Supercharger</b>,car;motorcar;hgv;bus
|
||||
socket:type2,Type2_socket.svg,<b>Type 2</b> (mennekes),,,230;400,16;32,11 kW;22 kW,<b>Type 2</b> (mennekes),car;motorcar;hgv;bus
|
||||
socket:type2_combo,Type2_CCS.svg,<b>Type 2 CCS</b> (mennekes),,,500;920,125;350,50 kW,<b>Type 2 CCS</b> (mennekes),car;motorcar;hgv;bus
|
||||
socket:type2_cable,Type2_tethered.svg,<b>Type 2 with cable</b> (mennekes),,,230;400,16;32,11 kW;22 kW,<b>Type 2 met kabel</b> (J1772),car;motorcar;hgv;bus
|
||||
socket:tesla_supercharger_ccs,Type2_CCS.svg,<b>Tesla Supercharger CCS</b> (a branded type2_css),,,500;920,125;350,50 kW,<b>Tesla Supercharger CCS</b> (een type2 CCS met Tesla-logo),car;motorcar;hgv;bus
|
||||
socket:tesla_destination,Tesla-hpwc-model-s.svg,<b>Tesla Supercharger (destination)</b>,us,,480,125;350,120 kW;150 kW;250 kW,<b>Tesla Supercharger (destination)</b>,car;motorcar;hgv;bus
|
||||
socket:tesla_destination,Type2_tethered.svg,<b>Tesla supercharger (destination</b> (A Type 2 with cable branded as tesla),,us,230;400,16;32,11 kW;22 kW,<b>Tesla supercharger (destination</b> (Een Type 2 met kabel en Tesla-logo),car;motorcar;hgv;bus
|
||||
socket:USB-A,usb_port.svg,<b>USB</b> to charge phones and small electronics,,,5,1;2,5W;10W,<b>USB</b> om GSMs en kleine electronica op te laden,*
|
||||
key,image,description:en,countryWhiteList,countryBlackList,commonVoltages,commonCurrents,commonOutputs,description:nl,associatedVehicleTypes,neverAssociatedWith
|
||||
socket:schuko,CEE7_4F.svg,<b>Schuko wall plug</b> without ground pin (CEE7/4 type F),be;fr;ma;tn;pl;cs;sk;mo,,230,16,3.6 kW,<b>Schuko stekker</b> zonder aardingspin (CEE7/4 type F),*,
|
||||
socket:typee,TypeE.svg,<b>European wall plug</b> with ground pin (CEE7/4 type E),,,230,16,3 kW;22 kW;,<b>Europese stekker</b> met aardingspin (CEE7/4 type E),*,
|
||||
socket:chademo,Chademo_type4.svg,<b>Chademo</b>,,,500,120,50 kW,<b>Chademo</b>,car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:type1_cable,Type1_J1772.svg,<b>Type 1 with cable</b> (J1772),,,200;240,32,3.7 kW;7 kW,<b>Type 1 met kabel</b> (J1772),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:type1,Type1_J1772.svg,<b>Type 1 <i>without</i> cable</b> (J1772),,,200;240,32,3.7 kW;6.6 kW;7 kW;7.2 kW,<b>Type 1 <i>zonder</i> kabel</b> (J1772),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:type1_combo,Type1-ccs.svg,<b>Type 1 CCS</b> (aka Type 1 Combo),,,400;1000,50;125,50 kW;62.5 kW;150 kW;350 kW;,<b>Type 1 CCS</b> (ook gekend als Type 1 Combo),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:tesla_supercharger,Tesla-hpwc-model-s.svg,<b>Tesla Supercharger</b>,,,480,125;350,120 kW;150 kW;250 kW,<b>Tesla Supercharger</b>,car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:type2,Type2_socket.svg,<b>Type 2</b> (mennekes),,,230;400,16;32,11 kW;22 kW,<b>Type 2</b> (mennekes),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:type2_combo,Type2_CCS.svg,<b>Type 2 CCS</b> (mennekes),,,500;920,125;350,50 kW,<b>Type 2 CCS</b> (mennekes),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:type2_cable,Type2_tethered.svg,<b>Type 2 with cable</b> (mennekes),,,230;400,16;32,11 kW;22 kW,<b>Type 2 met kabel</b> (J1772),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:tesla_supercharger_ccs,Type2_CCS.svg,<b>Tesla Supercharger CCS</b> (a branded type2_css),,,500;920,125;350,50 kW,<b>Tesla Supercharger CCS</b> (een type2 CCS met Tesla-logo),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:tesla_destination,Tesla-hpwc-model-s.svg,<b>Tesla Supercharger (destination)</b>,us,,480,125;350,120 kW;150 kW;250 kW,<b>Tesla Supercharger (destination)</b>,car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:tesla_destination,Type2_tethered.svg,<b>Tesla supercharger (destination</b> (A Type 2 with cable branded as tesla),,us,230;400,16;32,11 kW;22 kW,<b>Tesla supercharger (destination</b> (Een Type 2 met kabel en Tesla-logo),car;motorcar;hgv;bus,bicycle;scooter
|
||||
socket:USB-A,usb_port.svg,<b>USB</b> to charge phones and small electronics,,,5,1;2,5W;10W,<b>USB</b> om GSMs en kleine electronica op te laden,*,
|
||||
|
|
|
31
test.ts
31
test.ts
|
@ -1,2 +1,31 @@
|
|||
import {AllKnownLayouts} from "./Customizations/AllKnownLayouts";
|
||||
import {Translation} from "./UI/i18n/Translation";
|
||||
import TagRenderingQuestion from "./UI/Popup/TagRenderingQuestion";
|
||||
import {UIEventSource} from "./Logic/UIEventSource";
|
||||
import {VariableUiElement} from "./UI/Base/VariableUIElement";
|
||||
|
||||
const theme = AllKnownLayouts.allKnownLayouts.get("charging_stations")
|
||||
|
||||
const tagRendering = theme.layers[0].tagRenderings.filter(tr => tr.id === "Available_charging_stations (generated)")[0]
|
||||
const tag = new UIEventSource({
|
||||
id: "node/42",
|
||||
amenity:"charging_station",
|
||||
bicycle:"yes",
|
||||
car:"no",
|
||||
"motorcar":"no",
|
||||
"hgv":"no",
|
||||
bus:"no"
|
||||
})
|
||||
window.tags = tag
|
||||
|
||||
//const q =
|
||||
new VariableUiElement(tag.map(_ => new TagRenderingQuestion(tag, tagRendering) ))
|
||||
.SetStyle("width: 100px")
|
||||
.AttachTo("maindiv")
|
||||
|
||||
|
||||
window.setTimeout(_ => {
|
||||
tag.data.bicycle="no"
|
||||
tag.data.car = "yes"
|
||||
tag.ping()
|
||||
console.log("Pinged")
|
||||
}, 2500)
|
Loading…
Reference in a new issue