Auto-formatting

This commit is contained in:
Pieter Vander Vennet 2022-12-16 13:45:07 +01:00
parent 9e000d521f
commit fed4cff878
26 changed files with 360 additions and 304 deletions

View file

@ -210,8 +210,8 @@ export default class OverpassFeatureSource implements FeatureSource {
if (overpass === undefined) { if (overpass === undefined) {
return undefined return undefined
} }
this.runningQuery.setData(true); this.runningQuery.setData(true)
[data, date] = await overpass.queryGeoJson(bounds) ;[data, date] = await overpass.queryGeoJson(bounds)
} catch (e) { } catch (e) {
self.retries.data++ self.retries.data++
self.retries.ping() self.retries.ping()

View file

@ -59,7 +59,6 @@ export default class SelectedElementTagsUpdater {
return return
} }
try { try {
const latestTags = await OsmObject.DownloadPropertiesOf(id) const latestTags = await OsmObject.DownloadPropertiesOf(id)
if (latestTags === "deleted") { if (latestTags === "deleted") {
console.warn("The current selected element has been deleted upstream!") console.warn("The current selected element has been deleted upstream!")
@ -69,7 +68,7 @@ export default class SelectedElementTagsUpdater {
} }
currentTagsSource.data["_deleted"] = "yes" currentTagsSource.data["_deleted"] = "yes"
currentTagsSource.ping() currentTagsSource.ping()
return; return
} }
SelectedElementTagsUpdater.applyUpdate(state, latestTags, id) SelectedElementTagsUpdater.applyUpdate(state, latestTags, id)
console.log("Updated", id) console.log("Updated", id)

View file

@ -17,7 +17,10 @@ export default class RenderingMultiPlexerFeatureSource {
> >
private readonly pointRenderings: { rendering: PointRenderingConfig; index: number }[] private readonly pointRenderings: { rendering: PointRenderingConfig; index: number }[]
private readonly centroidRenderings: { rendering: PointRenderingConfig; index: number }[] private readonly centroidRenderings: { rendering: PointRenderingConfig; index: number }[]
private readonly projectedCentroidRenderings: { rendering: PointRenderingConfig; index: number }[] private readonly projectedCentroidRenderings: {
rendering: PointRenderingConfig
index: number
}[]
private readonly startRenderings: { rendering: PointRenderingConfig; index: number }[] private readonly startRenderings: { rendering: PointRenderingConfig; index: number }[]
private readonly endRenderings: { rendering: PointRenderingConfig; index: number }[] private readonly endRenderings: { rendering: PointRenderingConfig; index: number }[]
private readonly hasCentroid: boolean private readonly hasCentroid: boolean
@ -90,10 +93,15 @@ export default class RenderingMultiPlexerFeatureSource {
} }
} else if (feat.geometry.type === "MultiPolygon") { } else if (feat.geometry.type === "MultiPolygon") {
if (this.centroidRenderings.length > 0 || this.projectedCentroidRenderings.length > 0) { if (this.centroidRenderings.length > 0 || this.projectedCentroidRenderings.length > 0) {
const centerpoints: [number, number][] = (<[number, number][][][]>(
const centerpoints: [number, number][] = (<[number, number][][][]>feat.geometry.coordinates).map(rings => GeoOperations.centerpointCoordinates( feat.geometry.coordinates
{type: "Feature", properties: {}, geometry: {type: "Polygon", coordinates: rings}} )).map((rings) =>
)) GeoOperations.centerpointCoordinates({
type: "Feature",
properties: {},
geometry: { type: "Polygon", coordinates: rings },
})
)
for (const centroidRendering of this.centroidRenderings) { for (const centroidRendering of this.centroidRenderings) {
for (const centerpoint of centerpoints) { for (const centerpoint of centerpoints) {
addAsPoint(feat, centroidRendering, centerpoint) addAsPoint(feat, centroidRendering, centerpoint)
@ -105,8 +113,6 @@ export default class RenderingMultiPlexerFeatureSource {
addAsPoint(feat, centroidRendering, centerpoint) addAsPoint(feat, centroidRendering, centerpoint)
} }
} }
} }
// AT last, add it 'as is' to what we should render // AT last, add it 'as is' to what we should render
@ -116,7 +122,6 @@ export default class RenderingMultiPlexerFeatureSource {
lineRenderingIndex: i, lineRenderingIndex: i,
}) })
} }
} else { } else {
// This is a a line or polygon: add the centroids // This is a a line or polygon: add the centroids
let centerpoint: [number, number] = undefined let centerpoint: [number, number] = undefined

View file

@ -19,9 +19,9 @@ export default class UserDetails {
public totalMessages: number = 0 public totalMessages: number = 0
public home: { lon: number; lat: number } public home: { lon: number; lat: number }
public backend: string public backend: string
public account_created: string; public account_created: string
public tracesCount: number = 0; public tracesCount: number = 0
public description: string; public description: string
constructor(backend: string) { constructor(backend: string) {
this.backend = backend this.backend = backend
@ -214,8 +214,12 @@ export class OsmConnection {
data.name = userInfo.getAttribute("display_name") data.name = userInfo.getAttribute("display_name")
data.account_created = userInfo.getAttribute("account_created") data.account_created = userInfo.getAttribute("account_created")
data.uid = Number(userInfo.getAttribute("id")) data.uid = Number(userInfo.getAttribute("id"))
data.csCount = Number.parseInt( userInfo.getElementsByTagName("changesets")[0].getAttribute("count") ?? 0) data.csCount = Number.parseInt(
data.tracesCount = Number.parseInt( userInfo.getElementsByTagName("changesets")[0].getAttribute("count") ?? 0) userInfo.getElementsByTagName("changesets")[0].getAttribute("count") ?? 0
)
data.tracesCount = Number.parseInt(
userInfo.getElementsByTagName("changesets")[0].getAttribute("count") ?? 0
)
data.img = undefined data.img = undefined
const imgEl = userInfo.getElementsByTagName("img") const imgEl = userInfo.getElementsByTagName("img")

View file

@ -271,22 +271,25 @@ export default class MapState extends UserRelatedState {
(l) => l.layerDef.id === "selected_element" (l) => l.layerDef.id === "selected_element"
)[0] )[0]
const empty = [] const empty = []
const store = this.selectedElement.map(feature => { const store = this.selectedElement.map((feature) => {
if (feature === undefined || feature === null) { if (feature === undefined || feature === null) {
return empty return empty
} }
return [{ return [
{
feature: { feature: {
type: "Feature", type: "Feature",
properties: { properties: {
selected: "yes", selected: "yes",
id: "selected" + feature.properties.id id: "selected" + feature.properties.id,
}, },
geometry:feature.geometry geometry: feature.geometry,
} },
, freshness: new Date()}]; freshness: new Date(),
}); },
this.selectedElementsLayer = new TiledStaticFeatureSource(store,layerDef); ]
})
this.selectedElementsLayer = new TiledStaticFeatureSource(store, layerDef)
} }
private initUserLocationTrail() { private initUserLocationTrail() {

View file

@ -127,7 +127,8 @@ export default class MangroveReviews {
this._lastUpdate = new Date() this._lastUpdate = new Date()
const self = this const self = this
mangrove.getReviews({ sub: this.GetSubjectUri() }) mangrove
.getReviews({ sub: this.GetSubjectUri() })
.then((data) => { .then((data) => {
const reviews = [] const reviews = []
const reviewsByUser = [] const reviewsByUser = []
@ -140,7 +141,9 @@ export default class MangroveReviews {
"reviews.kid is", "reviews.kid is",
review.kid review.kid
) )
const byUser = self._mangroveIdentity.kid.map((data) => data === review.signature) const byUser = self._mangroveIdentity.kid.map(
(data) => data === review.signature
)
const rev: Review = { const rev: Review = {
made_by_user: byUser, made_by_user: byUser,
date: new Date(r.iat * 1000), date: new Date(r.iat * 1000),
@ -154,8 +157,8 @@ export default class MangroveReviews {
} }
self._reviews.setData(reviewsByUser.concat(reviews)) self._reviews.setData(reviewsByUser.concat(reviews))
}) })
.catch(e => { .catch((e) => {
console.error("Could not download review for ", e); console.error("Could not download review for ", e)
}) })
return this._reviews return this._reviews
} }

View file

@ -53,7 +53,8 @@ export default class DeleteConfig {
for (const defaultDeleteReason of DeleteConfig.defaultDeleteReasons) { for (const defaultDeleteReason of DeleteConfig.defaultDeleteReasons) {
this.deleteReasons.push({ this.deleteReasons.push({
changesetMessage: defaultDeleteReason.changesetMessage, changesetMessage: defaultDeleteReason.changesetMessage,
explanation: defaultDeleteReason.explanation.Clone(/*Must clone, hides translation otherwise*/) explanation:
defaultDeleteReason.explanation.Clone(/*Must clone, hides translation otherwise*/),
}) })
} }
} }
@ -67,7 +68,11 @@ export default class DeleteConfig {
}) })
if (this.nonDeleteMappings.length + this.deleteReasons.length == 0) { if (this.nonDeleteMappings.length + this.deleteReasons.length == 0) {
throw "At "+context+": a deleteconfig should have some reasons to delete: either the default delete reasons or a nonDeleteMapping or extraDeletereason should be given" throw (
"At " +
context +
": a deleteconfig should have some reasons to delete: either the default delete reasons or a nonDeleteMapping or extraDeletereason should be given"
)
} }
this.softDeletionTags = undefined this.softDeletionTags = undefined

View file

@ -10,9 +10,9 @@ import { FilterState } from "../FilteredLayer"
import { QueryParameters } from "../../Logic/Web/QueryParameters" import { QueryParameters } from "../../Logic/Web/QueryParameters"
import { Utils } from "../../Utils" import { Utils } from "../../Utils"
import { RegexTag } from "../../Logic/Tags/RegexTag" import { RegexTag } from "../../Logic/Tags/RegexTag"
import BaseUIElement from "../../UI/BaseUIElement"; import BaseUIElement from "../../UI/BaseUIElement"
import Table from "../../UI/Base/Table"; import Table from "../../UI/Base/Table"
import Combine from "../../UI/Base/Combine"; import Combine from "../../UI/Base/Combine"
export default class FilterConfig { export default class FilterConfig {
public readonly id: string public readonly id: string
@ -247,19 +247,22 @@ export default class FilterConfig {
} }
public GenerateDocs(): BaseUIElement { public GenerateDocs(): BaseUIElement {
const hasField = this.options.some(opt => opt.fields?.length > 0) const hasField = this.options.some((opt) => opt.fields?.length > 0)
return new Table( return new Table(
Utils.NoNull(["id", "question", "osmTags", hasField ? "fields" : undefined]), Utils.NoNull(["id", "question", "osmTags", hasField ? "fields" : undefined]),
this.options.map((opt, i) => { this.options.map((opt, i) => {
const isDefault = this.options.length > 1 && ((this.defaultSelection ?? 0) == i) const isDefault = this.options.length > 1 && (this.defaultSelection ?? 0) == i
return Utils.NoNull([ return Utils.NoNull([
this.id + "." + i, this.id + "." + i,
isDefault ? new Combine([opt.question.SetClass("font-bold"), "(default)"]) : opt.question , isDefault
? new Combine([opt.question.SetClass("font-bold"), "(default)"])
: opt.question,
opt.osmTags?.asHumanString(false, false, {}) ?? "", opt.osmTags?.asHumanString(false, false, {}) ?? "",
opt.fields?.length > 0 ? new Combine(opt.fields.map(f => f.name+" ("+f.type+")")) : undefined opt.fields?.length > 0
? new Combine(opt.fields.map((f) => f.name + " (" + f.type + ")"))
]); : undefined,
])
}) })
); )
} }
} }

View file

@ -70,7 +70,6 @@ export default interface PointRenderingConfigJson {
*/ */
css?: string | TagRenderingConfigJson css?: string | TagRenderingConfigJson
/** /**
* A snippet of css-classes. They can be space-separated * A snippet of css-classes. They can be space-separated
*/ */

View file

@ -301,7 +301,10 @@ export default class LayerConfig extends WithContextLoader {
const hasCenterRendering = this.mapRendering.some( const hasCenterRendering = this.mapRendering.some(
(r) => (r) =>
r.location.has("centroid") || r.location.has("projected_centerpoint") || r.location.has("start") || r.location.has("end") r.location.has("centroid") ||
r.location.has("projected_centerpoint") ||
r.location.has("start") ||
r.location.has("end")
) )
if (this.lineRendering.length === 0 && this.mapRendering.length === 0) { if (this.lineRendering.length === 0 && this.mapRendering.length === 0) {
@ -605,7 +608,7 @@ export default class LayerConfig extends WithContextLoader {
const filterDocs: (string | BaseUIElement)[] = [] const filterDocs: (string | BaseUIElement)[] = []
if (this.filters.length > 0) { if (this.filters.length > 0) {
filterDocs.push(new Title("Filters", 4)) filterDocs.push(new Title("Filters", 4))
filterDocs.push(...this.filters.map(filter => filter.GenerateDocs())) filterDocs.push(...this.filters.map((filter) => filter.GenerateDocs()))
} }
return new Combine([ return new Combine([
new Combine([new Title(this.id, 1), iconImg, this.description, "\n"]).SetClass( new Combine([new Title(this.id, 1), iconImg, this.description, "\n"]).SetClass(
@ -621,7 +624,7 @@ export default class LayerConfig extends WithContextLoader {
new Title("Supported attributes", 2), new Title("Supported attributes", 2),
quickOverview, quickOverview,
...this.tagRenderings.map((tr) => tr.GenerateDocumentation()), ...this.tagRenderings.map((tr) => tr.GenerateDocumentation()),
...filterDocs ...filterDocs,
]) ])
.SetClass("flex-col") .SetClass("flex-col")
.SetClass("link-underline") .SetClass("link-underline")

View file

@ -12,7 +12,7 @@ import { FixedUiElement } from "../../UI/Base/FixedUiElement"
import Img from "../../UI/Base/Img" import Img from "../../UI/Base/Img"
import Combine from "../../UI/Base/Combine" import Combine from "../../UI/Base/Combine"
import { VariableUiElement } from "../../UI/Base/VariableUIElement" import { VariableUiElement } from "../../UI/Base/VariableUIElement"
import {TagRenderingConfigJson} from "./Json/TagRenderingConfigJson"; import { TagRenderingConfigJson } from "./Json/TagRenderingConfigJson"
export default class PointRenderingConfig extends WithContextLoader { export default class PointRenderingConfig extends WithContextLoader {
private static readonly allowed_location_codes = new Set<string>([ private static readonly allowed_location_codes = new Set<string>([

View file

@ -71,20 +71,17 @@ export default class ScrollableFullScreen {
} }
ScrollableFullScreen._currentlyOpen = self ScrollableFullScreen._currentlyOpen = self
self.Activate() self.Activate()
} else { } else {
if (self.hashToShow !== undefined) { if (self.hashToShow !== undefined) {
Hash.hash.setData(undefined) Hash.hash.setData(undefined)
} }
// Some cleanup... // Some cleanup...
ScrollableFullScreen.collapse() ScrollableFullScreen.collapse()
} }
}) })
} }
private static initEmpty(): FixedUiElement { private static initEmpty(): FixedUiElement {
document.addEventListener("keyup", function (event) { document.addEventListener("keyup", function (event) {
if (event.code === "Escape") { if (event.code === "Escape") {
ScrollableFullScreen.collapse() ScrollableFullScreen.collapse()
@ -93,7 +90,6 @@ export default class ScrollableFullScreen {
}) })
return new FixedUiElement("") return new FixedUiElement("")
} }
public static collapse() { public static collapse() {
const fs = document.getElementById("fullscreen") const fs = document.getElementById("fullscreen")
@ -124,7 +120,6 @@ export default class ScrollableFullScreen {
fs.classList.remove("hidden") fs.classList.remove("hidden")
} }
private BuildComponent(title: BaseUIElement, content: BaseUIElement): BaseUIElement { private BuildComponent(title: BaseUIElement, content: BaseUIElement): BaseUIElement {
const returnToTheMap = new Combine([ const returnToTheMap = new Combine([
Svg.back_svg().SetClass("block md:hidden w-12 h-12 p-2 svg-foreground"), Svg.back_svg().SetClass("block md:hidden w-12 h-12 p-2 svg-foreground"),

View file

@ -147,15 +147,11 @@ export default class CopyrightPanel extends Combine {
imgSize, imgSize,
} }
), ),
new SubtleButton( new SubtleButton(Svg.mastodon_ui(), t.followOnMastodon, {
Svg.mastodon_ui(),
t.followOnMastodon,
{
url: "https://en.osm.town/web/notifications", url: "https://en.osm.town/web/notifications",
newTab: true, newTab: true,
imgSize, imgSize,
} }),
),
new OpenIdEditor(state, iconStyle), new OpenIdEditor(state, iconStyle),
new MapillaryLink(state, iconStyle), new MapillaryLink(state, iconStyle),
new OpenJosm(state, iconStyle), new OpenJosm(state, iconStyle),

View file

@ -13,7 +13,7 @@ import { VariableUiElement } from "../Base/VariableUIElement"
import FeatureInfoBox from "../Popup/FeatureInfoBox" import FeatureInfoBox from "../Popup/FeatureInfoBox"
import CopyrightPanel from "./CopyrightPanel" import CopyrightPanel from "./CopyrightPanel"
import FeaturePipelineState from "../../Logic/State/FeaturePipelineState" import FeaturePipelineState from "../../Logic/State/FeaturePipelineState"
import {FixedUiElement} from "../Base/FixedUiElement"; import { FixedUiElement } from "../Base/FixedUiElement"
export default class LeftControls extends Combine { export default class LeftControls extends Combine {
constructor( constructor(
@ -46,14 +46,11 @@ export default class LeftControls extends Combine {
}) })
).SetClass("inline-block w-full h-full") ).SetClass("inline-block w-full h-full")
feature.map((feature) => { feature.map((feature) => {
if (feature === undefined) { if (feature === undefined) {
return undefined return undefined
} }
const tagsSource = state.allElements.getEventSourceById( const tagsSource = state.allElements.getEventSourceById(feature.properties.id)
feature.properties.id
)
return new FeatureInfoBox(tagsSource, currentViewFL.layerDef, state, { return new FeatureInfoBox(tagsSource, currentViewFL.layerDef, state, {
hashToShow: "currentview", hashToShow: "currentview",
isShown: guiState.currentViewControlIsOpened, isShown: guiState.currentViewControlIsOpened,
@ -85,7 +82,6 @@ export default class LeftControls extends Combine {
) )
) )
new ScrollableFullScreen( new ScrollableFullScreen(
() => Translations.t.general.layerSelection.title.Clone(), () => Translations.t.general.layerSelection.title.Clone(),
() => () =>
@ -110,22 +106,17 @@ export default class LeftControls extends Combine {
// If the welcomeMessage is disabled, the copyright is hidden (as that is where the copyright is located // If the welcomeMessage is disabled, the copyright is hidden (as that is where the copyright is located
const copyright = new Toggle( const copyright = new Toggle(
undefined, undefined,
new Lazy( new Lazy(() => {
() =>
{
new ScrollableFullScreen( new ScrollableFullScreen(
() => Translations.t.general.attribution.attributionTitle, () => Translations.t.general.attribution.attributionTitle,
() => new CopyrightPanel(state), () => new CopyrightPanel(state),
"copyright", "copyright",
guiState.copyrightViewIsOpened guiState.copyrightViewIsOpened
); )
return new MapControlButton(Svg.copyright_svg()).onClick(() => return new MapControlButton(Svg.copyright_svg()).onClick(() =>
guiState.copyrightViewIsOpened.setData(true) guiState.copyrightViewIsOpened.setData(true)
) )
}),
}
),
state.featureSwitchWelcomeMessage state.featureSwitchWelcomeMessage
) )

View file

@ -1,20 +1,20 @@
import ScrollableFullScreen from "../Base/ScrollableFullScreen"; import ScrollableFullScreen from "../Base/ScrollableFullScreen"
import Translations from "../i18n/Translations"; import Translations from "../i18n/Translations"
import {OsmConnection} from "../../Logic/Osm/OsmConnection"; import { OsmConnection } from "../../Logic/Osm/OsmConnection"
import Combine from "../Base/Combine"; import Combine from "../Base/Combine"
import {SubtleButton} from "../Base/SubtleButton"; import { SubtleButton } from "../Base/SubtleButton"
import Svg from "../../Svg"; import Svg from "../../Svg"
import {VariableUiElement} from "../Base/VariableUIElement"; import { VariableUiElement } from "../Base/VariableUIElement"
import Img from "../Base/Img"; import Img from "../Base/Img"
import {FixedUiElement} from "../Base/FixedUiElement"; import { FixedUiElement } from "../Base/FixedUiElement"
import Link from "../Base/Link"; import Link from "../Base/Link"
import {UIEventSource} from "../../Logic/UIEventSource"; import { UIEventSource } from "../../Logic/UIEventSource"
import Loc from "../../Models/Loc"; import Loc from "../../Models/Loc"
import BaseUIElement from "../BaseUIElement"; import BaseUIElement from "../BaseUIElement"
import Showdown from "showdown" import Showdown from "showdown"
import LanguagePicker from "../LanguagePicker"; import LanguagePicker from "../LanguagePicker"
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"; import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"
import Constants from "../../Models/Constants"; import Constants from "../../Models/Constants"
export class ImportViewerLinks extends VariableUiElement { export class ImportViewerLinks extends VariableUiElement {
constructor(osmConnection: OsmConnection) { constructor(osmConnection: OsmConnection) {
@ -37,22 +37,25 @@ export class ImportViewerLinks extends VariableUiElement {
} }
class UserInformationMainPanel extends Combine { class UserInformationMainPanel extends Combine {
constructor(osmConnection: OsmConnection, locationControl: UIEventSource<Loc>, layout: LayoutConfig) { constructor(
const t = Translations.t.userinfo; osmConnection: OsmConnection,
locationControl: UIEventSource<Loc>,
layout: LayoutConfig
) {
const t = Translations.t.userinfo
const imgSize = "h-6 w-6" const imgSize = "h-6 w-6"
const ud = osmConnection.userDetails; const ud = osmConnection.userDetails
super([ super([
new VariableUiElement(
new VariableUiElement(ud.map(ud => { ud.map((ud) => {
if (!ud?.loggedIn) { if (!ud?.loggedIn) {
// Not logged in // Not logged in
return new SubtleButton( return new SubtleButton(Svg.login_svg(), "Login", { imgSize }).onClick(
Svg.login_svg(), "Login", {imgSize} osmConnection.AttemptLogin
).onClick(osmConnection.AttemptLogin) )
} }
let img: Img = Svg.person_svg(); let img: Img = Svg.person_svg()
if (ud.img !== undefined) { if (ud.img !== undefined) {
img = new Img(ud.img) img = new Img(ud.img)
} }
@ -64,69 +67,95 @@ class UserInformationMainPanel extends Combine {
Svg.pencil_svg().SetClass("h-4 w-4"), Svg.pencil_svg().SetClass("h-4 w-4"),
"https://www.openstreetmap.org/profile/edit", "https://www.openstreetmap.org/profile/edit",
true true
).SetClass("absolute block bg-subtle rounded-full p-2 bottom-2 right-2 w-min self-end") ).SetClass(
"absolute block bg-subtle rounded-full p-2 bottom-2 right-2 w-min self-end"
)
description = new Combine([ description = new Combine([
new FixedUiElement(new Showdown.Converter().makeHtml(ud.description)).SetClass("link-underline"), new FixedUiElement(
editButton new Showdown.Converter().makeHtml(ud.description)
).SetClass("link-underline"),
editButton,
]).SetClass("relative w-full m-2") ]).SetClass("relative w-full m-2")
} else { } else {
description = new Combine([ description = new Combine([
t.noDescription, new SubtleButton(Svg.pencil_svg(), t.noDescriptionCallToAction, {imgSize}) t.noDescription,
new SubtleButton(Svg.pencil_svg(), t.noDescriptionCallToAction, {
imgSize,
}),
]).SetClass("w-full m-2") ]).SetClass("w-full m-2")
} }
let panToHome: BaseUIElement; let panToHome: BaseUIElement
if (ud.home) { if (ud.home) {
panToHome = new SubtleButton(Svg.home_svg(), t.moveToHome, {imgSize}) panToHome = new SubtleButton(Svg.home_svg(), t.moveToHome, {
.onClick(() => { imgSize,
}).onClick(() => {
const home = ud?.home const home = ud?.home
if (home === undefined) { if (home === undefined) {
return return
} }
locationControl.setData({ ...home, zoom: 16 }) locationControl.setData({ ...home, zoom: 16 })
} })
);
} }
return new Combine([ return new Combine([
new Combine([img, description]).SetClass("flex border border-black rounded-md"), new Combine([img, description]).SetClass(
new LanguagePicker(layout.language, Translations.t.general.pickLanguage.Clone()), "flex border border-black rounded-md"
),
new LanguagePicker(
layout.language,
Translations.t.general.pickLanguage.Clone()
),
new SubtleButton(Svg.envelope_svg(), new Combine([t.gotoInbox, new SubtleButton(
ud.unreadMessages == 0 ? undefined : t.newMessages.SetClass("alert block") Svg.envelope_svg(),
new Combine([
t.gotoInbox,
ud.unreadMessages == 0
? undefined
: t.newMessages.SetClass("alert block"),
]), ]),
{imgSize, url: `${ud.backend}/messages/inbox`, newTab: true}), { imgSize, url: `${ud.backend}/messages/inbox`, newTab: true }
new SubtleButton(Svg.gear_svg(), t.gotoSettings, ),
{imgSize, url: `${ud.backend}/user/${encodeURIComponent(ud.name)}/account`, newTab: true}), new SubtleButton(Svg.gear_svg(), t.gotoSettings, {
imgSize,
url: `${ud.backend}/user/${encodeURIComponent(ud.name)}/account`,
newTab: true,
}),
panToHome, panToHome,
new ImportViewerLinks(osmConnection), new ImportViewerLinks(osmConnection),
new SubtleButton(Svg.logout_svg(), Translations.t.general.logout, {imgSize}).onClick(osmConnection.LogOut) new SubtleButton(Svg.logout_svg(), Translations.t.general.logout, {
imgSize,
}).onClick(osmConnection.LogOut),
])
})
).SetClass("flex flex-col"),
]) ])
}
)).SetClass("flex flex-col"),
]);
} }
} }
export default class UserInformationPanel extends ScrollableFullScreen { export default class UserInformationPanel extends ScrollableFullScreen {
constructor(state: { constructor(state: {
layoutToUse: LayoutConfig; layoutToUse: LayoutConfig
osmConnection: OsmConnection, locationControl: UIEventSource<Loc> osmConnection: OsmConnection
locationControl: UIEventSource<Loc>
}) { }) {
const t = Translations.t.general; const t = Translations.t.general
super( super(
() => { () => {
return new VariableUiElement(state.osmConnection.userDetails.map(ud => "Welcome " + ud.name)) return new VariableUiElement(
state.osmConnection.userDetails.map((ud) => "Welcome " + ud.name)
)
}, },
() => { () => {
return new UserInformationMainPanel(state.osmConnection, state.locationControl, state.layoutToUse) return new UserInformationMainPanel(
state.osmConnection,
state.locationControl,
state.layoutToUse
)
}, },
"userinfo" "userinfo"
); )
} }
} }

View file

@ -52,8 +52,8 @@ export default class EditableTagRendering extends Toggle {
undefined, undefined,
renderingIsShown renderingIsShown
) )
const self = this; const self = this
editMode.addCallback(editing => { editMode.addCallback((editing) => {
if (editing) { if (editing) {
console.log("Scrolling etr into view") console.log("Scrolling etr into view")
self.ScrollIntoView() self.ScrollIntoView()
@ -96,13 +96,11 @@ export default class EditableTagRendering extends Toggle {
new EditButton(state.osmConnection, () => { new EditButton(state.osmConnection, () => {
editMode.setData(true) editMode.setData(true)
question.ScrollIntoView({ question.ScrollIntoView({
onlyIfPartiallyHidden:true onlyIfPartiallyHidden: true,
}) })
}), }),
]).SetClass("flex justify-between w-full") ]).SetClass("flex justify-between w-full")
rendering = new Toggle(question, answerWithEditButton, editMode) rendering = new Toggle(question, answerWithEditButton, editMode)
} }
return rendering return rendering
} }

View file

@ -79,11 +79,15 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
public static GenerateContent( public static GenerateContent(
tags: UIEventSource<any>, tags: UIEventSource<any>,
layerConfig: LayerConfig, layerConfig: LayerConfig,
state: FeaturePipelineState): BaseUIElement{ state: FeaturePipelineState
): BaseUIElement {
return new Toggle( return new Toggle(
new Combine([Svg.delete_icon_svg().SetClass("w-8 h-8"), Translations.t.delete.isDeleted]).SetClass("flex justify-center font-bold items-center") , new Combine([
Svg.delete_icon_svg().SetClass("w-8 h-8"),
Translations.t.delete.isDeleted,
]).SetClass("flex justify-center font-bold items-center"),
FeatureInfoBox.GenerateMainContent(tags, layerConfig, state), FeatureInfoBox.GenerateMainContent(tags, layerConfig, state),
tags.map(t => t["_deleted"] == "yes") tags.map((t) => t["_deleted"] == "yes")
) )
} }
private static GenerateMainContent( private static GenerateMainContent(
@ -91,7 +95,6 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
layerConfig: LayerConfig, layerConfig: LayerConfig,
state: FeaturePipelineState state: FeaturePipelineState
): BaseUIElement { ): BaseUIElement {
let questionBoxes: Map<string, QuestionBox> = new Map<string, QuestionBox>() let questionBoxes: Map<string, QuestionBox> = new Map<string, QuestionBox>()
const t = Translations.t.general const t = Translations.t.general
const allGroupNames = Utils.Dedup(layerConfig.tagRenderings.map((tr) => tr.group)) const allGroupNames = Utils.Dedup(layerConfig.tagRenderings.map((tr) => tr.group))

View file

@ -19,10 +19,10 @@ import MoveConfig from "../../Models/ThemeConfig/MoveConfig"
import { ElementStorage } from "../../Logic/ElementStorage" import { ElementStorage } from "../../Logic/ElementStorage"
import AvailableBaseLayers from "../../Logic/Actors/AvailableBaseLayers" import AvailableBaseLayers from "../../Logic/Actors/AvailableBaseLayers"
import BaseLayer from "../../Models/BaseLayer" import BaseLayer from "../../Models/BaseLayer"
import SearchAndGo from "../BigComponents/SearchAndGo"; import SearchAndGo from "../BigComponents/SearchAndGo"
import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction"; import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction"
import {And} from "../../Logic/Tags/And"; import { And } from "../../Logic/Tags/And"
import {Tag} from "../../Logic/Tags/Tag"; import { Tag } from "../../Logic/Tags/Tag"
interface MoveReason { interface MoveReason {
text: Translation | string text: Translation | string
@ -71,7 +71,7 @@ export default class MoveWizard extends Toggle {
includeSearch: true, includeSearch: true,
startZoom: 12, startZoom: 12,
minZoom: 6, minZoom: 6,
eraseAddressFields: true eraseAddressFields: true,
}) })
} }
if (options.enableImproveAccuracy) { if (options.enableImproveAccuracy) {
@ -85,7 +85,7 @@ export default class MoveWizard extends Toggle {
background: "photo", background: "photo",
startZoom: 17, startZoom: 17,
minZoom: 16, minZoom: 16,
eraseAddressFields: false eraseAddressFields: false,
}) })
} }
@ -166,7 +166,7 @@ export default class MoveWizard extends Toggle {
let searchPanel: BaseUIElement = undefined let searchPanel: BaseUIElement = undefined
if (reason.includeSearch) { if (reason.includeSearch) {
searchPanel = new SearchAndGo({ searchPanel = new SearchAndGo({
leafletMap: locationInput.leafletMap leafletMap: locationInput.leafletMap,
}) })
} }
@ -186,12 +186,14 @@ export default class MoveWizard extends Toggle {
if (reason.eraseAddressFields) { if (reason.eraseAddressFields) {
await state.changes.applyAction( await state.changes.applyAction(
new ChangeTagAction(featureToMove.properties.id, new ChangeTagAction(
new And([new Tag("addr:housenumber", ""), featureToMove.properties.id,
new And([
new Tag("addr:housenumber", ""),
new Tag("addr:street", ""), new Tag("addr:street", ""),
new Tag("addr:city", ""), new Tag("addr:city", ""),
new Tag("addr:postcode","")] new Tag("addr:postcode", ""),
), ]),
featureToMove.properties, featureToMove.properties,
{ {
changeType: "relocated", changeType: "relocated",

View file

@ -33,7 +33,7 @@ export default class QuestionBox extends VariableUiElement {
.filter((tr) => tr.question !== undefined) .filter((tr) => tr.question !== undefined)
.filter((tr) => tr.question !== null) .filter((tr) => tr.question !== null)
let focus: () => void = () => {}; let focus: () => void = () => {}
const tagRenderingQuestions = tagRenderings.map( const tagRenderingQuestions = tagRenderings.map(
(tagRendering, i) => (tagRendering, i) =>
@ -53,7 +53,6 @@ export default class QuestionBox extends VariableUiElement {
skippedQuestions.data.push(i) skippedQuestions.data.push(i)
skippedQuestions.ping() skippedQuestions.ping()
focus() focus()
}), }),
}) })
) )
@ -141,8 +140,9 @@ export default class QuestionBox extends VariableUiElement {
this.skippedQuestions = skippedQuestions this.skippedQuestions = skippedQuestions
this.restingQuestions = questionsToAsk this.restingQuestions = questionsToAsk
focus = () => this.ScrollIntoView({ focus = () =>
onlyIfPartiallyHidden: true this.ScrollIntoView({
onlyIfPartiallyHidden: true,
}) })
} }
} }

View file

@ -4,8 +4,8 @@ import {ShowDataLayerOptions} from "./ShowDataLayerOptions"
import { ElementStorage } from "../../Logic/ElementStorage" import { ElementStorage } from "../../Logic/ElementStorage"
import RenderingMultiPlexerFeatureSource from "../../Logic/FeatureSource/Sources/RenderingMultiPlexerFeatureSource" import RenderingMultiPlexerFeatureSource from "../../Logic/FeatureSource/Sources/RenderingMultiPlexerFeatureSource"
import ScrollableFullScreen from "../Base/ScrollableFullScreen" import ScrollableFullScreen from "../Base/ScrollableFullScreen"
import {LeafletMouseEvent} from "leaflet"; import { LeafletMouseEvent } from "leaflet"
import Hash from "../../Logic/Web/Hash"; import Hash from "../../Logic/Web/Hash"
/* /*
// import 'leaflet-polylineoffset'; // import 'leaflet-polylineoffset';
We don't actually import it here. It is imported in the 'MinimapImplementation'-class, which'll result in a patched 'L' object. We don't actually import it here. It is imported in the 'MinimapImplementation'-class, which'll result in a patched 'L' object.
@ -43,7 +43,10 @@ export default class ShowDataLayerImplementation {
* Note: the key of this dictionary is 'feature.properties.id+features.geometry.type' as one feature might have multiple presentations * Note: the key of this dictionary is 'feature.properties.id+features.geometry.type' as one feature might have multiple presentations
* @private * @private
*/ */
private readonly leafletLayersPerId = new Map<string, { feature: any; activateFunc: (event: LeafletMouseEvent) => void }>() private readonly leafletLayersPerId = new Map<
string,
{ feature: any; activateFunc: (event: LeafletMouseEvent) => void }
>()
private readonly showDataLayerid: number private readonly showDataLayerid: number
private readonly createPopup: ( private readonly createPopup: (
tags: UIEventSource<any>, tags: UIEventSource<any>,
@ -326,11 +329,11 @@ export default class ShowDataLayerImplementation {
const key = feature.properties.id const key = feature.properties.id
if (this.leafletLayersPerId.has(key)) { if (this.leafletLayersPerId.has(key)) {
const activate = this.leafletLayersPerId.get(key) const activate = this.leafletLayersPerId.get(key)
leafletLayer.addEventListener('click', activate.activateFunc) leafletLayer.addEventListener("click", activate.activateFunc)
if (Hash.hash.data === key) { if (Hash.hash.data === key) {
activate.activateFunc(null) activate.activateFunc(null)
} }
return; return
} }
let infobox: ScrollableFullScreen = undefined let infobox: ScrollableFullScreen = undefined
const self = this const self = this
@ -348,7 +351,9 @@ export default class ShowDataLayerImplementation {
}) })
} }
infobox.Activate() infobox.Activate()
self._selectedElement.setData( self.allElements.ContainingFeatures.get(feature.id) ?? feature ) self._selectedElement.setData(
self.allElements.ContainingFeatures.get(feature.id) ?? feature
)
event?.originalEvent?.preventDefault() event?.originalEvent?.preventDefault()
event?.originalEvent?.stopPropagation() event?.originalEvent?.stopPropagation()
event?.originalEvent?.stopImmediatePropagation() event?.originalEvent?.stopImmediatePropagation()
@ -358,8 +363,7 @@ export default class ShowDataLayerImplementation {
} }
} }
leafletLayer.addEventListener('click', activate) leafletLayer.addEventListener("click", activate)
// Add the feature to the index to open the popup when needed // Add the feature to the index to open the popup when needed
this.leafletLayersPerId.set(key, { this.leafletLayersPerId.set(key, {

View file

@ -1,6 +1,5 @@
import * as colors from "./assets/colors.json" import * as colors from "./assets/colors.json"
export class Utils { export class Utils {
/** /**
* In the 'deploy'-step, some code needs to be run by ts-node. * In the 'deploy'-step, some code needs to be run by ts-node.
@ -139,7 +138,13 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
"false", "false",
] ]
private static injectedDownloads = {} private static injectedDownloads = {}
private static _download_cache = new Map<string, { promise: Promise<any | {error: string, url: string, statuscode?: number}>; timestamp: number }>() private static _download_cache = new Map<
string,
{
promise: Promise<any | { error: string; url: string; statuscode?: number }>
timestamp: number
}
>()
/** /**
* Parses the arguments for special visualisations * Parses the arguments for special visualisations
@ -816,8 +821,12 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
*/ */
public static downloadAdvanced( public static downloadAdvanced(
url: string, url: string,
headers?: any, headers?: any
): Promise<{ content: string } | { redirect: string } | { error: string,url: string, statuscode?: number}> { ): Promise<
| { content: string }
| { redirect: string }
| { error: string; url: string; statuscode?: number }
> {
if (this.externalDownloadFunction !== undefined) { if (this.externalDownloadFunction !== undefined) {
return this.externalDownloadFunction(url, headers) return this.externalDownloadFunction(url, headers)
} }
@ -833,7 +842,11 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
} else if (xhr.status === 509 || xhr.status === 429) { } else if (xhr.status === 509 || xhr.status === 429) {
resolve({ error: "rate limited", url, statuscode: xhr.status }) resolve({ error: "rate limited", url, statuscode: xhr.status })
} else { } else {
resolve ({error: "other error: "+xhr.statusText, url, statuscode: xhr.status}) resolve({
error: "other error: " + xhr.statusText,
url,
statuscode: xhr.status,
})
} }
} }
xhr.open("GET", url) xhr.open("GET", url)
@ -888,14 +901,15 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
url: string, url: string,
maxCacheTimeMs: number, maxCacheTimeMs: number,
headers?: any headers?: any
): Promise<any | {error: string, url: string, statuscode?: number}> { ): Promise<any | { error: string; url: string; statuscode?: number }> {
const cached = Utils._download_cache.get(url) const cached = Utils._download_cache.get(url)
if (cached !== undefined) { if (cached !== undefined) {
if (new Date().getTime() - cached.timestamp <= maxCacheTimeMs) { if (new Date().getTime() - cached.timestamp <= maxCacheTimeMs) {
return cached.promise return cached.promise
} }
} }
const promise = /*NO AWAIT as we work with the promise directly */ Utils.downloadJsonAdvanced( const promise =
/*NO AWAIT as we work with the promise directly */ Utils.downloadJsonAdvanced(
url, url,
headers headers
) )
@ -911,8 +925,10 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
throw result["error"] throw result["error"]
} }
public static async downloadJsonAdvanced(
public static async downloadJsonAdvanced(url: string, headers?: any): Promise<{content: any} | {error: string, url: string, statuscode?: number}> { url: string,
headers?: any
): Promise<{ content: any } | { error: string; url: string; statuscode?: number }> {
const injected = Utils.injectedDownloads[url] const injected = Utils.injectedDownloads[url]
if (injected !== undefined) { if (injected !== undefined) {
console.log("Using injected resource for test for URL", url) console.log("Using injected resource for test for URL", url)
@ -923,21 +939,20 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
Utils.Merge({ accept: "application/json" }, headers ?? {}) Utils.Merge({ accept: "application/json" }, headers ?? {})
) )
if (result["error"] !== undefined) { if (result["error"] !== undefined) {
return <{error: string, url: string, statuscode?: number}> result return <{ error: string; url: string; statuscode?: number }>result
} }
const data = result["content"] const data = result["content"]
try { try {
if (typeof data === "string") { if (typeof data === "string") {
return { content: JSON.parse(data) } return { content: JSON.parse(data) }
} }
return {"content": data} return { content: data }
} catch (e) { } catch (e) {
console.error("Could not parse ", data, "due to", e, "\n", e.stack) console.error("Could not parse ", data, "due to", e, "\n", e.stack)
return { error: "malformed", url } return { error: "malformed", url }
} }
} }
/** /**
* Triggers a 'download file' popup which will download the contents * Triggers a 'download file' popup which will download the contents
*/ */
@ -1261,16 +1276,15 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
public static findParentWithScrolling(element: HTMLElement): HTMLElement { public static findParentWithScrolling(element: HTMLElement): HTMLElement {
// Check if the element itself has scrolling // Check if the element itself has scrolling
if (element.scrollHeight > element.clientHeight) { if (element.scrollHeight > element.clientHeight) {
return element; return element
} }
// If the element does not have scrolling, check if it has a parent element // If the element does not have scrolling, check if it has a parent element
if (!element.parentElement) { if (!element.parentElement) {
return null; return null
} }
// If the element has a parent, repeat the process for the parent element // If the element has a parent, repeat the process for the parent element
return Utils.findParentWithScrolling(element.parentElement); return Utils.findParentWithScrolling(element.parentElement)
} }
} }