311 lines
20 KiB
HTML
311 lines
20 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" enctype="multipart/form-data"
|
|
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="{{ form_values.get('report_date', 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="{{ form_values.get('notes', 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 border-top" id="photo-zone">
|
|
<div class="d-flex justify-content-between align-items-center mb-2">
|
|
<strong>Фотоотчёт</strong>
|
|
<span class="text-muted small">до {{ photo_limit }} фото · до {{ (photo_max_bytes / 1024 / 1024)|round(0)|int }} МБ · {{ photo_formats }}</span>
|
|
</div>
|
|
<div class="form-text mb-2">Фото привязываются к отчёту целиком. Можно выбрать файлы на компьютере или телефоне — из галереи или камерой, если это поддерживает устройство.</div>
|
|
|
|
{% if existing_photos %}
|
|
<div class="mb-3">
|
|
<div class="form-label">Сохранённые фотографии</div>
|
|
<div class="row g-2" id="existing-photos">
|
|
{% for photo in existing_photos %}
|
|
<div class="col-4 col-md-2">
|
|
<div class="border rounded p-1">
|
|
<img class="img-fluid rounded w-100"
|
|
style="aspect-ratio: 4 / 3; object-fit: cover;"
|
|
src="/projects/{{ project.id }}/daily-reports/{{ report.id }}/photos/{{ photo.id }}"
|
|
alt="{{ photo.original_name or ('Фото ' ~ photo.id) }}">
|
|
<div class="form-check mt-1">
|
|
<input class="form-check-input" type="checkbox"
|
|
name="delete_photo_{{ photo.id }}" value="1"
|
|
id="delete_photo_{{ photo.id }}">
|
|
<label class="form-check-label small text-danger"
|
|
for="delete_photo_{{ photo.id }}">Удалить</label>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
<div class="form-text">Существующие фото удаляются только по явной отметке «Удалить» и сохранению формы.</div>
|
|
</div>
|
|
{% endif %}
|
|
|
|
<div class="mb-2">
|
|
<label for="photo-input" class="form-label">Добавить фотографии</label>
|
|
<input class="form-control" type="file" id="photo-input" name="files"
|
|
accept="image/jpeg,image/png,image/webp,image/*" multiple>
|
|
</div>
|
|
<div class="row g-2" id="photo-preview"></div>
|
|
<div id="photo-empty" class="form-text">Новые файлы будут показаны миниатюрами здесь.</div>
|
|
</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();
|
|
|
|
// ---------- Фотоотчёт: миниатюры до сохранения ----------
|
|
const photoInput = document.getElementById('photo-input');
|
|
const photoPreview = document.getElementById('photo-preview');
|
|
const photoEmpty = document.getElementById('photo-empty');
|
|
if (photoInput && photoPreview) {
|
|
const renderPhotoPreview = () => {
|
|
photoPreview.textContent = '';
|
|
const files = [...photoInput.files];
|
|
if (photoEmpty) photoEmpty.hidden = files.length !== 0;
|
|
files.forEach((file, index) => {
|
|
const col = document.createElement('div');
|
|
col.className = 'col-4 col-md-2';
|
|
const box = document.createElement('div');
|
|
box.className = 'border rounded p-1';
|
|
const img = document.createElement('img');
|
|
img.className = 'img-fluid rounded w-100';
|
|
img.style.aspectRatio = '4 / 3';
|
|
img.style.objectFit = 'cover';
|
|
img.alt = file.name;
|
|
try {
|
|
img.src = URL.createObjectURL(file);
|
|
img.onload = () => URL.revokeObjectURL(img.src);
|
|
} catch { /* preview is best-effort */ }
|
|
const name = document.createElement('div');
|
|
name.className = 'small text-muted text-truncate';
|
|
name.textContent = file.name;
|
|
name.title = file.name;
|
|
const remove = document.createElement('button');
|
|
remove.type = 'button';
|
|
remove.className = 'btn btn-sm btn-outline-danger w-100 mt-1';
|
|
remove.textContent = 'Убрать';
|
|
remove.addEventListener('click', () => {
|
|
const dt = new DataTransfer();
|
|
[...photoInput.files].forEach((f, i) => { if (i !== index) dt.items.add(f); });
|
|
photoInput.files = dt.files;
|
|
renderPhotoPreview();
|
|
});
|
|
box.append(img, name, remove);
|
|
col.appendChild(box);
|
|
photoPreview.appendChild(col);
|
|
});
|
|
};
|
|
photoInput.addEventListener('change', renderPhotoPreview);
|
|
}
|
|
})();
|
|
</script>
|
|
</main>
|
|
</body>
|
|
</html>
|