mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2026-06-27 22:36:39 +00:00
Improve performance of previews and prevent double renders
This commit is contained in:
@@ -195,7 +195,7 @@ class PreviewController extends BaseController
|
||||
|
||||
$requestDesign = $request->design['design'];
|
||||
|
||||
$ps->boot();
|
||||
$ps->bootForPreviewDesign($requestDesign);
|
||||
|
||||
if (isset($requestDesign['blocks'])) {
|
||||
$ps->setJsonDesignHtml(
|
||||
|
||||
@@ -82,6 +82,37 @@ class PdfService
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the PDF context for design preview rendering without building
|
||||
* the currently-saved design first. The caller will render the request
|
||||
* design after this method prepares config, settings, locale variables, and
|
||||
* the designer/builder shells.
|
||||
*/
|
||||
public function bootForPreviewDesign(array $previewDesign): self
|
||||
{
|
||||
$this->start_time = microtime(true);
|
||||
|
||||
$this->config = (new PdfConfiguration($this))->init();
|
||||
|
||||
$this->applyJsonDesignSettingsOverrides($previewDesign);
|
||||
|
||||
$htmlEngine = ($this->invitation instanceof \App\Models\PurchaseOrderInvitation)
|
||||
? new VendorHtmlEngine($this->invitation)
|
||||
: new HtmlEngine($this->invitation);
|
||||
|
||||
$htmlEngine->setSettings($this->config->settings);
|
||||
|
||||
$this->html_variables = $htmlEngine->generateLabelsAndValues();
|
||||
|
||||
$this->designer = new PdfDesigner($this);
|
||||
$this->designer->template = '';
|
||||
$this->builder = new PdfBuilder($this);
|
||||
$this->builder->document = new \DOMDocument();
|
||||
$this->builder->document->loadHTML('<!DOCTYPE html><html><body></body></html>');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the PDF generation type and
|
||||
* attempts to generate a PDF from the HTML
|
||||
@@ -199,13 +230,19 @@ class PdfService
|
||||
*
|
||||
* No-op for non-JSON designs and for JSON designs with no documentSettings.
|
||||
*/
|
||||
private function applyJsonDesignSettingsOverrides(): void
|
||||
private function applyJsonDesignSettingsOverrides(?array $designData = null): void
|
||||
{
|
||||
if (!$this->isJsonDesign()) {
|
||||
return;
|
||||
if ($designData === null) {
|
||||
if (!$this->isJsonDesign()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$designData = $this->config->decodedDesign();
|
||||
}
|
||||
|
||||
$designData = $this->config->decodedDesign();
|
||||
if ($designData === null || !isset($designData['blocks'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$resolver = new DocumentSettingsResolver($designData, $this->config->settings);
|
||||
|
||||
|
||||
@@ -6029,6 +6029,7 @@ $lang = array(
|
||||
'label_value_gap' => 'Gap between label and value.',
|
||||
'row_spacing' => 'How much vertical space sits between each row.',
|
||||
'value_min_width' => 'Minimum width for values.',
|
||||
'fix_overlaps' => 'Fix Overlaps',
|
||||
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user