2020-07-31 21:54:30 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  { OsmConnection }  from  "./Logic/Osm/OsmConnection" ;  
						 
					
						
							
								
									
										
										
										
											2020-08-07 16:01:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  Combine  from  "./UI/Base/Combine" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { Button }  from  "./UI/Base/Button" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { TextField }  from  "./UI/Input/TextField" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { FixedUiElement }  from  "./UI/Base/FixedUiElement" ;  
						 
					
						
							
								
									
										
										
										
											2020-08-17 17:23:15 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  { UIEventSource }  from  "./Logic/UIEventSource" ;  
						 
					
						
							
								
									
										
										
										
											2021-05-07 13:17:42 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  { Utils }  from  "./Utils" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { SubtleButton }  from  "./UI/Base/SubtleButton" ;  
						 
					
						
							
								
									
										
										
										
											2021-05-07 15:09:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  LZString  from  "lz-string" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  { LayoutConfigJson }  from  "./Customizations/JSON/LayoutConfigJson" ;  
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:55:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  BaseUIElement  from  "./UI/BaseUIElement" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  Table  from  "./UI/Base/Table" ;  
						 
					
						
							
								
									
										
										
										
											2020-07-31 21:54:30 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-07-26 15:17:59 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const  connection  =  new  OsmConnection ( false ,  new  UIEventSource < string > ( undefined ) ,  "" ) ;  
						 
					
						
							
								
									
										
										
										
											2020-08-07 16:01:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								let  rendered  =  false ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 13:17:42 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function  salvageThemes ( preferences : any )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  knownThemeNames  =  new  Set < string > ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  correctThemeNames  =  [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( const  key  in  preferences )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! ( typeof  key  ===  "string" ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  prefix  =  "mapcomplete-installed-theme-" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        // mapcomplete-installed-theme-arbres_llefia-combined-11
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        //mapcomplete-installed-theme-1roadAlllanes-combined-length
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( ! key . startsWith ( prefix ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  theme  =  key . substring ( prefix . length ,  key . indexOf ( "-combined-" ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( key . endsWith ( "-length" ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            correctThemeNames . push ( theme ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            knownThemeNames . add ( theme ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( const  correctThemeName  of  correctThemeNames )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        knownThemeNames . delete ( correctThemeName ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    const  missingValues  =  Array . from ( knownThemeNames ) . map ( failedTheme  = >  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        let  i  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        let  foundValue  =  undefined 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        let  combined  =  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        do  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 15:09:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            const  prefix  =  "mapcomplete-installed-theme-" ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 13:17:42 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            const  key  =  prefix  +  failedTheme  +  "-combined-"  +  i ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            foundValue  =  preferences [ key ] 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 15:09:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            console . log ( key , "-->" , foundValue ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 13:17:42 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            i ++ ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            combined  +=  foundValue  ? ?  "" 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  while  ( foundValue  !==  undefined ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 15:09:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if ( combined  ===  "" ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            return  null ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        console . log ( "COmbined value is" ,  combined ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        let  jsonObject ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        try  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            jsonObject  =  JSON . parse ( atob ( combined ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        }  catch  ( e )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            // We try to decode with lz-string
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            jsonObject  =  JSON . parse ( Utils . UnMinify ( LZString . decompressFromBase64 ( combined ) ) )  as  LayoutConfigJson ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 13:17:42 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            themeName : failedTheme , 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 15:09:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            contents : JSON.stringify ( jsonObject ,  null ,  "  " ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 13:17:42 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 15:09:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    return   Utils . NoNull ( missingValues ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function  clearAll ( preferences ) {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for  ( const  key  in  preferences )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        const  pref  =  connection . GetPreference ( key ,  "" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        if  ( key . startsWith ( "mapcomplete" ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            pref . setData ( "" ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 13:17:42 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 15:09:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function  SalvageButton ( theme :  {  themeName : string ,  contents : string  } )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  new  SubtleButton ( "./assets/svg/bug.svg" ,  "Download broken theme "  +  theme . themeName ) . onClick ( 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 13:17:42 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ( )  = >  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-31 00:20:15 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            Utils . offerContentsAsDownloadableFile ( theme . contents ,  theme . themeName  +  ".json" ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 13:17:42 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-07 16:01:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								function  createTable ( preferences : any )  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( rendered )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    rendered  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:55:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    const  prefs :  ( BaseUIElement | string ) [ ] [ ]  =  [ ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-07 16:01:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    for  ( const  key  in  preferences )  { 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:55:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if ( ! preferences . hasOwnProperty ( key ) ) { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-07 16:01:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  pref  =  connection . GetPreference ( key ,  "" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:55:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        let  value : BaseUIElement  =  new  FixedUiElement ( pref . data ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-07 16:01:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        if  ( connection . userDetails . data . csCount  >  500  && 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ( key . startsWith ( "mapcomplete" )  ||  connection . userDetails . data . csCount  >  2500 ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2020-10-02 19:00:24 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            value  =  new  TextField ( { 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-07 16:01:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								                value : pref 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            } ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:55:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        const  row  =  [ 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-07 16:01:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            key , 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:55:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            new  Button ( "delete" ,  ( )  = >  pref . setData ( null ) ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            value 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-07 16:01:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:55:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        prefs . push ( row ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-07 16:01:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-04-10 03:50:44 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    new  Combine ( 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 13:17:42 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        [ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            . . . salvageThemes ( preferences ) . map ( theme  = >  SalvageButton ( theme ) ) , 
							 
						 
					
						
							
								
									
										
										
										
											2021-06-15 00:55:12 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								            new  Table ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                [ "Key" , "" , "Value" ] , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                prefs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								                
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								            ) , 
							 
						 
					
						
							
								
									
										
										
										
											2021-05-07 15:09:52 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								        new  SubtleButton ( "./assets/svg/delete_icon.svg" ,  "Delete all mapcomplete preferences (mangrove identies are preserved)" ) . onClick ( ( )  = >  clearAll ( preferences ) ) ] 
							 
						 
					
						
							
								
									
										
										
										
											2021-04-10 03:50:44 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ) . AttachTo ( "maindiv" ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2020-08-07 16:01:18 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-08-27 11:11:20 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								connection . preferencesHandler . preferences . addCallback ( ( prefs )  = >  createTable ( prefs ) )  
						 
					
						
							
								
									
										
										
										
											2020-08-07 16:01:18 +02:00