mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
sync logs :D
This commit is contained in:
@@ -119,8 +119,11 @@
|
||||
<th>Type</th>
|
||||
<th>Status</th>
|
||||
<th>Progress</th>
|
||||
<th>Items</th>
|
||||
<th>Started</th>
|
||||
<th>Duration</th>
|
||||
<th>Message</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -142,13 +145,27 @@
|
||||
<td>
|
||||
{% if sync.total_items > 0 %}
|
||||
{{ sync.processed_items }} / {{ sync.total_items }}
|
||||
{% if sync.total_items > 0 %}
|
||||
<div class="progress mt-1" style="height: 4px;">
|
||||
<div class="progress-bar bg-primary" role="progressbar"
|
||||
style="width: {{ (sync.processed_items / sync.total_items * 100)|round }}%"></div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<small>
|
||||
{% if sync.new_items > 0 %}<span class="text-success">+{{ sync.new_items }}</span>{% endif %}
|
||||
{% if sync.updated_items > 0 %} <span class="text-primary">{{ sync.updated_items }} updated</span>{% endif %}
|
||||
{% if sync.deleted_items > 0 %} <span class="text-danger">{{ sync.deleted_items }} deleted</span>{% endif %}
|
||||
{% if sync.new_items == 0 and sync.updated_items == 0 and sync.deleted_items == 0 %}No changes{% endif %}
|
||||
</small>
|
||||
</td>
|
||||
<td>
|
||||
{% if sync.started_at %}
|
||||
{{ sync.started_at|date('M j, H:i') }}
|
||||
<small>{{ sync.started_at|date('M j, H:i') }}</small>
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
@@ -157,16 +174,34 @@
|
||||
{% if sync.started_at and sync.completed_at %}
|
||||
{% set duration = sync.completed_at|date('U') - sync.started_at|date('U') %}
|
||||
{% if duration < 60 %}
|
||||
{{ duration }}s
|
||||
<small>{{ duration }}s</small>
|
||||
{% elseif duration < 3600 %}
|
||||
{{ (duration / 60)|round }}m
|
||||
<small>{{ (duration / 60)|round }}m</small>
|
||||
{% else %}
|
||||
{{ (duration / 3600)|round }}h
|
||||
<small>{{ (duration / 3600)|round }}h</small>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
-
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if sync.message %}
|
||||
<small class="text-muted" title="{{ sync.message }}">
|
||||
{{ sync.message|length > 50 ? sync.message|slice(0, 50) ~ '...' : sync.message }}
|
||||
</small>
|
||||
{% else %}
|
||||
<small class="text-muted">-</small>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{% if sync.errors %}
|
||||
<button class="btn btn-sm btn-outline-danger"
|
||||
onclick="showSyncDetails({{ sync.id }}, '{{ sync.source_name }}', '{{ sync.sync_type }}')"
|
||||
title="View errors and details">
|
||||
Details
|
||||
</button>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@@ -280,16 +315,118 @@
|
||||
|
||||
function getStatusMessage(data) {
|
||||
if (data.status === 'completed') {
|
||||
return `Completed: ${data.new_items} new, ${data.updated_items} updated`;
|
||||
let message = `Completed: ${data.new_items || 0} new`;
|
||||
if (data.updated_items > 0) message += `, ${data.updated_items} updated`;
|
||||
if (data.deleted_items > 0) message += `, ${data.deleted_items} deleted`;
|
||||
return message;
|
||||
} else if (data.status === 'failed') {
|
||||
return 'Failed: ' + (data.errors.join(', ') || 'Unknown error');
|
||||
return 'Failed: ' + (data.message || 'Unknown error');
|
||||
} else if (data.status === 'running') {
|
||||
return `Processing: ${data.processed_items}/${data.total_items} items`;
|
||||
let progress = 'Processing';
|
||||
if (data.total_items > 0) {
|
||||
progress += `: ${data.processed_items}/${data.total_items} items`;
|
||||
}
|
||||
if (data.message) {
|
||||
progress += ` - ${data.message}`;
|
||||
}
|
||||
return progress;
|
||||
} else {
|
||||
return data.message || 'Unknown status';
|
||||
}
|
||||
}
|
||||
|
||||
function showSyncDetails(syncId, sourceName, syncType) {
|
||||
// Fetch detailed sync information
|
||||
fetch(`/admin/sync/status/${syncId}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
const modal = document.createElement('div');
|
||||
modal.className = 'modal fade show';
|
||||
modal.style.display = 'block';
|
||||
modal.innerHTML = `
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Sync Details: ${sourceName} - ${syncType}</h5>
|
||||
<button type="button" class="btn-close" onclick="closeModal()"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-6">
|
||||
<strong>Status:</strong>
|
||||
<span class="badge bg-${data.status === 'completed' ? 'success' : data.status === 'failed' ? 'danger' : 'warning'} ms-2">
|
||||
${data.status}
|
||||
</span>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<strong>Started:</strong> ${data.started_at ? new Date(data.started_at).toLocaleString() : 'N/A'}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-6">
|
||||
<strong>Completed:</strong> ${data.completed_at ? new Date(data.completed_at).toLocaleString() : 'N/A'}
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<strong>Duration:</strong> ${data.started_at && data.completed_at ?
|
||||
formatDuration(new Date(data.completed_at) - new Date(data.started_at)) : 'N/A'}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-3"><strong>Total Items:</strong> ${data.total_items || 0}</div>
|
||||
<div class="col-md-3"><strong>Processed:</strong> ${data.processed_items || 0}</div>
|
||||
<div class="col-md-3"><strong>New:</strong> <span class="text-success">${data.new_items || 0}</span></div>
|
||||
<div class="col-md-3"><strong>Updated:</strong> <span class="text-primary">${data.updated_items || 0}</span></div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<strong>Message:</strong>
|
||||
<div class="alert alert-info">${data.message || 'No message available'}</div>
|
||||
</div>
|
||||
${data.errors && data.errors.length > 0 ? `
|
||||
<div class="mb-3">
|
||||
<strong>Errors:</strong>
|
||||
<div class="alert alert-danger">
|
||||
<ul class="mb-0">
|
||||
${data.errors.map(error => `<li>${error}</li>`).join('')}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" onclick="closeModal()">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
document.body.appendChild(modal);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error fetching sync details:', error);
|
||||
alert('Error loading sync details');
|
||||
});
|
||||
}
|
||||
|
||||
function closeModal() {
|
||||
const modal = document.querySelector('.modal.show');
|
||||
if (modal) {
|
||||
modal.remove();
|
||||
}
|
||||
}
|
||||
|
||||
function formatDuration(ms) {
|
||||
const seconds = Math.floor(ms / 1000);
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
const hours = Math.floor(minutes / 60);
|
||||
|
||||
if (hours > 0) {
|
||||
return `${hours}h ${minutes % 60}m`;
|
||||
} else if (minutes > 0) {
|
||||
return `${minutes}m ${seconds % 60}s`;
|
||||
} else {
|
||||
return `${seconds}s`;
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup intervals on page unload
|
||||
window.addEventListener('beforeunload', () => {
|
||||
Object.values(syncIntervals).forEach(interval => clearInterval(interval));
|
||||
|
||||
Reference in New Issue
Block a user