2021-10-15 05:20:02 +02:00
/ * *
* The part of the global state which initializes the feature switches , based on default values and on the layoutToUse
* /
import LayoutConfig from "../../Models/ThemeConfig/LayoutConfig"
2023-05-25 20:09:42 +02:00
import { UIEventSource } from "../UIEventSource"
import { QueryParameters } from "../Web/QueryParameters"
2021-10-15 05:20:02 +02:00
import Constants from "../../Models/Constants"
2023-05-25 20:09:42 +02:00
import { Utils } from "../../Utils"
2021-10-15 05:20:02 +02:00
2023-05-25 20:09:42 +02:00
class FeatureSwitchUtils {
static initSwitch (
key : string ,
deflt :boolean ,
documentation : string
) : UIEventSource < boolean > {
const defaultValue = deflt
const queryParam = QueryParameters . GetQueryParameter (
key ,
"" + defaultValue ,
documentation
)
// It takes the current layout, extracts the default value for this query parameter. A query parameter event source is then retrieved and flattened
return queryParam . sync (
( str ) = > ( str === undefined ? defaultValue : str !== "false" ) ,
[ ] ,
( b ) = > ( b == defaultValue ? undefined : "" + b )
)
}
}
export class OsmConnectionFeatureSwitches {
public readonly featureSwitchFakeUser : UIEventSource < boolean >
public readonly featureSwitchApiURL : UIEventSource < string >
constructor ( ) {
this . featureSwitchApiURL = QueryParameters . GetQueryParameter (
"backend" ,
"osm" ,
"The OSM backend to use - can be used to redirect mapcomplete to the testing backend when using 'osm-test'"
)
this . featureSwitchFakeUser = QueryParameters . GetBooleanQueryParameter (
"fake-user" ,
false ,
"If true, 'dryrun' mode is activated and a fake user account is loaded"
)
}
}
export default class FeatureSwitchState extends OsmConnectionFeatureSwitches {
2021-10-15 05:20:02 +02:00
/ * *
* The layout that is being used in this run
* /
public readonly layoutToUse : LayoutConfig
2022-09-08 21:40:48 +02:00
2021-10-15 05:20:02 +02:00
public readonly featureSwitchUserbadge : UIEventSource < boolean >
public readonly featureSwitchSearch : UIEventSource < boolean >
2021-12-04 12:20:24 +01:00
public readonly featureSwitchBackgroundSelection : UIEventSource < boolean >
2021-10-15 05:20:02 +02:00
public readonly featureSwitchAddNew : UIEventSource < boolean >
public readonly featureSwitchWelcomeMessage : UIEventSource < boolean >
2023-02-02 17:57:07 +01:00
public readonly featureSwitchCommunityIndex : UIEventSource < boolean >
2022-02-14 04:48:33 +01:00
public readonly featureSwitchExtraLinkEnabled : UIEventSource < boolean >
2021-10-15 05:20:02 +02:00
public readonly featureSwitchMoreQuests : UIEventSource < boolean >
public readonly featureSwitchShareScreen : UIEventSource < boolean >
public readonly featureSwitchGeolocation : UIEventSource < boolean >
public readonly featureSwitchIsTesting : UIEventSource < boolean >
public readonly featureSwitchIsDebugging : UIEventSource < boolean >
public readonly featureSwitchShowAllQuestions : UIEventSource < boolean >
public readonly featureSwitchFilter : UIEventSource < boolean >
public readonly featureSwitchEnableExport : UIEventSource < boolean >
public readonly overpassUrl : UIEventSource < string [ ] >
public readonly overpassTimeout : UIEventSource < number >
public readonly overpassMaxZoom : UIEventSource < number >
public readonly osmApiTileSize : UIEventSource < number >
public readonly backgroundLayerId : UIEventSource < string >
2023-05-25 20:09:42 +02:00
public constructor ( layoutToUse? : LayoutConfig ) {
super ( )
2021-10-15 05:20:02 +02:00
this . layoutToUse = layoutToUse
// Helper function to initialize feature switches
2023-05-25 20:09:42 +02:00
this . featureSwitchUserbadge = FeatureSwitchUtils . initSwitch (
2021-10-15 05:20:02 +02:00
"fs-userbadge" ,
2023-05-25 20:09:42 +02:00
layoutToUse ? . enableUserBadge ? ? true ,
2021-10-15 05:20:02 +02:00
"Disables/Enables the user information pill (userbadge) at the top left. Disabling this disables logging in and thus disables editing all together, effectively putting MapComplete into read-only mode."
)
2023-05-25 20:09:42 +02:00
this . featureSwitchSearch = FeatureSwitchUtils . initSwitch (
2021-10-15 05:20:02 +02:00
"fs-search" ,
2023-05-25 20:09:42 +02:00
layoutToUse ? . enableSearch ? ? true ,
2021-10-15 05:20:02 +02:00
"Disables/Enables the search bar"
)
2023-05-25 20:09:42 +02:00
this . featureSwitchBackgroundSelection = FeatureSwitchUtils . initSwitch (
2021-10-15 05:20:02 +02:00
"fs-background" ,
2023-05-25 20:09:42 +02:00
layoutToUse ? . enableBackgroundLayerSelection ? ? true ,
2021-10-15 05:20:02 +02:00
"Disables/Enables the background layer control"
)
2023-05-25 20:09:42 +02:00
this . featureSwitchFilter = FeatureSwitchUtils . initSwitch (
2021-10-15 05:20:02 +02:00
"fs-filter" ,
2023-05-25 20:09:42 +02:00
layoutToUse ? . enableLayers ? ? true ,
2022-02-14 04:48:33 +01:00
"Disables/Enables the filter view"
2021-10-15 05:20:02 +02:00
)
2023-05-25 20:09:42 +02:00
this . featureSwitchAddNew = FeatureSwitchUtils . initSwitch (
2021-10-15 05:20:02 +02:00
"fs-add-new" ,
2023-05-25 20:09:42 +02:00
layoutToUse ? . enableAddNewPoints ? ? true ,
2021-10-15 05:20:02 +02:00
"Disables/Enables the 'add new feature'-popup. (A theme without presets might not have it in the first place)"
)
2023-05-25 20:09:42 +02:00
this . featureSwitchWelcomeMessage = FeatureSwitchUtils . initSwitch (
2021-10-15 05:20:02 +02:00
"fs-welcome-message" ,
2023-05-25 20:09:42 +02:00
true ,
2021-10-15 05:20:02 +02:00
"Disables/enables the help menu or welcome message"
)
2023-05-25 20:09:42 +02:00
this . featureSwitchCommunityIndex = FeatureSwitchUtils . initSwitch (
2023-02-02 17:57:07 +01:00
"fs-community-index" ,
2023-05-25 20:09:42 +02:00
true ,
2023-02-02 17:57:07 +01:00
"Disables/enables the button to get in touch with the community"
)
2023-05-25 20:09:42 +02:00
this . featureSwitchExtraLinkEnabled = FeatureSwitchUtils . initSwitch (
2021-10-15 05:20:02 +02:00
"fs-iframe-popout" ,
2023-05-25 20:09:42 +02:00
true ,
2022-02-14 04:48:33 +01:00
"Disables/Enables the extraLink button. By default, if in iframe mode and the welcome message is hidden, a popout button to the full mapcomplete instance is shown instead (unless disabled with this switch or another extraLink button is enabled)"
2021-10-15 05:20:02 +02:00
)
2023-05-25 20:09:42 +02:00
this . featureSwitchMoreQuests = FeatureSwitchUtils . initSwitch (
2021-10-15 05:20:02 +02:00
"fs-more-quests" ,
2023-05-25 20:09:42 +02:00
layoutToUse ? . enableMoreQuests ? ? true ,
2021-10-15 05:20:02 +02:00
"Disables/Enables the 'More Quests'-tab in the welcome message"
)
2023-05-25 20:09:42 +02:00
this . featureSwitchShareScreen = FeatureSwitchUtils . initSwitch (
2021-10-15 05:20:02 +02:00
"fs-share-screen" ,
2023-05-25 20:09:42 +02:00
layoutToUse ? . enableShareScreen ? ? true ,
2021-10-15 05:20:02 +02:00
"Disables/Enables the 'Share-screen'-tab in the welcome message"
)
2023-05-25 20:09:42 +02:00
this . featureSwitchGeolocation = FeatureSwitchUtils . initSwitch (
2021-10-15 05:20:02 +02:00
"fs-geolocation" ,
2023-05-25 20:09:42 +02:00
layoutToUse ? . enableGeolocation ? ? true ,
2021-10-15 05:20:02 +02:00
"Disables/Enables the geolocation button"
)
2023-05-25 20:09:42 +02:00
this . featureSwitchShowAllQuestions = FeatureSwitchUtils . initSwitch (
2021-10-15 05:20:02 +02:00
"fs-all-questions" ,
2023-05-25 20:09:42 +02:00
layoutToUse ? . enableShowAllQuestions ? ? false ,
2021-10-15 05:20:02 +02:00
"Always show all questions"
)
2023-05-25 20:09:42 +02:00
this . featureSwitchEnableExport = FeatureSwitchUtils . initSwitch (
2021-10-15 05:20:02 +02:00
"fs-export" ,
2023-05-25 20:09:42 +02:00
layoutToUse ? . enableExportButton ? ? true ,
2021-10-15 05:20:02 +02:00
"Enable the export as GeoJSON and CSV button"
)
let testingDefaultValue = false
2021-10-20 00:09:40 +02:00
if (
this . featureSwitchApiURL . data !== "osm-test" &&
! Utils . runningFromConsole &&
2021-10-15 05:20:02 +02:00
( location . hostname === "localhost" || location . hostname === "127.0.0.1" )
) {
testingDefaultValue = true
}
2021-10-23 02:46:37 +02:00
this . featureSwitchIsTesting = QueryParameters . GetBooleanQueryParameter (
2021-10-15 05:20:02 +02:00
"test" ,
2022-02-14 18:18:05 +01:00
testingDefaultValue ,
2021-10-15 05:20:02 +02:00
"If true, 'dryrun' mode is activated. The app will behave as normal, except that changes to OSM will be printed onto the console instead of actually uploaded to osm.org"
2021-10-23 02:46:37 +02:00
)
2021-10-15 05:20:02 +02:00
2021-10-23 02:46:37 +02:00
this . featureSwitchIsDebugging = QueryParameters . GetBooleanQueryParameter (
2021-10-15 05:20:02 +02:00
"debug" ,
2022-02-14 18:18:05 +01:00
false ,
2021-10-15 05:20:02 +02:00
"If true, shows some extra debugging help such as all the available tags on every object"
2021-10-23 02:46:37 +02:00
)
2021-10-15 05:20:02 +02:00
this . overpassUrl = QueryParameters . GetQueryParameter (
"overpassUrl" ,
( layoutToUse ? . overpassUrl ? ? Constants . defaultOverpassUrls ) . join ( "," ) ,
"Point mapcomplete to a different overpass-instance. Example: https://overpass-api.de/api/interpreter"
2022-06-05 02:24:14 +02:00
) . sync (
2022-09-18 12:45:02 +02:00
( param ) = > param ? . split ( "," ) ,
2022-06-05 02:24:14 +02:00
[ ] ,
2022-09-18 12:45:02 +02:00
( urls ) = > urls ? . join ( "," )
2021-10-15 05:20:02 +02:00
)
this . overpassTimeout = UIEventSource . asFloat (
QueryParameters . GetQueryParameter (
"overpassTimeout" ,
"" + layoutToUse ? . overpassTimeout ,
"Set a different timeout (in seconds) for queries in overpass"
2022-09-08 21:40:48 +02:00
)
)
2021-10-15 05:20:02 +02:00
this . overpassMaxZoom = UIEventSource . asFloat (
QueryParameters . GetQueryParameter (
"overpassMaxZoom" ,
"" + layoutToUse ? . overpassMaxZoom ,
" point to switch between OSM-api and overpass"
)
2022-09-08 21:40:48 +02:00
)
2021-10-15 05:20:02 +02:00
this . osmApiTileSize = UIEventSource . asFloat (
QueryParameters . GetQueryParameter (
"osmApiTileSize" ,
"" + layoutToUse ? . osmApiTileSize ,
"Tilesize when the OSM-API is used to fetch data within a BBOX"
)
2022-09-08 21:40:48 +02:00
)
2021-10-15 05:20:02 +02:00
this . featureSwitchUserbadge . addCallbackAndRun ( ( userbadge ) = > {
if ( ! userbadge ) {
this . featureSwitchAddNew . setData ( false )
}
} )
this . backgroundLayerId = QueryParameters . GetQueryParameter (
"background" ,
layoutToUse ? . defaultBackgroundId ? ? "osm" ,
"The id of the background layer to start with"
)
}
}