Skip to content

Commit

Permalink
docs(action-buttons): description method()
Browse files Browse the repository at this point in the history
issue #424
  • Loading branch information
DissNik committed Apr 16, 2024
1 parent 2b78100 commit 6f9cf9e
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
70 changes: 70 additions & 0 deletions resources/views/pages/en/action_button.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@ public function components(): array
}
</x-code>

<x-moonshine::alert type="default" icon="heroicons.book-open">
For the <code>table-updated-index-table</code> event to work
<x-link link="{{ to_page('resources-table') }}#async">async mode</x-link> must be enabled.
</x-moonshine::alert>

<x-moonshine::divider label="Callback" />

<x-p>
Expand Down Expand Up @@ -545,6 +550,30 @@ public function components(): array
<em>ActionButton</em> without having to create additional controllers.
</x-p>

<x-code language="php">
method(
string $method,
array|Closure $params = [],
?string $message = null,
?string $selector = null,
array $events = [],
string|AsyncCallback|null $callback = null,
?Page $page = null,
?ResourceContract $resource = null
)
</x-code>

<x-ul>
<li><code>$method</code> - name of the method</li>
<li><code>$params</code> - parameters for the request,</li>
<li><code>$message</code> - messages</li>
<li><code>$selector</code> - selector of the element whose content will change</li>
<li><code>$events</code> - events to be called after a successful request,</li>
<li><code>$callback</code> - js callback function after receiving a response</li>
<li><code>$page</code> - page containing the method</li>
<li><code>$resource</code> - resource containing the method.</li>
</x-ul>

<x-code language="php">
public function components(): array
{
Expand Down Expand Up @@ -585,6 +614,47 @@ public function updateSomething(MoonShineRequest $request)
Methods called via <em>ActionButton</em> in a resource must be public!
</x-moonshine::alert>

<x-moonshine::alert type="error" icon="heroicons.information-circle">
Для доступа к данным из реквеста, необходимо передать их в параметрах.
</x-moonshine::alert>

<x-moonshine::divider label="Передача текущего элемента" />

<x-p>
Если в запросе присутствует <em>resourceItem</em>,
то в ресурсе вы можете получить доступ к текущему элементу через метод <code>getItem()</code>.
</x-p>

<x-ul>
<li>
When there is a model in the data and the button is created in the <code>buttons()</code> method
<x-link link="{{ to_page('advanced-table_builder') }}#buttons">TableBuilder</x-link>,
<x-link link="{{ to_page('advanced-cards_builder') }}#buttons">CardsBuilder</x-link>
or <x-link link="{{ to_page('advanced-form_builder') }}#buttons">FormBuilder</x-link>,
then it is automatically filled with data and the parameters will contain <code>resourceItem</code>.
</li>
<li>
When the button is on the <em>ModelResource</em> form page, you can pass the id of the current element.
<x-code language="php">
ActionButton::make('Click me')
->method(
'updateSomething',
params: ['resourceItem' => $this->getResource()->getItemID()] // [tl! focus]
)
</x-code>
</li>
<li>
When the button is in the <em>ModelResource</em> index table, you need to use a closure.
<x-code language="php">
ActionButton::make('Click me')
->method(
'updateSomething',
params: ['resourceItem' => fn($item) ['resourceItem' => $item->getKey()]] // [tl! focus]
)
</x-code>
</li>
</x-ul>

<x-sub-title id="event">Dispatch events</x-sub-title>

<x-p>
Expand Down
70 changes: 70 additions & 0 deletions resources/views/pages/ru/action_button.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,11 @@ public function components(): array
}
</x-code>

<x-moonshine::alert type="default" icon="heroicons.book-open">
Для работы события <code>table-updated-index-table</code>
должен быть включен <x-link link="{{ to_page('resources-table') }}#async">асинхронный режим</x-link>.
</x-moonshine::alert>

<x-moonshine::divider label="Callback" />

<x-p>
Expand Down Expand Up @@ -545,6 +550,30 @@ public function components(): array
<em>ActionButton</em> без необходимости создавать дополнительные контроллеры.
</x-p>

<x-code language="php">
method(
string $method,
array|Closure $params = [],
?string $message = null,
?string $selector = null,
array $events = [],
string|AsyncCallback|null $callback = null,
?Page $page = null,
?ResourceContract $resource = null
)
</x-code>

<x-ul>
<li><code>$method</code> - наименование метода,</li>
<li><code>$params</code> - параметры для запроса,</li>
<li><code>$message</code> - сообщения,</li>
<li><code>$selector</code> - selector элемента у которого будет изменяться контент,</li>
<li><code>$events</code> - вызываемые события после успешного запроса,</li>
<li><code>$callback</code> - js callback функция после получения ответа,</li>
<li><code>$page</code> - страница содержащая метод,</li>
<li><code>$resource</code> - ресурс содержащий метод.</li>
</x-ul>

<x-code language="php">
public function components(): array
{
Expand Down Expand Up @@ -585,6 +614,47 @@ public function updateSomething(MoonShineRequest $request)
Методы в вызываемые через <em>ActionButton</em> в ресурсе должны быть публичными!
</x-moonshine::alert>

<x-moonshine::alert type="error" icon="heroicons.information-circle">
Для доступа к данным из реквеста, необходимо передать их в параметрах.
</x-moonshine::alert>

<x-moonshine::divider label="Передача текущего элемента" />

<x-p>
Если в запросе присутствует <em>resourceItem</em>,
то в ресурсе вы можете получить доступ к текущему элементу через метод <code>getItem()</code>.
</x-p>

<x-ul>
<li>
Когда в данных присутствует модель и кнопка создается в методе <code>buttons()</code>
<x-link link="{{ to_page('advanced-table_builder') }}#buttons">TableBuilder</x-link>,
<x-link link="{{ to_page('advanced-cards_builder') }}#buttons">CardsBuilder</x-link>
или <x-link link="{{ to_page('advanced-form_builder') }}#buttons">FormBuilder</x-link>,
то она автоматически наполняется данными и в параметрах будет <code>resourceItem</code>.
</li>
<li>
Когда кнопка находится на странице формы <em>ModelResource</em> то можно передать id текущего элемента.
<x-code language="php">
ActionButton::make('Click me')
->method(
'updateSomething',
params: ['resourceItem' => $this->getResource()->getItemID()] // [tl! focus]
)
</x-code>
</li>
<li>
Когда кнопка находится в индексной таблице <em>ModelResource</em>, то необходимо воспользоваться замыканием.
<x-code language="php">
ActionButton::make('Click me')
->method(
'updateSomething',
params: ['resourceItem' => fn($item) ['resourceItem' => $item->getKey()]] // [tl! focus]
)
</x-code>
</li>
</x-ul>

<x-sub-title id="event">Вызов событий</x-sub-title>

<x-p>
Expand Down

0 comments on commit 6f9cf9e

Please sign in to comment.