Add comments management to admin area

This commit is contained in:
DariusIII
2025-10-10 10:49:09 +02:00
parent 742921bafc
commit 214a8c1ed8
3 changed files with 152 additions and 9 deletions
@@ -4,35 +4,34 @@ namespace App\Http\Controllers\Admin;
use App\Http\Controllers\BasePageController;
use App\Models\ReleaseComment;
use Illuminate\Http\RedirectResponse;
use Illuminate\View\View;
class AdminCommentsController extends BasePageController
{
/**
* @throws \Exception
* Display a listing of comments
*/
public function index(): void
public function index(): View
{
$this->setAdminPrefs();
$meta_title = $title = 'Comments List';
$commentsList = ReleaseComment::getCommentsRange();
$this->smarty->assign('commentslist', $commentsList);
$content = $this->smarty->fetch('comments-list.tpl');
$this->smarty->assign(compact('title', 'meta_title', 'content'));
$this->adminrender();
return view('admin.comments.index', compact('commentsList', 'title', 'meta_title'));
}
/**
* @return \Illuminate\Http\RedirectResponse
* Delete a comment
*/
public function destroy(int $id)
public function destroy(int $id): RedirectResponse
{
if ($id) {
ReleaseComment::deleteComment($id);
}
return redirect()->back();
return redirect()->back()->with('success', 'Comment deleted successfully');
}
}
@@ -0,0 +1,138 @@
@extends('layouts.admin')
@section('content')
<div class="container mx-auto px-4 py-6">
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm">
<!-- Header -->
<div class="px-6 py-4 border-b border-gray-200 dark:border-gray-700">
<div class="flex justify-between items-center">
<h1 class="text-2xl font-semibold text-gray-800 dark:text-gray-200">
<i class="fas fa-comments mr-2"></i>{{ $title }}
</h1>
<div class="text-sm text-gray-600 dark:text-gray-400">
Total: {{ $commentsList->total() }} comments
</div>
</div>
</div>
<!-- Comments Table -->
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200 dark:divide-gray-700">
<thead class="bg-gray-50 dark:bg-gray-900">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">ID</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">User</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Comment</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Release</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Status</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Created</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody class="bg-white dark:bg-gray-800 divide-y divide-gray-200 dark:divide-gray-700">
@forelse($commentsList as $comment)
<tr class="hover:bg-gray-50 dark:hover:bg-gray-700">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-200 font-mono">
#{{ $comment->id }}
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex items-center">
<div>
<div class="text-sm font-medium text-gray-900 dark:text-gray-200">
{{ $comment->username }}
</div>
@if($comment->host)
<div class="text-xs text-gray-500 dark:text-gray-400">
{{ $comment->host }}
</div>
@endif
</div>
</div>
</td>
<td class="px-6 py-4">
<div class="text-sm text-gray-900 dark:text-gray-200 max-w-md">
<div class="line-clamp-2" title="{{ $comment->text }}">
{{ Str::limit($comment->text, 150) }}
</div>
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">
@if($comment->guid)
<a href="{{ url('details/' . $comment->guid) }}"
target="_blank"
class="text-blue-600 dark:text-blue-400 hover:text-blue-900 dark:hover:text-blue-300">
<i class="fas fa-external-link-alt mr-1"></i>View Release
</a>
@else
<span class="text-gray-500 dark:text-gray-400"></span>
@endif
</td>
<td class="px-6 py-4 whitespace-nowrap">
<div class="flex flex-col space-y-1">
@if($comment->isvisible)
<span class="px-2 py-1 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200">
<i class="fas fa-eye mr-1"></i>Visible
</span>
@else
<span class="px-2 py-1 inline-flex text-xs leading-5 font-semibold rounded-full bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200">
<i class="fas fa-eye-slash mr-1"></i>Hidden
</span>
@endif
@if($comment->shared)
<span class="px-2 py-1 inline-flex text-xs leading-5 font-semibold rounded-full bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200">
<i class="fas fa-share-alt mr-1"></i>Shared
</span>
@endif
@if($comment->issynced)
<span class="px-2 py-1 inline-flex text-xs leading-5 font-semibold rounded-full bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200">
<i class="fas fa-sync mr-1"></i>Synced
</span>
@endif
</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
<div>{{ $comment->created_at ? $comment->created_at->format('Y-m-d') : '—' }}</div>
<div class="text-xs">{{ $comment->created_at ? $comment->created_at->format('H:i:s') : '' }}</div>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
<form method="POST" action="{{ url('admin/comments-delete?id=' . $comment->id) }}" class="inline">
@csrf
<button type="submit"
class="text-red-600 dark:text-red-400 hover:text-red-900 dark:hover:text-red-300"
title="Delete"
onclick="return confirm('Are you sure you want to delete this comment?')">
<i class="fas fa-trash"></i>
</button>
</form>
</td>
</tr>
@empty
<tr>
<td colspan="7" class="px-6 py-4 text-center text-gray-500 dark:text-gray-400">
No comments found.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
<!-- Pagination -->
<div class="px-6 py-4 bg-gray-50 dark:bg-gray-900 border-t border-gray-200 dark:border-gray-700">
{{ $commentsList->links() }}
</div>
</div>
</div>
@push('styles')
<style>
.line-clamp-2 {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
</style>
@endpush
@endsection
@@ -42,6 +42,12 @@
</div>
</div>
<!-- Comments -->
<a href="{{ url('/admin/comments-list') }}" class="flex items-center space-x-3 text-gray-300 dark:text-gray-400 hover:text-white dark:hover:text-white hover:bg-gray-800 dark:hover:bg-gray-800 py-2 px-3 rounded transition mb-4">
<i class="fas fa-comments"></i>
<span>Comments</span>
</a>
<!-- Releases -->
<div class="mb-4">
<button type="button" class="flex items-center justify-between w-full text-left text-gray-300 dark:text-gray-400 hover:text-white dark:hover:text-white transition" onclick="toggleAdminSubmenu('releases-menu')">