commit 1eeea9f83ad9230a5c1f7a75662770eaab0df837 Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 21:15:41 2025 +0200 Disable resuming of old time entries. commit 3e3ec2f01cb7943622b819a19179388078ae1315 Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 20:59:19 2025 +0200 Refactor db migrations. commit 15a51a569da36c6b7c9e01ab17b6fdbdee6ad994 Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 19:58:04 2025 +0200 Apply new style for Time Tracking view. commit 77e5278b303e060d2b03853b06277f8aa567ae68 Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 18:06:04 2025 +0200 Allow direct registrations as a Company. commit 188a8772757cbef374243d3a5f29e4440ddecabe Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 18:04:45 2025 +0200 Add email invitation feature. commit d9ebaa02aa01b518960a20dccdd5a327d82f30c6 Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 17:12:32 2025 +0200 Apply common style for Company, User, Team management pages. commit 81149caf4d8fc6317e2ab1b4f022b32fc5aa6d22 Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 16:44:32 2025 +0200 Move export functions to own module. commit 1a26e19338e73f8849c671471dd15cc3c1b1fe82 Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 15:51:15 2025 +0200 Split up models.py. commit 61f1ccd10f721b0ff4dc1eccf30c7a1ee13f204d Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 12:05:28 2025 +0200 Move utility function into own modules. commit 84b341ed35e2c5387819a8b9f9d41eca900ae79f Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 11:44:24 2025 +0200 Refactor auth functions use. commit 923e311e3da5b26d85845c2832b73b7b17c48adb Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 11:35:52 2025 +0200 Refactor route nameing and fix bugs along the way. commit f0a5c4419c340e62a2615c60b2a9de28204d2995 Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 10:34:33 2025 +0200 Fix URL endpoints in announcement template. commit b74d74542a1c8dc350749e4788a9464d067a88b5 Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 09:25:53 2025 +0200 Move announcements to own module. commit 9563a28021ac46c82c04fe4649b394dbf96f92c7 Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 09:16:30 2025 +0200 Combine Company view and edit templates. commit 6687c373e681d54e4deab6b2582fed5cea9aadf6 Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 08:17:42 2025 +0200 Move Users, Company and System Administration to own modules. commit 8b7894a2e3eb84bb059f546648b6b9536fea724e Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 07:40:57 2025 +0200 Move Teams and Projects to own modules. commit d11bf059d99839ecf1f5d7020b8c8c8a2454c00b Author: Jens Luedicke <jens@luedicke.me> Date: Mon Jul 7 07:09:33 2025 +0200 Move Tasks and Sprints to own modules.
363 lines
11 KiB
JavaScript
363 lines
11 KiB
JavaScript
// Sub-task Management Functions
|
|
|
|
// Global variable to track subtasks
|
|
let currentSubtasks = [];
|
|
|
|
// Initialize subtasks when loading a task
|
|
function initializeSubtasks(taskId) {
|
|
currentSubtasks = [];
|
|
const subtasksContainer = document.getElementById('subtasks-container');
|
|
if (!subtasksContainer) return;
|
|
|
|
subtasksContainer.innerHTML = '<div class="loading">Loading subtasks...</div>';
|
|
|
|
if (taskId) {
|
|
// Fetch existing subtasks
|
|
fetch(`/api/tasks/${taskId}`)
|
|
.then(response => response.json())
|
|
.then(task => {
|
|
if (task.subtasks) {
|
|
currentSubtasks = task.subtasks;
|
|
renderSubtasks();
|
|
} else {
|
|
subtasksContainer.innerHTML = '<p class="no-subtasks">No subtasks yet</p>';
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error loading subtasks:', error);
|
|
subtasksContainer.innerHTML = '<p class="error">Error loading subtasks</p>';
|
|
});
|
|
} else {
|
|
renderSubtasks();
|
|
}
|
|
}
|
|
|
|
// Render subtasks in the modal
|
|
function renderSubtasks() {
|
|
const container = document.getElementById('subtasks-container');
|
|
if (!container) return;
|
|
|
|
if (currentSubtasks.length === 0) {
|
|
container.innerHTML = '<p class="no-subtasks">No subtasks yet</p>';
|
|
return;
|
|
}
|
|
|
|
container.innerHTML = currentSubtasks.map((subtask, index) => `
|
|
<div class="subtask-item" data-subtask-id="${subtask.id || ''}" data-index="${index}">
|
|
<input type="checkbox"
|
|
class="subtask-checkbox"
|
|
${subtask.status === 'COMPLETED' ? 'checked' : ''}
|
|
onchange="toggleSubtaskStatus(${index})"
|
|
${subtask.id ? '' : 'disabled'}>
|
|
<input type="text"
|
|
class="subtask-name"
|
|
value="${escapeHtml(subtask.name)}"
|
|
placeholder="Subtask name"
|
|
onchange="updateSubtaskName(${index}, this.value)">
|
|
<select class="subtask-priority" onchange="updateSubtaskPriority(${index}, this.value)">
|
|
<option value="LOW" ${subtask.priority === 'LOW' ? 'selected' : ''}>Low</option>
|
|
<option value="MEDIUM" ${subtask.priority === 'MEDIUM' ? 'selected' : ''}>Medium</option>
|
|
<option value="HIGH" ${subtask.priority === 'HIGH' ? 'selected' : ''}>High</option>
|
|
<option value="URGENT" ${subtask.priority === 'URGENT' ? 'selected' : ''}>Urgent</option>
|
|
</select>
|
|
<select class="subtask-assignee" onchange="updateSubtaskAssignee(${index}, this.value)">
|
|
<option value="">Unassigned</option>
|
|
${renderAssigneeOptions(subtask.assigned_to_id)}
|
|
</select>
|
|
<button type="button" class="btn btn-danger btn-xs" onclick="removeSubtask(${index})">Remove</button>
|
|
</div>
|
|
`).join('');
|
|
}
|
|
|
|
// Add a new subtask
|
|
function addSubtask() {
|
|
const newSubtask = {
|
|
name: '',
|
|
status: 'TODO',
|
|
priority: 'MEDIUM',
|
|
assigned_to_id: null,
|
|
isNew: true
|
|
};
|
|
|
|
currentSubtasks.push(newSubtask);
|
|
renderSubtasks();
|
|
|
|
// Focus on the new subtask input
|
|
setTimeout(() => {
|
|
const inputs = document.querySelectorAll('.subtask-name');
|
|
if (inputs.length > 0) {
|
|
inputs[inputs.length - 1].focus();
|
|
}
|
|
}, 50);
|
|
}
|
|
|
|
// Remove a subtask
|
|
function removeSubtask(index) {
|
|
const subtask = currentSubtasks[index];
|
|
|
|
if (subtask.id) {
|
|
// If it has an ID, it exists in the database
|
|
if (confirm('Are you sure you want to delete this subtask?')) {
|
|
fetch(`/api/subtasks/${subtask.id}`, {
|
|
method: 'DELETE',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
}
|
|
})
|
|
.then(response => {
|
|
if (response.ok) {
|
|
currentSubtasks.splice(index, 1);
|
|
renderSubtasks();
|
|
showNotification('Subtask deleted successfully', 'success');
|
|
} else {
|
|
throw new Error('Failed to delete subtask');
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Error deleting subtask:', error);
|
|
showNotification('Error deleting subtask', 'error');
|
|
});
|
|
}
|
|
} else {
|
|
// Just remove from array if not saved yet
|
|
currentSubtasks.splice(index, 1);
|
|
renderSubtasks();
|
|
}
|
|
}
|
|
|
|
// Update subtask name
|
|
function updateSubtaskName(index, name) {
|
|
currentSubtasks[index].name = name;
|
|
}
|
|
|
|
// Update subtask priority
|
|
function updateSubtaskPriority(index, priority) {
|
|
currentSubtasks[index].priority = priority;
|
|
}
|
|
|
|
// Update subtask assignee
|
|
function updateSubtaskAssignee(index, assigneeId) {
|
|
currentSubtasks[index].assigned_to_id = assigneeId || null;
|
|
}
|
|
|
|
// Toggle subtask status
|
|
function toggleSubtaskStatus(index) {
|
|
const subtask = currentSubtasks[index];
|
|
const newStatus = subtask.status === 'DONE' ? 'TODO' : 'DONE';
|
|
|
|
if (subtask.id) {
|
|
// Update in database
|
|
fetch(`/api/subtasks/${subtask.id}`, {
|
|
method: 'PUT',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({ status: newStatus })
|
|
})
|
|
.then(response => response.json())
|
|
.then(updatedSubtask => {
|
|
currentSubtasks[index] = updatedSubtask;
|
|
renderSubtasks();
|
|
updateTaskProgress();
|
|
})
|
|
.catch(error => {
|
|
console.error('Error updating subtask status:', error);
|
|
showNotification('Error updating subtask status', 'error');
|
|
renderSubtasks(); // Re-render to revert checkbox
|
|
});
|
|
} else {
|
|
currentSubtasks[index].status = newStatus;
|
|
}
|
|
}
|
|
|
|
// Save all subtasks for a task
|
|
function saveSubtasks(taskId) {
|
|
const promises = [];
|
|
|
|
currentSubtasks.forEach(subtask => {
|
|
if (subtask.isNew && subtask.name.trim()) {
|
|
// Create new subtask
|
|
promises.push(
|
|
fetch('/api/subtasks', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
task_id: taskId,
|
|
name: subtask.name,
|
|
priority: subtask.priority,
|
|
assigned_to_id: subtask.assigned_to_id,
|
|
status: subtask.status
|
|
})
|
|
})
|
|
.then(response => response.json())
|
|
);
|
|
} else if (subtask.id && !subtask.isNew) {
|
|
// Update existing subtask
|
|
promises.push(
|
|
fetch(`/api/subtasks/${subtask.id}`, {
|
|
method: 'PUT',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
name: subtask.name,
|
|
priority: subtask.priority,
|
|
assigned_to_id: subtask.assigned_to_id,
|
|
status: subtask.status
|
|
})
|
|
})
|
|
.then(response => response.json())
|
|
);
|
|
}
|
|
});
|
|
|
|
return Promise.all(promises);
|
|
}
|
|
|
|
// Update task progress based on subtasks
|
|
function updateTaskProgress() {
|
|
const taskId = document.getElementById('task-id').value;
|
|
if (!taskId) return;
|
|
|
|
// Refresh the task card in the board
|
|
if (typeof refreshTaskCard === 'function') {
|
|
refreshTaskCard(taskId);
|
|
}
|
|
}
|
|
|
|
// Render assignee options
|
|
function renderAssigneeOptions(selectedId) {
|
|
// This should be populated from the global team members list
|
|
const teamMembers = window.teamMembers || [];
|
|
return teamMembers.map(member =>
|
|
`<option value="${member.id}" ${member.id == selectedId ? 'selected' : ''}>${escapeHtml(member.username)}</option>`
|
|
).join('');
|
|
}
|
|
|
|
// Helper function to escape HTML
|
|
function escapeHtml(unsafe) {
|
|
return unsafe
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
.replace(/"/g, """)
|
|
.replace(/'/g, "'");
|
|
}
|
|
|
|
// Display subtasks in task cards
|
|
function renderSubtasksInCard(subtasks) {
|
|
if (!subtasks || subtasks.length === 0) return '';
|
|
|
|
const completedCount = subtasks.filter(s => s.status === 'COMPLETED').length;
|
|
const totalCount = subtasks.length;
|
|
const percentage = Math.round((completedCount / totalCount) * 100);
|
|
|
|
return `
|
|
<div class="task-subtasks">
|
|
<div class="subtask-progress">
|
|
<div class="subtask-progress-bar">
|
|
<div class="subtask-progress-fill" style="width: ${percentage}%"></div>
|
|
</div>
|
|
<span class="subtask-count">${completedCount}/${totalCount} subtasks</span>
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
// Add subtask styles
|
|
const subtaskStyles = `
|
|
<style>
|
|
/* Subtask Styles - Compact */
|
|
.subtask-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.3rem;
|
|
margin-bottom: 0.4rem;
|
|
padding: 0.4rem 0.5rem;
|
|
background: #f8f9fa;
|
|
border-radius: 4px;
|
|
border: 1px solid #e9ecef;
|
|
}
|
|
|
|
.subtask-checkbox {
|
|
cursor: pointer;
|
|
width: 18px;
|
|
height: 18px;
|
|
}
|
|
|
|
.subtask-name {
|
|
flex: 2;
|
|
padding: 0.3rem 0.5rem;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
font-size: 0.85rem;
|
|
}
|
|
|
|
.subtask-priority {
|
|
flex: 0.8;
|
|
padding: 0.3rem 0.5rem;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
font-size: 0.8rem;
|
|
}
|
|
|
|
.subtask-assignee {
|
|
flex: 1.2;
|
|
padding: 0.3rem 0.5rem;
|
|
border: 1px solid #ddd;
|
|
border-radius: 4px;
|
|
font-size: 0.8rem;
|
|
}
|
|
|
|
.no-subtasks {
|
|
color: #6c757d;
|
|
font-style: italic;
|
|
text-align: center;
|
|
padding: 1rem;
|
|
}
|
|
|
|
/* Subtask progress in task cards */
|
|
.task-subtasks {
|
|
margin-top: 0.75rem;
|
|
padding-top: 0.75rem;
|
|
border-top: 1px solid #e9ecef;
|
|
}
|
|
|
|
.subtask-progress {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
.subtask-progress-bar {
|
|
flex: 1;
|
|
height: 6px;
|
|
background: #e9ecef;
|
|
border-radius: 3px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.subtask-progress-fill {
|
|
height: 100%;
|
|
background: #28a745;
|
|
transition: width 0.3s ease;
|
|
}
|
|
|
|
.subtask-count {
|
|
font-size: 0.75rem;
|
|
color: #6c757d;
|
|
white-space: nowrap;
|
|
}
|
|
</style>
|
|
`;
|
|
|
|
// Inject styles when document is ready
|
|
if (document.readyState === 'loading') {
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
document.head.insertAdjacentHTML('beforeend', subtaskStyles);
|
|
});
|
|
} else {
|
|
document.head.insertAdjacentHTML('beforeend', subtaskStyles);
|
|
} |