Add event fetching
This commit is contained in:
parent
38389f6fd7
commit
a4937bb6e9
|
@ -1 +1 @@
|
|||
Subproject commit e62934504bf2d33b65d0282a8d311df9cecb178e
|
||||
Subproject commit 10070f39ad7b91dee37f953325726e8b56694c6c
|
|
@ -4,8 +4,10 @@ namespace Silva\Adrema\Components;
|
|||
|
||||
use Cms\Classes\ComponentBase;
|
||||
use Cms\Classes\Page;
|
||||
use FetchAllEvents;
|
||||
use Silva\Adrema\Exceptions\ComponentException;
|
||||
use Silva\Adrema\Models\Settings;
|
||||
use Silva\Adrema\Support\FetchAllEvents as SupportFetchAllEvents;
|
||||
|
||||
class EventIndex extends ComponentBase
|
||||
{
|
||||
|
@ -13,7 +15,9 @@ class EventIndex extends ComponentBase
|
|||
public $settings;
|
||||
|
||||
/** @var string The active event */
|
||||
public ?string $event;
|
||||
public ?string $eventSlug;
|
||||
public ?array $event;
|
||||
public string $currentUrl;
|
||||
|
||||
public function componentDetails()
|
||||
{
|
||||
|
@ -26,12 +30,22 @@ class EventIndex extends ComponentBase
|
|||
public function onRun()
|
||||
{
|
||||
$this->addJs('assets/vendor/adrema-form/dist/main.js');
|
||||
$this->currentUrl = url()->current();
|
||||
// $this->addJs('http://localhost:5174/src/main.js', ['type' => 'module']);
|
||||
|
||||
$this->settings = [
|
||||
'primary_color' => Settings::get('primary_color'),
|
||||
...$this->resolvePageUrls(),
|
||||
];
|
||||
$this->event = $this->property('event');
|
||||
$this->eventSlug = $this->property('eventSlug');
|
||||
|
||||
if ($this->eventSlug) {
|
||||
$events = data_get(app(SupportFetchAllEvents::class)->run(), 'data');
|
||||
throw_if(is_null($events), ComponentException::class, 'event_fetching_failed');
|
||||
|
||||
$this->event = collect($events)->first(fn ($event) => $event['slug'] === $this->eventSlug);
|
||||
$this->page->title = $this->event['name'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -81,8 +95,8 @@ class EventIndex extends ComponentBase
|
|||
'type' => 'dropdown',
|
||||
'default' => null,
|
||||
],
|
||||
'event' => [
|
||||
'title' => __('properties.event_title'),
|
||||
'eventSlug' => [
|
||||
'title' => __('properties.event_slug_title'),
|
||||
'type' => 'text',
|
||||
'default' => null,
|
||||
],
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
{% if __SELF__.event %}
|
||||
{% put metatags %}
|
||||
<meta property="og:title" content="{{__SELF__.event.name}}">
|
||||
<meta property="og:url" content="{{__SELF__.currentUrl}}">
|
||||
<meta property="og:description" content="{{__SELF__.event.excerpt}}">
|
||||
<meta property="og:image" content="{{__SELF__.event.image}}">
|
||||
<meta property="og:type" content="article">
|
||||
{% endput %}
|
||||
{% endif %}
|
||||
|
||||
<event-index
|
||||
style="--primary: {{__SELF__.settings.primary_color}}; --primaryfg: #d1f8ff; --secondary: #800a19; --font: hsl(181, 84%, 78%); --circle: hsl(181, 86%, 16%)"
|
||||
index-url="{{__SELF__.settings.indexUrl}}"
|
||||
single-url="{{__SELF__.settings.singleUrl}}"
|
||||
register-url="{{__SELF__.settings.registerUrl}}"
|
||||
url="/api/silva_adrema_event_overview"
|
||||
{% if __SELF__.event %} event="{{__SELF__.event }}" {% endif %}
|
||||
{% if __SELF__.event %} event="{{__SELF__.event.slug }}" {% endif %}
|
||||
></event-index>
|
||||
|
|
|
@ -5,5 +5,5 @@
|
|||
"properties.index_page_title": "Seite für Übersicht",
|
||||
"properties.single_page_title": "Seite für Einzelansicht",
|
||||
"properties.register_page_title": "Seite zum anmelden",
|
||||
"properties.event_title": "Veranstaltung slug"
|
||||
"properties.event_slug_title": "Veranstaltung slug"
|
||||
}
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
"properties.index_page_title": "Page for overview",
|
||||
"properties.single_page_title": "Page for single view",
|
||||
"properties.register_page_title": "Page for registration",
|
||||
"properties.event_title": "Event slug",
|
||||
"properties.event_slug_title": "Event slug",
|
||||
"errors.not_all_pages_set": "You didn't assign all pages. Please edit your components.",
|
||||
"errors.page_not_found": "One page cannot be found. Event component cannot be rendered.",
|
||||
"errors.slug_not_found": "You need to set a placeholder in page urls to set the event slug (\":slug\")"
|
||||
"errors.slug_not_found": "You need to set a placeholder in page urls to set the event slug (\":slug\")",
|
||||
"errors.event_fetching_failed": "Failed to fetch event."
|
||||
}
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
<?php
|
||||
|
||||
use Silva\Adrema\Models\Settings;
|
||||
use Silva\Adrema\Support\FetchAllEvents;
|
||||
|
||||
Route::get('/api/silva_adrema_event_overview', function () {
|
||||
$baseUrl = Settings::get('base_url');
|
||||
$response = Http::get($baseUrl . '/api/form');
|
||||
$events = app(FetchAllEvents::class)->run();
|
||||
|
||||
if (!$response->ok()) {
|
||||
if (is_null($events)) {
|
||||
return Response::json(['message' => 'Fehler beim Laden der Veranstaltungen'], 422);
|
||||
}
|
||||
|
||||
return Response::json($response->json());
|
||||
return Response::json($events);
|
||||
})->middleware('api');
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Silva\Adrema\Support;
|
||||
|
||||
use Silva\Adrema\Models\Settings;
|
||||
use Http;
|
||||
|
||||
class FetchAllEvents
|
||||
{
|
||||
public function run(): ?array
|
||||
{
|
||||
$baseUrl = Settings::get('base_url');
|
||||
$response = Http::get($baseUrl . '/api/form');
|
||||
|
||||
if (!$response->ok()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $response->json();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue