mirror of
https://github.com/zvx-echo6/recon.git
synced 2026-05-20 06:34:40 +02:00
Add Nav-I dashboard section with restore-as conflict resolution
- Create Nav-I top-level section in dashboard navigation - Move Deleted Contacts from Knowledge subnav to Nav-I - Add Nav-I landing page with card grid (deleted count, API keys stub) - Add /nav-i/api-keys placeholder page - Add restore-as endpoint for Home/Work conflict resolution - Conflict modal in deleted contacts template for label rename on restore Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a4288c0cd8
commit
3280e34718
7 changed files with 210 additions and 3 deletions
29
lib/api.py
29
lib/api.py
|
|
@ -82,7 +82,6 @@ KNOWLEDGE_SUBNAV = [
|
|||
{'href': '/upload', 'label': 'Upload'},
|
||||
{'href': '/web-ingest', 'label': 'Web Ingest'},
|
||||
{'href': '/failures', 'label': 'Failures'},
|
||||
{'href': '/deleted-contacts', 'label': 'Deleted Contacts'},
|
||||
]
|
||||
|
||||
PEERTUBE_SUBNAV = [
|
||||
|
|
@ -102,6 +101,12 @@ SETTINGS_SUBNAV = [
|
|||
{'href': '/settings/health', 'label': 'Service Health'},
|
||||
]
|
||||
|
||||
NAVI_SUBNAV = [
|
||||
{'href': '/nav-i', 'label': 'Overview'},
|
||||
{'href': '/deleted-contacts', 'label': 'Deleted Contacts'},
|
||||
{'href': '/nav-i/api-keys', 'label': 'API Keys'},
|
||||
]
|
||||
|
||||
|
||||
def _format_source_citation(payload):
|
||||
"""Format a human-readable citation from a search result payload."""
|
||||
|
|
@ -335,11 +340,29 @@ def deleted_contacts_page():
|
|||
user_id = get_user_id() or "anonymous"
|
||||
db = ContactsDB()
|
||||
contacts = db.list_deleted(user_id)
|
||||
return render_template("knowledge/deleted_contacts.html",
|
||||
domain="knowledge", subnav=KNOWLEDGE_SUBNAV, active_page="/deleted-contacts",
|
||||
return render_template("navi/deleted_contacts.html",
|
||||
domain="navi", subnav=NAVI_SUBNAV, active_page="/deleted-contacts",
|
||||
contacts=contacts)
|
||||
|
||||
|
||||
@app.route("/nav-i")
|
||||
def navi_landing_page():
|
||||
from .auth import get_user_id
|
||||
from .contacts import ContactsDB
|
||||
user_id = get_user_id() or "anonymous"
|
||||
db = ContactsDB()
|
||||
deleted_count = len(db.list_deleted(user_id))
|
||||
return render_template("navi/landing.html",
|
||||
domain="navi", subnav=NAVI_SUBNAV, active_page="/nav-i",
|
||||
deleted_count=deleted_count)
|
||||
|
||||
|
||||
@app.route("/nav-i/api-keys")
|
||||
def navi_api_keys_page():
|
||||
return render_template("navi/api_keys.html",
|
||||
domain="navi", subnav=NAVI_SUBNAV, active_page="/nav-i/api-keys")
|
||||
|
||||
|
||||
@app.route('/peertube')
|
||||
def peertube_dashboard():
|
||||
return render_template('peertube/dashboard.html',
|
||||
|
|
|
|||
|
|
@ -178,6 +178,25 @@ class ContactsDB:
|
|||
conn.commit()
|
||||
return self.get(user_id, contact_id), None
|
||||
|
||||
def restore_as(self, user_id, contact_id, new_label):
|
||||
"""Restore a soft-deleted contact with a new label (for Home/Work conflict resolution)."""
|
||||
conn = self._get_conn()
|
||||
row = self.get(user_id, contact_id, include_deleted=True)
|
||||
if not row or not row.get('deleted_at'):
|
||||
return None, 'not_found'
|
||||
if not new_label or not new_label.strip():
|
||||
return None, 'invalid_label'
|
||||
now = datetime.now(timezone.utc).strftime('%Y-%m-%dT%H:%M:%fZ')
|
||||
try:
|
||||
conn.execute(
|
||||
"UPDATE contacts SET deleted_at = NULL, deleted_by = NULL, label = ?, updated_at = ? WHERE id = ? AND user_id = ?",
|
||||
(new_label.strip(), now, contact_id, user_id)
|
||||
)
|
||||
conn.commit()
|
||||
except sqlite3.IntegrityError:
|
||||
return None, 'conflict'
|
||||
return self.get(user_id, contact_id), None
|
||||
|
||||
def purge(self, user_id, contact_id):
|
||||
conn = self._get_conn()
|
||||
row = self.get(user_id, contact_id, include_deleted=True)
|
||||
|
|
|
|||
|
|
@ -102,6 +102,24 @@ def restore_contact(contact_id):
|
|||
return jsonify(contact)
|
||||
|
||||
|
||||
@contacts_bp.route('/api/contacts/<int:contact_id>/restore-as', methods=['POST'])
|
||||
@require_auth
|
||||
def restore_as_contact(contact_id):
|
||||
db = _get_db()
|
||||
data = request.get_json(force=True)
|
||||
new_label = data.get('label', '').strip()
|
||||
if not new_label:
|
||||
return jsonify({'error': 'label is required'}), 400
|
||||
contact, err = db.restore_as(request.user_id, contact_id, new_label)
|
||||
if err == 'not_found':
|
||||
return jsonify({'error': 'Not found'}), 404
|
||||
if err == 'invalid_label':
|
||||
return jsonify({'error': 'Invalid label'}), 400
|
||||
if err == 'conflict':
|
||||
return jsonify({'error': 'Label conflict'}), 409
|
||||
return jsonify(contact)
|
||||
|
||||
|
||||
@contacts_bp.route('/api/contacts/<int:contact_id>/purge', methods=['DELETE'])
|
||||
@require_auth
|
||||
def purge_contact(contact_id):
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
<a href="/peertube"{% if domain == 'peertube' %} class="active"{% endif %}>PeerTube</a>
|
||||
<a href="/kiwix"{% if domain == 'kiwix' %} class="active"{% endif %}>Kiwix</a>
|
||||
<a href="/search"{% if domain == 'search' %} class="active"{% endif %}>Search</a>
|
||||
<a href="/nav-i"{% if domain == 'navi' %} class="active"{% endif %}>Nav-I</a>
|
||||
<a href="/settings/keys"{% if domain == 'settings' %} class="active"{% endif %}>Settings</a>
|
||||
</div>
|
||||
{% if subnav %}
|
||||
|
|
|
|||
8
templates/navi/api_keys.html
Normal file
8
templates/navi/api_keys.html
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<h3 style="color:var(--orange);margin-bottom:16px;">API Keys</h3>
|
||||
<div class="panel">
|
||||
<p class="text-dim">Per-user API key management is coming soon.</p>
|
||||
<p class="text-dim" style="margin-top:8px;font-size:11px;">This will allow generating keys for programmatic access to the Navi contacts API.</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
116
templates/navi/deleted_contacts.html
Normal file
116
templates/navi/deleted_contacts.html
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<h3 style="color:var(--orange);margin-bottom:16px;">Deleted Contacts</h3>
|
||||
{% if not contacts %}
|
||||
<p class="text-dim">No deleted contacts.</p>
|
||||
{% else %}
|
||||
<table>
|
||||
<tr><th>Label</th><th>Name</th><th>Category</th><th>Phone</th><th>Deleted At</th><th>Actions</th></tr>
|
||||
{% for c in contacts %}
|
||||
<tr id="row-{{ c.id }}">
|
||||
<td>{{ c.label }}</td>
|
||||
<td>{{ c.name or '' }}</td>
|
||||
<td class="text-dim">{{ c.category or '' }}</td>
|
||||
<td class="text-dim text-xs">{{ c.phone or '' }}</td>
|
||||
<td class="text-dim text-xs">{{ c.deleted_at or '' }}</td>
|
||||
<td>
|
||||
<button class="btn" onclick="restoreContact({{ c.id }}, '{{ c.label }}')">Restore</button>
|
||||
<button class="btn" style="margin-left:4px;color:#ff4444;" onclick="purgeContact({{ c.id }})">Purge</button>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endif %}
|
||||
|
||||
<!-- Conflict resolution modal -->
|
||||
<div id="conflict-modal" style="display:none;position:fixed;inset:0;z-index:50;background:rgba(0,0,0,0.6);align-items:center;justify-content:center;">
|
||||
<div style="background:var(--bg-secondary);border:1px solid var(--border-light);padding:24px;max-width:400px;width:90%;">
|
||||
<h4 style="color:var(--orange);margin-bottom:12px;">Label Conflict</h4>
|
||||
<p class="text-dim" style="margin-bottom:16px;">An active contact with the label "<span id="conflict-label" style="color:var(--text-primary);"></span>" already exists. Choose a new label to restore this contact:</p>
|
||||
<input id="conflict-new-label" type="text" placeholder="New label..." style="width:100%;padding:6px 10px;background:var(--bg-tertiary);border:1px solid var(--border-light);color:var(--text-primary);font-family:var(--font-mono);font-size:13px;margin-bottom:16px;">
|
||||
<div style="display:flex;gap:8px;justify-content:flex-end;">
|
||||
<button class="btn" onclick="closeConflictModal()">Cancel</button>
|
||||
<button class="btn" id="conflict-submit" onclick="submitRestoreAs()" style="border-color:var(--green);color:var(--green);">Restore As</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
{% block scripts %}
|
||||
<script>
|
||||
var pendingRestoreId = null;
|
||||
|
||||
async function restoreContact(id, label) {
|
||||
try {
|
||||
var resp = await fetch('/api/contacts/' + id + '/restore', {method: 'POST'});
|
||||
if (resp.ok) {
|
||||
location.reload();
|
||||
} else if (resp.status === 409) {
|
||||
// Home/Work conflict — show modal
|
||||
pendingRestoreId = id;
|
||||
document.getElementById('conflict-label').textContent = label;
|
||||
document.getElementById('conflict-new-label').value = '';
|
||||
var modal = document.getElementById('conflict-modal');
|
||||
modal.style.display = 'flex';
|
||||
document.getElementById('conflict-new-label').focus();
|
||||
} else {
|
||||
var data = await resp.json();
|
||||
alert(data.error || 'Restore failed');
|
||||
}
|
||||
} catch(e) {
|
||||
alert('Error: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
function closeConflictModal() {
|
||||
document.getElementById('conflict-modal').style.display = 'none';
|
||||
pendingRestoreId = null;
|
||||
}
|
||||
|
||||
async function submitRestoreAs() {
|
||||
var newLabel = document.getElementById('conflict-new-label').value.trim();
|
||||
if (!newLabel) {
|
||||
document.getElementById('conflict-new-label').style.borderColor = 'var(--red)';
|
||||
return;
|
||||
}
|
||||
try {
|
||||
var resp = await fetch('/api/contacts/' + pendingRestoreId + '/restore-as', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({label: newLabel})
|
||||
});
|
||||
if (resp.ok) {
|
||||
location.reload();
|
||||
} else {
|
||||
var data = await resp.json();
|
||||
alert(data.error || 'Restore failed');
|
||||
}
|
||||
} catch(e) {
|
||||
alert('Error: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function purgeContact(id) {
|
||||
if (!confirm('Permanently delete this contact? This cannot be undone.')) return;
|
||||
try {
|
||||
var resp = await fetch('/api/contacts/' + id + '/purge', {method: 'DELETE'});
|
||||
if (resp.ok) {
|
||||
location.reload();
|
||||
} else {
|
||||
var data = await resp.json();
|
||||
alert(data.error || 'Purge failed');
|
||||
}
|
||||
} catch(e) {
|
||||
alert('Error: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// Close modal on Escape key
|
||||
document.addEventListener('keydown', function(e) {
|
||||
if (e.key === 'Escape') closeConflictModal();
|
||||
});
|
||||
// Close modal on backdrop click
|
||||
document.getElementById('conflict-modal').addEventListener('click', function(e) {
|
||||
if (e.target === this) closeConflictModal();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
22
templates/navi/landing.html
Normal file
22
templates/navi/landing.html
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{% extends "base.html" %}
|
||||
{% block content %}
|
||||
<h3 style="color:var(--green);margin-bottom:16px;">Nav-I</h3>
|
||||
<p class="text-dim" style="margin-bottom:24px;">Navi frontend management — contacts, API keys, and configuration.</p>
|
||||
|
||||
<div class="stat-grid">
|
||||
<a href="/deleted-contacts" style="text-decoration:none;">
|
||||
<div class="stat-card" style="cursor:pointer;transition:border-color 0.15s;">
|
||||
<div class="label">Deleted Contacts</div>
|
||||
<div class="value">{{ deleted_count }}</div>
|
||||
<div class="sublabel">awaiting restore or purge</div>
|
||||
</div>
|
||||
</a>
|
||||
<a href="/nav-i/api-keys" style="text-decoration:none;">
|
||||
<div class="stat-card" style="cursor:pointer;transition:border-color 0.15s;">
|
||||
<div class="label">API Keys</div>
|
||||
<div class="value" style="font-size:14px;color:var(--text-dim);margin-top:12px;">Coming soon</div>
|
||||
<div class="sublabel">per-user key management</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue