#2: Basic implementation of the quick-upload/quick-post feature

This commit is contained in:
Andy Heathershaw 2017-09-10 15:10:45 +01:00
parent d9d43e9c29
commit 544d3c5153
12 changed files with 94 additions and 4 deletions

18
app/Facade/Misc.php Normal file
View File

@ -0,0 +1,18 @@
<?php
namespace App\Facade;
use Illuminate\Support\Facades\Facade;
class Misc extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'misc';
}
}

View File

@ -43,7 +43,7 @@ class DbHelper
return $query->paginate(UserConfig::get('items_per_page'));
}
public static function getAlbumsForCurrentUser_NonPaged()
public static function getAlbumsForCurrentUser_NonPaged($permission = 'list')
{
$albumsQuery = Album::query();
$user = Auth::user();
@ -60,7 +60,7 @@ class DbHelper
->join('permissions', 'permissions.id', '=', 'album_anonymous_permissions.permission_id')
->where([
['permissions.section', 'album'],
['permissions.description', 'list']
['permissions.description', $permission]
]);
}
else
@ -78,12 +78,12 @@ class DbHelper
->where('albums.user_id', $user->id)
->orWhere([
['group_permissions.section', 'album'],
['group_permissions.description', 'list'],
['group_permissions.description', $permission],
['user_groups.user_id', $user->id]
])
->orWhere([
['user_permissions.section', 'album'],
['user_permissions.description', 'list'],
['user_permissions.description', $permission],
['album_user_permissions.user_id', $user->id]
]);
}

View File

@ -63,6 +63,9 @@ class GlobalConfiguration
{
$albums = DbHelper::getAlbumsForCurrentUser_NonPaged()->get();
View::share('albums', $albums);
$albumsToUpload = DbHelper::getAlbumsForCurrentUser_NonPaged('upload-photos')->get();
View::share('g_albums_upload', $albumsToUpload);
}
private function addLabelsToView()

View File

@ -38,6 +38,10 @@ class AppServiceProvider extends ServiceProvider
{
return $themeHelper;
});
$this->app->singleton('misc', function ($app)
{
return new MiscHelper();
});
$this->app->singleton('user_config', function ($app)
{
return new ConfigHelper();

View File

@ -78,6 +78,15 @@ class AuthServiceProvider extends ServiceProvider
return ($user->id == $photo->user_id);
});
Gate::define('photo.quick_upload', function($user)
{
$can = true;
$can &= $this->userHasAdminPermission($user, 'access');
$can &= $this->userHasAdminPermission($user, 'manage-albums');
return $can;
});
}
private function userHasAdminPermission(User $user, $permissionDescription)

View File

@ -227,6 +227,7 @@ return [
// Additional aliases added by AH
'Image' => \App\Facade\Image::class,
'Misc' => \App\Facade\Misc::class,
'Theme' => \App\Facade\Theme::class,
'UserConfig' => \App\Facade\UserConfig::class
],

View File

@ -2,6 +2,7 @@
return [
'activate_user_label' => 'Manually activate this account',
'admin_user_label' => 'User is an administrator',
'album_label' => 'Album:',
'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)',
@ -26,7 +27,9 @@ return [
'parent_album_placeholder' => 'None (top-level album)',
'password_label' => 'Password:',
'password_confirm_label' => 'Confirm password:',
'please_select' => '- Select an Option -',
'private_album_label' => 'Private album (only visible to me)',
'quick_upload_file_label' => 'Photo:',
'realname_label' => 'Your name:',
'register_action' => 'Create account',
'remember_me_label' => 'Remember me',

View File

@ -13,6 +13,10 @@ return [
'please_wait' => 'Please wait...',
'post_max_exceeded' => 'Your upload exceeded the maximum size the web server is configured to allow. Please check the value of the "post_max_size" parameter in php.ini.',
'powered_by' => 'Powered by :link_startBlue Twilight:link_end - the self-hosted PHP photo gallery software.',
'quick_upload' => [
'intro' => 'Use the quick upload feature to quickly add a new photo to an album.',
'title' => 'Quick Upload'
],
'units' => [
'megabytes' => 'MB'
]

View File

@ -30,6 +30,7 @@ return [
'labels' => 'Labels',
'login' => 'Login',
'logout' => 'Logout',
'quick_post' => 'Quick Upload',
'register' => 'Register',
'statistics' => 'Statistics'
]

View File

@ -87,6 +87,10 @@
@yield('content')
@can('photo.quick_upload')
@include(Theme::viewName('partials.quick_upload'))
@endcan
@if (isset($is_admin) && $is_admin)
@include(\App\Facade\Theme::viewName('partials.copyright_admin'))
@elseif (!\App\Facade\UserConfig::get('remove_copyright'))

View File

@ -1,5 +1,10 @@
<nav class="navbar navbar-expand-lg navbar-dark">
<a class="navbar-brand" href="{{ route('home') }}"><i class="fa fa-fw fa-photo"></i> {{ UserConfig::get('app_name') }}</a>
@can('photo.quick_upload')
<ul class="navbar-nav" style="min-width: 120px;">
<li class="nav-item"><a class="nav-link" href="#" data-toggle="modal" data-target="#quick-upload-modal"><i class="fa fa-plus"></i> @lang('navigation.navbar.quick_post')</a></li>
</ul>
@endcan
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-content" aria-controls="navbar-content" aria-expanded="false" aria-label="Toggle navigation">
<i class="fa fa-fw fa-bars"></i>
</button>

View File

@ -0,0 +1,38 @@
<form method="POST" action="{{ route('photos.store') }}" enctype="multipart/form-data">
{{ csrf_field() }}
<input type="hidden" name="queue_token" value="{{ Misc::randomString() }}"/>
<div class="modal" id="quick-upload-modal">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">@lang('global.quick_upload.title')</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p>@lang('global.quick_upload.intro')</p>
<div class="form-group">
<label class="control-label" for="quick-upload-file">@lang('forms.quick_upload_file_label')</label>
<input type="file" id="quick-upload-file" name="photo[]" class="form-control" multiple="multiple">
</div>
<div class="form-group">
<label class="control-label" for="quick-upload-album">@lang('forms.album_label')</label>
<select id="quick-upload-album" name="album_id" class="form-control">
<option>@lang('forms.please_select')</option>
@foreach ($g_albums_upload as $album)
<option value="{{ $album->id }}">{{ $album->name }}</option>
@endforeach
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-link" data-dismiss="modal">@lang('forms.cancel_action')</button>
<button type="submit" class="btn btn-success" onclick="this.disabled = true;"><i class="fa fa-upload"></i> @lang('forms.upload_action')</button>
</div>
</div>
</div>
</div>
</form>