From 9aa381c11d7121f3f302d9fdae8c414a097f57aa Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Fri, 23 Jul 2021 15:59:02 +0200 Subject: [PATCH] New tripmarkers field. --- .../js/components/fields/TripMarkers.vue | 84 +++++++++++++++++++ resources/js/field.js | 1 + src/TripMarkers.php | 74 ++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 resources/js/components/fields/TripMarkers.vue create mode 100644 src/TripMarkers.php diff --git a/resources/js/components/fields/TripMarkers.vue b/resources/js/components/fields/TripMarkers.vue new file mode 100644 index 0000000..c345e20 --- /dev/null +++ b/resources/js/components/fields/TripMarkers.vue @@ -0,0 +1,84 @@ + + + diff --git a/resources/js/field.js b/resources/js/field.js index b79122e..341ca24 100755 --- a/resources/js/field.js +++ b/resources/js/field.js @@ -5,6 +5,7 @@ Nova.booting((Vue, router) => { Vue.component('field-map', require('./components/FieldMap')); Vue.component('field-marker', require('./components/fields/Marker')); + Vue.component('field-markers', require('./components/fields/TripMarkers')); Vue.component('field-polyline', require('./components/fields/Polyline')); // Config leaflet images to load images from CDN diff --git a/src/TripMarkers.php b/src/TripMarkers.php new file mode 100644 index 0000000..4a024bb --- /dev/null +++ b/src/TripMarkers.php @@ -0,0 +1,74 @@ +help('Drag the marker to change the point.'); + + parent::__construct($name, $attribute = null, $resolveCallback); + } + + /** + * Set the name field. + * + * @param mixed $fieldName + * + * @return $this + */ + public function setProducts($fieldName) + { + return $this->withMeta([ + 'selected_products' => $fieldName, + ]); + } + + /** + * Resolve the attribute before sending to frontend. + * + * @param mixed $resource + * @param mixed|null $attribute + * + * @return array + */ + public function resolveAttribute($resource, $attribute = null) + { + return [ + // 'lat' => $resource->{$this->meta['latitudeField']}, + // 'lng' => $resource->{$this->meta['longitudeField']}, + 'selected_products' => $resource->{$this->meta['selected_products']}, + ]; + } + + /** + * Hydrate the given attribute on the model based on the incoming request. + * + * @param \Laravel\Nova\Http\Requests\NovaRequest $request + * @param string $requestAttribute + * @param object $model + * @param string $attribute + */ + protected function fillAttributeFromRequest(NovaRequest $request, $requestAttribute, $model, $attribute) + { + return json_decode($resource->{$attribute}); + + if ($request->exists($requestAttribute)) { + $latLng = json_decode($request[$requestAttribute]); + + $model->{$this->meta['all_products']} = $latLng->all_products; + $model->{$this->meta['selected_products']} = $latLng->selected_products; + } + } +}