Skip to content

Commit

Permalink
Merge pull request #126 from devaslanphp/dev
Browse files Browse the repository at this point in the history
pxlrbt/filament-excel integration
  • Loading branch information
heloufir authored Sep 30, 2022
2 parents 35be52f + 9a03735 commit 8eaffe9
Show file tree
Hide file tree
Showing 12 changed files with 824 additions and 24 deletions.
40 changes: 40 additions & 0 deletions app/Http/Livewire/Administration/Companies.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Company;
use App\Tables\Columns\UserColumn;
use Carbon\Carbon;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\BooleanColumn;
use Filament\Tables\Columns\ImageColumn;
Expand All @@ -15,6 +16,10 @@
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\HtmlString;
use Livewire\Component;
use Maatwebsite\Excel\Excel;
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;
use pxlrbt\FilamentExcel\Columns\Column;
use pxlrbt\FilamentExcel\Exports\ExcelExport;

class Companies extends Component implements HasTable
{
Expand Down Expand Up @@ -108,6 +113,41 @@ protected function getTableActions(): array
];
}

/**
* Table header actions definition
*
* @return array
*/
protected function getTableHeaderActions(): array
{
return [
ExportAction::make()
->label(__('Export'))
->color('success')
->icon('heroicon-o-document-download')
->exports([
ExcelExport::make()
->askForWriterType()
->withFilename('companies-export')
->withColumns([
Column::make('name')
->heading(__('Company name')),
Column::make('responsible.name')
->heading(__('Responsible')),
Column::make('is_disabled')
->heading(__('Company activated'))
->formatStateUsing(fn (bool $state) => $state ? __('No') : __('Yes')),
Column::make('users')
->heading(__('Company users'))
->formatStateUsing(fn (Company $record) => $record->users->pluck('name')->join(', ')),
Column::make('created_at')
->heading(__('Created at'))
->formatStateUsing(fn (Carbon $state) => $state->format(__('Y-m-d g:i A'))),
])
])
];
}

/**
* Table default sort column definition
*
Expand Down
37 changes: 37 additions & 0 deletions app/Http/Livewire/Administration/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Http\Livewire\Administration;

use App\Models\Company;
use Carbon\Carbon;
use Filament\Notifications\Notification;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\TextColumn;
Expand All @@ -11,6 +13,9 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
use Livewire\Component;
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;
use pxlrbt\FilamentExcel\Columns\Column;
use pxlrbt\FilamentExcel\Exports\ExcelExport;
use Spatie\Permission\Models\Role;

class Roles extends Component implements HasTable
Expand Down Expand Up @@ -76,6 +81,38 @@ protected function getTableActions(): array
];
}

/**
* Table header actions definition
*
* @return array
*/
protected function getTableHeaderActions(): array
{
return [
ExportAction::make()
->label(__('Export'))
->color('success')
->icon('heroicon-o-document-download')
->exports([
ExcelExport::make()
->askForWriterType()
->withFilename('user-roles-export')
->withColumns([
Column::make('name')
->heading(__('Role name')),
Column::make('permissions')
->heading(__('Permissions'))
->formatStateUsing(
fn (Role $record) => $record->permissions->pluck('name')->join(', ')
),
Column::make('created_at')
->heading(__('Created at'))
->formatStateUsing(fn (Carbon $state) => $state->format(__('Y-m-d g:i A'))),
])
])
];
}

/**
* Table default sort column definition
*
Expand Down
32 changes: 32 additions & 0 deletions app/Http/Livewire/Administration/TicketPriorities.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Http\Livewire\Administration;

use App\Models\TicketPriority;
use App\Models\User;
use Carbon\Carbon;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
Expand All @@ -11,6 +13,9 @@
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\HtmlString;
use Livewire\Component;
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;
use pxlrbt\FilamentExcel\Columns\Column;
use pxlrbt\FilamentExcel\Exports\ExcelExport;

class TicketPriorities extends Component implements HasTable
{
Expand Down Expand Up @@ -80,6 +85,33 @@ protected function getTableActions(): array
];
}

/**
* Table header actions definition
*
* @return array
*/
protected function getTableHeaderActions(): array
{
return [
ExportAction::make()
->label(__('Export'))
->color('success')
->icon('heroicon-o-document-download')
->exports([
ExcelExport::make()
->askForWriterType()
->withFilename('ticket-priorities-export')
->withColumns([
Column::make('title')
->heading(__('Title')),
Column::make('created_at')
->heading(__('Created at'))
->formatStateUsing(fn(Carbon $state) => $state->format(__('Y-m-d g:i A'))),
])
])
];
}

/**
* Table default sort column definition
*
Expand Down
31 changes: 31 additions & 0 deletions app/Http/Livewire/Administration/TicketStatuses.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Livewire\Administration;

use App\Models\TicketStatus;
use Carbon\Carbon;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\BooleanColumn;
use Filament\Tables\Columns\TextColumn;
Expand All @@ -12,6 +13,9 @@
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\HtmlString;
use Livewire\Component;
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;
use pxlrbt\FilamentExcel\Columns\Column;
use pxlrbt\FilamentExcel\Exports\ExcelExport;

class TicketStatuses extends Component implements HasTable
{
Expand Down Expand Up @@ -84,6 +88,33 @@ protected function getTableActions(): array
];
}

/**
* Table header actions definition
*
* @return array
*/
protected function getTableHeaderActions(): array
{
return [
ExportAction::make()
->label(__('Export'))
->color('success')
->icon('heroicon-o-document-download')
->exports([
ExcelExport::make()
->askForWriterType()
->withFilename('ticket-statuses-export')
->withColumns([
Column::make('title')
->heading(__('Title')),
Column::make('created_at')
->heading(__('Created at'))
->formatStateUsing(fn(Carbon $state) => $state->format(__('Y-m-d g:i A'))),
])
])
];
}

/**
* Table default sort column definition
*
Expand Down
31 changes: 31 additions & 0 deletions app/Http/Livewire/Administration/TicketTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Livewire\Administration;

use App\Models\TicketType;
use Carbon\Carbon;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Concerns\InteractsWithTable;
Expand All @@ -11,6 +12,9 @@
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\HtmlString;
use Livewire\Component;
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;
use pxlrbt\FilamentExcel\Columns\Column;
use pxlrbt\FilamentExcel\Exports\ExcelExport;

class TicketTypes extends Component implements HasTable
{
Expand Down Expand Up @@ -80,6 +84,33 @@ protected function getTableActions(): array
];
}

/**
* Table header actions definition
*
* @return array
*/
protected function getTableHeaderActions(): array
{
return [
ExportAction::make()
->label(__('Export'))
->color('success')
->icon('heroicon-o-document-download')
->exports([
ExcelExport::make()
->askForWriterType()
->withFilename('ticket-types-export')
->withColumns([
Column::make('title')
->heading(__('Title')),
Column::make('created_at')
->heading(__('Created at'))
->formatStateUsing(fn(Carbon $state) => $state->format(__('Y-m-d g:i A'))),
])
])
];
}

/**
* Table default sort column definition
*
Expand Down
57 changes: 47 additions & 10 deletions app/Http/Livewire/Administration/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

namespace App\Http\Livewire\Administration;

use App\Models\Company;
use App\Models\User;
use App\Notifications\UserCreatedNotification;
use Filament\Forms\Components\TagsInput;
use Carbon\Carbon;
use Filament\Notifications\Notification;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\BadgeColumn;
use Filament\Tables\Columns\BooleanColumn;
use Filament\Tables\Columns\TagsColumn;
use Filament\Tables\Columns\TextColumn;
Expand All @@ -18,6 +16,9 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
use Livewire\Component;
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;
use pxlrbt\FilamentExcel\Columns\Column;
use pxlrbt\FilamentExcel\Exports\ExcelExport;

class Users extends Component implements HasTable
{
Expand All @@ -43,11 +44,10 @@ protected function getTableQuery(): Builder|Relation
if (auth()->user()->can('View company users') && !auth()->user()->can('View all users')) {
$query->whereHas(
'companies',
fn ($query) =>
$query->whereIn(
'companies.id',
auth()->user()->ownCompanies->pluck('id')->toArray()
)
fn($query) => $query->whereIn(
'companies.id',
auth()->user()->ownCompanies->pluck('id')->toArray()
)
);
} elseif (!auth()->user()->can('View all users')) {
// Get empty list
Expand Down Expand Up @@ -75,7 +75,7 @@ protected function getTableColumns(): array
TagsColumn::make('roles.name')
->label(__('User roles'))
->limit(1)
->visible(fn () => auth()->user()->can('Assign permissions'))
->visible(fn() => auth()->user()->can('Assign permissions'))
->searchable()
->sortable(),

Expand Down Expand Up @@ -113,11 +113,48 @@ protected function getTableActions(): array
->icon('heroicon-o-pencil')
->link()
->label(__('Edit user'))
->visible(fn () => auth()->user()->can('Update users'))
->visible(fn() => auth()->user()->can('Update users'))
->action(fn(User $record) => $this->updateUser($record->id))
];
}

/**
* Table header actions definition
*
* @return array
*/
protected function getTableHeaderActions(): array
{
return [
ExportAction::make()
->label(__('Export'))
->color('success')
->icon('heroicon-o-document-download')
->exports([
ExcelExport::make()
->askForWriterType()
->withFilename('users-export')
->withColumns([
Column::make('name')
->heading(__('Full name')),
Column::make('companies')
->heading(__('Companies'))
->formatStateUsing(
fn(User $record) => $record->companies->pluck('name')->join(', ')
),
Column::make('roles')
->heading(__('User roles'))
->formatStateUsing(
fn(User $record) => $record->roles->pluck('name')->join(', ')
),
Column::make('created_at')
->heading(__('Created at'))
->formatStateUsing(fn(Carbon $state) => $state->format(__('Y-m-d g:i A'))),
])
])
];
}

/**
* Table default sort column definition
*
Expand Down
Loading

0 comments on commit 8eaffe9

Please sign in to comment.