e7abc7c86c
Split the Daily Report form into a top position picker (system filter, live search) and a bottom added-items list grouped by system, with quantity edit and remove. Switching systems no longer drops the added list; A1->B1->A2 keeps all three. Quantity can be entered in the picker before pressing Добавить and is carried into the selected list; removing a position returns it to the picker with the typed quantity intact. Draft quantities of never-added positions stay out of POST via a submit guard, so they never become Daily Report facts. Server rows are always rendered client-filtered; POST contract and apply_quantities unchanged.
221 lines
14 KiB
HTML
221 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="ru">
|
|
<head>
|
|
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>{{ 'Редактирование' if report else 'Новый' }} Daily Report — {{ project.name }}</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<style>
|
|
#picker-scroll { max-height: 420px; overflow-x: auto; overflow-y: auto; }
|
|
.item-action { white-space: nowrap; }
|
|
.table-compact { width: 100%; table-layout: fixed; }
|
|
.table-compact th, .table-compact td { padding-left: .35rem; padding-right: .35rem; overflow-wrap: anywhere; }
|
|
.sel-group td { background: #f8f9fa; }
|
|
</style>
|
|
</head>
|
|
<body class="bg-light">
|
|
<main class="container py-4">
|
|
<nav class="mb-3"><ol class="breadcrumb"><li class="breadcrumb-item"><a href="/projects/">Проекты</a></li><li class="breadcrumb-item"><a href="/projects/{{ project.id }}">{{ project.name }}</a></li><li class="breadcrumb-item"><a href="/projects/{{ project.id }}/daily-reports">Daily Reports</a></li><li class="breadcrumb-item active">{{ 'Редактирование' if report else 'Новый отчёт' }}</li></ol></nav>
|
|
<h1>{{ 'Редактировать Daily Report' if report else 'Новый Daily Report' }}</h1>
|
|
{% for error in errors %}<div class="alert alert-danger">{{ error }}</div>{% endfor %}
|
|
|
|
<form method="post" action="{% if report %}/projects/{{ project.id }}/daily-reports/{{ report.id }}/edit{% else %}/projects/{{ project.id }}/daily-reports{% endif %}">
|
|
<input type="hidden" name="system_id" id="hidden-system-id" value="{{ selected_system.id if selected_system else ('unclassified' if unclassified_selected else '') }}">
|
|
<div class="card card-body mb-3">
|
|
<div class="row g-3">
|
|
<div class="col-md-4"><label for="report-date" class="form-label">Дата отчёта</label><input id="report-date" class="form-control" type="date" name="report_date" required value="{{ report.report_date.isoformat() if report else '' }}"></div>
|
|
<div class="col-md-8"><label for="notes" class="form-label">Комментарий</label><input id="notes" class="form-control" name="notes" value="{{ report.notes if report and report.notes else '' }}"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- ============ Зона 1: подбор позиций ============ -->
|
|
<div class="card mb-3" id="picker-zone">
|
|
<div class="card-header"><strong>Подбор позиций</strong></div>
|
|
<div class="card-body py-2">
|
|
<div class="row g-2">
|
|
<div class="col-12 col-md-4">
|
|
<label for="system-picker" class="form-label">Система</label>
|
|
<select id="system-picker" class="form-select">
|
|
<option value="">Выберите систему</option>
|
|
{% for system in systems %}<option value="{{ system.id }}" {% if selected_system and selected_system.id == system.id %}selected{% endif %}>{{ system.name }}</option>{% endfor %}
|
|
{% if has_unclassified_items %}<option value="unclassified" {% if unclassified_selected %}selected{% endif %}>Проектные позиции без системы</option>{% endif %}
|
|
</select>
|
|
</div>
|
|
<div class="col-12 col-md-8">
|
|
<label for="position-search" class="form-label">Поиск</label>
|
|
<input id="position-search" class="form-control" type="search" autocomplete="off" placeholder="Номер, наименование, модель или производитель">
|
|
</div>
|
|
</div>
|
|
<div class="form-text">Выберите систему, при необходимости введите количество и нажмите «Добавить». Позиции разных систем можно добавлять в один отчёт — уже добавленные при смене системы сохраняются.</div>
|
|
</div>
|
|
<div id="picker-scroll" class="table-responsive">
|
|
<table class="table table-sm table-hover align-middle mb-0 table-compact">
|
|
<thead class="table-light"><tr><th class="d-none d-md-table-cell">Раздел</th><th>№</th><th>Рабочая позиция</th><th>Ед.</th><th style="width: 118px">Количество</th><th class="text-end" style="width: 104px" aria-label="Действие"></th></tr></thead>
|
|
<tbody id="picker-body">
|
|
{% for row in rows %}{% if row.current_quantity is none %}
|
|
<tr class="position-row" data-number="{{ row.item.source_number or '' }}" data-name="{{ row.item.name or '' }}" data-model="{{ row.item.model or '' }}" data-manufacturer="{{ row.item.manufacturer or '' }}" data-system="{{ row.item.system_id if row.item.system_id is not none else 'unclassified' }}" data-system-name="{{ row.item.system.name if row.item.system else 'Без системы' }}" data-section="{{ row.item.section.name if row.item.section else '—' }}" {% if not row.in_selection %}hidden{% endif %}>
|
|
<td class="d-none d-md-table-cell">{{ row.item.section.name if row.item.section else '—' }}</td>
|
|
<td>{{ row.item.source_number or '' }}</td>
|
|
<td>{{ row.item.name }}<div class="small text-muted">План: {{ row.planned_quantity if row.planned_quantity is not none else '—' }} · Накоплено: {{ row.accumulated }}</div></td>
|
|
<td>{{ row.item.unit or '' }}</td>
|
|
<td><input class="form-control form-control-sm picker-qty" type="number" min="0" step="0.0001" name="quantity_{{ row.item.id }}" value="" data-item-id="{{ row.item.id }}" aria-label="Выполнено: {{ row.item.name }}"></td>
|
|
<td class="text-end"><button type="button" class="btn btn-sm btn-outline-success item-action" data-action="add">Добавить</button></td>
|
|
</tr>
|
|
{% endif %}{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div id="picker-empty" class="card-footer text-muted" hidden>Совпадений нет.</div>
|
|
</div>
|
|
|
|
<!-- ============ Зона 2: добавленные позиции ============ -->
|
|
<div class="card mb-3" id="selected-zone">
|
|
<div class="card-header"><strong>Добавленные позиции</strong> — укажите фактическое количество хотя бы для одной</div>
|
|
<div class="table-responsive">
|
|
<table class="table table-sm align-middle mb-0">
|
|
<thead class="table-light"><tr><th class="d-none d-md-table-cell">Раздел</th><th>№</th><th>Наименование</th><th>Ед.</th><th style="width: 118px">Количество</th><th class="text-end" style="width: 96px" aria-label="Действие"></th></tr></thead>
|
|
<tbody id="selected-body">
|
|
{% for row in rows %}{% if row.current_quantity is not none %}
|
|
<tr class="position-row" data-number="{{ row.item.source_number or '' }}" data-name="{{ row.item.name or '' }}" data-model="{{ row.item.model or '' }}" data-manufacturer="{{ row.item.manufacturer or '' }}" data-system="{{ row.item.system_id if row.item.system_id is not none else 'unclassified' }}" data-system-name="{{ row.item.system.name if row.item.system else 'Без системы' }}" data-section="{{ row.item.section.name if row.item.section else '—' }}">
|
|
<td class="d-none d-md-table-cell">{{ row.item.section.name if row.item.section else '—' }}</td>
|
|
<td>{{ row.item.source_number or '' }}</td>
|
|
<td>{{ row.item.name }}</td>
|
|
<td>{{ row.item.unit or '' }}</td>
|
|
<td><input class="form-control form-control-sm" type="number" min="0" step="0.0001" name="quantity_{{ row.item.id }}" value="{{ row.current_quantity }}" aria-label="Выполнено: {{ row.item.name }}"></td>
|
|
<td class="text-end"><button type="button" class="btn btn-sm btn-outline-danger item-action" data-action="remove">Удалить</button></td>
|
|
</tr>
|
|
{% endif %}{% endfor %}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<div id="selected-empty" class="card-footer text-muted" hidden>Пока ничего не добавлено.</div>
|
|
<div class="card-footer d-flex justify-content-between">
|
|
<a class="btn btn-outline-secondary" href="/projects/{{ project.id }}/daily-reports">Отмена</a>
|
|
<button class="btn btn-primary" type="submit">{{ 'Сохранить изменения' if report else 'Создать отчёт' }}</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
|
|
<script>
|
|
(() => {
|
|
const pickerBody = document.getElementById('picker-body');
|
|
const selectedBody = document.getElementById('selected-body');
|
|
const systemPicker = document.getElementById('system-picker');
|
|
const search = document.getElementById('position-search');
|
|
const pickerEmpty = document.getElementById('picker-empty');
|
|
const selectedEmpty = document.getElementById('selected-empty');
|
|
const hiddenSystem = document.getElementById('hidden-system-id');
|
|
if (!pickerBody || !selectedBody) return;
|
|
|
|
const normalize = value => (value || '').toLocaleLowerCase('ru-RU').trim();
|
|
|
|
const applyPickerFilter = () => {
|
|
const selected = systemPicker ? systemPicker.value : '';
|
|
const query = normalize(search ? search.value : '');
|
|
let visible = 0;
|
|
for (const row of pickerBody.querySelectorAll('tr.position-row')) {
|
|
const inSystem = selected !== '' && row.dataset.system === selected;
|
|
const haystack = normalize(['number', 'name', 'model', 'manufacturer']
|
|
.map(key => row.dataset[key]).join(' '));
|
|
const show = inSystem && haystack.includes(query);
|
|
row.hidden = !show;
|
|
if (show) visible++;
|
|
}
|
|
if (pickerEmpty) pickerEmpty.hidden = visible !== 0;
|
|
};
|
|
|
|
const setAddedState = (row, added) => {
|
|
const input = row.querySelector('input[name^="quantity_"]');
|
|
const btn = row.querySelector('.item-action');
|
|
if (input) {
|
|
// DOC-C11: the same input travels with the row, so the typed
|
|
// quantity survives add / remove / filter / system switch.
|
|
input.disabled = false;
|
|
}
|
|
if (btn) {
|
|
btn.dataset.action = added ? 'remove' : 'add';
|
|
btn.textContent = added ? 'Удалить' : 'Добавить';
|
|
btn.classList.toggle('btn-outline-success', !added);
|
|
btn.classList.toggle('btn-outline-danger', added);
|
|
}
|
|
};
|
|
|
|
const rebuildSelected = () => {
|
|
const rows = [...selectedBody.querySelectorAll('tr.position-row')];
|
|
rows.sort((a, b) => {
|
|
const bySystem = (a.dataset.systemName || '').localeCompare(b.dataset.systemName || '', 'ru');
|
|
if (bySystem !== 0) return bySystem;
|
|
return (a.dataset.number || '').localeCompare(b.dataset.number || '', 'ru', { numeric: true });
|
|
});
|
|
selectedBody.textContent = '';
|
|
let lastSystem = null;
|
|
for (const row of rows) {
|
|
const systemName = row.dataset.systemName || 'Без системы';
|
|
if (systemName !== lastSystem) {
|
|
const group = document.createElement('tr');
|
|
group.className = 'sel-group';
|
|
const cell = document.createElement('td');
|
|
cell.colSpan = 6;
|
|
const strong = document.createElement('strong');
|
|
strong.textContent = systemName;
|
|
cell.appendChild(strong);
|
|
group.appendChild(cell);
|
|
selectedBody.appendChild(group);
|
|
lastSystem = systemName;
|
|
}
|
|
row.hidden = false;
|
|
selectedBody.appendChild(row);
|
|
}
|
|
if (selectedEmpty) selectedEmpty.hidden = rows.length !== 0;
|
|
};
|
|
|
|
const moveToSelected = row => {
|
|
setAddedState(row, true);
|
|
selectedBody.appendChild(row);
|
|
rebuildSelected();
|
|
applyPickerFilter();
|
|
};
|
|
|
|
const moveToPicker = row => {
|
|
setAddedState(row, false);
|
|
pickerBody.appendChild(row);
|
|
rebuildSelected();
|
|
applyPickerFilter();
|
|
};
|
|
|
|
document.addEventListener('click', event => {
|
|
const btn = event.target.closest('.item-action');
|
|
if (!btn) return;
|
|
const row = btn.closest('tr.position-row');
|
|
if (!row) return;
|
|
if (btn.dataset.action === 'add') moveToSelected(row);
|
|
else moveToPicker(row);
|
|
});
|
|
|
|
// DOC-C11: quantities typed in the picker but never submitted with
|
|
// "Добавить" must not reach POST / become Daily Report facts.
|
|
const form = pickerBody.closest('form');
|
|
if (form) {
|
|
form.addEventListener('submit', () => {
|
|
for (const row of pickerBody.querySelectorAll('tr.position-row')) {
|
|
const input = row.querySelector('input[name^="quantity_"]');
|
|
if (input) input.disabled = true;
|
|
}
|
|
});
|
|
}
|
|
|
|
if (systemPicker) {
|
|
systemPicker.addEventListener('change', () => {
|
|
if (hiddenSystem) hiddenSystem.value = systemPicker.value;
|
|
applyPickerFilter();
|
|
});
|
|
}
|
|
if (search) search.addEventListener('input', applyPickerFilter);
|
|
|
|
rebuildSelected();
|
|
applyPickerFilter();
|
|
})();
|
|
</script>
|
|
</main>
|
|
</body>
|
|
</html>
|