upfdated to ptint plugin
This commit is contained in:
Binary file not shown.
@@ -932,6 +932,162 @@ def upload_data():
|
||||
def print_module():
|
||||
return render_template('print_module.html')
|
||||
|
||||
@bp.route('/download_extension')
|
||||
def download_extension():
|
||||
"""Route for downloading the Chrome extension"""
|
||||
return render_template('download_extension.html')
|
||||
|
||||
@bp.route('/extension_files/<path:filename>')
|
||||
def extension_files(filename):
|
||||
"""Serve Chrome extension files for download"""
|
||||
import os
|
||||
from flask import send_from_directory, current_app
|
||||
|
||||
extension_dir = os.path.join(os.path.dirname(current_app.root_path), 'chrome_extension')
|
||||
return send_from_directory(extension_dir, filename)
|
||||
|
||||
@bp.route('/create_extension_package', methods=['POST'])
|
||||
def create_extension_package():
|
||||
"""Create and serve ZIP package of Chrome extension"""
|
||||
import os
|
||||
import zipfile
|
||||
from flask import current_app, jsonify, send_file
|
||||
import tempfile
|
||||
|
||||
try:
|
||||
# Use correct path to chrome_extension directory (it's in py_app, not py_app/app)
|
||||
extension_dir = os.path.join(os.path.dirname(current_app.root_path), 'chrome_extension')
|
||||
print(f"Looking for extension files in: {extension_dir}")
|
||||
|
||||
if not os.path.exists(extension_dir):
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': f'Extension directory not found: {extension_dir}'
|
||||
}), 500
|
||||
|
||||
# List files in extension directory for debugging
|
||||
all_files = []
|
||||
for root, dirs, files in os.walk(extension_dir):
|
||||
for file in files:
|
||||
file_path = os.path.join(root, file)
|
||||
all_files.append(file_path)
|
||||
|
||||
print(f"Found files: {all_files}")
|
||||
|
||||
# Create static directory if it doesn't exist
|
||||
static_dir = os.path.join(current_app.root_path, 'static')
|
||||
os.makedirs(static_dir, exist_ok=True)
|
||||
|
||||
zip_filename = 'quality_recticel_print_helper.zip'
|
||||
zip_path = os.path.join(static_dir, zip_filename)
|
||||
|
||||
# Create ZIP file directly in static directory
|
||||
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
||||
files_added = 0
|
||||
|
||||
# Add all extension files to ZIP
|
||||
for root, dirs, files in os.walk(extension_dir):
|
||||
for file in files:
|
||||
# Include all relevant files
|
||||
if file.endswith(('.json', '.js', '.html', '.css', '.png', '.md', '.txt')):
|
||||
file_path = os.path.join(root, file)
|
||||
# Create relative path for archive
|
||||
arcname = os.path.relpath(file_path, extension_dir)
|
||||
|
||||
print(f"Adding file: {file_path} as {arcname}")
|
||||
zipf.write(file_path, arcname)
|
||||
files_added += 1
|
||||
|
||||
# Add a README file with installation instructions
|
||||
readme_content = """# Quality Recticel Print Helper Chrome Extension
|
||||
|
||||
## Installation Instructions:
|
||||
|
||||
1. Extract this ZIP file to a folder on your computer
|
||||
2. Open Chrome and go to: chrome://extensions/
|
||||
3. Enable "Developer mode" in the top right
|
||||
4. Click "Load unpacked" and select the extracted folder
|
||||
5. The extension icon 🖨️ should appear in your toolbar
|
||||
|
||||
## Usage:
|
||||
|
||||
1. Go to the Print Module in the Quality Recticel application
|
||||
2. Select an order from the table
|
||||
3. Click the "🖨️ Print Direct" button
|
||||
4. The label will print automatically to your default printer
|
||||
|
||||
## Troubleshooting:
|
||||
|
||||
- Make sure your default printer is set up correctly
|
||||
- Click the extension icon to test printer connection
|
||||
- Check Chrome printer settings: chrome://settings/printing
|
||||
|
||||
For support, contact your system administrator.
|
||||
"""
|
||||
zipf.writestr('README.txt', readme_content)
|
||||
files_added += 1
|
||||
|
||||
print(f"Total files added to ZIP: {files_added}")
|
||||
|
||||
# Verify ZIP was created and has content
|
||||
if os.path.exists(zip_path):
|
||||
zip_size = os.path.getsize(zip_path)
|
||||
print(f"ZIP file created: {zip_path}, size: {zip_size} bytes")
|
||||
|
||||
if zip_size > 0:
|
||||
return jsonify({
|
||||
'success': True,
|
||||
'download_url': f'/static/{zip_filename}',
|
||||
'files_included': files_added,
|
||||
'zip_size': zip_size
|
||||
})
|
||||
else:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': 'ZIP file was created but is empty'
|
||||
}), 500
|
||||
else:
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': 'Failed to create ZIP file'
|
||||
}), 500
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error creating extension package: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
return jsonify({
|
||||
'success': False,
|
||||
'error': str(e)
|
||||
}), 500
|
||||
|
||||
@bp.route('/test_extension_files')
|
||||
def test_extension_files():
|
||||
"""Test route to check extension files"""
|
||||
import os
|
||||
from flask import current_app, jsonify
|
||||
|
||||
extension_dir = os.path.join(os.path.dirname(current_app.root_path), 'chrome_extension')
|
||||
|
||||
result = {
|
||||
'extension_dir': extension_dir,
|
||||
'dir_exists': os.path.exists(extension_dir),
|
||||
'files': []
|
||||
}
|
||||
|
||||
if os.path.exists(extension_dir):
|
||||
for root, dirs, files in os.walk(extension_dir):
|
||||
for file in files:
|
||||
file_path = os.path.join(root, file)
|
||||
file_size = os.path.getsize(file_path)
|
||||
result['files'].append({
|
||||
'path': file_path,
|
||||
'relative_path': os.path.relpath(file_path, extension_dir),
|
||||
'size': file_size
|
||||
})
|
||||
|
||||
return jsonify(result)
|
||||
|
||||
@bp.route('/label_templates')
|
||||
def label_templates():
|
||||
return render_template('label_templates.html')
|
||||
|
||||
144
py_app/app/templates/download_extension.html
Normal file
144
py_app/app/templates/download_extension.html
Normal file
@@ -0,0 +1,144 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Chrome Extension Download{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container-fluid">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-8">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3 class="mb-0">🖨️ Quality Recticel Print Helper - Chrome Extension</h3>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="alert alert-info">
|
||||
<strong>Direct Printing Solution:</strong> This Chrome extension enables direct printing from the Print Module to your default printer without browser dialogs.
|
||||
</div>
|
||||
|
||||
<h4>Features:</h4>
|
||||
<ul>
|
||||
<li>✅ Print labels directly to default printer</li>
|
||||
<li>✅ No browser print dialogs</li>
|
||||
<li>✅ Automatic printer detection</li>
|
||||
<li>✅ Print status notifications</li>
|
||||
<li>✅ Enhanced print button with visual feedback</li>
|
||||
</ul>
|
||||
|
||||
<h4>Installation Instructions:</h4>
|
||||
<ol>
|
||||
<li><strong>Download Extension Files:</strong>
|
||||
<div class="mt-2 mb-3">
|
||||
<button class="btn btn-primary" id="download-extension-btn">
|
||||
📥 Download Chrome Extension (.zip)
|
||||
</button>
|
||||
<br><br>
|
||||
<div class="alert alert-info" style="font-size: 12px;">
|
||||
<strong>Alternative:</strong> Download individual files:
|
||||
<br>
|
||||
<a href="{{ url_for('main.extension_files', filename='manifest.json') }}" target="_blank">manifest.json</a> |
|
||||
<a href="{{ url_for('main.extension_files', filename='background.js') }}" target="_blank">background.js</a> |
|
||||
<a href="{{ url_for('main.extension_files', filename='content.js') }}" target="_blank">content.js</a> |
|
||||
<a href="{{ url_for('main.extension_files', filename='popup.html') }}" target="_blank">popup.html</a> |
|
||||
<a href="{{ url_for('main.extension_files', filename='popup.js') }}" target="_blank">popup.js</a>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<li><strong>Extract Files:</strong>
|
||||
<p>Extract the downloaded ZIP file to a folder on your computer (e.g., Desktop/print_extension)</p>
|
||||
</li>
|
||||
|
||||
<li><strong>Open Chrome Extensions:</strong>
|
||||
<p>In Google Chrome, go to: <code>chrome://extensions/</code></p>
|
||||
</li>
|
||||
|
||||
<li><strong>Enable Developer Mode:</strong>
|
||||
<p>Toggle the "Developer mode" switch in the top-right corner</p>
|
||||
</li>
|
||||
|
||||
<li><strong>Load Extension:</strong>
|
||||
<p>Click "Load unpacked" and select the folder where you extracted the files</p>
|
||||
</li>
|
||||
|
||||
<li><strong>Verify Installation:</strong>
|
||||
<p>The extension icon 🖨️ should appear in your Chrome toolbar</p>
|
||||
</li>
|
||||
</ol>
|
||||
|
||||
<h4>Usage:</h4>
|
||||
<ol>
|
||||
<li>Navigate to the <a href="{{ url_for('main.print_module') }}" target="_blank">Print Module</a></li>
|
||||
<li>Select an order from the table</li>
|
||||
<li>Click the enhanced "🖨️ Print Direct" button</li>
|
||||
<li>The label will print automatically to your default printer</li>
|
||||
</ol>
|
||||
|
||||
<div class="alert alert-warning">
|
||||
<strong>System Requirements:</strong>
|
||||
<ul class="mb-0">
|
||||
<li>Google Chrome browser (version 88 or higher)</li>
|
||||
<li>Default printer configured on your system</li>
|
||||
<li>Printer drivers installed and working</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-success">
|
||||
<strong>Troubleshooting:</strong>
|
||||
<ul class="mb-0">
|
||||
<li>Click the extension icon 🖨️ to test printer connection</li>
|
||||
<li>Check Chrome's printer settings: <code>chrome://settings/printing</code></li>
|
||||
<li>Ensure your default printer is set correctly</li>
|
||||
<li>Reload the Print Module page after installing the extension</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="mt-4 text-center">
|
||||
<a href="{{ url_for('main.print_module') }}" class="btn btn-success">
|
||||
🖨️ Go to Print Module
|
||||
</a>
|
||||
<button class="btn btn-secondary" onclick="window.close()">
|
||||
✖️ Close
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Create ZIP file dynamically when download is requested
|
||||
document.getElementById('download-extension-btn').addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Show loading state
|
||||
this.innerHTML = '⏳ Preparing Download...';
|
||||
this.disabled = true;
|
||||
|
||||
// Create the extension package
|
||||
fetch('/create_extension_package', {method: 'POST'})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
// Start download
|
||||
window.location.href = data.download_url;
|
||||
|
||||
// Reset button
|
||||
setTimeout(() => {
|
||||
this.innerHTML = '📥 Download Chrome Extension (.zip)';
|
||||
this.disabled = false;
|
||||
}, 2000);
|
||||
} else {
|
||||
alert('Error creating extension package: ' + data.error);
|
||||
this.innerHTML = '📥 Download Chrome Extension (.zip)';
|
||||
this.disabled = false;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
alert('Error: ' + error.message);
|
||||
this.innerHTML = '📥 Download Chrome Extension (.zip)';
|
||||
this.disabled = false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -239,6 +239,11 @@ table tbody tr.selected td {
|
||||
<label for="print-label-btn" style="font-size: 14px; font-weight: 500; color: var(--app-card-text); margin-bottom: 0;">Print selected order</label>
|
||||
<button id="print-label-btn" class="btn btn-primary" style="font-size: 14px; padding: 6px 24px;">Print</button>
|
||||
</div>
|
||||
<div style="width: 100%; text-align: center; margin-top: 12px;">
|
||||
<a href="{{ url_for('main.download_extension') }}" target="_blank" style="font-size: 12px; color: #007bff; text-decoration: none;">
|
||||
🔗 Install Direct Print Extension
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Data Preview Card -->
|
||||
@@ -349,6 +354,9 @@ document.getElementById('check-db-btn').addEventListener('click', function() {
|
||||
if (data.length > 0) {
|
||||
updateLabelPreview(data[0]);
|
||||
|
||||
// Add fallback print functionality if extension is not available
|
||||
addFallbackPrintHandler();
|
||||
|
||||
// Auto-select first row
|
||||
setTimeout(() => {
|
||||
const firstRow = document.querySelector('.print-module-table tbody tr');
|
||||
@@ -428,5 +436,81 @@ function updateLabelPreview(order) {
|
||||
// Update barcode with the same prod order data
|
||||
document.getElementById('barcode-text').textContent = prodOrder;
|
||||
}
|
||||
|
||||
// Fallback print handler for when Chrome extension is not available
|
||||
function addFallbackPrintHandler() {
|
||||
// Check if Chrome extension modified the button
|
||||
setTimeout(() => {
|
||||
const printButton = document.getElementById('print-label-btn');
|
||||
|
||||
// If button text hasn't changed, extension is not active
|
||||
if (printButton && !printButton.innerHTML.includes('🖨️ Print Direct')) {
|
||||
console.log('Chrome extension not detected, adding fallback print handler');
|
||||
|
||||
// Add fallback event listener
|
||||
printButton.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const labelPreview = document.getElementById('label-preview');
|
||||
if (!labelPreview) {
|
||||
alert('Please select an order first.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a new window for printing
|
||||
const printWindow = window.open('', '_blank');
|
||||
const printContent = `
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Quality Recticel Label</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
.print-container {
|
||||
width: 210mm;
|
||||
height: 297mm;
|
||||
margin: 0 auto;
|
||||
}
|
||||
.label-wrapper {
|
||||
transform: scale(1.2);
|
||||
transform-origin: top left;
|
||||
}
|
||||
@media print {
|
||||
body { padding: 0; }
|
||||
.print-container { margin: 0; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="print-container">
|
||||
<div class="label-wrapper">
|
||||
${labelPreview.outerHTML}
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
printWindow.document.write(printContent);
|
||||
printWindow.document.close();
|
||||
|
||||
// Wait for content to load, then print
|
||||
printWindow.onload = function() {
|
||||
printWindow.focus();
|
||||
printWindow.print();
|
||||
printWindow.close();
|
||||
};
|
||||
});
|
||||
|
||||
// Update button text to indicate fallback mode
|
||||
printButton.innerHTML = '🖨️ Print (Browser)';
|
||||
printButton.title = 'Print using browser dialog - Install Chrome Extension for direct printing';
|
||||
}
|
||||
}, 2000); // Wait 2 seconds for extension to load
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user