mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-22 05:24:54 +01:00
compute: Fix ListResourceTable (#513)
Fixes #512 Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
This commit is contained in:
parent
b48ede58e9
commit
f1db4d497f
@ -16,23 +16,54 @@
|
|||||||
// under the License.
|
// under the License.
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
<div>
|
||||||
|
<a-input-search
|
||||||
|
v-if="showSearch"
|
||||||
|
style="width: 25vw;float: right;margin-bottom: 10px; z-index: 8"
|
||||||
|
:placeholder="$t('label.search')"
|
||||||
|
v-model="filter"
|
||||||
|
@search="handleSearch" />
|
||||||
|
|
||||||
<a-table
|
<a-table
|
||||||
size="small"
|
size="small"
|
||||||
:columns="fetchColumns()"
|
:columns="fetchColumns()"
|
||||||
:dataSource="items"
|
:dataSource="items"
|
||||||
:rowKey="item => item.id"
|
:rowKey="item => item.id"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
:pagination="false" >
|
:pagination="false"
|
||||||
|
@change="handleTableChange"
|
||||||
|
@handle-search-filter="handleTableChange" >
|
||||||
|
|
||||||
<template v-if="routerlink" :slot="routerlink.name" slot-scope="text, item">
|
<template v-for="(column, index) in Object.keys(routerlinks({}))" :slot="column" slot-scope="text, item" >
|
||||||
<router-link :to="{ path: routerlink.prefix + item.id }" v-if="routerlink.prefix">{{ text }}</router-link>
|
<span :key="index">
|
||||||
<span v-else>{{ text }}</span>
|
<router-link :set="routerlink = routerlinks(item)" :to="{ path: routerlink[column] }" >{{ text }}</router-link>
|
||||||
|
</span>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template slot="state" slot-scope="text">
|
<template slot="state" slot-scope="text">
|
||||||
<status :text="text ? text : ''" />{{ text }}
|
<status :text="text ? text : ''" />{{ text }}
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template slot="status" slot-scope="text">
|
||||||
|
<status :text="text ? text : ''" />{{ text }}
|
||||||
|
</template>
|
||||||
|
|
||||||
</a-table>
|
</a-table>
|
||||||
|
|
||||||
|
<div style="display: block; text-align: right; margin-top: 10px;">
|
||||||
|
<a-pagination
|
||||||
|
size="small"
|
||||||
|
:current="options.page"
|
||||||
|
:pageSize="options.pageSize"
|
||||||
|
:total="total"
|
||||||
|
:showTotal="total => `Total ${total} items`"
|
||||||
|
:pageSizeOptions="['10', '20', '40']"
|
||||||
|
@change="handleTableChange"
|
||||||
|
@showSizeChange="handlePageSizeChange"
|
||||||
|
showSizeChanger />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@ -45,13 +76,17 @@ export default {
|
|||||||
Status
|
Status
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
resource: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {}
|
||||||
|
},
|
||||||
apiName: {
|
apiName: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
routerlink: {
|
routerlinks: {
|
||||||
type: Object,
|
type: Function,
|
||||||
default: () => {}
|
default: () => { return {} }
|
||||||
},
|
},
|
||||||
params: {
|
params: {
|
||||||
type: Object,
|
type: Object,
|
||||||
@ -60,12 +95,35 @@ export default {
|
|||||||
columns: {
|
columns: {
|
||||||
type: Array,
|
type: Array,
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
showSearch: {
|
||||||
|
type: Boolean,
|
||||||
|
default: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
loading: false,
|
loading: false,
|
||||||
items: []
|
items: [],
|
||||||
|
total: 0,
|
||||||
|
filter: '',
|
||||||
|
options: {
|
||||||
|
page: 1,
|
||||||
|
pageSize: 10,
|
||||||
|
keyword: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
resource (newItem, oldItem) {
|
||||||
|
if (newItem !== oldItem) {
|
||||||
|
this.fetchData()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'$i18n.locale' (to, from) {
|
||||||
|
if (to !== from) {
|
||||||
|
this.fetchData()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
@ -74,11 +132,11 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
fetchData () {
|
fetchData () {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
var params = this.params
|
var params = { ...this.params, ...this.options }
|
||||||
params.listall = true
|
params.listall = true
|
||||||
params.response = 'json'
|
params.response = 'json'
|
||||||
params.details = 'min'
|
params.details = 'min'
|
||||||
api(this.apiName, this.params).then(json => {
|
api(this.apiName, params).then(json => {
|
||||||
var responseName
|
var responseName
|
||||||
var objectName
|
var objectName
|
||||||
for (const key in json) {
|
for (const key in json) {
|
||||||
@ -89,6 +147,7 @@ export default {
|
|||||||
}
|
}
|
||||||
for (const key in json[responseName]) {
|
for (const key in json[responseName]) {
|
||||||
if (key === 'count') {
|
if (key === 'count') {
|
||||||
|
this.total = json[responseName][key]
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
objectName = key
|
objectName = key
|
||||||
@ -112,6 +171,23 @@ export default {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
return columns
|
return columns
|
||||||
|
},
|
||||||
|
handleSearch (value) {
|
||||||
|
this.filter = value
|
||||||
|
this.options.page = 1
|
||||||
|
this.options.pageSize = 10
|
||||||
|
this.options.keyword = this.filter
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
handleTableChange (page, pagesize) {
|
||||||
|
this.options.page = page
|
||||||
|
this.options.pageSize = pagesize
|
||||||
|
this.fetchData()
|
||||||
|
},
|
||||||
|
handlePageSizeChange (page, pagesize) {
|
||||||
|
this.options.page = 1
|
||||||
|
this.options.pageSize = pagesize
|
||||||
|
this.fetchData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,16 +118,19 @@
|
|||||||
<a-tab-pane :tab="$t('label.vm.snapshots')" key="vmsnapshots" v-if="'listVMSnapshot' in $store.getters.apis">
|
<a-tab-pane :tab="$t('label.vm.snapshots')" key="vmsnapshots" v-if="'listVMSnapshot' in $store.getters.apis">
|
||||||
<ListResourceTable
|
<ListResourceTable
|
||||||
apiName="listVMSnapshot"
|
apiName="listVMSnapshot"
|
||||||
|
:resource="resource"
|
||||||
:params="{virtualmachineid: this.resource.id}"
|
:params="{virtualmachineid: this.resource.id}"
|
||||||
:columns="['name', 'state', 'type', 'created']"
|
:columns="['displayname', 'state', 'type', 'created']"
|
||||||
:routerlink="{name: 'name', prefix: '/vmsnapshot/'}"/>
|
:routerlinks="(record) => { return { displayname: '/vmsnapshot/' + record.id } }"/>
|
||||||
</a-tab-pane>
|
</a-tab-pane>
|
||||||
<a-tab-pane :tab="$t('label.backup')" key="backups" v-if="'listBackups' in $store.getters.apis">
|
<a-tab-pane :tab="$t('label.backup')" key="backups" v-if="'listBackups' in $store.getters.apis">
|
||||||
<ListResourceTable
|
<ListResourceTable
|
||||||
apiName="listBackups"
|
apiName="listBackups"
|
||||||
|
:resource="resource"
|
||||||
:params="{virtualmachineid: this.resource.id}"
|
:params="{virtualmachineid: this.resource.id}"
|
||||||
:columns="['id', 'state', 'type', 'created']"
|
:columns="['id', 'status', 'type', 'created']"
|
||||||
:routerlink="{name: 'id', prefix: '/backup/'}"/>
|
:routerlinks="(record) => { return { id: '/backup/' + record.id } }"
|
||||||
|
:showSearch="false"/>
|
||||||
</a-tab-pane>
|
</a-tab-pane>
|
||||||
<a-tab-pane :tab="$t('label.settings')" key="settings">
|
<a-tab-pane :tab="$t('label.settings')" key="settings">
|
||||||
<DetailSettings :resource="resource" :loading="loading" />
|
<DetailSettings :resource="resource" :loading="loading" />
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user