Skip to content

Commit

Permalink
fix edit map point
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Sep 16, 2024
1 parent 62147e7 commit acbf777
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
42 changes: 28 additions & 14 deletions app/Filament/Imports/PointImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,23 @@ public static function getColumns(): array
ImportColumn::make('latitude')
->label(__('map_points.fields.latitude'))
->example('27.9506')
->rules(
[
'required',
'string',
]
)
->requiredMapping(),

ImportColumn::make('longitude')
->label(__('map_points.fields.longitude'))
->example('27.9506')
->rules(
[
'required',
'string',
]
)
->requiredMapping(),

ImportColumn::make('pointType')
Expand Down Expand Up @@ -65,26 +77,28 @@ public static function getColumns(): array
ImportColumn::make('city_id')
->label(__('map_points.city'))
->example('Sector 2')
->fillRecordUsing(
function (Point $record, string $state) {
$cityId = City::search($state)->where('county', $record->county->name)->first()?->id ?? 0;
if ($cityId !== 0) {
$record->city_id = $cityId;
}
->fillRecordUsing(function (Point $record, string $state) {
$cityId = City::search($state)->where('county', $record->county->name)->first()?->id ?? 0;
if ($cityId !== 0) {
$record->city_id = $cityId;
}
)
})
->requiredMapping()
->rules(
[
'required',
'string',
]
),
->rules([
'required',
'string',
]),

ImportColumn::make('address')
->requiredMapping()
->label(__('map_points.fields.address'))
->example('Strada Ștefan cel Mare 1')
->rules(
[
'required',
'string',
]
)
->ignoreBlankState(),

ImportColumn::make('notes')
Expand Down Expand Up @@ -203,7 +217,7 @@ public function saveRecord(): void
$this->checkDefaultFields();

parent::saveRecord(); // TODO: Change the autogenerated stub
if (!empty($this->options['import_materials'])) {
if (! empty($this->options['import_materials'])) {
collect($materials)->each(function ($material) {
$this->record->materials()->attach(Material::search($material)->first());
});
Expand Down
14 changes: 13 additions & 1 deletion app/Filament/Resources/PointResource/Pages/ViewMapPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ public function infolist(Infolist $infolist): Infolist
TextEntry::make('notes')
->icon('heroicon-s-pencil-square')
->label(__('map_points.fields.notes')),

TextEntry::make('observations')
->icon('heroicon-s-pencil-square')
->label(__('map_points.fields.observations')),
]
)
->headerActions(
Expand All @@ -145,6 +149,8 @@ public function infolist(Infolist $infolist): Infolist
->hiddenLabel(),
Textarea::make('notes')
->label(__('map_points.fields.notes')),
Textarea::make('observations')
->label(__('map_points.fields.observations')),

]
)->action(function (array $data, $livewire) {
Expand All @@ -167,7 +173,12 @@ public function infolist(Infolist $infolist): Infolist
$this->refreshFormData([
'address', 'notes', 'location',
]);
}),
})->fillForm([
'location' => ['lat' => $this->record->location->latitude, 'lng' => $this->record->location->longitude],
'nominatim_autocomplete' => $this->record->address,
'notes' => $this->record->notes,
'observations' => $this->record->observations,
]),
]
)->columnSpan(3),

Expand All @@ -176,6 +187,7 @@ public function infolist(Infolist $infolist): Infolist
->state(fn ($record) => ['lat' => $record?->location->latitude, 'lng' => $record?->location->longitude])
->draggable(false)
->zoom(18)
->extraAttributes(['class'=>'h-full'])
->columnSpan(9),

Section::make(__('map_points.sections.details'))
Expand Down

0 comments on commit acbf777

Please sign in to comment.