feat: add absorb command — merge source entity into target
DB: Absorb() merges body (newline-separated), unions tags, demotes
crystallized sources, soft-deletes source. Rejects crystallized targets.
API: POST /api/entities/:id/absorb { source_id }
CLI: nib absorb <target> <source> with prefix ID resolution
Web: absorb button on fluid entities, 'a' keyboard shortcut,
source picker modal
This commit is contained in:
+60
-6
@@ -85,6 +85,14 @@
|
||||
});
|
||||
return resp.json();
|
||||
},
|
||||
async absorbEntity(targetId, sourceId) {
|
||||
const resp = await fetch('/api/entities/' + targetId + '/absorb', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ source_id: sourceId }),
|
||||
});
|
||||
return resp.json();
|
||||
},
|
||||
async listTags() {
|
||||
const resp = await fetch('/api/tags');
|
||||
return resp.json();
|
||||
@@ -269,6 +277,7 @@
|
||||
actions += `<button class="action-btn" onclick="nibApp.demoteEntity('${e.id}')">demote</button>`;
|
||||
} else {
|
||||
actions += `<button class="action-btn primary" onclick="nibApp.showPromote('${e.id}')">promote</button>`;
|
||||
actions += `<button class="action-btn" onclick="nibApp.showAbsorb('${e.id}')">absorb</button>`;
|
||||
}
|
||||
actions += `<button class="action-btn danger" onclick="nibApp.deleteEntity('${e.id}')">delete</button>`;
|
||||
|
||||
@@ -469,6 +478,44 @@
|
||||
}
|
||||
},
|
||||
|
||||
showAbsorb(targetId) {
|
||||
const target = state.entities.find(x => x.id === targetId);
|
||||
if (!target) return;
|
||||
if (target.card_type) return;
|
||||
|
||||
const modal = $('#absorb-modal');
|
||||
modal.dataset.targetId = targetId;
|
||||
const list = $('#absorb-source-list');
|
||||
|
||||
const sources = state.entities.filter(x => x.id !== targetId);
|
||||
if (!sources.length) { list.innerHTML = '<div class="detail-empty">no other entities</div>'; }
|
||||
else {
|
||||
list.innerHTML = sources.map(e => {
|
||||
const g = displayGlyph(e);
|
||||
const gc = glyphClass(e);
|
||||
return `<div class="absorb-source-item" data-id="${e.id}">
|
||||
<span class="entity-glyph ${gc}">${g}</span>
|
||||
<span class="entity-body">${escHtml(e.body)}</span>
|
||||
</div>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
list.querySelectorAll('.absorb-source-item').forEach(el => {
|
||||
el.addEventListener('click', async () => {
|
||||
modal.classList.add('hidden');
|
||||
modal.classList.remove('visible');
|
||||
await api.absorbEntity(targetId, el.dataset.id);
|
||||
await loadEntities();
|
||||
await loadTags();
|
||||
const idx = state.entities.findIndex(x => x.id === targetId);
|
||||
if (idx >= 0) selectEntity(idx);
|
||||
});
|
||||
});
|
||||
|
||||
modal.classList.remove('hidden');
|
||||
modal.classList.add('visible');
|
||||
},
|
||||
|
||||
async toggleStep(id, stepIdx) {
|
||||
const e = state.entities.find(x => x.id === id);
|
||||
if (!e || !e.card_data) return;
|
||||
@@ -520,13 +567,14 @@
|
||||
});
|
||||
});
|
||||
|
||||
$('.modal-backdrop').addEventListener('click', closeModal);
|
||||
$('.modal-close').addEventListener('click', closeModal);
|
||||
$$('.modal-backdrop').forEach(el => el.addEventListener('click', closeModal));
|
||||
$$('.modal-close').forEach(el => el.addEventListener('click', closeModal));
|
||||
|
||||
function closeModal() {
|
||||
const modal = $('#promote-modal');
|
||||
modal.classList.add('hidden');
|
||||
modal.classList.remove('visible');
|
||||
$$('.modal.visible').forEach(m => {
|
||||
m.classList.add('hidden');
|
||||
m.classList.remove('visible');
|
||||
});
|
||||
}
|
||||
|
||||
// ========== Keyboard shortcuts ==========
|
||||
@@ -541,7 +589,8 @@
|
||||
return;
|
||||
}
|
||||
|
||||
if ($('#promote-modal').classList.contains('visible')) {
|
||||
if ($('#promote-modal').classList.contains('visible') ||
|
||||
$('#absorb-modal').classList.contains('visible')) {
|
||||
if (ev.key === 'Escape') closeModal();
|
||||
return;
|
||||
}
|
||||
@@ -586,6 +635,11 @@
|
||||
startEditBody();
|
||||
break;
|
||||
}
|
||||
case 'a': {
|
||||
const e = state.entities[state.selectedIndex];
|
||||
if (e && !e.card_type) nibApp.showAbsorb(e.id);
|
||||
break;
|
||||
}
|
||||
case '1': switchView('stream'); break;
|
||||
case '2': switchView('cards'); break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user