Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ const Sync = {
progress: document.getElementById( 'progress-wrapper' ),
submitButton: document.getElementById( 'submit' ),
stopButton: document.getElementById( 'stop-sync' ),
progressCount: document.getElementById( 'sync-progress' ),
barSyncCount: document.getElementById( 'sync-total' ),
completed: document.getElementById( 'completed-notice' ),
show: 'inline-block',
hide: 'none',
isRunning: false,
getStatus: function getStatus() {
var self = this,
resourceType = [],
Expand All @@ -22,8 +21,9 @@ const Sync = {
request.setRequestHeader( 'X-WP-Nonce', cloudinaryApi.nonce );
},
} ).done( function( data ) {
if ( data.done < data.total ) {
setTimeout( Sync.getStatus, 2000 );
Sync.isRunning = data.is_running;
if ( Sync.isRunning ) {
setTimeout( Sync.getStatus, 10000 );
}
Sync._updateUI( data );
} );
Expand All @@ -32,6 +32,8 @@ const Sync = {
var self = this,
url = cloudinaryApi.restUrl + 'cloudinary/v1/sync';

Sync.isRunning = false;

wp.ajax.send( {
url: url,
data: {
Expand All @@ -48,11 +50,16 @@ const Sync = {
var self = this,
url = cloudinaryApi.restUrl + 'cloudinary/v1/sync';

Sync.isRunning = true;
Sync.progress.style.display = Sync.show;

wp.ajax.send( {
url: url,
beforeSend: function( request ) {
request.setRequestHeader( 'X-WP-Nonce', cloudinaryApi.nonce );
},
} ).done( function ( data ) {
setTimeout( Sync.getStatus, 10000 );
} );
},
_updateUI: function _updateUI( data ) {
Expand All @@ -75,13 +82,14 @@ const Sync = {
this.stopButton.style.display = this.hide;
}

if ( data.percent < 100 ) {
this.barSyncCount.innerText = data.total;
this.progressCount.innerText = data.done;
if ( data.percent === 100 ) {
this.completed.style.display = this.show;
}

if ( this.isRunning ) {
this.progress.style.display = this.show;
}
else {
this.completed.style.display = this.show;
this.progress.style.display = this.hide;
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Upload_Queue {
*
* @var bool
*/
private $running = null;
private $running = false;

/**
* Upload_Queue constructor.
Expand Down Expand Up @@ -127,7 +127,7 @@ public function mark( $id, $type = 'done' ) {
* @return bool
*/
public function is_running() {
if ( null === $this->running ) {
if ( false === $this->running ) {
$queue = $this->get_queue();
$this->running = empty( $queue['started'] ) ? false : true;
}
Expand Down Expand Up @@ -175,6 +175,8 @@ public function get_queue_status() {
$this->stop_queue();
}

$return['is_running'] = $this->is_running();

return $return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
<span class="dashicons dashicons-update-alt"></span> <?php esc_html_e( 'Sync all media to Cloudinary', 'cloudinary' ); ?>
</button>
<span id="progress-wrapper" class="sync-media-progress">
<span class="progress-text"><span id="sync-progress"></span> / <span id="sync-total"></span></span><?php esc_html_e( 'Currently Synced', 'cloudinary' ); ?>
<span class="progress-text">
<img src="<?php echo esc_url( CLDN_URL . 'css/loading.svg'); ?>" alt="<?php esc_attr_e( 'Syncing…', 'cloudinary' ); ?>">
<?php esc_html_e( 'Syncing…', 'cloudinary' ); ?>
</span>
</span>
<div class="settings-tab-section-card completed" id="completed-notice">
<div class="settings-tab-section-fields-dashboard-success">
Expand Down