From b9116e7215caf3d7547ed4f2c43d320baaece018 Mon Sep 17 00:00:00 2001 From: nachoparker Date: Thu, 5 Apr 2018 22:27:23 +0200 Subject: ncp-web: faster first load by asynchronous call to is_active() --- changelog.md | 4 +++- ncp-web/activate/JS.js | 52 ++++++++++++++++++++++++++---------------------- ncp-web/index.php | 6 +++--- ncp-web/ncp-launcher.php | 2 +- ncp-web/ncp.js | 44 +++++++++++++++++++++++----------------- ncp-web/sidebar.php | 13 +++++++----- 6 files changed, 69 insertions(+), 52 deletions(-) diff --git a/changelog.md b/changelog.md index bcdb34fe..a7db4a7f 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,7 @@ -[v0.53.23](https://github.com/nextcloud/nextcloudpi/commit/b7ee6cd) (2018-04-05) ncp-web: force reload CSRF tokens every time +[v0.53.24](https://github.com/nextcloud/nextcloudpi/commit/181603a) (2018-04-05) ncp-web: faster first load by asynchronous call to is_active() + +[v0.53.23](https://github.com/nextcloud/nextcloudpi/commit/6fa40c5) (2018-04-05) ncp-web: force reload CSRF tokens every time [v0.53.22](https://github.com/nextcloud/nextcloudpi/commit/6f916a1) (2018-04-05) ncp-web: collapse sidebar menu when clicking in new sections diff --git a/ncp-web/activate/JS.js b/ncp-web/activate/JS.js index e9152707..740f71c8 100644 --- a/ncp-web/activate/JS.js +++ b/ncp-web/activate/JS.js @@ -17,6 +17,33 @@ function errorMsg() $('#error-box').fill( "Something went wrong. Try refreshing the page" ); } +function launch_nc_passwd() +{ + // request + $.request('post', '../ncp-launcher.php', { action: 'launch', + ref : 'nc-passwd', + config: '{ "PASSWORD":"' + $('#ncp-pwd').get('.value') + '",' + + '"CONFIRM" :"' + $('#ncp-pwd').get('.value') + '"}', + csrf_token: $( '#csrf-token' ).get( '.value' ) }).then( + + function success( result ) + { + var ret = $.parseJSON( result ); + if ( ret.ret == '0' ) + { + setTimeout( function(){ + $('#loading-gif').hide(); + $('#error-box').fill( "ACTIVATION SUCCESSFUL" ); + var url = window.location.protocol + '//' + window.location.hostname + ':4443'; + if ( !window.open( url, '_blank' ) ) // try to open in a new tab first + window.location.replace( url ); + }, 2000 ); + } else { + $('#error-box').fill( "nc-passwd error" ); + } + } ).error( errorMsg ); +} + $(function() { // print info page @@ -64,30 +91,7 @@ $(function() if ( ret.ret == '0' ) { if ( ret.token ) $('#csrf-token').set( { value: ret.token } ); - - // request - $.request('post', '../ncp-launcher.php', { action: 'launch', - ref : 'nc-passwd', - config: '{ "PASSWORD":"' + $('#ncp-pwd').get('.value') + '",' - + '"CONFIRM" :"' + $('#ncp-pwd').get('.value') + '"}', - csrf_token: $( '#csrf-token' ).get( '.value' ) }).then( - - function success( result ) - { - var ret = $.parseJSON( result ); - if ( ret.ret == '0' ) - { - setTimeout( function(){ - $('#loading-gif').hide(); - $('#error-box').fill( "ACTIVATION SUCCESSFUL" ); - var url = window.location.protocol + '//' + window.location.hostname + ':4443'; - if ( !window.open( url, '_blank' ) ) // try to open in a new tab first - window.location.replace( url ); - }, 2000 ); - } else { - $('#error-box').fill( "nc-passwd error" ); - } - } ).error( errorMsg ); + launch_nc_passwd(); } else { $('#error-box').fill( "nc-admin error" ); } diff --git a/ncp-web/index.php b/ncp-web/index.php index f06aa1f3..b3ec641f 100644 --- a/ncp-web/index.php +++ b/ncp-web/index.php @@ -163,7 +163,7 @@ HTML;
@@ -237,8 +237,8 @@ HTML; '; - echo ''; + echo ''; + echo ''; ?> diff --git a/ncp-web/ncp-launcher.php b/ncp-web/ncp-launcher.php index 9c870cd1..3fe1690d 100644 --- a/ncp-web/ncp-launcher.php +++ b/ncp-web/ncp-launcher.php @@ -199,7 +199,7 @@ else require( "sidebar.php" ); // return JSON echo '{ "token": "' . getCSRFToken() . '",'; // Get new token - echo ' "output": ' . json_encode( print_sidebar( $l ) ) . ' , '; + echo ' "output": ' . json_encode( print_sidebar( $l, true ) ) . ' , '; echo ' "ret": "0" }'; } } diff --git a/ncp-web/ncp.js b/ncp-web/ncp.js index 81820f0e..733753ec 100644 --- a/ncp-web/ncp.js +++ b/ncp-web/ncp.js @@ -105,18 +105,37 @@ function set_sidebar_click_handlers() }); } +function print_dashboard() +{ + $.request('post', 'ncp-launcher.php', { action: 'info', + csrf_token: $( '#csrf-token-ui' ).get( '.value' ) }).then( + + function success( result ) + { + var ret = $.parseJSON( result ); + if ( ret.token ) + $('#csrf-token-ui').set( { value: ret.token } ); + $('#loading-info-gif').hide(); + $('#dashboard-table').ht( ret.table ); + $('#dashboard-suggestions').ht( ret.suggestions ); + reload_sidebar(); + } ).error( errorMsg ); +} + function reload_sidebar() { // request $.request('post', 'ncp-launcher.php', { action:'sidebar', - csrf_token: $( '#csrf-token' ).get( '.value' ) }).then( + csrf_token: $( '#csrf-token-ui' ).get( '.value' ) }).then( function success( result ) { var ret = $.parseJSON( result ); if ( ret.token ) - $('#csrf-token').set( { value: ret.token } ); - $('#ncp-options').ht( ret.output ); - set_sidebar_click_handlers(); + $('#csrf-token-ui').set( { value: ret.token } ); + if ( ret.ret && ret.ret == '0' ) { + $('#ncp-options').ht( ret.output ); + set_sidebar_click_handlers(); + } }).error( errorMsg ); } @@ -336,20 +355,6 @@ $(function() // click to nextcloud button $('#nextcloud-btn').set( '@href', window.location.protocol + '//' + window.location.hostname ); - // load dashboard info - $.request('post', 'ncp-launcher.php', { action: 'info', - csrf_token: $( '#csrf-token-dash' ).get( '.value' ) }).then( - - function success( result ) - { - var ret = $.parseJSON( result ); - if ( ret.token ) - $('#csrf-token-dash').set( { value: ret.token } ); - $('#loading-info-gif').hide(); - $('#dashboard-table').ht( ret.table ); - $('#dashboard-suggestions').ht( ret.suggestions ); - } ).error( errorMsg ); - // dashboard button $( '#dashboard-btn' ).on('click', function(e) { @@ -365,6 +370,9 @@ $(function() close_menu(); switch_to_section( 'nc-config' ); } ); + + // load dashboard info + print_dashboard(); } ); // License diff --git a/ncp-web/sidebar.php b/ncp-web/sidebar.php index f8ee63fa..51351b59 100644 --- a/ncp-web/sidebar.php +++ b/ncp-web/sidebar.php @@ -10,7 +10,7 @@ // fill options with contents from directory -function print_sidebar( $l /* translations l10n object */ ) +function print_sidebar( $l /* translations l10n object */, $ticks /* wether to calculate ticks(slow) */ ) { $modules_path = '/usr/local/etc/nextcloudpi-config.d/'; $files = array_diff(scandir($modules_path), array('.', '..', 'nc-wifi.sh', 'nc-info.sh', 'l10n')); @@ -21,10 +21,13 @@ function print_sidebar( $l /* translations l10n object */ ) $txt = file_get_contents($modules_path . $file); $active = ""; - $etc = '/usr/local/etc'; - exec("bash -c \"source $etc/library.sh && is_active_script $etc/nextcloudpi-config.d/$script\".sh", $output, $retval); - if ($retval == 0) - $active = " ✓"; + if ( $ticks ) { + $etc = '/usr/local/etc'; + exec("bash -c \"source $etc/library.sh && is_active_script $etc/nextcloudpi-config.d/$script\".sh", $output, $retval); + if ($retval == 0) + $active = " ✓"; + } else if (preg_match('/^ACTIVE_=yes$/m', $txt, $matches)) + $active = " ✓"; $ret .= "
  • "; $ret .= " {$l->__($script, $script)}$active "; -- cgit v1.2.3