fix: fix users view

This commit is contained in:
woothu
2019-10-19 15:28:42 +02:00
parent 988bb84576
commit b24bdc4f6e
2 changed files with 32 additions and 40 deletions
+6 -13
View File
@@ -10,12 +10,12 @@
striped striped
small small
fixed fixed
:items="items($route.params.id)" :items="getUserData($route.params.id)"
:fields="$options.fields" :fields="$options.fields"
/> />
</CCardBody> </CCardBody>
<CCardFooter> <CCardFooter>
<CButton @click="goBack">Back</CButton> <CButton color="primary" @click="goBack">Back</CButton>
</CCardFooter> </CCardFooter>
</CCard> </CCard>
</CCol> </CCol>
@@ -26,25 +26,18 @@
import usersData from './UsersData' import usersData from './UsersData'
export default { export default {
name: 'User', name: 'User',
props: {
caption: {
type: String,
default: 'User id'
},
},
fields: [ fields: [
{ key: 'key', _style: 'width:150px' }, { key: 'key', _style: 'width:150px' },
{ key: 'value' , _style:'width:150px;', _classes:'font-weight-bold'} { key: 'value' , _style: 'width:150px;' }
], ],
methods: { methods: {
items (id) { getUserData (id) {
const user = usersData.find( user => user.id.toString() === id) const user = usersData.find((user, index) => index + 1 == id)
const userDetails = user ? Object.entries(user) : [['id', 'Not found']] const userDetails = user ? Object.entries(user) : [['id', 'Not found']]
return userDetails.map(([key, value]) => {return {key: key, value: value}}) return userDetails.map(([key, value]) => { return { key, value } })
}, },
goBack() { goBack() {
this.$router.go(-1) this.$router.go(-1)
// this.$router.replace({path: '/users'})
} }
} }
} }
+17 -18
View File
@@ -2,28 +2,31 @@
<CRow> <CRow>
<CCol col="12" xl="8"> <CCol col="12" xl="8">
<transition name="slide"> <transition name="slide">
<CCard header-html="users" body-wrapper> <CCard header-html="Users" body-wrapper>
<CTable <CTable
hover hover
striped striped
:items="items" :items="items"
:fields="fields" :fields="fields"
:current-page="currentPage" :items-per-page="perPage"
:per-page="perPage"
@row-clicked="rowClicked" @row-clicked="rowClicked"
:pagination="$options.paginationProps" :pagination="$options.paginationProps"
index-column
clickable-rows
> >
<td slot="id" slot-scope="data"> <template #username="data">
<strong>{{data.item.id}}</strong> <td>
<strong>{{data.item.username}}</strong>
</td> </td>
<td slot="name" slot-scope="data"> </template>
<strong>{{data.item.name}}</strong>
</td> <template #status="data">
<td slot="status" slot-scope="data"> <td>
<CBadge :color="getBadge(data.item.status)"> <CBadge :color="getBadge(data.item.status)">
{{data.item.status}} {{data.item.status}}
</CBadge> </CBadge>
</td> </td>
</template>
</CTable> </CTable>
</CCard> </CCard>
</transition> </transition>
@@ -37,22 +40,19 @@ export default {
name: 'Users', name: 'Users',
data: () => { data: () => {
return { return {
items: usersData.filter((user) => user.id < 42), items: usersData,
fields: [ fields: [
{key: 'id'}, { key: 'username', label: 'Name' },
{key: 'name'},
{ key: 'registered' }, { key: 'registered' },
{ key: 'role' }, { key: 'role' },
{ key: 'status' } { key: 'status' }
], ],
currentPage: 1,
perPage: 5, perPage: 5,
totalRows: 0
} }
}, },
paginationProps: { paginationProps: {
align: 'center', align: 'center',
hideDoubleArrows: true, doubleArrows: false,
previousButtonHtml: 'prev', previousButtonHtml: 'prev',
nextButtonHtml: 'next' nextButtonHtml: 'next'
}, },
@@ -66,11 +66,10 @@ export default {
userLink (id) { userLink (id) {
return `users/${id.toString()}` return `users/${id.toString()}`
}, },
rowClicked (item) { rowClicked (item, index) {
const userLink = this.userLink(item.id) const userLink = this.userLink(index + 1)
this.$router.push({path: userLink}) this.$router.push({path: userLink})
} }
} }
} }
</script> </script>