wip(Member & memberships sections)
All checks were successful
Deploy Roxane to Preprod / deploy (push) Successful in 1m29s
All checks were successful
Deploy Roxane to Preprod / deploy (push) Successful in 1m29s
This commit is contained in:
65
app/Filament/Actions/ServiceToggleAction.php
Normal file
65
app/Filament/Actions/ServiceToggleAction.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Actions;
|
||||
|
||||
use Filament\Actions\Action;
|
||||
use Illuminate\Support\Facades\Bus;
|
||||
use App\Models\Member;
|
||||
|
||||
class ServiceToggleAction extends Action
|
||||
{
|
||||
protected string $serviceIdentifier;
|
||||
|
||||
public static function forService(string $serviceIdentifier): static
|
||||
{
|
||||
return static::make('toggle_' . $serviceIdentifier)
|
||||
->configureForService($serviceIdentifier);
|
||||
}
|
||||
|
||||
protected function configureForService(string $serviceIdentifier): static
|
||||
{
|
||||
$this->serviceIdentifier = $serviceIdentifier;
|
||||
|
||||
return $this
|
||||
->label('Service actif')
|
||||
->icon(fn (Member $record) =>
|
||||
$record->hasService($serviceIdentifier)
|
||||
? 'heroicon-o-check-circle'
|
||||
: 'heroicon-o-x-circle'
|
||||
)
|
||||
->color(fn (Member $record) =>
|
||||
$record->hasService($serviceIdentifier)
|
||||
? 'success'
|
||||
: 'gray'
|
||||
)
|
||||
->requiresConfirmation()
|
||||
->modalHeading(fn (Member $record) =>
|
||||
$record->hasService($serviceIdentifier)
|
||||
? 'Désactiver le service'
|
||||
: 'Activer le service'
|
||||
)
|
||||
->modalDescription(fn (Member $record) =>
|
||||
$record->hasService($serviceIdentifier)
|
||||
? 'Êtes-vous sûr·e de vouloir désactiver ce service pour ce membre ?'
|
||||
: 'Êtes-vous sûr·e de vouloir activer ce service pour ce membre ?'
|
||||
)
|
||||
->modalSubmitActionLabel(fn (Member $record) =>
|
||||
$record->hasService($serviceIdentifier)
|
||||
? 'Désactiver'
|
||||
: 'Activer'
|
||||
)
|
||||
->action(function (Member $record) use ($serviceIdentifier) {
|
||||
|
||||
// @todo à discuter
|
||||
/* if ($record->hasService($serviceIdentifier)) {
|
||||
Bus::dispatch(
|
||||
new \App\Jobs\DisableServiceJob($record, $serviceIdentifier)
|
||||
);
|
||||
} else {
|
||||
Bus::dispatch(
|
||||
new \App\Jobs\EnableServiceJob($record, $serviceIdentifier)
|
||||
);
|
||||
}*/
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ use App\Models\Member;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\ViewField;
|
||||
use Filament\Infolists\Components\ViewEntry;
|
||||
use Filament\Schemas\Components\Tabs;
|
||||
use Filament\Schemas\Components\Tabs\Tab;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
@@ -17,6 +17,8 @@ use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Infolists\Components\RepeatableEntry;
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use App\Filament\Actions\ServiceToggleAction;
|
||||
|
||||
class MemberForm
|
||||
{
|
||||
@@ -41,6 +43,7 @@ class MemberForm
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
Tabs\Tab::make('Informations générales')
|
||||
->icon(Heroicon::OutlinedInformationCircle)
|
||||
->schema([
|
||||
Section::make('Informations personnelles')
|
||||
->collapsible()
|
||||
@@ -120,15 +123,19 @@ class MemberForm
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
Tabs\Tab::make('Modules')
|
||||
->icon(Heroicon::OutlinedPuzzlePiece)
|
||||
->schema([
|
||||
/*
|
||||
| Messageries ISPConfig (lecture seule)
|
||||
*/
|
||||
Section::make('Messagerie ISPConfig')
|
||||
->afterHeader([
|
||||
ServiceToggleAction::forService('mail'),
|
||||
])
|
||||
->collapsible()
|
||||
->schema([
|
||||
RepeatableEntry::make('ispconfig_mails')
|
||||
->label('')
|
||||
->label('Données ISPConfig Mail')
|
||||
->state(fn(?Member $record) => $record?->ispconfigs()
|
||||
->where('type', IspconfigType::MAIL)
|
||||
->get()
|
||||
@@ -141,13 +148,20 @@ class MemberForm
|
||||
->label('ID ISPConfig'),
|
||||
|
||||
TextEntry::make('data.mailuser.quota')
|
||||
->label('Quota')
|
||||
->formatStateUsing(fn($state) => $state ? "{$state} Mo" : 'Non défini'
|
||||
),
|
||||
->label('Quota'),
|
||||
//->formatStateUsing(fn($state) => $state ? "{$state} Mo" : 'Non défini'
|
||||
//),
|
||||
|
||||
TextEntry::make('data.mailuser.domain')
|
||||
->label('Domaine')
|
||||
->default('retzien.fr'),
|
||||
ViewEntry::make('data')
|
||||
->label('JSON')
|
||||
->view('filament.components.json-viewer')
|
||||
->viewData(fn($state) => [
|
||||
'data' => $state,
|
||||
])
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(2),
|
||||
])
|
||||
@@ -159,49 +173,92 @@ class MemberForm
|
||||
/*
|
||||
| Hébergements web ISPConfig
|
||||
*/
|
||||
/*Section::make('Hébergements Web')
|
||||
Section::make('Hébergements Web')
|
||||
->afterHeader([
|
||||
ServiceToggleAction::forService('webhosting'),
|
||||
])
|
||||
->collapsible()
|
||||
->schema([
|
||||
RepeatableEntry::make('ispconfigs_web')
|
||||
->label('')
|
||||
->label('Données ISPConfig Web')
|
||||
->state(fn(?Member $record) => $record?->ispconfigs()
|
||||
->where('type', IspconfigType::WEB)
|
||||
->get()
|
||||
->map(fn ($ispconfig) => $ispconfig->toArray())
|
||||
->map(fn($ispconfig) => $ispconfig->toArray())
|
||||
->all()
|
||||
)
|
||||
->schema([
|
||||
TextEntry::make('data.domain_id')
|
||||
->label('ID Domaine'),
|
||||
->label('ID ISPConfig'),
|
||||
|
||||
TextEntry::make('data.domain')
|
||||
->label('Domaine'),
|
||||
|
||||
TextEntry::make('data.active')
|
||||
->label('État')
|
||||
->formatStateUsing(fn($state) => $state == 'o' ? "Activé" : 'Désactivé'
|
||||
->formatStateUsing(fn($state) => $state === 'y' ? 'Activé' : 'Désactivé'
|
||||
),
|
||||
ViewEntry::make('data')
|
||||
->label('JSON')
|
||||
->view('filament.components.json-viewer')
|
||||
->viewData(fn($state) => [
|
||||
'data' => $state,
|
||||
])
|
||||
->columnSpanFull(),
|
||||
// @todo: background color : #F5F8FA
|
||||
])
|
||||
->columns(2),
|
||||
->columns(3),
|
||||
|
||||
])
|
||||
->visible(fn(?Member $record) => $record?->ispconfigs()
|
||||
->where('type', IspconfigType::WEB)
|
||||
->exists()
|
||||
),*/
|
||||
Section::make('Hébergements Web')
|
||||
),
|
||||
|
||||
/*
|
||||
| Compte(s) NextCloud (lecture seule)
|
||||
*/
|
||||
Section::make('NextCloud')
|
||||
->afterHeader([
|
||||
ServiceToggleAction::forService('nextcloud'),
|
||||
])
|
||||
->collapsible()
|
||||
->schema([
|
||||
ViewField::make('ispconfig_web_hostings')
|
||||
->view('filament.components.members.web-hostings')
|
||||
->viewData(fn (?Member $record) => [
|
||||
'member' => $record,
|
||||
]),
|
||||
RepeatableEntry::make('nextcloud_accounts')
|
||||
->label('Données NextCloud')
|
||||
->state(fn(?Member $record) => $record?->nextcloudAccounts()
|
||||
->get()
|
||||
->map(fn($nextcloudAccount) => $nextcloudAccount->toArray())
|
||||
->all()
|
||||
)
|
||||
->schema([
|
||||
TextEntry::make('nextcloud_user_id')
|
||||
->label('Id Nextcloud'),
|
||||
|
||||
TextEntry::make('data.displayname')
|
||||
->label('Nom de l\'utilisateur'),
|
||||
|
||||
TextEntry::make('data.enabled')
|
||||
->label('État')
|
||||
->formatStateUsing(fn($state) => $state == 'true' ? 'Activé' : 'Désactivé'
|
||||
),
|
||||
|
||||
ViewEntry::make('data')
|
||||
->label('JSON')
|
||||
->view('filament.components.json-viewer')
|
||||
->viewData(fn($state) => [
|
||||
'data' => $state,
|
||||
])
|
||||
->columnSpanFull(),
|
||||
])
|
||||
->columns(3),
|
||||
])
|
||||
->visible(fn (?Member $record) =>
|
||||
$record?->ispconfigs()
|
||||
->where('type', IspconfigType::WEB)
|
||||
->visible(fn(?Member $record) => $record?->nextcloudAccounts()
|
||||
->exists()
|
||||
),
|
||||
]),
|
||||
]),
|
||||
])
|
||||
->contained(false)
|
||||
])
|
||||
->columnSpan(3),
|
||||
|
||||
|
||||
@@ -7,6 +7,11 @@ use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Enums\FiltersLayout;
|
||||
use Filament\Tables\Filters\QueryBuilder;
|
||||
use Filament\Tables\Filters\QueryBuilder\Constraints\DateConstraint;
|
||||
use Filament\Tables\Filters\QueryBuilder\Constraints\SelectConstraint;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
class MembershipsTable
|
||||
@@ -16,8 +21,8 @@ class MembershipsTable
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('id')
|
||||
->label('id')
|
||||
->sortable(),
|
||||
->label('id')
|
||||
->sortable(),
|
||||
TextColumn::make('member.full_name')
|
||||
->label(Membership::getAttributeLabel('member_id'))
|
||||
->sortable(),
|
||||
@@ -70,9 +75,39 @@ class MembershipsTable
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
->searchable([
|
||||
'member.firstname',
|
||||
'member.lastname',
|
||||
'author.name',
|
||||
'status',
|
||||
'payment_status',
|
||||
'amount',
|
||||
])
|
||||
->filters([
|
||||
// Filtres pour status, date de début et date de fin, status de paiement
|
||||
|
||||
QueryBuilder::make()
|
||||
->constraints([
|
||||
SelectConstraint::make('status')
|
||||
->label('Statut de l\'adhésion')
|
||||
->options([
|
||||
'active' => 'Active',
|
||||
'expired' => 'Expirée',
|
||||
'pending' => 'En attente',
|
||||
]),
|
||||
DateConstraint::make('start_date')
|
||||
->label('Date de début'),
|
||||
DateConstraint::make('end_date')
|
||||
->label('Date de fin'),
|
||||
SelectConstraint::make('payment_status')
|
||||
->label('Statut de paiement')
|
||||
->options([
|
||||
'paid' => 'Payée',
|
||||
'unpaid' => 'Impayée',
|
||||
'partial' => 'Partiellement payée'
|
||||
]),
|
||||
]),
|
||||
], layout: FiltersLayout::Modal)
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
|
||||
@@ -23,8 +23,9 @@ class ServicesTable
|
||||
TextColumn::make('identifier')
|
||||
->label(Service::getAttributeLabel('identifier'))
|
||||
->searchable(),
|
||||
TextColumn::make('icon')
|
||||
->searchable(),
|
||||
IconColumn::make('icon')
|
||||
->label('Icône')
|
||||
->icon(fn (Service $record) => 'heroicon-o-' . $record->icon),
|
||||
TextColumn::make('created_at')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
|
||||
@@ -46,4 +46,13 @@ class UserResource extends Resource
|
||||
'edit' => EditUser::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return User::getAttributeLabel('user');
|
||||
}
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return User::getAttributeLabel('users');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user