Skip to content

Commit

Permalink
tl;dr
Browse files Browse the repository at this point in the history
  • Loading branch information
angel cruz committed Aug 10, 2020
1 parent d55aac9 commit aa5dfcc
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 40 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,15 @@
with composer:

```bash
// TODO
composer require abr4xas/gmaps-input-backpack
```

#### How to use

Publish package assets with:

```bash
// TODO
```

Add your Google Api Key to the env file:

```
GOOGLE_MAPS_API_KEY=
GOOGLE_MAPS_API_KEY=
```

Add this to your backpack controller:
Expand All @@ -34,8 +28,12 @@ $this->crud->addField([
'attributes' => [
'class' => 'form-control map-input', // do not change this, add more classes if needed
],
'view_namespace' => 'custom-google-maps-field-for-backpack::fields',
]);
```
> Notice the view_namespace attribute - make sure that is exactly as above, to tell Backpack to load the field from this addon package, instead of assuming it's inside the Backpack\CRUD package.


#### Preview:

Expand Down
41 changes: 41 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "abr4xas/gmaps-input-backpack",
"description": "Custom Google Maps Input for Laravel Backpack",
"license": "MIT",
"authors": [
{
"name": "angel cruz",
"email": "bullgram@gmail.com",
"homepage": "https://angelcruz.dev",
"role": "Developer"
}
],
"keywords": [
"Laravel",
"Backpack",
"Backpack for Laravel",
"Addon",
"Admin Panel",
"Google Maps"
],
"require": {},
"require-dev": {},
"autoload": {
"psr-4": {
"Abr4xas\\CustomGoogleMapsFieldForBackpack\\": "src/"
}
},
"scripts": {},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Abr4xas\\CustomGoogleMapsFieldForBackpack\\AddonServiceProvider"
]
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
18 changes: 18 additions & 0 deletions src/AddonServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Abr4xas\CustomGoogleMapsFieldForBackpack;

use Illuminate\Support\ServiceProvider;

class AddonServiceProvider extends ServiceProvider
{
/**
* Perform post-registration booting of services.
*
* @return void
*/
public function boot()
{
$this->loadViewsFrom(realpath(__DIR__ . '/resources/views'), 'custom-google-maps-field-for-backpack');
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
<!-- field_type_name -->
<div @include('crud::inc.field_wrapper_attributes') >
<div @include('crud::inc.field_wrapper_attributes')>
<label>{!! $field['label'] !!}</label>
<input
type="text"
id="{{ $field['name'] }}"
name="{{ $field['name'] }}"
<input type="text" id="{{ $field['name'] }}" name="{{ $field['name'] }}"
value="{{ old($field['name']) ? old($field['name']) : (isset($field['value']) ? $field['value'] : (isset($field['default']) ? $field['default'] : '' )) }}"
@include('crud::inc.field_attributes')
>
@include('crud::inc.field_attributes')>
<input type="hidden" name="address_latitude" id="address-latitude" value="0" />
<input type="hidden" name="address_longitude" id="address-longitude" value="0" />
<div id="address-map-container" style="width:100%;height:400px; ">
<div style="width: 100%; height: 100%" id="address-map"></div>
</div>

{{-- HINT --}}
@if (isset($field['hint']))
<p class="help-block">{!! $field['hint'] !!}</p>
@endif
</div>

@if ($crud->checkIfFieldIsFirstOfItsType($field, $fields))
{{-- FIELD EXTRA CSS --}}
{{-- push things in the after_styles section --}}

@push('crud_fields_styles')
<!-- no styles -->
@endpush

{{-- FIELD EXTRA JS --}}
{{-- push things in the after_scripts section --}}

@push('crud_fields_scripts')
<!-- no scripts -->
<script
src="https://maps.googleapis.com/maps/api/js?key={{ env('GOOGLE_MAPS_API_KEY') }}&libraries=places&callback=initialize" async defer></script>
<script>
function initialize() {
Expand Down Expand Up @@ -87,35 +105,14 @@ function initialize() {
});
}
}
}
function setLocationCoordinates(key, lat, lng) {
function setLocationCoordinates(key, lat, lng) {
const latitudeField = document.getElementById(key + "-" + "latitude");
const longitudeField = document.getElementById(key + "-" + "longitude");
latitudeField.value = lat;
longitudeField.value = lng;
}
</script>

{{-- HINT --}}
@if (isset($field['hint']))
<p class="help-block">{!! $field['hint'] !!}</p>
@endif
</div>

@if ($crud->checkIfFieldIsFirstOfItsType($field, $fields))
{{-- FIELD EXTRA CSS --}}
{{-- push things in the after_styles section --}}

@push('crud_fields_styles')
<!-- no styles -->
@endpush

{{-- FIELD EXTRA JS --}}
{{-- push things in the after_scripts section --}}

@push('crud_fields_scripts')
<!-- no scripts -->
<script src="https://maps.googleapis.com/maps/api/js?key={{ env('GOOGLE_MAPS_API_KEY') }}&libraries=places&callback=initialize" async defer></script>
@endpush
@endif
@endpush
@endif

0 comments on commit aa5dfcc

Please sign in to comment.