#4: Added an admin screen to manage comments

This commit is contained in:
Andy Heathershaw 2018-09-21 15:00:07 +01:00
parent f2ba0e9475
commit 428c43a4c3
13 changed files with 126 additions and 1 deletions

View File

@ -16,6 +16,7 @@ use App\Http\Requests\SaveSettingsRequest;
use App\Label;
use App\Mail\TestMailConfig;
use App\Photo;
use App\PhotoComment;
use App\Services\GiteaService;
use App\Services\GithubService;
use App\Services\PhotoService;
@ -140,6 +141,7 @@ class DefaultController extends Controller
$photoCount = Photo::all()->count();
$groupCount = Group::all()->count();
$labelCount = Label::all()->count();
$commentCount = PhotoComment::whereNotNull('approved_at')->count();
$userCount = User::where('is_activated', true)->count();
$minMetadataVersion = Photo::min('metadata_version');
@ -157,6 +159,7 @@ class DefaultController extends Controller
return Theme::render('admin.index', [
'album_count' => $albumCount,
'app_version' => config('app.version'),
'comment_count' => $commentCount,
'group_count' => $groupCount,
'label_count' => $labelCount,
'memory_limit' => ini_get('memory_limit'),

View File

@ -0,0 +1,32 @@
<?php
namespace App\Http\Controllers\Admin;
use App\Facade\Theme;
use App\Facade\UserConfig;
use App\Http\Controllers\Controller;
use App\PhotoComment;
use Illuminate\Support\Facades\View;
class PhotoCommentController extends Controller
{
public function __construct()
{
$this->middleware('auth');
View::share('is_admin', true);
}
public function index()
{
$this->authorizeAccessToAdminPanel();
$comments = PhotoComment::with('photo')
->with('photo.album')
->orderBy('created_at', 'desc')
->paginate(UserConfig::get('items_per_page'));
return Theme::render('admin.list_comments', [
'comments' => $comments
]);
}
}

View File

@ -61,6 +61,11 @@ class PhotoComment extends Model
return $this->belongsTo(PhotoComment::class, 'parent_comment_id');
}
public function photo()
{
return $this->belongsTo(Photo::class);
}
public function textAsHtml()
{
$start = '<p>';

View File

@ -54,6 +54,10 @@ class AuthServiceProvider extends ServiceProvider
{
return $this->userHasAdminPermission($user, 'manage-albums');
});
Gate::define('admin:manage-comments', function ($user)
{
return $this->userHasAdminPermission($user, 'manage-comments');
});
Gate::define('admin:manage-groups', function ($user)
{
return $this->userHasAdminPermission($user, 'manage-groups');

View File

@ -72,6 +72,14 @@ class PermissionsSeeder extends Seeder
'is_default' => false,
'sort_order' => 0
]);
// admin:manage-comments = controls if photo comments can be managed
DatabaseSeeder::createOrUpdate('permissions', [
'section' => 'admin',
'description' => 'manage-comments',
'is_default' => false,
'sort_order' => 0
]);
}
private function seedAlbumPermissions()

View File

@ -62,6 +62,7 @@ return [
'cannot_remove_own_admin' => 'You cannot remove your own administrator permissions. Please ask another administrator to remove the administrator permissions for you.',
'change_album_message' => 'Please select the album to move the photo(s) to:',
'change_album_title' => 'Move photo(s) to another album',
'comment_summary' => ':album_name / :photo_name',
'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.',
@ -136,6 +137,8 @@ return [
'list_albums' => 'Go to your albums',
'list_albums_intro' => 'Albums contain collections of individual photographs in the same way as a physical photo album or memory book.',
'list_albums_title' => 'Albums',
'list_comments_intro' => 'Comments are messages left on your photos by visitors and users.',
'list_comments_title' => 'Comments',
'list_groups_intro' => 'Organise your users into categories or types by using groups. You can assign permissions on albums to groups of users to make administration and management easier.',
'list_groups_title' => 'Groups',
'list_labels_intro' => 'Organise your photos differently using labels. Assign one or more labels to your photos and your visitors can view all photos with a specific tag in a single view.',
@ -254,6 +257,7 @@ return [
'statistics_prefs_saved_message' => 'The statistics preferences were saved successfully.',
'stats_widget' => [
'albums' => 'album|albums',
'comments' => 'comment|comments',
'groups' => 'group|groups',
'labels' => 'label|labels',
'panel_header' => 'Statistics',

View File

@ -4,6 +4,7 @@ return [
'about' => 'About',
'admin' => 'Admin',
'albums' => 'Albums',
'comments' => 'Comments',
'create_album' => 'Create album',
'create_group' => 'Create group',
'create_storage' => 'Create storage',

View File

@ -4,6 +4,7 @@ return [
'access' => 'Access the administration panel',
'configure' => 'Configure the application',
'manage-albums' => 'Manage photo albums',
'manage-comments' => 'Manage comments',
'manage-groups' => 'Manage user groups',
'manage-labels' => 'Manage photo labels',
'manage-storage' => 'Manage storage locations',

View File

@ -87,6 +87,10 @@
'permission' => Theme::getPermission($all_permissions, 'admin', 'manage-labels')
])
@include(Theme::viewName('partials.permission_checkbox'), [
'permission' => Theme::getPermission($all_permissions, 'admin', 'manage-comments')
])
@include(Theme::viewName('partials.permission_checkbox'), [
'permission' => Theme::getPermission($all_permissions, 'admin', 'manage-users')
])

View File

@ -0,0 +1,54 @@
@extends(Theme::viewName('layout'))
@section('title', trans('admin.list_comments_title'))
@section('breadcrumb')
<li class="breadcrumb-item"><a href="{{ route('home') }}"><i class="fa fa-fw fa-home"></i></a></li>
<li class="breadcrumb-item"><a href="{{ route('admin') }}">@lang('navigation.breadcrumb.admin')</a></li>
<li class="breadcrumb-item active">@lang('navigation.breadcrumb.comments')</li>
@endsection
@section('content')
<div class="container">
<div class="row">
<div class="col">
<h1>@yield('title')</h1>
<div class="alert alert-info" style="margin-bottom: 30px;">
<i class="fa fa-fw fa-info"></i> @lang('admin.list_comments_intro')
</div>
@if (count($comments) == 0)
<div class="text-center">
<h4 class="text-danger"><b>@lang('admin.no_comments_title')</b></h4>
<p>@lang('admin.no_comments_text')</p>
<p style="margin-top: 40px;">
<a href="{{ route('comments.create') }}" class="btn btn-lg btn-success">@lang('admin.create_comment')</a>
</p>
</div>
@else
<table class="table table-hover table-striped">
<tbody>
@foreach ($comments as $comment)
<tr>
<td>
<p>
<a href="{{ route('comments.edit', ['id' => $comment->id]) }}"><span style="font-size: 1.3em;">{{ $comment->name }}</span></a><br/>
<span class="text-muted" style="font-size: smaller;">{{ trans('admin.comment_summary', ['album_name' => $comment->photo->album->name, 'photo_name' => $comment->photo->name]) }}</span>
</p>
<blockquote>{!! $comment->textAsHtml() !!}</blockquote>
</td>
<td class="text-right">
<a href="{{ route('comments.delete', ['id' => $comment->id]) }}" class="btn btn-danger">@lang('forms.delete_action')</a>
</td>
</tr>
@endforeach
</tbody>
</table>
<div class="text-center">
{{ $comments->links() }}
</div>
@endif
</div>
</div>
</div>
@endsection

View File

@ -5,6 +5,7 @@
$canManageLabels = Auth::user()->can('admin:manage-labels');
$canManageStorage = Auth::user()->can('admin:manage-storage');
$canManageUsers = Auth::user()->can('admin:manage-users');
$canManageComments = Auth::user()->can('admin:manage-comments');
@endphp
@if ($canConfigure || $canManageAlbums || $canManageGroups || $canManageStorage || $canManageUsers)
@ -17,6 +18,9 @@
@if ($canManageLabels)
<a class="btn btn-link" href="{{ route('labels.index') }}"><i class="fa fa-fw fa-tags"></i> @lang('navigation.breadcrumb.labels')</a>
@endif
@if ($canManageComments)
<a class="btn btn-link" href="{{ route('comments.index') }}"><i class="fa fa-fw fa-edit"></i> @lang('navigation.breadcrumb.comments')</a>
@endif
@if ($canManageUsers)
<a class="btn btn-link" href="{{ route('users.index') }}"><i class="fa fa-fw fa-user"></i> @lang('navigation.breadcrumb.users')</a>
@endif

View File

@ -2,7 +2,8 @@
<div class="card-header">@lang('admin.stats_widget.panel_header')</div>
<div class="card-body">
<b>{{ $album_count }}</b> {{ trans_choice('admin.stats_widget.albums', $album_count) }} &middot;
<b>{{ $photo_count }}</b> {{ trans_choice('admin.stats_widget.photos', $photo_count) }}<br/>
<b>{{ $photo_count }}</b> {{ trans_choice('admin.stats_widget.photos', $photo_count) }} &middot;
<b>{{ $comment_count }}</b> {{ trans_choice('admin.stats_widget.comments', $comment_count) }} <br/>
<b>{{ $label_count }}</b> {{ trans_choice('admin.stats_widget.labels', $label_count) }}
@can('admin:access')
<br/>

View File

@ -63,6 +63,10 @@ Route::group(['prefix' => 'admin'], function () {
// Group management
Route::get('groups/{id}/delete', 'Admin\GroupController@delete')->name('groups.delete');
Route::resource('groups', 'Admin\GroupController');
// Comments management
Route::get('comments/{id}/delete', 'Admin\PhotoCommentController@delete')->name('comments.delete');
Route::resource('comments', 'Admin\PhotoCommentController');
});
// Installation