Implement resource pagination on table #15

Fixes #15

Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
Rohit Yadav 2019-09-25 12:55:48 +05:30
parent 0bd0fe2880
commit 1748e79ec4
6 changed files with 63 additions and 20 deletions

View File

@ -156,7 +156,7 @@ export default {
<style lang="less"> <style lang="less">
.layout-content { .layout-content {
&.is-header-fixed { &.is-header-fixed {
margin: 76px 12px 0; margin: 78px 12px 0;
} }
} }

View File

@ -18,7 +18,7 @@
<span v-else>{{ item.name }}</span> <span v-else>{{ item.name }}</span>
</div> </div>
<div slot="description" style="height: 80px"> <div slot="description" style="height: 80px">
<status :text="item.state" displayText /> <status :text="item.state ? item.state : ''" displayText />
<div v-if="item.ipaddress"> <div v-if="item.ipaddress">
<a-icon type="wifi" style="padding-right: 5px" /> <a-icon type="wifi" style="padding-right: 5px" />
<router-link :to="{ path: $route.path + '/' + item.id }">{{ item.ipaddress }}</router-link> <router-link :to="{ path: $route.path + '/' + item.id }">{{ item.ipaddress }}</router-link>

View File

@ -39,5 +39,8 @@ export default {
} }
</script> </script>
<style scoped> <style>
.info-card {
margin-top: 12px;
}
</style> </style>

View File

@ -4,9 +4,9 @@
:loading="loading" :loading="loading"
:columns="columns" :columns="columns"
:dataSource="items" :dataSource="items"
:rowKey="record => record.id" :rowKey="record => record.id || record.name"
:scroll="{ x: '100%' }" :scroll="{ x: '100%' }"
:pagination="{ position: 'bottom', size: 'small', showSizeChanger: true }" :pagination="false"
:rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
:rowClassName="getRowClassName" :rowClassName="getRowClassName"
> >
@ -33,7 +33,7 @@
<router-link :to="{ path: '/vm/' + record.virtualmachineid }">{{ text }}</router-link> <router-link :to="{ path: '/vm/' + record.virtualmachineid }">{{ text }}</router-link>
</a> </a>
<template slot="state" slot-scope="text"> <template slot="state" slot-scope="text">
<status :text="text" /> <status :text="text ? text : ''" />
</template> </template>
<a slot="account" slot-scope="text, record" href="javascript:;"> <a slot="account" slot-scope="text, record" href="javascript:;">

View File

@ -19,5 +19,6 @@ Vue.use(VueI18n)
export default new VueI18n({ export default new VueI18n({
locale: Vue.ls ? Vue.ls.get('current_locale') || 'en' : 'en', locale: Vue.ls ? Vue.ls.get('current_locale') || 'en' : 'en',
fallbackLocale: 'en', fallbackLocale: 'en',
silentTranslationWarn: true,
messages: loadLocaleMessages() messages: loadLocaleMessages()
}) })

View File

@ -1,6 +1,6 @@
<template> <template>
<div> <div>
<breadcrumb v-if="device !== 'desktop'" style="margin-left: -16px; margin-right: -16px; margin-top: -16px" /> <breadcrumb v-if="device !== 'desktop'" class="mobile-breadcrumb" />
<a-row> <a-row>
<a-col :span="17"> <a-col :span="17">
<a-tooltip placement="bottom" v-for="(action, actionIndex) in actions" :key="actionIndex" v-if="(!dataView && (action.listView || action.groupAction && selectedRowKeys.length > 0)) || (dataView && action.dataView)"> <a-tooltip placement="bottom" v-for="(action, actionIndex) in actions" :key="actionIndex" v-if="(!dataView && (action.listView || action.groupAction && selectedRowKeys.length > 0)) || (dataView && action.dataView)">
@ -75,8 +75,9 @@
<a-input-search <a-input-search
size="default" size="default"
placeholder="Search" placeholder="Search"
@search="onSearch" v-model="searchQuery"
v-if="!dataView" v-if="!dataView"
@search="onSearch"
> >
<a-icon slot="prefix" type="search" /> <a-icon slot="prefix" type="search" />
</a-input-search> </a-input-search>
@ -170,7 +171,7 @@
<component :is="$route.meta.viewComponent" :resource="resource" v-if="$route.meta.viewComponent"/></component> <component :is="$route.meta.viewComponent" :resource="resource" v-if="$route.meta.viewComponent"/></component>
<data-view :resource="resource" v-else /> <data-view :resource="resource" v-else />
</div> </div>
<div style="margin-top: 12px" v-else> <div class="row-element" v-else>
<list-view <list-view
:loading="loading" :loading="loading"
:columns="columns" :columns="columns"
@ -180,8 +181,18 @@
:items="items" :items="items"
:loading="loading" :loading="loading"
v-show="!tableView" /> v-show="!tableView" />
<a-pagination
class="row-element"
size="small"
:current="page"
:pageSize="pageSize"
:total="itemCount"
:showTotal="total => `Total ${total} items`"
:pageSizeOptions="['20', '40', '80', '100']"
@change="changePage"
@showSizeChange="changePageSize"
showSizeChanger />
</div> </div>
</div> </div>
</template> </template>
@ -214,6 +225,10 @@ export default {
autoRefresh: false, autoRefresh: false,
columns: [], columns: [],
items: [], items: [],
itemCount: 0,
page: 1,
pageSize: 20,
searchQuery: '',
resource: {}, resource: {},
selectedRowKeys: [], selectedRowKeys: [],
currentAction: {}, currentAction: {},
@ -234,6 +249,7 @@ export default {
watch: { watch: {
'$route' (to, from) { '$route' (to, from) {
if (to.fullPath !== from.fullPath && !to.fullPath.includes('action/')) { if (to.fullPath !== from.fullPath && !to.fullPath.includes('action/')) {
this.page = 1
this.fetchData() this.fetchData()
} }
}, },
@ -247,7 +263,7 @@ export default {
this.form = this.$form.createForm(this) this.form = this.$form.createForm(this)
}, },
methods: { methods: {
fetchData (search = '') { fetchData () {
this.routeName = this.$route.name this.routeName = this.$route.name
if (!this.routeName) { if (!this.routeName) {
this.routeName = this.$route.matched[this.$route.matched.length - 1].parent.name this.routeName = this.$route.matched[this.$route.matched.length - 1].parent.name
@ -263,8 +279,8 @@ export default {
Object.assign(params, this.$route.meta.params) Object.assign(params, this.$route.meta.params)
} }
if (search !== '') { if (this.searchQuery !== '') {
params['keyword'] = search params['keyword'] = this.searchQuery
} }
if (this.$route && this.$route.params && this.$route.params.id) { if (this.$route && this.$route.params && this.$route.params.id) {
@ -316,6 +332,8 @@ export default {
if (this.$route.params && this.$route.params.id) { if (this.$route.params && this.$route.params.id) {
params['id'] = this.$route.params.id params['id'] = this.$route.params.id
} }
params['page'] = this.page
params['pagesize'] = this.pageSize
api(this.apiName, params).then(json => { api(this.apiName, params).then(json => {
this.loading = false this.loading = false
var responseName var responseName
@ -327,7 +345,10 @@ export default {
} }
} }
for (const key in json[responseName]) { for (const key in json[responseName]) {
if (key === 'count') continue if (key === 'count') {
this.itemCount = json[responseName]['count']
continue
}
objectName = key objectName = key
break break
} }
@ -346,7 +367,8 @@ export default {
}) })
}, },
onSearch (value) { onSearch (value) {
this.fetchData(value) this.searchQuery = value
this.fetchData()
}, },
toggleAutoRefresh () { toggleAutoRefresh () {
this.autoRefresh = !this.autoRefresh this.autoRefresh = !this.autoRefresh
@ -506,6 +528,16 @@ export default {
} }
}) })
}, },
changePage (page, pageSize) {
this.page = page
this.pageSize = pageSize
this.fetchData()
},
changePageSize (currentPage, pageSize) {
this.page = currentPage
this.pageSize = pageSize
this.fetchData()
},
start () { start () {
this.loading = true this.loading = true
this.fetchData() this.fetchData()
@ -518,18 +550,25 @@ export default {
} }
</script> </script>
<style> <style scoped>
.info-card {
margin-top: 12px; .mobile-breadcrumb {
margin-left: -16px;
margin-right: -16px;
margin-top: -16px;
padding-bottom: 16px;
}
.row-element {
margin-top: 10px;
margin-bottom: 10px;
} }
.ant-breadcrumb { .ant-breadcrumb {
vertical-align: text-bottom; vertical-align: text-bottom;
margin-bottom: 8px;
} }
.ant-breadcrumb .anticon { .ant-breadcrumb .anticon {
margin-left: 8px; margin-left: 8px;
} }
</style> </style>