From 4f7f6db8044d6b52a6535863b49f0d26f936b781 Mon Sep 17 00:00:00 2001 From: Gary Sharp Date: Sun, 1 Mar 2026 14:15:27 +1100 Subject: [PATCH] qol: option to view/print generated document inline --- .../Controllers/DocumentTemplateController.cs | 4 +- .../DocumentTemplatePackageController.cs | 16 +++---- .../Modules/Disco-DocumentGenerator.js | 42 ++++++++++++++++++- .../Modules/Disco-DocumentGenerator.min.js | 2 +- .../disco.documentgenerator.js | 42 ++++++++++++++++++- Disco.Web/ClientSource/Style/BundleSite.css | 17 +++++++- .../ClientSource/Style/BundleSite.min.css | 2 +- Disco.Web/ClientSource/Style/Site.css | 17 +++++++- Disco.Web/ClientSource/Style/Site.less | 21 +++++++++- Disco.Web/ClientSource/Style/Site.min.css | 2 +- ...PI.DocumentTemplateController.generated.cs | 8 ++-- ...mentTemplatePackageController.generated.cs | 8 ++-- .../Shared/_GenerateDocumentControl.cshtml | 1 + .../_GenerateDocumentControl.generated.cs | 16 +++++-- 14 files changed, 170 insertions(+), 28 deletions(-) diff --git a/Disco.Web/Areas/API/Controllers/DocumentTemplateController.cs b/Disco.Web/Areas/API/Controllers/DocumentTemplateController.cs index 78e076ef..a9fe97e8 100644 --- a/Disco.Web/Areas/API/Controllers/DocumentTemplateController.cs +++ b/Disco.Web/Areas/API/Controllers/DocumentTemplateController.cs @@ -1774,7 +1774,7 @@ namespace Disco.Web.Areas.API.Controllers } [HttpPost, ValidateAntiForgeryToken] - public virtual ActionResult Generate(string id, string targetId) + public virtual ActionResult Generate(string id, string targetId, bool? inline = null) { Disco.Services.DocumentTemplateExtensions.GetTemplateAndTarget(Database, Authorization, id, targetId, out var template, out var target, out _); @@ -1787,7 +1787,7 @@ namespace Disco.Web.Areas.API.Controllers } Database.SaveChanges(); - return File(document, "application/pdf", $"{template.Id}_{target.AttachmentReferenceId.Replace('\\', '_')}_{timestamp:yyyyMMdd-HHmmss}.pdf"); + return File(document, "application/pdf", (inline ?? false) ? null : $"{template.Id}_{target.AttachmentReferenceId.Replace('\\', '_')}_{timestamp:yyyyMMdd-HHmmss}.pdf"); } [DiscoAuthorize(Claims.Config.DocumentTemplate.Delete)] diff --git a/Disco.Web/Areas/API/Controllers/DocumentTemplatePackageController.cs b/Disco.Web/Areas/API/Controllers/DocumentTemplatePackageController.cs index ed21f12d..9d649e76 100644 --- a/Disco.Web/Areas/API/Controllers/DocumentTemplatePackageController.cs +++ b/Disco.Web/Areas/API/Controllers/DocumentTemplatePackageController.cs @@ -19,12 +19,12 @@ namespace Disco.Web.Areas.API.Controllers { public partial class DocumentTemplatePackageController : AuthorizedDatabaseController { - const string pDescription = "description"; - const string pScope = "scope"; - const string pFilterExpression = "filterexpression"; - const string pOnGenerateExpression = "ongenerateexpression"; - const string pIsHidden = "ishidden"; - const string pInsertBlankPages = "insertblankpages"; + private const string pDescription = "description"; + private const string pScope = "scope"; + private const string pFilterExpression = "filterexpression"; + private const string pOnGenerateExpression = "ongenerateexpression"; + private const string pIsHidden = "ishidden"; + private const string pInsertBlankPages = "insertblankpages"; [DiscoAuthorize(Claims.Config.DocumentTemplate.Configure)] [HttpPost, ValidateAntiForgeryToken] @@ -396,7 +396,7 @@ namespace Disco.Web.Areas.API.Controllers } [HttpPost, ValidateAntiForgeryToken] - public virtual ActionResult Generate(string id, string targetId) + public virtual ActionResult Generate(string id, string targetId, bool? inline = false) { if (string.IsNullOrWhiteSpace(id)) throw new ArgumentNullException(nameof(id)); @@ -435,7 +435,7 @@ namespace Disco.Web.Areas.API.Controllers } Database.SaveChanges(); - return File(document, "application/pdf", $"{package.Id}_{target.AttachmentReferenceId.Replace('\\', '_')}_{timestamp:yyyyMMdd-HHmmss}.pdf"); + return File(document, "application/pdf", (inline ?? false) ? null : $"{package.Id}_{target.AttachmentReferenceId.Replace('\\', '_')}_{timestamp:yyyyMMdd-HHmmss}.pdf"); } [DiscoAuthorize(Claims.Config.DocumentTemplate.Delete)] diff --git a/Disco.Web/ClientSource/Scripts/Modules/Disco-DocumentGenerator.js b/Disco.Web/ClientSource/Scripts/Modules/Disco-DocumentGenerator.js index 1fb7b111..176e9bce 100644 --- a/Disco.Web/ClientSource/Scripts/Modules/Disco-DocumentGenerator.js +++ b/Disco.Web/ClientSource/Scripts/Modules/Disco-DocumentGenerator.js @@ -12,6 +12,7 @@ const handlersPackageUrl = $container.attr('data-handlerspackageurl'); let $handlersDialog = null; let lastTemplateId = null; + let lastTemplateName = null; const downloadPdf = function (templateId) { let action = generatePdfUrl; @@ -35,6 +36,36 @@ form.submit(); } + const viewPdf = function (templateId, templateName) { + let action = generatePdfUrl; + if (templateId.lastIndexOf('Package:', 0) === 0) { + templateId = templateId.substring(8); + action = generatePackageUrl; + } + + const $dialog = $('
') + .appendTo(document.body) + .dialog({ + resizable: false, + modal: true, + autoOpen: true, + width: 850, + height: 700, + title: 'Document: ' + templateName, + close: function () { + $dialog.dialog('destroy').remove(); + } + }); + const $iframe = $('