Skip to content

Commit 1748e79

Browse files
Implement resource pagination on table #15
Fixes #15 Signed-off-by: Rohit Yadav <[email protected]>
1 parent 0bd0fe2 commit 1748e79

File tree

6 files changed

+63
-20
lines changed

6 files changed

+63
-20
lines changed

ui/src/components/page/GlobalLayout.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export default {
156156
<style lang="less">
157157
.layout-content {
158158
&.is-header-fixed {
159-
margin: 76px 12px 0;
159+
margin: 78px 12px 0;
160160
}
161161
}
162162

ui/src/components/widgets/CardView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<span v-else>{{ item.name }}</span>
1919
</div>
2020
<div slot="description" style="height: 80px">
21-
<status :text="item.state" displayText />
21+
<status :text="item.state ? item.state : ''" displayText />
2222
<div v-if="item.ipaddress">
2323
<a-icon type="wifi" style="padding-right: 5px" />
2424
<router-link :to="{ path: $route.path + '/' + item.id }">{{ item.ipaddress }}</router-link>

ui/src/components/widgets/DataView.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@ export default {
3939
}
4040
</script>
4141

42-
<style scoped>
42+
<style>
43+
.info-card {
44+
margin-top: 12px;
45+
}
4346
</style>

ui/src/components/widgets/ListView.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
:loading="loading"
55
:columns="columns"
66
:dataSource="items"
7-
:rowKey="record => record.id"
7+
:rowKey="record => record.id || record.name"
88
:scroll="{ x: '100%' }"
9-
:pagination="{ position: 'bottom', size: 'small', showSizeChanger: true }"
9+
:pagination="false"
1010
:rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
1111
:rowClassName="getRowClassName"
1212
>
@@ -33,7 +33,7 @@
3333
<router-link :to="{ path: '/vm/' + record.virtualmachineid }">{{ text }}</router-link>
3434
</a>
3535
<template slot="state" slot-scope="text">
36-
<status :text="text" />
36+
<status :text="text ? text : ''" />
3737
</template>
3838

3939
<a slot="account" slot-scope="text, record" href="javascript:;">

ui/src/locales/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ Vue.use(VueI18n)
1919
export default new VueI18n({
2020
locale: Vue.ls ? Vue.ls.get('current_locale') || 'en' : 'en',
2121
fallbackLocale: 'en',
22+
silentTranslationWarn: true,
2223
messages: loadLocaleMessages()
2324
})

ui/src/views/AutogenView.vue

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<breadcrumb v-if="device !== 'desktop'" style="margin-left: -16px; margin-right: -16px; margin-top: -16px" />
3+
<breadcrumb v-if="device !== 'desktop'" class="mobile-breadcrumb" />
44
<a-row>
55
<a-col :span="17">
66
<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 @@
7575
<a-input-search
7676
size="default"
7777
placeholder="Search"
78-
@search="onSearch"
78+
v-model="searchQuery"
7979
v-if="!dataView"
80+
@search="onSearch"
8081
>
8182
<a-icon slot="prefix" type="search" />
8283
</a-input-search>
@@ -170,7 +171,7 @@
170171
<component :is="$route.meta.viewComponent" :resource="resource" v-if="$route.meta.viewComponent"/></component>
171172
<data-view :resource="resource" v-else />
172173
</div>
173-
<div style="margin-top: 12px" v-else>
174+
<div class="row-element" v-else>
174175
<list-view
175176
:loading="loading"
176177
:columns="columns"
@@ -180,8 +181,18 @@
180181
:items="items"
181182
:loading="loading"
182183
v-show="!tableView" />
184+
<a-pagination
185+
class="row-element"
186+
size="small"
187+
:current="page"
188+
:pageSize="pageSize"
189+
:total="itemCount"
190+
:showTotal="total => `Total ${total} items`"
191+
:pageSizeOptions="['20', '40', '80', '100']"
192+
@change="changePage"
193+
@showSizeChange="changePageSize"
194+
showSizeChanger />
183195
</div>
184-
185196
</div>
186197
</template>
187198

@@ -214,6 +225,10 @@ export default {
214225
autoRefresh: false,
215226
columns: [],
216227
items: [],
228+
itemCount: 0,
229+
page: 1,
230+
pageSize: 20,
231+
searchQuery: '',
217232
resource: {},
218233
selectedRowKeys: [],
219234
currentAction: {},
@@ -234,6 +249,7 @@ export default {
234249
watch: {
235250
'$route' (to, from) {
236251
if (to.fullPath !== from.fullPath && !to.fullPath.includes('action/')) {
252+
this.page = 1
237253
this.fetchData()
238254
}
239255
},
@@ -247,7 +263,7 @@ export default {
247263
this.form = this.$form.createForm(this)
248264
},
249265
methods: {
250-
fetchData (search = '') {
266+
fetchData () {
251267
this.routeName = this.$route.name
252268
if (!this.routeName) {
253269
this.routeName = this.$route.matched[this.$route.matched.length - 1].parent.name
@@ -263,8 +279,8 @@ export default {
263279
Object.assign(params, this.$route.meta.params)
264280
}
265281
266-
if (search !== '') {
267-
params['keyword'] = search
282+
if (this.searchQuery !== '') {
283+
params['keyword'] = this.searchQuery
268284
}
269285
270286
if (this.$route && this.$route.params && this.$route.params.id) {
@@ -316,6 +332,8 @@ export default {
316332
if (this.$route.params && this.$route.params.id) {
317333
params['id'] = this.$route.params.id
318334
}
335+
params['page'] = this.page
336+
params['pagesize'] = this.pageSize
319337
api(this.apiName, params).then(json => {
320338
this.loading = false
321339
var responseName
@@ -327,7 +345,10 @@ export default {
327345
}
328346
}
329347
for (const key in json[responseName]) {
330-
if (key === 'count') continue
348+
if (key === 'count') {
349+
this.itemCount = json[responseName]['count']
350+
continue
351+
}
331352
objectName = key
332353
break
333354
}
@@ -346,7 +367,8 @@ export default {
346367
})
347368
},
348369
onSearch (value) {
349-
this.fetchData(value)
370+
this.searchQuery = value
371+
this.fetchData()
350372
},
351373
toggleAutoRefresh () {
352374
this.autoRefresh = !this.autoRefresh
@@ -506,6 +528,16 @@ export default {
506528
}
507529
})
508530
},
531+
changePage (page, pageSize) {
532+
this.page = page
533+
this.pageSize = pageSize
534+
this.fetchData()
535+
},
536+
changePageSize (currentPage, pageSize) {
537+
this.page = currentPage
538+
this.pageSize = pageSize
539+
this.fetchData()
540+
},
509541
start () {
510542
this.loading = true
511543
this.fetchData()
@@ -518,18 +550,25 @@ export default {
518550
}
519551
</script>
520552

521-
<style>
522-
.info-card {
523-
margin-top: 12px;
553+
<style scoped>
554+
555+
.mobile-breadcrumb {
556+
margin-left: -16px;
557+
margin-right: -16px;
558+
margin-top: -16px;
559+
padding-bottom: 16px;
560+
}
561+
562+
.row-element {
563+
margin-top: 10px;
564+
margin-bottom: 10px;
524565
}
525566
526567
.ant-breadcrumb {
527568
vertical-align: text-bottom;
528-
margin-bottom: 8px;
529569
}
530570
531571
.ant-breadcrumb .anticon {
532572
margin-left: 8px;
533573
}
534-
535574
</style>

0 commit comments

Comments
 (0)