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"
import { UIEventSource } from "../UIEventSource"
import { QueryParameters } from "../Web/QueryParameters"
import Constants from "../../Models/Constants"
2021-10-20 00:09:40 +02:00
import { Utils } from "../../Utils"
2021-10-15 05:20:02 +02:00
export default class FeatureSwitchState {
/ * *
* 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 featureSwitchApiURL : UIEventSource < string >
public readonly featureSwitchFilter : UIEventSource < boolean >
public readonly featureSwitchEnableExport : UIEventSource < boolean >
public readonly featureSwitchFakeUser : UIEventSource < boolean >
public readonly featureSwitchExportAsPdf : 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 >
2021-10-28 03:21:17 +02:00
public constructor ( layoutToUse : LayoutConfig ) {
2021-10-15 05:20:02 +02:00
this . layoutToUse = layoutToUse
// Helper function to initialize feature switches
function featSw (
key : string ,
deflt : ( layout : LayoutConfig ) = > boolean ,
documentation : string
) : UIEventSource < boolean > {
const defaultValue = deflt ( layoutToUse )
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
2022-06-05 02:24:14 +02:00
return queryParam . sync (
( str ) = > ( str === undefined ? defaultValue : str !== "false" ) ,
[ ] ,
( b ) = > ( b == defaultValue ? undefined : "" + b )
2021-10-15 05:20:02 +02:00
)
}
this . featureSwitchUserbadge = featSw (
"fs-userbadge" ,
( layoutToUse ) = > layoutToUse ? . enableUserBadge ? ? true ,
"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."
)
this . featureSwitchSearch = featSw (
"fs-search" ,
( layoutToUse ) = > layoutToUse ? . enableSearch ? ? true ,
"Disables/Enables the search bar"
)
2021-12-04 12:20:24 +01:00
this . featureSwitchBackgroundSelection = featSw (
2021-10-15 05:20:02 +02:00
"fs-background" ,
( layoutToUse ) = > layoutToUse ? . enableBackgroundLayerSelection ? ? true ,
"Disables/Enables the background layer control"
)
this . featureSwitchFilter = featSw (
"fs-filter" ,
( layoutToUse ) = > layoutToUse ? . enableLayers ? ? true ,
2022-02-14 04:48:33 +01:00
"Disables/Enables the filter view"
2021-10-15 05:20:02 +02:00
)
this . featureSwitchAddNew = featSw (
"fs-add-new" ,
( layoutToUse ) = > layoutToUse ? . enableAddNewPoints ? ? true ,
"Disables/Enables the 'add new feature'-popup. (A theme without presets might not have it in the first place)"
)
this . featureSwitchWelcomeMessage = featSw (
"fs-welcome-message" ,
( ) = > true ,
"Disables/enables the help menu or welcome message"
)
2023-02-02 17:57:07 +01:00
this . featureSwitchCommunityIndex = featSw (
"fs-community-index" ,
( ) = > true ,
"Disables/enables the button to get in touch with the community"
)
2022-02-14 04:48:33 +01:00
this . featureSwitchExtraLinkEnabled = featSw (
2021-10-15 05:20:02 +02:00
"fs-iframe-popout" ,
2022-02-14 04:48:33 +01:00
( _ ) = > true ,
"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
)
this . featureSwitchMoreQuests = featSw (
"fs-more-quests" ,
( layoutToUse ) = > layoutToUse ? . enableMoreQuests ? ? true ,
"Disables/Enables the 'More Quests'-tab in the welcome message"
)
this . featureSwitchShareScreen = featSw (
"fs-share-screen" ,
( layoutToUse ) = > layoutToUse ? . enableShareScreen ? ? true ,
"Disables/Enables the 'Share-screen'-tab in the welcome message"
)
this . featureSwitchGeolocation = featSw (
"fs-geolocation" ,
( layoutToUse ) = > layoutToUse ? . enableGeolocation ? ? true ,
"Disables/Enables the geolocation button"
)
this . featureSwitchShowAllQuestions = featSw (
"fs-all-questions" ,
( layoutToUse ) = > layoutToUse ? . enableShowAllQuestions ? ? false ,
"Always show all questions"
)
this . featureSwitchEnableExport = featSw (
"fs-export" ,
( layoutToUse ) = > layoutToUse ? . enableExportButton ? ? false ,
"Enable the export as GeoJSON and CSV button"
)
this . featureSwitchExportAsPdf = featSw (
"fs-pdf" ,
( layoutToUse ) = > layoutToUse ? . enablePdfDownload ? ? false ,
"Enable the PDF download button"
)
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'"
)
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
2022-02-14 18:18:05 +01:00
this . featureSwitchFakeUser = QueryParameters . GetBooleanQueryParameter (
"fake-user" ,
false ,
2021-10-15 05:20:02 +02:00
"If true, 'dryrun' mode is activated and a fake user account is loaded"
)
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"
)
}
}