forked from MapComplete/MapComplete
Chore: remove all unused imports, port 'allTags' to proper svelte
This commit is contained in:
parent
f7b555b9b6
commit
d09f89dc2a
38 changed files with 216 additions and 227 deletions
|
@ -1,17 +1,14 @@
|
|||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { Utils } from "../../../src/Utils";
|
||||
import ScriptUtils from "../../../scripts/ScriptUtils";
|
||||
import { LayerConfigJson } from "../../../src/Models/ThemeConfig/Json/LayerConfigJson";
|
||||
import FilterConfigJson from "../../../src/Models/ThemeConfig/Json/FilterConfigJson";
|
||||
import {
|
||||
QuestionableTagRenderingConfigJson
|
||||
} from "../../../src/Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson";
|
||||
import RewritableConfigJson from "../../../src/Models/ThemeConfig/Json/RewritableConfigJson";
|
||||
import { TagRenderingConfigJson } from "../../../src/Models/ThemeConfig/Json/TagRenderingConfigJson";
|
||||
import { readFileSync, writeFileSync } from "fs"
|
||||
import { Utils } from "../../../src/Utils"
|
||||
import ScriptUtils from "../../../scripts/ScriptUtils"
|
||||
import { LayerConfigJson } from "../../../src/Models/ThemeConfig/Json/LayerConfigJson"
|
||||
import FilterConfigJson from "../../../src/Models/ThemeConfig/Json/FilterConfigJson"
|
||||
import RewritableConfigJson from "../../../src/Models/ThemeConfig/Json/RewritableConfigJson"
|
||||
import { TagRenderingConfigJson } from "../../../src/Models/ThemeConfig/Json/TagRenderingConfigJson"
|
||||
|
||||
|
||||
function colonSplit(value: string): string[] {
|
||||
return value.split(";").map(v => v.replace(/"/g, '').trim()).filter(s => s !== "");
|
||||
return value.split(";").map(v => v.replace(/"/g, "").trim()).filter(s => s !== "")
|
||||
}
|
||||
|
||||
function loadCsv(file): {
|
||||
|
@ -34,14 +31,14 @@ function loadCsv(file): {
|
|||
return Utils.NoNull(entries.map(entry => {
|
||||
const values = entry.split(",").map(str => str.trim())
|
||||
if (values[0] === undefined || values[0] === "") {
|
||||
return undefined;
|
||||
return undefined
|
||||
}
|
||||
|
||||
const v = {}
|
||||
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];
|
||||
const key = header[j]
|
||||
if (key.startsWith("description")) {
|
||||
const language = key.substring("description:".length)
|
||||
descriptionTranslations.set(language, values[j])
|
||||
|
@ -54,10 +51,10 @@ function loadCsv(file): {
|
|||
}
|
||||
}
|
||||
v["description"] = descriptionTranslations
|
||||
if(v["id"] === ""){
|
||||
v["id"] = v["key"]
|
||||
if (v["id"] === "") {
|
||||
v["id"] = v["key"]
|
||||
}
|
||||
return <any>v;
|
||||
return <any>v
|
||||
}))
|
||||
}
|
||||
|
||||
|
@ -70,9 +67,9 @@ function run(file, protojson) {
|
|||
{
|
||||
question: {
|
||||
en: "All connectors",
|
||||
nl: "Alle types"
|
||||
}
|
||||
}
|
||||
nl: "Alle types",
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
const entries = loadCsv(file)
|
||||
|
@ -82,7 +79,7 @@ function run(file, protojson) {
|
|||
|
||||
{
|
||||
// Add the entities to the 'rewrite-able part'
|
||||
let specificQuestions: RewritableConfigJson<TagRenderingConfigJson> = <any>proto.tagRenderings.find(tr => tr["rewrite"] !== undefined && !(tr["rewrite"]["into"]?.length > 0));
|
||||
let specificQuestions: RewritableConfigJson<TagRenderingConfigJson> = <any>proto.tagRenderings.find(tr => tr["rewrite"] !== undefined && !(tr["rewrite"]["into"]?.length > 0))
|
||||
specificQuestions.rewrite.into = entries.map(e => [
|
||||
e.id,
|
||||
e.key,
|
||||
|
@ -90,24 +87,24 @@ function run(file, protojson) {
|
|||
e.image,
|
||||
e.commonVoltages,
|
||||
e.commonCurrents,
|
||||
e.commonOutputs
|
||||
]);
|
||||
e.commonOutputs,
|
||||
])
|
||||
}
|
||||
|
||||
for (let i = 0; i < entries.length; i++) {
|
||||
const e = entries[i];
|
||||
const e = entries[i]
|
||||
const txt = {
|
||||
en: e.description.get("en"),
|
||||
nl: e.description.get("nl")
|
||||
nl: e.description.get("nl"),
|
||||
}
|
||||
const json = {
|
||||
if: `${e.key}=1`,
|
||||
ifnot: `${e.key}=`,
|
||||
then: txt,
|
||||
icon:{
|
||||
path:"./assets/layers/charging_station/" + e.image,
|
||||
class:"medium"
|
||||
}
|
||||
icon: {
|
||||
path: "./assets/layers/charging_station/" + e.image,
|
||||
class: "medium",
|
||||
},
|
||||
}
|
||||
|
||||
if (e.countryWhiteList.length > 0 && e.countryBlackList.length > 0) {
|
||||
|
@ -116,32 +113,32 @@ function run(file, protojson) {
|
|||
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"] = {and: countries} // Should be and, as we want to hide if it does not match any of the countries
|
||||
json["hideInAnswer"] = { and: countries } // Should be and, as we want to hide if it does not match any of the countries
|
||||
} 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}
|
||||
json["hideInAnswer"] = { or: countries }
|
||||
}
|
||||
|
||||
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 associatedWith = {and: [].concat(...e.associatedVehicleTypes.map(neededVehicle => [neededVehicle + "=no"]))}
|
||||
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")
|
||||
or: e.neverAssociatedWith.map(vehicleType => vehicleType + "=yes"),
|
||||
},
|
||||
...e.associatedVehicleTypes.map(associated => associated + "!=yes")
|
||||
]
|
||||
...e.associatedVehicleTypes.map(associated => associated + "!=yes"),
|
||||
],
|
||||
}
|
||||
|
||||
let conditions = [associatedWith, neverAssociatedIsSet]
|
||||
if (json["hideInAnswer"] !== undefined) {
|
||||
conditions.push(json["hideInAnswer"])
|
||||
}
|
||||
json["hideInAnswer"] = {or: conditions}
|
||||
json["hideInAnswer"] = { or: conditions }
|
||||
|
||||
}
|
||||
|
||||
|
@ -151,14 +148,14 @@ function run(file, protojson) {
|
|||
// We add a second time for any amount to trigger a visualisation; but this is not an answer option
|
||||
const no_ask_json = {
|
||||
if: {
|
||||
and:Utils.NoEmpty( [`${e.key}~*`, `${e.key}!=1`, ...e.extraVisualisationCondition.split(";")])
|
||||
and: Utils.NoEmpty([`${e.key}~*`, `${e.key}!=1`, ...e.extraVisualisationCondition.split(";")]),
|
||||
},
|
||||
then: txt,
|
||||
hideInAnswer: true,
|
||||
icon:{
|
||||
icon: {
|
||||
path: `./assets/layers/charging_station/${e.image}`,
|
||||
class:"medium"
|
||||
}
|
||||
class: "medium",
|
||||
},
|
||||
}
|
||||
overview_question_answers.push(no_ask_json)
|
||||
|
||||
|
@ -168,9 +165,9 @@ function run(file, protojson) {
|
|||
filterOptions.push({
|
||||
question: {
|
||||
en: `Has a ${descrWithImage_en} connector`,
|
||||
nl: `Heeft een ${descrWithImage_nl}`
|
||||
nl: `Heeft een ${descrWithImage_nl}`,
|
||||
},
|
||||
osmTags: `${e.key}~*`
|
||||
osmTags: `${e.key}~*`,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -178,25 +175,25 @@ function run(file, protojson) {
|
|||
"id": "Available_charging_stations (generated)",
|
||||
"question": {
|
||||
"en": "Which charging connections are available here?",
|
||||
"nl": "Welke aansluitingen zijn hier beschikbaar?"
|
||||
"nl": "Welke aansluitingen zijn hier beschikbaar?",
|
||||
},
|
||||
"multiAnswer": true,
|
||||
"mappings": overview_question_answers
|
||||
"mappings": overview_question_answers,
|
||||
}
|
||||
|
||||
|
||||
const insertQuestionsAt = proto.tagRenderings.findIndex(tr => tr["id"] === "$$$")
|
||||
proto.tagRenderings.splice(insertQuestionsAt, 1, toggles)
|
||||
|
||||
if(typeof proto.filter === "string"){
|
||||
if (typeof proto.filter === "string") {
|
||||
throw "Filters of a the protojson should be a list of FilterConfigJsons"
|
||||
}
|
||||
proto.filter = <FilterConfigJson[]> proto.filter;
|
||||
proto.filter = <FilterConfigJson[]>proto.filter
|
||||
proto.tagRenderings.forEach(tr => {
|
||||
if (typeof tr === "string") {
|
||||
return;
|
||||
return
|
||||
}
|
||||
if(tr["rewrite"]){
|
||||
if (tr["rewrite"]) {
|
||||
return
|
||||
}
|
||||
if (tr["id"] === undefined || typeof tr["id"] !== "string") {
|
||||
|
@ -207,18 +204,18 @@ function run(file, protojson) {
|
|||
|
||||
proto.filter.push({
|
||||
id: "connection_type",
|
||||
options: filterOptions
|
||||
options: filterOptions,
|
||||
})
|
||||
|
||||
const importedUnits = {}
|
||||
for (const entry of entries) {
|
||||
importedUnits[entry.key+":voltage"] = "voltage"
|
||||
importedUnits[entry.key+":current"] = "current"
|
||||
importedUnits[entry.key+":output"] = { quantity: "power", "denominations":["mW","kW"] }
|
||||
importedUnits[entry.key + ":voltage"] = "voltage"
|
||||
importedUnits[entry.key + ":current"] = "current"
|
||||
importedUnits[entry.key + ":output"] = { quantity: "power", "denominations": ["mW", "kW"] }
|
||||
}
|
||||
|
||||
const extraUnits = [importedUnits
|
||||
];
|
||||
const extraUnits = [importedUnits,
|
||||
]
|
||||
|
||||
if (proto["units"] == undefined) {
|
||||
proto["units"] = []
|
||||
|
@ -234,10 +231,10 @@ async function queryTagInfo(file, type, clean: ((s: string) => string)) {
|
|||
const result = value.data
|
||||
const counts = new Map<string, number>()
|
||||
for (const r of result) {
|
||||
let key = r.value;
|
||||
let key = r.value
|
||||
key = clean(key)
|
||||
key.trim();
|
||||
if (key.indexOf('-') >= 0) {
|
||||
key.trim()
|
||||
if (key.indexOf("-") >= 0) {
|
||||
continue
|
||||
}
|
||||
if (r.fraction < 0.05) {
|
||||
|
@ -276,7 +273,7 @@ function mergeTranslations(origPath, newConfig: LayerConfigJson) {
|
|||
}
|
||||
const applicable = newRenderings.filter(r => r["id"] === oldRenderingName)[0]
|
||||
if (applicable === undefined) {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
// @ts-ignore
|
||||
Utils.Merge(oldRendering, applicable)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue