Storage locations can now be deleted. If no storage location exists when creating an album, user is redirected to the create storage page.

This commit is contained in:
Andy Heathershaw 2016-09-28 20:32:19 +01:00
parent 6635d20ead
commit 522887aaa2
7 changed files with 106 additions and 8 deletions

View File

@ -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', [

View File

@ -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)

View File

@ -17,4 +17,9 @@ class Storage extends Model
protected $fillable = [
'name', 'source', 'is_default', 'location'
];
public function albums()
{
return $this->hasMany(Album::class);
}
}

View File

@ -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.',

View File

@ -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',

View File

@ -0,0 +1,35 @@
@extends('themes.base.layout')
@section('title', trans('admin.delete_storage', ['name' => $storage->name]))
@section('breadcrumb')
<div class="breadcrumb">
<div class="container">
<ol class="breadcrumb">
<li><a href="{{ route('home') }}">@lang('navigation.breadcrumb.home')</a></li>
<li><a href="{{ route('admin') }}">@lang('navigation.breadcrumb.admin')</a></li>
<li><a href="{{ route('storage.index') }}">@lang('navigation.breadcrumb.storage')</a></li>
<li class="active">@lang('navigation.breadcrumb.delete_storage')</li>
</ol>
</div>
</div>
@endsection
@section('content')
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1>@yield('title')</h1>
<p>@lang('admin.delete_storage_confirm', ['name' => $storage->name])</p>
<div class="alert alert-warning">
@lang('admin.delete_storage_warning')
</div>
<div class="form-actions">
{!! Form::open(['route' => ['storage.destroy', $storage->id], 'method' => 'DELETE']) !!}
<a href="{{ route('storage.index') }}" class="btn btn-default">@lang('forms.cancel_action')</a>
{!! Form::submit(trans('forms.delete_action'), ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
</div>
</div>
</div>
</div>
@endsection

View File

@ -8,7 +8,7 @@
<li><a href="{{ route('home') }}">@lang('navigation.breadcrumb.home')</a></li>
<li><a href="{{ route('admin') }}">@lang('navigation.breadcrumb.admin')</a></li>
<li><a href="{{ route('storage.index') }}">@lang('navigation.breadcrumb.storage')</a></li>
<li class="active">@lang('navigation.breadcrumb.create_storage')</li>
<li class="active">@lang('navigation.breadcrumb.edit_storage')</li>
</ol>
</div>
</div>