Skip to content

Commit

Permalink
replace layout and overlay to proper Enum types (#2015)
Browse files Browse the repository at this point in the history
* replace layout and overlay to proper Enum types
* sync Lychee-front
  • Loading branch information
ildyria authored Sep 16, 2023
1 parent f852b94 commit 8eb6310
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 53 deletions.
15 changes: 15 additions & 0 deletions app/Enum/AlbumLayoutType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Enum;

/**
* Enum AlbumLayoutType.
*
* All the allowed layout possibilities on Album
*/
enum AlbumLayoutType: string
{
case SQUARE = 'square';
case JUSTIFIED = 'justified';
case UNJUSTIFIED = 'unjustified';
}
16 changes: 16 additions & 0 deletions app/Enum/ImageOverlayType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Enum;

/**
* Enum ImageOverlayType.
*
* All the allowed overlay info on Photos
*/
enum ImageOverlayType: string
{
case NONE = 'none';
case DESC = 'desc';
case DATE = 'date';
case EXIF = 'exif';
}
4 changes: 2 additions & 2 deletions app/Http/Requests/Settings/AbstractSettingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
abstract class AbstractSettingRequest extends BaseApiRequest
{
protected string|int|bool $value;
protected string|int|bool|\BackedEnum $value;

protected string $name;

Expand All @@ -30,7 +30,7 @@ public function getSettingName(): string
return $this->name;
}

public function getSettingValue(): string|int|bool
public function getSettingValue(): string|int|bool|\BackedEnum
{
return $this->value;
}
Expand Down
12 changes: 5 additions & 7 deletions app/Http/Requests/Settings/SetImageOverlaySettingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@

namespace App\Http\Requests\Settings;

use Illuminate\Validation\Rule;
use App\Enum\ImageOverlayType;
use Illuminate\Validation\Rules\Enum;

class SetImageOverlaySettingRequest extends AbstractSettingRequest
{
public const ATTRIBUTE = 'image_overlay_type';

public function rules(): array
{
return [self::ATTRIBUTE => [
'required',
'string',
Rule::in(['none', 'desc', 'date', 'exif']),
],
return [
self::ATTRIBUTE => ['required', new Enum(ImageOverlayType::class)],
];
}

protected function processValidatedValues(array $values, array $files): void
{
$this->name = self::ATTRIBUTE;
$this->value = $values[self::ATTRIBUTE];
$this->value = ImageOverlayType::from($values[self::ATTRIBUTE]);
}
}
7 changes: 4 additions & 3 deletions app/Http/Requests/Settings/SetLayoutSettingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

namespace App\Http\Requests\Settings;

use Illuminate\Validation\Rule;
use App\Enum\AlbumLayoutType;
use Illuminate\Validation\Rules\Enum;

class SetLayoutSettingRequest extends AbstractSettingRequest
{
Expand All @@ -11,13 +12,13 @@ class SetLayoutSettingRequest extends AbstractSettingRequest
public function rules(): array
{
return [
self::ATTRIBUTE => ['required', Rule::in([0, 1, 2])],
self::ATTRIBUTE => ['required', new Enum(AlbumLayoutType::class)],
];
}

protected function processValidatedValues(array $values, array $files): void
{
$this->name = self::ATTRIBUTE;
$this->value = (int) $values[self::ATTRIBUTE];
$this->value = AlbumLayoutType::from($values[self::ATTRIBUTE]);
}
}
6 changes: 4 additions & 2 deletions app/Http/Resources/ConfigurationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use App\DTO\PhotoSortingCriterion;
use App\Enum\AlbumDecorationOrientation;
use App\Enum\AlbumDecorationType;
use App\Enum\AlbumLayoutType;
use App\Enum\DefaultAlbumProtectionType;
use App\Enum\ImageOverlayType;
use App\Enum\ThumbAlbumSubtitleType;
use App\Exceptions\Handler;
use App\Metadata\Versions\InstalledVersion;
Expand Down Expand Up @@ -131,10 +133,10 @@ public function toArray($request): array
'footer_show_social_media' => Configs::getValueAsBool('footer_show_social_media'),
'grants_download' => Configs::getValueAsBool('grants_download'),
'grants_full_photo_access' => Configs::getValueAsBool('grants_full_photo_access'),
'image_overlay_type' => Configs::getValueAsString('image_overlay_type'),
'image_overlay_type' => Configs::getValueAsEnum('image_overlay_type', ImageOverlayType::class),
'landing_page_enable' => Configs::getValueAsBool('landing_page_enable'),
'lang' => Configs::getValueAsString('lang'),
'layout' => Configs::getValueAsString('layout'),
'layout' => Configs::getValueAsEnum('layout', AlbumLayoutType::class),
'legacy_id_redirection' => Configs::getValueAsBool('legacy_id_redirection'),
'location_decoding' => Configs::getValueAsBool('location_decoding'),
'location_decoding_timeout' => Configs::getValueAsInt('location_decoding_timeout'),
Expand Down
70 changes: 70 additions & 0 deletions database/migrations/2023_09_16_070405_refactor_type_layout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class() extends Migration {
public const SQUARE = 'square';
public const JUSTIFIED = 'justified';
public const UNJUSTIFIED = 'unjustified';

/**
* Run the migrations.
*/
public function up(): void
{
/** @var int $layout */
$layout = DB::table('configs')->select('value')->where('key', '=', 'layout')->first()->value;
DB::table('configs')->where('key', '=', 'layout')->delete();
DB::table('configs')->insert([
[
'key' => 'layout',
'value' => $this->toEnum($layout),
'confidentiality' => 0,
'cat' => 'Gallery',
'type_range' => self::SQUARE . '|' . self::JUSTIFIED . '|' . self::UNJUSTIFIED,
'description' => 'Layout for pictures',
],
]);
}

/**
* Reverse the migrations.
*/
public function down(): void
{
/** @var string $layout */
$layout = DB::table('configs')->select('value')->where('key', '=', 'layout')->first()->value;
DB::table('configs')->where('key', '=', 'layout')->delete();
DB::table('configs')->insert([
[
'key' => 'layout',
'value' => $this->fromEnum($layout),
'confidentiality' => 0,
'cat' => 'Gallery',
'type_range' => '0|1|2',
'description' => 'Layout for pictures',
],
]);
}

private function toEnum(int $layout): string
{
return match ($layout) {
0 => self::SQUARE,
1 => self::JUSTIFIED,
2 => self::UNJUSTIFIED,
default => self::JUSTIFIED,
};
}

private function fromEnum(string $layout): int
{
return match ($layout) {
self::SQUARE => 0,
self::JUSTIFIED => 1,
self::UNJUSTIFIED => 2,
default => 1,
};
}
};
2 changes: 1 addition & 1 deletion public/dist/frontend.css

Large diffs are not rendered by default.

111 changes: 79 additions & 32 deletions public/dist/frontend.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions public/dist/landing.css
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ b {
user-select: none;
-webkit-transition: color 0.3s, opacity 0.3s ease-out, -webkit-transform 0.3s ease-out, -webkit-box-shadow 0.3s;
transition: color 0.3s, opacity 0.3s ease-out, -webkit-transform 0.3s ease-out, -webkit-box-shadow 0.3s;
-o-transition: color 0.3s, opacity 0.3s ease-out, transform 0.3s ease-out, box-shadow 0.3s;
transition: color 0.3s, opacity 0.3s ease-out, transform 0.3s ease-out, box-shadow 0.3s;
transition: color 0.3s, opacity 0.3s ease-out, transform 0.3s ease-out, box-shadow 0.3s, -webkit-transform 0.3s ease-out, -webkit-box-shadow 0.3s;
}
Expand Down Expand Up @@ -3772,7 +3771,6 @@ a {
padding: 5px 0 5px 0;
-webkit-transition: color 0.3s, opacity 0.3s ease-out, margin-left 0.5s, -webkit-transform 0.3s ease-out, -webkit-box-shadow 0.3s;
transition: color 0.3s, opacity 0.3s ease-out, margin-left 0.5s, -webkit-transform 0.3s ease-out, -webkit-box-shadow 0.3s;
-o-transition: color 0.3s, opacity 0.3s ease-out, transform 0.3s ease-out, box-shadow 0.3s, margin-left 0.5s;
transition: color 0.3s, opacity 0.3s ease-out, transform 0.3s ease-out, box-shadow 0.3s, margin-left 0.5s;
transition: color 0.3s, opacity 0.3s ease-out, transform 0.3s ease-out, box-shadow 0.3s, margin-left 0.5s, -webkit-transform 0.3s ease-out, -webkit-box-shadow 0.3s;
}
Expand Down
4 changes: 2 additions & 2 deletions public/dist/landing.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion tests/Feature/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public function testSetLang(): void
public function testSetLayout(): void
{
$this->sendKV('/Settings::setLayout', 'layout', 3, 422);
$this->sendKV('/Settings::setLayout', 'layout', 1);
$this->sendKV('/Settings::setLayout', 'layout', 'something', 422);
$this->sendKV('/Settings::setLayout', 'layout', 'justified');
}

// Route::post('/Settings::setDefaultLicense', [Administration\SettingsController::class, 'setDefaultLicense']);
Expand Down

0 comments on commit 8eb6310

Please sign in to comment.