Skip to content

Commit

Permalink
fix visible status in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Oct 13, 2023
1 parent 7f37bbf commit cbc55f1
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 25 deletions.
52 changes: 34 additions & 18 deletions app/Filament/Resources/ProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
use Filament\Forms;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieMediaLibraryFileUpload;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Filament\Tables\Actions\Position;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\SelectFilter;

Expand All @@ -41,25 +44,38 @@ public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('organization_id')
Select::make('organization_id')
->label(__('project.labels.organization'))
->inlineLabel()
->columnSpanFull()
->relationship('organization', 'name')
->disabled()
->required(),
Forms\Components\Select::make('status')->options(ProjectStatus::options())->disabled()
Select::make('status')->options(ProjectStatus::options())->disabled()
->label(__('project.labels.status'))
->inlineLabel()
->columnSpanFull()
->required(),
TextInput::make('visible_status')
->label(__('project.labels.visible_status'))
->inlineLabel()
->columnSpanFull()
->formatStateUsing(function (Project $record) {
return __(sprintf('project.visible_status.%s', $record->visible_status));
})
->hidden(
function (callable $get) {
return $get('status') != ProjectStatus::approved;
}
)
->disabled(),
Forms\Components\Toggle::make('is_national')
->label(__('project.labels.is_national'))
->inlineLabel()
->columnSpanFull()
->reactive()
->required(),
Forms\Components\Select::make('counties')
Select::make('counties')
->relationship('counties', 'name')
->label(__('project.labels.counties'))
->inlineLabel()
Expand All @@ -70,18 +86,18 @@ public static function form(Form $form): Form
->hidden(function (callable $get) {
return $get('is_national') === true;
}),
Forms\Components\Select::make('categories')
Select::make('categories')
->relationship('categories', 'name')
->label(__('project.labels.category'))
->inlineLabel()
->columnSpanFull()
->multiple()
->preload()
->required(),
Forms\Components\TextInput::make('name')
TextInput::make('name')
->required()
->maxLength(255),
Forms\Components\TextInput::make('target_budget')
TextInput::make('target_budget')
->required(),
Forms\Components\DatePicker::make('start')
->required(),
Expand Down Expand Up @@ -112,10 +128,10 @@ public static function form(Form $form): Form
->multiple()
->maxFiles(20),
Forms\Components\Repeater::make('videos')->schema([
Forms\Components\TextInput::make('url'),
TextInput::make('url'),
]),
Forms\Components\Repeater::make('external_links')->schema([
Forms\Components\TextInput::make('url'),
TextInput::make('url'),
]),
]);
}
Expand All @@ -130,10 +146,10 @@ public static function table(Table $table): Table
'heroicon-o-clock' => ProjectStatus::rejected->value,
'heroicon-o-check-circle' => ProjectStatus::approved->value,
]),
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('category'),
TextColumn::make('name'),
TextColumn::make('category'),

Tables\Columns\TextColumn::make('created_at')->date(),
TextColumn::make('created_at')->date(),
]);
}

Expand Down Expand Up @@ -186,30 +202,30 @@ public static function getPages(): array
public static function getWidgetColumns(): array
{
return [
Tables\Columns\TextColumn::make('id')
TextColumn::make('id')
->formatStateUsing(function (Project $record) {
return sprintf('#%d', $record->id);
})
->label(__('project.labels.id'))
->sortable(),
Tables\Columns\TextColumn::make('name')->description(fn (Project $record) => $record->organization->name)->searchable(),
Tables\Columns\TextColumn::make('category')->formatStateUsing(fn (Project $record) => $record->categories->pluck('name')->join(', '))
TextColumn::make('name')->description(fn (Project $record) => $record->organization->name)->searchable(),
TextColumn::make('category')->formatStateUsing(fn (Project $record) => $record->categories->pluck('name')->join(', '))
->label(__('project.labels.category')),
Tables\Columns\TextColumn::make('counties')->formatStateUsing(function (Project $record) {
TextColumn::make('counties')->formatStateUsing(function (Project $record) {
if ($record->is_national) {
return __('project.labels.national');
}

return $record->counties->pluck('name')->join(', ');
})
->label(__('project.labels.counties')),
Tables\Columns\TextColumn::make('target_budget')->formatStateUsing(function (Project $record) {
TextColumn::make('target_budget')->formatStateUsing(function (Project $record) {
return number_format($record->target_budget, 2, ',', '.');
})
->label(__('project.labels.target_budget')),
Tables\Columns\TextColumn::make('status_updated_at')->date('d-m-Y H:i:s')
TextColumn::make('status_updated_at')->date('d-m-Y H:i:s')
->label(__('project.labels.status_updated_at')),
Tables\Columns\TextColumn::make('created_at')->date('d-m-Y H:i:s')
TextColumn::make('created_at')->date('d-m-Y H:i:s')
->label(__('project.labels.created_at')),
];
}
Expand Down
60 changes: 58 additions & 2 deletions app/Filament/Resources/ProjectResource/Widgets/ApprovedProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Enums\ProjectStatus;
use App\Models\Project;
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\BadgeColumn;
use Filament\Tables\Columns\TextColumn;
use Illuminate\Database\Eloquent\Builder;

class ApprovedProject extends BaseProjectWidget
Expand All @@ -15,12 +17,24 @@ class ApprovedProject extends BaseProjectWidget

protected function getTableHeading(): string
{
return __('project.heading.approved',['number' => $this->getTableQuery()->count()]);
return __('project.heading.approved', ['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'])->whereIsApproved();
return Project::query()->select([
'id',
'organization_id',
'name',
'target_budget',
'is_national',
'created_at',
'status_updated_at',
'archived_at',
'start',
'end',
'status',
])->whereIsApproved();
}

protected function getTableQueryStringIdentifier(): ?string
Expand Down Expand Up @@ -63,4 +77,46 @@ protected function getTableActions(): array
->icon(null),
];
}

protected function getTableColumns(): array
{
return [
TextColumn::make('id')
->formatStateUsing(function (Project $record) {
return sprintf('#%d', $record->id);
})
->label(__('project.labels.id'))
->sortable(),
BadgeColumn::make('visible_status')
->label('status')
->colors(
[
'primary' => 'published',
'success' => 'open',
'warning' => 'starting_soon',
'info' => 'archived',
'danger' => 'close',
]
)->sortable(),
TextColumn::make('name')->description(fn (Project $record) => $record->organization->name)->searchable(),
TextColumn::make('category')->formatStateUsing(fn (Project $record) => $record->categories->pluck('name')->join(', '))
->label(__('project.labels.category')),
TextColumn::make('counties')->formatStateUsing(function (Project $record) {
if ($record->is_national) {
return __('project.labels.national');
}

return $record->counties->pluck('name')->join(', ');
})
->label(__('project.labels.counties')),
TextColumn::make('target_budget')->formatStateUsing(function (Project $record) {
return number_format($record->target_budget, 2, ',', '.');
})
->label(__('project.labels.target_budget')),
TextColumn::make('status_updated_at')->date('d-m-Y H:i:s')
->label(__('project.labels.status_updated_at')),
TextColumn::make('created_at')->date('d-m-Y H:i:s')
->label(__('project.labels.created_at')),
];
}
}
5 changes: 5 additions & 0 deletions app/Models/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ public function scopeWhereDoesntHaveDonations(Builder $query): Builder
return $query->whereDoesntHave('projects.donations');
}

public function EuPlatescIsActive(): bool
{
return $this->eu_platesc_merchant_id !== null && $this->eu_platesc_private_key !== null;
}

public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
Expand Down
20 changes: 20 additions & 0 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,24 @@ public function getIsEndingSoonAttribute(): bool

return $this->end->diffInDays(today()) <= 5;
}

public function getVisibleStatusAttribute(): string
{
if ($this->isStartingSoon()) {
return 'starting_soon';
}
if ($this->isOpen()) {
return 'open';
}
if ($this->isClose())
{
return 'close';
}
if ($this->isArchived()) {
return 'archived';
}

return $this->status->value;

}
}
36 changes: 36 additions & 0 deletions app/Traits/HasProjectStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@ public function isRejected(): bool
return $this->status === ProjectStatus::rejected;
}

public function isDraft(): bool
{
return $this->status === ProjectStatus::draft;
}

public function isPublished(): bool
{
return $this->isApproved() && $this->archived_at === null;
}

public function isOpen(): bool
{
return $this->isPublished() && $this->start->isPast() && $this->end->isFuture();
}

public function isArchived(): bool
{
return $this->isApproved() && ! empty($this->archived_at);
}

public function isStartingSoon(): bool
{
return $this->isPublished() && ($this->start->isFuture() || ! $this->organization->EuPlatescIsActive());
}

public function isClose(): bool
{
return $this->isPublished() && $this->end->isPast();
}

public function scopeWhereIsPending(Builder $query): Builder
{
return $query->where('status', ProjectStatus::pending);
Expand Down Expand Up @@ -61,6 +91,12 @@ public function scopeWhereStartsSoon(Builder $query): Builder
{
return $query->whereIsPublished()
->whereDate('start', '>=', now())
->orWhere(
fn (Builder $query) => $query->whereHas(
'organization',
fn (Builder $query) => $query->whereDoesntHaveEuPlatesc()
)
)
->orderBy('start');
}

Expand Down
19 changes: 14 additions & 5 deletions lang/ro/project.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
'category' => 'Categorie',
'counties' => 'Județe',
'created_from' => 'Creată de la',
'status_updated_at_from' => 'Trimis spre apr. de la',
'status_updated_at_from' => 'Status schimbat de la',
'created_until' => 'Creată până la',
'status_updated_at_until' => 'Trimis spre apr. pana la',
'status_updated_at_until' => 'Status schimbat pana la',
],
'status_arr' => [
'draft' => 'Draft',
'pending' => 'În așteptare',
'active' => 'Activă',
'disabled' => 'Inactivă',
'approved' => 'Aprobat',
'rejected' => 'Dezactivat',
],
'actions' => [
'view' => 'Vezi',
Expand Down Expand Up @@ -66,9 +66,18 @@
'accepting_comments' => 'Acceptă comentarii',
'videos' => 'Video-uri',
'external_links' => 'Link-uri externe',
'status_updated_at' => 'Trimis spre apr.',
'status_updated_at' => 'Status schimbat la data',
'preview_image' => 'Imagine de prezentare',
'gallery' => 'Galerie',
'visible_status' => 'Status in platforma public',

],
'visible_status'=>[
'published' => 'Publicat',
'archived' => 'Arhivat',
'open' => 'Deschis',
'close' => 'Închis',
'starting_soon' => 'Începe în curând',
]

];

0 comments on commit cbc55f1

Please sign in to comment.