Add debug flag to pdf export

This commit is contained in:
Constantin Graf
2024-12-03 16:57:14 +01:00
committed by Constantin Graf
parent 32bce2f749
commit a4f3e014d9
5 changed files with 38 additions and 4 deletions

View File

@@ -173,6 +173,7 @@ class TimeEntryController extends Controller
} else { } else {
$this->checkPermission($organization, 'time-entries:view:all'); $this->checkPermission($organization, 'time-entries:view:all');
} }
$debug = $request->getDebug();
$format = $request->getFormatValue(); $format = $request->getFormatValue();
if ($format === ExportFormat::PDF && ! $this->canAccessPremiumFeatures($organization)) { if ($format === ExportFormat::PDF && ! $this->canAccessPremiumFeatures($organization)) {
throw new FeatureIsNotAvailableInFreePlanApiException; throw new FeatureIsNotAvailableInFreePlanApiException;
@@ -195,7 +196,7 @@ class TimeEntryController extends Controller
$export = new TimeEntriesDetailedCsvExport(config('filesystems.private'), $folderPath, $filename, $timeEntriesQuery, 1000, $timezone); $export = new TimeEntriesDetailedCsvExport(config('filesystems.private'), $folderPath, $filename, $timeEntriesQuery, 1000, $timezone);
$export->export(); $export->export();
} elseif ($format === ExportFormat::PDF) { } elseif ($format === ExportFormat::PDF) {
if (config('services.gotenberg.url') === null) { if (config('services.gotenberg.url') === null && ! $debug) {
throw new PdfRendererIsNotConfiguredException; throw new PdfRendererIsNotConfiguredException;
} }
$viewFile = file_get_contents(resource_path('views/reports/time-entry-index/pdf.blade.php')); $viewFile = file_get_contents(resource_path('views/reports/time-entry-index/pdf.blade.php'));
@@ -225,6 +226,13 @@ class TimeEntryController extends Controller
throw new \LogicException('View file not found'); throw new \LogicException('View file not found');
} }
$footerHtml = Blade::render($footerViewFile); $footerHtml = Blade::render($footerViewFile);
if ($debug) {
return response()->json([
'html' => $html,
'footer_html' => $footerHtml,
]);
}
$client = new Client([ $client = new Client([
'auth' => config('services.gotenberg.basic_auth_username') !== null && config('services.gotenberg.basic_auth_password') !== null ? [ 'auth' => config('services.gotenberg.basic_auth_username') !== null && config('services.gotenberg.basic_auth_password') !== null ? [
config('services.gotenberg.basic_auth_username'), config('services.gotenberg.basic_auth_username'),
@@ -347,6 +355,7 @@ class TimeEntryController extends Controller
if ($format === ExportFormat::PDF && ! $this->canAccessPremiumFeatures($organization)) { if ($format === ExportFormat::PDF && ! $this->canAccessPremiumFeatures($organization)) {
throw new FeatureIsNotAvailableInFreePlanApiException; throw new FeatureIsNotAvailableInFreePlanApiException;
} }
$debug = $request->getDebug();
$user = $this->user(); $user = $this->user();
$group = $request->getGroup(); $group = $request->getGroup();
@@ -381,7 +390,7 @@ class TimeEntryController extends Controller
$path = $folderPath.'/'.$filename; $path = $folderPath.'/'.$filename;
if ($format === ExportFormat::PDF) { if ($format === ExportFormat::PDF) {
if (config('services.gotenberg.url') === null) { if (config('services.gotenberg.url') === null && ! $debug) {
throw new PdfRendererIsNotConfiguredException; throw new PdfRendererIsNotConfiguredException;
} }
$client = new Client([ $client = new Client([
@@ -402,12 +411,19 @@ class TimeEntryController extends Controller
'subGroup' => $subGroup, 'subGroup' => $subGroup,
'start' => $request->getStart()->timezone($timezone), 'start' => $request->getStart()->timezone($timezone),
'end' => $request->getEnd()->timezone($timezone), 'end' => $request->getEnd()->timezone($timezone),
'debug' => $debug,
]); ]);
$footerViewFile = file_get_contents(resource_path('views/reports/time-entry-aggregate/pdf-footer.blade.php')); $footerViewFile = file_get_contents(resource_path('views/reports/time-entry-aggregate/pdf-footer.blade.php'));
if ($footerViewFile === false) { if ($footerViewFile === false) {
throw new \LogicException('View file not found'); throw new \LogicException('View file not found');
} }
$footerHtml = Blade::render($footerViewFile); $footerHtml = Blade::render($footerViewFile);
if ($debug) {
return response()->json([
'html' => $html,
'footer_html' => $footerHtml,
]);
}
$request = Gotenberg::chromium(config('services.gotenberg.url')) $request = Gotenberg::chromium(config('services.gotenberg.url'))
->pdf() ->pdf()
->waitForExpression("window.status === 'ready'") ->waitForExpression("window.status === 'ready'")

View File

@@ -160,9 +160,18 @@ class TimeEntryAggregateExportRequest extends FormRequest
'string', 'string',
'in:true,false', 'in:true,false',
], ],
'debug' => [
'string',
'in:true,false',
],
]; ];
} }
public function getDebug(): bool
{
return $this->input('debug') === 'true';
}
public function getGroup(): TimeEntryAggregationType public function getGroup(): TimeEntryAggregationType
{ {
return TimeEntryAggregationType::from($this->input('group')); return TimeEntryAggregationType::from($this->input('group'));

View File

@@ -129,9 +129,18 @@ class TimeEntryIndexExportRequest extends TimeEntryIndexRequest
'string', 'string',
'in:true,false', 'in:true,false',
], ],
'debug' => [
'string',
'in:true,false',
],
]; ];
} }
public function getDebug(): bool
{
return $this->input('debug', 'false') === 'true';
}
public function getStart(): Carbon public function getStart(): Carbon
{ {
$start = Carbon::createFromFormat('Y-m-d\TH:i:s\Z', $this->input('start'), 'UTC'); $start = Carbon::createFromFormat('Y-m-d\TH:i:s\Z', $this->input('start'), 'UTC');

View File

@@ -1,4 +1,4 @@
// Version: 5.5.1
/* /*
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file * or more contributor license agreements. See the NOTICE file

View File

@@ -48,7 +48,7 @@
<script> <script>
window.status = 'processing'; window.status = 'processing';
</script> </script>
<script src="echarts.min.js"></script> <script src="{{ $debug ? 'https://cdn.jsdelivr.net/npm/echarts@5.5.1/dist/echarts.min.js' : 'echarts.min.js' }}"></script>
</head> </head>
<body> <body>