librelad 1b0040dbf1 refactor(tasks): decompose tasks-manager god-file into 8 responsibility files
Faithful brace-aware split of tasks-manager.js (2664->491 line base) into
list-render, data-load, log-stream, row-expand, actions, modals, logs-modal,
format — augmenting TasksManager.prototype. First removed 4 provably-dead
duplicate defs (the earlier init/setupAutoRefresh/startLogStreaming/loadTaskLogs
that the later defs already overrode — behavior-preserving). Methods relocated
verbatim via a brace-aware Node extractor (handles strings/templates/comments/
regex, fixing the line-heuristic over-capture). Verified: all 60 (deduped)
methods present exactly once, no dups, all 9 files node --check clean. Wired
after the base in the task-system loader (async=false-ordered).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-30 14:53:19 +01:00

218 lines
7.3 KiB
JavaScript

// Auto-extracted from tasks-manager.js (verbatim) — augments TasksManager.prototype. Loaded after the base.
Object.assign(TasksManager.prototype, {
async refreshTasks() {
// Show refresh notification
const refreshNotification = window.notificationSystem.info(
'🔄 Refreshing tasks...',
'Tasks',
null,
null
);
try {
await this.loadTasks();
// Remove refresh notification and show success
if (refreshNotification && refreshNotification.remove) {
refreshNotification.remove();
}
if (window.notificationSystem) {
window.notificationSystem.success(
'🔄 Tasks refreshed successfully',
'Tasks',
null,
null
);
}
} catch (error) {
console.error('Error refreshing tasks:', error);
// Remove refresh notification and show error
if (refreshNotification && refreshNotification.remove) {
refreshNotification.remove();
}
if (window.notificationSystem) {
window.notificationSystem.error(
`⚠️ Failed to refresh tasks: ${error.message}`,
'Tasks',
null,
null
);
}
}
},
async loadTasks() {
try {
//// // console.log('🔄 Loading tasks from file system...');
// Check if task system is available
if (!this.taskManager) {
console.warn('⚠️ Task system not yet initialized, skipping task loading');
this.tasks = [];
return;
}
// Get tasks using new system
// console.log('📥 Getting tasks using new queue system...');
// Get queue and current status
let queue = [];
let current = {};
try {
const queueResponse = await fetch('/read-file?path=tasks/queue.json');
if (queueResponse.ok) {
const queueText = await queueResponse.text();
if (queueText.trim()) { // Only parse if not empty
try {
queue = JSON.parse(queueText);
} catch (parseError) {
console.warn('⚠️ Invalid queue.json format, starting with empty queue');
queue = [];
}
}
}
} catch (error) {
// console.log('📝 Queue file not found, starting with empty queue');
}
try {
const currentResponse = await fetch('/read-file?path=tasks/current.json');
if (currentResponse.ok) {
const currentText = await currentResponse.text();
if (currentText.trim()) { // Only parse if not empty
try {
current = JSON.parse(currentText);
} catch (parseError) {
console.warn('⚠️ Invalid current.json format, treating as empty');
current = {};
}
}
}
} catch (error) {
// console.log('📝 Current file not found, no current task');
}
// Load individual task files
const allTasks = [];
// Add queued tasks
for (const taskId of queue) {
try {
const task = await this.taskManager.getTask(taskId);
if (task) allTasks.push(task);
} catch (error) {
console.warn(`⚠️ Failed to load queued task ${taskId}:`, error);
}
}
// Add current task if different from queue
if (current.id && !queue.includes(current.id)) {
try {
const task = await this.taskManager.getTask(current.id);
if (task) allTasks.push(task);
} catch (error) {
console.warn(`⚠️ Failed to load current task ${current.id}:`, error);
}
}
// Scan tasks folder for all task files (including completed ones) - OPTIMIZED
try {
// console.log('🔍 Scanning tasks folder for all task files...');
const tasksResponse = await fetch('/read-directory?path=tasks');
if (tasksResponse.ok) {
const files = await tasksResponse.json();
const taskFiles = files.filter(file =>
file.endsWith('.json') &&
file !== 'queue.json' &&
file !== 'current.json'
);
// console.log(`📁 Found ${taskFiles.length} task files in folder`);
// OPTIMIZATION: Batch load tasks instead of individual calls
const missingTaskIds = taskFiles
.map(file => file.replace('.json', ''))
.filter(taskId => !allTasks.find(task => task.id === taskId));
if (missingTaskIds.length > 0) {
// console.log(`📦 Batch loading ${missingTaskIds.length} missing tasks...`);
try {
const batchResponse = await fetch('/read-tasks-batch', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ taskIds: missingTaskIds })
});
if (batchResponse.ok) {
const batchTasks = await batchResponse.json();
batchTasks.forEach(task => {
if (task) {
allTasks.push(task);
// console.log(`✅ Added completed task ${task.id} from batch load`);
}
});
} else {
// Fallback to individual loading if batch endpoint not available
// console.log('⚠️ Batch endpoint not available, falling back to individual loading');
await this.loadTasksIndividually(missingTaskIds, allTasks);
}
} catch (error) {
console.warn('⚠️ Batch loading failed, falling back to individual loading:', error);
await this.loadTasksIndividually(missingTaskIds, allTasks);
}
}
}
} catch (error) {
console.warn('⚠️ Failed to scan tasks folder:', error);
}
//// // console.log('📊 Task counts:', {
//queued: queuedTasks.length,
//processing: processingTasks.length,
//completed: completedTasks.length
//});
// Combine all tasks
this.tasks = allTasks;
// Sort by creation time (newest first)
this.tasks.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt));
// console.log(`✅ Loaded ${this.tasks.length} tasks`);
//// // console.log('📋 All tasks:', this.tasks);
this.renderTasks();
this.updateStats();
this.updateSidebarCounts();
this.generateAppCategories();
} catch (error) {
console.error('❌ Failed to load tasks:', error);
if (window.notificationSystem) {
window.notificationSystem.error(`Failed to load tasks: ${error.message}`);
}
this.tasks = [];
this.renderTasks();
this.updateStats();
this.updateSidebarCounts();
this.generateAppCategories();
}
},
async loadTasksIndividually(taskIds, allTasks) {
// Fallback method for individual task loading
for (const taskId of taskIds) {
try {
const task = await this.taskManager.getTask(taskId);
if (task) {
allTasks.push(task);
// console.log(`✅ Added completed task ${taskId} from individual load`);
}
} catch (error) {
console.warn(`⚠️ Failed to load task ${taskId}:`, error);
}
}
},
});