Skip to content

Commit

Permalink
add organization button
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 16, 2023
1 parent a8cc3a5 commit 45baeae
Show file tree
Hide file tree
Showing 19 changed files with 373 additions and 93 deletions.
4 changes: 2 additions & 2 deletions app/Filament/Resources/OrganizationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use App\Filament\Resources\OrganizationResource\RelationManagers\TicketsRelationManager;
use App\Filament\Resources\OrganizationResource\RelationManagers\UsersRelationManager;
use App\Filament\Resources\OrganizationResource\RelationManagers\VolunteersRelationManager;
use App\Forms\Components\UserLink;
use App\Forms\Components\Link;
use App\Models\Organization;
use App\Rules\ValidCIF;
use Filament\Forms\Components\Fieldset;
Expand Down Expand Up @@ -56,7 +56,7 @@ public static function form(Form $form): Form
{
return $form
->schema([
UserLink::make('administator')
Link::make('administator')
->label(__('organization.labels.administrator'))
->inlineLabel()
->columnSpanFull(),
Expand Down
12 changes: 11 additions & 1 deletion app/Filament/Resources/ProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@

use App\Enums\ProjectStatus;
use App\Filament\Resources\ProjectResource\Pages;
use App\Filament\Resources\ProjectResource\RelationManagers\ActivitiesRelationManager;
use App\Filament\Resources\ProjectResource\RelationManagers\DonationsRelationManager;
use App\Filament\Resources\ProjectResource\RelationManagers\VolunteersRelationManager;
use App\Filament\Resources\ProjectResource\Widgets\ApprovedProject;
use App\Filament\Resources\ProjectResource\Widgets\NewProject;
use App\Filament\Resources\ProjectResource\Widgets\PendingChangesProjectWidget;
use App\Filament\Resources\ProjectResource\Widgets\RejectedProject;
use App\Forms\Components\Link;
use App\Models\Project;
use Filament\Forms;
use Filament\Forms\Components\DatePicker;
Expand Down Expand Up @@ -45,6 +49,10 @@ public static function form(Form $form): Form
{
return $form
->schema([
Link::make('organizatii')->type('organization')
->label(__('organization.labels.administrator'))
->inlineLabel()
->columnSpanFull(),
Select::make('organization_id')
->label(__('project.labels.organization'))
->inlineLabel()
Expand Down Expand Up @@ -187,7 +195,9 @@ protected function getTableActionsPosition(): ?string
public static function getRelations(): array
{
return [
//
VolunteersRelationManager::class,
DonationsRelationManager::class,
ActivitiesRelationManager::class,
];
}

Expand Down
5 changes: 5 additions & 0 deletions app/Filament/Resources/ProjectResource/Pages/ViewProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,9 @@
class ViewProject extends ViewRecord
{
protected static string $resource = ProjectResource::class;

public function hasCombinedRelationManagerTabsWithForm(): bool
{
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\ProjectResource\RelationManagers;

use App\Filament\Resources\OrganizationResource\Actions\Tables\Activity\ApproveActivityAction;
use App\Filament\Resources\OrganizationResource\Actions\Tables\Activity\RejectActivityAction;
use App\Filament\Resources\OrganizationResource\Actions\Tables\Activity\ViewActivityAction;
use App\Filament\Resources\UserResource;
use App\Models\Activity;
use Carbon\Carbon;
use Filament\Forms;
use Filament\Forms\Components\DatePicker;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\Layout;
use Filament\Tables\Filters\SelectFilter;
use Illuminate\Database\Eloquent\Builder;

class ActivitiesRelationManager extends RelationManager
{
protected static string $relationship = 'activities';

// protected static ?string $recordTitleAttribute = 'description';

public static function getTitle(): string
{
return __('activity.label.plural');
}

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('description')
->required()
->maxLength(255),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('created_at')
->label(__('activity.column.created_at'))
->sortable(),

TextColumn::make('changed_field')
->label(__('activity.column.changed_field'))
->formatStateUsing(
fn ($state) => __('project.labels.' . $state)
),

TextColumn::make('causer.name')
->label(__('activity.column.causer'))
->description(
fn (Activity $record) => $record->causer?->role->label()
)
->url(
fn (Activity $record) => $record->causer
? UserResource::getUrl('view', $record->causer)
: null
)
->sortable(),

TextColumn::make('status')
->label(__('activity.column.status')),
])
->filters([
Filter::make('created_at')
->columns()
->form([
DatePicker::make('logged_from')
->label(__('activity.filter.logged_from'))
->placeholder(
fn ($state): string => today()
->setDay(17)
->setMonth(11)
->subYear()
->toFormattedDate()
),

DatePicker::make('logged_until')
->label(__('activity.filter.logged_until'))
->placeholder(
fn ($state): string => today()
->toFormattedDate()
),
])
->query(
fn (Builder $query, array $data) => $query->betweenDates(
data_get($data, 'logged_from'),
data_get($data, 'logged_until'),
)
)
->indicateUsing(
fn (array $data) => collect(['logged_from', 'logged_until'])
->mapWithKeys(function (string $filter) use ($data) {
$value = data_get($data, $filter);

if (! \is_null($value)) {
$value = __("activity.indicator.{$filter}", [
'date' => Carbon::parse($value)->toFormattedDate(),
]);
}

return [$filter => $value];
})
->filter()
->all()
),

// SelectFilter::make('causer_id')
// ->relationship('causer', 'name'),

// SelectFilter::make('changed_field'),
])
->filtersLayout(Layout::AboveContent)
->actions([
ViewActivityAction::make(),

ApproveActivityAction::make(),

RejectActivityAction::make(),
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\ProjectResource\RelationManagers;

use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;

class DonationsRelationManager extends RelationManager
{
protected static string $relationship = 'donations';

protected static ?string $recordTitleAttribute = 'uuid';

public static function getTitle(): string
{
return __('donation.label.plural');
}

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('uuid')
->required()
->maxLength(255),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('uuid'),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\ProjectResource\RelationManagers;

use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;

class VolunteersRelationManager extends RelationManager
{
protected static string $relationship = 'volunteers';

protected static ?string $recordTitleAttribute = 'full_name';

public static function getTitle(): string
{
return __('volunteer.label.plural');
}

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('full_name')
->required()
->maxLength(255),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('full_name'),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}
}
4 changes: 2 additions & 2 deletions app/Filament/Resources/ProjectResource/Widgets/NewProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class NewProject extends BaseProjectWidget

protected function getTableHeading(): string
{
return __('project.heading.pending',['number' => $this->getTableQuery()->count()]);
return __('project.heading.pending', ['number' => $this->getTableQuery()->count()]);
}

protected function getTableQuery(): Builder
{
return Project::query()->select(['id','organization_id','name','target_budget','is_national','created_at','status_updated_at','status'])->whereIsPending();
return Project::query()->select(['id', 'organization_id', 'name', 'target_budget', 'is_national', 'created_at', 'status_updated_at', 'status'])->whereIsPending();
}

protected function getTableQueryStringIdentifier(): ?string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace App\Filament\Resources\ProjectResource\Widgets;

use App\Filament\Resources\OrganizationResource\Widgets\BaseOrganizationsWidget;
use App\Models\Activity;
use App\Models\Organization;
use App\Tables\Columns\TitleWithImageColumn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function getTableHeading(): string

protected function getTableQuery(): Builder
{
return Project::query()->select(['id','organization_id','name','target_budget','is_national','created_at','status_updated_at','status'])->whereIsRejected();
return Project::query()->select(['id', 'organization_id', 'name', 'target_budget', 'is_national', 'created_at', 'status_updated_at', 'status'])->whereIsRejected();
}

protected function getTableQueryStringIdentifier(): ?string
Expand Down
54 changes: 54 additions & 0 deletions app/Forms/Components/Link.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace App\Forms\Components;

use App\Filament\Resources\OrganizationResource;
use App\Filament\Resources\UserResource;
use App\Models\User;
use Filament\Forms\Components\Field;
use Illuminate\Support\Collection;

class Link extends Field
{
protected string $view = 'forms.components.user-link';

protected string $type = 'user';

public function getUsers(): Collection
{
return $this->getRecord()
->users
->map(fn (User $user) => [
'name' => $user->name,
'url' => UserResource::getUrl('view', $user),
]);
}

public function getOrganization(): Collection
{
return collect([])->push(['name' => $this->getRecord()->organization->name, 'url' => OrganizationResource::getUrl('view', $this->getRecord()->organization)]);
}

public function type(string $type): self
{
$this->type = $type;

return $this;
}

public function getType(): string
{
return $this->type;
}

public function getLinks(): Collection
{
if ($this->type === 'user') {
return $this->getUsers();
}

return $this->getOrganization();
}
}
Loading

0 comments on commit 45baeae

Please sign in to comment.