Rebuild request detail page: fix API routes + two-column layout
- Fix all API endpoints to use correct routes:
GET /api/requests/{id} (single call for request + children)
POST /api/projects/{pid}/objects (file upload)
POST /api/projects/{pid}/entries (create comment/document)
PUT /api/projects/{pid}/entries/{eid} (mark as answered)
- Two-column desktop layout: Request (read-only) | Response (docs + upload)
- Full-width Discussion section below
- Upload creates both object + document entry linked to request
- "Mark as Answered" button updates request status
- Priority badge, section/item_number badge, answered banner
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
051c6afe19
commit
667657c9fb
|
|
@ -41,38 +41,60 @@
|
|||
Admin</a></div>
|
||||
</div>
|
||||
</nav>
|
||||
<main class="flex-1 p-8 max-w-4xl">
|
||||
<!-- Request Header -->
|
||||
<div id="reqHeader" class="mb-8">
|
||||
<div class="flex items-start gap-4 mb-3">
|
||||
<div class="flex-1">
|
||||
<h1 id="reqTitle" class="text-2xl font-bold text-white mb-2">Loading...</h1>
|
||||
<p id="reqDesc" class="text-[#94a3b8] text-sm"></p>
|
||||
<main class="flex-1 p-8 max-w-6xl">
|
||||
|
||||
<!-- Two-column layout: Request + Response -->
|
||||
<div class="grid grid-cols-1 lg:grid-cols-12 gap-6 mb-6">
|
||||
|
||||
<!-- LEFT: Request (read-only) -->
|
||||
<div class="lg:col-span-7 bg-[#0d1f3c] border border-white/[0.08] rounded-xl p-6">
|
||||
<div class="flex items-center gap-2 mb-5">
|
||||
<span class="text-lg">📋</span>
|
||||
<h2 class="text-sm font-semibold text-[#94a3b8] uppercase tracking-wider">Request</h2>
|
||||
</div>
|
||||
<div class="flex items-start gap-3 mb-4">
|
||||
<h1 id="reqTitle" class="text-xl font-bold text-white leading-tight flex-1">Loading...</h1>
|
||||
<span id="reqItemBadge" class="hidden shrink-0 px-2.5 py-1 rounded-md bg-[#c9a84c]/15 text-[#c9a84c] text-xs font-semibold"></span>
|
||||
</div>
|
||||
<p id="reqDesc" class="text-[#94a3b8] text-sm leading-relaxed mb-5"></p>
|
||||
<div class="border-t border-white/[0.06] pt-4 flex flex-wrap items-center gap-3">
|
||||
<span id="reqPriority" class="hidden px-2.5 py-1 rounded-full text-xs font-medium"></span>
|
||||
<span id="reqDue" class="hidden text-xs text-[#475569]"></span>
|
||||
<span id="reqStatus" class="px-2.5 py-1 rounded-full text-xs font-medium capitalize"></span>
|
||||
</div>
|
||||
<span id="reqStatus" class="shrink-0 px-3 py-1 rounded-full text-sm font-medium"></span>
|
||||
</div>
|
||||
<div class="flex gap-3 flex-wrap text-xs text-[#475569]">
|
||||
<span id="reqDue"></span>
|
||||
<span id="reqAssignee"></span>
|
||||
|
||||
<!-- RIGHT: Response -->
|
||||
<div class="lg:col-span-5 bg-[#0d1f3c] border border-white/[0.08] rounded-xl p-6 flex flex-col">
|
||||
<div class="flex items-center gap-2 mb-5">
|
||||
<span class="text-lg">📁</span>
|
||||
<h2 class="text-sm font-semibold text-[#94a3b8] uppercase tracking-wider">Response</h2>
|
||||
</div>
|
||||
<div id="answeredBanner" class="hidden mb-4 px-4 py-2.5 rounded-lg bg-green-500/10 border border-green-500/20 text-green-300 text-sm font-medium flex items-center gap-2">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
|
||||
Answered
|
||||
</div>
|
||||
<div id="answers" class="space-y-2 mb-4 flex-1"></div>
|
||||
<div id="uploadArea" class="border-2 border-dashed border-white/[0.08] rounded-xl p-6 text-center hover:border-[#c9a84c]/40 transition cursor-pointer" onclick="document.getElementById('fileInput').click()">
|
||||
<div class="text-2xl mb-1">📎</div>
|
||||
<p class="text-[#94a3b8] text-sm">Drop files to submit response</p>
|
||||
<p class="text-[#475569] text-xs mt-1">PDF, DOCX, XLSX, images</p>
|
||||
<input id="fileInput" type="file" multiple class="hidden" onchange="uploadFiles(this.files)">
|
||||
</div>
|
||||
<div id="uploadStatus" class="mt-2 text-sm text-[#94a3b8]"></div>
|
||||
<button id="markAnsweredBtn" onclick="markAnswered()" class="hidden mt-4 w-full px-4 py-2.5 bg-green-600 hover:bg-green-700 text-white font-semibold rounded-lg text-sm transition flex items-center justify-center gap-2">
|
||||
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
|
||||
Mark as Answered
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Answer / Upload -->
|
||||
<div class="bg-[#0d1f3c] border border-white/[0.08] rounded-xl p-6 mb-6">
|
||||
<h2 class="text-sm font-semibold text-[#94a3b8] uppercase tracking-wider mb-4">Response</h2>
|
||||
<div id="answers" class="space-y-4 mb-6"></div>
|
||||
<div id="uploadArea" class="border-2 border-dashed border-white/[0.08] rounded-xl p-8 text-center hover:border-[#c9a84c]/40 transition cursor-pointer" onclick="document.getElementById('fileInput').click()">
|
||||
<div class="text-3xl mb-2">📎</div>
|
||||
<p class="text-[#94a3b8] text-sm">Drop files here or click to upload</p>
|
||||
<p class="text-[#475569] text-xs mt-1">PDF, DOCX, XLSX, images</p>
|
||||
<input id="fileInput" type="file" multiple class="hidden" onchange="uploadFiles(this.files)">
|
||||
</div>
|
||||
<div id="uploadStatus" class="mt-3 text-sm text-[#94a3b8]"></div>
|
||||
</div>
|
||||
|
||||
<!-- Activity / Comments -->
|
||||
<!-- BOTTOM: Discussion (full width) -->
|
||||
<div class="bg-[#0d1f3c] border border-white/[0.08] rounded-xl p-6">
|
||||
<h2 class="text-sm font-semibold text-[#94a3b8] uppercase tracking-wider mb-4">Comments</h2>
|
||||
<div class="flex items-center gap-2 mb-5">
|
||||
<span class="text-lg">💬</span>
|
||||
<h2 class="text-sm font-semibold text-[#94a3b8] uppercase tracking-wider">Discussion</h2>
|
||||
</div>
|
||||
<div id="comments" class="space-y-3 mb-4"></div>
|
||||
<div class="flex gap-3">
|
||||
<textarea id="commentText" rows="2" placeholder="Add a comment..." class="flex-1 px-4 py-2.5 bg-[#0a1628] border border-white/[0.08] rounded-lg text-white placeholder-[#475569] focus:outline-none focus:border-[#c9a84c] focus:ring-1 focus:ring-[#c9a84c] text-sm resize-none"></textarea>
|
||||
|
|
@ -100,93 +122,178 @@
|
|||
function escHtml(s) { const d = document.createElement('div'); d.textContent = s; return d.innerHTML; }
|
||||
|
||||
const statusColors = { open: 'bg-yellow-500/20 text-yellow-300', answered: 'bg-green-500/20 text-green-300', closed: 'bg-gray-500/20 text-gray-300', 'under-review': 'bg-blue-500/20 text-blue-300' };
|
||||
const priorityColors = { high: 'bg-red-500/20 text-red-300', medium: 'bg-yellow-500/20 text-yellow-300', low: 'bg-blue-500/20 text-blue-300' };
|
||||
|
||||
async function loadRequest() {
|
||||
let currentRequest = null; // stores the full request entry
|
||||
let currentData = null; // stores parsed data_text
|
||||
|
||||
async function loadAll() {
|
||||
try {
|
||||
const res = await fetchAPI('/api/entries/' + reqID);
|
||||
const res = await fetchAPI('/api/requests/' + reqID);
|
||||
if (!res.ok) { document.getElementById('reqTitle').textContent = 'Not found'; return; }
|
||||
const req = await res.json();
|
||||
const d = parseData(req.data_text);
|
||||
const title = d.title || req.summary || 'Untitled';
|
||||
document.title = title + ' — Dealspace';
|
||||
document.getElementById('reqRef').textContent = d.ref || title;
|
||||
document.getElementById('reqTitle').textContent = title;
|
||||
document.getElementById('reqDesc').textContent = d.description || '';
|
||||
if (req.project_id) document.getElementById('backToProject').href = '/app/projects/' + req.project_id;
|
||||
const status = d.status || 'open';
|
||||
const sc = statusColors[status] || 'bg-gray-500/20 text-gray-300';
|
||||
document.getElementById('reqStatus').className = 'shrink-0 px-3 py-1 rounded-full text-sm font-medium capitalize ' + sc;
|
||||
document.getElementById('reqStatus').textContent = status;
|
||||
if (d.due_date) document.getElementById('reqDue').textContent = '📅 Due: ' + d.due_date;
|
||||
if (d.assignee) document.getElementById('reqAssignee').textContent = '👤 ' + d.assignee;
|
||||
} catch(e) {}
|
||||
const json = await res.json();
|
||||
currentRequest = json.request;
|
||||
currentData = parseData(currentRequest.data_text);
|
||||
const children = json.children || [];
|
||||
|
||||
renderRequest(currentRequest, currentData);
|
||||
renderAnswers(children.filter(c => c.type === 'answer' || c.type === 'document'));
|
||||
renderComments(children.filter(c => c.type === 'comment'));
|
||||
} catch(e) {
|
||||
document.getElementById('reqTitle').textContent = 'Error loading request';
|
||||
}
|
||||
}
|
||||
|
||||
async function loadAnswers() {
|
||||
try {
|
||||
const res = await fetchAPI('/api/entries/' + reqID + '/children?type=answer');
|
||||
const items = await res.json();
|
||||
const el = document.getElementById('answers');
|
||||
if (!items || items.length === 0) { el.innerHTML = '<p class="text-[#475569] text-sm">No documents uploaded yet.</p>'; return; }
|
||||
el.innerHTML = items.map(a => {
|
||||
const d = parseData(a.data_text);
|
||||
const name = d.filename || d.name || a.summary || 'Document';
|
||||
return `<div class="flex items-center gap-3 px-4 py-3 rounded-lg bg-[#0a1628] border border-white/[0.05]">
|
||||
<span class="text-2xl">${name.endsWith('.pdf') ? '📄' : name.match(/\.(jpg|jpeg|png|gif)$/i) ? '🖼️' : '📎'}</span>
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="text-white text-sm font-medium truncate">${escHtml(name)}</div>
|
||||
<div class="text-[#475569] text-xs">${new Date(a.created_at).toLocaleString()}</div>
|
||||
function renderRequest(req, d) {
|
||||
const title = d.title || req.summary || 'Untitled';
|
||||
document.title = title + ' — Dealspace';
|
||||
document.getElementById('reqRef').textContent = d.item_number || title;
|
||||
document.getElementById('reqTitle').textContent = title;
|
||||
document.getElementById('reqDesc').textContent = d.description || '';
|
||||
|
||||
if (req.project_id) document.getElementById('backToProject').href = '/app/projects/' + req.project_id;
|
||||
|
||||
// Item number / section badge
|
||||
const badge = document.getElementById('reqItemBadge');
|
||||
const badgeParts = [d.section, d.item_number].filter(Boolean);
|
||||
if (badgeParts.length) { badge.textContent = badgeParts.join(' · '); badge.classList.remove('hidden'); }
|
||||
|
||||
// Priority
|
||||
const prioEl = document.getElementById('reqPriority');
|
||||
if (d.priority) {
|
||||
const pc = priorityColors[d.priority] || 'bg-gray-500/20 text-gray-300';
|
||||
prioEl.className = 'px-2.5 py-1 rounded-full text-xs font-medium capitalize ' + pc;
|
||||
prioEl.textContent = d.priority + ' priority';
|
||||
prioEl.classList.remove('hidden');
|
||||
}
|
||||
|
||||
// Due date
|
||||
if (d.due_date) {
|
||||
const dueEl = document.getElementById('reqDue');
|
||||
dueEl.textContent = '📅 Due: ' + d.due_date;
|
||||
dueEl.classList.remove('hidden');
|
||||
}
|
||||
|
||||
// Status
|
||||
const status = d.status || 'open';
|
||||
const sc = statusColors[status] || 'bg-gray-500/20 text-gray-300';
|
||||
const statusEl = document.getElementById('reqStatus');
|
||||
statusEl.className = 'px-2.5 py-1 rounded-full text-xs font-medium capitalize ' + sc;
|
||||
statusEl.textContent = status;
|
||||
|
||||
// Answered banner + mark-answered button
|
||||
if (status === 'answered') {
|
||||
document.getElementById('answeredBanner').classList.remove('hidden');
|
||||
document.getElementById('markAnsweredBtn').classList.add('hidden');
|
||||
} else {
|
||||
document.getElementById('answeredBanner').classList.add('hidden');
|
||||
document.getElementById('markAnsweredBtn').classList.remove('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
function renderAnswers(docs) {
|
||||
const el = document.getElementById('answers');
|
||||
if (!docs || docs.length === 0) {
|
||||
el.innerHTML = '<p class="text-[#475569] text-sm">No response submitted yet.</p>';
|
||||
return;
|
||||
}
|
||||
const projectID = currentRequest.project_id;
|
||||
el.innerHTML = docs.map(a => {
|
||||
const d = parseData(a.data_text);
|
||||
const name = d.filename || d.name || a.summary || 'Document';
|
||||
const icon = name.endsWith('.pdf') ? '📄' : name.match(/\.(jpg|jpeg|png|gif)$/i) ? '🖼️' : name.match(/\.(xlsx?|csv)$/i) ? '📊' : '📎';
|
||||
const objectID = d.object_id || '';
|
||||
const downloadUrl = objectID ? '/api/projects/' + projectID + '/objects/' + objectID + '?filename=' + encodeURIComponent(name) : '#';
|
||||
return `<div class="flex items-center gap-3 px-3 py-2.5 rounded-lg bg-[#0a1628] border border-white/[0.05]">
|
||||
<span class="text-xl">${icon}</span>
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="text-white text-sm font-medium truncate">${escHtml(name)}</div>
|
||||
<div class="text-[#475569] text-xs">${a.created_at ? new Date(a.created_at * 1000).toLocaleString() : ''}</div>
|
||||
</div>
|
||||
${objectID ? `<a href="${downloadUrl}" class="text-[#c9a84c] text-sm hover:underline shrink-0">Download</a>` : ''}
|
||||
</div>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function renderComments(comments) {
|
||||
const el = document.getElementById('comments');
|
||||
if (!comments || comments.length === 0) {
|
||||
el.innerHTML = '<p class="text-[#475569] text-sm">No comments yet.</p>';
|
||||
return;
|
||||
}
|
||||
el.innerHTML = comments.map(c => {
|
||||
const d = parseData(c.data_text);
|
||||
return `<div class="flex gap-3">
|
||||
<div class="w-7 h-7 rounded-full bg-[#c9a84c]/20 flex items-center justify-center text-[#c9a84c] text-xs font-semibold shrink-0 mt-0.5">${(d.author||'?')[0].toUpperCase()}</div>
|
||||
<div>
|
||||
<div class="flex items-baseline gap-2 mb-1">
|
||||
<span class="text-white text-sm font-medium">${escHtml(d.author||'Unknown')}</span>
|
||||
<span class="text-[#475569] text-xs">${c.created_at ? new Date(c.created_at * 1000).toLocaleString() : ''}</span>
|
||||
</div>
|
||||
<a href="/api/entries/${a.entry_id}/download" class="text-[#c9a84c] text-sm hover:underline">Download</a>
|
||||
</div>`;
|
||||
}).join('');
|
||||
} catch(e) {}
|
||||
<p class="text-[#94a3b8] text-sm">${escHtml(d.text||'')}</p>
|
||||
</div>
|
||||
</div>`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
async function uploadFiles(files) {
|
||||
if (!currentRequest) return;
|
||||
const projectID = currentRequest.project_id;
|
||||
const status = document.getElementById('uploadStatus');
|
||||
for (const file of files) {
|
||||
status.textContent = 'Uploading ' + file.name + '...';
|
||||
const fd = new FormData();
|
||||
fd.append('file', file);
|
||||
fd.append('parent_id', reqID);
|
||||
try {
|
||||
const res = await fetchAPI('/api/upload', { method: 'POST', body: fd });
|
||||
if (res.ok) { status.textContent = file.name + ' uploaded.'; loadAnswers(); }
|
||||
else { status.textContent = 'Upload failed for ' + file.name; }
|
||||
// 1. Upload file to object store
|
||||
const uploadRes = await fetchAPI('/api/projects/' + projectID + '/objects', { method: 'POST', body: fd });
|
||||
if (!uploadRes.ok) { status.textContent = 'Upload failed for ' + file.name; continue; }
|
||||
const uploadData = await uploadRes.json();
|
||||
|
||||
// 2. Create document entry linked to request
|
||||
const entryBody = {
|
||||
project_id: projectID,
|
||||
parent_id: reqID,
|
||||
type: 'document',
|
||||
data: JSON.stringify({ filename: file.name, name: file.name, content_type: file.type, object_id: uploadData.object_id })
|
||||
};
|
||||
const entryRes = await fetchAPI('/api/projects/' + projectID + '/entries', { method: 'POST', body: JSON.stringify(entryBody) });
|
||||
if (entryRes.ok) { status.textContent = file.name + ' uploaded.'; }
|
||||
else { status.textContent = 'Failed to save ' + file.name; }
|
||||
} catch(e) { status.textContent = 'Error: ' + e.message; }
|
||||
}
|
||||
setTimeout(() => status.textContent = '', 3000);
|
||||
}
|
||||
|
||||
async function loadComments() {
|
||||
try {
|
||||
const res = await fetchAPI('/api/entries/' + reqID + '/children?type=comment');
|
||||
const items = await res.json();
|
||||
const el = document.getElementById('comments');
|
||||
if (!items || items.length === 0) { el.innerHTML = '<p class="text-[#475569] text-sm">No comments yet.</p>'; return; }
|
||||
el.innerHTML = items.map(c => {
|
||||
const d = parseData(c.data_text);
|
||||
return `<div class="flex gap-3">
|
||||
<div class="w-7 h-7 rounded-full bg-[#c9a84c]/20 flex items-center justify-center text-[#c9a84c] text-xs font-semibold shrink-0 mt-0.5">${(d.author||'?')[0].toUpperCase()}</div>
|
||||
<div>
|
||||
<div class="flex items-baseline gap-2 mb-1">
|
||||
<span class="text-white text-sm font-medium">${escHtml(d.author||'Unknown')}</span>
|
||||
<span class="text-[#475569] text-xs">${new Date(c.created_at).toLocaleString()}</span>
|
||||
</div>
|
||||
<p class="text-[#94a3b8] text-sm">${escHtml(d.text||'')}</p>
|
||||
</div>
|
||||
</div>`;
|
||||
}).join('');
|
||||
} catch(e) {}
|
||||
loadAll(); // refresh
|
||||
}
|
||||
|
||||
async function postComment() {
|
||||
if (!currentRequest) return;
|
||||
const text = document.getElementById('commentText').value.trim();
|
||||
if (!text) return;
|
||||
const projectID = currentRequest.project_id;
|
||||
const body = {
|
||||
project_id: projectID,
|
||||
parent_id: reqID,
|
||||
type: 'comment',
|
||||
data: JSON.stringify({ text, author: user.name || user.email })
|
||||
};
|
||||
try {
|
||||
const res = await fetchAPI('/api/entries/' + reqID + '/children', { method: 'POST', body: JSON.stringify({ type: 'comment', data: { text, author: user.name || user.email } }) });
|
||||
if (res.ok) { document.getElementById('commentText').value = ''; loadComments(); }
|
||||
const res = await fetchAPI('/api/projects/' + projectID + '/entries', { method: 'POST', body: JSON.stringify(body) });
|
||||
if (res.ok) { document.getElementById('commentText').value = ''; loadAll(); }
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
async function markAnswered() {
|
||||
if (!currentRequest || !currentData) return;
|
||||
const projectID = currentRequest.project_id;
|
||||
const updatedData = { ...currentData, status: 'answered' };
|
||||
const body = {
|
||||
data: JSON.stringify(updatedData),
|
||||
version: currentRequest.version
|
||||
};
|
||||
try {
|
||||
const res = await fetchAPI('/api/projects/' + projectID + '/entries/' + reqID, { method: 'PUT', body: JSON.stringify(body) });
|
||||
if (res.ok) loadAll();
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
|
|
@ -196,9 +303,7 @@
|
|||
ua.addEventListener('dragleave', () => ua.classList.remove('border-[#c9a84c]/60'));
|
||||
ua.addEventListener('drop', e => { e.preventDefault(); ua.classList.remove('border-[#c9a84c]/60'); uploadFiles(e.dataTransfer.files); });
|
||||
|
||||
loadRequest();
|
||||
loadAnswers();
|
||||
loadComments();
|
||||
loadAll();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Reference in New Issue