|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NovaExportConfiguration\Nova\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
|
6
|
|
|
use Laravel\Nova\Actions\Action; |
|
7
|
|
|
use Laravel\Nova\Http\Requests\ActionRequest; |
|
8
|
|
|
use Maatwebsite\LaravelNovaExcel\Actions\ExportToExcel; |
|
9
|
|
|
use NovaExportConfiguration\NovaExportConfig; |
|
10
|
|
|
use NovaResourceDynamicExport\Models\ExportStoredFile; |
|
11
|
|
|
|
|
12
|
|
|
class ConfiguredExportToExcelAction extends ExportToExcel |
|
13
|
|
|
{ |
|
14
|
|
|
use WithQueue; |
|
15
|
|
|
|
|
16
|
|
|
public $showOnIndex = false; |
|
17
|
|
|
|
|
18
|
|
|
public $showInline = true; |
|
19
|
|
|
|
|
20
|
|
|
public $showOnDetail = true; |
|
21
|
|
|
|
|
22
|
|
|
public function name(): string |
|
23
|
|
|
{ |
|
24
|
|
|
return __('Export Config'); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
protected function withDefaultFilename(ActionRequest $request): void |
|
28
|
|
|
{ |
|
29
|
|
|
$model = $request->findModelOrFail($request->resources); |
|
30
|
|
|
$this->withFilename(Str::kebab($model->name) . date('-Ymd') . '.' . $this->getDefaultExtension()); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
public function handle(ActionRequest $request, Action $exportable) |
|
35
|
|
|
{ |
|
36
|
|
|
/** @var \NovaExportConfiguration\Models\ExportConfig $model */ |
|
37
|
|
|
$model = $request->findModelOrFail($request->resources); |
|
38
|
|
|
|
|
39
|
|
|
$repo = NovaExportConfig::getRepositories()->getByName($model->type); |
|
|
|
|
|
|
40
|
|
|
if (!$repo) { |
|
41
|
|
|
return Action::danger(__('Export repository not found.')); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$dbExport = ExportStoredFile::init( |
|
45
|
|
|
$request->resource()::uriKey(), |
|
46
|
|
|
$this->getDisk() ?: $repo->disk(), |
|
47
|
|
|
date('Y/m/d/') . Str::uuid() . '.' . $this->getDefaultExtension(), |
|
48
|
|
|
$this->getFilename(), |
|
|
|
|
|
|
49
|
|
|
function (ExportStoredFile $model) use ($request) { |
|
50
|
|
|
$model->meta->setAttribute('fields', $request->resolveFields()); |
|
51
|
|
|
$model->meta->setAttribute('filters', $request->filters); |
|
52
|
|
|
if ($user = $request->user()) { |
|
53
|
|
|
$model->meta->toMorph('author', $user); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
); |
|
57
|
|
|
|
|
58
|
|
|
$export = $repo->export($model, $dbExport); |
|
59
|
|
|
|
|
60
|
|
|
if ($queueName = $this->getQueue($repo->queue())) { |
|
61
|
|
|
$export->queue( |
|
62
|
|
|
$dbExport->path, |
|
63
|
|
|
$dbExport->disk, |
|
64
|
|
|
$this->getWriterType() |
|
65
|
|
|
)->allOnQueue($queueName); |
|
66
|
|
|
} else { |
|
67
|
|
|
$export->store( |
|
68
|
|
|
$dbExport->path, |
|
69
|
|
|
$dbExport->disk, |
|
70
|
|
|
$this->getWriterType() |
|
71
|
|
|
); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
return Action::message(__('Export started.')); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
// Global ESG Equity Market Neutral strategy with a focus on Europe. |
|
80
|
|
|
// Impact with less volatility and market factors. |
|
81
|
|
|
//Working across renewables, waste, water, circular economy, clean transportation and Argriculture. |
|
82
|
|
|
|
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.