Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Jobs/DataTableExportJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use OpenSpout\Common\Helper\CellTypeHelper;
Expand Down Expand Up @@ -183,6 +184,11 @@ public function handle()
if ($this->getS3Disk()) {
Storage::disk($this->getS3Disk())->putFileAs('', (new File($path)), $filename);
}

if (request('emailTo')) {
$data = ['email' => urldecode(strval(request('emailTo'))), 'path' => $path];
$this->sendResults($data);
}
}

/**
Expand Down Expand Up @@ -271,4 +277,18 @@ protected function isNumeric($value): bool

return is_numeric($value);
}

/**
* @param array $data
* @return void
*/
public function sendResults(array $data): void
{
Mail::send('datatables-export::export-email', $data, function ($message) use ($data) {
$message->attach($data['path']);
$message->to($data['email'])
->subject('Export Report');
$message->from(config('datatables-export.mail_from'));
});
}
}
2 changes: 2 additions & 0 deletions src/Livewire/ExportButtonComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ExportButtonComponent extends Component

public ?string $tableId;

public ?string $emailTo = '';

public string $type = 'xlsx';

public string $filename = '';
Expand Down
10 changes: 10 additions & 0 deletions src/config/datatables-export.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@
*/
's3_disk' => '',

/*
|--------------------------------------------------------------------------
| Mail from address
|--------------------------------------------------------------------------
|
| Will be used to email report from this address.
|
*/
'mail_from' => env('MAIL_FROM_ADDRESS', ''),

/*
|--------------------------------------------------------------------------
| Default Date Format
Expand Down
6 changes: 5 additions & 1 deletion src/resources/views/export-button.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
x-on:submit.prevent="
$refs.exportBtn.disabled = true;
var url = window._buildUrl(LaravelDataTables['{{ $tableId }}'], 'exportQueue');
$.get(url + '&exportType={{$fileType}}&sheetName={{$sheetName}}').then(function(exportId) {
$.get(url + '&exportType={{$fileType}}&sheetName={{$sheetName}}&emailTo={{urlencode($emailTo)}}').then(function(exportId) {
$wire.export(exportId)
}).catch(function(error) {
$wire.exportFinished = true;
Expand All @@ -20,6 +20,10 @@ class="{{ $class }}"
</button>
</form>

@if($exporting && $emailTo)
<div class="d-inline">Export will be emailed to {{ $emailTo }}.</div>
@endif

@if($exporting && !$exportFinished)
<div class="d-inline" wire:poll="updateExportProgress">Exporting...please wait.</div>
@endif
Expand Down
1 change: 1 addition & 0 deletions src/resources/views/export-email.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Attached you will find requested report.