Skip to content

Commit

Permalink
Review/admin projects (#297)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* cs-fixer

* cs-fixer
  • Loading branch information
gheorghelupu17 authored Oct 3, 2023
1 parent 659f8ce commit 7f6e96c
Show file tree
Hide file tree
Showing 36 changed files with 406 additions and 404 deletions.
3 changes: 0 additions & 3 deletions app/Enums/ProjectStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ enum ProjectStatus: string

case draft = 'draft';
case pending = 'pending';
case change_request = 'change_request';
case approved = 'approved';
case rejected = 'rejected';
case active = 'active';
case disabled = 'disabled';

protected function labelKeyPrefix(): ?string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use App\Filament\Resources\OrganizationResource\Actions\Pages\DeactivateOrganizationAction;
use App\Filament\Resources\OrganizationResource\Actions\Pages\ReactivateOrganizationAction;
use App\Filament\Resources\OrganizationResource\Actions\Pages\RejectOrganizationAction;
use App\Filament\Resources\OrganizationResource\Widgets\OrganizationActivityWidget;
use Filament\Pages\Actions\EditAction;
use Filament\Resources\Pages\ViewRecord;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\OrganizationResource\RelationManagers;

use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class DonationsRelationManager extends RelationManager
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\OrganizationResource\RelationManagers;

use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class ProjectsRelationManager extends RelationManager
{
Expand All @@ -21,7 +21,6 @@ public static function getTitle(): string
return __('project.label.plural');
}


public static function form(Form $form): Form
{
return $form
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\OrganizationResource\RelationManagers;

use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class TicketsRelationManager extends RelationManager
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\OrganizationResource\RelationManagers;

use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class VolunteersRelationManager extends RelationManager
{
Expand Down
8 changes: 4 additions & 4 deletions app/Filament/Resources/ProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public static function table(Table $table): Table
Tables\Columns\IconColumn::make('status')->options([
'heroicon-o-x-circle',
'heroicon-o-pencil' => ProjectStatus::draft->value,
'heroicon-o-clock' => ProjectStatus::disabled->value,
'heroicon-o-check-circle' => ProjectStatus::active->value,
'heroicon-o-clock' => ProjectStatus::rejected->value,
'heroicon-o-check-circle' => ProjectStatus::approved->value,
]),
Tables\Columns\TextColumn::make('name'),
Tables\Columns\TextColumn::make('category'),
Expand All @@ -131,10 +131,10 @@ public static function getWidgetFilters(): array
Filter::make('created_at')
->form([
Grid::make()->schema([
DatePicker::make('created_at')->label(__('project.filters.created_from'))->columnSpan(1),
DatePicker::make('created_at')->label(__('project.filters.created_from')),
DatePicker::make('created_at')->label(__('project.filters.created_until')),
]),
])->columnSpan(2),
]),
];
}

Expand Down
8 changes: 4 additions & 4 deletions app/Filament/Resources/ProjectResource/Pages/EditProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ protected function getActions(): array
Actions\DeleteAction::make(),
Action::make('Approve')
->action(function () {
$this->record->status = ProjectStatus::active->value;
$this->record->status = ProjectStatus::approved->value;
$this->record->save();
})
->requiresConfirmation()->hidden(fn () => $this->record->status == ProjectStatus::active->value),
->requiresConfirmation()->hidden(fn () => $this->record->status == ProjectStatus::approved->value),
Action::make('Reject')
->action(function () {
$this->record->status = ProjectStatus::disabled->value;
$this->record->status = ProjectStatus::rejected->value;
$this->record->save();
})
->requiresConfirmation()->hidden(fn () => $this->record->status == ProjectStatus::disabled->value),
->requiresConfirmation()->hidden(fn () => $this->record->status == ProjectStatus::rejected->value),
];
}
}
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()->isApproved();
return Project::query()->whereIsApproved();
}

protected function getTableQueryStringIdentifier(): ?string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ protected function getTableFilters(): array
return ProjectResource::getWidgetFilters();
}

protected function getTableFiltersLayout(): ?string
{
return Layout::AboveContent;
}
// protected function getTableFiltersLayout(): ?string
// {
// return Layout::AboveContent;
// }

protected function getTableRecordUrlUsing(): \Closure
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Filament\Resources\ProjectResource;
use App\Models\Project;
use Filament\Tables\Actions\Action;
use Filament\Tables\Actions\ViewAction;
use Illuminate\Database\Eloquent\Builder;

class NewProject extends BaseProjectWidget
Expand All @@ -25,7 +26,7 @@ protected function getTableHeading(): string

protected function getTableQuery(): Builder
{
return Project::query()->isPending();
return Project::query()->whereIsPending();
}

protected function getTableQueryStringIdentifier(): ?string
Expand All @@ -36,6 +37,12 @@ protected function getTableQueryStringIdentifier(): ?string
protected function getTableActions(): array
{
return [

ViewAction::make()
->label(__('project.actions.view'))
->url(fn (Project $record) => route('filament.resources.projects.edit', $record))
->icon(null)
->size('sm'),
Action::make('edit')
->label(__('project.actions.edit'))
->url(self::getTableRecordUrlUsing())
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()->isRejected();
return Project::query()->whereIsRejected();
}

protected function getTableQueryStringIdentifier(): ?string
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/ChampionshipController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class ChampionshipController extends Controller
public function index()
{
$championship = Championship::current()->firstOrFail();
$projects = $championship->activeStage()->projects()->paginate()->withQueryString()->through(fn ($project) =>$project->project);
$projects = $championship->activeStage()->projects()->paginate()->withQueryString()->through(fn ($project) => $project->project);
$projectAmount = $championship->activeStage()->projects()->sum('amount_of_donation');
$projectDonationsNumber = $championship->activeStage()->projects()->sum('number_of_donation');
$counties = County::get(['name', 'id']);
Expand Down Expand Up @@ -141,7 +141,7 @@ public function edition()
],
];

$projects = Project::publish()->paginate(9)->withQueryString();
$projects = Project::whereIsOpen()->paginate(9)->withQueryString();
$counties = County::get(['name', 'id']);

return Inertia::render('Public/Championship/Edition', [
Expand All @@ -162,7 +162,7 @@ public function projects(Request $request)
return auth()->user()?->organization
->projects()
// ->notInChampionship($request->championship_id)
->publish()
->whereIsOpen()
->offset($offset)->limit(8)->get();
}

Expand Down
50 changes: 25 additions & 25 deletions app/Http/Controllers/DonorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,42 +66,42 @@ public function donations()
],
],
'first_page_url' => 'http=>//bursabinelui.test/proiecte?page=1',
'from'=> 1,
'last_page'=> 2,
'last_page_url'=> 'http://bursabinelui.test/proiecte?page=2',
'links'=> [
'from' => 1,
'last_page' => 2,
'last_page_url' => 'http://bursabinelui.test/proiecte?page=2',
'links' => [
[
'url'=> 'http://bursabinelui.test/proiecte?page=1',
'label'=> '1',
'active'=> true,
'url' => 'http://bursabinelui.test/proiecte?page=1',
'label' => '1',
'active' => true,
],
[
'url'=> 'http://bursabinelui.test/proiecte?page=1',
'label'=> '1',
'active'=> true,
'url' => 'http://bursabinelui.test/proiecte?page=1',
'label' => '1',
'active' => true,
],
[
'url'=> 'http://bursabinelui.test/proiecte?page=2',
'label'=> '2',
'active'=> false,
'url' => 'http://bursabinelui.test/proiecte?page=2',
'label' => '2',
'active' => false,
],
[
'url'=> 'http://bursabinelui.test/proiecte?page=3',
'label'=> '3',
'active'=> false,
'url' => 'http://bursabinelui.test/proiecte?page=3',
'label' => '3',
'active' => false,
],
[
'url'=> 'http://bursabinelui.test/proiecte?page=1',
'label'=> '1',
'active'=> true,
'url' => 'http://bursabinelui.test/proiecte?page=1',
'label' => '1',
'active' => true,
],
],
'next_page_url'=> 'http://bursabinelui.test/proiecte?page=3',
'path'=> 'http://bursabinelui.test/proiecte',
'per_page'=> 15,
'prev_page_url'=> 'http://bursabinelui.test/proiecte?page=1',
'to'=> 15,
'total'=> 20,
'next_page_url' => 'http://bursabinelui.test/proiecte?page=3',
'path' => 'http://bursabinelui.test/proiecte',
'per_page' => 15,
'prev_page_url' => 'http://bursabinelui.test/proiecte?page=1',
'to' => 15,
'total' => 20,
];

return Inertia::render('Donor/Donations', [
Expand Down
12 changes: 5 additions & 7 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
namespace App\Http\Controllers;

use App\Http\Resources\Articles\ArticleCardResource;
use App\Http\Resources\BCRProjectCardResource;
use App\Http\Resources\ProjectCardResource;
use App\Models\Article;
use App\Models\Organization;
use App\Models\Project;
Expand All @@ -20,22 +18,22 @@ public function index()

return Inertia::render('Public/Home', [
'projects_count' => Project::query()
->publish()
->whereIsOpen()
->count(),

'organizations_count' => Organization::query()
->isApproved()
->count(),

'projects' => ProjectCardResource::collection(
Project::publish()
'projects' => ProjectCardsResource::collection(
Project::whereIsOpen()
->inRandomOrder()
->limit(12)
->get()
),

'bcr_projects' => BCRProjectCardResource::collection(
Project::publish()
'bcr_projects' => BCRProjectCardsResource::collection(
Project::whereIsOpen()
// TODO: ->whereOrganizationIsBCR()
->limit(12)
->get()
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/OrganizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function show(Organization $organization)
$organization->loadMissing([
'activityDomains',
'counties',
'projects' => fn ($query) => $query->wherePublished(),
'projects' => fn ($query) => $query->whereIsPublished(),
]),
),
]);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function projectList(Request $request, string $view): Response
AllowedSort::custom('donations_total', new ProjectDonationsSumSort),
AllowedSort::custom('donations_count', new ProjectDonationsCountSort),
])
->wherePublished()
->whereIsPublished()
->paginate()
->withQueryString()
),
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/RegionalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function index()
],
];

$projects = Project::publish()->paginate(9)->withQueryString();
$projects = Project::whereIsOpen()->paginate(9)->withQueryString();

$countries = County::get(['name', 'id']);

Expand Down Expand Up @@ -194,7 +194,7 @@ public function edition()
],
];

$projects = Project::publish()->paginate(9)->withQueryString();
$projects = Project::whereIsOpen()->paginate(9)->withQueryString();

return Inertia::render('Public/Regional/Edition', [
'query' => $projects,
Expand Down Expand Up @@ -293,7 +293,7 @@ public function regionalEdition()
'status' => 'in-progress',
];

$projects = Project::publish()->paginate(9)->withQueryString();
$projects = Project::whereIsOpen()->paginate(9)->withQueryString();

return Inertia::render('Public/Regional/Edition', [
'query' => $projects,
Expand Down
1 change: 1 addition & 0 deletions app/Models/ChampionshipStageProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class ChampionshipStageProject extends Model
{
protected $table = 'championship_stage_project';

use HasFactory;

protected $with = ['project'];
Expand Down
Loading

0 comments on commit 7f6e96c

Please sign in to comment.