Skip to content

Commit

Permalink
refactor (#31)
Browse files Browse the repository at this point in the history
* refactor locale middleware

* simplify build

* refactor colors

* refactor intervention domains

* refactor icons

* refactor home page

* refactor routes

* refactor ngos

* refactor services

* refactor pages

* refactor header

* wip

* wip

* wip

* wip
  • Loading branch information
andreiio authored Aug 24, 2023
1 parent 4da587b commit 20a0253
Show file tree
Hide file tree
Showing 97 changed files with 1,327 additions and 1,313 deletions.
16 changes: 16 additions & 0 deletions app/Concerns/BelongsToInterventionDomains.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace App\Concerns;

use App\Models\InterventionDomain;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

trait BelongsToInterventionDomains
{
public function interventionDomains(): BelongsToMany
{
return $this->belongsToMany(InterventionDomain::class);
}
}
22 changes: 0 additions & 22 deletions app/Concerns/ClearsResponseCache.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,43 @@

namespace App\Filament\Resources;

use App\Filament\Resources\InterventionDomainsResource\Pages;
use App\Models\InterventionDomains;
use Closure;
use App\Filament\Resources\InterventionDomainResource\Pages;
use App\Models\InterventionDomain;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Concerns\Translatable;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Illuminate\Support\Str;

class InterventionDomainsResource extends Resource
class InterventionDomainResource extends Resource
{
use Translatable;

protected static ?string $model = InterventionDomains::class;
protected static ?string $model = InterventionDomain::class;

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

public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')->afterStateUpdated(function (Closure $set, $state) {
$set('slug', Str::slug($state));
})->reactive(),
TextInput::make('slug')->disabled(),
TextInput::make('name'),

Select::make('icon')
->options([
'health' => 'health',
'food' => 'food',
'house' => 'house',
'hygiene' => 'hygiene',
'finance_support' => 'finance_support',
'protection' => 'protection',
'education' => 'education',
'management' => 'management',
'integration' => 'integration',
]),
]);
}

Expand All @@ -40,7 +49,7 @@ public static function table(Table $table): Table
return $table
->columns([
TextColumn::make('name'),

TextColumn::make('icon'),
])
->filters([
//
Expand All @@ -64,8 +73,8 @@ public static function getPages(): array
{
return [
'index' => Pages\ListInterventionDomains::route('/'),
'create' => Pages\CreateInterventionDomains::route('/create'),
'edit' => Pages\EditInterventionDomains::route('/{record}/edit'),
'create' => Pages\CreateInterventionDomain::route('/create'),
'edit' => Pages\EditInterventionDomain::route('/{record}/edit'),
];
}

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

declare(strict_types=1);

namespace App\Filament\Resources\InterventionDomainResource\Pages;

use App\Filament\Base\CreateRecord;
use App\Filament\Resources\InterventionDomainResource;

class CreateInterventionDomain extends CreateRecord
{
protected static string $resource = InterventionDomainResource::class;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\InterventionDomainResource\Pages;

use App\Filament\Base\EditRecord;
use App\Filament\Resources\InterventionDomainResource;

class EditInterventionDomain extends EditRecord
{
protected static string $resource = InterventionDomainResource::class;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

declare(strict_types=1);

namespace App\Filament\Resources\InterventionDomainsResource\Pages;
namespace App\Filament\Resources\InterventionDomainResource\Pages;

use App\Filament\Resources\InterventionDomainsResource;
use App\Filament\Resources\InterventionDomainResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ListRecords;

class ListInterventionDomains extends ListRecords
{
protected static string $resource = InterventionDomainsResource::class;
protected static string $resource = InterventionDomainResource::class;

protected function getActions(): array
{
Expand Down

This file was deleted.

This file was deleted.

107 changes: 73 additions & 34 deletions app/Filament/Resources/ServiceResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

use App\Enums\ServiceApplicationType;
use App\Filament\Resources\ServiceResource\Pages;
use App\Models\BeneficiaryGroup;
use App\Models\County;
use App\Models\InterventionDomains;
use App\Models\Service;
use Closure;
use Filament\Forms;
use Filament\Forms\Components\Card;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Resources\Concerns\Translatable;
Expand All @@ -34,38 +33,37 @@ class ServiceResource extends Resource

public static function form(Form $form): Form
{
$beneficiaryGroup = BeneficiaryGroup::pluck('name', 'id');

$interventionDomains = InterventionDomains::pluck('name', 'id');

return $form
->schema([

Card::make()
->columnSpan(2)
->columns(2)
->schema([
TextInput::make('name')->required()
->afterStateUpdated(function (Closure $set, $state) {
$set('slug', Str::slug($state));
})->reactive(),
TextInput::make('slug')->disabled(),
TextInput::make('name')
->required()
->afterStateUpdated(fn (Closure $set, $state) => $set('slug', Str::slug($state)))
->reactive(),

TextInput::make('project_name')->required(),
TextInput::make('slug')
->disabled(),

TextInput::make('project_name')
->required(),

Select::make('ngo_id')->relationship('ngo', 'name')
->searchable()
->preload()
->required(),
Forms\Components\Select::make('county_id')

Select::make('county_id')
->label('County')
->options(County::pluck('name', 'id'))
->required()
->reactive()
->searchable()
->afterStateUpdated(fn (callable $set) => $set('city_id', null)),

Forms\Components\Select::make('city_id')
Select::make('city_id')
->label('City')
->required()
->options(
Expand All @@ -75,35 +73,76 @@ public static function form(Form $form): Form
)
->searchable()
->reactive(),
Forms\Components\Grid::make()->schema([
TextInput::make('duration')->required(),
Select::make('status')->options(['active' => 'În derulare/Activ', 'finished' => 'Finalizat'])->required(),
TextInput::make('budget')->required(),
])->columns(3),

Forms\Components\TextInput::make('lat')
Grid::make()
->columns(3)
->schema([
TextInput::make('duration')
->required(),

Select::make('status')
->options([
'active' => 'În derulare/Activ',
'finished' => 'Finalizat',
])
->required(),

TextInput::make('budget')
->required(),
]),

TextInput::make('lat')
->numeric()
->minValue(-90)
->maxValue(90)
->required(),
Forms\Components\TextInput::make('lng')

TextInput::make('lng')
->numeric()
->minValue(-180)
->maxValue(180)
->required(),
Select::make('intervention_domains')->relationship('interventionDomain','name')->multiple()->required(),
Select::make('beneficiary_groups')->relationship('beneficiaryGroup','name')->multiple()->required(),

Select::make('intervention_domains')
->relationship('interventionDomains', 'name')
->multiple()
->required(),

Select::make('beneficiary_groups')
->relationship('beneficiaryGroups', 'name')
->multiple()
->required(),
]),
Card::make()
->columns(2)
->schema([
Repeater::make('application_methods')
->columnSpan(2)
->schema([
Select::make('type')
->options(ServiceApplicationType::selectable())
->reactive()
->required(),

TextInput::make('application_url')
->url()
->hidden(fn (Closure $get) => $get('type') !== ServiceApplicationType::Online->value)
->required(),

TextInput::make('application_phone')
->hidden(fn (Closure $get) => $get('type') !== ServiceApplicationType::Phone->value)
->requiredWithout('application_email'),

TextInput::make('application_email')
->email()
->hidden(fn (Closure $get) => $get('type') !== ServiceApplicationType::Phone->value)
->requiredWithout('application_phone'),

TextInput::make('application_address')
->hidden(fn (Closure $get) => $get('type') !== ServiceApplicationType::Physical->value)
->required(),
]),
]),
Card::make()->columns(2)->schema([
Forms\Components\Repeater::make('application_methods')->columnSpan(2)->schema([
Select::make('type')->options(ServiceApplicationType::selectable())->reactive()->required(),
TextInput::make('application_url')->url()->hidden(fn (Closure $get) => $get('type') !== ServiceApplicationType::Online->value)->required(),
TextInput::make('application_phone')->hidden(fn (Closure $get) => $get('type') !== ServiceApplicationType::Phone->value)->required(),
TextInput::make('application_email')->email()->hidden(fn (Closure $get) => $get('type') !== ServiceApplicationType::Phone->value)->required(),
TextInput::make('application_address')->hidden(fn (Closure $get) => $get('type') !== ServiceApplicationType::Physical->value)->required(),
])->defaultItems(0),
]),
]);
}

Expand Down
23 changes: 23 additions & 0 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Models\InterventionDomain;
use App\Models\Ngo;
use App\Models\Service;
use Illuminate\View\View;

class HomeController extends Controller
{
public function __invoke(): View
{
return view('home', [
'services_count' => Service::count(),
'ngos_count' => Ngo::count(),
'beneficiaries_count' => Ngo::sum('number_of_beneficiaries'),
'domains' => InterventionDomain::all(),
]);
}
}
Loading

0 comments on commit 20a0253

Please sign in to comment.