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-06-14 20:39:36 +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-06-14 20:39:36 +02:00
import { Utils } from "../../Utils"
2024-06-23 02:54:53 +02:00
import { Query } from "pg"
2021-10-15 05:20:02 +02:00
2023-05-25 20:09:42 +02:00
class FeatureSwitchUtils {
2024-06-23 02:54:53 +02:00
/ * * H e l p e r f u n c t i o n t o i n i t i a l i z e f e a t u r e s w i t c h e s
*
* /
2023-06-14 20:39:36 +02:00
static initSwitch ( key : string , deflt : boolean , documentation : string ) : UIEventSource < boolean > {
const defaultValue = deflt
2023-07-28 01:12:42 +02:00
const queryParam = QueryParameters . GetQueryParameter (
key ,
"" + defaultValue ,
documentation ,
2024-07-09 13:42:08 +02:00
{ stackOffset : - 1 }
2023-07-28 01:12:42 +02:00
)
2023-06-14 20:39:36 +02:00
// 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" ) ,
[ ] ,
2024-07-09 13:42:08 +02:00
( b ) = > ( b == defaultValue ? undefined : "" + b )
2023-06-14 20:39:36 +02:00
)
}
2023-05-25 20:09:42 +02:00
}
export class OsmConnectionFeatureSwitches {
public readonly featureSwitchFakeUser : UIEventSource < boolean >
constructor ( ) {
this . featureSwitchFakeUser = QueryParameters . GetBooleanQueryParameter (
"fake-user" ,
false ,
2024-07-09 13:42:08 +02:00
"If true, 'dryrun' mode is activated and a fake user account is loaded"
2023-05-25 20:09:42 +02:00
)
}
}
2023-06-14 20:39:36 +02:00
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
2023-08-10 15:37:44 +02:00
public readonly featureSwitchEnableLogin : UIEventSource < boolean >
2021-10-15 05:20:02 +02:00
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 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 >
2024-06-16 19:00:43 +02:00
public readonly featureSwitchBackToThemeOverview : UIEventSource < boolean >
2021-10-15 05:20:02 +02:00
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 >
2024-05-06 14:23:54 +02:00
public readonly featureSwitchMorePrivacy : UIEventSource < boolean >
2024-06-27 01:57:32 +02:00
public readonly featureSwitchLayerDefault : UIEventSource < boolean >
2021-10-15 05:20:02 +02:00
2023-05-25 20:09:42 +02:00
public constructor ( layoutToUse? : LayoutConfig ) {
super ( )
2021-10-15 05:20:02 +02:00
this . layoutToUse = layoutToUse
2024-06-23 02:54:53 +02:00
const legacyRewrite : Record < string , string | string [ ] > = {
"fs-userbadge" : "fs-enable-login" ,
"fs-layers" : [ "fs-filter" , "fs-background" ] ,
}
for ( const key in legacyRewrite ) {
let intoList = legacyRewrite [ key ]
if ( ! QueryParameters . wasInitialized ( key ) ) {
continue
}
if ( typeof intoList === "string" ) {
intoList = [ intoList ]
}
for ( const into of intoList ) {
if ( ! QueryParameters . wasInitialized ( into ) ) {
const v = QueryParameters . GetQueryParameter ( key , "" , "" ) . data
console . log ( "Adding url param due to legacy:" , key , "-->" , into , "(" , v + ")" )
QueryParameters . GetQueryParameter ( into , "" , "" ) . setData ( v )
}
}
}
2021-10-15 05:20:02 +02:00
2023-08-10 15:37:44 +02:00
this . featureSwitchEnableLogin = FeatureSwitchUtils . initSwitch (
"fs-enable-login" ,
2023-05-25 20:09:42 +02:00
layoutToUse ? . enableUserBadge ? ? true ,
2024-07-09 13:42:08 +02:00
"Disables/Enables logging in and thus disables editing all together. This effectively puts MapComplete into read-only mode."
2021-10-15 05:20:02 +02:00
)
2023-10-19 13:36:49 +02:00
{
2023-10-30 13:44:27 +01:00
if ( QueryParameters . wasInitialized ( "fs-userbadge" ) ) {
2023-10-19 13:36:49 +02:00
// userbadge is the legacy name for 'enable-login'
2023-10-30 13:44:27 +01:00
this . featureSwitchEnableLogin . setData (
QueryParameters . GetBooleanQueryParameter ( "fs-userbadge" , undefined , "Legacy" )
2024-07-09 13:42:08 +02:00
. data
2023-10-30 13:44:27 +01:00
)
2023-10-19 13:36:49 +02:00
}
}
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 ,
2024-07-09 13:42:08 +02:00
"Disables/Enables the search bar"
2021-10-15 05:20:02 +02:00
)
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 ,
2024-07-09 13:42:08 +02:00
"Disables/Enables the background layer control where a user can enable e.g. aerial imagery"
2021-10-15 05:20:02 +02:00
)
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 ,
2024-07-09 13:42:08 +02:00
"Disables/Enables the filter view where a user can enable/disable MapComplete-layers or filter for certain properties"
2021-10-15 05:20:02 +02:00
)
2023-08-10 15:37:44 +02:00
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 ,
2024-07-09 13:42:08 +02:00
"Disables/enables the help menu or welcome message"
2021-10-15 05:20:02 +02:00
)
2023-05-25 20:09:42 +02:00
this . featureSwitchCommunityIndex = FeatureSwitchUtils . initSwitch (
2023-02-02 17:57:07 +01:00
"fs-community-index" ,
2023-10-11 01:41:42 +02:00
this . featureSwitchEnableLogin . data ,
2024-07-09 13:42:08 +02:00
"Disables/enables the button to get in touch with the community"
2023-02-02 17:57:07 +01:00
)
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 ,
2024-07-09 13:42:08 +02: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
)
2024-06-16 19:00:43 +02:00
this . featureSwitchBackToThemeOverview = FeatureSwitchUtils . initSwitch (
"fs-homepage-link" ,
2023-05-25 20:09:42 +02:00
layoutToUse ? . enableMoreQuests ? ? true ,
2024-07-09 13:42:08 +02:00
"Disables/Enables the various links which go back to the index page with the theme overview"
2021-10-15 05:20:02 +02:00
)
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 ,
2024-07-09 13:42:08 +02:00
"Disables/Enables the 'Share-screen'-tab in the welcome message"
2021-10-15 05:20:02 +02:00
)
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 ,
2024-07-09 13:42:08 +02:00
"Disables/Enables the geolocation button"
2024-06-27 17:37:34 +02:00
)
2024-07-09 13:42:08 +02:00
this . featureSwitchLayerDefault = QueryParameters . GetBooleanQueryParameter (
"fs-layers-enabled" ,
true ,
"If set to false, all layers will be disabled - except the explicitly enabled layers"
2021-10-15 05:20:02 +02:00
)
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 ,
2024-07-09 13:42:08 +02:00
"Always show all questions"
2021-10-15 05:20:02 +02:00
)
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 ,
2024-07-09 13:42:08 +02:00
"Enable the export as GeoJSON and CSV button"
2021-10-15 05:20:02 +02:00
)
let testingDefaultValue = false
2021-10-20 00:09:40 +02:00
if (
! Utils . runningFromConsole &&
2024-07-17 18:42:39 +02:00
( location . hostname === "localhost" || location . hostname === "127.0.0.1" ) &&
! Constants . osmAuthConfig . url . startsWith ( "https://master.apis.dev.openstreetmap.org" )
2021-10-15 05:20:02 +02:00
) {
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 ,
2024-07-09 13:42:08 +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 ,
2024-07-09 13:42:08 +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
2024-05-06 14:23:54 +02:00
this . featureSwitchMorePrivacy = QueryParameters . GetBooleanQueryParameter (
"moreprivacy" ,
layoutToUse . enableMorePrivacy ,
2024-07-09 13:42:08 +02:00
"If true, the location distance indication will not be written to the changeset and other privacy enhancing measures might be taken."
2024-05-06 14:23:54 +02:00
)
2021-10-15 05:20:02 +02:00
this . overpassUrl = QueryParameters . GetQueryParameter (
"overpassUrl" ,
( layoutToUse ? . overpassUrl ? ? Constants . defaultOverpassUrls ) . join ( "," ) ,
2024-07-09 13:42:08 +02:00
"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
[ ] ,
2024-07-09 13:42:08 +02:00
( urls ) = > urls ? . join ( "," )
2021-10-15 05:20:02 +02:00
)
2023-10-05 15:55:18 +02:00
this . overpassTimeout = UIEventSource . asInt (
2021-10-15 05:20:02 +02:00
QueryParameters . GetQueryParameter (
"overpassTimeout" ,
"" + layoutToUse ? . overpassTimeout ,
2024-07-09 13:42:08 +02:00
"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 ,
2024-07-09 13:42:08 +02:00
" point to switch between OSM-api and overpass"
)
2022-09-08 21:40:48 +02:00
)
2021-10-15 05:20:02 +02:00
2023-10-05 15:55:18 +02:00
this . osmApiTileSize = UIEventSource . asInt (
2021-10-15 05:20:02 +02:00
QueryParameters . GetQueryParameter (
"osmApiTileSize" ,
"" + layoutToUse ? . osmApiTileSize ,
2024-07-09 13:42:08 +02:00
"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 . backgroundLayerId = QueryParameters . GetQueryParameter (
"background" ,
2023-09-24 16:34:36 +02:00
layoutToUse ? . defaultBackgroundId ,
2024-07-09 13:42:08 +02:00
"The id of the background layer to start with"
2021-10-15 05:20:02 +02:00
)
}
}