Skip to content

Commit

Permalink
XWIKI-19917: Add an administration section to configure the PDF expor…
Browse files Browse the repository at this point in the history
…t mode

* Show the PDF generator status
  • Loading branch information
mflorea committed Oct 14, 2022
1 parent adaa118 commit be3b947
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});</code>
</property>
<property>
Expand Down Expand Up @@ -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;
}</code>
</property>
<property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<size>30</size>
<unmodifiable>0</unmodifiable>
<validationMessage/>
<validationRegExp/>
<validationRegExp>[a-zA-Z0-9][a-zA-Z0-9_.-]+</validationRegExp>
<classType>com.xpn.xwiki.objects.classes.StringClass</classType>
</chromeDockerContainerName>
<chromeDockerImage>
Expand Down Expand Up @@ -118,7 +118,7 @@
<size>30</size>
<unmodifiable>0</unmodifiable>
<validationMessage/>
<validationRegExp/>
<validationRegExp>[a-zA-Z0-9][a-zA-Z0-9_.-]+</validationRegExp>
<classType>com.xpn.xwiki.objects.classes.StringClass</classType>
</dockerNetwork>
<serverSide>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@
<separators>|, </separators>
<size>5</size>
<unmodifiable>0</unmodifiable>
<values>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</values>
<values>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</values>
<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType>
</async_context>
<async_enabled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
<contenttype>FullyRenderedText</contenttype>
<customDisplay/>
<disabled>0</disabled>
<editor>---</editor>
<editor>Text</editor>
<hint>XWiki.PDFExport.TemplateClass_cover.hint</hint>
<name>cover</name>
<number>1</number>
<picker>1</picker>
<picker>0</picker>
<prettyName>Cover</prettyName>
<rows>5</rows>
<rows>20</rows>
<size>40</size>
<unmodifiable>0</unmodifiable>
<validationMessage/>
Expand All @@ -72,13 +72,13 @@
<contenttype>FullyRenderedText</contenttype>
<customDisplay/>
<disabled>0</disabled>
<editor>---</editor>
<editor>Text</editor>
<hint>XWiki.PDFExport.TemplateClass_footer.hint</hint>
<name>footer</name>
<number>4</number>
<picker>1</picker>
<picker>0</picker>
<prettyName>Footer</prettyName>
<rows>5</rows>
<rows>20</rows>
<size>40</size>
<unmodifiable>0</unmodifiable>
<validationMessage/>
Expand All @@ -89,13 +89,13 @@
<contenttype>FullyRenderedText</contenttype>
<customDisplay/>
<disabled>0</disabled>
<editor>---</editor>
<editor>Text</editor>
<hint>XWiki.PDFExport.TemplateClass_header.hint</hint>
<name>header</name>
<number>3</number>
<picker>1</picker>
<picker>0</picker>
<prettyName>Header</prettyName>
<rows>5</rows>
<rows>20</rows>
<size>40</size>
<unmodifiable>0</unmodifiable>
<validationMessage/>
Expand All @@ -106,13 +106,13 @@
<contenttype>FullyRenderedText</contenttype>
<customDisplay/>
<disabled>0</disabled>
<editor>---</editor>
<editor>Text</editor>
<hint>XWiki.PDFExport.TemplateClass_toc.hint</hint>
<name>toc</name>
<number>2</number>
<picker>1</picker>
<picker>0</picker>
<prettyName>Table of Contents</prettyName>
<rows>5</rows>
<rows>20</rows>
<size>40</size>
<unmodifiable>0</unmodifiable>
<validationMessage/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -289,19 +289,19 @@ require([

$('body').css('cursor', 'wait');
const notification = pdfExportOptionsModal.find('.modal-body &gt; .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',
sheet: 'XWiki.PDFExport.WebHome',
data: 'serverSidePrintingAvailable',
}))).then(response =&gt; response.json()).then(data =&gt; {
if (!data.serverSidePrintingAvailable) {
return Promise.reject(l10n['export.pdf.serverSidePrinting.unavailable']);
return Promise.reject(l10n['export.pdf.generator.unavailable']);
}
}).catch(reason =&gt; {
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);
Expand Down Expand Up @@ -753,7 +753,7 @@ require([
<separators>|, </separators>
<size>5</size>
<unmodifiable>0</unmodifiable>
<values>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</values>
<values>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</values>
<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType>
</async_context>
<async_enabled>
Expand Down

0 comments on commit be3b947

Please sign in to comment.