This commit is contained in:
Meghdad committed 2026-11-26 12:29:14 +03:30
commit 647c8a8cab
236 files changed
+24692

No files matched your search

+55
View File
@@ -0,0 +1,55 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Resources\Collections\CollectionResource;
use App\Filament\Resources\Designs\DesignResource;
use App\Filament\Resources\GarmentTemplates\GarmentTemplateResource;
use App\Models\Collection;
use App\Models\Design;
use App\Models\GarmentTemplate;
use Filament\Support\Icons\Heroicon;
use Filament\Widgets\StatsOverviewWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Illuminate\Support\Number;
class CatalogOverview extends StatsOverviewWidget
{
protected static ?int $sort = 10;
protected static ?bool $isLazyLoaded = false;
protected ?string $pollingInterval = null;
protected int|array|null $columns = ['default' => 2, '@xl' => 3];
protected function getHeading(): string
{
return __('admin.dashboard.overview');
}
protected function getStats(): array
{
$designs = Design::query()
->selectRaw('count(*) as total, count(*) - count(published_at) as drafts')
->selectSub(Design::visible()->selectRaw('count(*)'), 'visible')
->toBase()
->first();
return [
Stat::make(__('admin.dashboard.total_designs'), Number::format($designs->total, locale: 'fa'))
->icon(Heroicon::OutlinedSwatch)->url(DesignResource::getUrl('index')),
Stat::make(__('admin.dashboard.visible_designs'), Number::format($designs->visible, locale: 'fa'))
->icon(Heroicon::OutlinedGlobeAlt),
Stat::make(__('admin.dashboard.drafts'), Number::format($designs->drafts, locale: 'fa'))
->icon(Heroicon::OutlinedPencilSquare),
Stat::make(__('admin.dashboard.hidden_designs'), Number::format($designs->total - $designs->visible - $designs->drafts, locale: 'fa'))
->icon(Heroicon::OutlinedEyeSlash)
->description(__('admin.dashboard.hidden_description')),
Stat::make(__('admin.collections.plural'), Number::format(Collection::count(), locale: 'fa'))
->icon(Heroicon::OutlinedRectangleStack)->url(CollectionResource::getUrl('index')),
Stat::make(__('admin.garments.plural'), Number::format(GarmentTemplate::count(), locale: 'fa'))
->icon(Heroicon::OutlinedPhoto)->url(GarmentTemplateResource::getUrl('index')),
];
}
}
@@ -0,0 +1,104 @@
<?php
namespace App\Filament\Widgets;
use App\Models\Collection;
use Filament\Widgets\BarChartWidget;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection as Models;
use Illuminate\Support\Number;
use Illuminate\Support\Str;
class CollectionDesignChart extends BarChartWidget
{
private const LIMIT = 8;
protected static ?int $sort = 20;
protected static ?bool $isLazyLoaded = false;
protected ?string $pollingInterval = null;
protected ?string $maxHeight = '20rem';
/** @var Models<int, Collection>|null */
private ?Models $collections = null;
public function getHeading(): string
{
return __('admin.dashboard.collection_chart');
}
public function getDescription(): string
{
return __('admin.dashboard.chart_description', ['limit' => Number::format(self::LIMIT, locale: 'fa')]);
}
public function getEmptyStateHeading(): string
{
return __('admin.dashboard.empty_chart');
}
protected function getData(): array
{
$collections = $this->collections();
if (! $collections->max('designs_count')) {
return [];
}
return [
'labels' => $collections->map(fn (Collection $collection): string => Str::limit($collection->name_fa, 22))->all(),
'datasets' => [
[
'label' => __('admin.dashboard.on_site'),
'data' => $collections->pluck('visible_count')->all(),
'backgroundColor' => '#ad263f',
'maxBarThickness' => 24,
],
[
'label' => __('admin.dashboard.off_site'),
'data' => $collections->map(fn (Collection $collection): int => $collection->designs_count - $collection->visible_count)->all(),
'backgroundColor' => '#90827b',
'maxBarThickness' => 24,
],
],
];
}
public function getChartAssistiveContent(): string
{
return $this->collections()->map(fn (Collection $collection): string => __('admin.dashboard.chart_row', [
'name' => $collection->name_fa,
'visible' => Number::format($collection->visible_count, locale: 'fa'),
'hidden' => Number::format($collection->designs_count - $collection->visible_count, locale: 'fa'),
]))->implode(' ');
}
protected function getOptions(): array
{
return [
'indexAxis' => 'y',
'locale' => 'fa-IR',
'scales' => [
'x' => ['stacked' => true, 'reverse' => true, 'beginAtZero' => true, 'ticks' => ['precision' => 0]],
'y' => ['stacked' => true, 'position' => 'right', 'ticks' => ['autoSkip' => false]],
],
'plugins' => [
'legend' => ['rtl' => true, 'textDirection' => 'rtl'],
'tooltip' => ['rtl' => true, 'textDirection' => 'rtl'],
],
];
}
/** @return Models<int, Collection> */
private function collections(): Models
{
return $this->collections ??= Collection::query()
->withCount(['designs', 'designs as visible_count' => fn (Builder $query) => $query->visible()])
->orderByDesc('designs_count')
->orderBy('id')
->limit(self::LIMIT)
->get();
}
}
@@ -0,0 +1,88 @@
<?php
namespace App\Filament\Widgets;
use App\Models\DesignDailyView;
use Filament\Widgets\LineChartWidget;
use Illuminate\Support\Number;
use IntlDateFormatter;
class DesignTrafficChart extends LineChartWidget
{
private const DAYS = 14;
protected static ?int $sort = 25;
protected static ?bool $isLazyLoaded = false;
protected ?string $pollingInterval = null;
protected ?string $maxHeight = '20rem';
public function getHeading(): string
{
return __('admin.dashboard.traffic');
}
public function getDescription(): string
{
return __('admin.dashboard.traffic_summary', [
'views' => Number::format(array_sum($this->getCachedData()['datasets'][0]['data']), locale: 'fa'),
'days' => Number::format(self::DAYS, locale: 'fa'),
]);
}
public function getChartAssistiveContent(): string
{
$chart = $this->getCachedData();
return collect($chart['labels'])->map(fn (string $date, int $index): string => __('admin.dashboard.traffic_row', [
'date' => $date,
'views' => Number::format($chart['datasets'][0]['data'][$index], locale: 'fa'),
]))->implode(' ');
}
protected function getData(): array
{
$today = DesignDailyView::today();
$start = $today->subDays(self::DAYS - 1);
$dailyViews = DesignDailyView::query()
->whereBetween('viewed_on', [$start->toDateString(), $today->toDateString()])
->groupBy('viewed_on')
->selectRaw('viewed_on, sum(views) as total')
->pluck('total', 'viewed_on');
$formatter = new IntlDateFormatter('fa_IR@calendar=persian', IntlDateFormatter::NONE, IntlDateFormatter::NONE,
DesignDailyView::TIMEZONE, IntlDateFormatter::TRADITIONAL, 'd MMM');
$labels = [];
$counts = [];
for ($date = $start; $date <= $today; $date = $date->addDay()) {
$labels[] = $formatter->format($date);
$counts[] = (int) $dailyViews->get($date->toDateString(), 0);
}
return [
'labels' => $labels,
'datasets' => [[
'label' => __('admin.dashboard.daily_views'),
'data' => $counts,
'fill' => true,
]],
];
}
protected function getOptions(): array
{
return [
'locale' => 'fa-IR',
'scales' => [
'x' => ['reverse' => true, 'ticks' => ['maxTicksLimit' => 5, 'maxRotation' => 0]],
'y' => ['position' => 'right', 'beginAtZero' => true, 'suggestedMax' => 1, 'ticks' => ['precision' => 0]],
],
'plugins' => [
'legend' => ['display' => false],
'tooltip' => ['rtl' => true, 'textDirection' => 'rtl'],
],
];
}
}
+37
View File
@@ -0,0 +1,37 @@
<?php
namespace App\Filament\Widgets;
use App\Filament\Resources\Designs\DesignResource;
use App\Models\Design;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Filament\Widgets\TableWidget;
class RecentDesigns extends TableWidget
{
protected static ?int $sort = 30;
protected static ?bool $isLazyLoaded = false;
protected int|string|array $columnSpan = 'full';
public function table(Table $table): Table
{
return $table
->heading(__('admin.dashboard.recent_designs'))
->query(Design::query()->with('collection')->withSum('dailyViews as page_views', 'views')
->latest('updated_at')->orderByDesc('id')->limit(6))
->paginated(false)
->columns([
TextColumn::make('name_fa')->label(__('admin.designs.singular'))
->description(fn (Design $record): string => $record->collection->name_fa)
->wrap(),
TextColumn::make('updated_at')->label(__('admin.dashboard.last_updated'))
->since()->dateTimeTooltip(),
TextColumn::make('page_views')->label(__('admin.dashboard.total_page_views'))->default(0)->numeric(locale: 'fa'),
])
->recordUrl(fn (Design $record) => DesignResource::getUrl('view', ['record' => $record]))
->emptyStateHeading(__('admin.dashboard.no_designs'));
}
}