diff --git a/app/Http/Controllers/FeedsController.php b/app/Http/Controllers/FeedsController.php index 19b9074..f233e2d 100644 --- a/app/Http/Controllers/FeedsController.php +++ b/app/Http/Controllers/FeedsController.php @@ -67,4 +67,15 @@ public function destroy(Feed $feed): RedirectResponse return redirect()->route('feeds.index') ->with('success', 'Feed deleted successfully!'); } + + public function toggle(Feed $feed): RedirectResponse + { + $newStatus = !$feed->is_active; + $feed->update(['is_active' => $newStatus]); + + $status = $newStatus ? 'activated' : 'deactivated'; + + return redirect()->route('feeds.index') + ->with('success', "Feed {$status} successfully!"); + } } diff --git a/app/Http/Controllers/OnboardingController.php b/app/Http/Controllers/OnboardingController.php index b32d817..2403c25 100644 --- a/app/Http/Controllers/OnboardingController.php +++ b/app/Http/Controllers/OnboardingController.php @@ -7,19 +7,32 @@ use App\Models\PlatformChannel; use App\Models\PlatformInstance; use App\Services\SystemStatusService; +use App\Services\DashboardStatsService; use Illuminate\Http\Request; use Illuminate\View\View; use Illuminate\Http\RedirectResponse; class OnboardingController extends Controller { - public function index(): View|RedirectResponse + public function index(Request $request): View|RedirectResponse { // Check if user needs onboarding if (!$this->needsOnboarding()) { $systemStatus = resolve(SystemStatusService::class)->getSystemStatus(); + $statsService = resolve(DashboardStatsService::class); + + $period = $request->get('period', 'today'); + $stats = $statsService->getStats($period); + $systemStats = $statsService->getSystemStats(); + $availablePeriods = $statsService->getAvailablePeriods(); - return view('pages.dashboard', compact('systemStatus')); + return view('pages.dashboard', compact( + 'systemStatus', + 'stats', + 'systemStats', + 'availablePeriods', + 'period' + )); } return view('onboarding.welcome'); diff --git a/app/Services/DashboardStatsService.php b/app/Services/DashboardStatsService.php new file mode 100644 index 0000000..9b8d5db --- /dev/null +++ b/app/Services/DashboardStatsService.php @@ -0,0 +1,83 @@ +getDateRange($period); + + $articlesFetched = Article::when($dateRange, function ($query) use ($dateRange) { + return $query->whereBetween('created_at', $dateRange); + })->count(); + + $articlesPublished = ArticlePublication::when($dateRange, function ($query) use ($dateRange) { + return $query->whereBetween('published_at', $dateRange); + })->count(); + + $publishedPercentage = $articlesFetched > 0 + ? round(($articlesPublished / $articlesFetched) * 100, 1) + : 0.0; + + return [ + 'articles_fetched' => $articlesFetched, + 'articles_published' => $articlesPublished, + 'published_percentage' => $publishedPercentage, + ]; + } + + /** + * @return array + */ + public function getAvailablePeriods(): array + { + return [ + 'today' => 'Today', + 'week' => 'This Week', + 'month' => 'This Month', + 'year' => 'This Year', + 'all' => 'All Time', + ]; + } + + /** + * @return array{0: Carbon, 1: Carbon}|null + */ + private function getDateRange(string $period): ?array + { + $now = Carbon::now(); + + return match ($period) { + 'today' => [$now->copy()->startOfDay(), $now->copy()->endOfDay()], + 'week' => [$now->copy()->startOfWeek(), $now->copy()->endOfWeek()], + 'month' => [$now->copy()->startOfMonth(), $now->copy()->endOfMonth()], + 'year' => [$now->copy()->startOfYear(), $now->copy()->endOfYear()], + 'all' => null, // No date filtering for all-time stats + default => [$now->copy()->startOfDay(), $now->copy()->endOfDay()], + }; + } + + /** + * Get additional stats for dashboard + * @return array{total_feeds: int, active_feeds: int, total_channels: int, active_channels: int, total_routes: int, active_routes: int} + */ + public function getSystemStats(): array + { + return [ + 'total_feeds' => \App\Models\Feed::count(), + 'active_feeds' => \App\Models\Feed::where('is_active', true)->count(), + 'total_channels' => \App\Models\PlatformChannel::count(), + 'active_channels' => \App\Models\PlatformChannel::where('is_active', true)->count(), + 'total_routes' => \App\Models\Route::count(), + 'active_routes' => \App\Models\Route::where('is_active', true)->count(), + ]; + } +} \ No newline at end of file diff --git a/resources/views/pages/dashboard.blade.php b/resources/views/pages/dashboard.blade.php index 8944763..91ce35d 100644 --- a/resources/views/pages/dashboard.blade.php +++ b/resources/views/pages/dashboard.blade.php @@ -5,6 +5,19 @@

Dashboard

+ + +
+ + +
@if(session('success')) @@ -13,6 +26,60 @@
@endif + +
+ +
+
+
+
+ +
+
+
+
Articles Fetched
+
{{ number_format($stats['articles_fetched']) }}
+
+
+
+
+
+ + +
+
+
+
+ +
+
+
+
Articles Published
+
{{ number_format($stats['articles_published']) }}
+
+
+
+
+
+ + +
+
+
+
+ +
+
+
+
Published Rate
+
{{ $stats['published_percentage'] }}%
+
+
+
+
+
+
+
@@ -70,18 +137,30 @@
- +
-
+
-
-
-
Quick Stats
-
Coming Soon
-
+
+

System Configuration

+
+
+ +
+
+ Feeds + {{ $systemStats['active_feeds'] }}/{{ $systemStats['total_feeds'] }} +
+
+ Channels + {{ $systemStats['active_channels'] }}/{{ $systemStats['total_channels'] }} +
+
+ Routes + {{ $systemStats['active_routes'] }}/{{ $systemStats['total_routes'] }}
diff --git a/resources/views/pages/feeds/index.blade.php b/resources/views/pages/feeds/index.blade.php index 64eec8a..c5d5602 100644 --- a/resources/views/pages/feeds/index.blade.php +++ b/resources/views/pages/feeds/index.blade.php @@ -51,7 +51,19 @@
{{ $feed->status }}
-
+
+ +
+ @csrf + +
+ + View diff --git a/routes/web.php b/routes/web.php index 0d0ae8f..272b7ee 100644 --- a/routes/web.php +++ b/routes/web.php @@ -24,6 +24,7 @@ Route::resource('channels', App\Http\Controllers\PlatformChannelsController::class)->names('channels'); Route::post('/channels/{channel}/toggle', [App\Http\Controllers\PlatformChannelsController::class, 'toggle'])->name('channels.toggle'); Route::resource('feeds', App\Http\Controllers\FeedsController::class)->names('feeds'); +Route::post('/feeds/{feed}/toggle', [App\Http\Controllers\FeedsController::class, 'toggle'])->name('feeds.toggle'); Route::get('/routing', [App\Http\Controllers\RoutingController::class, 'index'])->name('routing.index'); Route::get('/routing/create', [App\Http\Controllers\RoutingController::class, 'create'])->name('routing.create');