4
4
5
5
use App \Models \IdeaKey ;
6
6
use App \Models \IdeaRequest ;
7
+ use App \Orchid \Layouts \BasicIndicators ;
8
+ use Carbon \Carbon ;
7
9
use Illuminate \Http \Request ;
8
- use Illuminate \Support \Facades \Blade ;
9
10
use Illuminate \Support \Facades \DB ;
10
11
use Illuminate \Support \Str ;
11
12
use Orchid \Screen \Actions \Link ;
12
13
use Orchid \Screen \Actions \ModalToggle ;
14
+ use Orchid \Screen \Components \Cells \Boolean ;
13
15
use Orchid \Screen \Components \Cells \DateTimeSplit ;
14
16
use Orchid \Screen \Fields \Input ;
15
17
use Orchid \Screen \Layouts \Persona ;
@@ -27,12 +29,20 @@ class ListScreen extends Screen
27
29
*/
28
30
public function query (): iterable
29
31
{
32
+ $ start = Carbon::now ()->subMonth ();
33
+ $ end = Carbon::now ();
34
+
30
35
return [
36
+ 'charts ' => [
37
+ IdeaRequest::countByDays ($ start , $ end )->toChart ('Запросы ' ),
38
+ IdeaKey::where ('activated ' , 1 )->countByDays ($ start , $ end , 'updated_at ' )->toChart ('Одобрения ' ),
39
+ ],
31
40
'ideaRequests ' => IdeaRequest::with (['user ' , 'key ' ])
32
41
->defaultSort ('created_at ' , 'desc ' )
33
42
->filters ()
34
43
->paginate (),
35
44
'metrics ' => [
45
+ 'used_keys_month ' => IdeaKey::where ('activated ' , 1 )->whereDate ('updated_at ' , '> ' , $ start )->count (),
36
46
'unused_keys ' => IdeaKey::where ('activated ' , 0 )->count (),
37
47
'used_keys ' => IdeaKey::where ('activated ' , 1 )->count (),
38
48
],
@@ -56,7 +66,7 @@ public function name(): ?string
56
66
*/
57
67
public function description (): ?string
58
68
{
59
- return '' ;
69
+ return 'Вы можете просмотреть детали каждого запроса и статус выдачи ключа. ' ;
60
70
}
61
71
62
72
/**
@@ -69,89 +79,91 @@ public function commandBar(): iterable
69
79
return [
70
80
ModalToggle::make ('Добавить ключи ' )
71
81
->modal ('addKeys ' )
72
- ->method ('addKeys ' ),
82
+ ->method ('addKeys ' )
83
+ ->icon ('file-earmark-arrow-up ' )
73
84
];
74
85
}
75
86
76
87
/**
77
88
* The screen's layout elements.
78
89
*
79
- * @throws \ReflectionException
80
- *
81
90
* @return \Orchid\Screen\Layout[]|string[]
82
91
*/
83
92
public function layout (): iterable
84
93
{
85
94
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 ' ,
152
105
]),
153
- ])->title ( ' Загрузка ключей Laravel Idea ' ),
106
+ ])->ratio ( ' 80/20 ' ),
154
107
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 (),
155
167
];
156
168
}
157
169
@@ -181,6 +193,6 @@ public function addKeys(Request $request): void
181
193
DB ::table ('idea_keys ' )->insertOrIgnore ($ keysForInsertion );
182
194
183
195
// Display a success message.
184
- Toast::info ('Ключи успешно добавлены. ' );
196
+ Toast::info ('Ключи успешно добавлены! Теперь они доступны для использования . ' );
185
197
}
186
198
}
0 commit comments