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

Commit eaa7e7a

Browse files
committed
Fixed compatiblity with Nova 3.8.4.
1 parent ac153d0 commit eaa7e7a

File tree

12 files changed

+128
-166
lines changed

12 files changed

+128
-166
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.2.2] - 2020-09-04
8+
### Fixed
9+
- compatibility with Nova 3.8.4.
10+
711
## [0.2.1] - 2020-09-03
812
### Added
913
- max version constraint due to Nova 3.8.4 having breaking changes.

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
],
1515
"require": {
1616
"illuminate/support": "^7.0",
17-
"laravel/nova": "<3.8.4",
17+
"laravel/nova": "*",
1818
"symfony/thanks": "^1.1"
1919
},
20+
"require-dev": {
21+
"sebastian/phpcpd": "^5.0",
22+
"squizlabs/php_codesniffer": "^3.4"
23+
},
2024
"autoload": {
2125
"psr-4": {
2226
"GeneaLabs\\NovaMapMarkerField\\": "src/"

dist/js/field.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mix-manifest.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"/js/field.js": "/js/field.js",
3-
"/css/field.css": "/css/field.css"
2+
"/js/field.js": "/js/field.js"
43
}

phpcs.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer" xsi:noNamespaceSchemaLocation="phpcs.xsd">
3+
<description>GeneaLabs coding standards.</description>
4+
5+
<rule ref="PSR1"></rule>
6+
<rule ref="PSR2"></rule>
7+
<rule ref="PSR12">
8+
<exclude name="PSR12.Classes.ClassInstantiation.MissingParentheses"/>
9+
<exclude name="PSR12.Functions.ReturnTypeDeclaration.SpaceBeforeColon"/>
10+
</rule>
11+
</ruleset>

resources/js/components/DetailField.vue

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
data: function () {
1919
return {
2020
iconRetina: this.field.iconRetinaUrl
21-
|| require('leaflet/dist/images/marker-icon-2x.png'),
21+
|| '/vendor/leaflet/dist/images/marker-icon-2x.png',
2222
icon: this.field.iconUrl
23-
|| require('leaflet/dist/images/marker-icon.png'),
23+
|| '/vendor/leaflet/dist/images/marker-icon.png',
2424
shadow: this.field.shadowUrl
25-
|| require('leaflet/dist/images/marker-shadow.png'),
25+
|| '/vendor/leaflet/dist/images/marker-shadow.png',
2626
tileUrl: 'https://{s}.tile.osm.org/{z}/{x}/{y}.png',
2727
mapOptions: {
2828
boxZoom: false,
@@ -39,7 +39,7 @@
3939
4040
created: function () {
4141
delete L.Icon.Default.prototype._getIconUrl;
42-
42+
4343
L.Icon.Default.mergeOptions({
4444
iconRetinaUrl: this.iconRetina,
4545
iconUrl: this.icon,
@@ -81,26 +81,30 @@
8181
},
8282
8383
locationIsSet: function () {
84-
if (this.value.latitude === undefined) {
84+
if (this.value.length === 0) {
8585
this.setInitialValue();
8686
}
8787
88-
return this.value.latitude > 0
89-
|| this.value.longitude > 0;
88+
let value = JSON.parse(this.value);
89+
90+
return value.latitude > 0
91+
|| value.longitude > 0;
9092
},
9193
9294
locationIsNotSet: function () {
9395
return !this.locationIsSet;
9496
},
9597
9698
mapCenter: function () {
97-
if (this.value.latitude === undefined) {
99+
if (this.value.length === 0) {
98100
this.setInitialValue();
99101
}
100102
103+
let value = JSON.parse(this.value);
104+
101105
return [
102-
this.value.latitude,
103-
this.value.longitude,
106+
(value.latitude || this.field.defaultLatitude || 0),
107+
(value.longitude || this.field.defaultLongitude || 0),
104108
];
105109
},
106110
},
@@ -124,10 +128,21 @@
124128
},
125129
126130
setInitialValue: function () {
127-
this.value = {
128-
latitude: this.field.value[this.field.latitude || "latitude"] || 0,
129-
longitude: this.field.value[this.field.longitude || "longitude"] || 0,
130-
};
131+
let value = JSON.parse(this.value || this.field.value);
132+
133+
this.setValue(value.latitude, value.longitude);
134+
},
135+
136+
setValue: function (latitude, longitude) {
137+
this.value = '{"latitude_field":'
138+
+ '"' + (this.field.latitude || 'latitude') + '"'
139+
+ ',"longitude_field":'
140+
+ '"' + (this.field.longitude || 'longitude') + '"'
141+
+ ',"latitude":'
142+
+ (latitude || 0)
143+
+ ',"longitude":'
144+
+ (longitude || 0)
145+
+ '}';
131146
},
132147
},
133148
};

resources/js/components/FormField.vue

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
mounted: function () {
5555
this.$nextTick(() => {
5656
this.map = this.$refs.map.mapObject;
57+
this.setInitialValue();
5758
});
5859
},
5960
@@ -122,26 +123,8 @@
122123
return ((this.field.centerCircle || {}).border || 0);
123124
},
124125
125-
firstLocationError: function () {
126-
if (this.hasLocationError) {
127-
return (this.errors.first(this.latitudeFieldName)
128-
|| this.errors.first(this.longitudeFieldName));
129-
}
130-
},
131-
132126
hasLocationError: function () {
133-
return (this.errors.has(this.latitudeFieldName)
134-
|| this.errors.has(this.longitudeFieldName));
135-
},
136-
137-
latitudeFieldName: function () {
138-
return this.field.latitude
139-
|| "latitude";
140-
},
141-
142-
longitudeFieldName: function () {
143-
return this.field.longitude
144-
|| "longitude";
127+
return this.errors.has(this.field.attribute);
145128
},
146129
147130
listenToEventName: function () {
@@ -156,55 +139,59 @@
156139
},
157140
158141
showErrors: function () {
159-
console.log(this.errors);
142+
// console.error(this.errors);
160143
},
161144
162145
mapCenter: function () {
163-
if (this.value.latitude === undefined) {
146+
if (this.value.length === 0) {
164147
this.setInitialValue();
165148
}
166149
150+
let value = JSON.parse(this.value);
151+
167152
return [
168-
this.value.latitude
169-
|| this.defaultLatitude,
170-
this.value.longitude
171-
|| this.defaultLongitude,
153+
(value.latitude || this.field.defaultLatitude || 0),
154+
(value.longitude || this.field.defaultLongitude || 0),
172155
];
173156
},
174157
},
175158
176159
methods: {
177160
fill: function (formData) {
178-
formData.append((this.field.latitude || "latitude"), this.value.latitude);
179-
formData.append((this.field.longitude || "longitude"), this.value.longitude);
161+
formData.append(this.field.attribute, this.value || '');
180162
},
181163
182164
handleChange: function (value) {
183-
this.value.latitude = value.latitude;
184-
this.value.longitude = value.longitude;
165+
this.setValue(value.latitude, value.longitude);
185166
},
186167
187168
mapMoved: function (event) {
188169
let coordinates = event.target.getCenter();
189170
190-
this.value.latitude = coordinates.lat;
191-
this.value.longitude = coordinates.lng;
171+
this.setValue(coordinates.lat, coordinates.lng);
192172
},
193173
194174
setInitialValue: function () {
195-
this.value = {
196-
latitude: this.field.value[this.field.latitude || "latitude"]
197-
|| 0,
198-
longitude: this.field.value[this.field.longitude || "longitude"]
199-
|| 0,
200-
};
175+
let value = JSON.parse(this.value || this.field.value);
176+
177+
this.setValue(value.latitude, value.longitude);
178+
},
179+
180+
setValue: function (latitude, longitude) {
181+
this.value = '{"latitude_field":'
182+
+ '"' + (this.field.latitude || 'latitude') + '"'
183+
+ ',"longitude_field":'
184+
+ '"' + (this.field.longitude || 'longitude') + '"'
185+
+ ',"latitude":'
186+
+ (latitude || 0)
187+
+ ',"longitude":'
188+
+ (longitude || 0)
189+
+ '}';
201190
},
202191
203192
mapNewCenter: function (event) {
204193
var center = [event.lat, event.long];
205-
206-
this.value.latitude = event.lat;
207-
this.value.longitude = event.long;
194+
this.setValue(event.lat, event.long);
208195
this.map.panTo(center, {animate:true});
209196
},
210197
},
@@ -250,9 +237,6 @@
250237
/>
251238
</l-map>
252239
</div>
253-
<p v-if="hasLocationError" class="my-2 text-danger">
254-
{{ firstLocationError }}
255-
</p>
256240
</template>
257241
</default-field>
258242
</template>

resources/js/components/IndexField.vue

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,30 @@ export default {
44
55
data: function () {
66
return {
7-
latitude: this.field.value[this.field.latitude || "latitude"] || 0,
8-
longitude: this.field.value[this.field.longitude || "longitude"] || 0,
7+
value: JSON.parse(this.field.value || {}),
98
};
109
},
1110
1211
computed: {
12+
latitude: function () {
13+
return this.value.latitude;
14+
},
15+
16+
longitude: function () {
17+
return this.value.longitude;
18+
},
19+
1320
hasLatitude: function () {
14-
return (this.latitude.length > 0);
21+
return (this.latitude != 0);
1522
},
1623
1724
hasLongitude: function () {
18-
return (this.longitude.length > 0);
25+
return (this.longitude != 0);
1926
},
2027
2128
locationIsSet: function () {
22-
return this.latitude > 0
23-
|| this.longitude > 0;
29+
return this.hasLatitude
30+
|| this.hasLongitude;
2431
},
2532
2633
locationIsNotSet: function () {
@@ -59,4 +66,3 @@ export default {
5966
white-space: nowrap;
6067
}
6168
</style>
62-

resources/sass/field.scss

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)