From e232f2e2238cb12ddc8d0ba68833421e73fb6d7b Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 28 Apr 2015 11:04:46 +0200 Subject: [PATCH] Delete tags --- app/Http/Controllers/TagController.php | 31 +++++++++++++ app/Repositories/Tag/TagRepository.php | 28 +++++++++--- .../Tag/TagRepositoryInterface.php | 7 +++ resources/views/tags/delete.blade.php | 44 +++++++++++++++++++ 4 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 resources/views/tags/delete.blade.php diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index ba15b3ea83..46cf6fea45 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -39,6 +39,37 @@ class TagController extends Controller View::share('tagOptions', $tagOptions); } + /** + * @param Tag $tag + * + * @return \Illuminate\View\View + */ + public function delete(Tag $tag) + { + $subTitle = 'Delete "' . e($tag->tag) . '"'; + + // put previous url in session + Session::put('tags.delete.url', URL::previous()); + + return view('tags.delete', compact('tag', 'subTitle')); + } + + /** + * @param Tag $tag + * + * @return \Illuminate\Http\RedirectResponse + */ + public function destroy(Tag $tag, TagRepositoryInterface $repository) + { + + $tagName = $tag->tag; + $repository->destroy($tag); + + Session::flash('success', 'Tag "' . e($tagName) . '" was deleted.'); + + return Redirect::to(route('tags.index')); + } + /** * @return \Illuminate\View\View */ diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php index 030813b8a6..9ca40a968b 100644 --- a/app/Repositories/Tag/TagRepository.php +++ b/app/Repositories/Tag/TagRepository.php @@ -15,6 +15,18 @@ use Illuminate\Support\Collection; class TagRepository implements TagRepositoryInterface { + /** + * @param Tag $tag + * + * @return boolean + */ + public function destroy(Tag $tag) + { + $tag->delete(); + + return true; + } + /** * @return Collection */ @@ -60,15 +72,17 @@ class TagRepository implements TagRepositoryInterface * * @return Tag */ - public function update(Tag $tag, array $data) { - $tag->tag = $data['tag']; - $tag->date = $data['date']; + public function update(Tag $tag, array $data) + { + $tag->tag = $data['tag']; + $tag->date = $data['date']; $tag->description = $data['description']; - $tag->latitude = $data['latitude']; - $tag->longitude = $data['longitude']; - $tag->zoomLevel = $data['zoomLevel']; - $tag->tagMode = $data['tagMode']; + $tag->latitude = $data['latitude']; + $tag->longitude = $data['longitude']; + $tag->zoomLevel = $data['zoomLevel']; + $tag->tagMode = $data['tagMode']; $tag->save(); + return $tag; } } \ No newline at end of file diff --git a/app/Repositories/Tag/TagRepositoryInterface.php b/app/Repositories/Tag/TagRepositoryInterface.php index 124aa88707..937bc51b4a 100644 --- a/app/Repositories/Tag/TagRepositoryInterface.php +++ b/app/Repositories/Tag/TagRepositoryInterface.php @@ -31,4 +31,11 @@ interface TagRepositoryInterface { * @return Tag */ public function update(Tag $tag, array $data); + + /** + * @param Tag $tag + * + * @return boolean + */ + public function destroy(Tag $tag); } \ No newline at end of file diff --git a/resources/views/tags/delete.blade.php b/resources/views/tags/delete.blade.php new file mode 100644 index 0000000000..0320cf1a1a --- /dev/null +++ b/resources/views/tags/delete.blade.php @@ -0,0 +1,44 @@ +@extends('layouts.default') +@section('content') +{!! Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $tag) !!} +{!! Form::open(['class' => 'form-horizontal','id' => 'destroy','url' => route('tags.destroy',$tag->id)]) !!} +
+
+
+
+ Delete tag "{{{$tag->tag}}}" +
+
+

+ Are you sure that you want to delete tag "{{{$tag->tag}}}"? +

+ + @if($tag->transactionjournals()->count() > 0) +

+ Tag "{{{$tag->name}}}" still has {{$tag->transactionjournals()->count()}} transaction(s) connected + to it. These will not be removed but will lose their connection to this tag. +

+ @endif + +

+ + Cancel +

+
+
+
+
+ +
+
+
+
+ +
+
+
+
+ + +{!! Form::close() !!} +@stop