Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andreiio committed Oct 21, 2024
1 parent 8ee8805 commit f1bf3b1
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 16 deletions.
15 changes: 0 additions & 15 deletions app/Filament/Resources/CountryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,11 @@ public static function table(Table $table): Table
->searchable()
->sortable(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
Expand Down
65 changes: 65 additions & 0 deletions app/Filament/Resources/CountyResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources;

use App\Filament\Resources\CountyResource\Pages;
use App\Models\County;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

class CountyResource extends Resource
{
protected static ?string $model = County::class;

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

protected static bool $isScopedToTenant = false;

public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('id')
->label(__('admin.field.siruta'))
->unique(ignoreRecord: true)
->required(),

TextInput::make('name')
->label(__('admin.field.name'))
->required(),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('id')
->label(__('admin.field.siruta'))
->sortable()
->shrink(),

TextColumn::make('name')
->label(__('admin.field.name'))
->searchable()
->sortable(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
]);
}

public static function getPages(): array
{
return [
'index' => Pages\ManageCounties::route('/'),
];
}
}
21 changes: 21 additions & 0 deletions app/Filament/Resources/CountyResource/Pages/ManageCounties.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\CountyResource\Pages;

use App\Filament\Resources\CountyResource;
use Filament\Actions;
use Filament\Resources\Pages\ManageRecords;

class ManageCounties extends ManageRecords
{
protected static string $resource = CountyResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
103 changes: 103 additions & 0 deletions app/Filament/Resources/LocalityResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources;

use App\Filament\Resources\LocalityResource\Pages;
use App\Models\Locality;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Table;

class LocalityResource extends Resource
{
protected static ?string $model = Locality::class;

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

protected static bool $isScopedToTenant = false;

public static function form(Form $form): Form
{
return $form
->schema([
Select::make('county_id')
->relationship('county', 'name')
->required(),

TextInput::make('level')
->required()
->numeric(),

TextInput::make('type')
->required()
->numeric(),

TextInput::make('parent_id')
->numeric(),

TextInput::make('name')
->required()
->maxLength(255),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('id')
->label(__('admin.field.siruta'))
->sortable(),

TextColumn::make('name')
->label(__('admin.field.name'))
->searchable()
->sortable(),

TextColumn::make('level')
->numeric()
->sortable(),

TextColumn::make('type')
->numeric()
->sortable(),

TextColumn::make('parent.name')
->sortable(),

TextColumn::make('county.name')
->label(__('admin.field.county'))
->searchable()
->sortable(),

])
->filters([
SelectFilter::make('county')
->relationship('county', 'name')
->label(__('admin.field.county')),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}

public static function getPages(): array
{
return [
'index' => Pages\ManageLocalities::route('/'),
];
}
}
21 changes: 21 additions & 0 deletions app/Filament/Resources/LocalityResource/Pages/ManageLocalities.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace App\Filament\Resources\LocalityResource\Pages;

use App\Filament\Resources\LocalityResource;
use Filament\Actions;
use Filament\Resources\Pages\ManageRecords;

class ManageLocalities extends ManageRecords
{
protected static string $resource = LocalityResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
5 changes: 5 additions & 0 deletions app/Models/Locality.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public function county(): BelongsTo
return $this->belongsTo(County::class);
}

public function parent(): BelongsTo
{
return $this->belongsTo(static::class, 'parent_id');
}

protected function getNameWithCountyAttribute(): string
{
return "{$this->name}, {$this->county->name}";
Expand Down
2 changes: 1 addition & 1 deletion database/data/siruta.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16963,7 +16963,7 @@ INSERT INTO `localities` (`id`, `county_id`, `level`, `type`, `parent_id`, `name
(178947, 396, 2, 3, NULL, 'Obrejița'),
(178956, 396, 2, 3, NULL, 'Răstoaca'),
(178965, 396, 2, 3, NULL, 'Spulber'),
(179132, 403, 2, 9, NULL, 'Municipiul'),
(179132, 403, 2, 9, NULL, 'Municipiul București'),
(179141, 403, 3, 6, 179132, 'Sectorul 1'),
(179150, 403, 3, 6, 179132, 'Sectorul 2'),
(179169, 403, 3, 6, 179132, 'Sectorul 3'),
Expand Down
1 change: 1 addition & 0 deletions lang/ro/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'date' => 'Dată',
'email' => 'Email',
'id' => 'ID',
'siruta' => 'ID SIRUTA',
'initial_complement' => 'Înscriși pe listele complementare',
'initial_permanent' => 'Înscriși pe listele permanente',
'is_live' => 'Live',
Expand Down
7 changes: 7 additions & 0 deletions lang/ro/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
],
],

'election_type' => [
'label' => [
'singular' => 'tip alegeri',
'plural' => 'tipuri alegeri',
],
],

'party' => [
'label' => [
'singular' => 'partid',
Expand Down

0 comments on commit f1bf3b1

Please sign in to comment.