@@ -36,14 +36,44 @@ const jsonrpc = (method, params) => {
3636 } ) ;
3737} ;
3838
39+ // show/hide logout menu
40+ const showLogout = ( ) => { // eslint-disable-line no-unused-vars
41+ const element = document . getElementById ( 'logout-div' ) ;
42+ const style = window . getComputedStyle ( element ) ;
43+ const disp = style . getPropertyValue ( 'display' ) ;
44+
45+ if ( disp === 'block' ) {
46+ document . getElementById ( 'menu-holder' ) . style . border = '1px solid rgb(255, 255, 255)' ;
47+ document . getElementById ( 'logout-div' ) . style . display = 'none' ;
48+ } else {
49+ document . getElementById ( 'menu-holder' ) . style . border = '1px solid rgb(4, 159, 217)' ;
50+ document . getElementById ( 'logout-div' ) . style . display = 'block' ;
51+ }
52+ } ;
53+
54+ // logout and direct browser to login page
55+ const logout = ( ) => { // eslint-disable-line no-unused-vars
56+ jsonrpc ( 'logout' , { } ) ;
57+ window . location . href = '/webui-one' ;
58+ } ;
59+
3960// fetch the system version with the get_system_setting method.
4061// Return request promise
4162const fetchSystemVersion = ( ) => jsonrpc ( 'get_system_setting' , { operation : 'version' } ) ;
4263
64+ // fetch the current user with the get_system_setting method.
65+ // Return request promise
66+ const getCurrentUser = ( ) => {
67+ jsonrpc ( 'get_system_setting' , { operation : 'user' } ) . then ( ( username ) => {
68+ document . getElementById ( 'username' ) . textContent = username ;
69+ } ) ;
70+ } ;
71+
4372// update the systemVersion element when the window has loaded.
4473window . addEventListener ( 'load' , ( ) => {
4574 fetchSystemVersion ( ) . then ( ( version ) => {
4675 const element = document . getElementById ( 'systemVersion' ) ;
4776 element . innerText = version ;
4877 } ) ;
78+ getCurrentUser ( ) ;
4979} ) ;
0 commit comments