Skip to content

Commit 4c1eb49

Browse files
committed
Improve admin page for idea
1 parent e4bed0a commit 4c1eb49

File tree

1 file changed

+85
-73
lines changed

1 file changed

+85
-73
lines changed

app/Orchid/Screens/Idea/ListScreen.php

+85-73
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44

55
use App\Models\IdeaKey;
66
use App\Models\IdeaRequest;
7+
use App\Orchid\Layouts\BasicIndicators;
8+
use Carbon\Carbon;
79
use Illuminate\Http\Request;
8-
use Illuminate\Support\Facades\Blade;
910
use Illuminate\Support\Facades\DB;
1011
use Illuminate\Support\Str;
1112
use Orchid\Screen\Actions\Link;
1213
use Orchid\Screen\Actions\ModalToggle;
14+
use Orchid\Screen\Components\Cells\Boolean;
1315
use Orchid\Screen\Components\Cells\DateTimeSplit;
1416
use Orchid\Screen\Fields\Input;
1517
use Orchid\Screen\Layouts\Persona;
@@ -27,12 +29,20 @@ class ListScreen extends Screen
2729
*/
2830
public function query(): iterable
2931
{
32+
$start = Carbon::now()->subMonth();
33+
$end = Carbon::now();
34+
3035
return [
36+
'charts' => [
37+
IdeaRequest::countByDays($start, $end)->toChart('Запросы'),
38+
IdeaKey::where('activated', 1)->countByDays($start, $end, 'updated_at')->toChart('Одобрения'),
39+
],
3140
'ideaRequests' => IdeaRequest::with(['user', 'key'])
3241
->defaultSort('created_at', 'desc')
3342
->filters()
3443
->paginate(),
3544
'metrics' => [
45+
'used_keys_month' => IdeaKey::where('activated', 1)->whereDate('updated_at', '>', $start)->count(),
3646
'unused_keys' => IdeaKey::where('activated', 0)->count(),
3747
'used_keys' => IdeaKey::where('activated', 1)->count(),
3848
],
@@ -56,7 +66,7 @@ public function name(): ?string
5666
*/
5767
public function description(): ?string
5868
{
59-
return '';
69+
return 'Вы можете просмотреть детали каждого запроса и статус выдачи ключа.';
6070
}
6171

6272
/**
@@ -69,89 +79,91 @@ public function commandBar(): iterable
6979
return [
7080
ModalToggle::make('Добавить ключи')
7181
->modal('addKeys')
72-
->method('addKeys'),
82+
->method('addKeys')
83+
->icon('file-earmark-arrow-up')
7384
];
7485
}
7586

7687
/**
7788
* The screen's layout elements.
7889
*
79-
* @throws \ReflectionException
80-
*
8190
* @return \Orchid\Screen\Layout[]|string[]
8291
*/
8392
public function layout(): iterable
8493
{
8594
return [
86-
Layout::metrics([
87-
'Выдано ключей:' => 'metrics.used_keys',
88-
'Не использовано ключей:' => 'metrics.unused_keys',
89-
]),
90-
91-
Layout::table('ideaRequests', [
92-
93-
TD::make('Пользователь')
94-
->cantHide()
95-
->width(230)
96-
->render(fn (IdeaRequest $ideaRequest) => new Persona($ideaRequest->user->presenter())),
97-
98-
/*
99-
TD::make('first_name','Имя')
100-
->width(150),
101-
TD::make('last_name','Фамилия')
102-
->width(150),
103-
104-
TD::make('city','Город')
105-
->width(150),
106-
TD::make('email','email')
107-
->width(150),
108-
*/
109-
110-
TD::make('message', 'Сообщение')
111-
->alignLeft()
112-
->render(fn (IdeaRequest $ideaRequest) => Str::of($ideaRequest->message)->trim()->words(10).Link::make()
113-
->class('hidden')
114-
->route('platform.idea.request', $ideaRequest->id)
115-
->stretched()
116-
)
117-
->width(300),
118-
119-
TD::make('key', 'Статус')
120-
->align(TD::ALIGN_RIGHT)
121-
->render(function (IdeaRequest $ideaRequest) {
122-
if ($ideaRequest->key()->exists()) {
123-
return Blade::render('<x-icon path="bs.check" height="1.5em" width="1.5em" />');
124-
}
125-
126-
return '';
127-
}),
128-
129-
TD::make('created_at', __('Created'))
130-
->width(120)
131-
->usingComponent(DateTimeSplit::class)
132-
->align(TD::ALIGN_RIGHT)
133-
->defaultHidden()
134-
->sort(),
135-
136-
TD::make('updated_at', 'Последнее обновление')
137-
->width(120)
138-
->usingComponent(DateTimeSplit::class)
139-
->defaultHidden()
140-
->align(TD::ALIGN_RIGHT)
141-
->sort(),
142-
]),
143-
144-
Layout::modal('addKeys', [
145-
Layout::rows([
146-
Input::make('file')
147-
->type('file')
148-
->accept('.txt')
149-
->required()
150-
->title('Выберите файл с ключами Laravel Idea')
151-
->help('Пожалуйста, выберите файл формата .txt, содержащий ключи для Laravel Idea. Каждый ключ должен быть на новой строке.'),
95+
Layout::split([
96+
BasicIndicators::make('charts')
97+
->description('Отслеживайте динамику запросов и выдачи ключей. Старайтесь не откладывать выдачу на последний день — это отражается на пиках на графике.')
98+
->title('Статистика за последние 30 дней')
99+
->height(285),
100+
101+
Layout::metrics([
102+
'Выдано за месяц:' => 'metrics.used_keys_month',
103+
'Общее количество выданных:' => 'metrics.used_keys',
104+
'Неактивированные ключи:' => 'metrics.unused_keys',
152105
]),
153-
])->title('Загрузка ключей Laravel Idea'),
106+
])->ratio('80/20'),
154107

108+
109+
Layout::table('ideaRequests', $this->getIdeaRequestsTableColumns()),
110+
111+
Layout::modal('addKeys', Layout::rows([
112+
Input::make('file')
113+
->type('file')
114+
->accept('.txt')
115+
->required()
116+
->title('Выберите файл с ключами для Laravel Idea')
117+
->help('Пожалуйста, выберите файл формата .txt, содержащий ключи, где каждый ключ на новой строчке.'),
118+
]))->title('Загрузка ключей'),
119+
];
120+
}
121+
122+
/**
123+
* Get the columns for the idea requests table.
124+
*
125+
* @return TD[]
126+
* @throws \ReflectionException
127+
*/
128+
private function getIdeaRequestsTableColumns(): array
129+
{
130+
return [
131+
TD::make('Пользователь')
132+
->cantHide()
133+
->width(230)
134+
->render(fn (IdeaRequest $ideaRequest) => new Persona($ideaRequest->user->presenter())),
135+
136+
TD::make('message', 'Сообщение')
137+
->alignLeft()
138+
->render(fn (IdeaRequest $ideaRequest) => Str::of($ideaRequest->message)->trim()->words(10)
139+
.Link::make()->class('hidden')
140+
->route('platform.idea.request', $ideaRequest->id)
141+
->stretched())
142+
->width(400),
143+
144+
TD::make('city', 'Город')
145+
->width(120)
146+
->align(TD::ALIGN_RIGHT),
147+
148+
TD::make('key', 'Статус')
149+
->width(50)
150+
->align(TD::ALIGN_RIGHT)
151+
->render(function (IdeaRequest $ideaRequest) {
152+
return \Orchid\Support\Blade::renderComponent(Boolean::class, ['value' => $ideaRequest->key()->exists()]);
153+
}),
154+
155+
TD::make('created_at', 'Создано')
156+
->width(120)
157+
->usingComponent(DateTimeSplit::class)
158+
->align(TD::ALIGN_RIGHT)
159+
->sort(),
160+
161+
TD::make('updated_at', 'Последнее обновление')
162+
->width(120)
163+
->usingComponent(DateTimeSplit::class)
164+
->defaultHidden()
165+
->align(TD::ALIGN_RIGHT)
166+
->sort(),
155167
];
156168
}
157169

@@ -181,6 +193,6 @@ public function addKeys(Request $request): void
181193
DB::table('idea_keys')->insertOrIgnore($keysForInsertion);
182194

183195
// Display a success message.
184-
Toast::info('Ключи успешно добавлены.');
196+
Toast::info('Ключи успешно добавлены! Теперь они доступны для использования.');
185197
}
186198
}

0 commit comments

Comments
 (0)