From 29863d907482d9d92ee7485898ff5a6318944e37 Mon Sep 17 00:00:00 2001 From: Lupu Gheorghe Date: Thu, 7 Nov 2024 15:07:50 +0200 Subject: [PATCH] wip --- .../PointResource/Actions/Page/AddPoint.php | 2 +- .../PointResource/Pages/ViewMapPoint.php | 37 +++++------------ .../Widgets/PointFromProximity.php | 40 +++++++++++++++++++ app/Models/Point.php | 1 + lang/ro/map_points.php | 2 + 5 files changed, 53 insertions(+), 29 deletions(-) create mode 100644 app/Filament/Resources/PointResource/Widgets/PointFromProximity.php diff --git a/app/Filament/Resources/PointResource/Actions/Page/AddPoint.php b/app/Filament/Resources/PointResource/Actions/Page/AddPoint.php index 87f716ac..8e6fd25d 100644 --- a/app/Filament/Resources/PointResource/Actions/Page/AddPoint.php +++ b/app/Filament/Resources/PointResource/Actions/Page/AddPoint.php @@ -145,7 +145,6 @@ protected function setUp(): void 'location' => new PointObject($data['location']['lat'], $data['location']['lng']), 'county_id' => $data['county_id'], 'city_id' => $data['city_id'], - 'status' => Status::VERIFIED, 'address' => $data['address'], 'business_name' => $data['business_name'] ?? null, 'administered_by' => $data['administered_by'] ?? null, @@ -155,6 +154,7 @@ protected function setUp(): void 'offers_vouchers' => $data['offers_vouchers'] ?? null, 'free_of_charge' => $data['free_of_charge'] ?? null, 'website' => $data['website'] ?? null, + 'verified_at' => now(), 'email' => $data['email'] ?? null, 'phone' => $data['phone'] ?? null, ]); diff --git a/app/Filament/Resources/PointResource/Pages/ViewMapPoint.php b/app/Filament/Resources/PointResource/Pages/ViewMapPoint.php index d2614963..942ff594 100644 --- a/app/Filament/Resources/PointResource/Pages/ViewMapPoint.php +++ b/app/Filament/Resources/PointResource/Pages/ViewMapPoint.php @@ -120,8 +120,12 @@ public function infolist(Infolist $infolist): Infolist Section::make(__('map_points.sections.location')) ->schema( [ + TextEntry::make('address') ->icon('heroicon-s-map-pin') + ->formatStateUsing(function (string $state, $record) { + return \sprintf('%s, %s, %s', $record->address, $record->city->name, $record->county->name); + }) ->label(__('map_points.fields.address')), TextEntry::make('location') @@ -334,37 +338,14 @@ public function infolist(Infolist $infolist): Infolist )->columns(12); } - public function table(Table $table): Table + protected function getFooterWidgets(): array { - return $table - ->query(ActionLogModel::whereModel(\get_class($this->getRecord()))->whereModelId($this->getRecord()->id)->orderBy('created_at', 'desc')) - ->columns([ - TextColumn::make('user.name') - ->formatStateUsing(function (string $state, $record) { - }) - ->html(), - TextColumn::make('action') - ->formatStateUsing(function (string $state, $record) { - return trans('actions.' . $record->action); - }) - ->html(), - TextColumn::make('old_values') - ->formatStateUsing(function (string $state, $record) { - return ActionLogModel::formatValuesText($record, 'old_values'); - }) - ->wrap() - ->html(), - TextColumn::make('new_values') - ->formatStateUsing(function (string $state, $record) { - return ActionLogModel::formatValuesText($record, 'new_values'); - }) - ->wrap() - ->html(), - TextColumn::make('created_at'), - - ]); + return [ + PointResource\Widgets\PointFromProximity::class + ]; } + private function showField(string $string): bool { if ($this->record->serviceType === null) { diff --git a/app/Filament/Resources/PointResource/Widgets/PointFromProximity.php b/app/Filament/Resources/PointResource/Widgets/PointFromProximity.php new file mode 100644 index 00000000..1add727c --- /dev/null +++ b/app/Filament/Resources/PointResource/Widgets/PointFromProximity.php @@ -0,0 +1,40 @@ +query( + Point::query() + ->withCount('problems') + ->where('administered_by', $this->record->administered_by) + ->where('id', '!=', $this->record->id) + ->where('point_type_id', $this->record->point_type_id) + ->where('city_id', $this->record->city_id) + ->where('county_id', $this->record->county_id) + ->where('service_type_id', $this->record->service_type_id) + ->withDistanceSphere('location', $this->record->location) + ->whereDistance('location', $this->record->location, '<', 100) + ) + ->heading(__('map_points.proximity_points')) + ->columns([TextColumn::make('distance')->label(__('map_points.distance')), ...PointResource::getColumns()]); + } +} diff --git a/app/Models/Point.php b/app/Models/Point.php index 89b8617a..4882d4fe 100644 --- a/app/Models/Point.php +++ b/app/Models/Point.php @@ -328,4 +328,5 @@ public function status(): Attribute return Status::VERIFIED; }); } + } diff --git a/lang/ro/map_points.php b/lang/ro/map_points.php index 83532b35..03c10ab8 100644 --- a/lang/ro/map_points.php +++ b/lang/ro/map_points.php @@ -31,6 +31,8 @@ 'point_save_success' => 'Punct salvat cu succes', 'import_materials' => 'Importa materiale', 'use_default_values' => 'Foloseste valorile implicite', + 'proximity_points' => 'Puncte in apropiere care au accealeasi caracteristici', + 'distance' => 'Distanță', 'subheading' => ':serviceType :pointType administrat de :administeredBy alocat la grup :group',