Skip to content

Commit 786cf64

Browse files
authored
Merge pull request #572 from code16/update-assets-button
Handle update assets button
2 parents 3dfd081 + cb32201 commit 786cf64

File tree

6 files changed

+66
-13
lines changed

6 files changed

+66
-13
lines changed

resources/views/components/alert/assets-outdated.blade.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,27 @@
77
@if($self->isAssetsOutdated())
88
<div class="fixed bottom-0 left-0 right-0 bg-background border-t p-4 z-50">
99
<div class="container">
10-
<div class="flex items-center space-x-4 md:space-x-6">
10+
<div class="flex flex-wrap items-center gap-4 md:gap-6">
1111
<div class="shrink-0">
1212
<svg class="w-6 h-6 stroke-[1.5]" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"/><path d="M12 9v4"/><path d="M12 17h.01"/></svg>
1313
</div>
14-
<div class="flex-1">
15-
<p class="mb-1">
16-
Sharp assets are out of date. Please run the following command:
17-
</p>
18-
<input class="w-full font-mono bg-inherit text-sm"
19-
value="php artisan vendor:publish --tag=sharp-assets --force"
20-
onclick="this.select()" aria-label="Command">
14+
<div class="flex-1 flex flex-col sm:flex-row sm:items-center gap-4 md:gap-6">
15+
<div class="flex-1">
16+
<p class="mb-1">
17+
Sharp assets are out of date. Please run the following command:
18+
</p>
19+
<input class="w-full font-mono bg-inherit text-sm"
20+
value="php artisan vendor:publish --tag=sharp-assets --force"
21+
onclick="this.select()" aria-label="Command">
22+
</div>
23+
<form action="{{ route('code16.sharp.update-assets') }}" method="post">
24+
@csrf
25+
<button class="inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 bg-primary text-primary-foreground hover:bg-primary/90 h-10 px-4 py-2"
26+
type="submit"
27+
>
28+
Update assets
29+
</button>
30+
</form>
2131
</div>
2232
</div>
2333
</div>

src/EntityList/Commands/Command.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Code16\Sharp\Utils\Traits\HandleLocalizedFields;
1313
use Code16\Sharp\Utils\Traits\HandlePageAlertMessage;
1414
use Code16\Sharp\Utils\Traits\HandleValidation;
15+
use Code16\Sharp\Utils\Traits\CanNotify;
1516
use Code16\Sharp\Utils\Transformers\WithCustomTransformers;
1617

1718
abstract class Command
@@ -22,6 +23,7 @@ abstract class Command
2223
use HandleValidation;
2324
use HasModalFormLayout;
2425
use WithCustomTransformers;
26+
use CanNotify;
2527

2628
protected int $groupIndex = 0;
2729
protected ?string $commandKey = null;
@@ -99,11 +101,6 @@ protected function streamDownload(string $fileContent, string $fileName): array
99101
];
100102
}
101103

102-
public function notify(string $title): SharpNotification
103-
{
104-
return new SharpNotification($title);
105-
}
106-
107104
/**
108105
* @param string|(\Closure(array $formData): string) $formModalTitle
109106
* @return $this

src/Form/SharpForm.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Code16\Sharp\Utils\Traits\HandleLocalizedFields;
1111
use Code16\Sharp\Utils\Traits\HandlePageAlertMessage;
1212
use Code16\Sharp\Utils\Traits\HandleValidation;
13+
use Code16\Sharp\Utils\Traits\CanNotify;
1314
use Code16\Sharp\Utils\Transformers\WithCustomTransformers;
1415

1516
abstract class SharpForm
@@ -20,6 +21,7 @@ abstract class SharpForm
2021
use HandlePageAlertMessage;
2122
use HandleValidation;
2223
use WithCustomTransformers;
24+
use CanNotify;
2325

2426
protected ?FormLayout $formLayout = null;
2527
protected bool $displayShowPageAfterCreation = false;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Code16\Sharp\Http\Controllers;
4+
5+
use Code16\Sharp\Utils\Traits\CanNotify;
6+
use Illuminate\Support\Facades\Artisan;
7+
8+
class UpdateAssetsController extends SharpProtectedController
9+
{
10+
use CanNotify;
11+
12+
public function __invoke()
13+
{
14+
try {
15+
Artisan::call('vendor:publish', [
16+
'--tag' => 'sharp-assets',
17+
'--force' => true
18+
]);
19+
} catch (\Exception $e) {
20+
$this->notify('Error while updating assets')->setLevelDanger();
21+
return redirect()->back();
22+
}
23+
24+
$this->notify('Assets updated successfully')->setLevelSuccess();
25+
return redirect()->back();
26+
}
27+
}

src/Utils/Traits/CanNotify.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Code16\Sharp\Utils\Traits;
4+
5+
use Code16\Sharp\Utils\SharpNotification;
6+
7+
trait CanNotify
8+
{
9+
public function notify(string $title): SharpNotification
10+
{
11+
return new SharpNotification($title);
12+
}
13+
}

src/routes/web.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Code16\Sharp\Http\Controllers\HomeController;
1111
use Code16\Sharp\Http\Controllers\ShowController;
1212
use Code16\Sharp\Http\Controllers\SingleShowController;
13+
use Code16\Sharp\Http\Controllers\UpdateAssetsController;
1314
use Illuminate\Support\Facades\Route;
1415

1516
Route::group([
@@ -61,4 +62,7 @@
6162

6263
Route::post('/filters/{filterKey}', [GlobalFilterController::class, 'update'])
6364
->name('code16.sharp.filters.update');
65+
66+
Route::post('/update-assets', UpdateAssetsController::class)
67+
->name('code16.sharp.update-assets');
6468
});

0 commit comments

Comments
 (0)