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:
@@ -23,6 +23,9 @@
|
||||
<a class="nav {% if page == 'emails' %}act{% endif %}" href="/emails" title="">
|
||||
<span>📥</span><span class="tip">Письма</span>
|
||||
</a>
|
||||
<a class="nav {% if page == 'contacts' %}act{% endif %}" href="/contacts" title="">
|
||||
<span>👥</span><span class="tip">Контакты</span>
|
||||
</a>
|
||||
<a class="nav {% if page == 'search' %}act{% endif %}" href="/search" title="">
|
||||
<span>🔍</span><span class="tip">Поиск</span>
|
||||
</a>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
{% extends "base.html" %}
|
||||
{% block title %}Email Assistant — Контакты{% endblock %}
|
||||
{% block content %}
|
||||
{% include "partials/contacts_content.html" %}
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,12 @@
|
||||
{% macro edit_value(contact, field) -%}
|
||||
<div class="ed" x-data="{edit:false, val:{{ (contact.get(field) or '')|tojson }}, err:''}">
|
||||
<span class="cellv" x-show="!edit" x-on:click.stop="edit=true"
|
||||
title="клик — редактировать">{{ contact.get(field) or '—' }}</span>
|
||||
<template x-if="edit">
|
||||
<input x-model="val" x-on:click.stop x-on:keyup.enter="window.CTSave($data,'{{ contact.id }}','{{ field }}',val)"
|
||||
x-on:keyup.escape="edit=false" x-on:blur="edit=false"
|
||||
x-init="$nextTick(()=>$el.focus())">
|
||||
</template>
|
||||
<div class="cerr" x-show="err" x-text="err"></div>
|
||||
</div>
|
||||
{%- endmacro %}
|
||||
@@ -0,0 +1,91 @@
|
||||
{% from "partials/_contact_macros.html" import edit_value %}
|
||||
{% if current %}
|
||||
<div class="ccard">
|
||||
<div class="chd">
|
||||
<div style="flex:1;min-width:0">
|
||||
<div class="cname" id="cfullname">{{ current.get('full_name') or '(без имени)' }}</div>
|
||||
<div class="cmeta">
|
||||
{{ current.get('company') or '—' }}{% if current.get('position') %} · {{ current.get('position') }}{% endif %}
|
||||
</div>
|
||||
<div class="cmeta2">
|
||||
{% if current.get('email') %}<a href="mailto:{{ current.get('email') }}">{{ current.get('email') }}</a>{% endif %}
|
||||
{% if current.get('phone') %} · {{ current.get('phone') }}{% endif %}
|
||||
{% if current.get('caldav', {}).get('dirty') %}<span class="dirty" title="правка не ушла в CardDAV">не синхронизировано</span>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<button class="pb-btn" title="Создать задачу из переписки с контактом"
|
||||
onclick="CTTask(this, {{ (current.get('id') or '')|tojson }})">📋</button>
|
||||
</div>
|
||||
|
||||
<div class="cfields">
|
||||
{% for field, title in [('last_name','Фамилия'), ('first_name','Имя'), ('middle_name','Отчество'),
|
||||
('company','Компания'), ('position','Должность'), ('phone','Телефон'),
|
||||
('phone_secondary','Телефон 2'), ('email','Почта'), ('address','Адрес')] %}
|
||||
<div class="cfld">
|
||||
<div class="cfl">{{ title }}</div>
|
||||
{{ edit_value(current, field) }}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="cmails">
|
||||
<div class="csec">
|
||||
<div class="csh">📥 Полученные <span class="cnt">{{ mails.received|length }}</span></div>
|
||||
{% for m in mails.received %}
|
||||
<a class="cm" href="/emails?path={{ m.path|urlencode }}">
|
||||
<span class="d">{{ (m.date or '')[:10] }}</span>
|
||||
<span class="s">{{ m.subject or '(без темы)' }}</span>
|
||||
</a>
|
||||
{% else %}
|
||||
<div class="empty">писем нет</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="csec">
|
||||
<div class="csh">📤 Отправленные <span class="cnt">{{ mails.sent|length }}</span></div>
|
||||
{% for m in mails.sent %}
|
||||
<a class="cm" href="/emails?path={{ m.path|urlencode }}">
|
||||
<span class="d">{{ (m.date or '')[:10] }}</span>
|
||||
<span class="s">{{ m.subject or '(без темы)' }}</span>
|
||||
</a>
|
||||
{% else %}
|
||||
<div class="empty">писем нет</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if ctasks %}
|
||||
<div class="csec">
|
||||
<div class="csh">✅ Задачи из писем <span class="cnt">{{ ctasks|length }}</span></div>
|
||||
{% for t in ctasks %}
|
||||
<div class="cm">
|
||||
<span class="d">{{ t.due or '' }}</span>
|
||||
<span class="s{% if t.completed %} done{% endif %}">{{ t.summary }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="csys">
|
||||
<span>id: {{ current.get('id') }}</span>
|
||||
{% if current.get('caldav', {}).get('uid') %}<span>CardDAV: {{ current.get('caldav', {}).get('uid') }}</span>{% endif %}
|
||||
{% if current.get('first_seen') %}<span>впервые: {{ current.get('first_seen') }}</span>{% endif %}
|
||||
{% if current.get('source_folders') %}<span>папки: {{ current.get('source_folders')|join(', ') }}</span>{% endif %}
|
||||
{% if current.get('manual_fields') %}<span>правки: {{ current.get('manual_fields')|join(', ') }}</span>{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function CTTask(btn, contactId) {
|
||||
var fd = new FormData();
|
||||
fd.append('subject', document.getElementById('cfullname').textContent.trim());
|
||||
fd.append('from', {{ (current.get('email') or '')|tojson }});
|
||||
fd.append('body', 'контакт: ' + contactId);
|
||||
fetch('/api/tasks/create', {method: 'POST', body: fd})
|
||||
.then(function (r) { return r.text(); })
|
||||
.then(function () { btn.textContent = '✓'; btn.disabled = true; })
|
||||
.catch(function () { btn.textContent = '✗'; });
|
||||
}
|
||||
</script>
|
||||
{% else %}
|
||||
<div class="empty">Выберите контакт в таблице</div>
|
||||
{% endif %}
|
||||
@@ -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>
|
||||
@@ -0,0 +1,31 @@
|
||||
{% from "partials/_contact_macros.html" import edit_value %}
|
||||
<table class="ctab">
|
||||
<thead>
|
||||
<tr>
|
||||
{% for field, title in [('last_name','Фамилия'), ('first_name','Имя'), ('middle_name','Отчество'),
|
||||
('company','Компания'), ('position','Должность'),
|
||||
('phone','Телефон'), ('email','Почта')] %}
|
||||
{% set next_dir = 'desc' if (sort == field and dir == 'asc') else 'asc' %}
|
||||
<th hx-get="{{ params_url('/contacts', params, sort=field, dir=next_dir) }}"
|
||||
hx-target="#contacts-cols" hx-swap="outerHTML" hx-push-url="true"
|
||||
title="сортировать по полю «{{ title }}»">{{ title }}{% if sort == field %}<span class="sarr">{{ '▲' if dir == 'asc' else '▼' }}</span>{% endif %}</th>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for c in contacts %}
|
||||
<tr class="crow" hx-get="/contacts/{{ c.id }}" hx-target="#c3" hx-swap="innerHTML"
|
||||
title="открыть карточку контакта">
|
||||
<td>{{ edit_value(c, 'last_name') }}</td>
|
||||
<td>{{ edit_value(c, 'first_name') }}</td>
|
||||
<td>{{ edit_value(c, 'middle_name') }}</td>
|
||||
<td>{{ edit_value(c, 'company') }}</td>
|
||||
<td>{{ edit_value(c, 'position') }}</td>
|
||||
<td class="nowrap">{{ edit_value(c, 'phone') }}</td>
|
||||
<td class="nowrap">{{ edit_value(c, 'email') }}</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
<tr><td colspan="7" class="empty">Контактов не найдено — измените фильтры</td></tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
Reference in New Issue
Block a user