Skip to content

Commit 5b2b502

Browse files
committed
Add sprint relation manager to projects instead of a separated resource
1 parent 5bfdacb commit 5b2b502

19 files changed

Lines changed: 762 additions & 311 deletions

File tree

app/Filament/Pages/Board.php

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace App\Filament\Pages;
4+
5+
use App\Models\Project;
6+
use Filament\Forms\Components\Card;
7+
use Filament\Forms\Components\Grid;
8+
use Filament\Forms\Components\Select;
9+
use Filament\Forms\Concerns\InteractsWithForms;
10+
use Filament\Forms\Contracts\HasForms;
11+
use Filament\Pages\Page;
12+
13+
class Board extends Page implements HasForms
14+
{
15+
use InteractsWithForms;
16+
17+
protected static ?string $navigationIcon = 'heroicon-o-view-boards';
18+
19+
protected static string $view = 'filament.pages.board';
20+
21+
protected static ?string $slug = 'board';
22+
23+
protected static ?int $navigationSort = 4;
24+
25+
public function mount(): void
26+
{
27+
$this->form->fill();
28+
}
29+
30+
protected static function getNavigationLabel(): string
31+
{
32+
return __('Board');
33+
}
34+
35+
protected static function getNavigationGroup(): ?string
36+
{
37+
return __('Management');
38+
}
39+
40+
protected function getFormSchema(): array
41+
{
42+
return [
43+
Card::make()
44+
->schema([
45+
Grid::make()
46+
->columns(1)
47+
->schema([
48+
Select::make('project')
49+
->label(__('Project'))
50+
->required()
51+
->searchable()
52+
->reactive()
53+
->afterStateUpdated(fn () => $this->search())
54+
->helperText(__("Choose a project to show it's board"))
55+
->options(fn() => Project::where('owner_id', auth()->user()->id)
56+
->orWhereHas('users', function ($query) {
57+
return $query->where('users.id', auth()->user()->id);
58+
})->pluck('name', 'id')->toArray()),
59+
]),
60+
]),
61+
];
62+
}
63+
64+
public function search(): void
65+
{
66+
$data = $this->form->getState();
67+
$project = Project::find($data['project']);
68+
if ($project->type === "scrum") {
69+
$this->redirect(route('filament.pages.scrum/{project}', ['project' => $project]));
70+
} else {
71+
$this->redirect(route('filament.pages.kanban/{project}', ['project' => $project]));
72+
}
73+
}
74+
}

app/Filament/Pages/Kanban.php

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ class Kanban extends Page implements HasForms
2727

2828
protected static ?string $navigationIcon = 'heroicon-o-view-boards';
2929

30-
protected static ?string $slug = 'kanban';
30+
protected static ?string $slug = 'kanban/{project}';
3131

3232
protected static string $view = 'filament.pages.kanban';
3333

34-
protected static ?int $navigationSort = 4;
34+
protected static bool $shouldRegisterNavigation = false;
3535

3636
public bool $sortable = true;
3737

@@ -49,26 +49,21 @@ class Kanban extends Page implements HasForms
4949
'closeTicketDialog'
5050
];
5151

52-
public function mount()
52+
public function mount(Project $project)
5353
{
54-
if (request()->has('project')) {
55-
$this->project = Project::find(request()->get('project'));
56-
if (
57-
$this->project->owner_id != auth()->user()->id
58-
&&
59-
!$this->project->users->where('id', auth()->user()->id)->count()
60-
) {
61-
abort(403);
62-
}
54+
$this->project = $project;
55+
if ($this->project->type === 'scrum') {
56+
$this->redirect(route('filament.pages.scrum/{project}', ['project' => $project]));
57+
} elseif (
58+
$this->project->owner_id != auth()->user()->id
59+
&&
60+
!$this->project->users->where('id', auth()->user()->id)->count()
61+
) {
62+
abort(403);
6363
}
6464
$this->form->fill();
6565
}
6666

67-
protected static function getNavigationLabel(): string
68-
{
69-
return __('Kanban');
70-
}
71-
7267
protected function getFormSchema(): array
7368
{
7469
return [
@@ -130,14 +125,14 @@ protected function getActions(): array
130125
];
131126
}
132127

133-
protected static function getNavigationGroup(): ?string
134-
{
135-
return __('Management');
136-
}
137-
138128
protected function getHeading(): string|Htmlable
139129
{
140-
$heading = '<div class="flex flex-col gap-1">';
130+
$heading = '<div class="w-full flex flex-col gap-1">';
131+
$heading .= '<a href="' . route('filament.pages.board') . '"
132+
class="text-primary-500 text-xs font-medium hover:underline">';
133+
$heading .= __('Back to board');
134+
$heading .= '</a>';
135+
$heading .= '<div class="flex flex-col gap-1">';
141136
$heading .= '<span>' . __('Kanban');
142137
if ($this->project) {
143138
$heading .= ' - ' . $this->project->name . '</span>';
@@ -147,6 +142,7 @@ protected function getHeading(): string|Htmlable
147142
. '</span>';
148143
}
149144
$heading .= '</div>';
145+
$heading .= '</div>';
150146
return new HtmlString($heading);
151147
}
152148

0 commit comments

Comments
 (0)