MVP
This commit is contained in:
parent
34dfc28740
commit
888be36ca0
@ -11,13 +11,13 @@ app.use(express.static('public'));
|
|||||||
app.use(express.json());
|
app.use(express.json());
|
||||||
|
|
||||||
// Test print function
|
// Test print function
|
||||||
app.post('/test-print', async (req, res) => {
|
app.post('/print', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { username, studentId } = req.body;
|
const { username, studentId } = req.body;
|
||||||
if (!username || !studentId) {
|
if (!username || !studentId) {
|
||||||
return res.status(400).json({ message: 'Username and Student ID are required.' });
|
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) {
|
} catch (error) {
|
||||||
console.error('Print Error:', error);
|
console.error('Print Error:', error);
|
||||||
res.status(500).json({ message: 'Print Error', error: error.message });
|
res.status(500).json({ message: 'Print Error', error: error.message });
|
||||||
|
@ -4,7 +4,7 @@ const { spawn } = require('child_process');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
generateFile(username, studentId, req, res) {
|
printCredentials(username, studentId, req, res) {
|
||||||
// Create the output text
|
// Create the output text
|
||||||
const infoArray = [
|
const infoArray = [
|
||||||
'Username:',
|
'Username:',
|
||||||
|
@ -3,19 +3,38 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<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>
|
</head>
|
||||||
<body>
|
<body class="bg-gray-100 font-sans leading-normal tracking-normal">
|
||||||
<h1>Thermal Printer Test</h1>
|
<div class="max-w-lg mx-auto mt-10 bg-white p-8 rounded-lg shadow-lg">
|
||||||
<form id="printForm">
|
<h1 class="text-2xl font-bold text-center mb-4 text-gray-700">ITS Credential Printer</h1>
|
||||||
<label for="username">Username:</label>
|
<p class="text-center text-gray-600 mb-6">
|
||||||
<input type="text" id="username" name="username" required><br><br>
|
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>
|
<form id="printForm" class="space-y-4">
|
||||||
<input type="text" id="studentId" name="studentId" required><br><br>
|
<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>
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
document.getElementById('printForm').addEventListener('submit', (event) => {
|
document.getElementById('printForm').addEventListener('submit', (event) => {
|
||||||
@ -27,7 +46,7 @@
|
|||||||
const studentId = formData.get('studentId');
|
const studentId = formData.get('studentId');
|
||||||
|
|
||||||
// Send a POST request with the form data to the server
|
// Send a POST request with the form data to the server
|
||||||
fetch('/test-print', {
|
fetch('/print', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
Loading…
Reference in New Issue
Block a user