Add viewpoint for buurtnatuur, add translation of AddPointPoi

This commit is contained in:
Pieter Vander Vennet 2020-07-24 15:52:21 +02:00
parent 7bbc140f05
commit c3d04c79b9
13 changed files with 271 additions and 71 deletions

View file

@ -1,4 +1,5 @@
import {UIElement} from "../UIElement";
import Locale from "../i18n/Locale";
export class Button extends UIElement {
private _text: UIElement;
@ -6,7 +7,7 @@ export class Button extends UIElement {
private _clss: string;
constructor(text: UIElement, onclick: (() => void), clss: string = "") {
super(undefined);
super(Locale.language);
this._text = text;
this._onclick = onclick;
if (clss !== "") {
@ -28,9 +29,7 @@ export class Button extends UIElement {
InnerUpdate(htmlElement: HTMLElement) {
super.InnerUpdate(htmlElement);
const self = this;
console.log("Update for ", htmlElement)
document.getElementById("button-"+this.id).onclick = function(){
console.log("Clicked");
self._onclick();
}
}

View file

@ -89,7 +89,6 @@ export class DropDown<T> extends InputElement<T> {
var t = this._value.data;
for (let i = 0; i < this._values.length ; i++) {
const value = this._values[i].value;
console.log("Checking",value," against ",t, ":", t === value)
if (value === t) {
// @ts-ignore
e.selectedIndex = i;

View file

@ -6,6 +6,8 @@ import {Changes} from "../Logic/Changes";
import {FixedUiElement} from "./Base/FixedUiElement";
import {Button} from "./Base/Button";
import {UserDetails} from "../Logic/OsmConnection";
import Translations from "./i18n/Translations";
import Combine from "./Base/Combine";
/**
* Asks to add a feature at the last clicked location, at least if zoom is sufficient
@ -42,7 +44,7 @@ export class SimpleAddUI extends UIElement {
// <button type='button'> looks SO retarded
// the default type of button is 'submit', which performs a POST and page reload
const button =
new Button(new FixedUiElement("Add a " + option.name.Render() + " here"),
new Button(Translations.t.general.add.addNew.Subs({category: option.name}),
this.CreatePoint(option));
this._addButtons.push(button);
}
@ -60,25 +62,25 @@ export class SimpleAddUI extends UIElement {
}
InnerRender(): string {
const header = "<h2>No data here</h2>" +
"You clicked somewhere where no data is known yet.<br/>";
const header = Translations.t.general.add.header;
if (!this._userDetails.data.loggedIn) {
return header + "<a class='activate-osm-authentication'>Please log in to add a new point</a>"
return new Combine([header, Translations.t.general.add.pleaseLogin]).Render()
}
if (this._zoomlevel.data.zoom < 19) {
return header + "Zoom in further to add a point.";
return new Combine([header, Translations.t.general.add.zoomInFurther]).Render()
}
if (this._dataIsLoading.data) {
return header + "The data is still loading. Please wait a bit before you add a new point";
return new Combine([header, Translations.t.general.add.stillLoading]).Render()
}
var html = "";
for (const button of this._addButtons) {
html += button.Render();
}
return header + html;
return header.Render() + html;
}
InnerUpdate(htmlElement: HTMLElement) {

View file

@ -1,11 +1,48 @@
import { UIElement } from "../UIElement"
import {UIElement} from "../UIElement"
import Locale from "./Locale"
import {FixedUiElement} from "../Base/FixedUiElement";
import {TagUtils} from "../../Logic/TagsFilter";
import Combine from "../Base/Combine";
export default class Translation extends UIElement {
private static forcedLanguage = undefined;
public Subs(text: any /*Map<string, string | UIElement>*/) {
const newTranslations = {};
for (const lang in this.translations) {
let template: string = this.translations[lang];
for (const k in text) {
const combined = [];
const parts = template.split("{" + k + "}");
const el: string | UIElement = text[k];
let rtext: string = "";
console.log(parts)
if (typeof (el) === "string") {
rtext = el;
} else {
Translation.forcedLanguage = lang; // This is a very dirty hack - it'll bite me one day
rtext = el.InnerRender();
console.log(rtext)
}
for (let i = 0; i < parts.length - 1; i++) {
combined.push(parts[i]);
combined.push(rtext)
}
combined.push(parts[parts.length - 1]);
template = new Combine(combined).InnerRender();
}
newTranslations[lang] = template;
}
Translation.forcedLanguage = undefined;
return new Translation(newTranslations);
}
get txt(): string {
const txt = this.translations[Locale.language.data];
const txt = this.translations[Translation.forcedLanguage ?? Locale.language.data];
if (txt !== undefined) {
return txt;
}
@ -36,8 +73,9 @@ export default class Translation extends UIElement {
return new Translation(this.translations).Render();
}
public Clone(){
public Clone() {
return new Translation(this.translations)
}
}

View file

@ -391,7 +391,31 @@ export default class Translations {
number: new T({
en: "number",
nl: "getal"
})
}),
add: {
addNew: new T({
en: "Add a new {category} here",
nl: "Voeg hier een {category} toe"
}),
header: new T({
en: "<h2>No data</h2>You clicked somewhere where no data is known yet.<br/>",
nl: "<h2>Geen selectie</h2>Je klikte ergens waar er nog geen data is.<br/>"
}),
pleaseLogin: new T({
en: "<a class='activate-osm-authentication'>Please log in to add a new point</a>",
nl: "<a class='activate-osm-authentication'>Gelieve je aan te melden om een punt to te voegen</a>"
}),
zoomInFurther: new T({
en: "Zoom in further to add a point.",
nl: "Gelieve verder in te zoomen om een punt toe te voegen"
}),
stillLoading: new T({
en: "The data is still loading. Please wait a bit before you add a new point",
nl: "De data wordt nog geladen. Nog even geduld en dan kan je een punt toevoegen."
})
}
}
}