This commit is contained in:
Skylar Grant 2024-09-10 13:29:16 -04:00
parent 34dfc28740
commit 888be36ca0
3 changed files with 33 additions and 14 deletions

View File

@ -11,13 +11,13 @@ app.use(express.static('public'));
app.use(express.json());
// Test print function
app.post('/test-print', async (req, res) => {
app.post('/print', async (req, res) => {
try {
const { username, studentId } = req.body;
if (!username || !studentId) {
return res.status(400).json({ message: 'Username and Student ID are required.' });
}
await Thermal.generateFile(username, studentId, req, res);
await Thermal.printCredentials(username, studentId, req, res);
} catch (error) {
console.error('Print Error:', error);
res.status(500).json({ message: 'Print Error', error: error.message });

View File

@ -4,7 +4,7 @@ const { spawn } = require('child_process');
const path = require('path');
module.exports = {
generateFile(username, studentId, req, res) {
printCredentials(username, studentId, req, res) {
// Create the output text
const infoArray = [
'Username:',

View File

@ -3,19 +3,38 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thermal Printer Test</title>
<title>Credential Printer</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<h1>Thermal Printer Test</h1>
<form id="printForm">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required><br><br>
<body class="bg-gray-100 font-sans leading-normal tracking-normal">
<div class="max-w-lg mx-auto mt-10 bg-white p-8 rounded-lg shadow-lg">
<h1 class="text-2xl font-bold text-center mb-4 text-gray-700">ITS Credential Printer</h1>
<p class="text-center text-gray-600 mb-6">
Provide the username and student ID in the fields below, then click the Print button.
A pre-formatted receipt will print with the information from the thermal printer.
</p>
<label for="studentId">Student ID:</label>
<input type="text" id="studentId" name="studentId" required><br><br>
<form id="printForm" class="space-y-4">
<div>
<label for="username" class="block text-sm font-medium text-gray-700">Username:</label>
<input type="text" id="username" name="username" required
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
</div>
<button type="submit">Test Print</button>
<div>
<label for="studentId" class="block text-sm font-medium text-gray-700">Student ID:</label>
<input type="text" id="studentId" name="studentId" required
class="mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm">
</div>
<div class="text-center">
<button type="submit"
class="w-full bg-indigo-600 text-white py-2 px-4 rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-opacity-50">
Print
</button>
</div>
</form>
</div>
<script>
document.getElementById('printForm').addEventListener('submit', (event) => {
@ -27,7 +46,7 @@
const studentId = formData.get('studentId');
// Send a POST request with the form data to the server
fetch('/test-print', {
fetch('/print', {
method: 'POST',
headers: {
'Content-Type': 'application/json',