8000 Implemented the third phase of CRUD users · vs0uz4/l5vueka-laravel-vuejs@f498183 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit f498183

Browse files
committed
Implemented the third phase of CRUD users
- Created method update in UsersControllers; - Imported bus event for VdUsersTable component; - Implemented 'edit' method in VdUsersTable component; - Pre-initiate 'remove' method in VdUsersTable component; - Adjusted the columns styles of the table; - Refactor the VdUserForm component to accept editing method.
1 parent 9c25789 commit f498183

File tree

6 files changed

+89
-36
lines changed

6 files changed

+89
-36
lines changed

app/Http/Controllers/UsersController.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,20 @@ public function create()
2626
return redirect()->route('user.index')->with('success', 'Usuário Cadastrado com Sucesso!');
2727
}
2828

29-
public function update()
29+
public function update($id)< 8000 /div>
3030
{
31+
$input = \Request::only('name', 'email', 'password');
32+
33+
$user = User::find($id);
34+
$user->name = $input['name'];
35+
$user->email = $input['email'];
36+
37+
if (!empty($input['password'])) {
38+
$user->password = bcrypt($input['password']);
39+
}
40+
$user->save();
3141

42+
return redirect()->route('user.index')->with('success', 'Usuário Atualizado com Sucesso!');
3243
}
3344

3445
public function remove()

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

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

public/build/rev-manifest.json

+1-1
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-bc3d901cc2.js"
4+
"js/app.js": "js/app-0eda38ff77.js"
55
}

public/js/app.js

+10-10
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

+43-8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,48 @@
22
import bus from '../utils/events/bus'
33
export default {
44
props: ['token'],
5+
data () {
6+
return {
7+
user: {
8+
id: 0,
9+
name: '',
10+
email: '',
11+
password: '',
12+
created_at: '',
13+
updated_at: '',
14+
}
15+
}
16+
},
17+
computed: {
18+
isEditing () {
19+
return this.user.id !== 0
20+
},
21+
action () {
22+
if (this.isEditing) {
23+
return `/usuarios/atualizar/${this.user.id}`
24+
} else {
25+
return `/usuarios/criar`
26+
}
27+
},
28+
},
529
mounted () {
6-
jQuery(this.$refs.userFormModal).on('hidden.bs.modal', () => {
7-
this.$refs.userForm.reset()
30+
const userFormModal = jQuery(this.$refs.userFormModal)
31+
32+
bus.$on('open-form', (obj) => {
33+
if (obj !== undefined){
34+
this.user = obj.user
35+
}
36+
37+
userFormModal.modal('show')
838
})
939
10-
bus.$on('open-form', () => {
11-
jQuery(this.$refs.userFormModal).modal('show')
40+
userFormModal.on('hidden.bs.modal', () => {
41+
this.user.id = 0
42+
this.user.name = ''
43+
this.user.email = ''
44+
this.user.password = ''
45+
this.user.created_at = ''
46+
this.user.updated_at = ''
1247
})
1348
}
1449
}
@@ -27,19 +62,19 @@
2762
<h4 class="modal-title">Criar Novo Usuário</h4>
2863
</div>
2964
<div class="modal-body">
30-
<form ref="userForm" method="post" action="/usuarios/criar">
65+
<form ref="userForm" method="post" :action="action">
3166
<input id="_token" name="_token" type="hidden" :value="token">
3267
<div class="form-group">
3368
<label for="name" class="control-label">Nome</label>
34-
<input id="name" name="name" type="text" class="form-control">
69+
<input id="name" name="name" type="text" class="form-control" v-model="user.name">
3570
</div>
3671
<div class="form-group">
3772
<label for="email" class="control-label">E-mail</label>
38-
<input id="email" name="email" type="email" class="form-control">
73+
<input id="email" name="email" type="email" class="form-control" v-model="user.email">
3974
</div>
4075
<div class="form-group">
4176
<label for="password" class="control-label">Senha</label>
42-
<input id="password" name="password" type="password" class="form-control">
77+
<input id="password" name="password" type="password" class="form-control" v-model="user.password">
4378
</div>
4479
<div class="modal-footer">
4580
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script>
22
import moment from 'moment'
3+
import bus from '../utils/events/bus'
34
45
export default {
56
props: ['list'],
@@ -38,7 +39,13 @@
3839
},
3940
formatDate (date) {
4041
return moment(date).format('DD/MM/YYYY')
41-
}
42+
},
43+
edit (user) {
44+
bus.$emit('open-form', { user: user})
45+
},
46+
remove (id) {
47+
48+
},
4249
}
4350
}
4451
</script>
@@ -64,7 +71,7 @@
6471
</thead>
6572
<tbody v-for="user in users">
6673
<tr>
67-
<td class="text-center">
74+
<td width="2%" nowrap>
6875
<a href="#" @click.prevent="toggle(user.id)">
6976
<i class="fa fa-fw" :class="{
7077
'fa-plus-circle red' : !details.includes(user.id),
@@ -74,10 +81,10 @@
7481
</td>
7582
<td>{{ user.name }}</td>
7683
<td>{{ user.email }}</td>
77-
<td class="text-center">{{ formatDate(user.created_at) }}</td>
78-
<td class="text-center">
79-
<a href="#"><i class="fa fa-fw fa-pencil" aria-hidden="true"></i></a>
80-
<a href="#"><i class="fa fa-fw fa-trash-o" aria-hidden="true"></i></a>
84+
<td width="12%" class="text-center" nowrap>{{ formatDate(user.created_at) }}</td>
85+
<td width="1%" class="text-center" nowrap>
86+
<a href="#" @click.prevent="edit(user)"><i class="fa fa-fw fa-pencil" aria-hidden="true"></i></a>
87+
<a href="#" @click.prevent="remove(user.id)"><i class="fa fa-fw fa-trash-o" aria-hidden="true"></i></a>
8188
</td>
8289
</tr>
8390
<tr v-show="details.includes(user.id)">

0 commit comments

Comments
 (0)
0