Skip to content

Commit c6e24cc

Browse files
committed
new guide's content
1 parent 09739c2 commit c6e24cc

File tree

1 file changed

+223
-2
lines changed

1 file changed

+223
-2
lines changed

docs/guide/index.md

Lines changed: 223 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,229 @@ It's that easy, more info on filtering can be found in [awes-io/repository docum
288288

289289
We've updated the existing filter, but what if we want to build a custom filter of some kind for our lead management UI?
290290

291+
We have the option to search leads by their names, but the filter doesn't work, let's fix this:
292+
293+
<img src="https://static.awes.io/docs/guide/08_filter_by_name_not_working.png" alt="Awes.io">
294+
295+
All we need to do is to add `name` parameter to `$searchable` property in `App\Sections\Leads\Repositories\LeadRepository` and in this case we need to use `like` operator:
296+
297+
```php
298+
protected $searchable = [
299+
'status',
300+
'name' => 'like'
301+
];
302+
```
303+
304+
<img src="https://static.awes.io/docs/guide/09_filter_by_name.png" alt="Awes.io">
305+
306+
Now let's add a new filtering option by status. Firstly we need to set up an additional input field in `resources/views/sections/leads/index.blade.php` template:
307+
308+
```html
309+
<fb-input name="name" label="{{ _p('pages.leads.filter.name', 'Name') }}"></fb-input>
310+
<fb-input name="status" label="{{ _p('pages.leads.filter.status', 'Status') }}"></fb-input>
311+
```
312+
313+
<img src="https://static.awes.io/docs/guide/10_filter_by_status_input.png" alt="Awes.io">
314+
315+
And because we're tracking changes in `status` parameter already:
316+
317+
```php
318+
'scope_api_params' => ['orderBy', 'is_public', 'name', 'status'],
319+
```
320+
321+
and we've added it to repository `searchable` property earlier:
322+
323+
```php
324+
protected $searchable = [
325+
'status',
326+
'name' => 'like'
327+
];
328+
```
329+
330+
Everything should work as intended:
331+
332+
<img src="https://static.awes.io/docs/guide/11_filter_by_status_results.png" alt="Awes.io">
333+
291334
## New sorting
292335

293-
## Customizing table
336+
What about sorting? We have an option to sort leads by names, let's make it work. Again all we need to do is to add `name` parameter to model's `$orderable` property and repository package will do the rest:
337+
338+
```php
339+
// App\Sections\Leads\Models\Lead
340+
public $orderable = ['name'];
341+
```
342+
343+
Now let's add sorting by a lead status right into a table column. Firstly update `index` template:
344+
345+
```html
346+
<!-- <tb-column name="status" label="{{ _p('pages.leads.table.col.status', 'Status') }}"></tb-column> -->
347+
<tb-column name="status" label="{{ _p('pages.leads.table.col.status', 'Status') }}" sort></tb-column>
348+
```
349+
350+
as you can see we've added `sort` property to a respective table column, this will enable sorting controls:
351+
352+
<img src="https://static.awes.io/docs/guide/12_column_sorting_controls.png" alt="Awes.io">
353+
354+
To make them work. we need to add `status` parameter to `$orderable` model property:
355+
356+
```php
357+
public $orderable = ['name', 'status'];
358+
```
359+
360+
That's it, it just works:
361+
362+
<img src="https://static.awes.io/docs/guide/13_column_sorting_results.png" alt="Awes.io">
363+
364+
If you want to add a new sorting option to `Sort by` drop-down menu, it's very simple:
365+
366+
```html
367+
...
368+
<cm-query :param="{orderBy: 'name_desc'}">{{ _p('pages.leads.filter.name', 'Name') }} &uarr;</cm-query>
369+
<cm-query :param="{orderBy: 'status'}">{{ _p('pages.leads.filter.status', 'Status') }} &darr;</cm-query>
370+
<cm-query :param="{orderBy: 'status_desc'}">{{ _p('pages.leads.filter.status', 'Status') }} &uarr;</cm-query>
371+
...
372+
```
373+
374+
<img src="https://static.awes.io/docs/guide/14_sort_by_status.png" alt="Awes.io">
375+
376+
## Creating new leads
377+
378+
What if we need to create a new record? If you click the yellow action button, a new modal window will open, let's update it so we can create new leads.
379+
380+
For now, all we have is one input field for a name. Let's add one more for status:
381+
382+
```html
383+
<!-- index.blade.php -->
384+
<form-builder url="" :disabled-dialog="true">
385+
<fb-input name="name" label="{{ _p('pages.leads.modal_add.name', 'Name') }}"></fb-input>
386+
<fb-input name="status" label="{{ _p('pages.leads.modal_add.status', 'Status') }}"></fb-input>
387+
</form-builder>
388+
```
389+
390+
<img src="https://static.awes.io/docs/guide/15_create_lead_modal_window.png" alt="Awes.io">
391+
392+
And add a new route, to store data:
393+
394+
```html
395+
<!-- <form-builder url="" :disabled-dialog="true"> -->
396+
<form-builder url="{{ route('leads.store') }}" :disabled-dialog="true">
397+
```
398+
399+
Of course, we need to add a new route to `web.php` file:
400+
401+
```php
402+
Route::namespace('\App\Sections\Leads\Controllers')->prefix('leads')->group(function () {
403+
...
404+
Route::post('/', 'LeadController@store')->name('leads.store');
405+
});
406+
```
407+
408+
Respective method to `LeadController` (we'll keep things as simple as possible for easy understanding):
409+
410+
```php
411+
public function store(Request $request)
412+
{
413+
$this->leads->create($request->all());
414+
}
415+
```
416+
417+
And column names into `$fillable` model's property:
418+
419+
```php
420+
public $fillable = ['name', 'status'];
421+
```
422+
423+
We can now create new leads, but it'd be really helpful if the table could refresh its content after that. To achieve that, we need to handle a successful response after creating a new record:
424+
425+
```html
426+
<!-- <form-builder url="{{ route('leads.store') }}" :disabled-dialog="true"> -->
427+
<form-builder url="{{ route('leads.store') }}" :disabled-dialog="true" @sended="AWES.emit('content::leads:update')">
428+
```
429+
430+
All we do here is emiting event, now table will refresh after successfully creating a new record.
431+
432+
## Customizing table & updating existing leads
433+
434+
At last, we want to implement something fun and really useful. How about modifying our table and creating a new modal window to update any of our leads data.
435+
436+
Let's add new menu to each table row, with `edit lead` item:
437+
438+
```html
439+
...
440+
<tb-column name="status" label="{{ _p('pages.leads.table.col.status', 'Status') }}" sort></tb-column>
441+
<tb-column name="">
442+
<template slot-scope="d">
443+
<context-menu right boundary="table">
444+
<cm-button @click="AWES._store.commit('setData', {param: 'editLead', data: d.data}); AWES.emit('modal::edit-lead:open')">
445+
{{ _p('pages.leads.table.options.edit', 'Edit') }}
446+
</cm-button>
447+
</context-menu>
448+
</template>
449+
</tb-column>
450+
```
451+
452+
<img src="https://static.awes.io/docs/guide/16_edit_lead_menu.png" alt="Awes.io">
453+
454+
And new modal window:
455+
456+
```html
457+
<modal-window name="edit-lead" class="modal_formbuilder" title="{{ _p('pages.leads.modal.edit_lead.title', 'Edit lead') }}">
458+
<form-builder method="PATCH" url="/leads/{id}" store-data="editLead" @sended="AWES.emit('content::leads:update')">
459+
<fb-input name="name" label="{{ _p('pages.leads.modal_add.name', 'Name') }}"></fb-input>
460+
<fb-input name="status" label="{{ _p('pages.leads.modal_add.status', 'Status') }}"></fb-input>
461+
</form-builder>
462+
</modal-window>
463+
```
464+
465+
Now if we click on the 'Edit' menu item in any table row, modal window with respective data will open:
466+
467+
<img src="https://static.awes.io/docs/guide/17_edit_lead_modal_window.png" alt="Awes.io">
468+
469+
It remains only to add a new `update` method to the controller and new `PATCH` route:
470+
471+
```php
472+
public function update(Request $request, $id)
473+
{
474+
$this->leads->update($request->all(), $id);
475+
}
476+
```
477+
478+
```php
479+
Route::namespace('\App\Sections\Leads\Controllers')->prefix('leads')->group(function () {
480+
...
481+
Route::patch('/{id}', 'LeadController@update')->name('leads.update');
482+
});
483+
```
484+
485+
# Additional features
486+
487+
Just to make things even more interesting, let's update our project with some easy-to-use features available in Awes.io platform out-of-box.
488+
489+
## Validation errors
490+
491+
It's always helpful to display user any validation errors if any does occur. This functionality is also supported by our platform.
492+
493+
Let's create a form request class using Artisan command:
494+
495+
```bash
496+
php artisan make:request '\App\Sections\Leads\Requests\StoreLead'
497+
```
498+
499+
And add some basic validation rules into it:
500+
501+
```php
502+
return [
503+
'name' => 'required|string|max:255',
504+
'status' => 'required|string|max:255',
505+
];
506+
```
507+
508+
That's all, now any validation errors will be displayed.
509+
510+
## Custom filters
511+
512+
<!-- Building custom scope for searching in several fields. -->
513+
514+
## Notifications
294515

295-
## Creating and updating leads
516+
<!-- success notification after new lead creation-->

0 commit comments

Comments
 (0)