mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-28 17:01:16 +00:00
Add reported releases widget to dashboard
This commit is contained in:
@@ -129,6 +129,11 @@ class AdminPageController extends BasePageController
|
||||
return \App\Models\DnzbFailure::count();
|
||||
});
|
||||
|
||||
// Cache reported releases count for 5 minutes
|
||||
$reportedCount = \Illuminate\Support\Facades\Cache::remember('admin_stats_reported_count', 300, function () {
|
||||
return \App\Models\ReleaseReport::where('status', 'pending')->count();
|
||||
});
|
||||
|
||||
// Today's counts can be cached for 1 minute since they change frequently
|
||||
$releasesToday = \Illuminate\Support\Facades\Cache::remember('admin_stats_releases_today_'.$today, 60, function () use ($today) {
|
||||
return \App\Models\Release::whereRaw('DATE(adddate) = ?', [$today])->count();
|
||||
@@ -146,6 +151,7 @@ class AdminPageController extends BasePageController
|
||||
'groups' => $groupsCount,
|
||||
'active_groups' => $activeGroupsCount,
|
||||
'failed' => $failedCount,
|
||||
'reported' => $reportedCount,
|
||||
'disk_free' => $this->getDiskSpace(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -3,11 +3,14 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ReleaseReport extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Release;
|
||||
use App\Models\ReleaseReport;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\ReleaseReport>
|
||||
*/
|
||||
class ReleaseReportFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var class-string<\App\Models\ReleaseReport>
|
||||
*/
|
||||
protected $model = ReleaseReport::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
$reasons = array_keys(ReleaseReport::REASONS);
|
||||
|
||||
return [
|
||||
'releases_id' => Release::factory(),
|
||||
'users_id' => User::factory(),
|
||||
'reason' => fake()->randomElement($reasons),
|
||||
'description' => fake()->optional()->sentence(),
|
||||
'status' => 'pending',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the report is pending.
|
||||
*/
|
||||
public function pending(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'pending',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the report has been reviewed.
|
||||
*/
|
||||
public function reviewed(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'reviewed',
|
||||
'reviewed_by' => User::factory(),
|
||||
'reviewed_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the report has been resolved.
|
||||
*/
|
||||
public function resolved(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'resolved',
|
||||
'reviewed_by' => User::factory(),
|
||||
'reviewed_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the report has been dismissed.
|
||||
*/
|
||||
public function dismissed(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'dismissed',
|
||||
'reviewed_by' => User::factory(),
|
||||
'reviewed_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Stats Grid -->
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-5 gap-6">
|
||||
<!-- Total Releases -->
|
||||
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm p-6 border border-gray-200 dark:border-gray-700">
|
||||
<div class="flex items-center justify-between">
|
||||
@@ -81,6 +81,24 @@
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Reported Releases -->
|
||||
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm p-6 border border-gray-200 dark:border-gray-700">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<p class="text-sm text-gray-500 dark:text-gray-400 mb-1">Reported Releases</p>
|
||||
<p class="text-3xl font-bold text-gray-800 dark:text-gray-200">{{ number_format($stats['reported'] ?? 0) }}</p>
|
||||
</div>
|
||||
<div class="w-12 h-12 bg-orange-100 dark:bg-orange-900 rounded-lg flex items-center justify-center">
|
||||
<i class="fas fa-flag text-2xl text-orange-600 dark:text-orange-400"></i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4">
|
||||
<a href="{{ url('/admin/release-reports') }}" class="text-sm text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-300">
|
||||
View reports <i class="fas fa-arrow-right"></i>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- User Statistics Widget -->
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
class AdminDashboardReportedReleasesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test that the dashboard blade template contains reported releases widget markup.
|
||||
*/
|
||||
public function test_dashboard_blade_contains_reported_releases_widget(): void
|
||||
{
|
||||
$bladePath = resource_path('views/admin/dashboard.blade.php');
|
||||
|
||||
$this->assertFileExists($bladePath);
|
||||
|
||||
$content = file_get_contents($bladePath);
|
||||
|
||||
// Check that the blade file contains the reported releases widget
|
||||
$this->assertStringContainsString('Reported Releases', $content);
|
||||
$this->assertStringContainsString("stats['reported']", $content);
|
||||
$this->assertStringContainsString('/admin/release-reports', $content);
|
||||
$this->assertStringContainsString('View reports', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the AdminPageController contains the reported count in stats.
|
||||
*/
|
||||
public function test_controller_stats_method_has_reported_key(): void
|
||||
{
|
||||
$controllerPath = app_path('Http/Controllers/Admin/AdminPageController.php');
|
||||
|
||||
$this->assertFileExists($controllerPath);
|
||||
|
||||
$content = file_get_contents($controllerPath);
|
||||
|
||||
// Check that the controller contains the reported releases count
|
||||
$this->assertStringContainsString("'reported'", $content);
|
||||
$this->assertStringContainsString('admin_stats_reported_count', $content);
|
||||
$this->assertStringContainsString('ReleaseReport::where', $content);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user