From be3b9476e9bb02ccccbd1edeaf8e7bf6d058e916 Mon Sep 17 00:00:00 2001 From: Marius Dumitru Florea Date: Fri, 14 Oct 2022 06:45:50 +0300 Subject: [PATCH] XWIKI-19917: Add an administration section to configure the PDF export mode * Show the PDF generator status --- .../chrome/ChromeManagerProvider.java | 1 + .../XWiki/PDFExport/AdminSection.xml | 48 +++++++++++++++++ .../XWiki/PDFExport/ConfigurationSheet.xml | 52 +++++++++++++++++++ .../XWiki/PDFExport/ConfigurationTemplate.xml | 4 +- .../main/resources/XWiki/PDFExport/Sheet.xml | 2 +- .../resources/XWiki/PDFExport/Template.xml | 24 ++++----- .../XWiki/PDFExport/Translations.xml | 10 ++-- .../resources/XWiki/PDFExport/WebHome.xml | 14 ++--- 8 files changed, 129 insertions(+), 26 deletions(-) diff --git a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-default/src/main/java/org/xwiki/export/pdf/internal/chrome/ChromeManagerProvider.java b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-default/src/main/java/org/xwiki/export/pdf/internal/chrome/ChromeManagerProvider.java index 2947212ea13f..ce04cdaecfcc 100644 --- a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-default/src/main/java/org/xwiki/export/pdf/internal/chrome/ChromeManagerProvider.java +++ b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-default/src/main/java/org/xwiki/export/pdf/internal/chrome/ChromeManagerProvider.java @@ -129,6 +129,7 @@ private void disconnect() if (this.containerId != null && this.isContainerCreator) { this.containerManagerProvider.get().stopContainer(this.containerId); this.containerId = null; + this.isContainerCreator = false; } } diff --git a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/AdminSection.xml b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/AdminSection.xml index 2d346d3882d4..affdd777b32b 100644 --- a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/AdminSection.xml +++ b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/AdminSection.xml @@ -49,7 +49,11 @@ {{html clean="false"}} #set ($configDoc = $xwiki.getDocument('XWiki.PDFExport.Configuration')) <form id="pdfExportConfig" method="post" action="$configDoc.getURL('save')"> + #displayPDFExportStatus() <fieldset> + <legend> + $escapetool.xml($services.localization.render('export.pdf.admin.configuration')) + </legend> #if ($configDoc.isNew()) ## Copy the configuration object from the template. #set ($templateDoc = $xwiki.getDocument('XWiki.PDFExport.ConfigurationTemplate')) @@ -82,6 +86,50 @@ </form> {{/html}} #end + +#macro (spinner) + #if ($services.icon.currentIconSetName == 'Font Awesome') + <span class="fa fa-spinner fa-spin"></span> + #else + <img src="$escapetool.xml($xwiki.getSkinFile('icons/xwiki/spinner.gif'))" /> + #end +#end + +#macro (displayPDFExportStatus) + <fieldset class="xform"> + <legend> + $escapetool.xml($services.localization.render('export.pdf.admin.status')) + </legend> + <dl> + <dt> + <label> + $escapetool.xml($services.localization.render('export.pdf.generator.label')) + </label> + <span class="xHint"> + $escapetool.xml($services.localization.render('export.pdf.generator.hint')) + </span> + </dt> + <dd class="pdfGeneratorStatus pdfGeneratorStatus-checking"> + <div class="pdfGeneratorStatus-checking-message"> + #spinner() + $escapetool.xml($services.localization.render('export.pdf.generator.checking')) + </div> + <div class="pdfGeneratorStatus-checkFailed-message"> + $services.icon.renderHTML('error') + $escapetool.xml($services.localization.render('export.pdf.generator.checkFailed')) + </div> + <div class="pdfGeneratorStatus-available-message"> + $services.icon.renderHTML('check') + $escapetool.xml($services.localization.render('export.pdf.generator.available')) + </div> + <div class="pdfGeneratorStatus-unavailable-message"> + $services.icon.renderHTML('warning') + $escapetool.xml($services.localization.render('export.pdf.generator.unavailable')) + </div> + </dd> + </dl> + </fieldset> +#end {{/velocity}} {{velocity}} diff --git a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/ConfigurationSheet.xml b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/ConfigurationSheet.xml index 9857a7a2c5f9..2b5582bf4ba9 100644 --- a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/ConfigurationSheet.xml +++ b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/ConfigurationSheet.xml @@ -283,6 +283,44 @@ require(['jquery', 'xwiki-events-bridge'], function($) { event.preventDefault(); } }); + + const setPDFGeneratorStatus = function(status) { + document.querySelectorAll('dd.pdfGeneratorStatus').forEach(statusContainer => { + statusContainer.className = `pdfGeneratorStatus pdfGeneratorStatus-${status}`; + }); + }; + + const fetchPDFGeneratorStatus = function() { + setPDFGeneratorStatus('checking'); + fetch(XWiki.currentDocument.getURL('get', $.param({ + outputSyntax: 'plain', + sheet: 'XWiki.PDFExport.WebHome', + data: 'serverSidePrintingAvailable' + }))).then(response => response.json()).then(data => { + if (data.serverSidePrintingAvailable) { + setPDFGeneratorStatus('available'); + } else { + setPDFGeneratorStatus('unavailable'); + } + }).catch(reason => { + setPDFGeneratorStatus('checkFailed'); + }); + }; + + const updatePDFGeneratorStatus = function() { + if (document.getElementById('pdfGenerator')?.value === 'userBrowser') { + setPDFGeneratorStatus('available'); + } else { + fetchPDFGeneratorStatus(); + } + }; + + $(document).on('xwiki:action:save', (event) => { + setPDFGeneratorStatus('checking'); + }); + + $(document).on('xwiki:document:saved', updatePDFGeneratorStatus); + updatePDFGeneratorStatus(); }); @@ -442,6 +480,20 @@ fieldset.pdfGeneratorConfig { .box-shadow(@shadow); } } +} + +.pdfGeneratorStatus-checking-message, +.pdfGeneratorStatus-checkFailed-message, +.pdfGeneratorStatus-available-message, +.pdfGeneratorStatus-unavailable-message { + display: none; +} + +.pdfGeneratorStatus-checking .pdfGeneratorStatus-checking-message, +.pdfGeneratorStatus-checkFailed .pdfGeneratorStatus-checkFailed-message, +.pdfGeneratorStatus-available .pdfGeneratorStatus-available-message, +.pdfGeneratorStatus-unavailable .pdfGeneratorStatus-unavailable-message { + display: block; } diff --git a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/ConfigurationTemplate.xml b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/ConfigurationTemplate.xml index 7d10d303fe2a..fb0350d9269b 100644 --- a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/ConfigurationTemplate.xml +++ b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/ConfigurationTemplate.xml @@ -62,7 +62,7 @@ 30 0 - + [a-zA-Z0-9][a-zA-Z0-9_.-]+ com.xpn.xwiki.objects.classes.StringClass @@ -118,7 +118,7 @@ 30 0 - + [a-zA-Z0-9][a-zA-Z0-9_.-]+ com.xpn.xwiki.objects.classes.StringClass diff --git a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Sheet.xml b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Sheet.xml index d5055ccad85a..4e52d29d3cbe 100644 --- a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Sheet.xml +++ b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Sheet.xml @@ -562,7 +562,7 @@ |, 5 0 - action=Action|doc.reference=Document|icon.theme=Icon theme|locale=Language|rendering.defaultsyntax=Default syntax|rendering.restricted=Restricted|rendering.targetsyntax=Target syntax|request.base=Request base URL|request.parameters=Request parameters|request.url=Request URL|request.wiki=Request wiki|user=User|wiki=Wiki + action=Action|doc.reference=Document|icon.theme=Icon theme|locale=Language|rendering.defaultsyntax=Default syntax|rendering.restricted=Restricted|rendering.targetsyntax=Target syntax|request.base=Request base URL|request.cookies|request.parameters=Request parameters|request.url=Request URL|request.wiki=Request wiki|user=User|wiki=Wiki com.xpn.xwiki.objects.classes.StaticListClass diff --git a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Template.xml b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Template.xml index 9cbda25e9d91..7ed7e0d7e192 100644 --- a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Template.xml +++ b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Template.xml @@ -55,13 +55,13 @@ FullyRenderedText 0 - --- + Text XWiki.PDFExport.TemplateClass_cover.hint cover 1 - 1 + 0 Cover - 5 + 20 40 0 @@ -72,13 +72,13 @@ FullyRenderedText 0 - --- + Text XWiki.PDFExport.TemplateClass_footer.hint footer 4 - 1 + 0 Footer - 5 + 20 40 0 @@ -89,13 +89,13 @@ FullyRenderedText 0 - --- + Text XWiki.PDFExport.TemplateClass_header.hint header 3 - 1 + 0 Header - 5 + 20 40 0 @@ -106,13 +106,13 @@ FullyRenderedText 0 - --- + Text XWiki.PDFExport.TemplateClass_toc.hint toc 2 - 1 + 0 Table of Contents - 5 + 20 40 0 diff --git a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Translations.xml b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Translations.xml index db411c161e42..fdfda57ca7c9 100644 --- a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Translations.xml +++ b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/Translations.xml @@ -40,10 +40,6 @@ export.pdf.options.template.hint=The PDF template controls the information displayed on the cover page, in the table of contents as well as in the header and footer of each page. export.pdf.options.loadFailure=Failed to load the PDF export options. -export.pdf.serverSidePrinting.checking=Checking if server-side PDF printing is available... -export.pdf.serverSidePrinting.unavailable=Server-side PDF printing is currently unavailable. Please contact your administrator. -export.pdf.serverSidePrinting.checkFailed=Failed to check if server-side PDF printing is available. - export.pdf.modal.close=Close export.pdf.inProgress=Exporting as PDF... export.pdf.failed=Failed to export as PDF @@ -62,6 +58,8 @@ export.pdf.template.skinExtensionInfo=The CSS and JavaScript skin extensions pro admin.export.pdf=PDF Export admin.export.pdf.description=Configure how wiki pages are exported to PDF. +export.pdf.admin.status=Status +export.pdf.admin.configuration=Configuration export.pdf.admin.saveComment=Updated the PDF export configuration from the Administration export.pdf.admin.reset=Reset export.pdf.admin.reset.hint=Restore the default configuration @@ -72,6 +70,10 @@ export.pdf.config.empty=(empty) export.pdf.generator.label=Generator export.pdf.generator.hint=The tool used to generate the PDF. +export.pdf.generator.checking=Checking if the PDF generator is available... +export.pdf.generator.checkFailed=Failed to check if the PDF generator is available. +export.pdf.generator.available=Available +export.pdf.generator.unavailable=The PDF generator is currently unavailable. export.pdf.generator.userBrowser.label=User Browser export.pdf.generator.userBrowser.hint=The PDF is generated client-side using the print function provided by the user's own web browser. export.pdf.generator.chromeDockerContainer.label=Chrome Docker Container diff --git a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/WebHome.xml b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/WebHome.xml index 0bac194f57b5..2595d87f9ae3 100644 --- a/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/WebHome.xml +++ b/xwiki-platform-core/xwiki-platform-export/xwiki-platform-export-pdf/xwiki-platform-export-pdf-ui/src/main/resources/XWiki/PDFExport/WebHome.xml @@ -184,9 +184,9 @@ 'export.pdf.options.template', 'export.pdf.options.template.hint', 'export.pdf.options.loadFailure', - 'export.pdf.serverSidePrinting.checking', - 'export.pdf.serverSidePrinting.unavailable', - 'export.pdf.serverSidePrinting.checkFailed', + 'export.pdf.generator.checking', + 'export.pdf.generator.unavailable', + 'export.pdf.generator.checkFailed', 'export.pdf.modal.close', 'export.pdf.inProgress', 'export.pdf.failed', @@ -289,7 +289,7 @@ require([ $('body').css('cursor', 'wait'); const notification = pdfExportOptionsModal.find('.modal-body > .alert') - .text(l10n['export.pdf.serverSidePrinting.checking']) + .text(l10n['export.pdf.generator.checking']) .prepend(renderIcon(config.icons.spinner)); return fetch(XWiki.currentDocument.getURL('get', $.param({ outputSyntax: 'plain', @@ -297,11 +297,11 @@ require([ data: 'serverSidePrintingAvailable', }))).then(response => response.json()).then(data => { if (!data.serverSidePrintingAvailable) { - return Promise.reject(l10n['export.pdf.serverSidePrinting.unavailable']); + return Promise.reject(l10n['export.pdf.generator.unavailable']); } }).catch(reason => { notification.removeClass('alert-progress').addClass('alert-danger') - .text(reason || l10n['export.pdf.serverSidePrinting.checkFailed']) + .text(reason || l10n['export.pdf.generator.checkFailed']) .prepend(renderIcon(config.icons.error)); // Propagate the error in order to prevent the loading of the PDF export options. return Promise.reject(reason); @@ -753,7 +753,7 @@ require([ |, 5 0 - action=Action|doc.reference=Document|icon.theme=Icon theme|locale=Language|rendering.defaultsyntax=Default syntax|rendering.restricted=Restricted|rendering.targetsyntax=Target syntax|request.base=Request base URL|request.parameters=Request parameters|request.url=Request URL|request.wiki=Request wiki|user=User|wiki=Wiki + action=Action|doc.reference=Document|icon.theme=Icon theme|locale=Language|rendering.defaultsyntax=Default syntax|rendering.restricted=Restricted|rendering.targetsyntax=Target syntax|request.base=Request base URL|request.cookies|request.parameters=Request parameters|request.url=Request URL|request.wiki=Request wiki|user=User|wiki=Wiki com.xpn.xwiki.objects.classes.StaticListClass