fixed columns bind

This commit is contained in:
2026-06-17 21:14:20 +03:00
parent 25c3990753
commit 2ad2e06dc2
7 changed files with 973 additions and 207 deletions
+113 -46
View File
@@ -37,6 +37,37 @@ foreach ($savedItems as $s) {
$resolvedItems[] = $s;
}
// Raggruppa le righe per campo (custom: mapping_id, fixed: fixed_field_key),
// mantenendo l'ordine di prima apparizione. Ogni gruppo elenca prima i pending.
$groups = [];
$groupOrder = [];
$pushToGroup = function (array $row, string $type, $idx = null) use (&$groups, &$groupOrder) {
$kind = $row['kind'] ?? 'custom';
$gkey = $kind === 'fixed'
? 'fx:' . ($row['fixed_field_key'] ?? '')
: 'cf:' . (int) ($row['mapping_id'] ?? 0);
if (!isset($groups[$gkey])) {
$groups[$gkey] = [
'label' => $row['field_label'] ?? $gkey,
'kind' => $kind,
'pending' => [],
'resolved' => [],
];
$groupOrder[] = $gkey;
}
if ($type === 'pending') {
$groups[$gkey]['pending'][] = ['idx' => $idx, 'data' => $row];
} else {
$groups[$gkey]['resolved'][] = ['data' => $row];
}
};
foreach ($items as $idx => $item) {
$pushToGroup($item, 'pending', $idx);
}
foreach ($resolvedItems as $res) {
$pushToGroup($res, 'resolved');
}
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
$stmt = $pdo->prepare("SELECT name FROM excel_templates WHERE id = ?");
@@ -124,52 +155,74 @@ $templateName = $stmt->fetchColumn() ?: ('Template ' . $templateId);
<table class="table table-bordered align-middle">
<thead>
<tr>
<th>Campo (template_mapping)</th>
<th style="width:32px;"></th>
<th>Valore JSON</th>
<th>Valore LIMS</th>
<th style="width:210px;">Azioni</th>
</tr>
</thead>
<tbody>
<?php foreach ($items as $idx => $item): ?>
<tr class="binding-row"
data-index="<?= $idx ?>"
data-mapping-id="<?= (int) $item['mapping_id'] ?>"
data-field-id="<?= (int) $item['field_id'] ?>"
data-json-value="<?= htmlspecialchars($item['json_value'], ENT_QUOTES) ?>"
data-datadb-ids="<?= htmlspecialchars(json_encode($item['datadb_ids']), ENT_QUOTES) ?>">
<td class="text-muted"><?= htmlspecialchars($item['field_label']) ?></td>
<td class="json-value"><?= htmlspecialchars($item['json_value']) ?></td>
<td>
<select class="form-select binding-select" data-field-id="<?= (int) $item['field_id'] ?>">
<option value="">Seleziona valore LIMS...</option>
</select>
</td>
<td>
<button type="button" class="btn btn-sm btn-outline-secondary skip-binding-btn">Nessuna corrispondenza</button>
<div class="binding-status text-muted mt-1">In attesa</div>
<?php foreach ($groupOrder as $gkey): $g = $groups[$gkey];
$pendCount = count($g['pending']);
$totalCount = $pendCount + count($g['resolved']); ?>
<tr class="binding-group-header table-light">
<td colspan="4">
<strong><?= htmlspecialchars($g['label']) ?></strong>
<?php if ($g['kind'] === 'fixed'): ?><span class="badge bg-light text-dark border">fixed</span><?php endif; ?>
<span class="text-muted">&middot; <?= $totalCount ?> valore/i<?php if ($pendCount): ?>, <?= $pendCount ?> da risolvere<?php endif; ?></span>
</td>
</tr>
<?php endforeach; ?>
<?php foreach ($resolvedItems as $res): ?>
<tr class="binding-row"
data-mapping-id="<?= (int) $res['mapping_id'] ?>"
data-field-id="<?= (int) $res['field_id'] ?>"
data-json-value="<?= htmlspecialchars($res['json_value'], ENT_QUOTES) ?>"
data-datadb-ids="<?= htmlspecialchars(json_encode($res['datadb_ids']), ENT_QUOTES) ?>">
<td class="text-muted"><?= htmlspecialchars($res['field_label']) ?></td>
<td class="json-value"><?= htmlspecialchars($res['json_value']) ?></td>
<td>
<select class="form-select binding-select" data-field-id="<?= (int) $res['field_id'] ?>">
<option value="<?= (int) $res['lims_value_id'] ?>" selected><?= htmlspecialchars($res['lims_value']) ?></option>
</select>
</td>
<td>
<button type="button" class="btn btn-sm btn-outline-secondary skip-binding-btn">Nessuna corrispondenza</button>
<div class="binding-status mt-1"><span class="badge <?= $res['badge_class'] ?>"><?= $res['badge'] ?></span></div>
</td>
</tr>
<?php foreach ($g['pending'] as $p): $idx = $p['idx']; $item = $p['data']; $kind = $item['kind'] ?? 'custom'; ?>
<tr class="binding-row"
data-index="<?= $idx ?>"
data-kind="<?= $kind ?>"
<?php if ($kind === 'fixed'): ?>
data-fixed-key="<?= htmlspecialchars($item['fixed_field_key'], ENT_QUOTES) ?>"
<?php else: ?>
data-mapping-id="<?= (int) ($item['mapping_id'] ?? 0) ?>"
data-field-id="<?= (int) ($item['field_id'] ?? 0) ?>"
<?php endif; ?>
data-json-value="<?= htmlspecialchars($item['json_value'], ENT_QUOTES) ?>"
data-datadb-ids="<?= htmlspecialchars(json_encode($item['datadb_ids']), ENT_QUOTES) ?>">
<td class="text-muted ps-4">&rsaquo;</td>
<td class="json-value"><?= htmlspecialchars($item['json_value']) ?></td>
<td>
<select class="form-select binding-select">
<option value="">Seleziona valore LIMS...</option>
</select>
</td>
<td>
<button type="button" class="btn btn-sm btn-outline-secondary skip-binding-btn">Nessuna corrispondenza</button>
<div class="binding-status text-muted mt-1">In attesa</div>
</td>
</tr>
<?php endforeach; ?>
<?php foreach ($g['resolved'] as $r): $res = $r['data']; $kind = $res['kind'] ?? 'custom'; ?>
<tr class="binding-row"
data-kind="<?= $kind ?>"
<?php if ($kind === 'fixed'): ?>
data-fixed-key="<?= htmlspecialchars($res['fixed_field_key'], ENT_QUOTES) ?>"
<?php else: ?>
data-mapping-id="<?= (int) ($res['mapping_id'] ?? 0) ?>"
data-field-id="<?= (int) ($res['field_id'] ?? 0) ?>"
<?php endif; ?>
data-json-value="<?= htmlspecialchars($res['json_value'], ENT_QUOTES) ?>"
data-datadb-ids="<?= htmlspecialchars(json_encode($res['datadb_ids']), ENT_QUOTES) ?>">
<td class="text-muted ps-4">&rsaquo;</td>
<td class="json-value"><?= htmlspecialchars($res['json_value']) ?></td>
<td>
<select class="form-select binding-select">
<option value="<?= (int) $res['lims_value_id'] ?>" selected><?= htmlspecialchars($res['lims_value']) ?></option>
</select>
</td>
<td>
<button type="button" class="btn btn-sm btn-outline-secondary skip-binding-btn">Nessuna corrispondenza</button>
<div class="binding-status mt-1"><span class="badge <?= $res['badge_class'] ?>"><?= $res['badge'] ?></span></div>
</td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>
@@ -206,21 +259,29 @@ $templateName = $stmt->fetchColumn() ?: ('Template ' . $templateId);
const $btn = $('#confirmBindingsBtn');
const $error = $('#bindingError');
// Dropdown valori LIMS per riga (search_customfield_values.php).
// Dropdown valori LIMS per riga: sorgente custom vs fixed.
$('.binding-select').each(function() {
const fieldId = $(this).data('field-id');
const $row = $(this).closest('.binding-row');
const kind = $row.data('kind');
const isFixed = kind === 'fixed';
$(this).select2({
placeholder: 'Seleziona valore LIMS...',
width: '100%',
ajax: {
url: 'search_customfield_values.php',
url: isFixed ? 'search_fixed_field_values.php' : 'search_customfield_values.php',
dataType: 'json',
delay: 200,
data: params => ({
field_id: fieldId,
data: params => isFixed ? {
field_key: $row.data('fixed-key'),
template_id: TEMPLATE_ID,
q: params.term || '',
limit: 50
}),
} : {
field_id: $row.data('field-id'),
q: params.term || '',
limit: 50
},
processResults: data => ({
results: data.results || []
})
@@ -262,13 +323,20 @@ $templateName = $stmt->fetchColumn() ?: ('Template ' . $templateId);
const tasks = $('.binding-row').toArray().map(row => {
const $row = $(row);
const $status = $row.find('.binding-status');
const kind = $row.data('kind');
const isFixed = kind === 'fixed';
const datadbIds = JSON.stringify($row.data('datadb-ids') || []);
const jsonValue = String($row.data('json-value'));
const targetFields = isFixed
? { kind: 'fixed', fixed_field_key: $row.data('fixed-key') }
: { kind: 'custom', mapping_id: $row.data('mapping-id'), field_id: $row.data('field-id') };
// Riga senza corrispondenza: azzera il valore, niente binding.
if ($row.hasClass('is-skipped')) {
return $.post('skip_binding.php', {
mapping_id: $row.data('mapping-id'),
...targetFields,
template_id: TEMPLATE_ID,
json_value: jsonValue,
datadb_ids: datadbIds
}).then(resp => {
@@ -285,8 +353,7 @@ $templateName = $stmt->fetchColumn() ?: ('Template ' . $templateId);
const selectedData = $select.select2('data')[0] || {};
return $.post('save_binding.php', {
mapping_id: $row.data('mapping-id'),
field_id: $row.data('field-id'),
...targetFields,
template_id: TEMPLATE_ID,
json_value: jsonValue,
lims_value_id: $select.val(),