import { UserListComponent } from './UserListComponent' ; import { Menu } from "./Menu" ; import { OptionManager } from "./OptionManager" ; import { Share } from "./share" ; import { User } from "./User" ; export class UserManager { param userId param bool description static setUserCanWrite ( userId , bool ) { console . log ( `setUserCanWrite(${ userId }, ${ bool })` ) ; UserManager . users [ userId ] . setCanWrite ( bool ) ; if ( userId == UserManager . me . userID ) { /** toggle the visibility for elements for editing the board */ const elements = document . getElementsByClassName ( "edit" ) ; for ( let i = 0 ; i < elements . length ; i ++ ) { ( < HTMLElement > elements [ i ] ) . hidden = ! bool ; } } UserListComponent . updateGUIUser ( userId ) ; } static me : User = undefined ; static users : { [ id ] : User ; } = { } ; /**
     * initialisation: creation of myself :)
     */ static init ( ) { UserManager . me = new User ( true ) ; UserManager . users [ 'root' ] = UserManager . me ; UserManager . me . setUserID ( 'root' ) ; OptionManager . string ( { name : "userName" , defaultValue : "me" , onChange : ( userName ) => { setTimeout ( ( ) => Share . execute ( "setUserName" , [ UserManager . me . userID , userName ] ) , 1000 ) ; } } ) ; document . getElementById ( "numberOfUsers" ) . onclick = ( ) => { Menu . show ( ) ; Menu . openPageShare ( ) ; } ; } returns static isIamResponsibleForData ( ) { let minkey = "zzzzzzzzzzzzzzzz" ; for ( const key in UserManager . users ) { if ( UserManager . users [ key ] . isRoot ) if ( key < minkey ) minkey = key ; } return ( UserManager . me . userID == minkey ) ; } param { * } userid description static leave ( userid ) { UserManager . users [ userid ] . destroy ( ) ; delete UserManager . users [ userid ] ; UserListComponent . leave ( userid ) ; } param { * } userid description static add ( userid ) { UserManager . users [ userid ] = new User ( false ) ; UserListComponent . add ( userid ) ; } param { * } userid description static setMyUserID ( userid ) { for ( const key in UserManager . users ) { if ( UserManager . users [ key ] == UserManager . me ) delete UserManager . users [ key ] ; } UserManager . users [ userid ] = UserManager . me ; UserManager . me . setUserID ( userid ) ; UserListComponent . updateGUIUsers ( ) ; } returns static getNumberOfUsers ( ) { return Object . keys ( UserManager . users ) . length ; } description static setSymbolCursorPosition ( ) { for ( const userid in UserManager . users ) { const user = UserManager . users [ userid ] ; if ( user != UserManager . me ) user . setSymbolCursorPosition ( ) ; } } }