feat(contacts): страница контактов — фильтры, алфавит, таблица с инлайн-правкой, карточка
- /contacts в раскладке c1/c2/c3: фильтры (общий поиск + организация, фамилия,
имя, отчество, должность, телефон, почта; состояние в URL через hx-push-url),
алфавит А-Я/A-Z/# (126 букв, пустые неактивны), sticky-фильтры + кнопка «Наверх»,
таблица 7 колонок с сортировкой, инлайн-правка ячеек (Alpine, Enter→PUT).
- Карточка контакта (c3): поля с инлайн-правкой, последние 5 полученных и 5
отправленных писем (db.emails_with_contact), задачи из писем
(radicale.get_tasks_by_email), служебный блок, кнопка 📋 → /api/tasks/create.
- API: GET /contacts (страница/HTMX-фрагмент), GET /contacts/{id},
GET /api/contacts, PUT /api/contact/{id}/field (валидация email/телефона).
- Экстрактор и CardDAV-синк: flock+atomic в save_json, manual_fields и
разобранные части ФИО не перезаписываются, N в vCard из last/first/middle,
PULL пропускается для caldav.dirty, dirty-контакты пушатся.
- tests/test_contacts_ui.py: 11 тестов (страница, фильтры, сортировка, алфавит,
карточка, API, 401/400/404, mocked-правка).
Проверено: 11/11 UI + 17/17 слоя данных, регресс smoke 7, tasktracker 8, move 14;
контейнер healthy, GET /contacts 200 за 132 мс (206 строк, 126 букв, фильтр
phone=79857201401 → 1); CardDAV push тестовой карточки → 200+etag, DELETE → 404;
правка поля на копии базы → manual_fields + etag, отказ CardDAV → dirty.
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
{% from "partials/_contact_macros.html" import edit_value %}
|
||||
<div class="cols" id="contacts-cols" style="flex:1">
|
||||
|
||||
<!-- колонка 1: фильтры + алфавитный указатель -->
|
||||
<div class="c1 cfit">
|
||||
<div class="ch"><span>👥 Фильтры</span><span class="cnt">{{ contacts|length }} из {{ total }}</span></div>
|
||||
<form class="cfilters" hx-get="/contacts" hx-target="#contacts-cols" hx-swap="outerHTML"
|
||||
hx-trigger="input changed delay:350ms, search, submit" hx-push-url="true"
|
||||
onsubmit="return false" autocomplete="off">
|
||||
<label class="cf">
|
||||
<span>Поиск по всем полям</span>
|
||||
<input type="search" name="q" id="cq" value="{{ filters.q or '' }}" placeholder="фамилия, компания, телефон, почта…">
|
||||
</label>
|
||||
<label class="cf"><span>Организация</span>
|
||||
<input name="company" value="{{ filters.company or '' }}" list="dl-company" placeholder="напр. Купаж">
|
||||
</label>
|
||||
<label class="cf"><span>Фамилия</span>
|
||||
<input name="last_name" value="{{ filters.last_name or '' }}" placeholder="Баулин">
|
||||
</label>
|
||||
<label class="cf"><span>Имя</span>
|
||||
<input name="first_name" value="{{ filters.first_name or '' }}" placeholder="Александр">
|
||||
</label>
|
||||
<label class="cf"><span>Отчество</span>
|
||||
<input name="middle_name" value="{{ filters.middle_name or '' }}" placeholder="Александрович">
|
||||
</label>
|
||||
<label class="cf"><span>Должность</span>
|
||||
<input name="position" value="{{ filters.position or '' }}" list="dl-position" placeholder="директор">
|
||||
</label>
|
||||
<label class="cf"><span>Телефон</span>
|
||||
<input name="phone" value="{{ filters.phone or '' }}" placeholder="79857201401">
|
||||
</label>
|
||||
<label class="cf"><span>Почта</span>
|
||||
<input name="email" value="{{ filters.email or '' }}" placeholder="a.baulin">
|
||||
</label>
|
||||
<div class="cfa">
|
||||
<button type="submit" class="btn">Найти</button>
|
||||
<a class="btn" href="/contacts">Сбросить</a>
|
||||
</div>
|
||||
{% if sort != 'last_name' %}<input type="hidden" name="sort" value="{{ sort }}">{% endif %}
|
||||
{% if dir != 'asc' %}<input type="hidden" name="dir" value="{{ dir }}">{% endif %}
|
||||
</form>
|
||||
|
||||
<datalist id="dl-company">
|
||||
{% for c in companies %}<option value="{{ c }}">{% endfor %}
|
||||
</datalist>
|
||||
<datalist id="dl-position">
|
||||
{% for p in positions %}<option value="{{ p }}">{% endfor %}
|
||||
</datalist>
|
||||
|
||||
<div class="alpha">
|
||||
{% for a in alphabet %}
|
||||
{% if a.count %}
|
||||
<a class="al{% if letter == a.letter %} act{% endif %}" title="{{ a.count }} конт."
|
||||
hx-get="{{ params_url('/contacts', params, letter=('' if letter == a.letter else a.letter)) }}"
|
||||
hx-target="#contacts-cols" hx-swap="outerHTML" hx-push-url="true">{{ a.letter }}</a>
|
||||
{% else %}
|
||||
<span class="al off" title="нет контактов">{{ a.letter }}</span>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- колонка 2: таблица -->
|
||||
<div class="c2 cwide">
|
||||
<div class="tb">
|
||||
<span class="tl">Контакты</span>
|
||||
{% if letter %}<span class="tagf">буква {{ letter }}</span>{% endif %}
|
||||
{% if filters.q %}<span class="tagf">«{{ filters.q }}»</span>{% endif %}
|
||||
</div>
|
||||
<div class="lw" id="clist">
|
||||
{% include "partials/contacts_table.html" %}
|
||||
</div>
|
||||
<button class="ctop" id="ctop" title="Наверх, к фильтрам"
|
||||
onclick="var l=document.getElementById('clist'); if(l) l.scrollTop=0; var q=document.getElementById('cq'); if(q) q.focus();">↑</button>
|
||||
</div>
|
||||
|
||||
<!-- колонка 3: карточка контакта -->
|
||||
<div class="c3" id="c3">
|
||||
{% include "partials/contact_card.html" %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
window.CTSave = function (data, id, field, value) {
|
||||
fetch('/api/contact/' + encodeURIComponent(id) + '/field', {
|
||||
method: 'PUT',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({field: field, value: value})
|
||||
}).then(function (r) {
|
||||
return r.json().then(function (d) { return d; });
|
||||
}).then(function (d) {
|
||||
if (d.error) { data.err = d.error; return; }
|
||||
data.val = d.value; data.edit = false;
|
||||
data.err = d.warning || '';
|
||||
var fn = document.getElementById('cfullname');
|
||||
if (fn && d.full_name) { fn.textContent = d.full_name; }
|
||||
}).catch(function (e) { data.err = 'ошибка: ' + e; });
|
||||
};
|
||||
(function () {
|
||||
var list = document.getElementById('clist'), top = document.getElementById('ctop');
|
||||
if (!list || !top) return;
|
||||
if (list._ctopHandler) list.removeEventListener('scroll', list._ctopHandler);
|
||||
list._ctopHandler = function () { top.style.display = list.scrollTop > 200 ? 'block' : 'none'; };
|
||||
list.addEventListener('scroll', list._ctopHandler);
|
||||
list._ctopHandler();
|
||||
})();
|
||||
</script>
|
||||
Reference in New Issue
Block a user