From ff1690e3075528d9625bf7f987614fd4b8e0d23a Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Mon, 13 Jul 2020 16:18:04 +0200 Subject: [PATCH] Hide edit buttons when not logged in, css tweaks --- Customizations/AllKnownLayouts.ts | 5 +++-- Customizations/Layers/Bookcases.ts | 2 +- Customizations/Layout.ts | 9 +-------- Customizations/Layouts/Bookcases.ts | 1 + Customizations/Layouts/Groen.ts | 2 ++ Customizations/TagRendering.ts | 13 ++++++++++++- Logic/Changes.ts | 2 +- UI/Image/ImageCarousel.ts | 15 ++++++++++----- index.css | 3 +-- index.html | 9 --------- index.ts | 18 ++++++++++++++++++ 11 files changed, 50 insertions(+), 29 deletions(-) diff --git a/Customizations/AllKnownLayouts.ts b/Customizations/AllKnownLayouts.ts index 68173c8e2..9a8728e84 100644 --- a/Customizations/AllKnownLayouts.ts +++ b/Customizations/AllKnownLayouts.ts @@ -5,13 +5,14 @@ import {Statues} from "./Layouts/Statues"; import {Bookcases} from "./Layouts/Bookcases"; import Cyclofix from "./Layouts/Cyclofix"; import {All} from "./Layouts/All"; +import {Layout} from "./Layout"; export class AllKnownLayouts { public static allSets: any = AllKnownLayouts.AllLayouts(); - private static AllLayouts() { + private static AllLayouts() : any{ const all = new All(); - const layouts = [ + const layouts : Layout[] = [ new Groen(), new GRB(), new Cyclofix(), diff --git a/Customizations/Layers/Bookcases.ts b/Customizations/Layers/Bookcases.ts index acc9d65ba..52e0b86e0 100644 --- a/Customizations/Layers/Bookcases.ts +++ b/Customizations/Layers/Bookcases.ts @@ -145,7 +145,7 @@ export class Bookcases extends LayerDefinition { new TagRenderingOptions({ freeform: { key: "description", - renderTemplate: "Beschrijving door de uitbater
{description}", + renderTemplate: "Beschrijving door de uitbater:
{description}", template: "$$$", } }) diff --git a/Customizations/Layout.ts b/Customizations/Layout.ts index 9ff0e4cd2..7a5b8809e 100644 --- a/Customizations/Layout.ts +++ b/Customizations/Layout.ts @@ -16,6 +16,7 @@ export class Layout { public startLat: number; public welcomeTail: string; + public locationContains: string[]; constructor( name: string, @@ -41,13 +42,5 @@ export class Layout { this.welcomeTail = welcomeTail; } -/* - - - static statues = new Layout( - - ); - -*/ } diff --git a/Customizations/Layouts/Bookcases.ts b/Customizations/Layouts/Bookcases.ts index 7d02aabb9..833150b30 100644 --- a/Customizations/Layouts/Bookcases.ts +++ b/Customizations/Layouts/Bookcases.ts @@ -23,5 +23,6 @@ export class Bookcases extends Layout{ " of door je " + " aan te melden.

", "Klik op een boekenruilkastje om vragen te beantwoorden"); + this.locationContains= ["Bookcases.html", "Bookcase.html","bookcase"] } } \ No newline at end of file diff --git a/Customizations/Layouts/Groen.ts b/Customizations/Layouts/Groen.ts index 8e7f04775..7f3d0f934 100644 --- a/Customizations/Layouts/Groen.ts +++ b/Customizations/Layouts/Groen.ts @@ -47,5 +47,7 @@ export class Groen extends Layout { "Als je inlogt, komt er een tweede cookie bij met je inloggegevens." + "" ); + + this.locationContains = ["buurtnatuur.be"] } } \ No newline at end of file diff --git a/Customizations/TagRendering.ts b/Customizations/TagRendering.ts index bd99ed470..a02f2a0eb 100644 --- a/Customizations/TagRendering.ts +++ b/Customizations/TagRendering.ts @@ -11,6 +11,7 @@ import {UIRadioButtonWithOther} from "../UI/Base/UIRadioButtonWithOther"; import {VariableUiElement} from "../UI/Base/VariableUIElement"; import {TagDependantUIElement, TagDependantUIElementConstructor} from "./UIElementConstructor"; import {OnlyShowIfConstructor} from "./OnlyShowIf"; +import {UserDetails} from "../Logic/OsmConnection"; export class TagRenderingOptions implements TagDependantUIElementConstructor { @@ -111,6 +112,7 @@ class TagRendering extends UIElement implements TagDependantUIElement { private _priority: number; + private _userDetails: UIEventSource; Priority(): number { return this._priority; @@ -162,6 +164,9 @@ class TagRendering extends UIElement implements TagDependantUIElement { this.ListenTo(this._questionSkipped); this.ListenTo(this._editMode); + this._userDetails = changes.login.userDetails; + this.ListenTo(this._userDetails); + this._question = options.question; this._priority = options.priority ?? 0; this._primer = options.primer ?? ""; @@ -397,8 +402,14 @@ class TagRendering extends UIElement implements TagDependantUIElement { if (html == "") { return ""; } + let editButton = ""; + if(this._userDetails.data.loggedIn){ + editButton = this._editButton.Render(); + } + return "" + - "" + html + "" + this._editButton.Render() + + "" + html + "" + + editButton + ""; } diff --git a/Logic/Changes.ts b/Logic/Changes.ts index b93e1f048..de58a769c 100644 --- a/Logic/Changes.ts +++ b/Logic/Changes.ts @@ -13,7 +13,7 @@ export class Changes { private static _nextId = -1; // New assined ID's are negative - private readonly login: OsmConnection; + public readonly login: OsmConnection; public readonly _allElements: ElementStorage; private _pendingChanges: { elementId: string, key: string, value: string }[] = []; // Gets reset on uploadAll diff --git a/UI/Image/ImageCarousel.ts b/UI/Image/ImageCarousel.ts index 82627f1cf..f8f69c9d4 100644 --- a/UI/Image/ImageCarousel.ts +++ b/UI/Image/ImageCarousel.ts @@ -7,6 +7,7 @@ import {VerticalCombine} from "../Base/VerticalCombine"; import {Changes} from "../../Logic/Changes"; import {VariableUiElement} from "../Base/VariableUIElement"; import {ConfirmDialog} from "../ConfirmDialog"; +import {UserDetails} from "../../Logic/OsmConnection"; export class ImageCarousel extends UIElement { @@ -18,10 +19,13 @@ export class ImageCarousel extends UIElement { private readonly _deleteButton: UIElement; private readonly _isDeleted: UIElement; + + private readonly _userDetails : UIEventSource; constructor(tags: UIEventSource, changes: Changes) { super(tags); - + this._userDetails = changes.login.userDetails; + const self = this; this.searcher = new ImageSearcher(tags, changes); @@ -40,8 +44,11 @@ export class ImageCarousel extends UIElement { const showDeleteButton = this.slideshow._currentSlide.map((i) => { + if(!self._userDetails.data.loggedIn){ + return false; + } return self.searcher.IsDeletable(self.searcher.data[i]); - }, [this.searcher]); + }, [this.searcher, this._userDetails]); this.slideshow._currentSlide.addCallback(() => { showDeleteButton.ping(); // This pings the showDeleteButton, which indicates that it has to hide it's subbuttons }) @@ -57,8 +64,7 @@ export class ImageCarousel extends UIElement { "Afbeelding verwijderen", "Terug", deleteCurrent, - () => { - }, + () => { }, 'delete-image-confirm', 'delete-image-cancel'); @@ -75,7 +81,6 @@ export class ImageCarousel extends UIElement { this._isDeleted = new VariableUiElement( mapping ) - // .HideOnEmpty(true); this.searcher._deletedImages.addCallback(() => { this.slideshow._currentSlide.ping(); diff --git a/index.css b/index.css index 07cf49b17..c86b574e1 100644 --- a/index.css +++ b/index.css @@ -573,7 +573,7 @@ form { /***************** Info box (box containing features and questions ******************/ .leaflet-popup-content { - width: 25vw !important; + width: 40em !important; } .featureinfobox { @@ -669,7 +669,6 @@ form { background-color: #e5f5ff; padding: 1em; border-radius: 1em; - margin-right: 1em; font-size: larger; } diff --git a/index.html b/index.html index e340617d1..16c538705 100644 --- a/index.html +++ b/index.html @@ -48,15 +48,6 @@ - - - - - - - - - diff --git a/index.ts b/index.ts index 45fd058a0..252cf5c50 100644 --- a/index.ts +++ b/index.ts @@ -21,6 +21,7 @@ import {VariableUiElement} from "./UI/Base/VariableUIElement"; import {SearchAndGo} from "./UI/SearchAndGo"; import {CollapseButton} from "./UI/Base/CollapseButton"; import {AllKnownLayouts} from "./Customizations/AllKnownLayouts"; +import {All} from "./Customizations/Layouts/All"; @@ -50,6 +51,23 @@ if (location.hostname === "localhost" || location.hostname === "127.0.0.1") { let defaultQuest = "buurtnatuur" + +for (const k in AllKnownLayouts.allSets) { + const layout = AllKnownLayouts.allSets[k]; + const possibleParts = layout.locationContains ?? []; + console.log(layout.locationContains) + for (const locationMatch of possibleParts) { + if(locationMatch === ""){ + continue + } + console.log(layout.name," -> ", locationMatch, window.location.href.indexOf(locationMatch)) + if(window.location.href.toLowerCase().indexOf(locationMatch.toLowerCase()) >= 0){ + defaultQuest = layout.name; + console.log("Detected a default by URL: ", layout.name, "matches", locationMatch) + } + } +} + if (window.location.search) { const params = window.location.search.substr(1).split("&"); const paramDict: any = {};