Enhance file attachment viewing experience
Replaced direct file links with a JavaScript-based viewer (`openAttachmentViewer`) and added a DevExtreme Popup (`attachment-viewer-popup`) for displaying attachments in a modal dialog. The viewer supports PDFs (via PDF.js), XML (with CodeMirror syntax highlighting), plain text, images, and provides a fallback for unsupported file types. Dynamically load CodeMirror for XML files and handle errors gracefully when loading file content. Added `onAttachmentPopupHiding` to clear popup content on close. Updated `ViewAttachmentModel` to return text/XML content directly for AJAX requests, improving frontend performance and enabling dynamic content loading.
This commit is contained in:
@@ -19,10 +19,17 @@ public class ViewAttachmentModel(AttachmentViewerService viewerService) : PageMo
|
||||
FileName = Path.GetFileName(filePath);
|
||||
ViewerType = viewerService.DetermineViewerType(FileName);
|
||||
|
||||
// Für Text/XML: Inhalt laden
|
||||
// Für Text/XML: Inhalt direkt als Content zurückgeben (für AJAX)
|
||||
if (ViewerType == AttachmentViewerType.Xml || ViewerType == AttachmentViewerType.Text)
|
||||
{
|
||||
TextContent = System.IO.File.ReadAllText(filePath, Encoding.UTF8);
|
||||
|
||||
// Wenn Request von AJAX kommt (Accept: */* oder text/plain)
|
||||
if (Request.Headers.Accept.ToString().Contains("*/*") ||
|
||||
Request.Headers["X-Requested-With"] == "XMLHttpRequest")
|
||||
{
|
||||
return Content(TextContent, "text/plain", Encoding.UTF8);
|
||||
}
|
||||
}
|
||||
|
||||
return Page();
|
||||
|
||||
Reference in New Issue
Block a user