From 64a3035db31bb0c45f25d1656d411fd1b294248c Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Mon, 14 Oct 2019 16:11:58 +0530 Subject: [PATCH] views: fix watchers and don't call APIs many times Signed-off-by: Rohit Yadav --- ui/src/views/common/InfoCard.vue | 15 +++++------ ui/src/views/common/ResourceView.vue | 33 ++--------------------- ui/src/views/compute/InstanceHardware.vue | 11 +++----- 3 files changed, 12 insertions(+), 47 deletions(-) diff --git a/ui/src/views/common/InfoCard.vue b/ui/src/views/common/InfoCard.vue index ea66eb9e300..82f791ccbde 100644 --- a/ui/src/views/common/InfoCard.vue +++ b/ui/src/views/common/InfoCard.vue @@ -133,8 +133,8 @@ :percent="Number(parseFloat(100.0 * (resource.memoryallocated) / resource.memorytotal).toFixed(2))" /> -
- {{ (totalStorage / (1024 * 1024 * 1024.0)).toFixed(2) }} GB Storage +
+ {{ (resource.volumes.reduce((total, item) => total += item.size, 0) / (1024 * 1024 * 1024.0)).toFixed(2) }} GB Storage
Read {{ toSize(resource.diskkbsread) }} Write {{ toSize(resource.diskkbswrite) }}
@@ -397,9 +397,11 @@ export default { }, watch: { resource: function (newItem, oldItem) { - console.log('reosurce changed in info-card') - console.log(newItem) this.resource = newItem + if (newItem.id === oldItem.id) { + return + } + this.resourceType = this.$route.meta.resourceType this.annotationType = '' this.showKeys = false @@ -434,11 +436,6 @@ export default { } } }, - computed: { - totalStorage: function () { - return this.resource.totalStorage - } - }, methods: { toSize (kb) { if (!kb) { diff --git a/ui/src/views/common/ResourceView.vue b/ui/src/views/common/ResourceView.vue index 3d17c5c0df8..0fe6e8b6c28 100644 --- a/ui/src/views/common/ResourceView.vue +++ b/ui/src/views/common/ResourceView.vue @@ -2,7 +2,7 @@
- +
@@ -19,7 +19,7 @@ v-for="tab in tabs" :tab="$t(tab.name)" :key="tab.name"> - + @@ -58,38 +58,9 @@ export default { } } }, - data () { - return { - settingsColumns: [ - { - title: this.$t('name'), - dataIndex: 'name', - sorter: true - }, { - title: this.$t('value'), - dataIndex: 'value' - }, { - title: this.$t('action'), - dataIndex: 'actions' - } - ], - settings: [] - } - }, - watch: { - '$route' (to, from) { - console.log(this.resource) - }, - resource: function (newItem, oldItem) { - this.resource = newItem - } - }, methods: { onTabChange (key) { this.activeTab = key - }, - resourceChange (newResource) { - this.resource = newResource } } } diff --git a/ui/src/views/compute/InstanceHardware.vue b/ui/src/views/compute/InstanceHardware.vue index 5da99f30c63..8701795bbcf 100644 --- a/ui/src/views/compute/InstanceHardware.vue +++ b/ui/src/views/compute/InstanceHardware.vue @@ -122,6 +122,9 @@ export default { watch: { resource: function (newItem, oldItem) { this.vm = newItem + if (newItem.id === oldItem.id) { + return + } this.fetchData() } }, @@ -133,13 +136,7 @@ export default { if (this.volumes) { this.volumes.sort((a, b) => { return a.deviceid - b.deviceid }) } - this.totalStorage = 0 - for (var volume of this.volumes) { - this.totalStorage += volume.size - } - this.resource.volumes = this.volumes - this.resource.totalStorage = this.totalStorage - this.$emit('resourceChange', this.resource) + this.$set(this.resource, 'volumes', this.volumes) }) } }