Improve dashboard UI and some fixes

This commit is contained in:
inubimambo
2025-07-08 23:14:31 +08:00
parent 9644f62dc5
commit bcd5a52995
5 changed files with 918 additions and 97 deletions

View File

@@ -31,7 +31,7 @@
<div class="card border-0 shadow-sm h-100">
<div class="card-body">
<div class="d-flex align-items-center mb-3">
<div class="file-icon bg-primary text-white rounded-circle d-flex align-items-center justify-content-center me-3" style="width: 50px; height: 50px;">
<div class="dashboard-file-icon bg-primary text-white rounded-circle d-flex align-items-center justify-content-center me-3">
<i class="fas fa-file-alt"></i>
</div>
<div class="flex-grow-1">
@@ -109,6 +109,73 @@
<% }); %>
</div>
<% } %>
<!-- Revised Files Section -->
<% if (typeof revisedFiles !== 'undefined' && revisedFiles.length > 0) { %>
<div class="ai-revised-section revised-files-section">
<div class="d-flex justify-content-between align-items-center mb-4">
<h3><i class="fas fa-brain me-2 text-success"></i>AI-Revised Notes</h3>
<small class="text-muted bg-white px-2 py-1 rounded-pill">
<%= revisedFiles.length %> revised file<%= revisedFiles.length !== 1 ? 's' : '' %>
</small>
</div>
<div class="row">
<% revisedFiles.forEach(function(file, index) { %>
<div class="col-md-6 col-lg-4 mb-4">
<div class="card border-0 shadow-sm h-100 border-start border-4 border-success">
<div class="card-body p-3">
<div class="d-flex align-items-start mb-3">
<div class="file-icon bg-success text-white rounded-circle d-flex align-items-center justify-content-center me-3 ai-icon" style="width: 50px; height: 50px; min-width: 50px; font-size: 1.2rem; font-weight: bold; letter-spacing: 1px;">
AI
</div>
<div class="flex-grow-1 min-w-0">
<h6 class="mb-1 file-name-truncate" title="<%= file.originalName %>">
<%= file.originalName %>
</h6>
<div class="d-flex flex-wrap align-items-center gap-1 mb-1">
<small class="text-muted"><%= Math.round(file.size / 1024) %> KB</small>
<span class="badge bg-success text-white">
<%= file.revisionType.charAt(0).toUpperCase() + file.revisionType.slice(1) %>
</span>
</div>
</div>
</div>
<div class="mb-3">
<div class="small text-muted mb-1">
<i class="fas fa-calendar me-1"></i>
<%= new Date(file.uploadDate).toLocaleDateString() %>
</div>
<% if (file.originalFileName) { %>
<div class="small text-muted file-name-truncate" title="From: <%= file.originalFileName %>">
<i class="fas fa-file-alt me-1"></i>
From: <%= file.originalFileName %>
</div>
<% } %>
</div>
<div class="mt-auto">
<div class="d-grid gap-2">
<button type="button" class="btn btn-outline-primary btn-sm" onclick="previewRevisedFile('<%= file.id %>')">
<i class="fas fa-eye me-1"></i>Preview
</button>
<div class="btn-group w-100" role="group">
<a href="/uploads/revised-notes/<%= file.filename %>" download class="btn btn-success btn-sm">
<i class="fas fa-download me-1"></i>Download
</a>
<button type="button" class="btn btn-outline-danger btn-sm" onclick="deleteRevisedFile('<%= file.id %>')" title="Delete">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
<% }); %>
</div>
</div>
<% } %>
</div>
</div>
</div>
@@ -806,6 +873,73 @@ document.addEventListener('DOMContentLoaded', function() {
}, 10000);
}
});
// Preview revised file function
async function previewRevisedFile(fileId) {
try {
// Get file information by making an API call instead of using template data
const response = await fetch(`/api/revised-files/${fileId}/info`);
if (!response.ok) {
throw new Error('Failed to get file info');
}
const fileInfo = await response.json();
if (!fileInfo.success) {
throw new Error(fileInfo.error || 'Failed to get file info');
}
const file = fileInfo.file;
// Download the file content
const contentResponse = await fetch(`/uploads/revised-notes/${file.filename}`);
if (!contentResponse.ok) {
throw new Error('Failed to load file content');
}
const content = await contentResponse.text();
const modal = new bootstrap.Modal(document.getElementById('previewModal'));
document.getElementById('preview-content').innerHTML = `
<div class="alert alert-info">
<i class="fas fa-brain me-2"></i>
<strong>AI-Revised Content</strong> • ${file.revisionType} • From: ${file.originalFileName || 'Unknown'}
</div>
<div class="border p-3 bg-light rounded" style="max-height: 400px; overflow-y: auto;">
<pre style="white-space: pre-wrap; word-wrap: break-word;">${escapeHtml(content)}</pre>
</div>
`;
modal.show();
} catch (error) {
console.error('Error previewing revised file:', error);
alert('Failed to preview file: ' + error.message);
}
}
// Delete revised file function
async function deleteRevisedFile(fileId) {
if (!confirm('Are you sure you want to delete this revised file? This action cannot be undone.')) {
return;
}
try {
const response = await fetch(`/api/revised-files/${fileId}`, {
method: 'DELETE'
});
const result = await response.json();
if (result.success) {
// Reload the page to update the file list
location.reload();
} else {
alert('Error deleting file: ' + (result.error || 'Unknown error'));
}
} catch (error) {
console.error('Error deleting revised file:', error);
alert('Network error: ' + error.message);
}
}
</script>
<%- include('partials/footer') %>