Compare commits
4 Commits
bec9ea2356
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de4e9421af | ||
|
|
b622df4187 | ||
|
|
746465d8fe | ||
|
|
559829882a |
@@ -1,16 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using DevExpress.AspNetCore.Reporting.WebDocumentViewer;
|
|
||||||
using DevExpress.AspNetCore.Reporting.WebDocumentViewer.Native.Services;
|
|
||||||
|
|
||||||
namespace DXApp.TemplateKitProject.Controllers
|
|
||||||
{
|
|
||||||
[Route("DocumentViewer")]
|
|
||||||
public class DocumentViewerController : WebDocumentViewerController
|
|
||||||
{
|
|
||||||
// Hier den erwarteten DevExpress-Service injizieren und an die Basisklasse weitergeben
|
|
||||||
public DocumentViewerController(IWebDocumentViewerMvcControllerService controllerService)
|
|
||||||
: base(controllerService)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,10 +16,8 @@
|
|||||||
</Target>
|
</Target>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DevExpress.AspNetCore.Reporting" Version="25.2.7" />
|
|
||||||
<PackageReference Include="DevExpress.Document.Processor" Version="25.2.7" />
|
<PackageReference Include="DevExpress.Document.Processor" Version="25.2.7" />
|
||||||
<PackageReference Include="DevExpress.Pdf.Drawing" Version="25.2.7" />
|
<PackageReference Include="DevExtreme.AspNet.Core" Version="25.2.*" />
|
||||||
<PackageReference Include="DevExtreme.AspNet.Core" Version="25.2.7" />
|
|
||||||
<PackageReference Include="MailKit" Version="4.16.0" />
|
<PackageReference Include="MailKit" Version="4.16.0" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
|
||||||
@@ -29,4 +27,8 @@
|
|||||||
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="3.0.71" />
|
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="3.0.71" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Controllers\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,119 +0,0 @@
|
|||||||
using DevExpress.XtraReports.UI;
|
|
||||||
using DevExpress.XtraReports.Web.Extensions;
|
|
||||||
using DXApp.TemplateKitProject.Data;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace DXApp.TemplateKitProject.DevExpressExtensions;
|
|
||||||
|
|
||||||
public class CustomReportStorageWebExtension : ReportStorageWebExtension
|
|
||||||
{
|
|
||||||
private readonly AppDbContext _db;
|
|
||||||
private readonly ILogger<CustomReportStorageWebExtension> _logger;
|
|
||||||
|
|
||||||
public CustomReportStorageWebExtension(
|
|
||||||
AppDbContext db,
|
|
||||||
ILogger<CustomReportStorageWebExtension> logger)
|
|
||||||
{
|
|
||||||
_db = db;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool CanSetData(string url)
|
|
||||||
{
|
|
||||||
// Wir erlauben KEIN Speichern von Änderungen über den Viewer
|
|
||||||
// PDFs sind bei uns Read-Only im Viewer
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool IsValidUrl(string url)
|
|
||||||
{
|
|
||||||
// Prüfen ob URL dem Format entspricht: "invoice-{id}"
|
|
||||||
return url.StartsWith("invoice-", StringComparison.OrdinalIgnoreCase);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override byte[] GetData(string url)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_logger.LogDebug("GetData aufgerufen für URL: {Url}", url);
|
|
||||||
|
|
||||||
// URL-Format: "invoice-123" → ID extrahieren
|
|
||||||
if (!url.StartsWith("invoice-", StringComparison.OrdinalIgnoreCase))
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Ungültige URL: {Url}", url);
|
|
||||||
return Array.Empty<byte>();
|
|
||||||
}
|
|
||||||
|
|
||||||
var idString = url.Substring("invoice-".Length);
|
|
||||||
if (!int.TryParse(idString, out var invoiceId))
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Ungültige Invoice-ID in URL: {Url}", url);
|
|
||||||
return Array.Empty<byte>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rechnung aus Datenbank laden
|
|
||||||
var invoice = _db.ZugferdInvoices
|
|
||||||
.AsNoTracking()
|
|
||||||
.FirstOrDefault(i => i.Id == invoiceId);
|
|
||||||
|
|
||||||
if (invoice == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Rechnung mit ID {Id} nicht gefunden.", invoiceId);
|
|
||||||
return Array.Empty<byte>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prüfen ob ResultFilePath existiert
|
|
||||||
if (string.IsNullOrEmpty(invoice.ResultFilePath))
|
|
||||||
{
|
|
||||||
_logger.LogWarning(
|
|
||||||
"Rechnung {Id} hat keine Result-PDF (ResultFilePath ist leer).",
|
|
||||||
invoiceId);
|
|
||||||
return Array.Empty<byte>();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Datei vom Dateisystem laden
|
|
||||||
if (!File.Exists(invoice.ResultFilePath))
|
|
||||||
{
|
|
||||||
_logger.LogError(
|
|
||||||
"Result-PDF-Datei nicht gefunden: {Path}",
|
|
||||||
invoice.ResultFilePath);
|
|
||||||
return Array.Empty<byte>();
|
|
||||||
}
|
|
||||||
|
|
||||||
var pdfBytes = File.ReadAllBytes(invoice.ResultFilePath);
|
|
||||||
|
|
||||||
_logger.LogInformation(
|
|
||||||
"Result-PDF geladen: Invoice {Id}, Größe: {Size} Bytes",
|
|
||||||
invoiceId,
|
|
||||||
pdfBytes.Length);
|
|
||||||
|
|
||||||
return pdfBytes;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Fehler beim Laden der PDF für URL: {Url}", url);
|
|
||||||
return Array.Empty<byte>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Dictionary<string, string> GetUrls()
|
|
||||||
{
|
|
||||||
// Diese Methode wird verwendet um eine Liste aller verfügbaren Reports zu liefern
|
|
||||||
// Für unseren Use-Case nicht benötigt (wir laden immer spezifisch eine Invoice)
|
|
||||||
return new Dictionary<string, string>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SetData(XtraReport report, string url)
|
|
||||||
{
|
|
||||||
// Nicht implementiert - wir erlauben kein Speichern über den Viewer
|
|
||||||
throw new NotSupportedException(
|
|
||||||
"Das Speichern von Reports über den Document Viewer ist nicht unterstützt.");
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string SetNewData(XtraReport report, string defaultUrl)
|
|
||||||
{
|
|
||||||
// Nicht implementiert - wir erstellen keine neuen Reports über den Viewer
|
|
||||||
throw new NotSupportedException(
|
|
||||||
"Das Erstellen neuer Reports über den Document Viewer ist nicht unterstützt.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
@if (!string.IsNullOrEmpty(Model.Invoice?.ResultFilePath))
|
@if (!string.IsNullOrEmpty(Model.Invoice?.ResultFilePath))
|
||||||
{
|
{
|
||||||
<a class="btn btn-primary mb-3 ms-2"
|
<button class="btn btn-primary mb-3 ms-2"
|
||||||
href="/Invoices/DocumentViewer?id=@Model.Invoice.Id">
|
onclick="openPdfViewer(@Model.Invoice.Id)">
|
||||||
<i class="dx-icon-pdffile"></i> Ergebnis anzeigen
|
<i class="dx-icon-pdffile"></i> Ergebnis anzeigen
|
||||||
</a>
|
</button>
|
||||||
}
|
}
|
||||||
|
|
||||||
@if (Model.Invoice is null)
|
@if (Model.Invoice is null)
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
@page
|
|
||||||
@model DXApp.TemplateKitProject.Pages.Invoices.DocumentViewerModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "Dokument Viewer";
|
|
||||||
var pdfUrl = Model.PdfUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
<div class="container-fluid" style="height:100vh; padding:0;">
|
|
||||||
<div class="d-flex align-items-center justify-content-between p-3 border-bottom">
|
|
||||||
<h5 class="m-0">Rechnung @Model.Id - Dokument</h5>
|
|
||||||
<div>
|
|
||||||
<a class="btn btn-secondary me-2" href="/Invoices">Zurück zur Übersicht</a>
|
|
||||||
<!-- Später: Button um DevExpress Viewer zu öffnen -->
|
|
||||||
<a class="btn btn-outline-primary" href="/Invoices/DocumentViewerDevExpress?id=@Model.Id">
|
|
||||||
DevExpress Viewer (experimental)
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style="height:calc(100vh - 64px);">
|
|
||||||
@* Solide, funktionierende Baseline: Browser-internen PDF-Renderer verwenden *@
|
|
||||||
<iframe id="pdf-viewer-iframe"
|
|
||||||
src="@pdfUrl"
|
|
||||||
style="width:100%; height:100%; border: none;"
|
|
||||||
title="PDF Viewer"></iframe>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
@* Hinweis:
|
|
||||||
- Diese Seite zeigt aktuell das PDF per einfachem iframe (funktioniert zuverlässig).
|
|
||||||
- Nächster Commit: wir ersetzen iframe durch DevExpress WebDocumentViewer oder laden diesen zusätzlich.
|
|
||||||
- Der Link "DevExpress Viewer (experimental)" ist ein Platzhalter; wir implementieren die Route /Invoices/DocumentViewerDevExpress in einem der nächsten Schritte.
|
|
||||||
*@
|
|
||||||
</div>
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
|
|
||||||
namespace DXApp.TemplateKitProject.Pages.Invoices;
|
|
||||||
|
|
||||||
public class DocumentViewerModel : PageModel
|
|
||||||
{
|
|
||||||
[BindProperty(SupportsGet = true)]
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
public string PdfUrl => $"/Invoices/ViewPdf?id={Id}";
|
|
||||||
|
|
||||||
public void OnGet()
|
|
||||||
{
|
|
||||||
// Keine serverseitige Logik nötig für die erste Version.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
@page
|
|
||||||
@model DXApp.TemplateKitProject.Pages.Invoices.DocumentViewerDevExpressModel
|
|
||||||
@{
|
|
||||||
ViewData["Title"] = "DevExpress Document Viewer";
|
|
||||||
}
|
|
||||||
|
|
||||||
@* Dev: Für schnelle Tests verwenden wir die CDN-Assets.
|
|
||||||
In Production bitte lokal hosten und Lizenz einbinden. *@
|
|
||||||
<link rel="stylesheet" href="https://cdn3.devexpress.com/jslib/25.2.7/css/dx.common.css" />
|
|
||||||
<link rel="stylesheet" href="https://cdn3.devexpress.com/jslib/25.2.7/css/dx.light.css" />
|
|
||||||
<script src="https://cdn3.devexpress.com/jslib/25.2.7/js/dx.all.js"></script>
|
|
||||||
<script src="https://cdn3.devexpress.com/jslib/25.2.7/js/dx.aspnet.data.js"></script>
|
|
||||||
|
|
||||||
<div class="container-fluid" style="height:100vh; padding:0;">
|
|
||||||
<div class="d-flex align-items-center justify-content-between p-3 border-bottom">
|
|
||||||
<h5 class="m-0">DevExpress Viewer — Rechnung @Model.Id</h5>
|
|
||||||
<div>
|
|
||||||
<a class="btn btn-secondary me-2" href="/Invoices">Zurück zur Übersicht</a>
|
|
||||||
<a class="btn btn-outline-secondary" href="/Invoices/DocumentViewer?id=@Model.Id">Baseline Viewer</a>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div style="height:calc(100vh - 64px);">
|
|
||||||
@* KORRIGIERTE SYNTAX: Der WebDocumentViewer-Helper wird direkt aufgerufen. *@
|
|
||||||
@(Html.DevExpress().WebDocumentViewer()
|
|
||||||
.Name("WebDocumentViewer")
|
|
||||||
.Height("100%")
|
|
||||||
.Width("100%")
|
|
||||||
.Bind(Model.ReportKey)
|
|
||||||
)
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
||||||
|
|
||||||
namespace DXApp.TemplateKitProject.Pages.Invoices;
|
|
||||||
|
|
||||||
public class DocumentViewerDevExpressModel : PageModel
|
|
||||||
{
|
|
||||||
[BindProperty(SupportsGet = true)]
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
public string ReportKey => $"invoice-{Id}";
|
|
||||||
|
|
||||||
public void OnGet()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,2 @@
|
|||||||
@page
|
@page
|
||||||
@model DXApp.TemplateKitProject.Pages.Invoices.ViewPdfModel
|
@model DXApp.TemplateKitProject.Pages.Invoices.ViewPdfModel
|
||||||
@{
|
|
||||||
Layout = "_Layout";
|
|
||||||
// Diese Seite liefert keinen HTML-Content; der Handler gibt die PDF zurück.
|
|
||||||
}
|
|
||||||
@@ -1,43 +1,24 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using DXApp.TemplateKitProject.Data;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||||
using DXApp.TemplateKitProject.Data;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace DXApp.TemplateKitProject.Pages.Invoices;
|
namespace DXApp.TemplateKitProject.Pages.Invoices;
|
||||||
|
|
||||||
public class ViewPdfModel : PageModel
|
public class ViewPdfModel(AppDbContext db) : PageModel
|
||||||
{
|
{
|
||||||
private readonly AppDbContext _db;
|
|
||||||
private readonly ILogger<ViewPdfModel> _logger;
|
|
||||||
|
|
||||||
public ViewPdfModel(AppDbContext db, ILogger<ViewPdfModel> logger)
|
|
||||||
{
|
|
||||||
_db = db;
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<IActionResult> OnGetAsync(int id)
|
public async Task<IActionResult> OnGetAsync(int id)
|
||||||
{
|
{
|
||||||
var invoice = await _db.ZugferdInvoices
|
var invoice = await db.ZugferdInvoices
|
||||||
.AsNoTracking()
|
|
||||||
.FirstOrDefaultAsync(i => i.Id == id);
|
.FirstOrDefaultAsync(i => i.Id == id);
|
||||||
|
|
||||||
if (invoice is null)
|
if (invoice is null || string.IsNullOrEmpty(invoice.ResultFilePath))
|
||||||
return NotFound();
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(invoice.ResultFilePath))
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
if (!System.IO.File.Exists(invoice.ResultFilePath))
|
if (!System.IO.File.Exists(invoice.ResultFilePath))
|
||||||
return NotFound();
|
return NotFound();
|
||||||
|
|
||||||
var bytes = await System.IO.File.ReadAllBytesAsync(invoice.ResultFilePath);
|
var bytes = await System.IO.File.ReadAllBytesAsync(invoice.ResultFilePath);
|
||||||
_logger.LogInformation("ViewPdf: Invoice {Id} ausgeliefert ({Size} Bytes).", id, bytes.Length);
|
|
||||||
|
|
||||||
// Wichtig: keine "attachment" Content-Disposition setzen
|
|
||||||
// wir setzen inline (oder lassen es weg) damit Browser im Viewer darstellt
|
|
||||||
Response.Headers["Content-Disposition"] = $"inline; filename=\"{Path.GetFileName(invoice.ResultFilePath)}\"";
|
|
||||||
|
|
||||||
return File(bytes, "application/pdf");
|
return File(bytes, "application/pdf");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,4 @@
|
|||||||
@using DXApp.TemplateKitProject
|
@using DXApp.TemplateKitProject
|
||||||
@using DXApp.TemplateKitProject.Pages
|
|
||||||
@namespace DXApp.TemplateKitProject.Pages
|
@namespace DXApp.TemplateKitProject.Pages
|
||||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||||
|
|
||||||
@* --- DevExpress & DevExtreme Integration --- *@
|
|
||||||
@using DevExpress.AspNetCore
|
|
||||||
@using DevExpress.AspNetCore.Reporting
|
|
||||||
@using DevExtreme.AspNet.Mvc
|
@using DevExtreme.AspNet.Mvc
|
||||||
@addTagHelper *, DevExtreme.AspNet.Core
|
|
||||||
@@ -1,22 +1,11 @@
|
|||||||
using DXApp.TemplateKitProject.Data;
|
using DXApp.TemplateKitProject.Data;
|
||||||
using DXApp.TemplateKitProject.DevExpressExtensions;
|
|
||||||
using DXApp.TemplateKitProject.Services;
|
using DXApp.TemplateKitProject.Services;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using DevExpress.AspNetCore;
|
|
||||||
using DevExpress.AspNetCore.Reporting;
|
|
||||||
using DevExpress.XtraReports.Web.Extensions;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// MVC-Controller hinzufügen (benötigt für DevExpress WebDocumentViewer)
|
|
||||||
builder.Services.AddControllersWithViews();
|
|
||||||
|
|
||||||
builder.Services.AddRazorPages();
|
builder.Services.AddRazorPages();
|
||||||
|
|
||||||
// DevExpress Controls und Reporting Services
|
|
||||||
builder.Services.AddDevExpressControls();
|
|
||||||
builder.Services.AddScoped<ReportStorageWebExtension, CustomReportStorageWebExtension>();
|
|
||||||
|
|
||||||
// Datenbank
|
// Datenbank
|
||||||
var connectionString = builder.Configuration.GetConnectionString("EcmContext")
|
var connectionString = builder.Configuration.GetConnectionString("EcmContext")
|
||||||
?? throw new InvalidOperationException("Connection string 'EcmContext' not found.");
|
?? throw new InvalidOperationException("Connection string 'EcmContext' not found.");
|
||||||
@@ -41,22 +30,13 @@ if (!app.Environment.IsDevelopment())
|
|||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
// MIME-Types für PDF.js UND DevExpress registrieren
|
// MIME-Types für PDF.js registrieren (einmaliger UseStaticFiles-Aufruf)
|
||||||
var provider = new Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider();
|
var provider = new Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider();
|
||||||
provider.Mappings[".mjs"] = "text/javascript";
|
provider.Mappings[".mjs"] = "text/javascript";
|
||||||
provider.Mappings[".ftl"] = "text/plain";
|
provider.Mappings[".ftl"] = "text/plain";
|
||||||
provider.Mappings[".woff2"] = "font/woff2";
|
|
||||||
provider.Mappings[".woff"] = "font/woff";
|
|
||||||
|
|
||||||
app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = provider });
|
app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = provider });
|
||||||
|
|
||||||
// DevExpress Middleware
|
|
||||||
app.UseDevExpressControls();
|
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
// Controller-Routen verfügbar machen (wichtig für DevExpress WebDocumentViewer)
|
|
||||||
app.MapControllers();
|
|
||||||
app.MapRazorPages();
|
app.MapRazorPages();
|
||||||
app.Run();
|
app.Run();
|
||||||
Reference in New Issue
Block a user