-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add organization profile resource (#112)
* feat: add organization profile resource * sort navigation items * fix document list eager loading * remove relation managers from edit * update dependencies
- Loading branch information
Showing
19 changed files
with
390 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources; | ||
|
||
use App\Filament\Resources\ProfileResource\Pages; | ||
use App\Filament\Resources\ProfileResource\RelationManagers\DocumentsRelationManager; | ||
use App\Filament\Resources\ProfileResource\RelationManagers\ResourcesRelationManager; | ||
use App\Filament\Resources\ProfileResource\RelationManagers\UsersRelationManager; | ||
use App\Filament\Resources\ProfileResource\RelationManagers\VolunteersRelationManager; | ||
use App\Models\Organisation; | ||
use Filament\Resources\Form; | ||
use Filament\Resources\Resource; | ||
|
||
class ProfileResource extends Resource | ||
{ | ||
protected static ?string $model = Organisation::class; | ||
|
||
protected static ?string $slug = 'profile'; | ||
|
||
protected static ?string $navigationIcon = 'heroicon-o-office-building'; | ||
|
||
protected static ?int $navigationSort = 1; | ||
|
||
public static function getModelLabel(): string | ||
{ | ||
return __('organisation.label.singular'); | ||
} | ||
|
||
public static function getPluralModelLabel(): string | ||
{ | ||
return self::getModelLabel(); | ||
} | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return OrganisationResource::form($form); | ||
} | ||
|
||
public static function getRelations(): array | ||
{ | ||
return [ | ||
VolunteersRelationManager::class, | ||
ResourcesRelationManager::class, | ||
UsersRelationManager::class, | ||
DocumentsRelationManager::class, | ||
]; | ||
} | ||
|
||
public static function getPages(): array | ||
{ | ||
return [ | ||
'index' => Pages\ViewProfile::route('/'), | ||
'edit' => Pages\EditProfile::route('/edit'), | ||
]; | ||
} | ||
|
||
public static function canViewAny(): bool | ||
{ | ||
return auth()->user()->isOrgAdmin(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/Filament/Resources/ProfileResource/Concerns/ResolvesRecord.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\ProfileResource\Concerns; | ||
|
||
trait ResolvesRecord | ||
{ | ||
public function mount($record = null): void | ||
{ | ||
$this->record = auth()->user()->organisation; | ||
|
||
$this->fillForm(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
app/Filament/Resources/ProfileResource/Pages/EditProfile.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\ProfileResource\Pages; | ||
|
||
use App\Filament\Resources\ProfileResource; | ||
use App\Filament\Resources\ProfileResource\Concerns\ResolvesRecord; | ||
use Filament\Resources\Pages\EditRecord; | ||
|
||
class EditProfile extends EditRecord | ||
{ | ||
use ResolvesRecord; | ||
|
||
protected static string $resource = ProfileResource::class; | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
|
||
public function getTitle(): string | ||
{ | ||
return $this->getRecord()->name; | ||
} | ||
|
||
protected function getRelationManagers(): array | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
|
||
public function hasCombinedRelationManagerTabsWithForm(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
protected function getRedirectUrl(): ?string | ||
{ | ||
return static::getResource()::getUrl('index'); | ||
} | ||
|
||
public function getFormTabLabel(): ?string | ||
{ | ||
return __('organisation.section.profile'); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/Filament/Resources/ProfileResource/Pages/ViewProfile.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\ProfileResource\Pages; | ||
|
||
use App\Filament\Resources\ProfileResource; | ||
use App\Filament\Resources\ProfileResource\Concerns\ResolvesRecord; | ||
use Filament\Pages\Actions\EditAction; | ||
use Filament\Resources\Pages\ViewRecord; | ||
|
||
class ViewProfile extends ViewRecord | ||
{ | ||
use ResolvesRecord; | ||
|
||
protected static string $resource = ProfileResource::class; | ||
|
||
public function getTitle(): string | ||
{ | ||
return $this->getRecord()->name; | ||
} | ||
|
||
protected function getActions(): array | ||
{ | ||
return [ | ||
EditAction::make() | ||
->url(static::getResource()::getUrl('edit')), | ||
]; | ||
} | ||
|
||
public function hasCombinedRelationManagerTabsWithForm(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
public function getFormTabLabel(): ?string | ||
{ | ||
return __('organisation.section.profile'); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/Filament/Resources/ProfileResource/RelationManagers/DocumentsRelationManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\ProfileResource\RelationManagers; | ||
|
||
use App\Filament\Resources\OrganisationResource\RelationManagers\DocumentsRelationManager as RelationManager; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
class DocumentsRelationManager extends RelationManager | ||
{ | ||
protected function getTableQuery(): Builder | ||
{ | ||
return parent::getTableQuery()->with('organisation:id,name,city_id,county_id'); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/Filament/Resources/ProfileResource/RelationManagers/ResourcesRelationManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\ProfileResource\RelationManagers; | ||
|
||
use App\Filament\Resources\OrganisationResource\RelationManagers\ResourcesRelationManager as RelationManager; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
class ResourcesRelationManager extends RelationManager | ||
{ | ||
// protected function getTableQuery(): Builder | ||
// { | ||
// return parent::getTableQuery()->with('organisation:id,name,city_id,county_id'); | ||
// } | ||
} |
16 changes: 16 additions & 0 deletions
16
app/Filament/Resources/ProfileResource/RelationManagers/UsersRelationManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\ProfileResource\RelationManagers; | ||
|
||
use App\Filament\Resources\OrganisationResource\RelationManagers\UsersRelationManager as RelationManager; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
class UsersRelationManager extends RelationManager | ||
{ | ||
protected function getTableQuery(): Builder | ||
{ | ||
return parent::getTableQuery()->with('organisation:id,name,city_id,county_id'); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
app/Filament/Resources/ProfileResource/RelationManagers/VolunteersRelationManager.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\ProfileResource\RelationManagers; | ||
|
||
use App\Filament\Resources\OrganisationResource\RelationManagers\VolunteersRelationManager as RelationManager; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
class VolunteersRelationManager extends RelationManager | ||
{ | ||
protected function getTableQuery(): Builder | ||
{ | ||
return parent::getTableQuery()->with('organisation:id,name,city_id,county_id'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.