diff --git a/app/Outlet.php b/app/Outlet.php index 2529e66..14f9c85 100644 --- a/app/Outlet.php +++ b/app/Outlet.php @@ -28,4 +28,20 @@ class Outlet extends Model { return $this->belongsTo(User::class); } + + public function getCoordinateAttribute() + { + if ($this->latitude && $this->longitude) { + return $this->latitude.', '.$this->longitude; + } + } + + public function getMapPopupContentAttribute() + { + $mapPopupContent = ''; + $mapPopupContent .= '
'.__('outlet.name').':
'.$this->name.'
'; + $mapPopupContent .= '
'.__('outlet.coordinate').':
'.$this->coordinate.'
'; + + return $mapPopupContent; + } } diff --git a/public/images/marker-icon-green.png b/public/images/marker-icon-green.png new file mode 100644 index 0000000..56db5ea Binary files /dev/null and b/public/images/marker-icon-green.png differ diff --git a/public/images/marker-shadow.png b/public/images/marker-shadow.png new file mode 100644 index 0000000..84c5808 Binary files /dev/null and b/public/images/marker-shadow.png differ diff --git a/resources/lang/en/outlet.php b/resources/lang/en/outlet.php index 86dcf85..18af16e 100644 --- a/resources/lang/en/outlet.php +++ b/resources/lang/en/outlet.php @@ -28,8 +28,10 @@ return [ 'undeleteable' => 'Outlet data cannot be deleted.', // Attributes - 'name' => 'Outlet Name', - 'address' => 'Outlet Address', - 'latitude' => 'Latitude', - 'longitude' => 'Longitude', + 'name' => 'Outlet Name', + 'address' => 'Outlet Address', + 'latitude' => 'Latitude', + 'longitude' => 'Longitude', + 'location' => 'Location', + 'coordinate' => 'Coordinate', ]; diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 47f604f..615791f 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -9,15 +9,13 @@ {{ config('app.name', 'Laravel') }} - - - + @yield('styles')
@@ -79,5 +77,8 @@ @yield('content')
+ + + @stack('scripts') diff --git a/resources/views/outlets/index.blade.php b/resources/views/outlets/index.blade.php index b170357..6fe17cc 100644 --- a/resources/views/outlets/index.blade.php +++ b/resources/views/outlets/index.blade.php @@ -45,9 +45,7 @@ {{ $outlet->latitude }} {{ $outlet->longitude }} - @can('view', $outlet) - {{ __('app.show') }} - @endcan + {{ __('app.show') }} @endforeach diff --git a/resources/views/outlets/show.blade.php b/resources/views/outlets/show.blade.php index 9f11dce..13f7774 100644 --- a/resources/views/outlets/show.blade.php +++ b/resources/views/outlets/show.blade.php @@ -25,5 +25,53 @@ +
+
+
{{ trans('outlet.location') }}
+ @if ($outlet->coordinate) +
+ @else +
{{ __('outlet.no_coordinate') }}
+ @endif +
+
@endsection + +@section('styles') + + + +@endsection +@push('scripts') + + + + +@endpush diff --git a/tests/Unit/Models/OutletTest.php b/tests/Unit/Models/OutletTest.php index 0f7f384..2a24d17 100644 --- a/tests/Unit/Models/OutletTest.php +++ b/tests/Unit/Models/OutletTest.php @@ -4,15 +4,15 @@ namespace Tests\Unit\Models; use App\User; use App\Outlet; -use Illuminate\Foundation\Testing\DatabaseMigrations; use Tests\BrowserKitTest as TestCase; +use Illuminate\Foundation\Testing\DatabaseMigrations; class OutletTest extends TestCase { use DatabaseMigrations; /** @test */ - public function a_outlet_has_name_link_attribute() + public function an_outlet_has_name_link_attribute() { $outlet = factory(Outlet::class)->create(); @@ -28,11 +28,36 @@ class OutletTest extends TestCase } /** @test */ - public function a_outlet_has_belongs_to_creator_relation() + public function an_outlet_has_belongs_to_creator_relation() { $outlet = factory(Outlet::class)->make(); $this->assertInstanceOf(User::class, $outlet->creator); $this->assertEquals($outlet->creator_id, $outlet->creator->id); } + + /** @test */ + public function an_outlet_has_coordinate_attribute() + { + $outlet = factory(Outlet::class)->make(['latitude' => '-3.333333', 'longitude' => '114.583333']); + $this->assertEquals($outlet->latitude.', '.$outlet->longitude, $outlet->coordinate); + + $outlet = factory(Outlet::class)->make(['latitude' => null, 'longitude' => null]); + $this->assertNull($outlet->coordinate); + + $outlet = factory(Outlet::class)->make(['latitude' => null, 'longitude' => '114.583333']); + $this->assertNull($outlet->coordinate); + } + + /** @test */ + public function an_outlet_has_map_popup_content_attribute() + { + $outlet = factory(Outlet::class)->make(['lat' => '-3.333333', 'long' => '114.583333']); + + $mapPopupContent = ''; + $mapPopupContent .= '
'.__('outlet.name').':
'.$outlet->name.'
'; + $mapPopupContent .= '
'.__('outlet.coordinate').':
'.$outlet->coordinate.'
'; + + $this->assertEquals($mapPopupContent, $outlet->map_popup_content); + } }