Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#34 - general settings #65

Merged
merged 6 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions app/Http/Controllers/Dashboard/SettingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers\Dashboard;

use App\Http\Controllers\Controller;
use App\Http\Requests\SettingRequest;
use App\Models\Setting;
use Illuminate\Http\RedirectResponse;
use Inertia\Response;

class SettingController extends Controller
{
public function edit(): Response
{
return inertia("Dashboard/Setting/Edit", [
"settings" => Setting::query()->first(),
]);
}

public function update(SettingRequest $request): RedirectResponse
{
Setting::query()->first()
->update($request->validated());

return redirect()
->back()
->with("success", "Zaktualizowano ustawienia");
}
}
14 changes: 9 additions & 5 deletions app/Http/Controllers/Public/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@
namespace App\Http\Controllers\Public;

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

class HomeController extends Controller
{
public function __invoke(): Response
{
/** @var Setting $settings */
$settings = Setting::query()->first();

return inertia("Public/Home", [
"title" => "mgr inż.",
"name" => "Krzysztof Rewak",
"email" => "krzysztof.rewak@collegiumwitelona.pl",
"department" => "Zakład Informatyki, Wydział Nauk Technicznych i Ekonomicznych",
"university" => "Collegium Witelona Uczelnia Państwowa",
"title" => $settings->teacher_titles,
"name" => $settings->teacher_name,
"email" => $settings->teacher_email,
"department" => $settings->department_name,
"university" => $settings->university_name,
"universityLogo" => "https://irg2023.collegiumwitelona.pl/assets/logos/cwup.png",
"sections" => [
[
Expand Down
21 changes: 21 additions & 0 deletions app/Http/Requests/SettingRequest.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 Illuminate\Foundation\Http\FormRequest;

class SettingRequest extends FormRequest
{
public function rules(): array
{
return [
"teacher_name" => ["required", "max:255"],
"teacher_email" => ["required", "email", "max:255"],
"teacher_titles" => ["required", "max:255"],
"university_name" => ["required", "max:255"],
"department_name" => ["required", "max:255"],
];
}
}
34 changes: 34 additions & 0 deletions app/Models/Setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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 string $teacher_name
* @property string $teacher_email
* @property string $teacher_titles
* @property string $university_name
* @property string $department_name
* @property Carbon $created_at
* @property Carbon $updated_at
*/
class Setting extends Model
{
use HasFactory;
use HasUlids;

protected $fillable = [
"teacher_name",
"teacher_email",
"teacher_titles",
"university_name",
"department_name",
];
}
21 changes: 21 additions & 0 deletions database/factories/SettingFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

class SettingFactory extends Factory
{
public function definition(): array
{
return [
"teacher_titles" => "dr",
"teacher_name" => fake()->name,
"teacher_email" => fake()->email,
"department_name" => "Zakład Informatyki, Wydział Nauk Technicznych i Ekonomicznych",
"university_name" => "Collegium Witelona Uczelnia Państwowa",
];
}
}
27 changes: 27 additions & 0 deletions database/migrations/2023_10_18_193906_create_settings_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?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("settings", function (Blueprint $table): void {
$table->ulid("id")->primary();
$table->string("teacher_name")->nullable();
$table->string("teacher_email")->nullable();
$table->string("teacher_titles")->nullable();
$table->string("university_name")->nullable();
$table->string("department_name")->nullable();
$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists("settings");
}
};
2 changes: 2 additions & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Database\Seeders;

use App\Models\Setting;
use App\Models\User;
use Illuminate\Database\Seeder;

Expand All @@ -12,5 +13,6 @@ class DatabaseSeeder extends Seeder
public function run(): void
{
User::factory()->create(["email" => "admin@example.com"]);
Setting::factory()->create();
}
}
5 changes: 5 additions & 0 deletions lang/pl/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,10 @@
"abbreviation" => "skrótowiec",
"form" => "tryb studiów",
"type" => "typ zajęć",
"teacher_name" => "imię i nazwisko nauczyciela",
"teacher_email" => "adres e-mail nauczyciela",
"teacher_titles" => "tytuły/stopnie naukowe nauczyciela",
"university_name" => "nazwa uczelni",
"department_name" => "nazwa wydziału",
],
];
2 changes: 1 addition & 1 deletion resources/js/Layouts/DashboardLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const navigation = [
title: 'Ogólne',
elements: [
{ name: 'Dashboard', href: '/dashboard', icon: HomeIcon, current: true },
{ name: 'Ustawienia', href: '#', icon: Cog6ToothIcon, current: false },
{ name: 'Ustawienia', href: '/dashboard/settings', icon: Cog6ToothIcon, current: false },
{ name: 'Aktualizacja hasła', href: '/dashboard/password', icon: LockOpenIcon, current: false },
{ name: 'Aktualności', href: '/dashboard/news', icon: NewspaperIcon, current: false },
{ name: 'FAQ', href: '/dashboard/faqs', icon: QuestionMarkCircleIcon, current: false },
Expand Down
91 changes: 91 additions & 0 deletions resources/js/Pages/Dashboard/Setting/Edit.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<script setup>
import DashboardLayout from '@/Layouts/DashboardLayout.vue'
import Section from '@/Shared/Components/Section.vue'
import SubmitButton from '@/Shared/Components/Buttons/SubmitButton.vue'
import FormGroup from '@/Shared/Forms/FormGroup.vue'
import FormLabel from '@/Shared/Forms/FormLabel.vue'
import TextInput from '@/Shared/Forms/TextInput.vue'
import { useForm } from '@inertiajs/inertia-vue3'
import FormError from '@/Shared/Forms/FormError.vue'
import ManagementHeader from '@/Shared/Components/ManagementHeader.vue'
import ManagementHeaderItem from '@/Shared/Components/ManagementHeaderItem.vue'

const props = defineProps({
settings: Object,
})

const form = useForm({
teacher_name: props.settings.teacher_name,
teacher_email: props.settings.teacher_email,
teacher_titles: props.settings.teacher_titles,
university_name: props.settings.university_name,
department_name: props.settings.department_name,
})

function updateSettings() {
form.patch('/dashboard/settings')
}
</script>

<template>
<DashboardLayout>
<div class="flex flex-col gap-8">
<ManagementHeader>
<template #header>
Zarządzanie ustawieniami
</template>
<template #statistics>
<ManagementHeaderItem>
Formularz edycji ustawień
</ManagementHeaderItem>
</template>
</ManagementHeader>
<form class="grid grid-cols-2" @submit.prevent="updateSettings">
<Section>
<div class="flex flex-col justify-between gap-4">
<FormGroup>
<FormLabel for="teacher_name">
Imię i nazwisko nauczyciela
</FormLabel>
<TextInput id="teacher_name" v-model="form.teacher_name" :error="form.errors.teacher_name" autocomplete="off" />
<FormError :error="form.errors.teacher_name" />
</FormGroup>
<FormGroup>
<FormLabel for="teacher_email">
E-mail nauczyciela
</FormLabel>
<TextInput id="teacher_email" v-model="form.teacher_email" :error="form.errors.teacher_email" autocomplete="off" />
<FormError :error="form.errors.teacher_email" />
</FormGroup>
<FormGroup>
<FormLabel for="teacher_titles">
Tytuły nauczyciela
</FormLabel>
<TextInput id="teacher_titles" v-model="form.teacher_titles" :error="form.errors.teacher_titles" autocomplete="off" />
<FormError :error="form.errors.teacher_titles" />
</FormGroup>
<FormGroup>
<FormLabel for="university_name">
Nazwa uczelni
</FormLabel>
<TextInput id="university_name" v-model="form.university_name" :error="form.errors.university_name" autocomplete="off" />
<FormError :error="form.errors.university_name" />
</FormGroup>
<FormGroup>
<FormLabel for="department_name">
Nazwa wydziału
</FormLabel>
<TextInput id="department_name" v-model="form.department_name" :error="form.errors.department_name" autocomplete="off" />
<FormError :error="form.errors.department_name" />
</FormGroup>
<div class="mt-4 flex justify-end">
<SubmitButton>
Zapisz
</SubmitButton>
</div>
</div>
</Section>
</form>
</div>
</DashboardLayout>
</template>
5 changes: 5 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Http\Controllers\Dashboard\NewsManagementController;
use App\Http\Controllers\Dashboard\PasswordUpdateController;
use App\Http\Controllers\Dashboard\SemesterController;
use App\Http\Controllers\Dashboard\SettingController;
use App\Http\Controllers\Dashboard\StudentController;
use App\Http\Controllers\Public\HomeController;
use App\Http\Controllers\Public\LoginController;
Expand Down Expand Up @@ -119,4 +120,8 @@
Route::patch("/semester-courses/{course}/groups/{group}/grades/{gradeColumn}/update", "updateGrade")->name("course.semester.group.grades.update");
Route::post("/semester-courses/{course}/groups/{group}/grades/{gradeColumn}/reorder/{down}", "reorder")->name("course.semester.group.grades.reorder");
});
Route::controller(SettingController::class)->group(function (): void {
Route::get("/settings", "edit")->name("settings.edit");
Route::patch("/settings", "update")->name("settings.update");
});
});
6 changes: 3 additions & 3 deletions tests/Feature/ExampleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Tests\Feature;

use App\Models\Setting;
use Tests\TestCase;

class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function testTheApplicationReturnsASuccessfulResponse(): void
{
Setting::factory()->create();

$response = $this->get("/");

$response->assertStatus(200);
Expand Down
Loading
Loading