Complete PDF Sort and Merge Flask Application
- Full-featured web application for PDF processing - Microsoft Entra (Azure AD) authentication with PKCE - Parallel PDF sorting and merging capabilities - Job management system with real-time progress tracking - Modern web UI with responsive design - Comprehensive error handling and logging - Ubuntu installation script for easy deployment - Environment configuration for secure credential management
This commit is contained in:
1 parent
31c2d27a62
commit
144adf64c4
18 files changed
+2903
-2
No files matched your search
@@ -0,0 +1,312 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>End of Year Statements</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
.header {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.logo {
|
||||
max-width: 200px;
|
||||
height: auto;
|
||||
}
|
||||
.upload-section {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.radio-group {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.radio-group label {
|
||||
margin-right: 20px;
|
||||
}
|
||||
input[type="file"] {
|
||||
margin: 10px 0;
|
||||
}
|
||||
button {
|
||||
background-color: #007bff;
|
||||
color: white;
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 16px;
|
||||
}
|
||||
button:disabled {
|
||||
background-color: #ccc;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
.progress-section {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
margin-bottom: 20px;
|
||||
display: none;
|
||||
}
|
||||
progress {
|
||||
width: 100%;
|
||||
height: 20px;
|
||||
}
|
||||
.result-section {
|
||||
background: white;
|
||||
padding: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
text-align: center;
|
||||
display: none;
|
||||
}
|
||||
.error {
|
||||
color: red;
|
||||
}
|
||||
#logArea {
|
||||
margin-top: 20px;
|
||||
padding: 10px;
|
||||
background: #f9f9f9;
|
||||
border: 1px solid #ddd;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
font-family: monospace;
|
||||
font-size: 12px;
|
||||
white-space: pre-line;
|
||||
}
|
||||
.clear-btn {
|
||||
background-color: #6c757d;
|
||||
color: white;
|
||||
padding: 8px 16px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
font-size: 14px;
|
||||
margin-left: 10px;
|
||||
}
|
||||
.clear-btn:hover {
|
||||
background-color: #5a6268;
|
||||
}
|
||||
.clear-progress {
|
||||
margin-top: 10px;
|
||||
display: none;
|
||||
}
|
||||
.clear-progress progress {
|
||||
width: 100%;
|
||||
height: 20px;
|
||||
}
|
||||
.nav-links {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.nav-links a {
|
||||
color: #007bff;
|
||||
text-decoration: none;
|
||||
margin: 0 15px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.nav-links a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
.auth-section {
|
||||
margin-top: 20px;
|
||||
text-align: center;
|
||||
}
|
||||
.user-info {
|
||||
display: inline-block;
|
||||
background: white;
|
||||
padding: 10px 20px;
|
||||
border-radius: 6px;
|
||||
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
||||
}
|
||||
.user-info span {
|
||||
margin-right: 15px;
|
||||
font-weight: bold;
|
||||
}
|
||||
.logout-btn, .login-btn {
|
||||
background-color: #dc3545;
|
||||
color: white;
|
||||
padding: 6px 12px;
|
||||
border: none;
|
||||
border-radius: 4px;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
display: inline-block;
|
||||
}
|
||||
.login-btn {
|
||||
background-color: #28a745;
|
||||
}
|
||||
.logout-btn:hover, .login-btn:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<img src="{{ url_for('static', filename='trbc-logo-full.png') }}" alt="Logo" class="logo">
|
||||
<h1>End of Year Statements Processor</h1>
|
||||
<p>Upload PDF files or folders to automatically sort by address and merge by page count</p>
|
||||
|
||||
<!-- Authentication section -->
|
||||
<div class="auth-section">
|
||||
{% if session.oauth_token %}
|
||||
<div class="user-info">
|
||||
<span>Welcome, {{ session.user_info.displayName or session.user_info.givenName or 'User' }}!</span>
|
||||
<a href="{{ url_for('logout') }}" class="logout-btn">Logout</a>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="login-prompt">
|
||||
<a href="{{ url_for('login') }}" class="login-btn">Login with Microsoft</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="nav-links">
|
||||
<a href="{{ url_for('results') }}">View All Jobs & Downloads</a>
|
||||
</div>
|
||||
|
||||
<div class="upload-section">
|
||||
<div class="radio-group">
|
||||
<label>
|
||||
<input type="radio" name="uploadType" value="files" checked> Upload Files (PDFs or ZIPs)
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" name="uploadType" value="folder"> Upload Folder
|
||||
</label>
|
||||
</div>
|
||||
<form id="uploadForm" enctype="multipart/form-data">
|
||||
<div id="filesInput">
|
||||
<input type="file" name="files" multiple accept=".pdf,.zip" id="fileInput">
|
||||
</div>
|
||||
<div id="folderInput" style="display:none;">
|
||||
<input type="file" webkitdirectory multiple id="folderFileInput">
|
||||
</div>
|
||||
<button type="submit" id="submitBtn">Process Files</button>
|
||||
<button type="button" id="clearBtn" class="clear-btn">Clear/Reset</button>
|
||||
</form>
|
||||
<div class="clear-progress" id="clearProgressContainer">
|
||||
<p>Clearing temporary files...</p>
|
||||
<progress id="clearProgress" value="0" max="100"></progress>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="nav-links">
|
||||
<a href="#section1">Section 1</a>
|
||||
<a href="#section2">Section 2</a>
|
||||
<a href="#section3">Section 3</a>
|
||||
</div>
|
||||
|
||||
{% with messages = get_flashed_messages() %}
|
||||
{% if messages %}
|
||||
<div class="error">
|
||||
{% for message in messages %}
|
||||
<p>{{ message }}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
<script>
|
||||
document.querySelectorAll('input[name="uploadType"]').forEach(radio => {
|
||||
radio.addEventListener('change', function() {
|
||||
document.getElementById('filesInput').style.display = this.value === 'files' ? 'block' : 'none';
|
||||
document.getElementById('folderInput').style.display = this.value === 'folder' ? 'block' : 'none';
|
||||
});
|
||||
});
|
||||
|
||||
document.getElementById('uploadForm').addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
alert("Starting upload and processing... This may take several minutes for large files.");
|
||||
const formData = new FormData();
|
||||
const uploadType = document.querySelector('input[name="uploadType"]:checked').value;
|
||||
const inputElement = uploadType === 'files' ? document.getElementById('fileInput') : document.getElementById('folderFileInput');
|
||||
|
||||
for (let file of inputElement.files) {
|
||||
formData.append('files', file);
|
||||
}
|
||||
|
||||
const xhr = new XMLHttpRequest();
|
||||
|
||||
document.getElementById('submitBtn').disabled = true;
|
||||
|
||||
xhr.upload.addEventListener('progress', function(e) {
|
||||
if (e.lengthComputable) {
|
||||
const percentComplete = (e.loaded / e.total) * 100;
|
||||
document.getElementById('status').textContent = `Uploading... ${Math.round(percentComplete)}%`;
|
||||
}
|
||||
});
|
||||
|
||||
xhr.addEventListener('load', function() {
|
||||
if (xhr.status === 200) {
|
||||
// Redirect to job status page
|
||||
window.location.href = xhr.responseURL || '/';
|
||||
} else {
|
||||
document.getElementById('status').textContent = 'Error: ' + xhr.status + ' ' + xhr.statusText;
|
||||
document.getElementById('submitBtn').disabled = false;
|
||||
}
|
||||
});
|
||||
|
||||
xhr.addEventListener('error', function() {
|
||||
document.getElementById('status').textContent = 'Upload failed';
|
||||
document.getElementById('submitBtn').disabled = false;
|
||||
});
|
||||
|
||||
xhr.open('POST', '/');
|
||||
xhr.send(formData);
|
||||
});
|
||||
</script>
|
||||
|
||||
<script>
|
||||
// Clear/Reset functionality
|
||||
document.getElementById('clearBtn').addEventListener('click', function() {
|
||||
if (confirm('This will clear all temporary files and reset the processing state. Continue?')) {
|
||||
const clearBtn = document.getElementById('clearBtn');
|
||||
const clearProgressContainer = document.getElementById('clearProgressContainer');
|
||||
const clearProgress = document.getElementById('clearProgress');
|
||||
|
||||
// Disable button and show progress
|
||||
clearBtn.disabled = true;
|
||||
clearProgressContainer.style.display = 'block';
|
||||
clearProgress.value = 0;
|
||||
|
||||
// Animate progress bar
|
||||
let progress = 0;
|
||||
const progressInterval = setInterval(() => {
|
||||
progress += Math.random() * 15; // Random increment for visual effect
|
||||
if (progress > 90) progress = 90; // Cap at 90% until actual completion
|
||||
clearProgress.value = progress;
|
||||
}, 100);
|
||||
|
||||
fetch('/clear', { method: 'POST' })
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
clearInterval(progressInterval);
|
||||
clearProgress.value = 100;
|
||||
|
||||
// Hide progress after a short delay
|
||||
setTimeout(() => {
|
||||
clearProgressContainer.style.display = 'none';
|
||||
clearBtn.disabled = false;
|
||||
alert(data.message);
|
||||
location.reload(); // Refresh the page
|
||||
}, 500);
|
||||
})
|
||||
.catch(err => {
|
||||
clearInterval(progressInterval);
|
||||
clearProgressContainer.style.display = 'none';
|
||||
clearBtn.disabled = false;
|
||||
alert('Error clearing files: ' + err);
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user