10-04-2026
This commit is contained in:
parent
4d6b4930b2
commit
4bb89aad8c
836 changed files with 52961 additions and 5950 deletions
|
|
@ -2,22 +2,29 @@
|
|||
|
||||
namespace FluxCms\Components\Livewire\Backend;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\Attributes\On;
|
||||
use FluxCms\Core\Models\Page;
|
||||
use FluxCms\Core\Models\PageComponent;
|
||||
use FluxCms\Core\Services\ComponentRegistry;
|
||||
use Illuminate\Support\Collection;
|
||||
use Livewire\Attributes\On;
|
||||
use Livewire\Component;
|
||||
|
||||
class PageEditor extends Component
|
||||
{
|
||||
public Page $page;
|
||||
|
||||
public Collection $components;
|
||||
|
||||
public array $availableLanguages = [];
|
||||
|
||||
public string $currentLocale = 'de';
|
||||
|
||||
public bool $showComponentModal = false;
|
||||
|
||||
public array $availableComponents = [];
|
||||
|
||||
public string $selectedCategory = 'all';
|
||||
|
||||
public bool $isLoading = false;
|
||||
|
||||
protected ComponentRegistry $componentRegistry;
|
||||
|
|
@ -39,7 +46,7 @@ class PageEditor extends Component
|
|||
public function render()
|
||||
{
|
||||
return view('flux-cms-components::livewire.backend.page-editor')
|
||||
->layout('flux-cms-components::layouts.admin');
|
||||
->layout('flux-cms-components::layouts.admin');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -99,8 +106,9 @@ class PageEditor extends Component
|
|||
*/
|
||||
public function addComponent(string $componentClass)
|
||||
{
|
||||
if (!$this->componentRegistry->isValidComponent($componentClass)) {
|
||||
if (! $this->componentRegistry->isValidComponent($componentClass)) {
|
||||
$this->addError('component', 'Invalid component selected.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +129,7 @@ class PageEditor extends Component
|
|||
session()->flash('success', 'Component added successfully.');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('component', 'Error adding component: ' . $e->getMessage());
|
||||
$this->addError('component', 'Error adding component: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -133,8 +141,9 @@ class PageEditor extends Component
|
|||
try {
|
||||
$component = $this->components->firstWhere('id', $componentId);
|
||||
|
||||
if (!$component) {
|
||||
if (! $component) {
|
||||
$this->addError('component', 'Component not found.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -145,7 +154,7 @@ class PageEditor extends Component
|
|||
session()->flash('success', 'Component deleted successfully.');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('component', 'Error deleting component: ' . $e->getMessage());
|
||||
$this->addError('component', 'Error deleting component: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -157,8 +166,9 @@ class PageEditor extends Component
|
|||
try {
|
||||
$component = $this->components->firstWhere('id', $componentId);
|
||||
|
||||
if (!$component) {
|
||||
if (! $component) {
|
||||
$this->addError('component', 'Component not found.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -169,7 +179,7 @@ class PageEditor extends Component
|
|||
session()->flash('success', 'Component duplicated successfully.');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('component', 'Error duplicating component: ' . $e->getMessage());
|
||||
$this->addError('component', 'Error duplicating component: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -181,15 +191,15 @@ class PageEditor extends Component
|
|||
try {
|
||||
$component = $this->components->firstWhere('id', $componentId);
|
||||
|
||||
if (!$component) {
|
||||
if (! $component) {
|
||||
return;
|
||||
}
|
||||
|
||||
$component->update(['is_active' => !$component->is_active]);
|
||||
$component->update(['is_active' => ! $component->is_active]);
|
||||
$this->loadComponents();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('component', 'Error toggling component: ' . $e->getMessage());
|
||||
$this->addError('component', 'Error toggling component: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -208,7 +218,7 @@ class PageEditor extends Component
|
|||
session()->flash('success', 'Component order updated.');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('order', 'Error updating order: ' . $e->getMessage());
|
||||
$this->addError('order', 'Error updating order: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -237,7 +247,7 @@ class PageEditor extends Component
|
|||
}
|
||||
|
||||
foreach ($config['fields'] as $field) {
|
||||
if (!$field instanceof \FluxCms\Core\FieldTypes\BaseField) {
|
||||
if (! $field instanceof \FluxCms\Core\FieldTypes\BaseField) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -271,7 +281,7 @@ class PageEditor extends Component
|
|||
session()->flash('success', 'Page data saved successfully.');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('page', 'Error saving page: ' . $e->getMessage());
|
||||
$this->addError('page', 'Error saving page: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -292,21 +302,21 @@ class PageEditor extends Component
|
|||
session()->flash('success', $message);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('publish', 'Error updating publish status: ' . $e->getMessage());
|
||||
$this->addError('publish', 'Error updating publish status: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create version
|
||||
*/
|
||||
public function createVersion(string $description = null)
|
||||
public function createVersion(?string $description = null)
|
||||
{
|
||||
try {
|
||||
$this->page->createVersion($description, auth()->id());
|
||||
session()->flash('success', 'Version created successfully.');
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->addError('version', 'Error creating version: ' . $e->getMessage());
|
||||
$this->addError('version', 'Error creating version: '.$e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -320,10 +330,11 @@ class PageEditor extends Component
|
|||
|
||||
if (empty($slug)) {
|
||||
$this->addError('preview', 'No slug available for current language.');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$url = $this->page->getUrl($locale) . '?preview=1';
|
||||
$url = $this->page->getUrl($locale).'?preview=1';
|
||||
$this->dispatch('open-preview', url: $url);
|
||||
}
|
||||
|
||||
|
|
@ -351,6 +362,7 @@ class PageEditor extends Component
|
|||
foreach ($this->availableComponents as $category => $categoryComponents) {
|
||||
$components = array_merge($components, $categoryComponents);
|
||||
}
|
||||
|
||||
return $components;
|
||||
}
|
||||
|
||||
|
|
@ -362,7 +374,7 @@ class PageEditor extends Component
|
|||
*/
|
||||
public function getPageStatusProperty(): string
|
||||
{
|
||||
if (!$this->page->is_published) {
|
||||
if (! $this->page->is_published) {
|
||||
return 'draft';
|
||||
}
|
||||
|
||||
|
|
@ -372,4 +384,4 @@ class PageEditor extends Component
|
|||
|
||||
return 'published';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue