mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-08 00:02:15 +01:00
Added import system
This commit is contained in:
@@ -6,11 +6,19 @@ namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Resources\OrganizationResource\Pages;
|
||||
use App\Models\Organization;
|
||||
use App\Service\Import\Importers\ImporterProvider;
|
||||
use App\Service\Import\Importers\ImportException;
|
||||
use App\Service\Import\Importers\ReportDto;
|
||||
use App\Service\Import\ImportService;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class OrganizationResource extends Resource
|
||||
{
|
||||
@@ -60,6 +68,52 @@ class OrganizationResource extends Resource
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Action::make('Import')
|
||||
->icon('heroicon-o-inbox-arrow-down')
|
||||
->action(function (Organization $record, array $data) {
|
||||
// TODO: different disk!
|
||||
try {
|
||||
/** @var ReportDto $report */
|
||||
$report = app(ImportService::class)->import($record, $data['type'], Storage::disk('public')->get($data['file']), []);
|
||||
Notification::make()
|
||||
->title('Import successful')
|
||||
->success()
|
||||
->body(
|
||||
'Imported time entries: '.$report->timeEntriesCreated.'<br>'.
|
||||
'Imported clients: '.$report->clientsCreated.'<br>'.
|
||||
'Imported projects: '.$report->projectsCreated.'<br>'.
|
||||
'Imported tasks: '.$report->tasksCreated.'<br>'.
|
||||
'Imported tags: '.$report->tagsCreated.'<br>'.
|
||||
'Imported users: '.$report->usersCreated
|
||||
)
|
||||
->persistent()
|
||||
->send();
|
||||
} catch (ImportException $exception) {
|
||||
report($exception);
|
||||
Notification::make()
|
||||
->title('Import failed, changes rolled back')
|
||||
->danger()
|
||||
->body('Message: '.$exception->getMessage())
|
||||
->persistent()
|
||||
->send();
|
||||
}
|
||||
})
|
||||
->tooltip(fn (Organization $record): string => "Import into {$record->name}")
|
||||
->form([
|
||||
Forms\Components\FileUpload::make('file')
|
||||
->label('File')
|
||||
->required(),
|
||||
Select::make('type')
|
||||
->required()
|
||||
->options(function (): array {
|
||||
$select = [];
|
||||
foreach (app(ImporterProvider::class)->getImporterKeys() as $key) {
|
||||
$select[$key] = $key;
|
||||
}
|
||||
|
||||
return $select;
|
||||
}),
|
||||
]),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\BulkActionGroup::make([
|
||||
|
||||
Reference in New Issue
Block a user