Skip to content

Commit

Permalink
Add debug flag to pdf export
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed Dec 3, 2024
1 parent d3f2d0a commit 902221c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/Http/Controllers/Api/V1/TimeEntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public function indexExport(Organization $organization, TimeEntryIndexExportRequ
} else {
$this->checkPermission($organization, 'time-entries:view:all');
}
$debug = $request->getDebug();
$format = $request->getFormatValue();
if ($format === ExportFormat::PDF && ! $this->canAccessPremiumFeatures($organization)) {
throw new FeatureIsNotAvailableInFreePlanApiException;
Expand All @@ -195,7 +196,7 @@ public function indexExport(Organization $organization, TimeEntryIndexExportRequ
$export = new TimeEntriesDetailedCsvExport(config('filesystems.private'), $folderPath, $filename, $timeEntriesQuery, 1000, $timezone);
$export->export();
} elseif ($format === ExportFormat::PDF) {
if (config('services.gotenberg.url') === null) {
if (config('services.gotenberg.url') === null && ! $debug) {
throw new PdfRendererIsNotConfiguredException;
}
$viewFile = file_get_contents(resource_path('views/reports/time-entry-index/pdf.blade.php'));
Expand Down Expand Up @@ -225,6 +226,13 @@ public function indexExport(Organization $organization, TimeEntryIndexExportRequ
throw new \LogicException('View file not found');
}
$footerHtml = Blade::render($footerViewFile);
if ($debug) {
return response()->json([
'html' => $html,
'footer_html' => $footerHtml,
]);

Check warning on line 233 in app/Http/Controllers/Api/V1/TimeEntryController.php

View check run for this annotation

Codecov / codecov/patch

app/Http/Controllers/Api/V1/TimeEntryController.php#L230-L233

Added lines #L230 - L233 were not covered by tests
}

$client = new Client([
'auth' => config('services.gotenberg.basic_auth_username') !== null && config('services.gotenberg.basic_auth_password') !== null ? [
config('services.gotenberg.basic_auth_username'),
Expand Down Expand Up @@ -347,6 +355,7 @@ public function aggregateExport(Organization $organization, TimeEntryAggregateEx
if ($format === ExportFormat::PDF && ! $this->canAccessPremiumFeatures($organization)) {
throw new FeatureIsNotAvailableInFreePlanApiException;
}
$debug = $request->getDebug();
$user = $this->user();

$group = $request->getGroup();
Expand Down Expand Up @@ -381,7 +390,7 @@ public function aggregateExport(Organization $organization, TimeEntryAggregateEx
$path = $folderPath.'/'.$filename;

if ($format === ExportFormat::PDF) {
if (config('services.gotenberg.url') === null) {
if (config('services.gotenberg.url') === null && ! $debug) {
throw new PdfRendererIsNotConfiguredException;
}
$client = new Client([
Expand All @@ -408,6 +417,12 @@ public function aggregateExport(Organization $organization, TimeEntryAggregateEx
throw new \LogicException('View file not found');
}
$footerHtml = Blade::render($footerViewFile);
if ($debug) {
return response()->json([
'html' => $html,
'footer_html' => $footerHtml,
]);

Check warning on line 424 in app/Http/Controllers/Api/V1/TimeEntryController.php

View check run for this annotation

Codecov / codecov/patch

app/Http/Controllers/Api/V1/TimeEntryController.php#L421-L424

Added lines #L421 - L424 were not covered by tests
}
$request = Gotenberg::chromium(config('services.gotenberg.url'))
->pdf()
->waitForExpression("window.status === 'ready'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,18 @@ public function rules(): array
'string',
'in:true,false',
],
'debug' => [
'string',
'in:true,false',
],
];
}

public function getDebug(): bool
{
return $this->input('debug') === 'true';
}

public function getGroup(): TimeEntryAggregationType
{
return TimeEntryAggregationType::from($this->input('group'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,18 @@ public function rules(): array
'string',
'in:true,false',
],
'debug' => [
'string',
'in:true,false',
],
];
}

public function getDebug(): bool
{
return $this->input('debug', 'false') === 'true';
}

public function getStart(): Carbon
{
$start = Carbon::createFromFormat('Y-m-d\TH:i:s\Z', $this->input('start'), 'UTC');
Expand Down

0 comments on commit 902221c

Please sign in to comment.