#12: Added the ability to add and remove redirects from the album's admin page (Redirects tab)
This commit is contained in:
parent
b7a8222ecf
commit
f9bc890de0
@ -170,6 +170,11 @@ class Album extends Model
|
|||||||
return $this->hasMany(Photo::class);
|
return $this->hasMany(Photo::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function redirects()
|
||||||
|
{
|
||||||
|
return $this->hasMany(AlbumRedirect::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function storage()
|
public function storage()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Storage::class);
|
return $this->belongsTo(Storage::class);
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace app\Http\Controllers\Admin;
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
use App\Album;
|
use App\Album;
|
||||||
use App\AlbumGroupPermission;
|
use App\AlbumRedirect;
|
||||||
use App\Facade\Theme;
|
use App\Facade\Theme;
|
||||||
use App\Facade\UserConfig;
|
use App\Facade\UserConfig;
|
||||||
use App\Group;
|
use App\Group;
|
||||||
use App\Helpers\DbHelper;
|
use App\Helpers\DbHelper;
|
||||||
use App\Helpers\FileHelper;
|
|
||||||
use App\Helpers\MiscHelper;
|
use App\Helpers\MiscHelper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests;
|
use App\Http\Requests;
|
||||||
@ -17,7 +16,6 @@ use App\Photo;
|
|||||||
use App\Services\AlbumService;
|
use App\Services\AlbumService;
|
||||||
use App\Services\PhotoService;
|
use App\Services\PhotoService;
|
||||||
use App\Storage;
|
use App\Storage;
|
||||||
use App\Upload;
|
|
||||||
use App\User;
|
use App\User;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
@ -91,6 +89,25 @@ class AlbumController extends Controller
|
|||||||
return Theme::render('admin.delete_album', ['album' => $album]);
|
return Theme::render('admin.delete_album', ['album' => $album]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function deleteRedirect(Request $request, $id, $redirectId)
|
||||||
|
{
|
||||||
|
$this->authorizeAccessToAdminPanel('admin:manage-albums');
|
||||||
|
|
||||||
|
$album = $this->loadAlbum($id, 'delete');
|
||||||
|
|
||||||
|
/** @var AlbumRedirect $redirect */
|
||||||
|
$redirect = $album->redirects()->where('id', $redirectId)->first();
|
||||||
|
if (is_null($redirect))
|
||||||
|
{
|
||||||
|
App::abort(404);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$redirect->delete();
|
||||||
|
$request->session()->flash('success', trans('admin.delete_redirect_success_message'));
|
||||||
|
return redirect(route('albums.show', ['id' => $id, 'tab' => 'redirects']));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the specified resource from storage.
|
* Remove the specified resource from storage.
|
||||||
*
|
*
|
||||||
@ -429,6 +446,21 @@ class AlbumController extends Controller
|
|||||||
return redirect(route('albums.show', ['id' => $album->id]));
|
return redirect(route('albums.show', ['id' => $album->id]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function storeRedirect(Requests\StoreAlbumRedirectRequest $request, $id)
|
||||||
|
{
|
||||||
|
$this->authorizeAccessToAdminPanel('admin:manage-albums');
|
||||||
|
|
||||||
|
$album = $this->loadAlbum($id);
|
||||||
|
|
||||||
|
$redirect = new AlbumRedirect();
|
||||||
|
$redirect->fill($request->only('source_url'));
|
||||||
|
$redirect->album_id = $album->id;
|
||||||
|
$redirect->save();
|
||||||
|
|
||||||
|
$request->session()->flash('success', trans('admin.create_redirect_success_message'));
|
||||||
|
return redirect(route('albums.show', ['id' => $id, 'tab' => 'redirects']));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified resource in storage.
|
* Update the specified resource in storage.
|
||||||
*
|
*
|
||||||
|
30
app/Http/Requests/StoreAlbumRedirectRequest.php
Normal file
30
app/Http/Requests/StoreAlbumRedirectRequest.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class StoreAlbumRedirectRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function authorize()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'source_url' => 'required|unique:album_redirects|max:255'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -24,6 +24,7 @@ return [
|
|||||||
'album_permissions_album' => 'Album Permissions',
|
'album_permissions_album' => 'Album Permissions',
|
||||||
'album_permissions_photo' => 'Photo Permissions',
|
'album_permissions_photo' => 'Photo Permissions',
|
||||||
'album_photos_tab' => 'Photos',
|
'album_photos_tab' => 'Photos',
|
||||||
|
'album_redirects_tab' => 'Redirects',
|
||||||
'album_saved_successfully' => 'The ":name" album was updated successfully.',
|
'album_saved_successfully' => 'The ":name" album was updated successfully.',
|
||||||
'album_security_tab' => 'Permissions',
|
'album_security_tab' => 'Permissions',
|
||||||
'album_settings_tab' => 'Settings',
|
'album_settings_tab' => 'Settings',
|
||||||
@ -45,6 +46,9 @@ return [
|
|||||||
'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_album_no_storage' => 'There are currently no storage locations set up. Please create a location to store your photos before creating an album.',
|
||||||
'create_group' => 'Create a group',
|
'create_group' => 'Create a group',
|
||||||
'create_group_intro' => 'Complete the form below to create a group in which to organise your users.',
|
'create_group_intro' => 'Complete the form below to create a group in which to organise your users.',
|
||||||
|
'create_redirect_heading' => 'Add a Redirect',
|
||||||
|
'create_redirect_success_message' => 'The redirect was added successfully.',
|
||||||
|
'create_redirect_text' => 'Enter the source address you would like to redirect and click the Create button to add a new redirect to this album.',
|
||||||
'create_storage' => 'Create storage location',
|
'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.',
|
'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.',
|
||||||
'create_user' => 'Create user',
|
'create_user' => 'Create user',
|
||||||
@ -65,6 +69,9 @@ return [
|
|||||||
'delete_photo_message' => 'Are you sure you want to delete this photo? This action cannot be undone!',
|
'delete_photo_message' => 'Are you sure you want to delete this photo? This action cannot be undone!',
|
||||||
'delete_photo_successful_message' => 'The photo ":name" was deleted successfully.',
|
'delete_photo_successful_message' => 'The photo ":name" was deleted successfully.',
|
||||||
'delete_photo_title' => 'Delete photo',
|
'delete_photo_title' => 'Delete photo',
|
||||||
|
'delete_redirect_confirm_message' => 'Are you sure you want to remove this redirect?',
|
||||||
|
'delete_redirect_confirm_title' => 'Delete Album Redirect',
|
||||||
|
'delete_redirect_success_message' => 'The redirect was deleted successfully.',
|
||||||
'delete_storage' => 'Delete storage location: :name',
|
'delete_storage' => 'Delete storage location: :name',
|
||||||
'delete_storage_confirm' => 'Are you sure you want to permanently remove this storage location?',
|
'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_existing_albums' => 'At least one album is still using the storage location. Please delete all albums before removing the storage location.',
|
||||||
@ -84,6 +91,7 @@ return [
|
|||||||
'edit_storage_intro' => 'Use the form below to update the details of the :storage_name storage location.',
|
'edit_storage_intro' => 'Use the form below to update the details of the :storage_name storage location.',
|
||||||
'edit_user_intro' => 'You can use the form below to edit the above user account. Changes take effect immediately.',
|
'edit_user_intro' => 'You can use the form below to edit the above user account. Changes take effect immediately.',
|
||||||
'edit_user_title' => 'Edit user account: :name',
|
'edit_user_title' => 'Edit user account: :name',
|
||||||
|
'existing_album_redirects' => 'The following redirects exist for this album.',
|
||||||
'group_deletion_failed' => 'An error occurred while removing the ":name" group: :error_message',
|
'group_deletion_failed' => 'An error occurred while removing the ":name" group: :error_message',
|
||||||
'group_deletion_successful' => 'The ":name" group was removed successfully.',
|
'group_deletion_successful' => 'The ":name" group was removed successfully.',
|
||||||
'group_details_tab' => 'Details',
|
'group_details_tab' => 'Details',
|
||||||
@ -127,6 +135,10 @@ return [
|
|||||||
'rotate_left' => 'Rotate left',
|
'rotate_left' => 'Rotate left',
|
||||||
'rotate_right' => 'Rotate right'
|
'rotate_right' => 'Rotate right'
|
||||||
],
|
],
|
||||||
|
'redirects_heading' => 'Redirects',
|
||||||
|
'redirects_actions_heading' => 'Actions',
|
||||||
|
'redirects_source_url_heading' => 'Source Address',
|
||||||
|
'redirects_text' => 'To access this album using different addresses, you can use redirects. This is useful when you have moved the album to a different parent and the old address no longer works.',
|
||||||
'save_changes_heading' => 'Save changes',
|
'save_changes_heading' => 'Save changes',
|
||||||
'save_changes_intro' => 'If you have made any changes to the above fields, you\'ll need to hit the Save Changes button below.',
|
'save_changes_intro' => 'If you have made any changes to the above fields, you\'ll need to hit the Save Changes button below.',
|
||||||
'security_groups_heading' => 'Group Permissions',
|
'security_groups_heading' => 'Group Permissions',
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
return [
|
return [
|
||||||
'activate_user_label' => 'Manually activate this account',
|
'activate_user_label' => 'Manually activate this account',
|
||||||
'admin_user_label' => 'User is an administrator',
|
'admin_user_label' => 'User is an administrator',
|
||||||
|
'album_redirect_source' => 'Source address:',
|
||||||
|
'album_redirect_source_help' => 'The address must start with a forward-slash (/)',
|
||||||
|
'album_redirect_source_placeholder' => '(e.g. /my-new-album)',
|
||||||
'album_source_label' => 'Storage location:',
|
'album_source_label' => 'Storage location:',
|
||||||
'album_view_label' => 'View as:',
|
'album_view_label' => 'View as:',
|
||||||
'apply_action' => 'Apply',
|
'apply_action' => 'Apply',
|
||||||
@ -27,6 +30,7 @@ return [
|
|||||||
'register_action' => 'Create account',
|
'register_action' => 'Create account',
|
||||||
'remember_me_label' => 'Remember me',
|
'remember_me_label' => 'Remember me',
|
||||||
'remove_action' => 'Remove',
|
'remove_action' => 'Remove',
|
||||||
|
'save_action' => 'Save Changes',
|
||||||
'select' => 'Select',
|
'select' => 'Select',
|
||||||
'select_current_text' => '(current)',
|
'select_current_text' => '(current)',
|
||||||
'settings_hotlink_protection' => 'Prevent hot-linking to images',
|
'settings_hotlink_protection' => 'Prevent hot-linking to images',
|
||||||
@ -48,6 +52,5 @@ return [
|
|||||||
'storage_service_region_label' => 'Region:',
|
'storage_service_region_label' => 'Region:',
|
||||||
'storage_tenant_name_label' => 'Tenant:',
|
'storage_tenant_name_label' => 'Tenant:',
|
||||||
'username_label' => 'Username:',
|
'username_label' => 'Username:',
|
||||||
'upload_action' => 'Upload',
|
'upload_action' => 'Upload'
|
||||||
'save_action' => 'Save Changes'
|
|
||||||
];
|
];
|
@ -24,10 +24,11 @@
|
|||||||
@can('upload-photos', $album)
|
@can('upload-photos', $album)
|
||||||
@include(Theme::viewName('partials.tab'), ['tab_name' => 'upload', 'tab_icon' => 'upload', 'tab_text' => trans('admin.album_upload_tab')])
|
@include(Theme::viewName('partials.tab'), ['tab_name' => 'upload', 'tab_icon' => 'upload', 'tab_text' => trans('admin.album_upload_tab')])
|
||||||
@endcan
|
@endcan
|
||||||
|
@include(Theme::viewName('partials.tab'), ['tab_name' => 'cameras', 'tab_icon' => 'camera', 'tab_text' => trans('admin.album_cameras_tab')])
|
||||||
@can('change-permissions', $album)
|
@can('change-permissions', $album)
|
||||||
@include(Theme::viewName('partials.tab'), ['tab_name' => 'permissions', 'tab_icon' => 'lock', 'tab_text' => trans('admin.album_security_tab')])
|
@include(Theme::viewName('partials.tab'), ['tab_name' => 'permissions', 'tab_icon' => 'lock', 'tab_text' => trans('admin.album_security_tab')])
|
||||||
@endcan
|
@endcan
|
||||||
@include(Theme::viewName('partials.tab'), ['tab_name' => 'cameras', 'tab_icon' => 'camera', 'tab_text' => trans('admin.album_cameras_tab')])
|
@include(Theme::viewName('partials.tab'), ['tab_name' => 'redirects', 'tab_icon' => 'retweet', 'tab_text' => trans('admin.album_redirects_tab')])
|
||||||
@include(Theme::viewName('partials.tab'), ['tab_name' => 'settings', 'tab_icon' => 'cog', 'tab_text' => trans('admin.album_settings_tab')])
|
@include(Theme::viewName('partials.tab'), ['tab_name' => 'settings', 'tab_icon' => 'cog', 'tab_text' => trans('admin.album_settings_tab')])
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
@ -38,12 +39,14 @@
|
|||||||
{{-- Upload --}}
|
{{-- Upload --}}
|
||||||
@include(Theme::viewName('partials.album_upload_tab'))
|
@include(Theme::viewName('partials.album_upload_tab'))
|
||||||
@endcan
|
@endcan
|
||||||
|
{{-- Cameras --}}
|
||||||
|
@include(Theme::viewName('partials.album_cameras_tab'))
|
||||||
@can('change-permissions', $album)
|
@can('change-permissions', $album)
|
||||||
{{-- Permissions --}}
|
{{-- Permissions --}}
|
||||||
@include(Theme::viewName('partials.album_permissions_tab'))
|
@include(Theme::viewName('partials.album_permissions_tab'))
|
||||||
@endcan
|
@endcan
|
||||||
{{-- Cameras --}}
|
{{-- Redirects --}}
|
||||||
@include(Theme::viewName('partials.album_cameras_tab'))
|
@include(Theme::viewName('partials.album_redirects_tab'))
|
||||||
{{-- Settings --}}
|
{{-- Settings --}}
|
||||||
@include(Theme::viewName('partials.album_settings_tab'))
|
@include(Theme::viewName('partials.album_settings_tab'))
|
||||||
</div>
|
</div>
|
||||||
|
@ -0,0 +1,104 @@
|
|||||||
|
<div role="tabpanel" class="tab-pane{{ $active_tab == 'redirects' ? ' active' : '' }}" id="redirects-tab">
|
||||||
|
<h4>@lang('admin.redirects_heading')</h4>
|
||||||
|
<p>@lang('admin.redirects_text')</p>
|
||||||
|
@if ($album->redirects()->count() > 0)
|
||||||
|
<p>@lang('admin.existing_album_redirects')</p>
|
||||||
|
|
||||||
|
<table class="table table-striped table-responsive">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>@lang('admin.redirects_source_url_heading')</th>
|
||||||
|
<th style="width: 100px;">@lang('admin.redirects_actions_heading')</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach ($album->redirects as $redirect)
|
||||||
|
<tr>
|
||||||
|
<td><a href="{{ route('home') }}/a{{ $redirect->source_url }}">{{ route('home') }}/a{{ $redirect->source_url }}</a></td>
|
||||||
|
<td>
|
||||||
|
<form method="post" action="{{ route('albums.delete_redirect', [$album->id, $redirect->id]) }}">
|
||||||
|
{{ csrf_field() }}
|
||||||
|
{{ method_field('DELETE') }}
|
||||||
|
<input type="hidden" name="redirect_id" value="{{ $redirect->id }}" />
|
||||||
|
<button type="submit" class="btn btn-sm btn-danger delete-redirect">@lang('forms.delete_action')</button>
|
||||||
|
</form>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
@endif
|
||||||
|
|
||||||
|
<hr/>
|
||||||
|
<h5>@lang('admin.create_redirect_heading')</h5>
|
||||||
|
<p>@lang('admin.create_redirect_text')</p>
|
||||||
|
|
||||||
|
<form method="post" action="{{ route('albums.store_redirect', [$album->id]) }}">
|
||||||
|
{{ csrf_field() }}
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="redirect-source">@lang('forms.album_redirect_source')</label>
|
||||||
|
<input type="text" class="form-control{{ $errors->has('source_url') ? ' is-invalid' : '' }}" id="redirect-source" name="source_url" placeholder="@lang('forms.album_redirect_source_placeholder')" aria-describedby="redirect-source-help">
|
||||||
|
<small id="redirect-source-help" class="form-text text-muted">@lang('forms.album_redirect_source_help')</small>
|
||||||
|
|
||||||
|
@if ($errors->has('source_url'))
|
||||||
|
<div class="invalid-feedback">
|
||||||
|
<strong>{{ $errors->first('source_url') }}</strong>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-right">
|
||||||
|
<button type="submit" class="btn btn-success"><i class="fa fa-check"></i> @lang('forms.create_action')</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<!-- Delete redirect modal -->
|
||||||
|
<div class="modal" id="confirm-redirect-delete-modal">
|
||||||
|
<div class="modal-dialog" role="document">
|
||||||
|
<div class="modal-content">
|
||||||
|
<div class="modal-header">
|
||||||
|
<h5 class="modal-title">@lang('admin.delete_redirect_confirm_title')</h5>
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
<p>@lang('admin.delete_redirect_confirm_message')</p>
|
||||||
|
<p><strong class="redirect-url"></strong></p>
|
||||||
|
</div>
|
||||||
|
<div class="modal-footer">
|
||||||
|
<button type="button" class="btn btn-secondary" data-dismiss="modal">@lang('forms.cancel_action')</button>
|
||||||
|
<button type="button" class="btn btn-danger">@lang('forms.delete_action')</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@push('scripts')
|
||||||
|
<script type="text/javascript">
|
||||||
|
var source_form = null;
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('.btn-danger', '#confirm-redirect-delete-modal').click(function(e)
|
||||||
|
{
|
||||||
|
$(source_form).submit();
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.delete-redirect').click(function(e) {
|
||||||
|
source_form = $(this).closest('form');
|
||||||
|
$('#confirm-redirect-delete-modal').modal();
|
||||||
|
alert($(this).closest('a').html());
|
||||||
|
$('.redirect-url', '#confirm-redirect-delete-modal').html($(this).closest('a').html());
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endpush
|
@ -25,6 +25,8 @@ Route::group(['prefix' => 'admin'], function () {
|
|||||||
Route::get('albums/{id}/delete', 'Admin\AlbumController@delete')->name('albums.delete');
|
Route::get('albums/{id}/delete', 'Admin\AlbumController@delete')->name('albums.delete');
|
||||||
Route::post('albums/{id}/set-group-permissions', 'Admin\AlbumController@setGroupPermissions')->name('albums.set_group_permissions');
|
Route::post('albums/{id}/set-group-permissions', 'Admin\AlbumController@setGroupPermissions')->name('albums.set_group_permissions');
|
||||||
Route::post('albums/{id}/set-user-permissions', 'Admin\AlbumController@setUserPermissions')->name('albums.set_user_permissions');
|
Route::post('albums/{id}/set-user-permissions', 'Admin\AlbumController@setUserPermissions')->name('albums.set_user_permissions');
|
||||||
|
Route::delete('albums/{id}/delete-redirect/{redirectId}', 'Admin\AlbumController@deleteRedirect')->name('albums.delete_redirect');
|
||||||
|
Route::post('albums/{id}/store-redirect', 'Admin\AlbumController@storeRedirect')->name('albums.store_redirect');
|
||||||
Route::resource('albums', 'Admin\AlbumController');
|
Route::resource('albums', 'Admin\AlbumController');
|
||||||
|
|
||||||
// Photo management
|
// Photo management
|
||||||
|
Loading…
Reference in New Issue
Block a user