Compare commits
No commits in common. "38389f6fd790eea6eeb1d9392673f47394fec363" and "b82041937e98c3c7dd67902f9b8e16e785378f9a" have entirely different histories.
38389f6fd7
...
b82041937e
|
@ -3,7 +3,6 @@
|
|||
namespace Silva\Adrema;
|
||||
|
||||
use Backend;
|
||||
use Silva\Adrema\Components\EventIndex;
|
||||
use Silva\Adrema\Models\Settings;
|
||||
use System\Classes\PluginBase;
|
||||
|
||||
|
@ -48,8 +47,10 @@ class Plugin extends PluginBase
|
|||
*/
|
||||
public function registerComponents()
|
||||
{
|
||||
return []; // Remove this line to activate
|
||||
|
||||
return [
|
||||
EventIndex::class => 'adrema_event_index',
|
||||
'Silva\Adrema\Components\MyComponent' => 'myComponent',
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit e62934504bf2d33b65d0282a8d311df9cecb178e
|
||||
Subproject commit f76b46bc9fe159324e58783ff945595b5ba5e488
|
|
@ -1,113 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Silva\Adrema\Components;
|
||||
|
||||
use Cms\Classes\ComponentBase;
|
||||
use Cms\Classes\Page;
|
||||
use Silva\Adrema\Exceptions\ComponentException;
|
||||
use Silva\Adrema\Models\Settings;
|
||||
|
||||
class EventIndex extends ComponentBase
|
||||
{
|
||||
|
||||
public $settings;
|
||||
|
||||
/** @var string The active event */
|
||||
public ?string $event;
|
||||
|
||||
public function componentDetails()
|
||||
{
|
||||
return [
|
||||
'name' => 'EventOverview Component',
|
||||
'description' => 'No description provided yet...'
|
||||
];
|
||||
}
|
||||
|
||||
public function onRun()
|
||||
{
|
||||
$this->addJs('assets/vendor/adrema-form/dist/main.js');
|
||||
|
||||
$this->settings = [
|
||||
'primary_color' => Settings::get('primary_color'),
|
||||
...$this->resolvePageUrls(),
|
||||
];
|
||||
$this->event = $this->property('event');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function resolvePageUrls(): array
|
||||
{
|
||||
$indexPage = $this->getPageFromProperty('indexPage');
|
||||
$singlePage = $this->getPageFromProperty('singlePage');
|
||||
$registerPage = $this->getPageFromProperty('registerPage');
|
||||
|
||||
throw_if(!str($singlePage->url)->contains(':slug'), ComponentException::class, 'slug_not_found');
|
||||
throw_if(!str($registerPage->url)->contains(':slug'), ComponentException::class, 'slug_not_found');
|
||||
|
||||
return [
|
||||
'indexUrl' => $indexPage->url,
|
||||
'singleUrl' => $singlePage->url,
|
||||
'registerUrl' => $registerPage->url,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getPageFromProperty(string $property): Page
|
||||
{
|
||||
throw_if(!$this->property('indexPage') || !$this->property('singlePage') || !$this->property('registerPage'), ComponentException::class, 'not_all_pages_set');
|
||||
|
||||
$page = Page::find($this->property($property));
|
||||
throw_if($page === null, ComponentException::class, 'page_not_found');
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
public function defineProperties()
|
||||
{
|
||||
return [
|
||||
'indexPage' => [
|
||||
'title' => __('properties.index_page_title'),
|
||||
'type' => 'dropdown',
|
||||
'default' => null,
|
||||
],
|
||||
'singlePage' => [
|
||||
'title' => __('properties.single_page_title'),
|
||||
'type' => 'dropdown',
|
||||
'default' => null,
|
||||
],
|
||||
'registerPage' => [
|
||||
'title' => __('properties.register_page_title'),
|
||||
'type' => 'dropdown',
|
||||
'default' => null,
|
||||
],
|
||||
'event' => [
|
||||
'title' => __('properties.event_title'),
|
||||
'type' => 'text',
|
||||
'default' => null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function getIndexPageOptions(): array
|
||||
{
|
||||
return $this->pageOptions();
|
||||
}
|
||||
|
||||
public function getSinglePageOptions(): array
|
||||
{
|
||||
return $this->pageOptions();
|
||||
}
|
||||
|
||||
public function getRegisterPageOptions(): array
|
||||
{
|
||||
return $this->pageOptions();
|
||||
}
|
||||
|
||||
private function pageOptions(): array
|
||||
{
|
||||
return Page::get()
|
||||
->mapWithKeys(fn ($page) => [$page->fileName => $page->title])
|
||||
->toArray();
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
<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 %}
|
||||
></event-index>
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Silva\Adrema\Exceptions;
|
||||
|
||||
use App;
|
||||
use ApplicationException;
|
||||
use Lang;
|
||||
use Throwable;
|
||||
|
||||
class ComponentException extends ApplicationException
|
||||
{
|
||||
|
||||
public function __construct($message = "", $code = 0, Throwable $previous = null)
|
||||
{
|
||||
$translations = json_decode(file_get_contents(__DIR__ . '/../lang/en.json'), true);
|
||||
|
||||
parent::__construct($translations['errors.' . $message] ?? $message, $code, $previous);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,7 @@
|
|||
{
|
||||
"setting_description": "App für DPSG-NaMi",
|
||||
"url_pattern_comment": "Die Page-URL, auf der einzelne Veranstaltungen angezeigt werden. {slug} wird mit dem Bezeichner der Veranstaltung ersetzt.",
|
||||
"url_pattern_label": "URL für einzelne Veranstaltungen",
|
||||
"base_url_label": "Base-URL",
|
||||
"base_url_comment": "Die Domain (app_url), auf der deine Adrema läuft",
|
||||
"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"
|
||||
"base_url_comment": "Die Domain (app_url), auf der deine Adrema läuft"
|
||||
}
|
||||
|
|
12
lang/en.json
12
lang/en.json
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"setting_description": "App for DPSG-NaMi",
|
||||
"base_url_label": "Base-URL",
|
||||
"base_url_comment": "The domain (APP_URL) of the Adrema application.",
|
||||
"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",
|
||||
"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\")"
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
<?php namespace Silva\Adrema\Models;
|
||||
|
||||
use Model;
|
||||
|
||||
/**
|
||||
* Setting Model
|
||||
*
|
||||
* @link https://docs.octobercms.com/3.x/extend/system/models.html
|
||||
*/
|
||||
class Setting extends Model
|
||||
{
|
||||
use \October\Rain\Database\Traits\Validation;
|
||||
|
||||
/**
|
||||
* @var string table name
|
||||
*/
|
||||
public $table = 'silva_adrema_settings';
|
||||
|
||||
/**
|
||||
* @var array rules for validation
|
||||
*/
|
||||
public $rules = [];
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
# ===================================
|
||||
# List Column Definitions
|
||||
# ===================================
|
||||
|
||||
columns:
|
||||
id:
|
||||
label: ID
|
||||
searchable: true
|
|
@ -1,8 +0,0 @@
|
|||
# ===================================
|
||||
# Form Field Definitions
|
||||
# ===================================
|
||||
|
||||
fields:
|
||||
id:
|
||||
label: ID
|
||||
disabled: true
|
14
routes.php
14
routes.php
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
|
||||
use Silva\Adrema\Models\Settings;
|
||||
|
||||
Route::get('/api/silva_adrema_event_overview', function () {
|
||||
$baseUrl = Settings::get('base_url');
|
||||
$response = Http::get($baseUrl . '/api/form');
|
||||
|
||||
if (!$response->ok()) {
|
||||
return Response::json(['message' => 'Fehler beim Laden der Veranstaltungen'], 422);
|
||||
}
|
||||
|
||||
return Response::json($response->json());
|
||||
})->middleware('api');
|
Loading…
Reference in New Issue