Skip to content

Commit 418b261

Browse files
Adding missing icons type in the backend and db enums
1 parent 78bcbee commit 418b261

4 files changed

Lines changed: 43 additions & 2 deletions

File tree

app/Http/Controllers/ImageController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function update(Request $request, Image $image)
148148
'background' => [
149149
'sometimes',
150150
'required',
151-
'in:'.Image::BG_CUSTOM.','.Image::BG_TRANSPARENT.','.Image::BG_GRADIENT,
151+
'in:'.Image::BG_CUSTOM.','.Image::BG_TRANSPARENT.','.Image::BG_GRADIENT.','.Image::BG_ICONS,
152152
new ImageBackgroundRule($image),
153153
],
154154
// if mutable we would have to check the legal etc
@@ -215,7 +215,7 @@ public function store(Request $request, Image $image)
215215
],
216216
'background' => [
217217
'required',
218-
'in:'.Image::BG_CUSTOM.','.Image::BG_TRANSPARENT.','.Image::BG_GRADIENT,
218+
'in:'.Image::BG_CUSTOM.','.Image::BG_TRANSPARENT.','.Image::BG_GRADIENT.','.Image::BG_ICONS,
219219
new ImageBackgroundRule($image),
220220
],
221221
'type' => ['required', 'in:'.Image::TYPE_RAW.','.Image::TYPE_FINAL],

app/Image.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class Image extends Model
7070
public const BG_GRADIENT = 'gradient';
7171
public const BG_TRANSPARENT = 'transparent';
7272
public const BG_CUSTOM = 'custom';
73+
public const BG_ICONS = 'icons';
7374

7475
/**
7576
* The attributes that should be hidden for arrays.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use App\Image;
4+
use Illuminate\Support\Facades\Schema;
5+
use Illuminate\Database\Schema\Blueprint;
6+
use Illuminate\Database\Migrations\Migration;
7+
use Illuminate\Support\Facades\DB;
8+
9+
class AddIconsBackgroundToImagesTable extends Migration
10+
{
11+
/**
12+
* Run the migrations.
13+
*
14+
* @return void
15+
*/
16+
public function up()
17+
{
18+
DB::statement("ALTER TABLE images MODIFY COLUMN background ENUM('gradient', 'transparent', 'custom', 'icons') NOT NULL");
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
// ensure no rows use the 'icons' value
29+
DB::table('images')->where('background', 'icons')->update(['background' => 'gradient']);
30+
DB::statement("ALTER TABLE images MODIFY COLUMN background ENUM('gradient', 'transparent', 'custom') NOT NULL");
31+
}
32+
}

resources/js/components/organisms/OImageDialog.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ import {
183183
},
184184
185185
downloadLink() {
186+
if (!this.finalImageSrc) {
187+
return null;
188+
}
189+
186190
const url = new URL(this.finalImageSrc);
187191
url.searchParams.append('format', this.downloadImageFileExtension);
188192
url.searchParams.append('color_profile', this.colorEncoding);
@@ -334,6 +338,10 @@ import {
334338
},
335339
336340
processImage() {
341+
if (!this.finalImageSrc) {
342+
return Promise.reject(new Error('Image source not available yet'));
343+
}
344+
337345
// trigger a download to process the image on the server
338346
// it will cache processed image server sides and dramatically
339347
// increase ux when clicking the download button.

0 commit comments

Comments
 (0)