Skip to content

Commit b24bdc4

Browse files
committed
fix: fix users view
1 parent 988bb84 commit b24bdc4

File tree

2 files changed

+32
-40
lines changed

2 files changed

+32
-40
lines changed

src/views/users/User.vue

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
striped
1111
small
1212
fixed
13-
:items="items($route.params.id)"
13+
:items="getUserData($route.params.id)"
1414
:fields="$options.fields"
1515
/>
1616
</CCardBody>
1717
<CCardFooter>
18-
<CButton @click="goBack">Back</CButton>
18+
<CButton color="primary" @click="goBack">Back</CButton>
1919
</CCardFooter>
2020
</CCard>
2121
</CCol>
@@ -26,25 +26,18 @@
2626
import usersData from './UsersData'
2727
export default {
2828
name: 'User',
29-
props: {
30-
caption: {
31-
type: String,
32-
default: 'User id'
33-
},
34-
},
3529
fields: [
36-
{ key: 'key', _style:'width:150px'},
37-
{ key: 'value' , _style:'width:150px;', _classes:'font-weight-bold'}
30+
{ key: 'key', _style: 'width:150px' },
31+
{ key: 'value' , _style: 'width:150px;' }
3832
],
3933
methods: {
40-
items (id) {
41-
const user = usersData.find( user => user.id.toString() === id)
34+
getUserData (id) {
35+
const user = usersData.find((user, index) => index + 1 == id)
4236
const userDetails = user ? Object.entries(user) : [['id', 'Not found']]
43-
return userDetails.map(([key, value]) => {return {key: key, value: value}})
37+
return userDetails.map(([key, value]) => { return { key, value } })
4438
},
4539
goBack() {
4640
this.$router.go(-1)
47-
// this.$router.replace({path: '/users'})
4841
}
4942
}
5043
}

src/views/users/Users.vue

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,31 @@
22
<CRow>
33
<CCol col="12" xl="8">
44
<transition name="slide">
5-
<CCard header-html="users" body-wrapper>
5+
<CCard header-html="Users" body-wrapper>
66
<CTable
77
hover
88
striped
99
:items="items"
1010
:fields="fields"
11-
:current-page="currentPage"
12-
:per-page="perPage"
11+
:items-per-page="perPage"
1312
@row-clicked="rowClicked"
1413
:pagination="$options.paginationProps"
14+
index-column
15+
clickable-rows
1516
>
16-
<td slot="id" slot-scope="data">
17-
<strong>{{data.item.id}}</strong>
18-
</td>
19-
<td slot="name" slot-scope="data">
20-
<strong>{{data.item.name}}</strong>
21-
</td>
22-
<td slot="status" slot-scope="data">
23-
<CBadge :color="getBadge(data.item.status)">
24-
{{data.item.status}}
25-
</CBadge>
26-
</td>
17+
<template #username="data">
18+
<td>
19+
<strong>{{data.item.username}}</strong>
20+
</td>
21+
</template>
22+
23+
<template #status="data">
24+
<td>
25+
<CBadge :color="getBadge(data.item.status)">
26+
{{data.item.status}}
27+
</CBadge>
28+
</td>
29+
</template>
2730
</CTable>
2831
</CCard>
2932
</transition>
@@ -37,22 +40,19 @@ export default {
3740
name: 'Users',
3841
data: () => {
3942
return {
40-
items: usersData.filter((user) => user.id < 42),
43+
items: usersData,
4144
fields: [
42-
{key: 'id'},
43-
{key: 'name'},
44-
{key: 'registered'},
45-
{key: 'role'},
46-
{key: 'status'}
45+
{ key: 'username', label: 'Name' },
46+
{ key: 'registered' },
47+
{ key: 'role' },
48+
{ key: 'status' }
4749
],
48-
currentPage: 1,
4950
perPage: 5,
50-
totalRows: 0
5151
}
5252
},
5353
paginationProps: {
5454
align: 'center',
55-
hideDoubleArrows: true,
55+
doubleArrows: false,
5656
previousButtonHtml: 'prev',
5757
nextButtonHtml: 'next'
5858
},
@@ -66,11 +66,10 @@ export default {
6666
userLink (id) {
6767
return `users/${id.toString()}`
6868
},
69-
rowClicked (item) {
70-
const userLink = this.userLink(item.id)
69+
rowClicked (item, index) {
70+
const userLink = this.userLink(index + 1)
7171
this.$router.push({path: userLink})
7272
}
73-
7473
}
7574
}
7675
</script>

0 commit comments

Comments
 (0)