forked from MapComplete/MapComplete
feature(usersettings): Add option to show all questions at once
This commit is contained in:
parent
7bd3fcd490
commit
60f3499eb0
10 changed files with 72 additions and 26 deletions
|
@ -161,9 +161,12 @@ export class OsmConnection {
|
|||
public GetPreference(
|
||||
key: string,
|
||||
defaultValue: string = undefined,
|
||||
prefix: string = "mapcomplete-"
|
||||
options?: {
|
||||
documentation?: string
|
||||
prefix?: string
|
||||
}
|
||||
): UIEventSource<string> {
|
||||
return this.preferencesHandler.GetPreference(key, defaultValue, prefix)
|
||||
return this.preferencesHandler.GetPreference(key, defaultValue, options)
|
||||
}
|
||||
|
||||
public GetLongPreference(key: string, prefix: string = "mapcomplete-"): UIEventSource<string> {
|
||||
|
|
|
@ -33,8 +33,9 @@ export class OsmPreferences {
|
|||
this.longPreferences[prefix + key] = source
|
||||
|
||||
const allStartWith = prefix + key + "-combined"
|
||||
const subOptions = { prefix: "" }
|
||||
// Gives the number of combined preferences
|
||||
const length = this.GetPreference(allStartWith + "-length", "", "")
|
||||
const length = this.GetPreference(allStartWith + "-length", "", subOptions)
|
||||
|
||||
if ((allStartWith + "-length").length > 255) {
|
||||
throw (
|
||||
|
@ -56,9 +57,9 @@ export class OsmPreferences {
|
|||
let count = parseInt(length.data)
|
||||
for (let i = 0; i < count; i++) {
|
||||
// Delete all the preferences
|
||||
self.GetPreference(allStartWith + "-" + i, "", "").setData("")
|
||||
self.GetPreference(allStartWith + "-" + i, "", subOptions).setData("")
|
||||
}
|
||||
self.GetPreference(allStartWith + "-length", "", "").setData("")
|
||||
self.GetPreference(allStartWith + "-length", "", subOptions).setData("")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -70,7 +71,9 @@ export class OsmPreferences {
|
|||
if (i > 100) {
|
||||
throw "This long preference is getting very long... "
|
||||
}
|
||||
self.GetPreference(allStartWith + "-" + i, "", "").setData(str.substr(0, 255))
|
||||
self.GetPreference(allStartWith + "-" + i, "", subOptions).setData(
|
||||
str.substr(0, 255)
|
||||
)
|
||||
str = str.substr(255)
|
||||
i++
|
||||
}
|
||||
|
@ -116,8 +119,12 @@ export class OsmPreferences {
|
|||
public GetPreference(
|
||||
key: string,
|
||||
defaultValue: string = undefined,
|
||||
prefix: string = "mapcomplete-"
|
||||
options?: {
|
||||
documentation?: string
|
||||
prefix?: string
|
||||
}
|
||||
): UIEventSource<string> {
|
||||
const prefix: string = options?.prefix ?? "mapcomplete-"
|
||||
if (key.startsWith(prefix) && prefix !== "") {
|
||||
console.trace(
|
||||
"A preference was requested which has a duplicate prefix in its key. This is probably a bug"
|
||||
|
@ -173,7 +180,7 @@ export class OsmPreferences {
|
|||
const matches = prefixes.some((prefix) => key.startsWith(prefix))
|
||||
if (matches) {
|
||||
console.log("Clearing ", key)
|
||||
self.GetPreference(key, "", "").setData("")
|
||||
self.GetPreference(key, "", { prefix: "" }).setData("")
|
||||
}
|
||||
}
|
||||
isRunning = false
|
||||
|
|
|
@ -34,10 +34,10 @@ export default class UserRelatedState extends ElementsState {
|
|||
*/
|
||||
public maprouletteConnection: Maproulette
|
||||
|
||||
public readonly isTranslator: Store<boolean>
|
||||
|
||||
public readonly installedUserThemes: Store<string[]>
|
||||
|
||||
public readonly showAllQuestionsAtOnce: UIEventSource<boolean>
|
||||
|
||||
constructor(layoutToUse: LayoutConfig, options?: { attemptLogin: true | boolean }) {
|
||||
super(layoutToUse)
|
||||
|
||||
|
@ -73,7 +73,12 @@ export default class UserRelatedState extends ElementsState {
|
|||
}
|
||||
|
||||
this.changes = new Changes(this, layoutToUse?.isLeftRightSensitive() ?? false)
|
||||
|
||||
this.showAllQuestionsAtOnce = UIEventSource.asBoolean(
|
||||
this.osmConnection.GetPreference("show-all-questions", "false", {
|
||||
documentation:
|
||||
"Either 'true' or 'false'. If set, all questions will be shown all at once",
|
||||
})
|
||||
)
|
||||
new ChangeToElementsActor(this.changes, this.allElements)
|
||||
new PendingChangesUploader(this.changes, this.selectedElement)
|
||||
|
||||
|
|
|
@ -754,4 +754,12 @@ export class UIEventSource<T> extends Store<T> {
|
|||
}
|
||||
return this
|
||||
}
|
||||
|
||||
static asBoolean(stringUIEventSource: UIEventSource<string>) {
|
||||
return stringUIEventSource.sync(
|
||||
(str) => str === "true",
|
||||
[],
|
||||
(b) => "" + b
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,10 +40,8 @@ export class QueryParameters {
|
|||
deflt: boolean,
|
||||
documentation?: string
|
||||
): UIEventSource<boolean> {
|
||||
return QueryParameters.GetQueryParameter(key, "" + deflt, documentation).sync(
|
||||
(str) => str === "true",
|
||||
[],
|
||||
(b) => "" + b
|
||||
return UIEventSource.asBoolean(
|
||||
QueryParameters.GetQueryParameter(key, "" + deflt, documentation)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { Utils } from "../Utils"
|
||||
|
||||
export default class Constants {
|
||||
public static vNumber = "0.26.2"
|
||||
public static vNumber = "0.26.3"
|
||||
|
||||
public static ImgurApiKey = "7070e7167f0a25a"
|
||||
public static readonly mapillary_client_token_v4 =
|
||||
|
|
|
@ -74,7 +74,7 @@ class SingleUserSettingsPanel extends EditableTagRendering {
|
|||
if (kv.k.startsWith("_")) {
|
||||
continue
|
||||
}
|
||||
osmConnection.GetPreference(kv.k, "", "").setData(kv.v)
|
||||
osmConnection.GetPreference(kv.k, "", {prefix: ""}).setData(kv.v)
|
||||
}
|
||||
|
||||
editMode.setData(false)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { UIEventSource } from "../../Logic/UIEventSource"
|
||||
import { Store, UIEventSource } from "../../Logic/UIEventSource"
|
||||
import EditableTagRendering from "./EditableTagRendering"
|
||||
import QuestionBox from "./QuestionBox"
|
||||
import Combine from "../Base/Combine"
|
||||
|
@ -35,9 +35,13 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
|
|||
if (state === undefined) {
|
||||
throw "State is undefined!"
|
||||
}
|
||||
const showAllQuestions = state.featureSwitchShowAllQuestions.map(
|
||||
(fsShow) => fsShow || state.showAllQuestionsAtOnce.data,
|
||||
[state.showAllQuestionsAtOnce]
|
||||
)
|
||||
super(
|
||||
() => FeatureInfoBox.GenerateTitleBar(tags, layerConfig, state),
|
||||
() => FeatureInfoBox.GenerateContent(tags, layerConfig, state),
|
||||
() => FeatureInfoBox.GenerateContent(tags, layerConfig, state, showAllQuestions),
|
||||
options?.hashToShow ?? tags.data.id ?? "item",
|
||||
options?.isShown,
|
||||
options
|
||||
|
@ -79,21 +83,23 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
|
|||
public static GenerateContent(
|
||||
tags: UIEventSource<any>,
|
||||
layerConfig: LayerConfig,
|
||||
state: FeaturePipelineState
|
||||
state: FeaturePipelineState,
|
||||
showAllQuestions?: Store<boolean>
|
||||
): BaseUIElement {
|
||||
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"),
|
||||
FeatureInfoBox.GenerateMainContent(tags, layerConfig, state),
|
||||
FeatureInfoBox.GenerateMainContent(tags, layerConfig, state, showAllQuestions),
|
||||
tags.map((t) => t["_deleted"] == "yes")
|
||||
)
|
||||
}
|
||||
private static GenerateMainContent(
|
||||
tags: UIEventSource<any>,
|
||||
layerConfig: LayerConfig,
|
||||
state: FeaturePipelineState
|
||||
state: FeaturePipelineState,
|
||||
showAllQuestions?: Store<boolean>
|
||||
): BaseUIElement {
|
||||
let questionBoxes: Map<string, QuestionBox> = new Map<string, QuestionBox>()
|
||||
const t = Translations.t.general
|
||||
|
@ -108,8 +114,7 @@ export default class FeatureInfoBox extends ScrollableFullScreen {
|
|||
tagRenderings: questions,
|
||||
units: layerConfig.units,
|
||||
showAllQuestionsAtOnce:
|
||||
questionSpec?.freeform?.helperArgs["showAllQuestions"] ??
|
||||
state.featureSwitchShowAllQuestions,
|
||||
questionSpec?.freeform?.helperArgs["showAllQuestions"] ?? showAllQuestions,
|
||||
})
|
||||
questionBoxes.set(groupName, questionBox)
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ export default class QuestionBox extends VariableUiElement {
|
|||
tagsSource: UIEventSource<any>
|
||||
tagRenderings: TagRenderingConfig[]
|
||||
units: Unit[]
|
||||
showAllQuestionsAtOnce?: boolean | UIEventSource<boolean>
|
||||
showAllQuestionsAtOnce?: boolean | Store<boolean>
|
||||
}
|
||||
) {
|
||||
const skippedQuestions: UIEventSource<number[]> = new UIEventSource<number[]>([])
|
||||
|
|
|
@ -67,6 +67,26 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "all-questions-at-once",
|
||||
"question": {
|
||||
"en": "Should questions for unknown data fields appear one-by-one or together?"
|
||||
},
|
||||
"mappings": [
|
||||
{
|
||||
"if": "mapcomplete-show-all-questions=true",
|
||||
"then": {
|
||||
"en": "Show all questions in the infobox together"
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": "mapcomplete-show-all-questions=false",
|
||||
"then": {
|
||||
"en": "Show questions one-by-one"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "translations-title",
|
||||
"group": "translations",
|
||||
|
|
Loading…
Reference in a new issue