Skip to content

Commit

Permalink
Merge pull request #49 from mostafaznv/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
mostafaznv authored Mar 17, 2024
2 parents 87e0ce4 + 1606df6 commit 0f0db09
Show file tree
Hide file tree
Showing 24 changed files with 125 additions and 174 deletions.
43 changes: 33 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ Therefore, if you decide to use my packages, please kindly consider making a don
## Requirements:

- PHP 8.0.2 or higher
- Laravel 8 or higher
- Laravel 10.* or higher


## Laravel Compatibility

| Laravel | PHP | Nova Map Field |
|---------------|--------|-----------------------------------------------------------------|
| ^8.0 - ^9.0 | ^8.0.2 | [^3.0](https://github.com/mostafaznv/nova-map-field/tree/3.2.0) |
| ^10.0 - ^11.0 | ^8.1 | ^4.0 (latest) |



## Installation
Expand Down Expand Up @@ -65,17 +74,18 @@ Therefore, if you decide to use my packages, please kindly consider making a don
};
```
2. ##### Add `HasSpatialColumns` trait to model
2. ##### Add `HasSpatial` trait to model
```php
<?php
namespace App\Models;
use Mostafaznv\NovaMapField\Traits\HasSpatialColumns;
use MatanYadaev\EloquentSpatial\Traits\HasSpatial;
class Location extends Model
{
use HasSpatialColumns;
use HasSpatial;
}
```
Expand All @@ -88,10 +98,12 @@ Therefore, if you decide to use my packages, please kindly consider making a don
use MatanYadaev\EloquentSpatial\Objects\MultiPolygon;
use MatanYadaev\EloquentSpatial\Objects\Point;
use MatanYadaev\EloquentSpatial\Objects\Polygon;
use MatanYadaev\EloquentSpatial\Traits\HasSpatial;
class Location extends Model
{
use HasSpatialColumns;
use HasSpatial;
protected $casts = [
'location' => Point::class,
Expand All @@ -111,6 +123,7 @@ Therefore, if you decide to use my packages, please kindly consider making a don
use Mostafaznv\NovaMapField\Fields\MapPointField;
use Mostafaznv\NovaMapField\Fields\MapPolygonField;
class Location extends Resource
{
public function fields(Request $request): array
Expand Down Expand Up @@ -280,9 +293,9 @@ use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use App\Models\Location as Model;
use Mostafaznv\NovaMapField\DTOs\Capture;
use Mostafaznv\NovaMapField\DTOs\MapSearchBoxType;
use Mostafaznv\NovaMapField\DTOs\MapSearchProvider;
use Mostafaznv\NovaMapField\DTOs\PointValue;
use Mostafaznv\NovaMapField\Enums\MapSearchBoxType;
use Mostafaznv\NovaMapField\Enums\MapSearchProvider;
use Mostafaznv\NovaMapField\Fields\MapPointField;
class Location extends Resource
Expand Down Expand Up @@ -312,14 +325,14 @@ class Location extends Resource
->mapHeight(360)
->hideDetailButton(false)
->markerIcon(3)
->searchProvider(MapSearchProvider::OSM())
->searchProvider(MapSearchProvider::OSM)
->searchProviderApiKey('api-key')
->withAutocompleteSearch()
->searchAutocompleteMinLength(4)
->searchAutocompleteTimeout(500)
->searchLanguage('fa-IR')
->searchPlaceholder('Placeholder ...')
->searchBoxType(MapSearchBoxType::BUTTON())
->searchBoxType(MapSearchBoxType::BUTTON)
->searchResultLimit(3)
->searchResultKeepOpen(true)
->withTransformation()
Expand All @@ -345,9 +358,19 @@ class Location extends Resource
];
}
}
```
----
## Migration
#### From 3.* to 4.*
- Support for `matanyadaev/laravel-eloquent-spatial` versions 2 and 3 has been dropped. The package now exclusively supports version 4 and higher.
- The `HasSpatialColumns` trait has been removed from the package. Instead, use the `HasSpatial` trait from the laravel-eloquent-spatial package.
- Both `MapSearchBoxType` and `MapSearchProvider` custom enums have been refactored and are now located in the `Mostafaznv\NovaMapField\Enums` namespace, utilizing PHP 8.1 enums. This update affects:
- The `searchBoxType` and `searchProvider` methods across all map field types (MapPointField, MapPolygonField, MapMultiPolygonField)
- The configuration file properties `search.box-type` and `search.provider`.
----
I am on an open-source journey 🚀, and I wish I could solely focus on my development path without worrying about my financial situation. However, as life is not perfect, I have to consider other factors.
Expand Down
11 changes: 9 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
],
"license": "MIT",
"require": {
"illuminate/support": "^8.0|^9.0|^10.0",
"php": "^8.1",
"illuminate/support": "^10.0|^11.0",
"laravel/nova": "^4.0",
"matanyadaev/laravel-eloquent-spatial": "^2.0.1|^3.0"
"matanyadaev/laravel-eloquent-spatial": "^4.2"
},
"autoload": {
"psr-4": {
Expand All @@ -31,6 +32,12 @@
]
}
},
"repositories": [
{
"type": "composer",
"url": "https://nova.laravel.com"
}
],
"config": {
"sort-packages": true
},
Expand Down
7 changes: 5 additions & 2 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

use Mostafaznv\NovaMapField\Enums\MapSearchBoxType;
use Mostafaznv\NovaMapField\Enums\MapSearchProvider;

return [
/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -219,7 +222,7 @@
|
*/

'provider' => \Mostafaznv\NovaMapField\DTOs\MapSearchProvider::OSM(),
'provider' => MapSearchProvider::OSM,

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -297,7 +300,7 @@
|
*/

'box-type' => \Mostafaznv\NovaMapField\DTOs\MapSearchBoxType::TEXT_FIELD(),
'box-type' => MapSearchBoxType::TEXT_FIELD,

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion dist/field.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/field.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* Copyright 2015-2021 Esri. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 @preserve */

/*!
* ol-contextmenu - v5.3.0
* ol-contextmenu - v5.4.0
* https://github.com/jonataswalker/ol-contextmenu
* Built: Fri Sep 22 2023 13:13:39 GMT-0300 (Brasilia Standard Time)
* Built: Fri Mar 08 2024 12:11:47 GMT+0000 (Coordinated Universal Time)
*/

/*!
Expand Down
2 changes: 1 addition & 1 deletion dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"/field.css": "/field.css?id=0b29f4e7358b74e4b94d6e9a649b58e6",
"/field.js": "/field.js?id=f64606caf6305ae78dc87eab0dcfa0a9",
"/field.js": "/field.js?id=e13aa350bf44aed5ced533c60094dc8e",
"/vendor/nova-map-field/dist/images/ic-pin-1.png": "/vendor/nova-map-field/dist/images/ic-pin-1.png?id=400bb8273d9fe0a31d86e144ef534856",
"/vendor/nova-map-field/dist/images/ic-pin-2.png": "/vendor/nova-map-field/dist/images/ic-pin-2.png?id=e084fdbb00a78f7e6d53819e518e64ec",
"/vendor/nova-map-field/dist/images/ic-pin-3.png": "/vendor/nova-map-field/dist/images/ic-pin-3.png?id=19780e69e0b6125989e3209759e51997"
Expand Down
1 change: 1 addition & 0 deletions src/DTOs/Capture.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static function make(string $column, int $width, int $height): self
return new self($column, $width, $height);
}


public function maxZoom(int $maxZoom): self
{
$this->maxZoom = $maxZoom;
Expand Down
20 changes: 0 additions & 20 deletions src/DTOs/MapSearchBoxType.php

This file was deleted.

21 changes: 0 additions & 21 deletions src/DTOs/MapSearchProvider.php

This file was deleted.

6 changes: 5 additions & 1 deletion src/DTOs/PointValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace Mostafaznv\NovaMapField\DTOs;


class PointValue
{
public function __construct(private float $latitude, private float $longitude) {}
public function __construct(
private readonly float $latitude,
private readonly float $longitude
) {}

public static function make(float $latitude, float $longitude): self
{
Expand Down
10 changes: 10 additions & 0 deletions src/Enums/MapSearchBoxType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Mostafaznv\NovaMapField\Enums;


enum MapSearchBoxType: string
{
case TEXT_FIELD = 'text-input';
case BUTTON = 'glass-button';
}
14 changes: 14 additions & 0 deletions src/Enums/MapSearchProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Mostafaznv\NovaMapField\Enums;


enum MapSearchProvider: string
{
case OSM = 'osm';
case MAPQUEST = 'mapquest';
case PHOTON = 'photon';
case PELIAS = 'pelias';
case BING = 'bing';
case OPENCAGE = 'opencage';
}
2 changes: 1 addition & 1 deletion src/Fields/MapMultiPolygonField.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib
}
}

$this->storeScreenshot($request, $requestAttribute, $model, $attribute);
$this->storeScreenshot($request, $requestAttribute, $model);
}

public function resolve($resource, $attribute = null): void
Expand Down
2 changes: 1 addition & 1 deletion src/Fields/MapPointField.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib
}
}

$this->storeScreenshot($request, $requestAttribute, $model, $attribute);
$this->storeScreenshot($request, $requestAttribute, $model);
}

public function resolve($resource, $attribute = null): void
Expand Down
2 changes: 1 addition & 1 deletion src/Fields/MapPolygonField.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function fillAttributeFromRequest(NovaRequest $request, $requestAttrib
}
}

$this->storeScreenshot($request, $requestAttribute, $model, $attribute);
$this->storeScreenshot($request, $requestAttribute, $model);
}

public function resolve($resource, $attribute = null): void
Expand Down
1 change: 1 addition & 0 deletions src/NovaMapFieldServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\ServiceProvider;
use Laravel\Nova\Nova;


class NovaMapFieldServiceProvider extends ServiceProvider
{
public function register(): void
Expand Down
25 changes: 11 additions & 14 deletions src/Rules/MultiPolygonRequiredRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

namespace Mostafaznv\NovaMapField\Rules;

use Illuminate\Contracts\Validation\Rule;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;


class MultiPolygonRequiredRule implements Rule
class MultiPolygonRequiredRule implements ValidationRule
{
public function passes($attribute, $value): bool
private string $message = 'The :attribute must be a geometry multi-polygon.';


public function validate(string $attribute, mixed $value, Closure $fail): void
{
if ($value) {
$polygons = json_decode($value);
Expand All @@ -17,26 +21,19 @@ public function passes($attribute, $value): bool
if (is_array($polygon) and count($polygon) >= 3) {
foreach ($polygon as $coordinate) {
if (!is_array($coordinate) or count($coordinate) !== 2) {
return false;
$fail(__($this->message));
}
}
}
else {
return false;
$fail(__($this->message));
}
}

return true;
return;
}

return false;
$fail(__($this->message));
}

return true;
}

public function message(): string
{
return __('The :attribute must be a geometry multi-polygon.');
}
}
23 changes: 12 additions & 11 deletions src/Rules/PointRequiredRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

namespace Mostafaznv\NovaMapField\Rules;

use Illuminate\Contracts\Validation\Rule;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;


class PointRequiredRule implements Rule
class PointRequiredRule implements ValidationRule
{
public function passes($attribute, $value): bool
private string $message = 'The :attribute must be a geometry point.';


public function validate(string $attribute, mixed $value, Closure $fail): void
{
if ($value) {
$value = json_decode($value);

return is_object($value) and $value?->latitude and $value?->longitude;
}
if (is_object($value) and $value?->latitude and $value?->longitude) {
return;
}

return true;
}

public function message(): string
{
return __('The :attribute must be a geometry point.');
$fail(__($this->message));
}
}
}
Loading

0 comments on commit 0f0db09

Please sign in to comment.