class-jetpack-cxn-test-base.php
3 years ago
class-jetpack-cxn-tests.php
3 years ago
class-jetpack-debug-data.php
3 years ago
class-jetpack-debugger.php
2 years ago
debug-functions.php
3 years ago
jetpack-debugger-site-health.css
6 years ago
jetpack-debugger-site-health.js
6 years ago
jetpack-debugger-site-health.js
81 lines
| 1 | /* global jetpackSiteHealth */ |
| 2 | /** |
| 3 | * This script runs on the site health page. |
| 4 | */ |
| 5 | |
| 6 | jQuery( document ).ready( function ( $ ) { |
| 7 | var JetpackSync = { |
| 8 | inProgress: true, |
| 9 | progressPercent: 0, |
| 10 | interval: false, |
| 11 | init: function () { |
| 12 | JetpackSync.progressPercent = parseInt( jetpackSiteHealth.progressPercent ); |
| 13 | JetpackSync.setProgress(); |
| 14 | JetpackSync.interval = setInterval( JetpackSync.checkProgress, 3000 ); |
| 15 | $( 'body' ).on( |
| 16 | 'click', |
| 17 | '[aria-controls=health-check-accordion-block-jetpack_test__full_sync_health]', |
| 18 | JetpackSync.setProgress |
| 19 | ); |
| 20 | }, |
| 21 | accordionButton: function () { |
| 22 | return $( '[aria-controls=health-check-accordion-block-jetpack_test__full_sync_health]' ); |
| 23 | }, |
| 24 | accordionIsOpen: function () { |
| 25 | return JetpackSync.accordionButton().attr( 'aria-expanded' ); |
| 26 | }, |
| 27 | checkProgress: function () { |
| 28 | $.post( jetpackSiteHealth.ajaxUrl, { action: 'jetpack_sync_progress_check' }, function ( |
| 29 | response |
| 30 | ) { |
| 31 | if ( 'done' === response ) { |
| 32 | clearInterval( JetpackSync.interval ); |
| 33 | if ( JetpackSync.inProgress ) { |
| 34 | JetpackSync.progressPercent = 100; |
| 35 | JetpackSync.setProgress(); |
| 36 | } |
| 37 | JetpackSync.inProgress = false; |
| 38 | return; |
| 39 | } |
| 40 | JetpackSync.inProgress = true; |
| 41 | JetpackSync.progressPercent = parseInt( response ); |
| 42 | JetpackSync.setProgress(); |
| 43 | } ); |
| 44 | }, |
| 45 | setProgress: function () { |
| 46 | if ( 'true' === JetpackSync.accordionIsOpen() ) { |
| 47 | // When the accordion is open, we remove the progress percentage from the accordion heading, |
| 48 | // and show a progress bar in the accordion body. |
| 49 | $( '.jetpack-sync-progress-bar' ).progressbar( { value: JetpackSync.progressPercent } ); |
| 50 | $( '.jetpack-sync-progress-label' ).text( JetpackSync.progressPercent + '%' ); |
| 51 | JetpackSync.accordionButton() |
| 52 | .find( '.title' ) |
| 53 | .text( jetpackSiteHealth.syncProgressHeading ); |
| 54 | } else { |
| 55 | // When the accordion is closed, we show the progress percentage in the accordion heading. |
| 56 | JetpackSync.accordionButton() |
| 57 | .find( '.title' ) |
| 58 | .text( |
| 59 | jetpackSiteHealth.syncProgressHeading + ' - ' + JetpackSync.progressPercent + '%' |
| 60 | ); |
| 61 | } |
| 62 | }, |
| 63 | }; |
| 64 | |
| 65 | if ( jetpackSiteHealth.progressPercent ) { |
| 66 | setTimeout( function () { |
| 67 | JetpackSync.init(); |
| 68 | }, 5000 ); |
| 69 | } |
| 70 | |
| 71 | $( 'body' ).on( 'click', '#full_sync_request_link', function () { |
| 72 | var data = { |
| 73 | action: 'jetpack_debugger_full_sync_start', |
| 74 | 'site-health-nonce': jetpackSiteHealth.fullSyncNonce, |
| 75 | }; |
| 76 | $.post( jetpackSiteHealth.ajaxUrl, data, function ( response ) { |
| 77 | window.location.reload( true ); |
| 78 | } ); |
| 79 | } ); |
| 80 | } ); |
| 81 |