Skip to content

Commit

Permalink
action buttons, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Loufek committed Feb 8, 2020
1 parent d7008fe commit 60fde1c
Show file tree
Hide file tree
Showing 13 changed files with 3,046 additions and 4 deletions.
1 change: 1 addition & 0 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = (grunt) ->
'node_modules/nette.ajax.js/nette.ajax.js'
'node_modules/nette-forms/src/assets/netteForms.js'
'node_modules/select2/dist/js/select2.full.min.js'
'node_modules/popper.js/dist/umd/popper.js'
'node_modules/admin-lte/dist/js/adminlte.min.js'
'node_modules/bootstrap/dist/js/bootstrap.min.js'
'src/AdminLTE/assets/custom/nette.init.js'
Expand Down
65 changes: 64 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ class AdminPresenter extends Presenter
$this->flashMessage('Looking for: ' . $word, 'danger');
}
}

```

@layout.latte
Expand All @@ -164,6 +163,70 @@ class AdminPresenter extends Presenter
{control admin $content, $flashes}
```
##Modals:
For `a` tags with modal property will be shown "no-layout" result inside modal window.

```latte
<a n:href="edit" class="btn btn-success" modal>Add user</a>
```

## Components:
##### Lazy screen (shown in demo site):

```php

protected function createComponentSlowScreen(): SlowComponent
{
return $this->slowComponentFactory->create();
}

// Component with slow response (reading remote data, compute something)
protected function createComponentSlowScreenLazyLoaded(): LazyScreen
{
return new LazyScreen(function () {
return $this->slowComponentFactory->create();
});
}
```

##### Action buttons (shown in demo site):
Sometimes is useful to add some actions related for view (e.g. on product detail edit, send, assign etc.).

```php
public function renderDetail(): void
{
$this['admin']->addActionButton(Button::builder()->typeWarning()
->link($this->link('this#test'))->faIcon('eye')->build());
$this['admin']->addActionButton(Button::builder()->typeInfo()
->link($this->link('this#test2'))->faIcon('cog')->build());
$this['admin']->addDropdownLink(new DropLink('', 'link'));
}
```
##### Info-board (shown in demo site):
For dashboard purposes we can show some info boxes with useful information.

```php
protected function createComponentDashBoard(): InfoBoard
{
return (new InfoBoard())
->setColSpan(6)
->addBox((new InfoBox())
->setColor('red')
->setLink('#')
->setIcon('pencil')
->setNumber(1222)
->setProgress(90)
->setText('Pencil text')
)
->addBox((new InfoBox())
->setColor('green')
->setIcon('globe')
->setText('Globe text')
->setNumber((float) random_int(0, 9999))
);
}
```

## TODO:

- Improve menu control and better authorization for nested items
Expand Down
24 changes: 24 additions & 0 deletions src/AdminLTE/AdminControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Chap\AdminLTE;

use Chap\AdminLTE\Components\ActionButtons\Button;
use Chap\AdminLTE\Components\ActionButtons\DropLink;
use Chap\AdminLTE\Login\ILoginFormFactory;
use Chap\AdminLTE\Login\LoginForm;
use Chap\AdminLTE\Menu\IMenuControlFactory;
Expand Down Expand Up @@ -124,6 +126,28 @@ public function addPanel(IPanel $panel): self
return $this;
}

/**
* @param Button $button
* @return $this
*/
public function addActionButton(Button $button): self
{
$this['menu']['actionButtons']->addButton($button);

return $this;
}

/**
* @param DropLink $dropLink
* @return $this
*/
public function addDropdownLink(DropLink $dropLink): self
{
$this['menu']['actionButtons']->addDropdownLink($dropLink);

return $this;
}

/**
* @return LoginForm
*/
Expand Down
41 changes: 41 additions & 0 deletions src/AdminLTE/Components/ActionButtons/ActionButtons.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php declare(strict_types=1);

namespace Chap\AdminLTE\Components\ActionButtons;

use Nette\Application\UI\Control;
use Nette\Bridges\ApplicationLatte\Template;

class ActionButtons extends Control
{
/** @var Button[] */
private $buttons = [];

/** @var DropLink[] */
private $dropLinks = [];

/**
* @param Button $button
*/
public function addButton(Button $button): void
{
$this->buttons[] = $button;
}

/**
* @param DropLink $dropLink
*/
public function addDropdownLink(DropLink $dropLink): void
{
$this->dropLinks[] = $dropLink;
}

public function render(): void
{
/** @var Template $template */
$template = $this->getTemplate();
$template->render(__DIR__ . DIRECTORY_SEPARATOR . 'template.latte', [
'buttons' => $this->buttons,
'dropLinks' => $this->dropLinks,
]);
}
}
58 changes: 58 additions & 0 deletions src/AdminLTE/Components/ActionButtons/Button.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php declare(strict_types=1);

namespace Chap\AdminLTE\Components\ActionButtons;

class Button
{
/** @var string */
public static $BUTTON_TYPE_PRIMARY = 'primary';
/** @var string */
public static $BUTTON_TYPE_SECONDARY = 'secondary';
/** @var string */
public static $BUTTON_TYPE_SUCCESS = 'success';
/** @var string */
public static $BUTTON_TYPE_DANGER = 'danger';
/** @var string */
public static $BUTTON_TYPE_WARNING = 'warning';
/** @var string */
public static $BUTTON_TYPE_INFO = 'info';
/** @var string */
public static $BUTTON_TYPE_LIGHT = 'light';
/** @var string */
public static $BUTTON_TYPE_DARK = 'dark';

/** @var string */
public $link;
/** @var string */
public $type;
/** @var string|null */
public $caption;
/** @var string|null */
public $icon;
/** @var string|null */
public $title;

/**
* @param string $link
* @param string $type
* @param string|null $caption
* @param string|null $icon
* @param string|null $title
*/
public function __construct(string $link, string $type, ?string $caption = null, ?string $icon = null, ?string $title = null)
{
$this->link = $link;
$this->type = $type;
$this->caption = $caption;
$this->icon = $icon;
$this->title = $title;
}

/**
* @return ButtonBuilder
*/
public static function builder(): ButtonBuilder
{
return new ButtonBuilder();
}
}
Loading

0 comments on commit 60fde1c

Please sign in to comment.