Skip to content

Commit 45dba60

Browse files
authored
Merge pull request #3440 from codeeu/dev
Add amazon to nova
2 parents ab360f8 + cffbf6d commit 45dba60

3 files changed

Lines changed: 69 additions & 4 deletions

File tree

app/Console/Commands/CertificateSendWindow.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,16 @@ private function sendWindowForType(int $edition, string $type, int $limit, bool
8383

8484
$queued = 0;
8585
$failed = 0;
86+
$failures = [];
8687

8788
foreach ($rows as $excellence) {
8889
$bar->advance();
8990
$user = $excellence->user;
9091
if (! $user || ! $user->email) {
92+
$err = 'No user or email';
9193
$failed++;
92-
$excellence->update(['certificate_sent_error' => 'No user or email']);
94+
$excellence->update(['certificate_sent_error' => $err]);
95+
$failures[] = ['id' => $excellence->id, 'email' => $user?->email ?? '-', 'error' => $err];
9396
continue;
9497
}
9598

@@ -105,14 +108,19 @@ private function sendWindowForType(int $edition, string $type, int $limit, bool
105108
]);
106109
$queued++;
107110
} catch (\Throwable $e) {
111+
$err = $e->getMessage();
108112
$failed++;
109-
$excellence->update(['certificate_sent_error' => $e->getMessage()]);
113+
$excellence->update(['certificate_sent_error' => $err]);
114+
$failures[] = ['id' => $excellence->id, 'email' => $user->email, 'error' => $err];
110115
}
111116
}
112117

113118
$bar->finish();
114119
$this->newLine();
115120
$this->line(" [{$type}] Done. Queued: {$queued}, Failed: {$failed}.");
121+
if ($failed > 0 && count($failures) > 0) {
122+
$this->table(['id', 'email', 'error'], $failures);
123+
}
116124
return ['processed' => $rows->count(), 'queued' => $queued, 'failed' => $failed];
117125
}
118126

app/Http/Controllers/CertificateBackendController.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public function listRecipients(Request $request): JsonResponse
7878
->where('edition', $edition)
7979
->where('type', $type)
8080
->with('user')
81+
->orderByRaw('CASE WHEN certificate_sent_error IS NOT NULL THEN 0 ELSE 1 END')
82+
->orderByRaw('CASE WHEN certificate_generation_error IS NOT NULL THEN 0 ELSE 1 END')
8183
->orderBy('id');
8284

8385
if ($search !== '') {
@@ -352,6 +354,8 @@ public function errorsList(Request $request)
352354
$q->whereNotNull('certificate_generation_error')->orWhereNotNull('certificate_sent_error');
353355
})
354356
->with('user')
357+
->orderByRaw('CASE WHEN certificate_sent_error IS NOT NULL THEN 0 ELSE 1 END')
358+
->orderByRaw('CASE WHEN certificate_generation_error IS NOT NULL THEN 0 ELSE 1 END')
355359
->orderBy('id')
356360
->get();
357361

app/Nova/HomeSlide.php

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,36 @@ public static function localeOptions(): array
9595

9696
private const OVERRIDE_KEYS = ['title', 'description', 'button_text', 'button2_text'];
9797

98+
private static function isAbsoluteImageUrl(?string $value): bool
99+
{
100+
if (! is_string($value) || trim($value) === '') {
101+
return false;
102+
}
103+
104+
return str_starts_with($value, 'http://') || str_starts_with($value, 'https://');
105+
}
106+
107+
private static function fillImageFromInputs($request, $model): void
108+
{
109+
$path = trim((string) $request->get('image_path_input', ''));
110+
$url = trim((string) $request->get('image_url_input', ''));
111+
112+
// URL wins when both are provided.
113+
if ($url !== '') {
114+
$model->image = $url;
115+
return;
116+
}
117+
118+
if ($path !== '') {
119+
$model->image = ltrim($path, '/');
120+
return;
121+
}
122+
123+
if ($request->exists('image_path_input') || $request->exists('image_url_input')) {
124+
$model->image = null;
125+
}
126+
}
127+
98128
private static function parseOverrideAttribute(string $attribute): ?array
99129
{
100130
if (! str_starts_with($attribute, 'override_') || strlen($attribute) < 12) {
@@ -227,9 +257,32 @@ public function fields(Request $request): array
227257
->help('Leave empty to hide second button. Lang key or plain text.'),
228258
Boolean::make('Open second link in new tab', 'open_second_new_tab')
229259
->help('Open the second button link in a new window/tab.'),
230-
Text::make('Image', 'image')
260+
Text::make('Image (saved value)', 'image')
261+
->exceptOnForms()
231262
->nullable()
232-
->help('Path from site root e.g. images/dream-jobs/dream_jobs_bg.png (no leading slash), or full URL. Used as slide background.'),
263+
->help('Stored image reference used by the homepage slider.'),
264+
Text::make('Image path (site root)', 'image_path_input')
265+
->onlyOnForms()
266+
->nullable()
267+
->resolveUsing(function () {
268+
$image = $this->resource->image;
269+
return self::isAbsoluteImageUrl($image) ? '' : (string) ($image ?? '');
270+
})
271+
->fillUsing(function ($request, $model) {
272+
self::fillImageFromInputs($request, $model);
273+
})
274+
->help('Option 1: local path like images/dream-jobs/dream_jobs_bg.png (no leading slash).'),
275+
Text::make('Image URL (full)', 'image_url_input')
276+
->onlyOnForms()
277+
->nullable()
278+
->resolveUsing(function () {
279+
$image = $this->resource->image;
280+
return self::isAbsoluteImageUrl($image) ? (string) $image : '';
281+
})
282+
->fillUsing(function ($request, $model) {
283+
self::fillImageFromInputs($request, $model);
284+
})
285+
->help('Option 2: full URL, e.g. https://codeweek-resources.s3.eu-west-1.amazonaws.com/...'),
233286
Number::make('Position', 'position')
234287
->min(0)
235288
->default(0)

0 commit comments

Comments
 (0)