Move 'usersettings' into separate pseudolayer

This commit is contained in:
Pieter Vander Vennet 2023-01-12 01:17:07 +01:00
parent e1cdb75001
commit ee575a9c42
5 changed files with 110 additions and 160 deletions

View file

@ -19,11 +19,9 @@ import EditableTagRendering from "../Popup/EditableTagRendering"
import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig" import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig"
import { SaveButton } from "../Popup/SaveButton" import { SaveButton } from "../Popup/SaveButton"
import { TagUtils } from "../../Logic/Tags/TagUtils" import { TagUtils } from "../../Logic/Tags/TagUtils"
import * as questions from "../../assets/tagRenderings/questions.json" import * as usersettings from "../../assets/generated/layers/usersettings.json"
import { TagRenderingConfigJson } from "../../Models/ThemeConfig/Json/TagRenderingConfigJson"
import * as os from "os"
import { LoginToggle } from "../Popup/LoginButton" import { LoginToggle } from "../Popup/LoginButton"
import { userInfo } from "os" import LayerConfig from "../../Models/ThemeConfig/LayerConfig"
export class ImportViewerLinks extends VariableUiElement { export class ImportViewerLinks extends VariableUiElement {
constructor(osmConnection: OsmConnection) { constructor(osmConnection: OsmConnection) {
@ -45,6 +43,36 @@ export class ImportViewerLinks extends VariableUiElement {
} }
} }
class SingleUserSettingsPanel extends EditableTagRendering {
constructor(config: TagRenderingConfig, osmConnection: OsmConnection) {
const editMode = new UIEventSource(false)
super(
osmConnection.preferencesHandler.preferences,
config,
[],
{ osmConnection },
{
editMode,
createSaveButton: (store) =>
new SaveButton(
osmConnection.preferencesHandler.preferences,
osmConnection
).onClick(() => {
const prefs = osmConnection.preferencesHandler.preferences
const selection = TagUtils.FlattenMultiAnswer(
TagUtils.FlattenAnd(store.data, prefs.data)
).asChange(prefs.data)
for (const kv of selection) {
osmConnection.GetPreference(kv.k, "", "").setData(kv.v)
}
editMode.setData(false)
}),
}
)
}
}
class UserInformationMainPanel extends VariableUiElement { class UserInformationMainPanel extends VariableUiElement {
constructor( constructor(
osmConnection: OsmConnection, osmConnection: OsmConnection,
@ -78,7 +106,6 @@ class UserInformationMainPanel extends VariableUiElement {
.makeHtml(ud.description) .makeHtml(ud.description)
.replace(/>/g, ">") .replace(/>/g, ">")
.replace(/&lt;/g, "<") .replace(/&lt;/g, "<")
console.log("Before:", ud.description, "after", htmlString)
description = new Combine([ description = new Combine([
new FixedUiElement(htmlString).SetClass("link-underline"), new FixedUiElement(htmlString).SetClass("link-underline"),
editButton, editButton,
@ -108,36 +135,10 @@ class UserInformationMainPanel extends VariableUiElement {
}) })
} }
const editMode = new UIEventSource(false) const usersettingsConfig = new LayerConfig(usersettings, "userinformationpanel")
const licensePicker = new EditableTagRendering(
osmConnection.preferencesHandler.preferences,
new TagRenderingConfig(
<TagRenderingConfigJson>{
source: "shared-questions",
...questions["picture-license"],
},
"shared-questions"
),
[],
{ osmConnection },
{
editMode,
createSaveButton: (store) =>
new SaveButton(
osmConnection.preferencesHandler.preferences,
osmConnection
).onClick(() => {
const prefs = osmConnection.preferencesHandler.preferences
const selection = TagUtils.FlattenMultiAnswer(
TagUtils.FlattenAnd(store.data, prefs.data)
).asChange(prefs.data)
for (const kv of selection) {
osmConnection.GetPreference(kv.k, "", "").setData(kv.v)
}
editMode.setData(false) const questions = usersettingsConfig.tagRenderings.map((c) =>
}), new SingleUserSettingsPanel(c, osmConnection).SetClass("block my-4")
}
) )
return new Combine([ return new Combine([
@ -146,7 +147,7 @@ class UserInformationMainPanel extends VariableUiElement {
layout.language, layout.language,
Translations.t.general.pickLanguage.Clone() Translations.t.general.pickLanguage.Clone()
), ),
licensePicker.SetClass("block my-4"), ...questions,
new SubtleButton( new SubtleButton(
Svg.envelope_svg(), Svg.envelope_svg(),
new Combine([ new Combine([

View file

@ -9,9 +9,8 @@ import TagRenderingConfig from "../../Models/ThemeConfig/TagRenderingConfig"
import { Unit } from "../../Models/Unit" import { Unit } from "../../Models/Unit"
import Lazy from "../Base/Lazy" import Lazy from "../Base/Lazy"
import { FixedUiElement } from "../Base/FixedUiElement" import { FixedUiElement } from "../Base/FixedUiElement"
import { EditButton, SaveButton } from "./SaveButton" import { EditButton } from "./SaveButton"
import { TagsFilter } from "../../Logic/Tags/TagsFilter" import { UploadableTag } from "../../Logic/Tags/TagUtils"
import { TagUtils, UploadableTag } from "../../Logic/Tags/TagUtils"
export default class EditableTagRendering extends Toggle { export default class EditableTagRendering extends Toggle {
constructor( constructor(

View file

@ -0,0 +1,47 @@
{
"id": "usersettings",
"description": {
"en": "A special layer which is not meant to be shown on a map, but which is used to set user settings"
},
"title": null,
"source": {
"osmTags": "id~*"
},
"tagRenderings": [
{
"id": "picture-license",
"description": "This question is not meant to be placed on an OpenStreetMap-element; however it is used in the user information panel to ask which license the user wants",
"question": {
"en": "Under what license do you want to publish your pictures?"
},
"mappings": [
{
"if": "mapcomplete-pictures-license=",
"then": {
"en": "No license has been chosen yet"
},
"hideInAnswer": true
},
{
"if": "mapcomplete-pictures-license=CC0",
"then": {
"en": "Pictures you take will be licensed with CC0 and added to the public domain. This means that everyone can use your pictures for any purpose."
}
},
{
"if": "mapcomplete-pictures-license=CC-BY 4.0",
"then": {
"en": "Pictures you take will be licensed with CC-BY 4.0 which requires everyone using your picture that they have to attribute you"
}
},
{
"if": "mapcomplete-pictures-license=CC-BY-SA 4.0",
"then": {
"en": "Pictures you take will be licensed with CC-BY-SA 4.0 which means that everyone using your picture must attribute you and that derivatives of your picture must be reshared with the same license."
}
}
]
}
],
"mapRendering": null
}

View file

@ -1493,39 +1493,6 @@
} }
] ]
}, },
"picture-license": {
"description": "This question is not meant to be placed on an OpenStreetMap-element; however it is used in the user information panel to ask which license the user wants",
"question": {
"en": "Under what license do you want to publish your pictures?"
},
"mappings": [
{
"if": "mapcomplete-pictures-license=",
"then": {
"en": "No license has been chosen yet"
},
"hideInAnswer": true
},
{
"if": "mapcomplete-pictures-license=CC0",
"then": {
"en": "Pictures you take will be licensed with CC0 and added to the public domain. This means that everyone can use your pictures for any purpose."
}
},
{
"if": "mapcomplete-pictures-license=CC-BY 4.0",
"then": {
"en": "Pictures you take will be licensed with CC-BY 4.0 which requires everyone using your picture that they have to attribute you"
}
},
{
"if": "mapcomplete-pictures-license=CC-BY-SA 4.0",
"then": {
"en": "Pictures you take will be licensed with CC-BY-SA 4.0 which means that everyone using your picture must attribute you and that derivatives of your picture must be reshared with the same license."
}
}
]
},
"induction-loop": { "induction-loop": {
"description": "An accessibility feature: induction loops are for hard-hearing persons which have an FM-receiver.", "description": "An accessibility feature: induction loops are for hard-hearing persons which have an FM-receiver.",
"question": { "question": {

View file

@ -1,21 +1,13 @@
{ {
"id": "mapcomplete-changes", "id": "mapcomplete-changes",
"title": { "title": {
"en": "Changes made with MapComplete", "en": "Changes made with MapComplete"
"de": "Mit MapComplete vorgenommene Änderungen",
"nl": "Wijzigingen gemaakt met MapComplete"
}, },
"shortDescription": { "shortDescription": {
"en": "Shows changes made by MapComplete", "en": "Shows changes made by MapComplete"
"de": "Zeigt Änderungen, die von MapComplete vorgenommen wurden",
"nl": "Toont wijzigingen gemaakt met MapComplete"
}, },
"description": { "description": {
"en": "This map shows all the changes made with MapComplete", "en": "This maps shows all the changes made with MapComplete"
"ca": "Aquest mapa mostra tots els canvis fets amb MapComplete",
"de": "Diese Karte zeigt alle mit MapComplete vorgenommenen Änderungen",
"fr": "Cette carte montre tous les changements faits avec MapComplete",
"nl": "Deze kaart toont alle wijzigingen gemaakt met MapComplete"
}, },
"icon": "./assets/svg/logo.svg", "icon": "./assets/svg/logo.svg",
"hideFromOverview": true, "hideFromOverview": true,
@ -28,10 +20,7 @@
{ {
"id": "mapcomplete-changes", "id": "mapcomplete-changes",
"name": { "name": {
"en": "Changeset centers", "en": "Changeset centers"
"de": "Zentrum der Änderungssätze",
"fr": "Centres de modifications de paramètres",
"nl": "Middelpunt van de wijzigingenset"
}, },
"minzoom": 0, "minzoom": 0,
"source": { "source": {
@ -42,58 +31,41 @@
}, },
"title": { "title": {
"render": { "render": {
"en": "Changeset for {theme}", "en": "Changeset for {theme}"
"de": "Änderungssatz für {theme}",
"nl": "Changeset voor {theme}"
} }
}, },
"description": { "description": {
"en": "Shows all MapComplete changes", "en": "Shows all MapComplete changes"
"de": "Zeigt alle MapComplete-Änderungen",
"fr": "Montre tous les changements de MapComplete",
"nl": "Toon alle MapComplete wijzigingen"
}, },
"tagRenderings": [ "tagRenderings": [
{ {
"id": "show_changeset_id", "id": "show_changeset_id",
"render": { "render": {
"en": "Changeset <a href='https://openstreetmap.org/changeset/{id}' target='_blank'>{id}</a>", "en": "Changeset <a href='https://openstreetmap.org/changeset/{id}' target='_blank'>{id}</a>"
"de": "Änderungssatz <a href='https://openstreetmap.org/changeset/{id}' target='_blank'>{id}</a>",
"nl": "Wijzigingenset <a href='https://openstreetmap.org/changeset/{id}' target='_blank'>{id}</a>"
} }
}, },
{ {
"id": "contributor", "id": "contributor",
"question": { "question": {
"en": "What contributor did make this change?", "en": "What contributor did make this change?"
"de": "Welcher Mitwirkende hat diese Änderung vorgenommen?",
"fr": "Quel contributeur a fait ce changement ?",
"nl": "Welke bijdrager maakte deze wijziging?"
}, },
"freeform": { "freeform": {
"key": "user" "key": "user"
}, },
"render": { "render": {
"en": "Change made by <a href='https://openstreetmap.org/user/{user}' target='_blank'>{user}</a>", "en": "Change made by <a href='https://openstreetmap.org/user/{user}' target='_blank'>{user}</a>"
"de": "Änderung vorgenommen von <a href='https://openstreetmap.org/user/{user}' target='_blank'>{user}</a>",
"fr": "Modification faite par <a href='https://openstreetmap.org/user/{user}' target='_blank'>{user}</a>",
"nl": "Wijziging gemaakt door <a href='https://openstreetmap.org/user/{user}' target='_blank'>{user}</a>"
} }
}, },
{ {
"id": "theme-id", "id": "theme-id",
"question": { "question": {
"en": "What theme was used to make this change?", "en": "What theme was used to make this change?"
"de": "Welches Thema wurde für diese Änderung verwendet?",
"nl": "Welk thema is gebruikt voor deze wijziging?"
}, },
"freeform": { "freeform": {
"key": "theme" "key": "theme"
}, },
"render": { "render": {
"en": "Change with theme <a href='https://mapcomplete.osm.be/{theme}'>{theme}</a>", "en": "Change with theme <a href='https://mapcomplete.osm.be/{theme}'>{theme}</a>"
"de": "Geändert mit Thema <a href='https://mapcomplete.osm.be/{theme}'>{theme}</a>",
"nl": "Wijziging met thema <a href='https://mapcomplete.osm.be/{theme}'>{theme}</a>"
} }
}, },
{ {
@ -102,32 +74,19 @@
"key": "locale" "key": "locale"
}, },
"question": { "question": {
"en": "What locale (language) was this change made in?", "en": "What locale (language) was this change made in?"
"de": "In welchem Gebietsschema (Sprache) wurde diese Änderung vorgenommen?",
"fr": "En quelle langue est-ce que ce changement a été fait ?",
"nl": "In welke taal (en cultuur) werd deze wijziging gemaakt?"
}, },
"render": { "render": {
"en": "User locale is {locale}", "en": "User locale is {locale}"
"de": "Benutzergebietsschema ist {locale}",
"fr": "La langue de l'utilisateur est {locale}",
"nl": "De locale van de bijdrager is {locale}"
} }
}, },
{ {
"id": "host", "id": "host",
"render": { "render": {
"en": "Change with <a href='{host}'>{host}</a>", "en": "Change with with <a href='{host}'>{host}</a>"
"ca": "Canvi amb <a href='{host}'>{host}</a>",
"de": "Geändert über <a href='{host}'>{host}</a>",
"fr": "Changement avec <a href='{host}'>{host}</a>",
"nl": "Wijziging met <a href='{host}'>{host}</a>"
}, },
"question": { "question": {
"en": "What host (website) was this change made with?", "en": "What host (website) was this change made with?"
"de": "Über welchen Host (Webseite) wurde diese Änderung vorgenommen?",
"fr": "Depuis quel serveur (site web) ce changement a-t-il été fait ?",
"nl": "Op welk webadres werd deze wijziging gemaakt?"
}, },
"freeform": { "freeform": {
"key": "host" "key": "host"
@ -468,10 +427,7 @@
} }
], ],
"question": { "question": {
"en": "Themename contains {search}", "en": "Themename contains {search}"
"de": "Themename enthält {search}",
"fr": "Nom de thème contenant {search}",
"nl": "Themanaam bevat {search}"
} }
} }
] ]
@ -487,10 +443,7 @@
} }
], ],
"question": { "question": {
"en": "Made by contributor {search}", "en": "Made by contributor {search}"
"de": "Erstellt vom Mitwirkenden {search}",
"fr": "Fait par le contributeur {search}",
"nl": "Gemaakt door {search}"
} }
} }
] ]
@ -506,10 +459,7 @@
} }
], ],
"question": { "question": {
"en": "<b>Not</b> made by contributor {search}", "en": "<b>Not</b> made by contributor {search}"
"de": "<b>Nicht</b> von Mitwirkendem {search}",
"fr": "<b>Non</b> réalisé par le contributeur{search}",
"nl": "<b>Niet</b> gemaakt door {search}"
} }
} }
] ]
@ -526,10 +476,7 @@
} }
], ],
"question": { "question": {
"en": "Made before {search}", "en": "Made before {search}"
"de": "Erstellt vor {search}",
"fr": "Fait avant {search}",
"nl": "Gemaakt voor {search}"
} }
} }
] ]
@ -546,10 +493,7 @@
} }
], ],
"question": { "question": {
"en": "Made after {search}", "en": "Made after {search}"
"de": "Erstellt nach {search}",
"fr": "Fait après {search}",
"nl": "Gemaakt na {search}"
} }
} }
] ]
@ -565,10 +509,7 @@
} }
], ],
"question": { "question": {
"en": "User language (iso-code) {search}", "en": "User language (iso-code) {search}"
"de": "Benutzersprache (ISO-Code) {search}",
"fr": "Langage utilisateur (code-iso) {search}",
"nl": "Gebruikerstaal (iso-code) {search}"
} }
} }
] ]
@ -584,10 +525,7 @@
} }
], ],
"question": { "question": {
"en": "Made with host {search}", "en": "Made with host {search}"
"de": "Erstellt mit host {search}",
"fr": "Fait par le serveur {search}",
"nl": "Gemaakt met host {search}"
} }
} }
] ]
@ -613,9 +551,7 @@
{ {
"id": "link_to_more", "id": "link_to_more",
"render": { "render": {
"en": "More statistics can be found <a href='https://github.com/pietervdvn/MapComplete/tree/develop/Docs/Tools/graphs' target='_blank'>here</a>", "en": "More statistics can be found <a href='https://github.com/pietervdvn/MapComplete/tree/develop/Docs/Tools/graphs' target='_blank'>here</a>"
"de": "Weitere Statistiken <a href='https://github.com/pietervdvn/MapComplete/tree/develop/Docs/Tools/graphs' target='_blank'>hier</a>",
"nl": "Meer statistieken zijn <a href='https://github.com/pietervdvn/MapComplete/tree/develop/Docs/Tools/graphs' target='_blank'>hier</a> te vinden"
} }
}, },
{ {