Skip to content
Merged
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
19 changes: 2 additions & 17 deletions formwork/src/Panel/Controllers/OptionsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@

final class OptionsController extends AbstractController
{
/**
* All options tabs
*
* @var list<string>
*/
private array $tabs = ['site', 'system'];

/**
* Options@index action
*/
Expand Down Expand Up @@ -71,11 +64,7 @@ public function systemOptions(Schemes $schemes): Response
}

return new Response($this->view('@panel.options.system', [
'title' => $this->translate('panel.options.options'),
'tabs' => $this->view('@panel.options.tabs', [
'tabs' => $this->tabs,
'current' => 'system',
]),
'title' => $this->translate('panel.options.options'),
'fields' => $form->fields(),
]), $form->getResponseStatus());
}
Expand Down Expand Up @@ -119,11 +108,7 @@ public function siteOptions(Schemes $schemes): Response
}

return new Response($this->view('@panel.options.site', [
'title' => $this->translate('panel.options.options'),
'tabs' => $this->view('@panel.options.tabs', [
'tabs' => $this->tabs,
'current' => 'site',
]),
'title' => $this->translate('panel.options.options'),
'fields' => $form->fields(),
]), $form->getResponseStatus());
}
Expand Down
25 changes: 3 additions & 22 deletions formwork/src/Panel/Controllers/ToolsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@

final class ToolsController extends AbstractController
{
/**
* All options tabs
*
* @var list<string>
*/
private array $tabs = ['backups', 'updates', 'info'];

/**
* Cached composer.json data
*
Expand Down Expand Up @@ -57,11 +50,7 @@ public function backups(): Response
]);

return new Response($this->view('@panel.tools.backups', [
'title' => $this->translate('panel.tools.backups'),
'tabs' => $this->view('@panel.tools.tabs', [
'tabs' => $this->tabs,
'current' => 'backups',
]),
'title' => $this->translate('panel.tools.backups'),
'backups' => Collection::from($backups),
]));
}
Expand All @@ -76,11 +65,7 @@ public function updates(): Response
}

return new Response($this->view('@panel.tools.updates', [
'title' => $this->translate('panel.tools.updates'),
'tabs' => $this->view('@panel.tools.tabs', [
'tabs' => $this->tabs,
'current' => 'updates',
]),
'title' => $this->translate('panel.tools.updates'),
'currentVersion' => $this->app::VERSION,
]));
}
Expand Down Expand Up @@ -220,11 +205,7 @@ public function info(): Response
ksort($data['HTTP Response Headers']);

return new Response($this->view('@panel.tools.info', [
'title' => $this->translate('panel.tools.info'),
'tabs' => $this->view('@panel.tools.tabs', [
'tabs' => $this->tabs,
'current' => 'info',
]),
'title' => $this->translate('panel.tools.info'),
'formwork' => $formwork,
'warnings' => $warnings,
'info' => $data,
Expand Down
41 changes: 35 additions & 6 deletions formwork/src/Panel/Navigation/NavigationItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@

namespace Formwork\Panel\Navigation;

use Formwork\Data\Contracts\Arrayable;
use Formwork\Data\Traits\DataArrayable;
use Formwork\Data\Contracts\ArraySerializable;

class NavigationItem implements Arrayable
class NavigationItem implements ArraySerializable
{
use DataArrayable;
/**
* @var array<string,mixed>
*/
protected array $data = [];

/**
* @param array<string, mixed> $data
*/
public function __construct(protected string $id, array $data)
{
$this->data = $data;
foreach ($data as $key => $value) {
if ($key === 'children') {
$value = NavigationItemCollection::fromArray($value);
}
$this->data[$key] = $value;
}
}

/**
Expand Down Expand Up @@ -46,7 +53,7 @@ public function uri(): string
*/
public function permissions(): ?string
{
return $this->data['permissions'];
return $this->data['permissions'] ?? null;
}

/**
Expand Down Expand Up @@ -76,4 +83,26 @@ public function visible(): bool
{
return $this->data['visible'] ?? true;
}

/**
* Get navigation item children
*/
public function children(): ?NavigationItemCollection
{
return $this->data['children'] ?? null;
}

public function toArray(): array
{
$data = $this->data;
if (isset($data['children'])) {
$data['children'] = $data['children']->toArray();
}
return [...$data, 'id' => $this->id];
}

public static function fromArray(array $data): self
{
return new self($data['id'], $data);
}
}
14 changes: 13 additions & 1 deletion formwork/src/Panel/Navigation/NavigationItemCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
namespace Formwork\Panel\Navigation;

use Formwork\Data\AbstractCollection;
use Formwork\Data\Contracts\ArraySerializable;
use Formwork\Utils\Arr;

class NavigationItemCollection extends AbstractCollection
class NavigationItemCollection extends AbstractCollection implements ArraySerializable
{
protected bool $associative = true;

protected ?string $dataType = NavigationItem::class;

protected bool $mutable = true;

public function toArray(): array
{
return Arr::map($this->data, fn(NavigationItem $navigationItem) => $navigationItem->toArray());
}

public static function fromArray(array $data): self
{
return new self(Arr::map($data, fn(array $item, string $id) => NavigationItem::fromArray([...$item, 'id' => $id])));
}
}
21 changes: 12 additions & 9 deletions formwork/src/Panel/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@
use Formwork\Languages\LanguageCodes;
use Formwork\Panel\Events\PanelNavigationLoadedEvent;
use Formwork\Panel\Modals\Modals;
use Formwork\Panel\Navigation\NavigationItem;
use Formwork\Panel\Navigation\NavigationItemCollection;
use Formwork\Services\Container;
use Formwork\Translations\Translations;
use Formwork\Users\ColorScheme;
use Formwork\Users\User;
use Formwork\Users\Users;
use Formwork\Utils\Arr;
use Formwork\Utils\FileSystem;
use Formwork\Utils\Str;
use Formwork\Utils\Uri;
Expand Down Expand Up @@ -117,15 +115,20 @@ public function route(): string
*/
public function navigation(): NavigationItemCollection
{
if (isset($this->navigation)) {
return $this->navigation;
}

$translation = $this->translations->getCurrent();
if (!isset($this->navigation)) {
$items = $this->container->call(require $this->config->get('system.panel.config.navigation'), [

$this->navigation = NavigationItemCollection::fromArray(
$this->container->call(require $this->config->get('system.panel.config.navigation'), [
'translation' => $translation,
]);
$this->navigation = new NavigationItemCollection();
$this->navigation->setMultiple(Arr::map($items, fn(array $data, string $id) => new NavigationItem($id, $data)));
$this->events->dispatch(new PanelNavigationLoadedEvent($this->navigation, $translation));
}
])
);

$this->events->dispatch(new PanelNavigationLoadedEvent($this->navigation, $translation));

return $this->navigation;
}

Expand Down
40 changes: 31 additions & 9 deletions panel/config/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
'label' => $translation->translate('panel.dashboard.dashboard'),
'uri' => '/dashboard/',
'permissions' => 'panel.dashboard',
'badge' => null,
'icon' => 'home',
],
'pages' => [
Expand All @@ -23,14 +22,12 @@
'label' => $translation->translate('panel.files.files'),
'uri' => '/files/',
'permissions' => 'panel.files',
'badge' => null,
'icon' => 'files',
],
'statistics' => [
'label' => $translation->translate('panel.statistics.statistics'),
'uri' => '/statistics/',
'permissions' => 'panel.statistics',
'badge' => null,
'icon' => 'chart-line',
],
'users' => [
Expand All @@ -44,15 +41,42 @@
'label' => $translation->translate('panel.options.options'),
'uri' => '/options/',
'permissions' => 'panel.options',
'badge' => null,
'icon' => 'gear',
'children' => [
'site' => [
'label' => $translation->translate('panel.options.site'),
'uri' => '/options/site/',
'permissions' => 'panel.options.site',
],
'system' => [
'label' => $translation->translate('panel.options.system'),
'uri' => '/options/system/',
'permissions' => 'panel.options.system',
],
],
],
'tools' => [
'label' => $translation->translate('panel.tools.tools'),
'uri' => '/tools/',
'permissions' => 'panel.tools',
'badge' => null,
'icon' => 'toolbox',
'children' => [
'backups' => [
'label' => $translation->translate('panel.tools.backups'),
'uri' => '/tools/backups/',
'permissions' => 'panel.tools.backups',
],
'updates' => [
'label' => $translation->translate('panel.tools.updates'),
'uri' => '/tools/updates/',
'permissions' => 'panel.tools.updates',
],
'info' => [
'label' => $translation->translate('panel.tools.info'),
'uri' => '/tools/info/',
'permissions' => 'panel.tools.info',
],
],
],
'plugins' => [
'label' => $translation->translate('panel.plugins.plugins'),
Expand All @@ -63,9 +87,7 @@
'visible' => !$app->plugins()->isEmpty(),
],
'logout' => [
'label' => $translation->translate('panel.login.logout'),
'uri' => '/logout/',
'permissions' => null,
'badge' => null,
'label' => $translation->translate('panel.login.logout'),
'uri' => '/logout/',
],
];
4 changes: 4 additions & 0 deletions panel/src/scss/components/_tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
}
}

.tabs-tab .icon {
margin-right: 0.375rem;
}

.tabs-panel {
display: none;
}
Expand Down
2 changes: 1 addition & 1 deletion panel/views/options/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<input type="hidden" name="csrf-token" value="<?= $csrfToken ?>">
</div>
</div>
<?= $tabs ?>
<?php $this->insert('@panel._navigation.tabs', ['items' => $panel->navigation()->get('options')->children(), 'current' => 'site']) ?>
<div>
<?php $this->insert('@panel.fields', ['fields' => $fields]) ?>
</div>
Expand Down
2 changes: 1 addition & 1 deletion panel/views/options/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<input type="hidden" name="csrf-token" value="<?= $csrfToken ?>">
</div>
</div>
<?= $tabs ?>
<?php $this->insert('@panel._navigation.tabs', ['items' => $panel->navigation()->get('options')->children(), 'current' => 'system']) ?>
<div>
<?php $this->insert('@panel.fields', ['fields' => $fields]) ?>
</div>
Expand Down
7 changes: 0 additions & 7 deletions panel/views/options/tabs.php

This file was deleted.

15 changes: 15 additions & 0 deletions panel/views/partials/navigation/sidebar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php foreach ($items as $item) : ?>
<?php if ($item->visible() && ($item->permissions() === null || $panel->user()->permissions()->has($item->permissions()))) : ?>
<li class="<?= $this->classes(['active' => $location === $item->id()]) ?>">
<a href="<?= $panel->uri($item->uri()) ?>">
<?php if ($item->icon()) : ?>
<?= $this->icon($item->icon()) ?>
<?php endif ?>
<?= $this->escape($item->label()) ?>
<?php if ($item->badge()) : ?>
<span class="badge"><?= $item->badge() ?></span>
<?php endif ?>
</a>
</li>
<?php endif ?>
<?php endforeach ?>
15 changes: 15 additions & 0 deletions panel/views/partials/navigation/tabs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div class="tabs">
<?php foreach ($items as $item) : ?>
<?php if ($item->visible() && ($item->permissions() === null || $panel->user()->permissions()->has($item->permissions()))) : ?>
<a class="<?= $this->classes(['tabs-tab', 'active' => $item->id() === $current]) ?>" href="<?= $panel->uri($item->uri()) ?>">
<?php if ($item->icon()) : ?>
<?= $this->icon($item->icon()) ?>
<?php endif ?>
<?= $this->escape($item->label()) ?>
<?php if ($item->badge()) : ?>
<span class="badge"><?= $item->badge() ?></span>
<?php endif ?>
</a>
<?php endif ?>
<?php endforeach ?>
</div>
Loading