HH/templates/projects/project_list.html
2026-03-09 16:10:24 +03:00

314 lines
18 KiB
HTML

{% extends 'layouts/base.html' %}
{% load i18n hospital_filters %}
{% block title %}{% trans "QI Projects" %} - PX360{% endblock %}
{% block extra_css %}
<style>
.status-active { background-color: #e0f2fe; color: #075985; }
.status-pending { background-color: #fef9c3; color: #854d0e; }
.status-completed { background-color: #dcfce7; color: #166534; }
.status-cancelled { background-color: #fee2e2; color: #991b1b; }
.filter-btn.active { background-color: #005696; color: white; }
.filter-btn:not(.active) { background-color: transparent; border: 1px solid #e2e8f0; color: #64748b; }
.filter-btn:not(.active):hover { background-color: #f8fafc; }
</style>
{% endblock %}
{% block content %}
<!-- Header -->
<header class="mb-6">
<div class="flex justify-between items-start">
<div>
<h1 class="text-2xl font-bold text-navy flex items-center gap-3">
<i data-lucide="folder-kanban" class="w-7 h-7 text-cyan-500"></i>
{% trans "Quality Improvement Projects" %}
</h1>
<p class="text-sm text-slate mt-1">{% trans "Track and manage quality improvement initiatives" %}</p>
</div>
<div class="flex items-center gap-3">
<div class="relative group">
<i data-lucide="search" class="w-4 h-4 absolute left-3 top-1/2 -translate-y-1/2 text-slate group-focus-within:text-navy"></i>
<input type="text" id="searchInput" placeholder="{% trans 'Search projects...' %}"
class="pl-10 pr-4 py-2.5 bg-slate-100 border-transparent border focus:border-navy/30 focus:bg-white rounded-xl text-sm outline-none w-64 transition-all"
value="{{ filters.search|default:'' }}">
</div>
{% if user.is_px_admin or user.is_hospital_admin or user.is_department_manager %}
<a href="{% url 'projects:template_list' %}" class="bg-white text-navy border-2 border-navy/30 px-5 py-2.5 rounded-xl text-sm font-bold hover:bg-navy hover:text-white flex items-center gap-2 transition">
<i data-lucide="copy" class="w-4 h-4"></i> {% trans "Templates" %}
</a>
<a href="{% url 'projects:project_create' %}" class="bg-navy text-white px-5 py-2.5 rounded-xl text-sm font-bold shadow-lg shadow-navy/20 hover:bg-blue flex items-center gap-2 transition">
<i data-lucide="plus" class="w-4 h-4"></i> {% trans "Create Project" %}
</a>
{% endif %}
</div>
</div>
</header>
<!-- Statistics Cards -->
<div class="grid grid-cols-4 gap-6 mb-6">
<div class="bg-white p-4 rounded-2xl border shadow-sm flex items-center gap-4">
<div class="p-3 bg-blue/10 rounded-xl">
<i data-lucide="layers" class="text-blue w-5 h-5"></i>
</div>
<div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider">{% trans "Total Projects" %}</p>
<p class="text-xl font-black text-navy leading-tight">{{ stats.total }}</p>
</div>
</div>
<div class="bg-white p-4 rounded-2xl border shadow-sm flex items-center gap-4">
<div class="p-3 bg-cyan-50 rounded-xl">
<i data-lucide="play-circle" class="text-cyan-600 w-5 h-5"></i>
</div>
<div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider">{% trans "Active" %}</p>
<p class="text-xl font-black text-navy leading-tight">{{ stats.active }}</p>
</div>
</div>
<div class="bg-white p-4 rounded-2xl border shadow-sm flex items-center gap-4">
<div class="p-3 bg-green-50 rounded-xl">
<i data-lucide="check-circle" class="text-green-600 w-5 h-5"></i>
</div>
<div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider">{% trans "Completed" %}</p>
<p class="text-xl font-black text-navy leading-tight">{{ stats.completed }}</p>
</div>
</div>
<div class="bg-white p-4 rounded-2xl border shadow-sm flex items-center gap-4">
<div class="p-3 bg-yellow-50 rounded-xl">
<i data-lucide="clock" class="text-yellow-600 w-5 h-5"></i>
</div>
<div>
<p class="text-[10px] font-bold text-slate uppercase tracking-wider">{% trans "Pending" %}</p>
<p class="text-xl font-black text-navy leading-tight">{{ stats.pending }}</p>
</div>
</div>
</div>
<!-- Filter Tabs -->
<div class="bg-white rounded-t-2xl shadow-sm border-2 border-slate-200">
<div class="px-6 py-4 border-b-2 border-slate-200 flex items-center justify-between bg-gradient-to-r from-slate-50 to-slate-100">
<h3 class="font-bold text-navy flex items-center gap-2">
<i data-lucide="filter" class="w-5 h-5 text-navy"></i>
{% trans "Filters" %}
</h3>
<div class="flex items-center gap-3">
<a href="?" class="filter-btn px-4 py-1.5 rounded-full text-xs font-semibold transition {% if not filters.status %}active{% endif %}">
{% trans "All Projects" %}
</a>
<a href="?status=active" class="filter-btn px-4 py-1.5 rounded-full text-xs font-semibold transition {% if filters.status == 'active' %}active{% endif %}">
{% trans "Active" %}
</a>
<a href="?status=pending" class="filter-btn px-4 py-1.5 rounded-full text-xs font-semibold transition {% if filters.status == 'pending' %}active{% endif %}">
{% trans "Pending" %}
</a>
<a href="?status=completed" class="filter-btn px-4 py-1.5 rounded-full text-xs font-semibold transition {% if filters.status == 'completed' %}active{% endif %}">
{% trans "Completed" %}
</a>
{% if user.is_px_admin %}
<div class="h-4 w-[1px] bg-slate-200 mx-2"></div>
<div class="flex items-center gap-2">
<label class="text-xs font-bold text-slate uppercase">{% trans "Hospital" %}</label>
<select id="hospitalFilter" class="px-3 py-1.5 bg-white border rounded-lg text-xs">
<option value="">{% trans "All Hospitals" %}</option>
{% for hospital in hospitals %}
<option value="{{ hospital.id }}" {% if filters.hospital == hospital.id|stringformat:'s' %}selected{% endif %}>
{{ hospital.name }}
</option>
{% endfor %}
</select>
</div>
{% endif %}
</div>
</div>
<p class="px-6 py-2 text-[10px] font-bold text-slate uppercase bg-slate-50 border-b-2 border-slate-200">
{% trans "Showing:" %} <span class="text-navy">{{ page_obj.start_index|default:0 }}-{{ page_obj.end_index|default:0 }} {% trans "of" %} {{ page_obj.paginator.count|default:0 }}</span>
</p>
<!-- Projects Table -->
<div class="bg-white rounded-b-2xl shadow-sm border-2 border-slate-200 overflow-hidden border-t-0">
<div class="px-6 py-4 border-b-2 border-slate-200 bg-gradient-to-r from-slate-50 to-slate-100">
<h3 class="font-bold text-navy flex items-center gap-2">
<i data-lucide="folder-kanban" class="w-5 h-5 text-cyan-500"></i>
{% trans "Projects" %}
</h3>
</div>
<table class="w-full text-left border-collapse">
<thead class="bg-slate-50 border-b uppercase text-[10px] font-bold text-slate tracking-wider">
<tr>
<th class="px-6 py-4">{% trans "Project" %}</th>
<th class="px-6 py-4">{% trans "Hospital" %}</th>
<th class="px-6 py-4">{% trans "Project Lead" %}</th>
<th class="px-6 py-4">{% trans "Status" %}</th>
<th class="px-6 py-4">{% trans "Tasks" %}</th>
<th class="px-6 py-4">{% trans "Timeline" %}</th>
<th class="px-6 py-4 text-right">{% trans "Actions" %}</th>
</tr>
</thead>
<tbody class="text-sm divide-y divide-slate-100">
{% for project in projects %}
<tr class="hover:bg-light/30 transition-colors cursor-pointer group" onclick="window.location.href='{% url 'projects:project_detail' pk=project.pk %}'">
<td class="px-6 py-4">
<a href="{% url 'projects:project_detail' pk=project.pk %}" class="font-bold text-navy hover:text-blue" onclick="event.stopPropagation()">
{{ project.name }}
</a>
{% if project.description %}
<p class="text-xs text-slate mt-0.5 truncate max-w-xs">{{ project.description|truncatechars:60 }}</p>
{% endif %}
</td>
<td class="px-6 py-4">
<span class="bg-slate-100 px-2 py-0.5 rounded text-[10px] font-bold text-slate-600">{{ project.hospital.name }}</span>
</td>
<td class="px-6 py-4 text-slate-600">
{% if project.project_lead %}
{{ project.project_lead.get_full_name }}
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td class="px-6 py-4">
{% if project.status == 'active' %}
<span class="status-active px-2.5 py-1 rounded-full text-[10px] font-bold uppercase">{{ project.get_status_display }}</span>
{% elif project.status == 'pending' %}
<span class="status-pending px-2.5 py-1 rounded-full text-[10px] font-bold uppercase">{{ project.get_status_display }}</span>
{% elif project.status == 'completed' %}
<span class="status-completed px-2.5 py-1 rounded-full text-[10px] font-bold uppercase">{{ project.get_status_display }}</span>
{% elif project.status == 'cancelled' %}
<span class="status-cancelled px-2.5 py-1 rounded-full text-[10px] font-bold uppercase">{{ project.get_status_display }}</span>
{% else %}
<span class="bg-slate-100 px-2.5 py-1 rounded-full text-[10px] font-bold uppercase text-slate-600">{{ project.get_status_display }}</span>
{% endif %}
</td>
<td class="px-6 py-4">
{% with total=project.tasks.count completed=project.tasks.completed.count %}
<div class="flex items-center gap-2">
<div class="flex-1 h-1.5 bg-slate-200 rounded-full overflow-hidden max-w-[80px]">
{% if total > 0 %}
<div class="h-full bg-green-500 rounded-full" style="width: {{ completed|div:total|mul:100|floatformat:0 }}%"></div>
{% endif %}
</div>
<span class="text-xs text-slate">
<span class="text-green-600 font-semibold">{{ completed }}</span>/{{ total }}
{% if total > 0 %}
<span class="text-muted">({{ completed|div:total|mul:100|floatformat:0 }}%)</span>
{% endif %}
</span>
</div>
{% endwith %}
</td>
<td class="px-6 py-4 text-slate-600">
{% if project.start_date or project.target_completion_date %}
<small>
{% if project.start_date %}{{ project.start_date|date:"M d" }}{% else %}-{% endif %}
{% if project.target_completion_date %}{{ project.target_completion_date|date:"M d, Y" }}{% else %}-{% endif %}
</small>
{% else %}
<span class="text-muted">-</span>
{% endif %}
</td>
<td class="px-6 py-4 text-right">
<div class="flex justify-end gap-2 opacity-0 group-hover:opacity-100 transition-opacity">
<a href="{% url 'projects:project_detail' pk=project.pk %}" class="p-1.5 text-navy hover:bg-white rounded border border-transparent hover:border-slate-200" title="{% trans 'View' %}" onclick="event.stopPropagation()">
<i data-lucide="eye" class="w-4 h-4"></i>
</a>
{% if user.is_px_admin or user.is_hospital_admin or user.is_department_manager %}
<a href="{% url 'projects:project_edit' pk=project.pk %}" class="p-1.5 text-blue hover:bg-white rounded border border-transparent hover:border-slate-200" title="{% trans 'Edit' %}" onclick="event.stopPropagation()">
<i data-lucide="pencil" class="w-4 h-4"></i>
</a>
{% endif %}
</div>
</td>
</tr>
{% empty %}
<tr>
<td colspan="7" class="px-6 py-12 text-center">
<i data-lucide="kanban" class="w-12 h-12 mx-auto text-slate-300 mb-3"></i>
<p class="text-slate mb-3">{% trans "No projects found" %}</p>
{% if user.is_px_admin or user.is_hospital_admin or user.is_department_manager %}
<a href="{% url 'projects:project_create' %}" class="bg-navy text-white px-5 py-2.5 rounded-xl text-sm font-bold shadow-lg shadow-navy/20 hover:bg-blue inline-flex items-center gap-2 transition">
<i data-lucide="plus" class="w-4 h-4"></i> {% trans "Create First Project" %}
</a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<!-- Pagination -->
{% if page_obj.has_other_pages %}
<div class="bg-slate-50 px-8 py-4 flex items-center justify-between border-t">
<div class="flex items-center gap-4">
<span class="text-xs text-slate font-medium">
{% trans "Showing" %} <span class="font-bold text-navy">{{ page_obj.start_index }}-{{ page_obj.end_index }}</span> {% trans "of" %} <span class="font-bold text-navy">{{ page_obj.paginator.count }}</span> {% trans "entries" %}
</span>
</div>
<div class="flex gap-2">
{% if page_obj.has_previous %}
<a href="?page={{ page_obj.previous_page_number }}{% if filters.search %}&search={{ filters.search }}{% endif %}{% if filters.status %}&status={{ filters.status }}{% endif %}{% if filters.hospital %}&hospital={{ filters.hospital }}{% endif %}"
class="w-8 h-8 flex items-center justify-center rounded-lg border bg-white hover:bg-slate-50 transition">
<i data-lucide="chevron-left" class="w-4 h-4 text-slate"></i>
</a>
{% else %}
<span class="w-8 h-8 flex items-center justify-center rounded-lg border bg-slate-100 text-slate-300 cursor-not-allowed">
<i data-lucide="chevron-left" class="w-4 h-4"></i>
</span>
{% endif %}
{% for num in page_obj.paginator.page_range %}
{% if page_obj.number == num %}
<span class="w-8 h-8 flex items-center justify-center rounded-lg bg-navy text-white text-xs font-bold">{{ num }}</span>
{% elif num > page_obj.number|add:'-3' and num < page_obj.number|add:'3' %}
<a href="?page={{ num }}{% if filters.search %}&search={{ filters.search }}{% endif %}{% if filters.status %}&status={{ filters.status }}{% endif %}{% if filters.hospital %}&hospital={{ filters.hospital }}{% endif %}"
class="w-8 h-8 flex items-center justify-center rounded-lg border bg-white hover:bg-slate-50 text-xs font-bold text-slate transition">
{{ num }}
</a>
{% elif num == 1 or num == page_obj.paginator.num_pages %}
<a href="?page={{ num }}{% if filters.search %}&search={{ filters.search }}{% endif %}{% if filters.status %}&status={{ filters.status }}{% endif %}{% if filters.hospital %}&hospital={{ filters.hospital }}{% endif %}"
class="w-8 h-8 flex items-center justify-center rounded-lg border bg-white hover:bg-slate-50 text-xs font-bold text-slate transition">
{{ num }}
</a>
{% elif num == page_obj.number|add:'-3' or num == page_obj.number|add:'3' %}
<span class="w-8 h-8 flex items-center justify-center text-xs text-slate">...</span>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<a href="?page={{ page_obj.next_page_number }}{% if filters.search %}&search={{ filters.search }}{% endif %}{% if filters.status %}&status={{ filters.status }}{% endif %}{% if filters.hospital %}&hospital={{ filters.hospital }}{% endif %}"
class="w-8 h-8 flex items-center justify-center rounded-lg border bg-white hover:bg-slate-50 transition">
<i data-lucide="chevron-right" class="w-4 h-4 text-slate"></i>
</a>
{% else %}
<span class="w-8 h-8 flex items-center justify-center rounded-lg border bg-slate-100 text-slate-300 cursor-not-allowed">
<i data-lucide="chevron-right" class="w-4 h-4"></i>
</span>
{% endif %}
</div>
</div>
{% endif %}
</div>
<script>
// Search functionality
document.getElementById('searchInput')?.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
const value = this.value;
let url = '?';
if (value) url += 'search=' + encodeURIComponent(value);
{% if filters.status %}url += '&status={{ filters.status }}';{% endif %}
{% if filters.hospital %}url += '&hospital={{ filters.hospital }}';{% endif %}
window.location.href = url;
}
});
// Hospital filter
document.getElementById('hospitalFilter')?.addEventListener('change', function() {
let url = '?';
if (this.value) url += 'hospital=' + this.value;
{% if filters.search %}url += '&search={{ filters.search }}';{% endif %}
{% if filters.status %}url += '&status={{ filters.status }}';{% endif %}
window.location.href = url;
});
</script>
{% endblock %}