Add description

This commit is contained in:
philipp lang 2024-02-04 01:12:22 +01:00
parent 7fa4948999
commit c83c892f53
10 changed files with 97 additions and 12 deletions

View File

@ -3,6 +3,7 @@
namespace Silva\Adrema;
use Backend;
use Silva\Adrema\Components\EventDescription;
use Silva\Adrema\Components\EventIndex;
use Silva\Adrema\Components\EventRegister;
use Silva\Adrema\Models\Settings;
@ -52,6 +53,7 @@ class Plugin extends PluginBase
return [
EventIndex::class => 'adrema_event_index',
EventRegister::class => 'adrema_event_register',
EventDescription::class => 'adrema_event_description',
];
}

@ -1 +1 @@
Subproject commit c55bb174c2caa5ed1cda99a04c877455e0387f13
Subproject commit 9666310ebfa9125ea0d2771b63166b39d7179999

View File

@ -0,0 +1,17 @@
<?php
namespace Silva\Adrema\Components;
class EventDescription extends EventManager
{
public function onRun()
{
$this->loadColors();
$this->loadSingleEvent();
}
public function isRegistering(): bool
{
return false;
}
}

View File

@ -4,4 +4,8 @@ namespace Silva\Adrema\Components;
class EventIndex extends EventManager
{
protected function isRegistering(): bool
{
return false;
}
}

View File

@ -2,18 +2,24 @@
namespace Silva\Adrema\Components;
use Illuminate\Support\Collection;
use Cms\Classes\ComponentBase;
use Cms\Classes\Page;
use Silva\Adrema\Exceptions\ComponentException;
use Silva\Adrema\Models\Settings;
use Silva\Adrema\Support\FetchAllEvents;
use Silva\Adrema\Support\FetchSingleEvent;
abstract class EventManager extends ComponentBase
{
public array $settings;
public ?array $event;
public array $settings = [];
public ?array $event = null;
/** @var Collection<int, mixed> */
public Collection $events;
public string $currentUrl;
abstract protected function isRegistering(): bool;
public function componentDetails()
{
@ -28,8 +34,34 @@ abstract class EventManager extends ComponentBase
public function onRun()
{
$this->addAssets();
$this->loadColors();
$this->loadSettings();
$this->loadSingleEvent();
$this->page['breadcrumbs'] = $this->getBreadcrumbs();
}
private function getBreadcrumbs(): Collection
{
$breadcrumbs = collect([]);
$breadcrumbs->push(['url' => $this->settings['indexUrl'], 'title' => 'Veranstaltungen', 'isActive' => $this->event === null]);
if ($this->event) {
$breadcrumbs->push([
'url' => (string) str($this->settings['singleUrl'])->replace(':slug', $this->event['slug']),
'title' => $this->event['name'],
'isActive' => !$this->isRegistering()
]);
}
if ($this->event && $this->isRegistering()) {
$breadcrumbs->push([
'url' => (string) str($this->settings['registerUrl'])->replace(':slug', $this->event['slug']),
'title' => 'Anmeldung',
'isActive' => true,
]);
}
return $breadcrumbs;
}
public function defineProperties()
@ -109,7 +141,7 @@ abstract class EventManager extends ComponentBase
];
}
private function loadSingleEvent(): void
protected function loadSingleEvent(): void
{
$eventSlug = $this->property('eventSlug');
@ -117,8 +149,8 @@ abstract class EventManager extends ComponentBase
return;
}
$this->event = app(FetchSingleEvent::class)->run($eventSlug);
$this->page->title = $this->event['name'];
$this->events = $this->page['events'] = collect(app(FetchAllEvents::class)->run()['data']);
$this->event = $this->page['event'] = $this->events->first(fn ($event) => $event['slug'] == $eventSlug);
$this->currentUrl = url()->current();
}
@ -131,8 +163,16 @@ abstract class EventManager extends ComponentBase
private function loadSettings(): void
{
$this->settings = [
'primary_color' => Settings::get('primary_color'),
...$this->settings,
...$this->resolvePageUrls(),
];
}
protected function loadColors(): void
{
$this->settings = [
...$this->settings,
'primary_color' => Settings::get('primary_color'),
];
}
}

View File

@ -4,4 +4,8 @@ namespace Silva\Adrema\Components;
class EventRegister extends EventManager
{
protected function isRegistering(): bool
{
return true;
}
}

View File

@ -0,0 +1,9 @@
<script type="text/javascript">
var adrema_event_description = {{__SELF__.event.description | json_encode | raw}};
</script>
<event-description
description-var-name="adrema_event_description"
style="--primary: {{__SELF__.settings.primary_color}}; --primaryfg: #d1f8ff; --secondary: #800a19; --font: hsl(181, 84%, 78%); --circle: hsl(181, 86%, 16%)"
image="{{__SELF__.event.image }}"
></event-description>

View File

@ -5,4 +5,5 @@
index-url="{{__SELF__.settings.indexUrl}}"
single-url="{{__SELF__.settings.singleUrl}}"
register-url="{{__SELF__.settings.registerUrl}}"
config-var-name="adrema_event_config"
></event-form>

View File

@ -2,10 +2,17 @@
namespace Silva\Adrema\Support;
use Illuminate\Support\Collection;
class FetchAllEvents
{
public function run(): ?array
public function run(): ?Collection
{
return app(Proxy::class)->run('/api/form');
$events = app(Proxy::class)->run('/api/form');
if (!$events) {
return null;
}
return collect($events);
}
}

View File

@ -6,13 +6,14 @@
<meta property="og:image" content="{{__SELF__.event.image}}">
<meta property="og:type" content="article">
{% endput %}
<script type="text/javascript">
var adrema_event_config = {{__SELF__.event.config | json_encode | raw}};
</script>
{% endif %}
{% put metatags %}
<meta name="adrema_base_url" content="/adrema-api">
{% endput %}
<script type="text/javascript">
var adrema_event = {{__SELF__.event.config | json_encode | raw}};
</script>