Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

Commit

Permalink
Fixed compatiblity with Nova 3.8.4.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner committed Sep 4, 2020
1 parent ac153d0 commit eaa7e7a
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 166 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.2.2] - 2020-09-04
### Fixed
- compatibility with Nova 3.8.4.

## [0.2.1] - 2020-09-03
### Added
- max version constraint due to Nova 3.8.4 having breaking changes.
Expand Down
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@
],
"require": {
"illuminate/support": "^7.0",
"laravel/nova": "<3.8.4",
"laravel/nova": "*",
"symfony/thanks": "^1.1"
},
"require-dev": {
"sebastian/phpcpd": "^5.0",
"squizlabs/php_codesniffer": "^3.4"
},
"autoload": {
"psr-4": {
"GeneaLabs\\NovaMapMarkerField\\": "src/"
Expand Down
2 changes: 1 addition & 1 deletion dist/js/field.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"/js/field.js": "/js/field.js",
"/css/field.css": "/css/field.css"
"/js/field.js": "/js/field.js"
}
11 changes: 11 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
<description>GeneaLabs coding standards.</description>

<rule ref="PSR1"></rule>
<rule ref="PSR2"></rule>
<rule ref="PSR12">
<exclude name="PSR12.Classes.ClassInstantiation.MissingParentheses"/>
<exclude name="PSR12.Functions.ReturnTypeDeclaration.SpaceBeforeColon"/>
</rule>
</ruleset>
43 changes: 29 additions & 14 deletions resources/js/components/DetailField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
data: function () {
return {
iconRetina: this.field.iconRetinaUrl
|| require('leaflet/dist/images/marker-icon-2x.png'),
|| '/vendor/leaflet/dist/images/marker-icon-2x.png',
icon: this.field.iconUrl
|| require('leaflet/dist/images/marker-icon.png'),
|| '/vendor/leaflet/dist/images/marker-icon.png',
shadow: this.field.shadowUrl
|| require('leaflet/dist/images/marker-shadow.png'),
|| '/vendor/leaflet/dist/images/marker-shadow.png',
tileUrl: 'https://{s}.tile.osm.org/{z}/{x}/{y}.png',
mapOptions: {
boxZoom: false,
Expand All @@ -39,7 +39,7 @@
created: function () {
delete L.Icon.Default.prototype._getIconUrl;
L.Icon.Default.mergeOptions({
iconRetinaUrl: this.iconRetina,
iconUrl: this.icon,
Expand Down Expand Up @@ -81,26 +81,30 @@
},
locationIsSet: function () {
if (this.value.latitude === undefined) {
if (this.value.length === 0) {
this.setInitialValue();
}
return this.value.latitude > 0
|| this.value.longitude > 0;
let value = JSON.parse(this.value);
return value.latitude > 0
|| value.longitude > 0;
},
locationIsNotSet: function () {
return !this.locationIsSet;
},
mapCenter: function () {
if (this.value.latitude === undefined) {
if (this.value.length === 0) {
this.setInitialValue();
}
let value = JSON.parse(this.value);
return [
this.value.latitude,
this.value.longitude,
(value.latitude || this.field.defaultLatitude || 0),
(value.longitude || this.field.defaultLongitude || 0),
];
},
},
Expand All @@ -124,10 +128,21 @@
},
setInitialValue: function () {
this.value = {
latitude: this.field.value[this.field.latitude || "latitude"] || 0,
longitude: this.field.value[this.field.longitude || "longitude"] || 0,
};
let value = JSON.parse(this.value || this.field.value);
this.setValue(value.latitude, value.longitude);
},
setValue: function (latitude, longitude) {
this.value = '{"latitude_field":'
+ '"' + (this.field.latitude || 'latitude') + '"'
+ ',"longitude_field":'
+ '"' + (this.field.longitude || 'longitude') + '"'
+ ',"latitude":'
+ (latitude || 0)
+ ',"longitude":'
+ (longitude || 0)
+ '}';
},
},
};
Expand Down
70 changes: 27 additions & 43 deletions resources/js/components/FormField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
mounted: function () {
this.$nextTick(() => {
this.map = this.$refs.map.mapObject;
this.setInitialValue();
});
},
Expand Down Expand Up @@ -122,26 +123,8 @@
return ((this.field.centerCircle || {}).border || 0);
},
firstLocationError: function () {
if (this.hasLocationError) {
return (this.errors.first(this.latitudeFieldName)
|| this.errors.first(this.longitudeFieldName));
}
},
hasLocationError: function () {
return (this.errors.has(this.latitudeFieldName)
|| this.errors.has(this.longitudeFieldName));
},
latitudeFieldName: function () {
return this.field.latitude
|| "latitude";
},
longitudeFieldName: function () {
return this.field.longitude
|| "longitude";
return this.errors.has(this.field.attribute);
},
listenToEventName: function () {
Expand All @@ -156,55 +139,59 @@
},
showErrors: function () {
console.log(this.errors);
// console.error(this.errors);
},
mapCenter: function () {
if (this.value.latitude === undefined) {
if (this.value.length === 0) {
this.setInitialValue();
}
let value = JSON.parse(this.value);
return [
this.value.latitude
|| this.defaultLatitude,
this.value.longitude
|| this.defaultLongitude,
(value.latitude || this.field.defaultLatitude || 0),
(value.longitude || this.field.defaultLongitude || 0),
];
},
},
methods: {
fill: function (formData) {
formData.append((this.field.latitude || "latitude"), this.value.latitude);
formData.append((this.field.longitude || "longitude"), this.value.longitude);
formData.append(this.field.attribute, this.value || '');
},
handleChange: function (value) {
this.value.latitude = value.latitude;
this.value.longitude = value.longitude;
this.setValue(value.latitude, value.longitude);
},
mapMoved: function (event) {
let coordinates = event.target.getCenter();
this.value.latitude = coordinates.lat;
this.value.longitude = coordinates.lng;
this.setValue(coordinates.lat, coordinates.lng);
},
setInitialValue: function () {
this.value = {
latitude: this.field.value[this.field.latitude || "latitude"]
|| 0,
longitude: this.field.value[this.field.longitude || "longitude"]
|| 0,
};
let value = JSON.parse(this.value || this.field.value);
this.setValue(value.latitude, value.longitude);
},
setValue: function (latitude, longitude) {
this.value = '{"latitude_field":'
+ '"' + (this.field.latitude || 'latitude') + '"'
+ ',"longitude_field":'
+ '"' + (this.field.longitude || 'longitude') + '"'
+ ',"latitude":'
+ (latitude || 0)
+ ',"longitude":'
+ (longitude || 0)
+ '}';
},
mapNewCenter: function (event) {
var center = [event.lat, event.long];
this.value.latitude = event.lat;
this.value.longitude = event.long;
this.setValue(event.lat, event.long);
this.map.panTo(center, {animate:true});
},
},
Expand Down Expand Up @@ -250,9 +237,6 @@
/>
</l-map>
</div>
<p v-if="hasLocationError" class="my-2 text-danger">
{{ firstLocationError }}
</p>
</template>
</default-field>
</template>
Expand Down
20 changes: 13 additions & 7 deletions resources/js/components/IndexField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,30 @@ export default {
data: function () {
return {
latitude: this.field.value[this.field.latitude || "latitude"] || 0,
longitude: this.field.value[this.field.longitude || "longitude"] || 0,
value: JSON.parse(this.field.value || {}),
};
},
computed: {
latitude: function () {
return this.value.latitude;
},
longitude: function () {
return this.value.longitude;
},
hasLatitude: function () {
return (this.latitude.length > 0);
return (this.latitude != 0);
},
hasLongitude: function () {
return (this.longitude.length > 0);
return (this.longitude != 0);
},
locationIsSet: function () {
return this.latitude > 0
|| this.longitude > 0;
return this.hasLatitude
|| this.hasLongitude;
},
locationIsNotSet: function () {
Expand Down Expand Up @@ -59,4 +66,3 @@ export default {
white-space: nowrap;
}
</style>

1 change: 0 additions & 1 deletion resources/sass/field.scss

This file was deleted.

Loading

0 comments on commit eaa7e7a

Please sign in to comment.