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

#30 - configurable sections #140

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ DOCKER_DATABASE_HOST_PORT=53853
DOCKER_REDIS_HOST_PORT=53852
DOCKER_INSTALL_XDEBUG=true
DOCKER_HOST_USER_ID=1000

CONTACT_ENABLED=true
FAQ_ENABLED=true
NEWS_ENABLED=true
10 changes: 10 additions & 0 deletions app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function share(Request $request): array
return array_merge(parent::share($request), [
"auth" => $this->getAuthData($request),
"flash" => $this->getFlashData($request),
"sections" => $this->getSectionsData(),
]);
}

Expand All @@ -33,4 +34,13 @@ protected function getFlashData(Request $request): Closure
"info" => $request->session()->get("info"),
];
}

protected function getSectionsData(): array
{
return [
"faq_enabled" => config("keating.sections.faq_enabled"),
"contact_enabled" => config("keating.sections.contact_enabled"),
"news_enabled" => config("keating.sections.news_enabled"),
];
}
}
25 changes: 25 additions & 0 deletions app/Policies/UserPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Keating\Policies;

use Keating\Models\User;

class UserPolicy
{
public function faqEnabled(User $user): bool
{
return config("keating.sections.faq_enabled");
}

public function contactEnabled(User $user): bool
{
return config("keating.sections.contact_enabled");
}

public function newsEnabled(User $user): bool
{
return config("keating.sections.news_enabled");
}
}
11 changes: 11 additions & 0 deletions config/keating.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

return [
"sections" => [
"faq_enabled" => env("FAQ_ENABLED", true),
"contact_enabled" => env("CONTACT_ENABLED", true),
"news_enabled" => env("ABOUT_ENABLED", true),
],
];
63 changes: 39 additions & 24 deletions resources/js/Layouts/PublicLayout.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<script setup>
import { ref } from 'vue'
import { Link } from '@inertiajs/inertia-vue3'
import { Link, usePage } from '@inertiajs/inertia-vue3'
import { Dialog, DialogPanel } from '@headlessui/vue'
import { Bars3Icon, EllipsisHorizontalIcon, XMarkIcon } from '@heroicons/vue/24/outline'

const sections = usePage().props.value.sections
const navigation = [
{ name: 'Strona główna', href: '/' },
{ name: 'Aktualności', href: '/aktualnosci' },
{ name: 'Kursy i materiały', href: '/kursy' },
{ name: 'Oceny', href: '/oceny' },
{ name: 'FAQ', href: '/faq' },
{ name: 'Kontakt', href: '/kontakt' },
{ name: 'Strona główna', href: '/', enabled: true },
{ name: 'Aktualności', href: '/aktualnosci', enabled: true },
{ name: 'Kursy i materiały', href: '/kursy', enabled: true },
{ name: 'Oceny', href: '/oceny', enabled: true },
{ name: 'FAQ', href: '/faq', enabled: true },
{ name: 'Kontakt', href: '/kontakt', enabled: sections.contact_enabled },
]

const mobileMenuOpen = ref(false)
Expand All @@ -19,50 +20,64 @@ const mobileMenuOpen = ref(false)
<template>
<div class="flex h-screen flex-col">
<header class="absolute inset-x-0 top-0 z-50">
<nav class="flex items-center justify-between p-6 lg:px-8" aria-label="Global">
<nav aria-label="Global" class="flex items-center justify-between p-6 lg:px-8">
<div class="flex lg:hidden">
<button type="button" class="-m-2.5 inline-flex items-center justify-center rounded-md p-2.5 text-gray-700" @click="mobileMenuOpen = true">
<button class="-m-2.5 inline-flex items-center justify-center rounded-md p-2.5 text-gray-700" type="button"
@click="mobileMenuOpen = true"
>
<span class="sr-only">Otwórz menu</span>
<Bars3Icon class="size-6" aria-hidden="true" />
<Bars3Icon aria-hidden="true" class="size-6" />
</button>
</div>
<div class="hidden lg:flex lg:gap-x-12">
<Link v-for="item in navigation" :key="item.name" :href="item.href" class="text-sm font-semibold leading-6 text-gray-900">
{{ item.name }}
</Link>
<span v-for="item in navigation" :key="item.name">
<Link v-if="item.enabled" :href="item.href" class="text-sm font-semibold leading-6 text-gray-900">
{{ item.name }}
</Link>
</span>
</div>
<div class="hidden lg:flex lg:flex-1 lg:justify-end">
<Link v-if="$page.props.auth.user" href="/dashboard" class="text-sm font-semibold leading-6 text-gray-900">
<Link v-if="$page.props.auth.user" class="text-sm font-semibold leading-6 text-gray-900" href="/dashboard">
Dashboard
<span aria-hidden="true">&rarr;</span>
</Link>
<Link v-else href="/login" class="text-sm font-semibold leading-6 text-gray-900">
<Link v-else class="text-sm font-semibold leading-6 text-gray-900" href="/login">
Logowanie
<span aria-hidden="true">&rarr;</span>
</Link>
</div>
</nav>
<Dialog as="div" class="lg:hidden" :open="mobileMenuOpen" @close="mobileMenuOpen = false">
<Dialog :open="mobileMenuOpen" as="div" class="lg:hidden" @close="mobileMenuOpen = false">
<div class="fixed inset-0 z-50" />
<DialogPanel class="fixed inset-y-0 right-0 z-50 w-full overflow-y-auto bg-white p-6 sm:max-w-sm sm:ring-1 sm:ring-gray-900/10">
<DialogPanel
class="fixed inset-y-0 right-0 z-50 w-full overflow-y-auto bg-white p-6 sm:max-w-sm sm:ring-1 sm:ring-gray-900/10"
>
<div class="flex items-center justify-between">
<button type="button" class="-m-2.5 rounded-md p-2.5 text-gray-700" @click="mobileMenuOpen = false">
<button class="-m-2.5 rounded-md p-2.5 text-gray-700" type="button" @click="mobileMenuOpen = false">
<span class="sr-only">Close menu</span>
<XMarkIcon class="size-6" aria-hidden="true" />
<XMarkIcon aria-hidden="true" class="size-6" />
</button>
</div>
<div class="mt-6 flow-root">
<div class="-my-6 divide-y divide-gray-500/10">
<div class="space-y-2 py-6">
<Link v-for="item in navigation" :key="item.name" :href="item.href" class="-mx-3 block rounded-lg px-3 py-2 text-base font-semibold leading-7 text-gray-900 hover:bg-gray-50">
{{ item.name }}
</Link>
<span v-for="item in navigation" :key="item.name">
<Link v-if="item.enabled" :key="item.name" :href="item.href"
class="-mx-3 block rounded-lg px-3 py-2 text-base font-semibold leading-7 text-gray-900 hover:bg-gray-50"
>
{{ item.name }}
</Link>
</span>
</div>
<div class="py-6">
<Link v-if="$page.props.auth.user" href="/dashboard" class="-mx-3 block rounded-lg px-3 py-2.5 text-base font-semibold leading-7 text-gray-900 hover:bg-gray-50">
<Link v-if="$page.props.auth.user" class="-mx-3 block rounded-lg px-3 py-2.5 text-base font-semibold leading-7 text-gray-900 hover:bg-gray-50"
href="/dashboard"
>
Dashboard
</Link>
<Link v-else href="/login" class="-mx-3 block rounded-lg px-3 py-2.5 text-base font-semibold leading-7 text-gray-900 hover:bg-gray-50">
<Link v-else class="-mx-3 block rounded-lg px-3 py-2.5 text-base font-semibold leading-7 text-gray-900 hover:bg-gray-50"
href="/login"
>
Logowanie
</Link>
</div>
Expand Down
3 changes: 2 additions & 1 deletion routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@
use Keating\Http\Controllers\Public\HomeController;
use Keating\Http\Controllers\Public\LoginController;
use Keating\Http\Controllers\Public\NewsController;
use Keating\Models\User;

Route::get("/", HomeController::class)->name("main");
Route::get("/aktualnosci", [NewsController::class, "index"]);
Route::get("/aktualnosci/{slug}", [NewsController::class, "get"]);
Route::get("/oceny/{semester?}/{course?}/{group?}/{index?}", PublicGradeController::class);
Route::get("/kursy", [PublicCourseController::class, "index"]);
Route::get("/kursy/{slug}", [PublicCourseController::class, "get"]);
Route::get("/kontakt", ContactController::class);
Route::get("/kontakt", ContactController::class)->can("contactEnabled", User::class)->name("contact");

Route::middleware("guest")->group(function (): void {
Route::get("/login", [LoginController::class, "create"])->name("login");
Expand Down
Loading