-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #34 - general settings added * #34 - js lint fix * #34 - cr fix * #34 - added one more test * #34 - validation fixes * - main page sections update feature * #35 - added some updates * #35 - section ordering fixes * #35 - added typography for tailwind * #35 - lintf
- Loading branch information
1 parent
cdca8e2
commit 2cdd712
Showing
24 changed files
with
845 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
enum SectionType: string | ||
{ | ||
case About = "about"; | ||
case Counter = "counter"; | ||
|
||
public static function labels(): array | ||
{ | ||
return [ | ||
"about" => __("About"), | ||
"counter" => __("Counters"), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Dashboard; | ||
|
||
use App\Enums\SectionType; | ||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\SectionRequest; | ||
use App\Models\Section; | ||
use App\Models\SectionSettings; | ||
use Illuminate\Http\RedirectResponse; | ||
use Inertia\Response; | ||
use Spatie\LaravelOptions\Options; | ||
|
||
class SectionController extends Controller | ||
{ | ||
public function show(): Response | ||
{ | ||
return inertia("Dashboard/Section/Show", [ | ||
"sectionTypes" => Options::forEnum(SectionType::class)->toArray(), | ||
"sectionSettings" => SectionSettings::query()->first(), | ||
"about" => Section::query()->about()->orderBy("created_at")->get(), | ||
"counters" => Section::query()->counter()->orderBy("created_at")->get(), | ||
]); | ||
} | ||
|
||
public function store(SectionRequest $request): RedirectResponse | ||
{ | ||
Section::query()->create($request->validated()); | ||
|
||
return redirect() | ||
->back() | ||
->with("success", "Dodano sekcję"); | ||
} | ||
|
||
public function update(SectionRequest $request, Section $section): RedirectResponse | ||
{ | ||
$section->update($request->validated()); | ||
|
||
return redirect() | ||
->back() | ||
->with("success", "Zaktualizowano sekcję"); | ||
} | ||
|
||
public function destroy(Section $section): RedirectResponse | ||
{ | ||
$section->delete(); | ||
|
||
return redirect() | ||
->back() | ||
->with("success", "Usunięto sekcję"); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
app/Http/Controllers/Dashboard/SectionSettingsController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Dashboard; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\SectionSettings; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
|
||
class SectionSettingsController extends Controller | ||
{ | ||
public function __invoke(Request $request): RedirectResponse | ||
{ | ||
SectionSettings::query()->first() | ||
->update([ | ||
"banner_enabled" => $request->boolean("banner_enabled"), | ||
"about_enabled" => $request->boolean("about_enabled"), | ||
"counters_enabled" => $request->boolean("counters_enabled"), | ||
"contact_enabled" => $request->boolean("contact_enabled"), | ||
]); | ||
|
||
return redirect() | ||
->back() | ||
->with("success", "Zaktualizowano ustawienia sekcji"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Requests; | ||
|
||
use App\Enums\SectionType; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Rules\Enum; | ||
|
||
class SectionRequest extends FormRequest | ||
{ | ||
public function rules(): array | ||
{ | ||
return [ | ||
"title" => ["required", "max:255"], | ||
"value" => ["required", "max:65000"], | ||
"type" => ["required", new Enum(SectionType::class)], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models; | ||
|
||
use App\Enums\SectionType; | ||
use Carbon\Carbon; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Casts\Attribute; | ||
use Illuminate\Database\Eloquent\Concerns\HasUlids; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Stevebauman\Purify\Facades\Purify; | ||
|
||
/** | ||
* @property string $id | ||
* @property string $title | ||
* @property string $value | ||
* @property SectionType $type | ||
* @property Carbon $created_at | ||
* @property Carbon $updated_at | ||
*/ | ||
class Section extends Model | ||
{ | ||
use HasFactory; | ||
use HasUlids; | ||
|
||
protected $fillable = [ | ||
"title", | ||
"value", | ||
"type", | ||
]; | ||
protected $casts = [ | ||
"type" => SectionType::class, | ||
]; | ||
|
||
public function scopeCounter(Builder $query): Builder | ||
{ | ||
return $query->where("type", SectionType::Counter->value); | ||
} | ||
|
||
public function scopeAbout(Builder $query): Builder | ||
{ | ||
return $query->where("type", SectionType::About->value); | ||
} | ||
|
||
protected function value(): Attribute | ||
{ | ||
return Attribute::make( | ||
set: fn(?string $value): string => Purify::clean($value), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Database\Eloquent\Concerns\HasUlids; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* @property string $id | ||
* @property bool $banner_enabled | ||
* @property bool $about_enabled | ||
* @property bool $counters_enabled | ||
* @property bool $contact_enabled | ||
* @property Carbon $created_at | ||
* @property Carbon $updated_at | ||
*/ | ||
class SectionSettings extends Model | ||
{ | ||
use HasUlids; | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
"banner_enabled", | ||
"about_enabled", | ||
"counters_enabled", | ||
"contact_enabled", | ||
]; | ||
protected $casts = [ | ||
"banner_enabled" => "boolean", | ||
"about_enabled" => "boolean", | ||
"counters_enabled" => "boolean", | ||
"contact_enabled" => "boolean", | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Enums\SectionType; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class SectionFactory extends Factory | ||
{ | ||
public function definition(): array | ||
{ | ||
return [ | ||
"title" => fake()->text(20), | ||
"value" => fake()->text(300), | ||
"type" => fake()->randomElement(SectionType::cases())->value, | ||
]; | ||
} | ||
|
||
public function counter(): static | ||
{ | ||
return $this->state(fn(array $attributes): array => [ | ||
"title" => fake()->numberBetween(1, 100), | ||
"value" => fake()->text(30), | ||
"type" => SectionType::Counter->value, | ||
]); | ||
} | ||
|
||
public function about(): static | ||
{ | ||
return $this->state(fn(array $attributes): array => [ | ||
"title" => fake()->text(30), | ||
"value" => fake()->text(300), | ||
"type" => SectionType::About->value, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories; | ||
|
||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class SectionSettingsFactory extends Factory | ||
{ | ||
public function definition(): array | ||
{ | ||
return [ | ||
"banner_enabled" => fake()->boolean, | ||
"about_enabled" => fake()->boolean, | ||
"counters_enabled" => fake()->boolean, | ||
"contact_enabled" => fake()->boolean, | ||
]; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
database/migrations/2023_10_18_193906_create_section_settings_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class() extends Migration { | ||
public function up(): void | ||
{ | ||
Schema::create("section_settings", function (Blueprint $table): void { | ||
$table->ulid("id")->primary(); | ||
$table->boolean("banner_enabled"); | ||
$table->boolean("about_enabled"); | ||
$table->boolean("counters_enabled"); | ||
$table->boolean("contact_enabled"); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists("section_settings"); | ||
} | ||
}; |
25 changes: 25 additions & 0 deletions
25
database/migrations/2023_10_18_193906_create_sections_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class() extends Migration { | ||
public function up(): void | ||
{ | ||
Schema::create("sections", function (Blueprint $table): void { | ||
$table->ulid("id")->primary(); | ||
$table->string("title"); | ||
$table->text("value"); | ||
$table->string("type"); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists("sections"); | ||
} | ||
}; |
Oops, something went wrong.