Skip to content

Commit 6a97c86

Browse files
authored
Merge pull request #100 from kaidesu/google-map-settings
Google map settings
2 parents 2b88a8b + 3af67d9 commit 6a97c86

9 files changed

Lines changed: 67 additions & 49 deletions

File tree

public/js/chunks/111.js

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

public/js/chunks/23.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.

public/js/chunks/64.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.

public/js/gravity.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.

public/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"/js/gravity.js": "/js/gravity.js?id=752b80df62bffbda0303",
2+
"/js/gravity.js": "/js/gravity.js?id=4e3e25fa9d175ec4e7be",
33
"/css/gravity.css": "/css/gravity.css?id=88cf59977307f36f5f29"
44
}

resources/js/fieldtypes/Address/Field.vue

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@
4646
class="mb-2"
4747
></p-input>
4848
</div>
49-
<div class="w-1/2 pl-2">
50-
<div class="h-full" :id="mapID">
51-
<div v-if="mapError" class="p-5" v-html="mapError">
52-
49+
<div class="w-1/2 pl-6">
50+
<div class="h-full rounded" :id="mapID">
51+
<div class="bg-gray-100 rounded shadow p-3" v-if="mapError" v-html="mapError"></div>
52+
53+
<div class="bg-gray-100 rounded shadow p-3" v-show="hasAPIKey == false">
54+
<p>A <a href="https://developers.google.com/maps/documentation/javascript/get-api-key" target="_blank">Google Maps API key</a> is required in order to view the map component and retrieve latitude and longitude coordinates for your address.</p>
55+
<p>Once you've obtained one, please visit the <router-link to="/settings/google_maps">Google Maps settings page</router-link> to enter your API key.</p>
5356
</div>
5457
</div>
5558
</div>
@@ -93,7 +96,7 @@
9396
return {
9497
marker: null,
9598
data: data,
96-
mapError: ''
99+
mapError: '',
97100
}
98101
},
99102
@@ -110,6 +113,14 @@
110113
},
111114
112115
computed: {
116+
apiKey() {
117+
return this.setting('maps_api_key')
118+
},
119+
120+
hasAPIKey() {
121+
return (this.apiKey && this.apiKey != '')
122+
},
123+
113124
mapID() {
114125
return this.field.handle + '_map'
115126
},
@@ -136,6 +147,14 @@
136147
watch: {
137148
addressLookup: function() {
138149
this.locateAddress();
150+
},
151+
152+
apiKey(value) {
153+
if (value && value != '') {
154+
this.$nextTick(() => {
155+
this.initializeMap()
156+
})
157+
}
139158
}
140159
},
141160
@@ -145,7 +164,23 @@
145164
this.$emit('input', this.data)
146165
},
147166
148-
createMap: function() {
167+
initializeMap() {
168+
if (_.isUndefined(window.google)) {
169+
let vm = this
170+
let mapScript = document.createElement('script')
171+
172+
window.mapInit = function() {
173+
vm.createMap()
174+
}
175+
176+
mapScript.setAttribute('src', `https://maps.googleapis.com/maps/api/js?key=${this.apiKey}&callback=mapInit`)
177+
document.head.appendChild(mapScript)
178+
} else {
179+
this.createMap()
180+
}
181+
},
182+
183+
createMap() {
149184
if (! _.isUndefined(window.google)) {
150185
this.map = new google.maps.Map(document.getElementById(this.mapID));
151186
@@ -203,25 +238,5 @@
203238
}, 500
204239
)
205240
},
206-
207-
mounted() {
208-
let vm = this
209-
let apiKey = vm.field.settings.api_key
210-
if (!apiKey || apiKey == '') {
211-
vm.mapError = 'You will need to generate a <a href="https://developers.google.com/maps/documentation/javascript/get-api-key" target="_blank">Google Maps API key</a> in order to view the map component and retrieve latitude and longitude coordinates for your address'
212-
return
213-
}
214-
if (_.isUndefined(window.google)) {
215-
window.mapInit = function() {
216-
vm.createMap()
217-
}
218-
let mapScript = document.createElement('script')
219-
mapScript.setAttribute('src', `https://maps.googleapis.com/maps/api/js?key=${apiKey}&callback=mapInit`)
220-
document.head.appendChild(mapScript)
221-
} else {
222-
vm.createMap();
223-
}
224-
}
225241
}
226242
</script>
227-
Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
<template>
2-
<div>
3-
<p-input
4-
name="settings.api_key"
5-
label="API Key"
6-
help='You will need to generate a <a href="https://developers.google.com/maps/documentation/javascript/get-api-key" target="_blank">Google Maps API key</a> in order to view the map component and retrieve latitude and longitude coordinates for your address'
7-
autocomplete="off"
8-
placeholder=""
9-
v-model="settings.api_key"
10-
:has-error="errors.has('settings.api_key')"
11-
:error-message="errors.get('settings.api_key')">
12-
</p-input>
13-
</div>
2+
<div>
3+
4+
</div>
145
</template>
156

167
<script>
@@ -22,4 +13,3 @@
2213
mixins: [fieldtype],
2314
}
2415
</script>
25-

resources/js/store/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default {
1818
getGroupSections: (state) => {
1919
return _.groupBy(state.groups, 'group')
2020
},
21-
21+
2222
getSetting: (state) => (key) => {
2323
return state.settings[key]
2424
},

settings/google_maps.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
return [
4+
'name' => 'Google Maps',
5+
'group' => 'Services',
6+
'icon' => 'map-marked-alt',
7+
'description' => 'Configure your Google Maps settings.',
8+
'settings' => [
9+
'General' => [
10+
[
11+
'name' => 'API Key',
12+
'handle' => 'maps_api_key',
13+
'description' => 'Your Google Maps API key.',
14+
],
15+
],
16+
],
17+
];

0 commit comments

Comments
 (0)