Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Nov 7, 2024
1 parent a449be1 commit 0ed282f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
20 changes: 17 additions & 3 deletions app/Filament/Imports/PointImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Get;
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\ValidationException;
use MatanYadaev\EloquentSpatial\Objects\Point as PointObject;

Expand Down Expand Up @@ -61,12 +62,14 @@ public static function getColumns(): array
->example('București')
->label(__('map_points.county'))
->validationAttribute('county')
->fillRecordUsing(function (Point $record, string $state) {
$city = City::search($state)->where('county', $state)->first();
->fillRecordUsing(function (Point $record, string $state, Get $get) {
$city = City::search()
->where('county', $state)
->first();
if (! $city) {
throw ValidationException::withMessages(
[
'county' => __('validation.county_city_exists'),
'county' => __('validation.county'),
]
);
}
Expand Down Expand Up @@ -169,6 +172,17 @@ public function getJobRetryUntil(): ?CarbonInterface

public function resolveRecord(): ?Point
{
Validator::make(
['latitude' => $this->data['latitude'], 'longitude' => $this->data['longitude']],
[
'latitude' => ['required', 'regex:^\d{2}\.\d{5}\d*^'],
'longitude' => ['required', 'regex:^\d{2}\.\d{5}\d*^'],
],
[
'latitude.regex' => __('validation.regex_valid_latitude'),
'longitude.regex' => __('validation.regex_valid_longitude'),
]
)->validate();
$this->data['location'] = new PointObject((float) $this->data['latitude'], (float) $this->data['longitude']);
unset($this->data['latitude'], $this->data['longitude']);

Expand Down
4 changes: 3 additions & 1 deletion lang/ro/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
'ends_with' => 'Câmpul :attribute trebuie să se încheie cu una din următoarele valori: :values',
'enum' => 'Câmpul :attribute selectat nu este valid.',
'exists' => 'Câmpul :attribute selectat nu este valid.',
'county_city_exists' => 'Nu am putut găsi județul sau localitatea introduse.',
'county' => 'Nu am putut găsi județul introdus.',
'file' => 'Câmpul :attribute trebuie să fie un fișier.',
'filled' => 'Câmpul :attribute trebuie completat.',
'gt' => [
Expand Down Expand Up @@ -117,6 +117,8 @@
'prohibited_unless' => 'Câmpul :attribute este interzis, cu excepția cazului în care :other este în :values.',
'prohibits' => 'Câmpul :attribute nu permite ca :other să fie prezent.',
'regex' => 'Câmpul :attribute nu are un format valid.',
'regex_valid_latitude' => 'Campul latitudine nu are o forma valida.',
'regex_valid_longitude' => 'Campul longitudine nu are o forma valida.',
'required' => 'Câmpul este obligatoriu.',
'required_array_keys' => 'Câmpul :attribute trebuie să conțină valori pentru: :values.',
'required_if' => 'Câmpul :attribute este necesar când :other este :value.',
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Layouts/MapLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<LControlScale position="bottomleft" :imperial="false" />

<LTileLayer
url="https://{s}.basemaps.cartocdn.com/rastertiles/voyager_labels_under/{z}/{x}/{y}{r}.png"
url="https://{s}.basemaps.cartocdn.com/rastertiles/voyager/{z}/{x}/{y}{r}.png"
layer-type="base"
subdomains="abcd"
name="OpenStreetMap"
Expand Down

0 comments on commit 0ed282f

Please sign in to comment.