Skip to content

Commit 07f6ca7

Browse files
committedMar 31, 2017
Ordenação e Filtros
1 parent 6298dad commit 07f6ca7

File tree

8 files changed

+94
-13
lines changed

8 files changed

+94
-13
lines changed
 

‎app/Http/Controllers/Api/BankAccountsController.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use CodeFin\Http\Requests\BankAccountCreateRequest;
99
use CodeFin\Http\Requests\BankAccountUpdateRequest;
1010
use CodeFin\Repositories\Interfaces\BankAccountRepository;
11-
use Prettus\Validator\Contracts\ValidatorInterface;
12-
use Prettus\Validator\Exceptions\ValidatorException;
1311

1412

1513
class BankAccountsController extends Controller
@@ -34,7 +32,7 @@ public function __construct(BankAccountRepository $repository)
3432
*/
3533
public function index()
3634
{
37-
return $this->repository->paginate(4);
35+
return $this->repository->paginate();
3836
}
3937

4038
/**
@@ -90,6 +88,6 @@ public function update(BankAccountUpdateRequest $request, $id)
9088
public function destroy($id)
9189
{
9290
$this->repository->delete($id);
93-
return response()->json([],204);
91+
return response()->json([], 204);
9492
}
9593
}

‎app/Repositories/BankAccountRepositoryEloquent.php

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
*/
1515
class BankAccountRepositoryEloquent extends BaseRepository implements BankAccountRepository
1616
{
17+
protected $fieldSearchable = [
18+
'name' => 'like',
19+
'agency' => 'like',
20+
'account' => 'like',
21+
'bank.name' => 'like'
22+
];
23+
1724
/**
1825
* Specify Model class name
1926
*

‎app/Repositories/Interfaces/BankAccountRepository.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
namespace CodeFin\Repositories\Interfaces;
44

5+
use Prettus\Repository\Contracts\RepositoryCriteriaInterface;
56
use Prettus\Repository\Contracts\RepositoryInterface;
67

78
/**
89
* Interface BankAccountRepository
910
* @package namespace CodeFin\Repositories\Interfaces;
1011
*/
11-
interface BankAccountRepository extends RepositoryInterface
12+
interface BankAccountRepository extends RepositoryInterface, RepositoryCriteriaInterface
1213
{
1314
//
1415
}

‎config/repository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
|
1616
*/
1717
'pagination' => [
18-
'limit' => 15
18+
'limit' => 10
1919
],
2020

2121
/*

‎public/css/spa.css

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎public/css/spa.css.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎resources/assets/spa/js/components/bank-account/BankAccountList.vue

+58-6
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,27 @@
77
</span>
88
</div>
99
<div class="card-panel z-depth-5">
10+
<form name="form" method="GET" @submit="filter()">
11+
<div class="filter-group">
12+
<button class="btn waves-effect" @click.prevent="filter()">
13+
<i class="material-icons">search</i>
14+
</button>
15+
<div class="filter-wrapper">
16+
<input type="text" v-model="search" placeholder="Buscar.."/>
17+
</div>
18+
</div>
19+
</form>
1020
<table class="bordered striped hightlight responsive-table">
1121
<thead>
1222
<tr>
13-
<th>#</th>
14-
<th>Nome</th>
15-
<th>Agência</th>
16-
<th>C/C</th>
23+
<th v-for="(key,o) in table.headers" :width="o.width">
24+
<a href="#" @click.prevent="sortBy(key)">
25+
{{o.label}}
26+
<i class="material-icons left" v-if="order.key==key">
27+
{{order.sort == 'asc' ? 'arrow_drop_up' : 'arrow_drop_down'}}
28+
</i>
29+
</a>
30+
</th>
1731
<th>Ações</th>
1832
</tr>
1933
</thead>
@@ -30,7 +44,8 @@
3044
</tr>
3145
</tbody>
3246
</table>
33-
<pagination :current-page.sync="pagination.current_page" :per-page="pagination.per_page" :total-records="pagination.total"></pagination>
47+
<pagination :current-page.sync="pagination.current_page" :per-page="pagination.per_page"
48+
:total-records="pagination.total"></pagination>
3449
</div>
3550

3651
<div class="fixed-action-btn">
@@ -77,6 +92,31 @@
7792
current_page: 0,
7893
per_page: 0,
7994
total: 0
95+
},
96+
search: '',
97+
order: {
98+
key: 'id',
99+
sort: 'asc'
100+
},
101+
table: {
102+
headers: {
103+
id: {
104+
label: '#',
105+
width: '10%'
106+
},
107+
name: {
108+
label: 'Nome',
109+
width: '45%'
110+
},
111+
agency: {
112+
label: 'Agência',
113+
width: '15%'
114+
},
115+
account: {
116+
label: 'C/C',
117+
width: '15%'
118+
}
119+
}
80120
}
81121
}
82122
},
@@ -97,13 +137,24 @@
97137
},
98138
getBankAccounts(){
99139
BankAccount.query({
100-
page: this.pagination.current_page + 1
140+
page: this.pagination.current_page + 1,
141+
orderBy: this.order.key,
142+
sortedBy: this.order.sort,
143+
search: this.search
101144
}).then((response) => {
102145
this.bankAccounts = response.data.data;
103146
let pagination = response.data.meta.pagination;
104147
pagination.current_page--;
105148
this.pagination = pagination;
106149
});
150+
},
151+
sortBy(key){
152+
this.order.key = key;
153+
this.order.sort = this.order.sort == 'desc' ? 'asc' : 'desc';
154+
this.getBankAccounts();
155+
},
156+
filter(){
157+
this.getBankAccounts();
107158
}
108159
},
109160
events: {
@@ -113,4 +164,5 @@
113164
}
114165
}
115166
167+
116168
</script>

‎resources/assets/spa/sass/spa.scss

+12
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,16 @@ main{
2626

2727
#sidenav-overlay {
2828
z-index: 996 !important;
29+
}
30+
31+
.filter-group{
32+
.btn{
33+
float: right;
34+
height: 3rem;
35+
line-height: 3rem;
36+
}
37+
.filter-wrapper{
38+
overflow: hidden;
39+
padding-right: 10px;
40+
}
2941
}

0 commit comments

Comments
 (0)
Please sign in to comment.