Initial commit: Pireon Admin — headless admin panel and public API
Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
103
app/Filament/Widgets/GrowthChart.php
Normal file
103
app/Filament/Widgets/GrowthChart.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Member;
|
||||
use App\Models\Project;
|
||||
use App\Models\RepositoryIssue;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
|
||||
class GrowthChart extends ChartWidget
|
||||
{
|
||||
protected static ?int $sort = 3;
|
||||
|
||||
public function getHeading(): string
|
||||
{
|
||||
return __('panel.widgets.growth_chart');
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$last30Days = collect(range(29, 0))->map(fn ($i) => Carbon::now()->subDays($i))->toArray();
|
||||
|
||||
$projectsData = array_map(
|
||||
fn (Carbon $date) => Project::query()
|
||||
->whereDate('created_at', '<=', $date)
|
||||
->published()
|
||||
->count(),
|
||||
$last30Days
|
||||
);
|
||||
|
||||
$membersData = array_map(
|
||||
fn (Carbon $date) => Member::query()
|
||||
->whereDate('created_at', '<=', $date)
|
||||
->public()
|
||||
->count(),
|
||||
$last30Days
|
||||
);
|
||||
|
||||
$issuesData = array_map(
|
||||
fn (Carbon $date) => RepositoryIssue::query()
|
||||
->whereDate('created_at', '<=', $date)
|
||||
->where('is_good_first_issue', true)
|
||||
->count(),
|
||||
$last30Days
|
||||
);
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => __('panel.widgets.growth.projects'),
|
||||
'data' => $projectsData,
|
||||
'borderColor' => '#3b82f6',
|
||||
'backgroundColor' => 'rgba(59, 130, 246, 0.1)',
|
||||
'tension' => 0.4,
|
||||
],
|
||||
[
|
||||
'label' => __('panel.widgets.growth.members'),
|
||||
'data' => $membersData,
|
||||
'borderColor' => '#10b981',
|
||||
'backgroundColor' => 'rgba(16, 185, 129, 0.1)',
|
||||
'tension' => 0.4,
|
||||
],
|
||||
[
|
||||
'label' => __('panel.widgets.growth.issues'),
|
||||
'data' => $issuesData,
|
||||
'borderColor' => '#f59e0b',
|
||||
'backgroundColor' => 'rgba(245, 158, 11, 0.1)',
|
||||
'tension' => 0.4,
|
||||
],
|
||||
],
|
||||
'labels' => array_map(fn (Carbon $date) => $date->format('M d'), $last30Days),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
|
||||
protected function getOptions(): array
|
||||
{
|
||||
return [
|
||||
'scales' => [
|
||||
'y' => [
|
||||
'beginAtZero' => true,
|
||||
],
|
||||
],
|
||||
'plugins' => [
|
||||
'legend' => [
|
||||
'display' => true,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function canView(): bool
|
||||
{
|
||||
return auth()->user()?->can('projects.view_any') ?? false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user