Skip to content

Commit

Permalink
feat: add organization profile resource (#112)
Browse files Browse the repository at this point in the history
* feat: add organization profile resource

* sort navigation items

* fix document list eager loading

* remove relation managers from edit

* update dependencies
  • Loading branch information
andreiio authored Oct 18, 2023
1 parent e9ea945 commit 1b1c36e
Show file tree
Hide file tree
Showing 19 changed files with 390 additions and 149 deletions.
2 changes: 2 additions & 0 deletions app/Filament/Resources/DocumentResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class DocumentResource extends Resource

protected static ?string $navigationIcon = 'heroicon-o-document-text';

protected static ?int $navigationSort = 2;

public static function getModelLabel(): string
{
return __('document.label.singular');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Filament\Resources\DocumentResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Database\Eloquent\Builder;

class ListDocuments extends ListRecords
{
Expand All @@ -18,4 +19,9 @@ protected function getActions(): array
Actions\CreateAction::make(),
];
}

protected function getTableQuery(): Builder
{
return parent::getTableQuery()->with('organisation');
}
}
3 changes: 2 additions & 1 deletion app/Filament/Resources/OrganisationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class OrganisationResource extends Resource

protected static ?string $navigationIcon = 'heroicon-o-office-building';

protected static ?int $navigationSort = 1;

public static function getModelLabel(): string
{
return __('organisation.label.singular');
Expand All @@ -51,7 +53,6 @@ public static function getPluralModelLabel(): string

public static function form(Form $form): Form
{
// debug(Organisation::find(1)->expertises);
return $form
->columns(3)
->schema([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
namespace App\Filament\Resources\OrganisationResource\Pages;

use App\Filament\Resources\OrganisationResource;
use App\Filament\Resources\OrganisationResource\RelationManagers\DocumentsRelationManager;
use App\Filament\Resources\OrganisationResource\RelationManagers\ResourcesRelationManager;
use App\Filament\Resources\OrganisationResource\RelationManagers\UsersRelationManager;
use App\Filament\Resources\OrganisationResource\RelationManagers\VolunteersRelationManager;
use Filament\Resources\Pages\EditRecord;

class EditOrganisation extends EditRecord
Expand All @@ -30,10 +26,7 @@ public function getTitle(): string
protected function getRelationManagers(): array
{
return [
VolunteersRelationManager::class,
ResourcesRelationManager::class,
DocumentsRelationManager::class,
UsersRelationManager::class,
//
];
}

Expand Down
63 changes: 63 additions & 0 deletions app/Filament/Resources/ProfileResource.php
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 app/Filament/Resources/ProfileResource/Concerns/ResolvesRecord.php
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 app/Filament/Resources/ProfileResource/Pages/EditProfile.php
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 app/Filament/Resources/ProfileResource/Pages/ViewProfile.php
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');
}
}
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');
}
}
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');
// }
}
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');
}
}
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');
}
}
2 changes: 2 additions & 0 deletions app/Filament/Resources/ResourceResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class ResourceResource extends Resource

protected static ?string $navigationIcon = 'heroicon-o-collection';

protected static ?int $navigationSort = 3;

public static function getModelLabel(): string
{
return __('resource.label.singular');
Expand Down
2 changes: 2 additions & 0 deletions app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class UserResource extends Resource

protected static ?string $navigationIcon = 'heroicon-o-users';

protected static ?int $navigationSort = 5;

public static function getModelLabel(): string
{
return __('user.label.singular');
Expand Down
2 changes: 2 additions & 0 deletions app/Filament/Resources/VolunteerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class VolunteerResource extends Resource

protected static ?string $navigationIcon = 'heroicon-o-user-group';

protected static ?int $navigationSort = 4;

public static function getModelLabel(): string
{
return __('volunteer.label.singular');
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"filament/spatie-laravel-media-library-plugin": "^2.17",
"guzzlehttp/guzzle": "^7.8",
"jeffgreco13/filament-breezy": "^1.5",
"laravel/framework": "^10.26",
"laravel/framework": "^10.28",
"laravel/sanctum": "^3.2",
"laravel/tinker": "^2.8",
"league/flysystem-aws-s3-v3": "^3.16",
Expand All @@ -21,13 +21,13 @@
"barryvdh/laravel-debugbar": "^3.9",
"barryvdh/laravel-ide-helper": "^2.13",
"fakerphp/faker": "^1.23",
"friendsofphp/php-cs-fixer": "^3.34",
"friendsofphp/php-cs-fixer": "^3.35",
"itsgoingd/clockwork": "^5.1",
"laravel-lang/common": "^4.0",
"laravel/sail": "^1.23",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^7.9",
"phpunit/phpunit": "^10.3",
"nunomaduro/collision": "^7.10",
"phpunit/phpunit": "^10.4",
"spatie/laravel-ignition": "^2.3"
},
"autoload": {
Expand Down
Loading

0 comments on commit 1b1c36e

Please sign in to comment.