- New Features: Introduced sortable column UI with drag-and-drop reordering, visual ghost and drag styling, and automatic card movement via API. - Enhancements: Added CSS classes for ghost and drag effects, integrated htmx `afterSwap` event to reinitialize sortable after dynamic swaps, and improved delay and filter settings. - Bug Fixes: Fixed column identification logic, ensured proper cleanup of existing sortable instances, and enhanced error handling to reload page on failed moves.
168 lines
7.6 KiB
HTML
168 lines
7.6 KiB
HTML
{% extends "base_authenticated.html" %}
|
|
{% block title %}{{ board.name }}{% endblock %}
|
|
{% block content_inner %}
|
|
<div class="flex items-center justify-between mb-6">
|
|
<div>
|
|
<div class="flex items-center gap-2 text-sm text-gray-500 mb-1">
|
|
<a href="{% url 'board_list' %}" class="hover:text-blue-600">Boards</a>
|
|
<span>/</span>
|
|
</div>
|
|
<h1 class="text-2xl font-bold text-gray-900">{{ board.name }}</h1>
|
|
{% if board.project %}<p class="text-sm text-gray-500">Project: {{ board.project.name }}</p>{% endif %}
|
|
</div>
|
|
<div class="flex gap-2">
|
|
<a href="{% url 'board_edit' board.pk %}" class="btn btn-sm btn-ghost">Edit</a>
|
|
{% if user.is_admin %}
|
|
<label for="delete-modal-board" class="btn btn-sm text-red-600 hover:bg-red-50 cursor-pointer">Delete</label>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex gap-4 overflow-x-auto pb-6 min-h-[60vh]" id="kanban-board">
|
|
{% for column in columns %}
|
|
<div class="bg-gray-100 rounded-2xl min-w-[280px] w-[280px] flex-shrink-0 flex flex-col">
|
|
<div class="flex items-center justify-between px-4 py-3">
|
|
<div class="flex items-center gap-2">
|
|
<div class="w-3 h-3 rounded-full {% cycle 'bg-blue-400' 'bg-amber-400' 'bg-green-400' 'bg-sky-400' 'bg-blue-400' 'bg-pink-400' %}"></div>
|
|
<h3 class="font-semibold text-gray-700 text-sm">{{ column.name }}</h3>
|
|
<span class="text-xs px-2 py-0.5 rounded-full bg-white/80 text-gray-500 font-medium">{{ column.cards.count }}</span>
|
|
</div>
|
|
</div>
|
|
<div class="flex-1 px-3 pb-3 space-y-2 min-h-[100px]"
|
|
id="column-{{ column.pk }}"
|
|
data-sortable-column="{{ column.pk }}">
|
|
{% for card in column.cards.all %}
|
|
{% include "partials/kanban/card.html" %}
|
|
{% endfor %}
|
|
</div>
|
|
<div class="px-3 pb-3">
|
|
<a href="{% url 'card_create' board.pk column.pk %}" class="btn btn-ghost btn-sm w-full text-gray-500 hover:text-gray-700 hover:bg-white/80">
|
|
<svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/></svg>
|
|
Add Card
|
|
</a>
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
<div class="flex-shrink-0 min-w-[280px] w-[280px]">
|
|
<div class="bg-gray-50 border-2 border-dashed border-gray-200 rounded-2xl p-4 h-full">
|
|
<form method="post" action="{% url 'column_create' board.pk %}">
|
|
{% csrf_token %}
|
|
<div class="flex items-center gap-2">
|
|
<input type="text" name="name" placeholder="New column name..." class="input input-sm w-full bg-white border-gray-200" required>
|
|
<button type="submit" class="btn btn-sm bg-blue-600 text-white hover:bg-blue-700 border-0">
|
|
<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="M12 4v16m8-8H4"/></svg>
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{% url 'board_delete' board.pk as delete_url %}
|
|
{% include "components/delete_modal.html" with modal_id="delete-modal-board" delete_url=delete_url %}
|
|
|
|
<!-- Card Delete Modal -->
|
|
<input type="checkbox" id="delete-card-modal" class="modal-toggle" />
|
|
<div class="modal" role="dialog">
|
|
<div class="modal-box text-center">
|
|
<div class="w-16 h-16 rounded-full bg-red-100 flex items-center justify-center mx-auto mb-4">
|
|
<svg class="w-8 h-8 text-red-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/></svg>
|
|
</div>
|
|
<h3 class="font-bold text-lg mb-2">Delete Card</h3>
|
|
<p class="py-4 text-gray-500">Are you sure you want to delete this card?</p>
|
|
<form id="card-delete-form" method="post" action="">
|
|
{% csrf_token %}
|
|
<div class="flex gap-3 justify-center">
|
|
<button type="submit" class="btn bg-red-600 text-white hover:bg-red-700 border-0">Delete</button>
|
|
<label for="delete-card-modal" class="btn btn-ghost">Cancel</label>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
<label class="modal-backdrop" for="delete-card-modal"></label>
|
|
</div>
|
|
{% endblock %}
|
|
<style>
|
|
.sortable-ghost { opacity: 0.3; }
|
|
.sortable-drag {
|
|
box-shadow: 0 20px 60px rgba(0,0,0,0.2) !important;
|
|
transform: rotate(3deg) !important;
|
|
}
|
|
</style>
|
|
{% block extra_scripts %}
|
|
<script>
|
|
function openCardDeleteModal(actionUrl) {
|
|
document.getElementById('card-delete-form').action = actionUrl;
|
|
document.getElementById('delete-card-modal').checked = true;
|
|
}
|
|
|
|
function getCookie(name) {
|
|
let cookieValue = null;
|
|
if (document.cookie && document.cookie !== '') {
|
|
const cookies = document.cookie.split(';');
|
|
for (let i = 0; i < cookies.length; i++) {
|
|
const cookie = cookies[i].trim();
|
|
if (cookie.substring(0, name.length + 1) === (name + '=')) {
|
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return cookieValue;
|
|
}
|
|
|
|
function initKanbanSortable() {
|
|
const containers = document.querySelectorAll('[data-sortable-column]');
|
|
const csrftoken = getCookie('csrftoken');
|
|
if (!csrftoken) return;
|
|
|
|
containers.forEach(function(container) {
|
|
if (container.sortableInstance) return;
|
|
|
|
container.sortableInstance = new Sortable(container, {
|
|
group: {
|
|
name: 'kanban',
|
|
pull: true,
|
|
put: true
|
|
},
|
|
animation: 150,
|
|
ghostClass: 'sortable-ghost',
|
|
dragClass: 'sortable-drag',
|
|
delay: 150,
|
|
delayOnTouchOnly: true,
|
|
filter: '.no-drag, a, button, input, textarea, select',
|
|
preventOnFilter: false,
|
|
scroll: true,
|
|
bubbleScroll: true,
|
|
onEnd: function(evt) {
|
|
var item = evt.item;
|
|
var to = evt.to;
|
|
if (!item || !to) return;
|
|
|
|
var cardId = item.getAttribute('data-card-id');
|
|
var newColumnId = to.getAttribute('data-sortable-column');
|
|
var order = evt.newIndex;
|
|
|
|
if (!cardId || !newColumnId || order === undefined) return;
|
|
|
|
fetch('/cards/' + cardId + '/move/', {
|
|
method: 'POST',
|
|
headers: {
|
|
'X-CSRFToken': csrftoken,
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
},
|
|
body: 'column_id=' + newColumnId + '&order=' + order
|
|
}).then(function(r) {
|
|
if (!r.ok) location.reload();
|
|
}).catch(function() {
|
|
location.reload();
|
|
});
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', initKanbanSortable);
|
|
document.addEventListener('htmx:afterSwap', initKanbanSortable);
|
|
</script>
|
|
{% endblock %}
|