Skip to content

Commit 376ba9d

Browse files
committed
Implemented the fourth phase of CRUD users
- Created 'remove' method in UsersControllers; - Refactored 'index' method in UsersControllers for list addresses; - Created 'remove' method in VdUsersTable component; - Changed VdUsersTable for view table only users exists; - Changed VdUsersTable for list users addresses; - Changed VdUsersTable 'edit' method for send bus event with title property; - Changed VdUserForm component for use dynamic modal titles; - Changed VdUsers component for send bus event with 'title' property.
1 parent f498183 commit 376ba9d

File tree

7 files changed

+57
-28
lines changed

7 files changed

+57
-28
lines changed

app/Http/Controllers/UsersController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class UsersController extends Controller
99
{
1010
public function index()
1111
{
12-
$users = User::all();
12+
$users = User::with('addresses')->get();
13+
1314
return view('users.index')->with(compact('users'));
1415
}
1516

@@ -42,8 +43,11 @@ public function update($id)
4243
return redirect()->route('user.index')->with('success', 'Usuário Atualizado com Sucesso!');
4344
}
4445

45-
public function remove()
46+
public function remove($id)
4647
{
48+
$user = User::find($id);
49+
$user->delete();
4750

51+
return redirect()->route('user.index')->with('success', 'Usuário Removido com Sucesso!');
4852
}
4953
}

public/build/js/app-0eda38ff77.js renamed to public/build/js/app-c6bfcb2ec9.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/rev-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"css/app.css": "css/app-ad87f36536.css",
33
"css/vendor.css": "css/vendor-0634183a17.css",
4-
"js/app.js": "js/app-0eda38ff77.js"
4+
"js/app.js": "js/app-c6bfcb2ec9.js"
55
}

public/js/app.js

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/js/app/users/form.vue

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,14 @@
88
id: 0,
99
name: '',
1010
email: '',
11-
password: '',
1211
created_at: '',
13-
updated_at: '',
14-
}
12+
updated_at: ''
13+
},
14+
modalTitle : '',
15+
isEditing: false,
1516
}
1617
},
1718
computed: {
18-
isEditing () {
19-
return this.user.id !== 0
20-
},
2119
action () {
2220
if (this.isEditing) {
2321
return `/usuarios/atualizar/${this.user.id}`
@@ -30,20 +28,26 @@
3028
const userFormModal = jQuery(this.$refs.userFormModal)
3129
3230
bus.$on('open-form', (obj) => {
33-
if (obj !== undefined){
31+
if (obj.user !== undefined){
32+
this.isEditing = true
3433
this.user = obj.user
34+
this.modalTitle = obj.title
35+
} else {
36+
this.isEditing = false
37+
this.modalTitle = obj.title
3538
}
3639
3740
userFormModal.modal('show')
3841
})
3942
4043
userFormModal.on('hidden.bs.modal', () => {
44+
this.isEditing = false
4145
this.user.id = 0
4246
this.user.name = ''
4347
this.user.email = ''
44-
this.user.password = ''
4548
this.user.created_at = ''
4649
this.user.updated_at = ''
50+
this.modalTitle = ''
4751
})
4852
}
4953
}
@@ -59,7 +63,7 @@
5963
<div class="modal-content">
6064
<div class="modal-header">
6165
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
62-
<h4 class="modal-title">Criar Novo Usuário</h4>
66+
<h4 class="modal-title"><i class="fa fa-fw fa-user"></i>{{ modalTitle }}</h4>
6367
</div>
6468
<div class="modal-body">
6569
<form ref="userForm" method="post" :action="action">

resources/assets/js/app/users/main.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
methods: {
1212
form (){
13-
bus.$emit('open-form')
13+
bus.$emit('open-form', { title: 'Criar Novo Usuário' })
1414
}
1515
}
1616
}

resources/assets/js/app/users/table.vue

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
users () {
1414
return JSON.parse(this.list)
1515
},
16+
hasUsers () {
17+
return this.users.length > 0
18+
},
1619
},
1720
methods: {
1821
toggle (id) {
@@ -41,18 +44,25 @@
4144
return moment(date).format('DD/MM/YYYY')
4245
},
4346
edit (user) {
44-
bus.$emit('open-form', { user: user})
47+
bus.$emit('open-form', { user: user, title: 'Editar Usuário'})
4548
},
4649
remove (id) {
50+
const confirm = window.confirm('Tem Certeza da Exclusão?')
4751
52+
if (confirm) {
53+
window.location = `usuarios/remover/${id}`
54+
}
4855
},
4956
}
5057
}
5158
</script>
5259

5360
<template>
5461
<div>
55-
<table class="table table-bordered table-striped">
62+
<h5 v-show="!hasUsers">
63+
Ainda Não Há Usuários Cadastrados.
64+
</h5>
65+
<table class="table table-bordered table-striped" v-show="hasUsers">
5666
<thead>
5767
<tr>
5868
<th class="text-center">
@@ -89,7 +99,11 @@
8999
</tr>
90100
<tr v-show="details.includes(user.id)">
91101
<td colspan="5">
92-
<i class="fa fa-fw fa-map-marker" aria-hidden="true"></i>Placeholder para Endereço
102+
<div class="row col-md-6" v-for="address in user.addresses">
103+
<div class="address">
104+
<i class="fa fa-fw fa-map-marker" aria-hidden="true"></i> {{ address.street }}, {{ address.number }} - {{ address.city }}, {{ address.state }}
105+
</div>
106+
</div>
93107
</td>
94108
</tr>
95109
</tbody>
@@ -98,6 +112,13 @@
98112
</template>
99113

100114
<style>
115+
.address {
116+
padding: 5px;
117+
margin: 5px 5px 5px 0;
118+
background-color: #f9f7ee;
119+
border: 1px solid #f3ede5;
120+
border-radius: 5px;
121+
}
101122
.green {
102123
color: red;
103124
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy