forked from MapComplete/MapComplete
chore: automated housekeeping...
This commit is contained in:
parent
94c61744c0
commit
04c8ccb0d2
89 changed files with 2353 additions and 1390 deletions
|
@ -170,7 +170,10 @@ class DetectInline extends DesugaringStep<QuestionableTagRenderingConfigJson> {
|
|||
|
||||
export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
||||
constructor() {
|
||||
super("AddQuestionBox", "Adds a 'questions'-object if no question element is added yet. Will ignore all elements which were previously asked for (and questions labeled with 'hidden')")
|
||||
super(
|
||||
"AddQuestionBox",
|
||||
"Adds a 'questions'-object if no question element is added yet. Will ignore all elements which were previously asked for (and questions labeled with 'hidden')"
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,14 +213,12 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
|||
(sp) => sp.args.length === 0 || sp.args[0].trim() === ""
|
||||
)
|
||||
|
||||
|
||||
if (noLabels.length > 1) {
|
||||
context.err(
|
||||
"Multiple 'questions'-visualisations found which would show _all_ questions. Don't do this - questions will be shown twice. Did you perhaps import all questions from another layer?",
|
||||
"Multiple 'questions'-visualisations found which would show _all_ questions. Don't do this - questions will be shown twice. Did you perhaps import all questions from another layer?"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* We want to construct a questionbox that shows all leftover questions.
|
||||
* For this, we need to determine what those leftover questions _are_ in the first place.
|
||||
|
@ -227,14 +228,14 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
|||
|
||||
// ALl labels that are used in this layer
|
||||
const allLabels = new Set(
|
||||
json.tagRenderings.flatMap(
|
||||
(tr) => (<QuestionableTagRenderingConfigJson>tr).labels ?? []
|
||||
)
|
||||
json.tagRenderings.flatMap(
|
||||
(tr) => (<QuestionableTagRenderingConfigJson>tr).labels ?? []
|
||||
)
|
||||
)
|
||||
/**
|
||||
* The essence of all questionboxes: what is whitelisted, what is blacklisted?
|
||||
*/
|
||||
const questionBoxes: { blacklist: string[], whitelist: string[] }[] = []
|
||||
const questionBoxes: { blacklist: string[]; whitelist: string[] }[] = []
|
||||
for (const questionSpecial of questionSpecials) {
|
||||
if (typeof questionSpecial === "string") {
|
||||
// Probably a header or something
|
||||
|
@ -273,7 +274,7 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
|||
for (const { blacklist, whitelist } of questionBoxes) {
|
||||
if (whitelist.length > 0 && blacklist.length == 0) {
|
||||
// All questions from "whitelist" are guaranteed to be used here
|
||||
whitelist.forEach(label => usedLabels.add(label))
|
||||
whitelist.forEach((label) => usedLabels.add(label))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -281,12 +282,14 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
|||
* Can we say that the whitelisted items are fully consumed?
|
||||
*/
|
||||
let needsEvaluation = true
|
||||
let toEvaluate = questionBoxes.filter(q => q.whitelist.length > 0 && q.blacklist.length > 0)
|
||||
let toEvaluate = questionBoxes.filter(
|
||||
(q) => q.whitelist.length > 0 && q.blacklist.length > 0
|
||||
)
|
||||
while (needsEvaluation && toEvaluate.length > 0) {
|
||||
needsEvaluation = false
|
||||
const toReEvaluate = []
|
||||
for (const { blacklist, whitelist } of toEvaluate) {
|
||||
const blacklistRest = blacklist.filter(label => !usedLabels.has(label))
|
||||
const blacklistRest = blacklist.filter((label) => !usedLabels.has(label))
|
||||
if (blacklistRest.length == 0) {
|
||||
// All items from the blacklist have been handled by a different questionbox
|
||||
// We can safely say that all whitelisted items are consumed
|
||||
|
@ -294,7 +297,7 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
|||
// Even better: this questionbox will show all leftover questions
|
||||
return json
|
||||
}
|
||||
whitelist.forEach(label => {
|
||||
whitelist.forEach((label) => {
|
||||
usedLabels.add(label)
|
||||
})
|
||||
needsEvaluation = true
|
||||
|
@ -312,11 +315,12 @@ export class AddQuestionBox extends DesugaringStep<LayerConfigJson> {
|
|||
|
||||
context.err(
|
||||
"Could not calculate a non-ambiguous leftover questions block. A {questions()}-special rendering is found which has both a whitelist and a blacklist; where the blacklist was not fully consumed by other tagRenderings\n\t" +
|
||||
JSON.stringify(toEvaluate)+"\n\tConsumed labels are: "+Array.from(usedLabels).join(", "),
|
||||
JSON.stringify(toEvaluate) +
|
||||
"\n\tConsumed labels are: " +
|
||||
Array.from(usedLabels).join(", ")
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
/* At this point, we know which question labels are not yet handled and which already are handled, and we
|
||||
* know there is no previous catch-all questions
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue