forked from MapComplete/MapComplete
chore: automated housekeeping...
This commit is contained in:
parent
8109c13b38
commit
297bb1c498
185 changed files with 2826 additions and 5874 deletions
|
|
@ -14,7 +14,6 @@ import {
|
|||
} from "geojson"
|
||||
import { Tiles } from "../Models/TileRange"
|
||||
import { Utils } from "../Utils"
|
||||
|
||||
;("use strict")
|
||||
|
||||
export class GeoOperations {
|
||||
|
|
|
|||
|
|
@ -9,13 +9,15 @@ import Constants from "../../Models/Constants"
|
|||
import Locale from "../../UI/i18n/Locale"
|
||||
import { Utils } from "../../Utils"
|
||||
|
||||
|
||||
export class ThemeSearchIndex {
|
||||
|
||||
private readonly themeIndex: Fuse<MinimalThemeInformation>
|
||||
private readonly layerIndex: Fuse<{ id: string, description }>
|
||||
private readonly layerIndex: Fuse<{ id: string; description }>
|
||||
|
||||
constructor(language: string, themesToSearch?: MinimalThemeInformation[], layersToIgnore: string[] = []) {
|
||||
constructor(
|
||||
language: string,
|
||||
themesToSearch?: MinimalThemeInformation[],
|
||||
layersToIgnore: string[] = []
|
||||
) {
|
||||
const themes = Utils.NoNull(themesToSearch ?? ThemeSearch.officialThemes?.themes)
|
||||
if (!themes) {
|
||||
throw "No themes loaded. Did generate:layeroverview fail?"
|
||||
|
|
@ -27,14 +29,17 @@ export class ThemeSearchIndex {
|
|||
{ name: "id", weight: 2 },
|
||||
"title." + language,
|
||||
"keywords." + language,
|
||||
"shortDescription." + language
|
||||
]
|
||||
"shortDescription." + language,
|
||||
],
|
||||
}
|
||||
|
||||
this.themeIndex = new Fuse(themes.filter(th => th?.id !== "personal"), fuseOptions)
|
||||
this.themeIndex = new Fuse(
|
||||
themes.filter((th) => th?.id !== "personal"),
|
||||
fuseOptions
|
||||
)
|
||||
|
||||
const toIgnore = new Set(layersToIgnore)
|
||||
const layersAsList: { id: string, description: Record<string, string[]> }[] = []
|
||||
const layersAsList: { id: string; description: Record<string, string[]> }[] = []
|
||||
for (const id in ThemeSearch.officialThemes.layers) {
|
||||
if (Constants.isPriviliged(id)) {
|
||||
continue
|
||||
|
|
@ -50,7 +55,7 @@ export class ThemeSearchIndex {
|
|||
minMatchCharLength: 3,
|
||||
ignoreLocation: true,
|
||||
threshold: 0.02,
|
||||
keys: ["id", "description." + language]
|
||||
keys: ["id", "description." + language],
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -61,7 +66,7 @@ export class ThemeSearchIndex {
|
|||
if (limit) {
|
||||
result = result.slice(0, limit)
|
||||
}
|
||||
return result.map(e => ThemeSearch.officialThemesById.get(e[0]))
|
||||
return result.map((e) => ThemeSearch.officialThemesById.get(e[0]))
|
||||
}
|
||||
|
||||
public searchWithScores(text: string): Map<string, number> {
|
||||
|
|
@ -76,20 +81,22 @@ export class ThemeSearchIndex {
|
|||
for (const layer of layerResults) {
|
||||
const matchingThemes = ThemeSearch.layersToThemes.get(layer.item.id)
|
||||
const score = layer.score
|
||||
matchingThemes?.forEach(th => {
|
||||
matchingThemes?.forEach((th) => {
|
||||
const previous = result.get(th.id) ?? 10000
|
||||
result.set(th.id, Math.min(previous, score * 5))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a search index containing all public and visited themes, but ignoring the layers loaded by the current theme
|
||||
*/
|
||||
public static fromState(state: { osmConnection: OsmConnection; theme: ThemeConfig }): Store<ThemeSearchIndex> {
|
||||
public static fromState(state: {
|
||||
osmConnection: OsmConnection
|
||||
theme: ThemeConfig
|
||||
}): Store<ThemeSearchIndex> {
|
||||
const layersToIgnore = state.theme.layers.filter((l) => l.isNormal()).map((l) => l.id)
|
||||
const knownHidden: Store<string[]> = UserRelatedState.initDiscoveredHiddenThemes(
|
||||
state.osmConnection
|
||||
|
|
@ -97,8 +104,11 @@ export class ThemeSearchIndex {
|
|||
const otherThemes: MinimalThemeInformation[] = ThemeSearch.officialThemes.themes.filter(
|
||||
(th) => th.id !== state.theme.id
|
||||
)
|
||||
return Locale.language.map(language => {
|
||||
const themes = otherThemes.concat(...knownHidden.data.map(id => ThemeSearch.officialThemesById.get(id)))
|
||||
return Locale.language.map(
|
||||
(language) => {
|
||||
const themes = otherThemes.concat(
|
||||
...knownHidden.data.map((id) => ThemeSearch.officialThemesById.get(id))
|
||||
)
|
||||
return new ThemeSearchIndex(language, themes, layersToIgnore)
|
||||
},
|
||||
[knownHidden]
|
||||
|
|
@ -116,9 +126,8 @@ export default class ThemeSearch {
|
|||
MinimalThemeInformation
|
||||
>()
|
||||
|
||||
|
||||
/*
|
||||
* For every layer id, states which themes use the layer
|
||||
* For every layer id, states which themes use the layer
|
||||
*/
|
||||
public static readonly layersToThemes: Map<string, MinimalThemeInformation[]> = new Map()
|
||||
static {
|
||||
|
|
@ -170,6 +179,4 @@ export default class ThemeSearch {
|
|||
|
||||
return `${linkPrefix}`
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,10 @@ export default class SearchState {
|
|||
)
|
||||
|
||||
const themeSearch = ThemeSearchIndex.fromState(state)
|
||||
this.themeSuggestions = this.searchTerm.mapD((query) => themeSearch.data.search(query, 3), [themeSearch])
|
||||
this.themeSuggestions = this.searchTerm.mapD(
|
||||
(query) => themeSearch.data.search(query, 3),
|
||||
[themeSearch]
|
||||
)
|
||||
|
||||
const layerSearch = new LayerSearch(state.theme)
|
||||
this.layerSuggestions = this.searchTerm.mapD((query) => layerSearch.search(query, 5))
|
||||
|
|
|
|||
|
|
@ -1,14 +1,42 @@
|
|||
import { Utils } from "../../Utils"
|
||||
/** This code is autogenerated - do not edit. Edit ./assets/layers/usersettings/usersettings.json instead */
|
||||
export class ThemeMetaTagging {
|
||||
public static readonly themeName = "usersettings"
|
||||
public static readonly themeName = "usersettings"
|
||||
|
||||
public metaTaggging_for_usersettings(feat: {properties: Record<string, string>}) {
|
||||
Utils.AddLazyProperty(feat.properties, '_mastodon_candidate_md', () => feat.properties._description.match(/\[[^\]]*\]\((.*(mastodon|en.osm.town).*)\).*/)?.at(1) )
|
||||
Utils.AddLazyProperty(feat.properties, '_d', () => feat.properties._description?.replace(/</g,'<')?.replace(/>/g,'>') ?? '' )
|
||||
Utils.AddLazyProperty(feat.properties, '_mastodon_candidate_a', () => (feat => {const e = document.createElement('div');e.innerHTML = feat.properties._d;return Array.from(e.getElementsByTagName("a")).filter(a => a.href.match(/mastodon|en.osm.town/) !== null)[0]?.href }) (feat) )
|
||||
Utils.AddLazyProperty(feat.properties, '_mastodon_link', () => (feat => {const e = document.createElement('div');e.innerHTML = feat.properties._d;return Array.from(e.getElementsByTagName("a")).filter(a => a.getAttribute("rel")?.indexOf('me') >= 0)[0]?.href})(feat) )
|
||||
Utils.AddLazyProperty(feat.properties, '_mastodon_candidate', () => feat.properties._mastodon_candidate_md ?? feat.properties._mastodon_candidate_a )
|
||||
feat.properties['__current_backgroun'] = 'initial_value'
|
||||
}
|
||||
}
|
||||
public metaTaggging_for_usersettings(feat: { properties: Record<string, string> }) {
|
||||
Utils.AddLazyProperty(feat.properties, "_mastodon_candidate_md", () =>
|
||||
feat.properties._description
|
||||
.match(/\[[^\]]*\]\((.*(mastodon|en.osm.town).*)\).*/)
|
||||
?.at(1)
|
||||
)
|
||||
Utils.AddLazyProperty(
|
||||
feat.properties,
|
||||
"_d",
|
||||
() => feat.properties._description?.replace(/</g, "<")?.replace(/>/g, ">") ?? ""
|
||||
)
|
||||
Utils.AddLazyProperty(feat.properties, "_mastodon_candidate_a", () =>
|
||||
((feat) => {
|
||||
const e = document.createElement("div")
|
||||
e.innerHTML = feat.properties._d
|
||||
return Array.from(e.getElementsByTagName("a")).filter(
|
||||
(a) => a.href.match(/mastodon|en.osm.town/) !== null
|
||||
)[0]?.href
|
||||
})(feat)
|
||||
)
|
||||
Utils.AddLazyProperty(feat.properties, "_mastodon_link", () =>
|
||||
((feat) => {
|
||||
const e = document.createElement("div")
|
||||
e.innerHTML = feat.properties._d
|
||||
return Array.from(e.getElementsByTagName("a")).filter(
|
||||
(a) => a.getAttribute("rel")?.indexOf("me") >= 0
|
||||
)[0]?.href
|
||||
})(feat)
|
||||
)
|
||||
Utils.AddLazyProperty(
|
||||
feat.properties,
|
||||
"_mastodon_candidate",
|
||||
() => feat.properties._mastodon_candidate_md ?? feat.properties._mastodon_candidate_a
|
||||
)
|
||||
feat.properties["__current_backgroun"] = "initial_value"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,10 @@ export default class SubstitutingTag extends TagsFilter {
|
|||
|
||||
asChange(properties: Readonly<Record<string, string>>): { k: string; v: string }[] {
|
||||
if (this._invert) {
|
||||
throw "An inverted substituting tag can not be used to create a change. The offending tag is " + this.asHumanString()
|
||||
throw (
|
||||
"An inverted substituting tag can not be used to create a change. The offending tag is " +
|
||||
this.asHumanString()
|
||||
)
|
||||
}
|
||||
const v = SubstitutingTag.substituteString(this._value, properties)
|
||||
if (v.match(/{.*}/) !== null) {
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ export class AndroidPolyfill {
|
|||
AndroidPolyfill.backfillGeolocation(AndroidPolyfill.databridgePlugin)
|
||||
}
|
||||
|
||||
public static async openLoginPage(){
|
||||
public static async openLoginPage() {
|
||||
await DatabridgePluginSingleton.request<{ oauth_token: string }>({ key: "open:login" })
|
||||
}
|
||||
public static async requestLoginCodes() {
|
||||
|
|
|
|||
|
|
@ -117,12 +117,12 @@ export class MangroveIdentity {
|
|||
return []
|
||||
}
|
||||
const allReviews = await MangroveReviews.getReviews({
|
||||
kid: pem
|
||||
kid: pem,
|
||||
})
|
||||
this.allReviewsById.setData(
|
||||
allReviews.reviews.map((r) => ({
|
||||
...r,
|
||||
...r.payload
|
||||
...r.payload,
|
||||
}))
|
||||
)
|
||||
})
|
||||
|
|
@ -283,7 +283,9 @@ export default class FeatureReviews {
|
|||
return cached
|
||||
}
|
||||
const themeIsSensitive = state.theme?.enableMorePrivacy
|
||||
const settings = state.osmConnection.getPreference<"always" | "yes" | "ask" | "hidden">("reviews-allowed")
|
||||
const settings = state.osmConnection.getPreference<"always" | "yes" | "ask" | "hidden">(
|
||||
"reviews-allowed"
|
||||
)
|
||||
const loadingAllowed = new UIEventSource(false)
|
||||
settings.addCallbackAndRun((s) => {
|
||||
console.log("Reviews allowed is", s)
|
||||
|
|
@ -329,7 +331,7 @@ export default class FeatureReviews {
|
|||
}
|
||||
const r: Review = {
|
||||
sub: this.subjectUri.data,
|
||||
...review
|
||||
...review,
|
||||
}
|
||||
const keypair: CryptoKeyPair = await this._identity.getKeypair()
|
||||
const jwt = await MangroveReviews.signReview(keypair, r)
|
||||
|
|
@ -344,7 +346,7 @@ export default class FeatureReviews {
|
|||
...r,
|
||||
kid,
|
||||
signature: jwt,
|
||||
madeByLoggedInUser: new ImmutableStore(true)
|
||||
madeByLoggedInUser: new ImmutableStore(true),
|
||||
}
|
||||
this._reviews.data.push(reviewWithKid)
|
||||
this._reviews.ping()
|
||||
|
|
@ -402,7 +404,7 @@ export default class FeatureReviews {
|
|||
signature: reviewData.signature,
|
||||
madeByLoggedInUser: this._identity.getKeyId().map((user_key_id) => {
|
||||
return reviewData.kid === user_key_id
|
||||
})
|
||||
}),
|
||||
})
|
||||
hasNew = true
|
||||
}
|
||||
|
|
@ -428,8 +430,8 @@ export default class FeatureReviews {
|
|||
} else if (this._uncertainty > 1000) {
|
||||
console.error(
|
||||
"Not fetching reviews. Only got a point and a very big uncertainty range (" +
|
||||
this._uncertainty +
|
||||
"), so you'd probably only get garbage. Specify a name"
|
||||
this._uncertainty +
|
||||
"), so you'd probably only get garbage. Specify a name"
|
||||
)
|
||||
return undefined
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue