New question system

This commit is contained in:
Pieter Vander Vennet 2020-07-05 18:59:47 +02:00
parent 1738fc4252
commit d1f8080c24
45 changed files with 1391 additions and 689 deletions

View file

@ -0,0 +1,39 @@
import {TagRendering, TagRenderingOptions} from "../TagRendering";
import {UIEventSource} from "../../UI/UIEventSource";
import {Changes} from "../../Logic/Changes";
import {And, Tag} from "../../Logic/TagsFilter";
export class AccessTag extends TagRenderingOptions {
private static options = {
priority: 10,
question: "Is dit gebied toegankelijk?",
primer: "Dit gebied is ",
freeform: {
key: "access",
extraTags: new Tag("fixme", "Freeform access tag used: possibly a wrong value"),
template: "Iets anders: $$$",
renderTemplate: "De toegangekelijkheid van dit gebied is: {access}",
placeholder: "Specifieer"
},
mappings: [
{k: new And([new Tag("access", "yes"), new Tag("fee", "")]), txt: "publiek toegankelijk"},
{k: new And([new Tag("access", "no"), new Tag("fee", "")]), txt: "niet toegankelijk"},
{k: new And([new Tag("access", "private"), new Tag("fee", "")]), txt: "niet toegankelijk, want privegebied"},
{k: new And([new Tag("access", "permissive"), new Tag("fee", "")]), txt: "toegankelijk, maar het is privegebied"},
{k: new And([new Tag("access", "guided"), new Tag("fee", "")]), txt: "enkel met gids of op activiteit"},
{
k: new And([new Tag("access", "yes"),
new Tag("fee", "yes")]),
txt: "toegankelijk mits betaling",
priority: 10
},
]
}
constructor() {
super(AccessTag.options);
}
}

View file

@ -0,0 +1,29 @@
import {TagRenderingOptions} from "../TagRendering";
import {And, Tag} from "../../Logic/TagsFilter";
export class NameInline extends TagRenderingOptions{
static Upper(string){
return string.charAt(0).toUpperCase() + string.slice(1);
}
constructor(category: string) {
super({
question: "",
freeform: {
renderTemplate: "{name}",
template: "De naam van dit "+category+" is $$$",
key: "name",
extraTags: new Tag("noname", "") // Remove 'noname=yes'
},
mappings: [
{k: new Tag("noname","yes"), txt: NameInline.Upper(category)+" zonder naam"},
{k: null, txt: NameInline.Upper(category)}
]
});
}
}

View file

@ -0,0 +1,30 @@
/**
* There are two ways to ask for names:
* One is a big 'name-question', the other is the 'edit name' in the title.
* THis one is the big question
*/
import {TagRenderingOptions} from "../TagRendering";
import {Tag} from "../../Logic/TagsFilter";
export class NameQuestion extends TagRenderingOptions{
static options = {
priority: 20,
question: "Wat is de <i>officiële</i> naam van dit gebied?",
freeform: {
key: "name",
template: "De naam is $$$",
renderTemplate: "", // We don't actually render it, only ask
placeholder: "",
extraTags: new Tag("noname","")
},
mappings: [
{k: new Tag("noname", "yes"), txt: "Dit gebied heeft geen naam"},
]
}
constructor() {
super(NameQuestion.options);
}
}

View file

@ -0,0 +1,30 @@
import {TagRenderingOptions} from "../TagRendering";
import {UIEventSource} from "../../UI/UIEventSource";
import {Changes} from "../../Logic/Changes";
import {Tag} from "../../Logic/TagsFilter";
export class OperatorTag extends TagRenderingOptions {
private static options = {
priority: 5,
question: "Wie beheert dit gebied?",
freeform: {
key: "operator",
template: "Dit gebied wordt beheerd door $$$",
renderTemplate: "Dit gebied wordt beheerd door {operator}",
placeholder: "organisatie"
},
mappings: [
{k: new Tag("operator", "Natuurpunt"), txt: "Natuurpunt"},
{k: new Tag("operator", "Agentschap Natuur en Bos"), txt: "het Agentschap Natuur en Bos (ANB)"},
{k: new Tag("operator", "private"), txt: "Beheer door een privépersoon"}
]
}
constructor() {
super(OperatorTag.options);
}
}

View file

@ -0,0 +1,31 @@
import {TagRenderingOptions} from "../TagRendering";
import {Img} from "../../UI/Img";
import {Tag} from "../../Logic/TagsFilter";
export class OsmLink extends TagRenderingOptions {
static options = {
freeform: {
key: "id",
template: "$$$",
renderTemplate:
"<span class='osmlink'><a href='https://osm.org/{id}' target='_blank'>" +
Img.osmAbstractLogo +
"</a></span>",
placeholder: "",
},
mappings: [
{k: new Tag("id", "node/-1"), txt: "<span class='alert'>Uploading</span>"}
]
}
constructor() {
super(OsmLink.options);
}
}

View file

@ -0,0 +1,53 @@
import {TagRenderingOptions} from "../TagRendering";
export class WikipediaLink extends TagRenderingOptions {
private static FixLink(value: string): string {
// @ts-ignore
if (value.startsWith("https")) {
return value;
} else {
const splitted = value.split(":");
const language = splitted[0];
splitted.shift();
const page = splitted.join(":");
return 'https://' + language + '.wikipedia.org/wiki/' + page;
}
}
static options = {
priority: 10,
// question: "Wat is het overeenstemmende wkipedia-artikel?",
freeform: {
key: "wikipedia",
template: "$$$",
renderTemplate:
"<span class='wikipedialink'>" +
"<a href='{wikipedia}' target='_blank'>" +
"<img width='64px' src='./assets/wikipedia.svg' alt='wikipedia'>" +
"</a></span>",
placeholder: "",
tagsPreprocessor: (tags) => {
const newTags = {};
for (const k in tags) {
if (k === "wikipedia") {
newTags["wikipedia"] = WikipediaLink.FixLink(tags[k]);
} else {
newTags[k] = tags[k];
}
}
return newTags;
}
},
}
constructor() {
super(WikipediaLink.options);
}
}