Intermediate refactoring

This commit is contained in:
Pieter Vander Vennet 2020-07-20 18:24:00 +02:00
parent 069cddf034
commit 7b80e945bb
16 changed files with 43 additions and 44 deletions

View file

@ -88,7 +88,6 @@ export class LayerDefinition {
}
} = undefined) {
if (options === undefined) {
console.log("No options!")
return;
}
this.name = options.name;
@ -100,7 +99,6 @@ export class LayerDefinition {
this.title = options.title;
this.elementsToShow = options.elementsToShow;
this.style = options.style;
console.log(this)
}
asLayer(basemap: Basemap, allElements: ElementStorage, changes: Changes, userDetails: UIEventSource<UserDetails>, selectedElement: UIEventSource<any>,

View file

@ -1,10 +1,8 @@
import {LayerDefinition} from "../LayerDefinition";
import L from "leaflet";
import {And, Or, Regex, Tag} from "../../Logic/TagsFilter";
import {QuestionDefinition} from "../../Logic/Question";
import {And, Or, Tag} from "../../Logic/TagsFilter";
import {TagRenderingOptions} from "../TagRendering";
import {NameInline} from "../Questions/NameInline";
import {NameQuestion} from "../Questions/NameQuestion";
import {ImageCarouselWithUploadConstructor} from "../../UI/Image/ImageCarouselWithUpload";
export class Bookcases extends LayerDefinition {

View file

@ -294,7 +294,19 @@ class TagRendering extends UIElement implements TagDependantUIElement {
const elements = [];
if (options.mappings !== undefined) {
const previousTexts= [];
for (const mapping of options.mappings) {
console.log(mapping);
if(mapping.k === null){
continue;
}
if(previousTexts.indexOf(mapping.txt) >= 0){
continue;
}
previousTexts.push(mapping.txt);
console.log("PUshed")
elements.push(this.InputElementForMapping(mapping));
}
}
@ -350,6 +362,7 @@ class TagRendering extends UIElement implements TagDependantUIElement {
} else if (tag instanceof Tag) {
return tag.value
}
console.log("Could not decode tag to string", tag)
return undefined;
}
@ -447,7 +460,7 @@ class TagRendering extends UIElement implements TagDependantUIElement {
}
protected InnerRender(): string {
InnerRender(): string {
if (this.IsQuestioning() || this._editMode.data) {
// Not yet known or questioning, we have to ask a question
@ -492,5 +505,10 @@ class TagRendering extends UIElement implements TagDependantUIElement {
return TagUtils.ApplyTemplate(template, tags);
}
InnerUpdate(htmlElement: HTMLElement) {
super.InnerUpdate(htmlElement);
this._questionElement.Update(); // Another manual update for them
}
}

View file

@ -60,7 +60,6 @@ export class Imgur {
}
console.log(data);
const licenseInfo = new LicenseInfo();
licenseInfo.licenseShortName = data.license;

View file

@ -57,8 +57,7 @@ export class LayerUpdater {
}
private handleFail(reason: any) {
console.log("QUERY FAILED", reason);
console.log("Retrying in 1s")
console.log("QUERY FAILED (retrying in 1 sec)", reason);
this.previousBounds = undefined;
const self = this;
window.setTimeout(
@ -73,7 +72,6 @@ export class LayerUpdater {
}
console.log("Zoom level: ",this._map.map.getZoom(), "Least needed zoom:", this._minzoom)
if (this._map.map.getZoom() < this._minzoom || this._map.Location.data.zoom < this._minzoom) {
console.log("Not running query: zoom not sufficient");
return;
}

View file

@ -18,7 +18,7 @@ export class Button extends UIElement {
}
protected InnerRender(): string {
InnerRender(): string {
return "<form>" +
"<button id='button-"+this.id+"' type='button' "+this._clss+">" + this._text.Render() + "</button>" +

View file

@ -8,7 +8,7 @@ export class FixedUiElement extends UIElement {
this._html = html ?? "";
}
protected InnerRender(): string {
InnerRender(): string {
return this._html;
}

View file

@ -12,16 +12,8 @@ export class VariableUiElement extends UIElement {
}
protected InnerRender(): string {
InnerRender(): string {
return this._html.data;
}
InnerUpdate(htmlElement: HTMLElement) {
super.InnerUpdate(htmlElement);
if(this._innerUpdate !== undefined){
this._innerUpdate(htmlElement);
}
}
}

View file

@ -26,7 +26,7 @@ export class InputElementWrapper<T> extends InputElement<T>{
return this.input.GetValue();
}
protected InnerRender(): string {
InnerRender(): string {
return this.pre.Render() + this.input.Render() + this.post.Render();
}

View file

@ -62,7 +62,7 @@ export class RadioButton<T> extends InputElement<T> {
return 'radio-' + this.id + '-' + i;
}
protected InnerRender(): string {
InnerRender(): string {
let body = "";
let i = 0;
@ -83,14 +83,16 @@ export class RadioButton<T> extends InputElement<T> {
if (t === undefined) {
return;
}
console.log("Trying to find an option for", t)
// We check that what is selected matches the previous rendering
for (let i = 0; i < this._elements.length; i++) {
const e = this._elements[i];
if (e.IsValid(t)) {
this._selectedElementIndex.setData(i);
e.GetValue().setData(t);
const radio = document.getElementById(this.IdFor(i));
// @ts-ignore
document.getElementById(this.IdFor(i)).checked = true;
radio?.checked = true;
return;
}

View file

@ -18,8 +18,8 @@ export class TextField<T> extends InputElement<T> {
constructor(options: {
placeholder?: string | UIElement,
toString?: (t: T) => string,
fromString?: (string: string) => T,
toString: (t: T) => string,
fromString: (string: string) => T,
value?: UIEventSource<T>
}) {
super(undefined);
@ -33,15 +33,18 @@ export class TextField<T> extends InputElement<T> {
this.mappedValue.addCallback((t) => this.value.setData(options.toString(t)));
this._placeholder =
typeof(options.placeholder) === "string" ? new FixedUiElement(options.placeholder) :
(options.placeholder ?? new FixedUiElement(""));
options.placeholder = options.placeholder ?? "";
if (options.placeholder instanceof UIElement) {
this._placeholder = options.placeholder
} else {
this._placeholder = new FixedUiElement(options.placeholder);
}
this._toString = options.toString ?? ((t) => ("" + t));
const self = this;
this.mappedValue.addCallback((t) => {
if (t === undefined && t === null) {
if (t === undefined || t === null) {
return;
}
const field = document.getElementById('text-' + this.id);
@ -57,7 +60,7 @@ export class TextField<T> extends InputElement<T> {
return this.mappedValue;
}
protected InnerRender(): string {
InnerRender(): string {
return "<form onSubmit='return false' class='form-text-field'>" +
"<input type='text' placeholder='" + this._placeholder.InnerRender() + "' id='text-" + this.id + "'>" +
"</form>";

View file

@ -45,7 +45,6 @@ export class MessageBoxHandler {
update() {
const wrapper = document.getElementById("messagesboxmobilewrapper");
const gen = this._uielement.data;
console.log("Generator: ", gen);
if (gen === undefined) {
wrapper.classList.add("hidden")
if (location.hash !== "") {
@ -55,10 +54,6 @@ export class MessageBoxHandler {
}
location.hash = "#element"
wrapper.classList.remove("hidden");
/* gen()
?.HideOnEmpty(true)
?.AttachTo("messagesbox")
?.Activate();*/
gen()
?.HideOnEmpty(true)

View file

@ -12,7 +12,7 @@ export class SaveButton extends UIElement {
this._value = value;
}
protected InnerRender(): string {
InnerRender(): string {
if (this._value.data === undefined ||
this._value.data === null
|| this._value.data === ""

View file

@ -60,7 +60,7 @@ export class SimpleAddUI extends UIElement {
}
}
protected InnerRender(): string {
InnerRender(): string {
const header = "<h2>Geen selectie</h2>" +
"Je klikte ergens waar er nog geen gezochte data is.<br/>";
if (!this._userDetails.data.loggedIn) {
@ -83,10 +83,6 @@ export class SimpleAddUI extends UIElement {
}
InnerUpdate(htmlElement: HTMLElement) {
super.InnerUpdate(htmlElement);
for (const button of this._addButtons) {
button.Update();
}
this._userDetails.data.osmConnection.registerActivateOsmAUthenticationClass();
}

View file

@ -100,7 +100,7 @@ export abstract class UIElement {
return this;
}
protected abstract InnerRender(): string;
public abstract InnerRender(): string;
public Activate(): void {
for (const i in this) {

View file

@ -58,7 +58,7 @@ export class UserBadge extends UIElement {
}
protected InnerRender(): string {
InnerRender(): string {
const user = this._userDetails.data;
if (!user.loggedIn) {
return "<div class='activate-osm-authentication'>Klik hier om aan te melden bij OSM</div>";