mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-06-02 04:15:05 +02:00
fixes #966 progression bar for sync metadata
* [Batch Manager] adding progression bar for metadata sync action * [Batch Manager] display the number of synchronized photos in the success message
This commit is contained in:
@@ -395,8 +395,7 @@ DELETE
|
||||
// synchronize metadata
|
||||
else if ('metadata' == $action)
|
||||
{
|
||||
sync_metadata($collection);
|
||||
$page['infos'][] = l10n('Metadata synchronized from file');
|
||||
$page['infos'][] = l10n('Metadata synchronized from file').' <span class="badge">'.count($collection).'</span>';
|
||||
}
|
||||
|
||||
else if ('delete_derivatives' == $action && !empty($_POST['del_derivatives_type']))
|
||||
|
||||
@@ -218,12 +218,81 @@ function selectDelDerivNone() {
|
||||
$("#action_delete_derivatives input[type=checkbox]").prop("checked", false);
|
||||
}
|
||||
|
||||
/* delete photos by blocks, with progress bar */
|
||||
/* sync metadatas or delete photos by blocks, with progress bar */
|
||||
jQuery('#applyAction').click(function(e) {
|
||||
if (typeof(elements) != "undefined") {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (jQuery('[name="selectAction"]').val() == 'metadata') {
|
||||
e.stopPropagation();
|
||||
jQuery('.bulkAction').hide();
|
||||
jQuery('#regenerationText').html(lang.syncProgressMessage);
|
||||
|
||||
elements = Array();
|
||||
|
||||
if (jQuery('input[name=setSelected]').is(':checked')) {
|
||||
elements = all_elements;
|
||||
}
|
||||
else {
|
||||
jQuery('input[name="selection[]"]').filter(':checked').each(function() {
|
||||
elements.push(jQuery(this).val());
|
||||
});
|
||||
}
|
||||
|
||||
progressBar_max = elements.length;
|
||||
var todo = 0;
|
||||
var syncBlockSize = Math.min(
|
||||
Number((elements.length/2).toFixed()),
|
||||
1000
|
||||
);
|
||||
var image_ids = Array();
|
||||
|
||||
jQuery('#applyActionBlock').hide();
|
||||
jQuery('select[name="selectAction"]').hide();
|
||||
jQuery('#regenerationMsg').show();
|
||||
jQuery('#progressBar').progressBar(0, {
|
||||
max: progressBar_max,
|
||||
textFormat: 'fraction',
|
||||
boxImage: 'themes/default/images/progressbar.gif',
|
||||
barImage: 'themes/default/images/progressbg_orange.gif'
|
||||
});
|
||||
for (i=0;i<elements.length;i++) {
|
||||
image_ids.push(elements[i]);
|
||||
if (i % syncBlockSize != syncBlockSize - 1 && i != elements.length - 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
(function(ids) {
|
||||
var thisBatchSize = ids.length;
|
||||
jQuery.ajax({
|
||||
url: "ws.php?format=json&method=pwg.images.syncMetadata",
|
||||
type:"POST",
|
||||
dataType: "json",
|
||||
data: {
|
||||
pwg_token: jQuery("input[name=pwg_token").val(),
|
||||
image_id: ids
|
||||
},
|
||||
success: function(data) {
|
||||
todo += thisBatchSize;
|
||||
var isOk = data.stat && "ok" == data.stat;
|
||||
if (isOk && data.result.nb_synchronized != thisBatchSize)
|
||||
/*TODO: user feedback only data.nb_synchronized images out of thisBatchSize were sync*/;
|
||||
/*TODO: user feedback if isError*/
|
||||
progressionBar(todo, progressBar_max, isOk);
|
||||
},
|
||||
error: function(data) {
|
||||
todo += thisBatchSize;
|
||||
/*TODO: user feedback*/
|
||||
progressionBar(todo, progressBar_max, false);
|
||||
}
|
||||
});
|
||||
} )(image_ids);
|
||||
|
||||
image_ids = Array();
|
||||
}
|
||||
}
|
||||
|
||||
if (jQuery('[name="selectAction"]').val() == 'delete') {
|
||||
if (!jQuery("#action_delete input[name=confirm_deletion]").is(':checked')) {
|
||||
jQuery("#action_delete span.errors").show();
|
||||
@@ -297,12 +366,12 @@ jQuery('#applyAction').click(function(e) {
|
||||
if (isOk && data.result != thisBatchSize)
|
||||
/*TODO: user feedback only data.result images out of thisBatchSize were deleted*/;
|
||||
/*TODO: user feedback if isError*/
|
||||
progressDelete(todo, progressBar_max, isOk);
|
||||
progressionBar(todo, progressBar_max, isOk);
|
||||
},
|
||||
error: function(data) {
|
||||
todo += thisBatchSize;
|
||||
/*TODO: user feedback*/
|
||||
progressDelete(todo, progressBar_max, false);
|
||||
progressionBar(todo, progressBar_max, false);
|
||||
}
|
||||
});
|
||||
} )(image_ids);
|
||||
@@ -316,7 +385,7 @@ jQuery('#applyAction').click(function(e) {
|
||||
return false;
|
||||
});
|
||||
|
||||
function progressDelete(val, max, success) {
|
||||
function progressionBar(val, max, success) {
|
||||
jQuery('#progressBar').progressBar(val, {
|
||||
max: max,
|
||||
textFormat: 'fraction',
|
||||
@@ -333,14 +402,14 @@ jQuery("#action_delete input[name=confirm_deletion]").change(function() {
|
||||
jQuery("#action_delete span.errors").hide();
|
||||
});
|
||||
|
||||
jQuery('#sync_md5sum').click(function(e) {
|
||||
jQuery(this).hide();
|
||||
jQuery('#add_md5sum').show();
|
||||
jQuery('#sync_md5sum').click(function(e) {
|
||||
jQuery(this).hide();
|
||||
jQuery('#add_md5sum').show();
|
||||
|
||||
var addBlockSize = Math.min(
|
||||
Number((jQuery('#md5sum_to_add').data('origin') / 2).toFixed()),
|
||||
1000
|
||||
);
|
||||
var addBlockSize = Math.min(
|
||||
Number((jQuery('#md5sum_to_add').data('origin') / 2).toFixed()),
|
||||
1000
|
||||
);
|
||||
add_md5sum_block(addBlockSize);
|
||||
|
||||
return false;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
var lang = {
|
||||
Cancel: '{'Cancel'|translate|escape:'javascript'}',
|
||||
deleteProgressMessage: "{'Deletion in progress'|translate|escape:'javascript'}",
|
||||
syncProgressMessage: "{'Synchronization in progress'|translate|escape:'javascript'}",
|
||||
AreYouSure: "{'Are you sure?'|translate|escape:'javascript'}"
|
||||
};
|
||||
|
||||
|
||||
@@ -860,6 +860,15 @@ h2:lang(en) { text-transform:capitalize; }
|
||||
border-left:4px solid #00529b;
|
||||
}
|
||||
|
||||
.badge {
|
||||
background-color:#0a0;
|
||||
color:white;
|
||||
padding:1px 5px;
|
||||
border-radius:10px;
|
||||
-moz-border-radius:10px;
|
||||
-webkit-border-radius:10px;
|
||||
margin-left:5px;
|
||||
}
|
||||
|
||||
.infos li, .errors li, .warnings li, .messages li { list-style-type:none; }
|
||||
.infos .submit {margin-left:30px;}
|
||||
|
||||
@@ -1831,6 +1831,40 @@ function ws_images_setMd5sum($params, $service)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* API method
|
||||
* Synchronize metadatas photos. Returns how many metadatas were sync.
|
||||
* @param mixed[] $params
|
||||
* @option int image_id
|
||||
*/
|
||||
function ws_images_syncMetadata($params, $service)
|
||||
{
|
||||
if (get_pwg_token() != $params['pwg_token'])
|
||||
{
|
||||
return new PwgError(403, 'Invalid security token');
|
||||
}
|
||||
|
||||
$query = '
|
||||
SELECT id
|
||||
FROM '.IMAGES_TABLE.'
|
||||
WHERE id IN ('.implode(', ', $params['image_id']).')
|
||||
;';
|
||||
$params['image_id'] = query2array($query, null, 'id');
|
||||
|
||||
if (empty($params['image_id']))
|
||||
{
|
||||
return new PwgError(403, 'No image found');
|
||||
}
|
||||
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions_metadata.php');
|
||||
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
||||
sync_metadata($params['image_id']);
|
||||
|
||||
return array(
|
||||
'nb_synchronized' => count($params['image_id'])
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* API method
|
||||
* Deletes orphan photos, by block. Returns how many orphans were deleted and how many are remaining.
|
||||
|
||||
@@ -1014,3 +1014,4 @@ $lang['%d checksums were added'] = '%d checksums were added';
|
||||
$lang['With no checksum'] = 'With no checksum';
|
||||
$lang['Compute %d missing checksums'] = 'Compute %d missing checksums';
|
||||
$lang['checksums to add'] = 'checksums to add';
|
||||
$lang['Synchronization in progress'] = 'Synchronization in progress';
|
||||
|
||||
@@ -510,17 +510,31 @@ function ws_addDefaultMethods( $arr )
|
||||
array('admin_only'=>true, 'post_only'=>true)
|
||||
);
|
||||
|
||||
$service->addMethod(
|
||||
'pwg.images.setMd5sum',
|
||||
'ws_images_setMd5sum',
|
||||
array(
|
||||
'block_size' => array('default'=>1000, 'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
|
||||
'pwg_token' => array(),
|
||||
),
|
||||
'Set md5sum column, by blocks. Returns how many md5sums were added and how many are remaining.',
|
||||
$ws_functions_root . 'pwg.images.php',
|
||||
array('admin_only'=>true, 'post_only'=>true)
|
||||
);
|
||||
$service->addMethod(
|
||||
'pwg.images.setMd5sum',
|
||||
'ws_images_setMd5sum',
|
||||
array(
|
||||
'block_size' => array('default'=>1000, 'type'=>WS_TYPE_INT|WS_TYPE_POSITIVE),
|
||||
'pwg_token' => array(),
|
||||
),
|
||||
'Set md5sum column, by blocks. Returns how many md5sums were added and how many are remaining.',
|
||||
$ws_functions_root . 'pwg.images.php',
|
||||
array('admin_only'=>true, 'post_only'=>true)
|
||||
);
|
||||
|
||||
$service->addMethod(
|
||||
'pwg.images.syncMetadata',
|
||||
'ws_images_syncMetadata',
|
||||
array(
|
||||
'image_id' => array('default'=>null,
|
||||
'type'=>WS_TYPE_ID|WS_TYPE_POSITIVE,
|
||||
'flags'=>WS_PARAM_FORCE_ARRAY),
|
||||
'pwg_token' => array(),
|
||||
),
|
||||
'Sync metadatas, by blocks. Returns how many images were synchronized',
|
||||
$ws_functions_root . 'pwg.images.php',
|
||||
array('admin_only'=>true, 'post_only'=>true)
|
||||
);
|
||||
|
||||
$service->addMethod(
|
||||
'pwg.images.deleteOrphans',
|
||||
|
||||
Reference in New Issue
Block a user