No Description

jetpack-debugger-site-health.js 2.5KB

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