Skip to content

Commit f1db4d4

Browse files
davidjumaniyadvr
authored andcommitted
compute: Fix ListResourceTable (#513)
Fixes #512 Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent b48ede5 commit f1db4d4

File tree

2 files changed

+104
-25
lines changed

2 files changed

+104
-25
lines changed

ui/src/components/view/ListResourceTable.vue

Lines changed: 97 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,54 @@
1616
// under the License.
1717

1818
<template>
19-
<a-table
20-
size="small"
21-
:columns="fetchColumns()"
22-
:dataSource="items"
23-
:rowKey="item => item.id"
24-
:loading="loading"
25-
:pagination="false" >
19+
<div>
20+
<a-input-search
21+
v-if="showSearch"
22+
style="width: 25vw;float: right;margin-bottom: 10px; z-index: 8"
23+
:placeholder="$t('label.search')"
24+
v-model="filter"
25+
@search="handleSearch" />
2626

27-
<template v-if="routerlink" :slot="routerlink.name" slot-scope="text, item">
28-
<router-link :to="{ path: routerlink.prefix + item.id }" v-if="routerlink.prefix">{{ text }}</router-link>
29-
<span v-else>{{ text }}</span>
30-
</template>
31-
<template slot="state" slot-scope="text">
32-
<status :text="text ? text : ''" />{{ text }}
33-
</template>
27+
<a-table
28+
size="small"
29+
:columns="fetchColumns()"
30+
:dataSource="items"
31+
:rowKey="item => item.id"
32+
:loading="loading"
33+
:pagination="false"
34+
@change="handleTableChange"
35+
@handle-search-filter="handleTableChange" >
36+
37+
<template v-for="(column, index) in Object.keys(routerlinks({}))" :slot="column" slot-scope="text, item" >
38+
<span :key="index">
39+
<router-link :set="routerlink = routerlinks(item)" :to="{ path: routerlink[column] }" >{{ text }}</router-link>
40+
</span>
41+
</template>
42+
43+
<template slot="state" slot-scope="text">
44+
<status :text="text ? text : ''" />{{ text }}
45+
</template>
46+
47+
<template slot="status" slot-scope="text">
48+
<status :text="text ? text : ''" />{{ text }}
49+
</template>
50+
51+
</a-table>
52+
53+
<div style="display: block; text-align: right; margin-top: 10px;">
54+
<a-pagination
55+
size="small"
56+
:current="options.page"
57+
:pageSize="options.pageSize"
58+
:total="total"
59+
:showTotal="total => `Total ${total} items`"
60+
:pageSizeOptions="['10', '20', '40']"
61+
@change="handleTableChange"
62+
@showSizeChange="handlePageSizeChange"
63+
showSizeChanger />
64+
</div>
65+
</div>
3466

35-
</a-table>
3667
</template>
3768

3869
<script>
@@ -45,13 +76,17 @@ export default {
4576
Status
4677
},
4778
props: {
79+
resource: {
80+
type: Object,
81+
default: () => {}
82+
},
4883
apiName: {
4984
type: String,
5085
required: true
5186
},
52-
routerlink: {
53-
type: Object,
54-
default: () => {}
87+
routerlinks: {
88+
type: Function,
89+
default: () => { return {} }
5590
},
5691
params: {
5792
type: Object,
@@ -60,12 +95,35 @@ export default {
6095
columns: {
6196
type: Array,
6297
required: true
98+
},
99+
showSearch: {
100+
type: Boolean,
101+
default: true
63102
}
64103
},
65104
data () {
66105
return {
67106
loading: false,
68-
items: []
107+
items: [],
108+
total: 0,
109+
filter: '',
110+
options: {
111+
page: 1,
112+
pageSize: 10,
113+
keyword: null
114+
}
115+
}
116+
},
117+
watch: {
118+
resource (newItem, oldItem) {
119+
if (newItem !== oldItem) {
120+
this.fetchData()
121+
}
122+
},
123+
'$i18n.locale' (to, from) {
124+
if (to !== from) {
125+
this.fetchData()
126+
}
69127
}
70128
},
71129
mounted () {
@@ -74,11 +132,11 @@ export default {
74132
methods: {
75133
fetchData () {
76134
this.loading = true
77-
var params = this.params
135+
var params = { ...this.params, ...this.options }
78136
params.listall = true
79137
params.response = 'json'
80138
params.details = 'min'
81-
api(this.apiName, this.params).then(json => {
139+
api(this.apiName, params).then(json => {
82140
var responseName
83141
var objectName
84142
for (const key in json) {
@@ -89,6 +147,7 @@ export default {
89147
}
90148
for (const key in json[responseName]) {
91149
if (key === 'count') {
150+
this.total = json[responseName][key]
92151
continue
93152
}
94153
objectName = key
@@ -112,6 +171,23 @@ export default {
112171
})
113172
}
114173
return columns
174+
},
175+
handleSearch (value) {
176+
this.filter = value
177+
this.options.page = 1
178+
this.options.pageSize = 10
179+
this.options.keyword = this.filter
180+
this.fetchData()
181+
},
182+
handleTableChange (page, pagesize) {
183+
this.options.page = page
184+
this.options.pageSize = pagesize
185+
this.fetchData()
186+
},
187+
handlePageSizeChange (page, pagesize) {
188+
this.options.page = 1
189+
this.options.pageSize = pagesize
190+
this.fetchData()
115191
}
116192
}
117193
}

ui/src/views/compute/InstanceTab.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,19 @@
118118
<a-tab-pane :tab="$t('label.vm.snapshots')" key="vmsnapshots" v-if="'listVMSnapshot' in $store.getters.apis">
119119
<ListResourceTable
120120
apiName="listVMSnapshot"
121+
:resource="resource"
121122
:params="{virtualmachineid: this.resource.id}"
122-
:columns="['name', 'state', 'type', 'created']"
123-
:routerlink="{name: 'name', prefix: '/vmsnapshot/'}"/>
123+
:columns="['displayname', 'state', 'type', 'created']"
124+
:routerlinks="(record) => { return { displayname: '/vmsnapshot/' + record.id } }"/>
124125
</a-tab-pane>
125126
<a-tab-pane :tab="$t('label.backup')" key="backups" v-if="'listBackups' in $store.getters.apis">
126127
<ListResourceTable
127128
apiName="listBackups"
129+
:resource="resource"
128130
:params="{virtualmachineid: this.resource.id}"
129-
:columns="['id', 'state', 'type', 'created']"
130-
:routerlink="{name: 'id', prefix: '/backup/'}"/>
131+
:columns="['id', 'status', 'type', 'created']"
132+
:routerlinks="(record) => { return { id: '/backup/' + record.id } }"
133+
:showSearch="false"/>
131134
</a-tab-pane>
132135
<a-tab-pane :tab="$t('label.settings')" key="settings">
133136
<DetailSettings :resource="resource" :loading="loading" />

0 commit comments

Comments
 (0)