diff --git a/app/Http/Controllers/Admin/AlbumController.php b/app/Http/Controllers/Admin/AlbumController.php index 78b98a9..d5af032 100644 --- a/app/Http/Controllers/Admin/AlbumController.php +++ b/app/Http/Controllers/Admin/AlbumController.php @@ -42,7 +42,7 @@ class AlbumController extends Controller * * @return \Illuminate\Http\Response */ - public function create() + public function create(Request $request) { $this->authorize('admin-access'); @@ -52,6 +52,12 @@ class AlbumController extends Controller $albumSources[$storage->id] = $storage->name; } + if (count($albumSources) == 0) + { + $request->session()->flash('info', trans('admin.create_album_no_storage')); + return redirect(route('storage.create')); + } + $defaultSourceId = Storage::where('is_default', true)->limit(1)->first(); return Theme::render('admin.create_album', [ diff --git a/app/Http/Controllers/Admin/StorageController.php b/app/Http/Controllers/Admin/StorageController.php index 0af70c9..1252f2b 100644 --- a/app/Http/Controllers/Admin/StorageController.php +++ b/app/Http/Controllers/Admin/StorageController.php @@ -23,7 +23,7 @@ class StorageController extends Controller * * @return \Illuminate\Http\Response */ - public function index() + public function index(Request $request) { $this->authorize('admin-access'); @@ -31,6 +31,7 @@ class StorageController extends Controller ->paginate(UserConfig::get('items_per_page')); return Theme::render('admin.list_storage', [ + 'error' => $request->session()->get('error'), 'storageLocations' => $storageLocations ]); } @@ -40,7 +41,7 @@ class StorageController extends Controller * * @return \Illuminate\Http\Response */ - public function create() + public function create(Request $request) { $this->authorize('admin-access'); @@ -48,7 +49,8 @@ class StorageController extends Controller return Theme::render('admin.create_storage', [ 'album_sources' => UserConfig::albumSources(), - 'filesystem_default_location' => $filesystemDefaultLocation + 'filesystem_default_location' => $filesystemDefaultLocation, + 'info' => $request->session()->get('info') ]); } @@ -86,6 +88,32 @@ class StorageController extends Controller // //} + /** + * Show the form for deleting the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function delete(Request $request, $id) + { + $this->authorize('admin-access'); + + $storage = Storage::where('id', intval($id))->first(); + if (is_null($storage)) + { + App::abort(404); + } + + if ($storage->albums()->count() > 0) + { + // Can't delete storage location while albums exist + $request->session()->set('error', trans('admin.delete_storage_existing_albums')); + return redirect(route('storage.index')); + } + + return Theme::render('admin.delete_storage', ['storage' => $storage]); + } + /** * Show the form for editing the specified resource. * @@ -140,9 +168,26 @@ class StorageController extends Controller * @param int $id * @return \Illuminate\Http\Response */ - public function destroy($id) + public function destroy(Request $request, $id) { - // + $this->authorize('admin-access'); + + $storage = Storage::where('id', intval($id))->first(); + if (is_null($storage)) + { + App::abort(404); + } + + if ($storage->albums()->count() > 0) + { + // Can't delete storage location while albums exist + $request->session()->flash('error', trans('admin.delete_storage_existing_albums')); + return redirect(route('storage.index')); + } + + $storage->delete(); + + return redirect(route('storage.index')); } private function unsetIsDefaultFromOthers(Storage $storage) diff --git a/app/Storage.php b/app/Storage.php index 75b6da3..9d36fbe 100644 --- a/app/Storage.php +++ b/app/Storage.php @@ -17,4 +17,9 @@ class Storage extends Model protected $fillable = [ 'name', 'source', 'is_default', 'location' ]; + + public function albums() + { + return $this->hasMany(Album::class); + } } diff --git a/resources/lang/en/admin.php b/resources/lang/en/admin.php index f7e9abe..e5808ad 100644 --- a/resources/lang/en/admin.php +++ b/resources/lang/en/admin.php @@ -14,11 +14,16 @@ return [ 'create_album' => 'Create a photo album', 'create_album_intro' => 'Photo albums contain individual photographs together in the same way as a physical photo album or memory book.', 'create_album_intro2' => 'Complete the form below to create a photo album.', + 'create_album_no_storage' => 'There are currently no storage locations set up. Please create a location to store your photos before creating an album.', 'create_storage' => 'Create storage location', 'create_storage_intro' => 'Complete the form below to create a new storage location to hold your photos. You can then select this storage location when you create an album.', 'delete_album' => 'Delete album :name', 'delete_album_confirm' => 'Are you sure you want to permanently delete this album and all its contents?', 'delete_album_warning' => 'This is a permanent action that cannot be undone!', + 'delete_storage' => 'Delete storage location: :name', + 'delete_storage_confirm' => 'Are you sure you want to permanently remove this storage location?', + 'delete_storage_existing_albums' => 'At least one album is still using the storage location. Please delete all albums before removing the storage location.', + 'delete_storage_warning' => 'This is a permanent action that cannot be undone!', 'edit_album' => 'Edit photo album: :album_name', 'edit_album_intro' => 'Photo albums contain individual photographs together in the same way as a physical photo album or memory book.', 'edit_album_intro2' => 'Complete the form below to edit the properties of the album: :album_name.', diff --git a/resources/lang/en/navigation.php b/resources/lang/en/navigation.php index 9a118d5..fbdac17 100644 --- a/resources/lang/en/navigation.php +++ b/resources/lang/en/navigation.php @@ -4,9 +4,11 @@ return [ 'admin' => 'Admin', 'albums' => 'Albums', 'create_album' => 'Create album', - 'delete_album' => 'Delete album', 'create_storage' => 'Create storage', + 'delete_album' => 'Delete album', + 'delete_storage' => 'Delete storage location', 'edit_album' => 'Edit album', + 'edit_storage' => 'Edit storage location', 'home' => 'Gallery', 'settings' => 'Settings', 'storage' => 'Storage', diff --git a/resources/views/themes/base/admin/delete_storage.blade.php b/resources/views/themes/base/admin/delete_storage.blade.php new file mode 100644 index 0000000..a44df4c --- /dev/null +++ b/resources/views/themes/base/admin/delete_storage.blade.php @@ -0,0 +1,35 @@ +@extends('themes.base.layout') +@section('title', trans('admin.delete_storage', ['name' => $storage->name])) + +@section('breadcrumb') +
+@endsection + +@section('content') +@lang('admin.delete_storage_confirm', ['name' => $storage->name])
+