-
Notifications
You must be signed in to change notification settings - Fork 0
Download Student Applications as PDF (background process) and Excel #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
betsyecastro
wants to merge
29
commits into
develop
Choose a base branch
from
bulk-export-student-apps-pdf
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e464738
Exports student applications to CSV
betsyecastro 5a0bb3d
Changes `toCsv()` macro from Builder facade to Collection
betsyecastro b78eaf2
Corrects value returned by the exportStudentApps() method
betsyecastro c81a9c3
Styles 'Export' button, renames the 'export' method to 'exportToCsv' …
betsyecastro 85caada
Adds student applications PDF export feature
betsyecastro 74df4ec
Adds export menu Livewire component
betsyecastro fd70896
Merge branch 'allow-bulk-export-andor-view-of-student-applications' i…
betsyecastro a56c355
Adds download menu and PDF export option for student applications
betsyecastro 8b5e69d
Removes unnecessary files
betsyecastro d9e4782
Generates student apps pdf file in the background
betsyecastro 4d9dcbe
Adds an interface to support multiple PDF generation service implemen…
betsyecastro 7f8385a
Removes unnecessary files and clean up
betsyecastro da2ffa8
Refactoring download request and download routes for generic authoriz…
betsyecastro 7dfaad4
Refactoring auth and moving file download endpoint to download via Li…
betsyecastro c781a47
Adds single student app download
betsyecastro 3e2984b
Fixes filter summary
betsyecastro 4aa0c6a
downloadAsPdf refactoring and add HasPdfDownloads trait
betsyecastro 9b3f3de
Removes unnecessary event listener
betsyecastro 3a421e7
Merge branch 'develop' into bulk-export-student-apps-pdf
betsyecastro 82534b5
Resolve conflicts related to Nov 2025 NPM and composer updates
betsyecastro a13215e
Update .env.example to add pdf and queue options
betsyecastro ff242da
Remove unnecessary listener and fix filing_status initialization
betsyecastro f15bc65
Move logic to get selected filters to HasFilters trait
betsyecastro 6b0f7e0
Fix logic to refresh students property
betsyecastro c8de2bd
Fix returned value for empty $students collection
betsyecastro f4d5da4
Add filing_status property to ProfileStudentsDownloadMenu
betsyecastro 75bf162
Fix psalm errors
betsyecastro ebe81ab
Update .env.example
betsyecastro 37bccdd
Remove unnecessary facades
betsyecastro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| <?php | ||
|
|
||
| namespace App\Console\Commands; | ||
|
|
||
| use Carbon\Carbon; | ||
| use Illuminate\Console\Command; | ||
| use Illuminate\Support\Facades\Storage; | ||
|
|
||
| class CleanUpPdfFiles extends Command | ||
| { | ||
| protected $signature = 'files:clean-up-pdfs | ||
| {--root=tmp/reports : Root directory where timestamped folders live} | ||
| {--hours=2 : Delete folders older than this many hours} | ||
| {--disk= : Filesystem disk to use (defaults to FILESYSTEM_DISK)} | ||
| {--dry : Show what would be deleted, but don\'t delete}'; | ||
|
|
||
| protected $description = 'Delete temporary PDF folders (Ymd_Hi format) older than the specified number of hours. Default: 2 hours.'; | ||
|
|
||
| public function handle(): int | ||
| { | ||
| $disk_name = $this->option('disk') ?: config('filesystems.default'); | ||
| $disk = Storage::disk($disk_name); | ||
|
|
||
| $root = rtrim($this->option('root') ?? 'tmp/reports', '/'); | ||
| $hours_opt = (string) ($this->option('hours') ?? '2'); | ||
|
|
||
|
|
||
| if (!ctype_digit($hours_opt)) { // validate hours | ||
| $this->error("Invalid --hours value: {$hours_opt}. Use a non-negative integer."); | ||
| return self::FAILURE; | ||
| } | ||
| $hours = (int) $hours_opt; | ||
|
|
||
| $now = now()->second(0); | ||
| $cutoff = $now->copy()->subHours($hours); | ||
|
|
||
| if (!$disk->exists($root)) { | ||
| $this->info("Root '{$root}' does not exist on disk '{$disk_name}'. Nothing to do."); | ||
| return self::SUCCESS; | ||
| } | ||
|
|
||
| // Only consider folders named Ymd_Hi (e.g., 20250826_1430) | ||
| $dirs = collect($disk->directories($root)) | ||
| ->filter(fn ($path) => (bool) preg_match('~^' . preg_quote($root, '~') . '/\d{8}_\d{4}$~', $path)) | ||
| ->sort() | ||
| ->values(); | ||
|
|
||
| if ($dirs->isEmpty()) { | ||
| $this->info("No timestamped folders found under '{$root}'."); | ||
| return self::SUCCESS; | ||
| } | ||
|
|
||
| $dry = (bool) $this->option('dry'); | ||
| $deleted = 0; $skipped = 0; | ||
|
|
||
| foreach ($dirs as $dir) { | ||
| $stamp = basename($dir); | ||
|
|
||
| // Parse folder timestamp; skip if malformed | ||
| $bucket_time = Carbon::createFromFormat('Ymd_Hi', $stamp, $now->timezone)->second(0); | ||
| if ($bucket_time === false) { | ||
| $this->warn("Skipping malformed folder name: {$dir}"); | ||
| $skipped++; | ||
| continue; | ||
| } | ||
|
|
||
| if ($bucket_time->lt($cutoff)) { | ||
| if ($dry) { | ||
| $this->line("[DRY] Would delete: {$dir} ({$bucket_time->toDateTimeString()})"); | ||
| } else { | ||
| $disk->deleteDirectory($dir); | ||
| $this->line("Deleted: {$dir} ({$bucket_time->toDateTimeString()})"); | ||
| } | ||
| $deleted++; | ||
| } else { | ||
| $skipped++; | ||
| } | ||
| } | ||
|
|
||
| $summary = $dry ? 'would delete' : 'deleted'; | ||
| $this->info("Cleanup complete: {$summary} {$deleted}, kept {$skipped}. Disk='{$disk_name}', Root='{$root}', Cutoff='{$cutoff->toDateTimeString()}'."); | ||
|
|
||
| return self::SUCCESS; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| <?php | ||
|
|
||
| namespace App\Helpers; | ||
|
|
||
| use App\Helpers\Contracts\PdfGenerationHelperContract; | ||
| use App\PdfGenerationResult; | ||
| use Carbon\Carbon; | ||
| use Illuminate\Support\Facades\Storage; | ||
| use Spatie\Browsershot\Browsershot; | ||
| use Illuminate\Support\Str; | ||
|
|
||
| class BrowsershotPdfHelper implements PdfGenerationHelperContract | ||
| { | ||
| public function generate(array $payload): PdfGenerationResult | ||
| { | ||
| $filename = $payload['filename'] ?? ''; | ||
| $data = $payload['data'] ?? ''; | ||
| $view = $payload['view'] ?? ''; | ||
|
|
||
| $folder_timestamp = $this->currentReportBucket(); | ||
| $dir = "tmp/reports/{$folder_timestamp}"; | ||
|
|
||
| $file_timestamp = Carbon::now()->addMinutes(30)->format('YmdHis'); | ||
| $filename = "{$filename}_{$file_timestamp}.pdf"; | ||
|
|
||
| $storage_path = "$dir/$filename"; | ||
| $absolute_path = Storage::path($storage_path); | ||
|
|
||
| Storage::makeDirectory($dir); | ||
|
|
||
| $html = ''; | ||
| $html .= view($view, $data)->render(); | ||
|
|
||
| $content = Browsershot::html($html) | ||
| ->waitUntilNetworkIdle() | ||
| ->ignoreHttpsErrors() | ||
| ->margins(30, 15, 30, 15); | ||
|
|
||
| if (config('pdf.node')) { | ||
| $content = $content->setNodeBinary(config('pdf.node')); | ||
| } | ||
|
|
||
| if (config('pdf.npm')) { | ||
| $content = $content->setNpmBinary(config('pdf.npm')); | ||
| } | ||
|
|
||
| if (config('pdf.modules')) { | ||
| $content = $content->setIncludePath(config('pdf.modules')); | ||
| } | ||
|
|
||
| if (config('pdf.chrome')) { | ||
| $content = $content->setChromePath(config('pdf.chrome')); | ||
| } | ||
|
|
||
| if (config('pdf.chrome_arguments')) { | ||
| $content = $content->addChromiumArguments(config('pdf.chrome_arguments')); | ||
| } | ||
|
|
||
| $content->timeout(60) | ||
| ->save($absolute_path); | ||
|
|
||
| return new PdfGenerationResult( | ||
| success: true, | ||
| filename: $filename, | ||
| path: $storage_path, | ||
| job_id: (string) Str::ulid(), | ||
| ); | ||
| } | ||
|
|
||
|
|
||
| public function currentReportBucket() | ||
| { | ||
| $t = Carbon::now()->copy()->second(0); | ||
|
|
||
| $bucket_minute = (int) (floor($t->minute / 30) * 30); | ||
| $t->minute($bucket_minute); | ||
|
|
||
| return $t->format('Ymd_Hi'); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?php | ||
|
|
||
| namespace App\Helpers\Contracts; | ||
|
|
||
| use App\PdfGenerationResult; | ||
|
|
||
| interface PdfGenerationHelperContract { | ||
|
|
||
| public function generate(array $payload): PdfGenerationResult; | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
|
|
||
| namespace App\Helpers; | ||
|
|
||
| use App\Helpers\Contracts\PdfGenerationHelperContract; | ||
| use App\PdfGenerationResult; | ||
| use Illuminate\Support\Str; | ||
|
|
||
| class LambdaPdfHelper implements PdfGenerationHelperContract | ||
| { | ||
| public function generate(array $payload): PdfGenerationResult | ||
| { | ||
|
|
||
| // Pdf::view('pdf.invoice', $data) | ||
| // ->onLambda() | ||
| // ->save('invoice.pdf'); | ||
|
|
||
| $filename = $payload['filename'] ?? ''; | ||
| $storage_path = $payload['storage_path'] ?? ''; | ||
| $job_id = $payload['job_id'] ?? (string) Str::ulid(); | ||
|
|
||
| return new PdfGenerationResult( | ||
| success: true, | ||
| filename: $filename, | ||
| path: $storage_path, | ||
| job_id: $job_id, | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,4 +10,5 @@ | |
| class Controller extends BaseController | ||
| { | ||
| use AuthorizesRequests, DispatchesJobs, ValidatesRequests; | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| <?php | ||
|
|
||
| namespace App\Http\Livewire\Concerns; | ||
|
|
||
| use App\Jobs\ProcessPdfJob; | ||
| use Illuminate\Support\Facades\Cache; | ||
| use Illuminate\Support\Facades\URL; | ||
| use Illuminate\Support\Str; | ||
|
|
||
| trait HasPdfDownloads | ||
| { | ||
| public function initiatePdfDownload($view, $data, $filename, $file_description = '') | ||
| { | ||
| if (!$data) { return false; } | ||
|
|
||
| $user = auth()->user(); | ||
| $token = (string) Str::ulid(); | ||
|
|
||
| $this->cachePdfToken($user, $token); | ||
|
|
||
| $download_request_url = URL::temporarySignedRoute('pdf.requestDownload', now()->addMinutes(10), ['user' => $user, 'token' => $token]); | ||
|
|
||
| ProcessPdfJob::dispatch($user, $view, $filename, $file_description, $token, $data); | ||
|
|
||
| $this->dispatchBrowserEvent('initiatePdfDownload', ['download_request_url' => $download_request_url]); | ||
| } | ||
|
|
||
| protected function cachePdfToken($user, $token) { | ||
| $user_tokens = Cache::get("pdf:tokens:{$user->pea}", collect()); | ||
| $user_tokens->push($token); | ||
|
|
||
| Cache::put("pdf:tokens:{$user->pea}", $user_tokens, now()->addMinutes(30)); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.