Refactor batch sorting functionality and update version code to 4.72.755

This commit enhances the batch sorting mechanism by introducing new functions to normalize and manage sorting keys for bib assignments. The AJAX handlers are updated to utilize these new sorting parameters, improving the overall flexibility and accuracy of batch operations. Additionally, the version code is incremented to reflect these changes.
This commit is contained in:
2026-07-08 11:05:00 -04:00
parent 7d342216f8
commit 588d573703
6 changed files with 526 additions and 96 deletions

View File

@ -201,13 +201,45 @@
});
}
function bibFetchBatchApplyChunk(row, selected, ba_id, opts) {
function bibGetRowSortKeys(row) {
if (!row) {
return { sort1: '', sort2: '' };
}
var s1 = row.querySelector('.batch-order');
var s2 = row.querySelector('.batch-order-2');
return {
sort1: s1 ? s1.value : '',
sort2: s2 ? s2.value : ''
};
}
function bibGetGlobalBatchSortKeys(panel) {
if (!panel) {
return { sort1: '', sort2: '' };
}
var s1 = panel.querySelector('.bib-global-batch-order');
var s2 = panel.querySelector('.bib-global-batch-order-2');
return {
sort1: s1 ? s1.value : '',
sort2: s2 ? s2.value : ''
};
}
function bibAppendBatchSortParams(body, sortKeys) {
sortKeys = sortKeys || {};
return body
+ '&sort_1=' + encodeURIComponent(sortKeys.sort1 || '')
+ '&sort_2=' + encodeURIComponent(sortKeys.sort2 || '');
}
function bibFetchBatchApplyChunk(row, selected, sortKeys, opts) {
opts = opts || {};
sortKeys = sortKeys || bibGetRowSortKeys(row);
var body =
'action=batch_apply_chunk'
+ '&epr_id=' + encodeURIComponent(row.dataset.eprId)
+ '&ranges=' + encodeURIComponent(JSON.stringify(selected))
+ '&ba_id=' + encodeURIComponent(ba_id)
+ bibAppendBatchSortParams('', sortKeys)
+ '&chunk_size=' + BIB_BATCH_CHUNK_SIZE
+ '&total_initial=' + (opts.totalInitial || 0)
+ '&batch_reset=' + (opts.batchReset ? 1 : 0)
@ -232,7 +264,7 @@
});
}
function bibRunBatchApplyChunks(row, selected, ba_id, options) {
function bibRunBatchApplyChunks(row, selected, sortKeys, options) {
options = options || {};
var showResult = options.showResult !== false;
var manageLoader = options.manageLoader !== false;
@ -255,7 +287,7 @@
return Promise.reject(new Error(bibJs('jsErrGeneric')));
}
return bibFetchBatchApplyChunk(row, selected, ba_id, {
return bibFetchBatchApplyChunk(row, selected, sortKeys, {
batchReset: batchReset,
totalInitial: totalInitial
}).then(function (data) {
@ -438,9 +470,9 @@
var plans = bibCollectGlobalBatchPlans();
var infoEl = bibGlobalBatchPanel.querySelector('.bib-global-batch__info');
var baSelect = bibGlobalBatchPanel.querySelector('.bib-global-batch-order');
var sortKeys = bibGetGlobalBatchSortKeys(bibGlobalBatchPanel);
if (!infoEl || !baSelect) {
if (!infoEl) {
return Promise.resolve();
}
@ -471,7 +503,7 @@
body:
'action=batch_global_analysis'
+ '&eve_id=' + encodeURIComponent(moduleBib.dataset.eveId || '')
+ '&ba_id=' + encodeURIComponent(baSelect.value)
+ bibAppendBatchSortParams('', sortKeys)
+ '&plans=' + encodeURIComponent(JSON.stringify(plans))
+ bibAjaxLangSuffix()
})
@ -503,7 +535,7 @@
}
var plans = bibCollectGlobalBatchPlans();
var baSelect = bibGlobalBatchPanel.querySelector('.bib-global-batch-order');
var sortKeys = bibGetGlobalBatchSortKeys(bibGlobalBatchPanel);
if (plans.length === 0) {
alert(bibJs('jsGlobalNoEpr') || bibJs('jsBatchNone'));
@ -515,15 +547,13 @@
return;
}
var ba_id = baSelect ? baSelect.value : '';
fetch('/ajax_bib_range.php', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body:
'action=batch_global_analysis'
+ '&eve_id=' + encodeURIComponent(moduleBib.dataset.eveId || '')
+ '&ba_id=' + encodeURIComponent(ba_id)
+ bibAppendBatchSortParams('', sortKeys)
+ '&plans=' + encodeURIComponent(JSON.stringify(plans))
+ bibAjaxLangSuffix()
})
@ -558,7 +588,7 @@
var pendingBefore = bibRowPendingBibs(row);
var offset = completedOffset;
return bibRunBatchApplyChunks(row, plan.ranges, ba_id, {
return bibRunBatchApplyChunks(row, plan.ranges, sortKeys, {
showResult: false,
manageLoader: false,
deferUiRefresh: true,
@ -680,9 +710,9 @@
e.preventDefault();
var bibGlobalBatchPanel = bibGetGlobalBatchPanel();
var plans = bibCollectGlobalBatchPlans();
var baSelect = bibGlobalBatchPanel
? bibGlobalBatchPanel.querySelector('.bib-global-batch-order')
: null;
var sortKeys = bibGlobalBatchPanel
? bibGetGlobalBatchSortKeys(bibGlobalBatchPanel)
: { sort1: '', sort2: '' };
if (plans.length === 0) {
alert(bibJs('jsGlobalNoEpr') || bibJs('jsBatchNone'));
@ -695,7 +725,7 @@
body:
'action=batch_global_simulate'
+ '&eve_id=' + encodeURIComponent(moduleBib.dataset.eveId || '')
+ '&ba_id=' + encodeURIComponent(baSelect ? baSelect.value : '')
+ bibAppendBatchSortParams('', sortKeys)
+ '&plans=' + encodeURIComponent(JSON.stringify(plans))
+ bibAjaxLangSuffix()
})
@ -727,7 +757,7 @@
});
moduleBib.addEventListener('change', function (e) {
if (!e.target.matches('.bib-global-epr-select, .bib-global-range-select, .bib-global-batch-order')) {
if (!e.target.matches('.bib-global-epr-select, .bib-global-range-select, .bib-global-batch-order, .bib-global-batch-order-2')) {
return;
}
@ -1694,6 +1724,7 @@
bibSetVisible('.epr-auto-info-group', showAutoReady, row);
bibSetVisible('.batch-reset-warning', showBatchReady && modes.reset, row);
bibSetVisible('.epr-batch-order-wrap', showBatchReady && !modes.reset, row);
bibSetVisible('.epr-batch-order-wrap--secondary', showBatchReady && !modes.reset, row);
bibSetVisible('.epr-action-sim-group', showBatchReady && !modes.reset, row);
bibSetVisible('.epr-action-go-group', showBatchReady, row);
bibSyncResetAllEprButton(row);
@ -2399,7 +2430,7 @@
return;
}
let isResetMode = row.dataset.mode === 'reset';
let ba_id = row.querySelector('.batch-order').value;
let sortKeys = bibGetRowSortKeys(row);
bibFetch('/ajax_bib_range.php', {
method: 'POST',
@ -2410,7 +2441,7 @@
(isResetMode ? 'action=reset_preview' : 'action=batch_go')
+ '&epr_id=' + encodeURIComponent(row.dataset.eprId)
+ '&ranges=' + encodeURIComponent(JSON.stringify(selected))
+ '&ba_id=' + encodeURIComponent(ba_id)
+ bibAppendBatchSortParams('', sortKeys)
+ bibAjaxLangSuffix()
})
.then(res => res.json())
@ -2559,7 +2590,7 @@
return;
}
let isResetMode = row.dataset.mode === 'reset';
let ba_id = row.querySelector('.batch-order').value;
let sortKeys = bibGetRowSortKeys(row);
if (isResetMode) {
bibFetch('/ajax_bib_range.php', {
@ -2571,7 +2602,7 @@
'action=reset_apply'
+ '&epr_id=' + encodeURIComponent(row.dataset.eprId)
+ '&ranges=' + encodeURIComponent(JSON.stringify(selected))
+ '&ba_id=' + encodeURIComponent(ba_id)
+ bibAppendBatchSortParams('', sortKeys)
+ bibAjaxLangSuffix()
})
.then(res => res.json())
@ -2588,7 +2619,7 @@
return;
}
bibRunBatchApplyChunks(row, selected, ba_id);
bibRunBatchApplyChunks(row, selected, sortKeys);
return;
}