dealspace/portal/templates/app/projects.html

144 lines
7.5 KiB
HTML

{{define "content"}}
<div class="px-8 pt-6 pb-8" style="max-width:calc(100vw - 14rem)">
<!-- Header with search -->
<div class="flex items-center justify-between mb-8">
<h1 class="text-2xl font-bold" style="color:var(--ds-tx)">Projects</h1>
<div class="relative w-72">
<svg class="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4" style="color:var(--ds-tx2)" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/></svg>
<input type="text" id="searchInput" placeholder="Search projects..." oninput="filterProjects()"
class="w-full pl-10 pr-4 py-2 rounded-lg text-sm focus:outline-none"
style="background:var(--ds-inp);border:1px solid var(--ds-bd);color:var(--ds-tx)">
</div>
</div>
<!-- Project grid -->
<div id="projectGrid" class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-5">
<div style="color:var(--ds-tx2)" class="text-sm col-span-full">Loading...</div>
</div>
<!-- Empty state -->
<div id="emptyState" class="hidden text-center py-24">
<div class="w-16 h-16 mx-auto mb-4 rounded-2xl flex items-center justify-center" style="background:var(--ds-hv)">
<svg class="w-8 h-8" style="color:var(--ds-tx2)" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"/></svg>
</div>
<h2 class="text-xl font-semibold mb-2" style="color:var(--ds-tx)">No projects yet</h2>
<p class="mb-6" style="color:var(--ds-tx2)">Create your first project to get started.</p>
<button onclick="openNewProject()" class="px-5 py-2.5 bg-[#c9a84c] hover:bg-[#b8973f] text-[#0a1628] font-semibold rounded-lg text-sm transition">Create Project</button>
</div>
</div>
{{end}}
{{define "scripts"}}
<script>
const statusColors = { active: 'bg-green-500/20 text-green-300', draft: 'bg-gray-500/20 text-gray-300', closed: 'bg-red-500/20 text-red-300', completed: 'bg-blue-500/20 text-blue-300' };
const dealTypeLabels = { sell_side: 'Sell-side', buy_side: 'Buy-side', merger: 'Merger', restructuring: 'Restructuring', capital_raise: 'Capital Raise' };
let allProjects = [];
async function loadProjects() {
try {
const res = await fetchAPI('/api/projects');
const projects = await res.json();
allProjects = (projects || []).map(p => {
const d = parseData(p.data_text);
return { ...p, _d: d };
});
if (allProjects.length === 0) {
document.getElementById('projectGrid').classList.add('hidden');
document.getElementById('emptyState').classList.remove('hidden');
return;
}
renderProjects(allProjects);
} catch(e) {
document.getElementById('projectGrid').innerHTML = '<div class="text-red-400 text-sm col-span-full">Failed to load projects.</div>';
}
}
function renderProjects(projects) {
const grid = document.getElementById('projectGrid');
grid.classList.remove('hidden');
document.getElementById('emptyState').classList.add('hidden');
const cards = projects.map(p => {
const d = p._d;
const status = d.status || 'active';
const sc = statusColors[status] || statusColors.active;
const name = d.name || p.summary || 'Untitled';
const desc = d.description || '';
const dealType = dealTypeLabels[d.deal_type] || '';
const date = new Date(p.created_at).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' });
return `<a href="/app/projects/${p.entry_id}" class="group block rounded-xl p-6 transition hover:scale-[1.01]"
style="background:var(--ds-sf);border:1px solid var(--ds-bd)">
<div class="flex items-start justify-between mb-3">
<div class="flex items-center gap-3">
<div class="w-10 h-10 rounded-lg flex items-center justify-center text-lg font-bold shrink-0"
style="background:var(--ds-ac);color:var(--ds-act)">${escHtml(name[0])}</div>
<div>
<h3 class="font-semibold text-base leading-tight group-hover:text-[#c9a84c] transition" style="color:var(--ds-tx)">${escHtml(name)}</h3>
<div class="flex items-center gap-2 mt-0.5">
${dealType ? `<span class="text-xs" style="color:var(--ds-tx2)">${dealType}</span>` : ''}
${dealType ? '<span style="color:var(--ds-tx2);opacity:.3">·</span>' : ''}
<span class="text-xs" style="color:var(--ds-tx2)">${date}</span>
</div>
</div>
</div>
<span class="shrink-0 px-2 py-0.5 rounded-full text-xs font-medium ${sc} capitalize">${status}</span>
</div>
${desc ? `<p class="text-sm mb-4 line-clamp-2" style="color:var(--ds-tx2)">${escHtml(desc)}</p>` : '<div class="mb-4"></div>'}
<div class="flex items-center gap-4 text-xs" style="color:var(--ds-tx2)">
<span class="flex items-center gap-1">
<svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/></svg>
${d.stage || p.stage || 'Pre-dataroom'}
</span>
</div>
</a>`;
});
// Add "New Project" card
if (user.is_super_admin) {
cards.push(`<button onclick="openNewProject()" class="group block rounded-xl p-6 transition hover:scale-[1.01] text-left"
style="background:var(--ds-sf);border:2px dashed var(--ds-bd)">
<div class="flex flex-col items-center justify-center py-6">
<div class="w-12 h-12 rounded-full flex items-center justify-center text-2xl mb-3 transition group-hover:scale-110"
style="background:var(--ds-hv);color:var(--ds-ac)">+</div>
<span class="font-medium text-sm" style="color:var(--ds-tx)">New Project</span>
<span class="text-xs mt-1" style="color:var(--ds-tx2)">Start a new project</span>
</div>
</button>`);
}
grid.innerHTML = cards.join('');
}
function filterProjects() {
const q = document.getElementById('searchInput').value.toLowerCase().trim();
if (!q) { renderProjects(allProjects); return; }
const filtered = allProjects.filter(p => {
const d = p._d;
const name = (d.name || p.summary || '').toLowerCase();
const desc = (d.description || '').toLowerCase();
return name.includes(q) || desc.includes(q);
});
renderProjects(filtered);
}
async function openNewProject() {
// Create a blank project, then redirect to it on the Parties tab
try {
const res = await fetchAPI('/api/projects', {
method: 'POST',
body: JSON.stringify({ name: 'New Project', description: '', status: 'draft' })
});
const data = await res.json();
if (!res.ok) throw new Error(data.error || 'Failed to create project');
// Redirect to project with Parties tab + auto-open Add Party modal
window.location.href = '/app/projects/' + (data.project_id || data.entry_id) + '?tab=orgs&addparty=1';
} catch(e) { alert(e.message); }
}
loadProjects();
</script>
{{end}}