forked from MapComplete/MapComplete
Add loading of live data
This commit is contained in:
parent
feab5a19b3
commit
0d6412f824
14 changed files with 291 additions and 35 deletions
|
@ -1,6 +1,8 @@
|
|||
import {UIElement} from "./UIElement";
|
||||
import OpeningHoursVisualization from "./OhVisualization";
|
||||
import {UIEventSource} from "../Logic/UIEventSource";
|
||||
import {VariableUiElement} from "./Base/VariableUIElement";
|
||||
import LiveQueryHandler from "../Logic/Web/LiveQueryHandler";
|
||||
|
||||
export default class SpecialVisualizations {
|
||||
|
||||
|
@ -8,13 +10,13 @@ export default class SpecialVisualizations {
|
|||
funcName: string,
|
||||
constr: ((tagSource: UIEventSource<any>, argument: string[]) => UIElement),
|
||||
docs: string,
|
||||
args: {name: string, defaultValue: string, doc: string}[]
|
||||
args: { name: string, defaultValue?: string, doc: string }[]
|
||||
}[] =
|
||||
|
||||
[{
|
||||
funcName: "opening_hours_table",
|
||||
docs: "Creates an opening-hours table. Usage: {opening_hours_table(opening_hours)} to create a table of the tag 'opening_hours'.",
|
||||
args:[{name:"key", defaultValue: "opening_hours", doc: "The tag from which the table is constructed"}],
|
||||
args: [{name: "key", defaultValue: "opening_hours", doc: "The tag from which the table is constructed"}],
|
||||
constr: (tagSource: UIEventSource<any>, args) => {
|
||||
let keyname = args[0];
|
||||
if (keyname === undefined || keyname === "") {
|
||||
|
@ -24,6 +26,26 @@ export default class SpecialVisualizations {
|
|||
}
|
||||
},
|
||||
|
||||
{
|
||||
funcName: "live",
|
||||
docs: "Downloads a JSON from the given URL, e.g. '{live(example.org/data.json, shorthand:x.y.z, other:a.b.c, shorthand)}' will download the given file, will create an object {shorthand: json[x][y][z], other: json[a][b][c] out of it and will return 'other' or 'json[a][b][c]. This is made to use in combination with tags, e.g. {live({url}, {url:format}, needed_value)}",
|
||||
args: [{
|
||||
name: "Url", doc: "The URL to load"
|
||||
}, {
|
||||
name: "Shorthands",
|
||||
doc: "A list of shorthands, of the format 'shorthandname:path.path.path'. Seperated by ;"
|
||||
}, {
|
||||
name: "path", doc: "The path (or shorthand) that should be returned"
|
||||
}],
|
||||
constr: (tagSource: UIEventSource<any>, args) => {
|
||||
const url = args[0];
|
||||
const shorthands = args[1];
|
||||
const neededValue = args[2];
|
||||
const source = LiveQueryHandler.FetchLiveData(url, shorthands.split(";"));
|
||||
return new VariableUiElement(source.map(data => data[neededValue] ?? "Loading..."));
|
||||
}
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
}
|
|
@ -47,23 +47,27 @@ export default class Translation extends UIElement {
|
|||
|
||||
for (const knownSpecial of knownSpecials) {
|
||||
|
||||
do {
|
||||
const matched = template.match(`(.*){${knownSpecial.funcName}\\((.*)\\)}(.*)`);
|
||||
if (matched === null) {
|
||||
break;
|
||||
}
|
||||
const partBefore = matched[1];
|
||||
const argument = matched[2];
|
||||
const partAfter = matched[3];
|
||||
|
||||
const matched = template.match(`(.*){${knownSpecial.funcName}\\((.*)\\)}(.*)`);
|
||||
if (matched === null) {
|
||||
continue;
|
||||
}
|
||||
const partBefore = matched[1];
|
||||
const argument = matched[2];
|
||||
const partAfter = matched[3];
|
||||
try {
|
||||
|
||||
const element = knownSpecial.constr(argument).Render();
|
||||
template = partBefore + element + partAfter;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
template = partBefore + partAfter;
|
||||
}
|
||||
|
||||
} while (true);
|
||||
|
||||
try {
|
||||
|
||||
const element = knownSpecial.constr(argument).Render();
|
||||
template = partBefore + element + partAfter;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
template = partBefore + partAfter;
|
||||
}
|
||||
}
|
||||
newTranslations[lang] = template;
|
||||
}
|
||||
|
|
|
@ -103,10 +103,10 @@ export default class Translations {
|
|||
}),
|
||||
|
||||
respectPrivacy: new T({
|
||||
en: "Please respect privacy. Do not photograph people nor license plates.<br/>Respect copyright. Only upload images you made yourself. Do not upload Google Streetview Images - these will be removed.",
|
||||
en: "Do not photograph people nor license plates. Do not upload Google Maps, Google Streetview or other copyrighted sources.",
|
||||
ca: "Respecta la privacitat. No fotografiïs gent o matrícules",
|
||||
es: "Respeta la privacidad. No fotografíes gente o matrículas",
|
||||
nl: "Respecteer privacy. Fotografeer geen mensen of nummerplaten.<br/>Repecteer auteursrechten. Voeg enkel foto's toe die je zelf maakte. Screenshots van andere services (zoals Google Streetview) worden verwijderd",
|
||||
nl: "Fotografeer geen mensen of nummerplaten. Voeg geen Google Maps, Google Streetview of foto's met auteursrechten toe.",
|
||||
fr: "Merci de respecter la vie privée. Ne publiez pas les plaques d\'immatriculation",
|
||||
gl: "Respecta a privacidade. Non fotografes xente ou matrículas",
|
||||
de: "Bitte respektieren Sie die Privatsphäre. Fotografieren Sie weder Personen noch Nummernschilder"
|
||||
|
@ -969,6 +969,9 @@ export default class Translations {
|
|||
}
|
||||
|
||||
public static WT(s: string | Translation): Translation {
|
||||
if(s === undefined){
|
||||
return undefined;
|
||||
}
|
||||
if (typeof (s) === "string") {
|
||||
return new Translation({en: s});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue