Skip to content

Commit

Permalink
#35 - main page management (#68)
Browse files Browse the repository at this point in the history
* #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
kamilpiech97 authored Nov 9, 2023
1 parent cdca8e2 commit 2cdd712
Show file tree
Hide file tree
Showing 24 changed files with 845 additions and 49 deletions.
19 changes: 19 additions & 0 deletions app/Enums/SectionType.php
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"),
];
}
}
54 changes: 54 additions & 0 deletions app/Http/Controllers/Dashboard/SectionController.php
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 app/Http/Controllers/Dashboard/SectionSettingsController.php
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");
}
}
36 changes: 7 additions & 29 deletions app/Http/Controllers/Public/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace App\Http\Controllers\Public;

use App\Http\Controllers\Controller;
use App\Models\Section;
use App\Models\SectionSettings;
use App\Models\Setting;
use Inertia\Response;

Expand All @@ -14,6 +16,8 @@ public function __invoke(): Response
{
/** @var Setting $settings */
$settings = Setting::query()->first();
/** @var SectionSettings $sectionSettings */
$sectionSettings = SectionSettings::query()->first();

return inertia("Public/Home", [
"title" => $settings->teacher_titles,
Expand All @@ -22,35 +26,9 @@ public function __invoke(): Response
"department" => $settings->department_name,
"university" => $settings->university_name,
"universityLogo" => "https://irg2023.collegiumwitelona.pl/assets/logos/cwup.png",
"sections" => [
[
"header" => "Naukowo",
"paragraphs" => [
"Ukończyłem studia inżynierskie i magisterskie na kierunku Automatyka i Robotyka na Wydziale Elektroniki Politechniki Wrocławskiej. Specjalizowałem się, kolejno na studiach pierwszego i drugiego stopnia, w systemach informatycznych w automatyce oraz technologiach informacyjnych w systemach automatyki.",
"Od pierwszej połowy 2016 roku prowadzę zawodowe praktyki dla studentów i uczę praktycznie programowania w ramach różnych projektów. W 2017 można było usłyszeć mój wykład w ramach Otwartych Seminariów Naukowych. Od 2017 pracuję jako nauczyciel akademicki na Wydziale Nauk Technicznych i Ekonomicznych Collegium Witelona Uczelnia Państwowa, dawniej Państwowej Wyższej Szkoły Zawodowej im. Witelona w Legnicy.",
],
],
[
"header" => "Zawodowo",
"paragraphs" => [
"Od 2014 roku pracuję jako programista. Zaczynałem jako młodszy programista PHP w małym wrocławskim software housie, gdzie pod bacznym okiem specjalistów nauczyłem się realistycznego i praktycznego podejścia do zawodu. Później pracowałem w projektach dla międzynarodowych korporacji, firm z sektora MŚP oraz startupów. Od 2020 roku jestem dyrektorem ds. technologii w software housie Blumilk.",
"Zawsze gdy moge wybrać, programuję w PHP - najchętniej w najnowszej wersji oraz przede wszystkim w Laravelu. Mam zawodowe doświadczenie w pracy z przeróżnymi frameworkami JavaScriptu, Pythonem oraz C#.",
],
],
[
"header" => "Prywatnie",
"paragraphs" => [
"Urodziłem się i mieszkam od urodzenia w Legnicy (choć miałem w tym pięcioletnią przerwę na mieszkanie i studiowanie we Wrocławiu). W wolnym czasie lubię siedzieć nad książkami wszelkiego gatunku, śledzić przeróżne seriale oraz jeździć po legnickich i okolicznych drogach rowerowych.",
"Ponadto jestem piwowarem domowym, więc warzę w domu własnoręcznie piwo, jestem zapalonym fanem Gwiezdnych wojen, a także - a jakżeby inaczej! - programuję najróżniejsze rzeczy w najróżniejszych technologiach w najróżniejszym celu.",
],
],
],
"counters" => [
["id" => 1, "name" => "lat prowadzenia zajęć dydaktycznych na uczelni", "value" => 7],
["id" => 2, "name" => "kursów prowadzonych w tym semestrze", "value" => 5],
["id" => 3, "name" => "studentów na wykładach i innych zajęciach", "value" => 345],
["id" => 4, "name" => "średnia ocena wystawiona przez studentów w ankiecie nt. jakości kształcenia", "value" => 4.93],
],
"sectionSettings" => $sectionSettings,
"about" => $sectionSettings->about_enabled ? Section::query()->about()->orderBy("created_at")->get() : [],
"counters" => $sectionSettings->counters_enabled ? Section::query()->counter()->orderBy("created_at")->get() : [],
]);
}
}
21 changes: 21 additions & 0 deletions app/Http/Requests/SectionRequest.php
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)],
];
}
}
54 changes: 54 additions & 0 deletions app/Models/Section.php
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),
);
}
}
38 changes: 38 additions & 0 deletions app/Models/SectionSettings.php
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",
];
}
38 changes: 38 additions & 0 deletions database/factories/SectionFactory.php
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,
]);
}
}
20 changes: 20 additions & 0 deletions database/factories/SectionSettingsFactory.php
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,
];
}
}
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 database/migrations/2023_10_18_193906_create_sections_table.php
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");
}
};
Loading

0 comments on commit 2cdd712

Please sign in to comment.