Skip to content

Commit

Permalink
add point proximity in tabel point resource
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Nov 11, 2024
1 parent 2365b9f commit 9fd90aa
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 27 deletions.
18 changes: 9 additions & 9 deletions app/Filament/Resources/ImportResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public static function table(Table $table): Table
->label(__('import.columns.processed'))
->searchable(),
Tables\Columns\TextColumn::make('points_count')
->counts('points')
->label(__('common.points_count')),
->counts('points')
->label(__('common.points_count')),

Tables\Columns\TextColumn::make('error_rows')
->label(__('import.columns.failed')),
Expand Down Expand Up @@ -129,13 +129,13 @@ public static function table(Table $table): Table
->label(__('imports.remove_points'))
->default(false),
])->action(function (Collection $records, array $data) {
$records->each(function (Import $record) use ($data) {
if ($data['remove_points']) {
$record->points()->delete();
}
$record->delete();
});
}),
$records->each(function (Import $record) use ($data) {
if ($data['remove_points']) {
$record->points()->delete();
}
$record->delete();
});
}),
]),
]);
}
Expand Down
9 changes: 7 additions & 2 deletions app/Filament/Resources/PointResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public static function getColumns()
->label(__('map_points.id'))
->sortable()
->searchable(),

TextColumn::make('serviceType.name')
->label(__('map_points.point_type')),

Expand All @@ -223,8 +224,7 @@ public static function getColumns()
TextColumn::make('materials.name')
->label(__('map_points.materials'))
->searchable()
->limitList(2)
->sortable(),
->limitList(2),

TextColumn::make('county.name')
->label(__('map_points.county'))
Expand All @@ -246,6 +246,11 @@ public static function getColumns()
->sortable()
->wrap(),

TextColumn::make('proximity_count')
->badge()
->color(fn ($state) => $state > 0 ? 'warning' : 'success')
->label(__('map_points.proximity_count')),

TextColumn::make('status')
->sortable()
->badge()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace App\Filament\Resources\PointResource\Actions\Page;

use App\Enums\Point\Source;
use App\Enums\Point\Status;
use App\Filament\Forms\Components\LeafletAutocomplete;
use App\Models\MaterialCategory;
use App\Models\Point;
Expand Down
10 changes: 3 additions & 7 deletions app/Filament/Resources/PointResource/Pages/ViewMapPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use App\Enums\Point\Status;
use App\Filament\Forms\Components\LeafletAutocomplete;
use App\Filament\Resources\PointResource;
use App\Models\ActionLog as ActionLogModel;
use App\Models\PointType;
use Dotswan\MapPicker\Infolists\MapEntry;
use Filament\Actions\Action;
Expand All @@ -26,8 +25,6 @@
use Filament\Infolists\Infolist;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\ViewRecord;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\HtmlString;

Expand Down Expand Up @@ -340,12 +337,11 @@ public function infolist(Infolist $infolist): Infolist

protected function getFooterWidgets(): array
{
return [
PointResource\Widgets\PointFromProximity::class
];
return [
PointResource\Widgets\PointFromProximity::class,
];
}


private function showField(string $string): bool
{
if ($this->record->serviceType === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget as BaseWidget;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Contracts\View\View;
use Illuminate\Database\Eloquent\Model;

class PointFromProximity extends BaseWidget
{
public ?Point $record = null;

protected int | string | array $columnSpan='full';
protected int | string | array $columnSpan = 'full';

public function table(Table $table): Table
{
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Resources/RecycleMaterialsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class RecycleMaterialsResource extends Resource

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


public static function getModelLabel(): string
{
return __('materials.singular');
Expand All @@ -35,6 +34,7 @@ public static function getPluralLabel(): string
{
return __('materials.plural');
}

public static function getNavigationGroup(): ?string
{
return __('nav.settings');
Expand Down
1 change: 1 addition & 0 deletions app/Filament/Resources/UserGroupResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static function getModelLabel(): string
{
return __('users.group.singular');
}

public static function getNavigationGroup(): ?string
{
return __('nav.settings');
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class UserResource extends Resource

public static function getNavigationGroup(): ?string
{
return __('nav.settings');
return __('nav.settings');
}

public static function form(Form $form): Form
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Resources/ContributionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function toArray(Request $request): array
(new Point)->getMorphClass() => $this->model,
(new Problem)->getMorphClass() => $this->model->point,
};
if (!$point) {
if (! $point) {
return [];
}

Expand Down
18 changes: 18 additions & 0 deletions app/Models/Point.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ class Point extends Model implements HasMedia
'verified_at' => 'datetime',
];

protected $appends = [
'proximity_count',
];

public function registerMediaCollections(): void
{
$this->addMediaCollection('default')
Expand Down Expand Up @@ -329,4 +333,18 @@ public function status(): Attribute
});
}

public function getProximityCountAttribute(): int
{
return self::query()
->withCount('problems')
->where('administered_by', $this->administered_by)
->where('id', '!=', $this->id)
->where('point_type_id', $this->point_type_id)
->where('city_id', $this->city_id)
->where('county_id', $this->county_id)
->where('service_type_id', $this->service_type_id)
->withDistanceSphere('location', $this->location)
->whereDistance('location', $this->location, '<', 100)
->count();
}
}
1 change: 1 addition & 0 deletions lang/ro/map_points.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
'import_materials' => 'Importa materiale',
'use_default_values' => 'Foloseste valorile implicite',
'proximity_points' => 'Puncte in apropiere care au accealeasi caracteristici',
'proximity_count' => 'Numar puncte posibil duplicate',
'distance' => 'Distanță',

'subheading' => ':serviceType :pointType administrat de :administeredBy alocat la grup :group',
Expand Down
2 changes: 1 addition & 1 deletion lang/ro/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'phone' => 'Telefon',
'password' => 'Parola',
'roles' => 'Roluri',
'contributions_count'=> 'Numar contributii',
'contributions_count' => 'Numar contributii',
'last_login_date' => 'Ultima datǎ de conectare',

];

0 comments on commit 9fd90aa

Please sign in to comment.