forked from MapComplete/MapComplete
Feature: add user preference to remember disabling/enabling layers; see #2442
This commit is contained in:
parent
721e8e89c3
commit
87583586d5
3 changed files with 62 additions and 42 deletions
|
@ -607,6 +607,51 @@
|
|||
],
|
||||
"metacondition": "_uid~*"
|
||||
},
|
||||
{
|
||||
"id": "override_layer_sync_selection",
|
||||
"#": "Overrides 'layer.syncSelection",
|
||||
"question": {
|
||||
"en": "When disabling/enabling a layer in the filter menu, should this be remembered between visits?"
|
||||
},
|
||||
"questionHint": {
|
||||
"en": "This setting will only take effect after reloading"
|
||||
},
|
||||
"mappings": [
|
||||
{
|
||||
"if": "mapcomplete-layer-override-sync-selection=default",
|
||||
"alsoShowIf": "mapcomplete-layer-override-sync-selection=",
|
||||
"then": {
|
||||
"en": "Don't remember layer settings (for most layers)"
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": "mapcomplete-layer-override-sync-selection=no",
|
||||
"then": {
|
||||
"en": "Never remember whether a layer is enabled, always use the default value to show/hide the layer"
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": "mapcomplete-layer-override-sync-selection=local",
|
||||
"then": {
|
||||
"en": "Remember whether a layer is enabled in between visits on the device"
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": "mapcomplete-layer-override-sync-selection=theme-only",
|
||||
"then": {
|
||||
"en": "Remember whether a layer is enabled in {_theme} in between visits and across devices"
|
||||
},
|
||||
"hideInAnswer": "_loggedIn=false"
|
||||
},
|
||||
{
|
||||
"if": "mapcomplete-layer-override-sync-selection=global",
|
||||
"then": {
|
||||
"en": "Remember whether a layer is enabled in all themes between visits and across devices"
|
||||
},
|
||||
"hideInAnswer": "_loggedIn=false"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "show_crosshair",
|
||||
"question": {
|
||||
|
|
|
@ -4,39 +4,11 @@ export class ThemeMetaTagging {
|
|||
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"
|
||||
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'
|
||||
}
|
||||
}
|
|
@ -74,7 +74,6 @@ export default class FilteredLayer {
|
|||
public static queryParameterKey(layer: LayerConfig) {
|
||||
return "layer-" + layer.id
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a FilteredLayer which is tied into the QueryParameters and/or user preferences
|
||||
*/
|
||||
|
@ -85,18 +84,22 @@ export default class FilteredLayer {
|
|||
enabledByDefault?: Store<boolean>
|
||||
) {
|
||||
let isDisplayed: UIEventSource<boolean>
|
||||
if (layer.syncSelection === "local") {
|
||||
let syncSelection: string = layer.syncSelection
|
||||
const userpreference: "default" | "no" | "local" | "theme-only" | "global" | string = osmConnection.getPreference("layer-override-sync-selection").data
|
||||
console.log("Userpreference is", userpreference)
|
||||
syncSelection = userpreference ?? syncSelection
|
||||
if (syncSelection === "local") {
|
||||
isDisplayed = LocalStorageSource.getParsed(
|
||||
context + "-layer-" + layer.id + "-enabled",
|
||||
layer.shownByDefault
|
||||
)
|
||||
} else if (layer.syncSelection === "theme-only" && osmConnection) {
|
||||
} else if (syncSelection === "theme-only" && osmConnection) {
|
||||
isDisplayed = FilteredLayer.getPref(
|
||||
osmConnection,
|
||||
context + "-layer-" + layer.id + "-enabled",
|
||||
layer
|
||||
)
|
||||
} else if (layer.syncSelection === "global" && osmConnection) {
|
||||
} else if (syncSelection === "global" && osmConnection) {
|
||||
isDisplayed = FilteredLayer.getPref(
|
||||
osmConnection,
|
||||
"layer-" + layer.id + "-enabled",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue