Add project files.

This commit is contained in:
EugeneTes
2026-01-13 09:06:47 +01:00
parent dd935fe1fa
commit 7390693f50
187 changed files with 83457 additions and 0 deletions

View File

@@ -0,0 +1,263 @@
@page
@model ConfigurationPannel.Pages.ConfigureModel
@{
ViewData["Title"] = "Printer Configuration";
}
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2>Printer Configuration</h2>
<div>
<button type="button" class="btn btn-secondary" onclick="discoverPrinters()">
<span id="discover-spinner" class="spinner-border spinner-border-sm d-none"></span>
Discover Printers
</button>
<a asp-page="/Logout" class="btn btn-outline-secondary">Logout</a>
</div>
</div>
<div id="discovery-status" class="alert alert-info d-none">
Discovering printers...
</div>
<div id="discovered-printers" class="mb-4">
<h5>Discovered Printers: <span id="printer-count">@Model.DiscoveredPrinters.Count</span></h5>
<ul id="printer-list" class="list-group">
@foreach (var printer in Model.DiscoveredPrinters)
{
<li class="list-group-item">@printer.IPAddress </li>
}
</ul>
</div>
<div class="card mb-4">
<div class="card-header d-flex justify-content-between align-items-center">
<h4>Logo Management</h4>
<button type="button" class="btn btn-sm btn-warning" onclick="document.getElementById('cleanLogosForm').submit()">
Clean Unused Logos
</button>
</div>
<div class="card-body">
<form method="post" asp-page-handler="UploadLogo" enctype="multipart/form-data" class="d-flex gap-2 align-items-center">
<input type="file" name="UploadedLogo" accept=".png,.jpg,.jpeg,.gif,.bmp" class="form-control" style="max-width: 400px;" />
<button type="submit" class="btn btn-primary">Upload Logo</button>
</form>
<small class="text-muted">Supported formats: PNG, JPG, JPEG, GIF, BMP</small>
@if (Model.AvailableLogos.Any())
{
<div class="mt-3">
<strong>Available logos (@Model.AvailableLogos.Count):</strong>
<div class="d-flex flex-wrap gap-2 mt-2">
@foreach (var logo in Model.AvailableLogos)
{
<div class="border p-2 text-center" style="width: 120px;">
<a href="/logos/@logo" target="_blank">
<img src="/logos/@logo" alt="@logo" style="max-width: 100px; max-height: 80px;" class="d-block mx-auto" />
</a>
<small class="text-muted d-block mt-1" style="font-size: 10px; word-break: break-all;">@logo</small>
</div>
}
</div>
</div>
}
</div>
</div>
<!-- Hidden form for cleaning logos -->
<form id="cleanLogosForm" method="post" asp-page-handler="CleanLogos" style="display: none;"></form>
<form method="post" asp-page-handler="Save">
<div class="card">
<div class="card-header">
<h4>Work Area Assignments</h4>
</div>
<div class="card-body">
@if (Model.WorkAreas == null || !Model.WorkAreas.Any())
{
<div class="alert alert-warning">No work areas found. Check configuration.</div>
}
else
{
<table class="table table-hover">
<thead>
<tr>
<th>Work Area</th>
<th>Assigned Printer</th>
<th>Font Size</th>
<th>Logo</th>
</tr>
</thead>
<tbody>
@for (int i = 0; i < Model.WorkAreas.Count; i++)
{
var workArea = Model.WorkAreas[i];
var currentPrinter = Model.CurrentAssignments.TryGetValue(workArea.Id, out var assigned) ? assigned.Address : "";
var currentFontSize = Model.CurrentAssignments.TryGetValue(workArea.Id, out var cfg) ? cfg.FontSize : 1;
<tr>
<td>
<strong>@workArea.Name</strong>
<input type="hidden" name="WorkAreaAssignments[@i].WorkAreaId" value="@workArea.Id" />
<input type="hidden" name="WorkAreaAssignments[@i].WorkAreaName" value="@workArea.Name" />
</td>
<td>
<select name="WorkAreaAssignments[@i].PrinterAddress"
class="form-select printer-select"
data-workarea="@workArea.Id">
<option value="">None</option>
@foreach (var printer in Model.DiscoveredPrinters)
{
var selected = currentPrinter == printer.IPAddress;
<option value="@printer.IPAddress" selected="@selected">
@printer.IPAddress @(!string.IsNullOrEmpty(printer.ModelName) ? $"({printer.ModelName})" : "")
</option>
}
</select>
</td>
<td>
<input type="number"
name="WorkAreaAssignments[@i].FontSize"
class="form-control"
min="1"
max="4"
value="@currentFontSize"
style="width: 80px;" />
</td>
<td>
@{
var currentLogo = Model.CurrentAssignments.TryGetValue(workArea.Id, out var cfgLogo) ? cfgLogo.LogoFilename : "";
}
<select name="WorkAreaAssignments[@i].LogoFilename"
id="logo-select-@i"
class="form-select logo-select"
onchange="updateLogoPreview(@i)"
style="max-width: 200px;">
<option value="">None</option>
@foreach (var logo in Model.AvailableLogos)
{
var selected = currentLogo == logo;
<option value="@logo" selected="@selected">@logo</option>
}
</select>
<div id="logo-preview-@i" class="mt-2" style="display: none;">
<a href="#" target="_blank" id="logo-link-@i">
<img id="logo-img-@i" src="" alt="Logo preview" style="max-height: 100px; cursor: pointer;" />
</a>
</div>
</td>
</tr>
}
</tbody>
</table>
}
</div>
</div>
<div class="mt-3">
<button type="submit" class="btn btn-primary btn-lg">Save Configuration</button>
</div>
@if (!string.IsNullOrEmpty(Model.SuccessMessage))
{
<div class="alert alert-success mt-3">@Model.SuccessMessage</div>
}
@if (!string.IsNullOrEmpty(Model.ErrorMessage))
{
<div class="alert alert-danger mt-3">@Model.ErrorMessage</div>
}
</form>
</div>
@section Scripts {
<script>
async function discoverPrinters() {
const button = document.querySelector('button[onclick="discoverPrinters()"]');
const spinner = document.getElementById('discover-spinner');
const status = document.getElementById('discovery-status');
const printerList = document.getElementById('printer-list');
const printerCount = document.getElementById('printer-count');
button.disabled = true;
spinner.classList.remove('d-none');
status.classList.remove('d-none');
printerList.innerHTML = '';
printerCount.textContent = '0';
try {
const response = await fetch('/Configure?handler=Discover', {
method: 'POST',
headers: {
'RequestVerificationToken': document.querySelector('input[name="__RequestVerificationToken"]').value
}
});
const printers = await response.json();
printerCount.textContent = printers.length;
if (printers.length === 0) {
printerList.innerHTML = '<li class="list-group-item">No printers found</li>';
} else {
// Update all select dropdowns with discovered printers
document.querySelectorAll('.printer-select').forEach(select => {
const currentValue = select.value;
// Keep "None" option
select.innerHTML = '<option value="">None</option>';
printers.forEach(printer => {
const option = document.createElement('option');
option.value = printer.ipAddress;
option.textContent = `${printer.ipAddress} ${printer.modelName ? '(' + printer.modelName + ')' : ''}`;
if (printer.ipAddress === currentValue) {
option.selected = true;
}
select.appendChild(option);
});
});
// Show discovered printers list
printers.forEach(printer => {
const li = document.createElement('li');
li.className = 'list-group-item';
li.textContent = `${printer.ipAddress}`;
printerList.appendChild(li);
});
}
} catch (error) {
printerList.innerHTML = `<li class="list-group-item text-danger">Error: ${error.message}</li>`;
} finally {
button.disabled = false;
spinner.classList.add('d-none');
status.classList.add('d-none');
}
}
function updateLogoPreview(index) {
const select = document.getElementById(`logo-select-${index}`);
const preview = document.getElementById(`logo-preview-${index}`);
const img = document.getElementById(`logo-img-${index}`);
const link = document.getElementById(`logo-link-${index}`);
if (select.value) {
const logoUrl = `/logos/${select.value}`;
img.src = logoUrl;
link.href = logoUrl;
preview.style.display = 'block';
} else {
preview.style.display = 'none';
}
}
// Initialize previews on page load
document.addEventListener('DOMContentLoaded', function() {
const selects = document.querySelectorAll('.logo-select');
selects.forEach((select, index) => {
if (select.value) {
updateLogoPreview(index);
}
});
});
</script>
}

View File

@@ -0,0 +1,225 @@
using ConfigurationPannel.Services;
using Inspectron.Epson;
using Inspectron.Epson.PrintServer.ConfigurationSources;
using Inspectron.Epson.PrintServer.PrintServices;
using Inspectron.Epson.PrintServer.WorkAreaSources;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Reflection;
using ConfigurationManager = ConfigurationPannel.Services.ConfigurationManager;
namespace ConfigurationPannel.Pages;
[Authorize]
public class ConfigureModel : PageModel
{
private readonly ConfigurationManager _configManager;
private readonly PrintServerHostedService _printServerService;
private readonly LogoService _logoService;
private readonly IWebHostEnvironment _env;
private readonly ENPCDiscoveryService _discoveryService;
private readonly ILogger<ConfigureModel> _logger;
public ConfigureModel(
ConfigurationManager configManager,
PrintServerHostedService printServerService,
LogoService logoService,
IWebHostEnvironment env,
ILogger<ConfigureModel> logger)
{
_configManager = configManager;
_printServerService = printServerService;
_logoService = logoService;
_env = env;
_discoveryService = new ENPCDiscoveryService();
_logger = logger;
}
public List<WorkArea> WorkAreas { get; set; } = new();
public List<DiscoveredPrinter> DiscoveredPrinters { get; set; } = new();
public Dictionary<string, PrinterConfiguration> CurrentAssignments { get; set; } = new();
public List<string> AvailableLogos { get; set; } = new();
[BindProperty]
public List<WorkAreaAssignment> WorkAreaAssignments { get; set; } = new();
[BindProperty]
public IFormFile? UploadedLogo { get; set; }
public string SuccessMessage { get; set; } = string.Empty;
public string ErrorMessage { get; set; } = string.Empty;
public async Task<IActionResult> OnGetAsync()
{
try
{
// Load current configuration
var config = await _configManager.LoadConfigurationAsync();
// Get work areas from API
var workAreaSource = new JamesWorkAreaSource(config);
WorkAreas = await workAreaSource.GetWorkAreasAsync();
// Map current assignments
CurrentAssignments = config.PrinterConfigurations
.GroupBy(kv => kv.Value.AreaId)
.ToDictionary(g => g.Key, g => g.First().Value);
// Initial discovery (quick timeout for page load)
DiscoveredPrinters = await _discoveryService.DiscoverPrintersAsync(TimeSpan.FromSeconds(3));
// Load available logos
AvailableLogos = _logoService.GetAllLogos();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error loading configuration page");
ErrorMessage = "Error loading configuration: " + ex.Message;
}
return Page();
}
public async Task<IActionResult> OnPostDiscoverAsync()
{
try
{
var printers = await _discoveryService.DiscoverPrintersAsync(TimeSpan.FromSeconds(5));
return new JsonResult(printers.Select(p => new
{
ipAddress = p.IPAddress,
modelName = p.ModelName,
macAddress = p.MACAddress
}));
}
catch (Exception ex)
{
_logger.LogError(ex, "Error discovering printers");
return new JsonResult(new { error = ex.Message }) { StatusCode = 500 };
}
}
public async Task<IActionResult> OnPostUploadLogoAsync()
{
try
{
if (UploadedLogo != null)
{
var filename = await _logoService.SaveLogoAsync(UploadedLogo);
SuccessMessage = $"Logo uploaded successfully: {filename}";
}
else
{
ErrorMessage = "No file selected";
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error uploading logo");
ErrorMessage = "Error uploading logo: " + ex.Message;
}
return await OnGetAsync();
}
public async Task<IActionResult> OnPostCleanLogosAsync()
{
try
{
var config = await _configManager.LoadConfigurationAsync();
var usedLogos = config.PrinterConfigurations.Values
.Select(p => p.LogoFilename)
.Where(f => !string.IsNullOrEmpty(f))
.ToList();
var cleanedLogos = _logoService.CleanUnusedLogos(usedLogos!);
if (cleanedLogos.Any())
{
SuccessMessage = $"Cleaned {cleanedLogos.Count} unused logo(s): {string.Join(", ", cleanedLogos)}";
}
else
{
SuccessMessage = "No unused logos found";
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error cleaning logos");
ErrorMessage = "Error cleaning logos: " + ex.Message;
}
return await OnGetAsync();
}
public async Task<IActionResult> OnPostSaveAsync()
{
try
{
// Load current config
var config = await _configManager.LoadConfigurationAsync();
// Clear existing printer configurations
var newPrinterConfigurations = new Dictionary<string, PrinterConfiguration>();
// Build new configurations from assignments
foreach (var assignment in WorkAreaAssignments)
{
if (!string.IsNullOrEmpty(assignment.PrinterAddress))
{
var printerKey = assignment.PrinterAddress;
if (!newPrinterConfigurations.ContainsKey(printerKey))
{
newPrinterConfigurations[printerKey] = new PrinterConfiguration
{
Address = assignment.PrinterAddress,
AreaId = assignment.WorkAreaId,
FontSize = assignment.FontSize,
LogoFilename = assignment.LogoFilename
};
// Copy logo to printer service directory
if (!string.IsNullOrEmpty(assignment.LogoFilename))
{
var printerServicePath = Path.Combine("logos");
_logoService.CopyLogoToDirectory(assignment.LogoFilename, printerServicePath);
}
}
}
}
// Update configuration
config.PrinterConfigurations = newPrinterConfigurations;
// Save configuration
await _configManager.SaveConfigurationAsync(config);
// Restart PrintLoop with new configuration
await _printServerService.RestartAsync();
SuccessMessage = "Configuration saved and print server restarted successfully!";
_logger.LogInformation("Configuration saved successfully");
// Reload page data
return await OnGetAsync();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error saving configuration");
ErrorMessage = "Error saving configuration: " + ex.Message;
return await OnGetAsync();
}
}
}
public class WorkAreaAssignment
{
public string WorkAreaId { get; set; } = string.Empty;
public string WorkAreaName { get; set; } = string.Empty;
public string PrinterAddress { get; set; } = string.Empty;
public int FontSize { get; set; } = 1;
public string? LogoFilename { get; set; }
}

View File

@@ -0,0 +1,26 @@
@page
@model ErrorModel
@{
ViewData["Title"] = "Error";
}
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (Model.ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@Model.RequestId</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>

View File

@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Diagnostics;
namespace ConfigurationPannel.Pages
{
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
[IgnoreAntiforgeryToken]
public class ErrorModel : PageModel
{
public string? RequestId { get; set; }
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
private readonly ILogger<ErrorModel> _logger;
public ErrorModel(ILogger<ErrorModel> logger)
{
_logger = logger;
}
public void OnGet()
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
}
}
}

View File

@@ -0,0 +1,10 @@
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
</div>

View File

@@ -0,0 +1,24 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace ConfigurationPannel.Pages
{
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
public IndexModel(ILogger<IndexModel> logger)
{
_logger = logger;
}
public IActionResult OnGet()
{
if (User.Identity?.IsAuthenticated == true)
{
return RedirectToPage("/Configure");
}
return RedirectToPage("/Login");
}
}
}

View File

@@ -0,0 +1,33 @@
@page
@model ConfigurationPannel.Pages.LoginModel
@{
ViewData["Title"] = "Login";
Layout = "_Layout";
}
<div class="container">
<div class="row justify-content-center mt-5">
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h3 class="card-title text-center mb-4">Printer Configuration</h3>
<form method="post">
<div class="mb-3">
<label asp-for="Username" class="form-label">Username</label>
<input asp-for="Username" class="form-control" placeholder="Enter username" required />
</div>
<div class="mb-3">
<label asp-for="Password" class="form-label">Password</label>
<input asp-for="Password" type="password" class="form-control" placeholder="Enter password" required />
</div>
@if (!string.IsNullOrEmpty(Model.ErrorMessage))
{
<div class="alert alert-danger">@Model.ErrorMessage</div>
}
<button type="submit" class="btn btn-primary w-100">Login</button>
</form>
</div>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,53 @@
using System.Security.Claims;
using ConfigurationPannel.Services;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace ConfigurationPannel.Pages;
public class LoginModel : PageModel
{
private readonly UserService _userService;
public LoginModel(UserService userService)
{
_userService = userService;
}
[BindProperty]
public string Username { get; set; } = string.Empty;
[BindProperty]
public string Password { get; set; } = string.Empty;
public string ErrorMessage { get; set; } = string.Empty;
public void OnGet()
{
}
public async Task<IActionResult> OnPostAsync()
{
if (await _userService.ValidateCredentialsAsync(Username, Password))
{
var claims = new List<Claim>
{
new Claim(ClaimTypes.Name, Username)
};
var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
var principal = new ClaimsPrincipal(identity);
await HttpContext.SignInAsync(
CookieAuthenticationDefaults.AuthenticationScheme,
principal);
return RedirectToPage("/Configure");
}
ErrorMessage = "Invalid username or password";
return Page();
}
}

View File

@@ -0,0 +1,2 @@
@page
@model ConfigurationPannel.Pages.LogoutModel

View File

@@ -0,0 +1,15 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace ConfigurationPannel.Pages;
public class LogoutModel : PageModel
{
public async Task<IActionResult> OnGetAsync()
{
await HttpContext.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme);
return RedirectToPage("/Login");
}
}

View File

@@ -0,0 +1,8 @@
@page
@model PrivacyModel
@{
ViewData["Title"] = "Privacy Policy";
}
<h1>@ViewData["Title"]</h1>
<p>Use this page to detail your site's privacy policy.</p>

View File

@@ -0,0 +1,20 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace ConfigurationPannel.Pages
{
public class PrivacyModel : PageModel
{
private readonly ILogger<PrivacyModel> _logger;
public PrivacyModel(ILogger<PrivacyModel> logger)
{
_logger = logger;
}
public void OnGet()
{
}
}
}

View File

@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - ConfigurationPannel</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/ConfigurationPannel.styles.css" asp-append-version="true" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container">
<a class="navbar-brand" asp-area="" asp-page="/Index">ConfigurationPannel</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
@if (User.Identity?.IsAuthenticated == true)
{
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/Configure">Configuration</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-page="/TestPrint">Test Print</a>
</li>
}
</ul>
<ul class="navbar-nav">
@if (User.Identity?.IsAuthenticated == true)
{
<li class="nav-item">
<span class="navbar-text me-3">Welcome, @User.Identity.Name</span>
</li>
}
</ul>
</div>
</div>
</nav>
</header>
<div class="container">
<main role="main" class="pb-3">
@RenderBody()
</main>
</div>
<footer class="border-top footer text-muted">
<div class="container">
&copy; 2025 - ConfigurationPannel - <a asp-area="" asp-page="/Privacy">Privacy</a>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>

View File

@@ -0,0 +1,48 @@
/* Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
for details on configuring this project to bundle and minify static web assets. */
a.navbar-brand {
white-space: normal;
text-align: center;
word-break: break-all;
}
a {
color: #0077cc;
}
.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
.nav-pills .nav-link.active, .nav-pills .show > .nav-link {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
.border-top {
border-top: 1px solid #e5e5e5;
}
.border-bottom {
border-bottom: 1px solid #e5e5e5;
}
.box-shadow {
box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05);
}
button.accept-policy {
font-size: 1rem;
line-height: inherit;
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
white-space: nowrap;
line-height: 60px;
}

View File

@@ -0,0 +1,2 @@
<script src="~/lib/jquery-validation/dist/jquery.validate.min.js"></script>
<script src="~/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js"></script>

View File

@@ -0,0 +1,62 @@
@page
@model ConfigurationPannel.Pages.TestPrintModel
@{
ViewData["Title"] = "Test Print";
}
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-4">
<h2>Test Print</h2>
<a asp-page="/Logout" class="btn btn-outline-secondary">Logout</a>
</div>
<form method="post">
<div class="card">
<div class="card-header">
<h4>Submit Test Print Job</h4>
</div>
<div class="card-body">
@if (Model.WorkAreas == null || !Model.WorkAreas.Any())
{
<div class="alert alert-warning">
No work areas found. Please check configuration.
</div>
}
else
{
<div class="mb-3">
<label asp-for="SelectedWorkAreaId" class="form-label">Work Area</label>
<select asp-for="SelectedWorkAreaId" class="form-select" required>
<option value="">Select a work area...</option>
@foreach (var workArea in Model.WorkAreas)
{
<option value="@workArea.Id">@workArea.Name</option>
}
</select>
</div>
<div class="mb-3">
<label asp-for="PrintContent" class="form-label">Content to Print</label>
<textarea asp-for="PrintContent"
class="form-control"
rows="6"
placeholder="Enter text to print..."
required></textarea>
<small class="text-muted">Text will be printed on the assigned printer for the selected work area</small>
</div>
<button type="submit" class="btn btn-primary">Submit Print Job</button>
}
</div>
</div>
@if (!string.IsNullOrEmpty(Model.SuccessMessage))
{
<div class="alert alert-success mt-3">@Model.SuccessMessage</div>
}
@if (!string.IsNullOrEmpty(Model.ErrorMessage))
{
<div class="alert alert-danger mt-3">@Model.ErrorMessage</div>
}
</form>
</div>

View File

@@ -0,0 +1,92 @@
using ConfigurationPannel.Services;
using Inspectron.Epson.PrintServer.WorkAreaSources;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using ConfigurationManager = ConfigurationPannel.Services.ConfigurationManager;
namespace ConfigurationPannel.Pages;
[Authorize]
public class TestPrintModel : PageModel
{
private readonly ConfigurationManager _configManager;
private readonly PrintServerHostedService _printServerService;
private readonly ILogger<TestPrintModel> _logger;
public TestPrintModel(
ConfigurationManager configManager,
PrintServerHostedService printServerService,
ILogger<TestPrintModel> logger)
{
_configManager = configManager;
_printServerService = printServerService;
_logger = logger;
}
public List<WorkArea> WorkAreas { get; set; } = new();
[BindProperty]
public string SelectedWorkAreaId { get; set; } = string.Empty;
[BindProperty]
public string PrintContent { get; set; } = string.Empty;
public string SuccessMessage { get; set; } = string.Empty;
public string ErrorMessage { get; set; } = string.Empty;
public async Task<IActionResult> OnGetAsync()
{
try
{
var config = await _configManager.LoadConfigurationAsync();
var workAreaSource = new JamesWorkAreaSource(config);
WorkAreas = await workAreaSource.GetWorkAreasAsync();
}
catch (Exception ex)
{
_logger.LogError(ex, "Error loading test print page");
ErrorMessage = "Error loading work areas: " + ex.Message;
}
return Page();
}
public async Task<IActionResult> OnPostAsync()
{
try
{
if (string.IsNullOrWhiteSpace(SelectedWorkAreaId))
{
ErrorMessage = "Please select a work area";
return await OnGetAsync();
}
if (string.IsNullOrWhiteSpace(PrintContent))
{
ErrorMessage = "Please enter content to print";
return await OnGetAsync();
}
var (success, message) = await _printServerService.SubmitPrintJobAsync(
SelectedWorkAreaId,
PrintContent);
if (success)
{
SuccessMessage = message;
PrintContent = string.Empty;
}
else
{
ErrorMessage = message;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Error submitting test print job");
ErrorMessage = "Error submitting print job: " + ex.Message;
}
return await OnGetAsync();
}
}

View File

@@ -0,0 +1,3 @@
@using ConfigurationPannel
@namespace ConfigurationPannel.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@@ -0,0 +1,3 @@
@{
Layout = "_Layout";
}