1616// under the License.
1717
1818<template >
19- <a-spin :spinning =" formLoading" >
20- <a-list
21- size =" small"
22- :dataSource =" resourceCountData"
23- >
24- <a-list-item slot =" renderItem" slot-scope =" item" class =" list-item" >
25- <div class =" list-item__container" >
26- <strong >
27- {{ $t('label.' + String(item).toLowerCase() + '.count') }}
28- </strong >
29- <br />
30- <br />
31- <div class =" list-item__vals" >
32- <div class =" list-item__data" >
33- Current Usage: {{ resourceData[item + 'total'] }} / {{ resourceData[item + 'limit'] }}
34- </div >
35- <div class =" list-item__data" >
36- Available: {{ resourceData[item + 'available'] }}
37- </div >
38- <a-progress
39- status =" normal"
40- :percent =" parseFloat(getPercentUsed(resourceData[item + 'total'], resourceData[item + 'limit']))"
41- :format =" p => parseFloat(getPercentUsed(resourceData[item + 'total'], resourceData[item + 'limit'])).toFixed(2) + '%'" />
19+ <a-list
20+ size =" small"
21+ :loading =" loading"
22+ :dataSource =" usageList" >
23+ <a-list-item slot =" renderItem" slot-scope =" item" class =" list-item" v-if =" !($route.meta.name === 'project' && item === 'project')" >
24+ <div class =" list-item__container" >
25+ <strong >
26+ {{ $t('label.' + item + 'limit') }}
27+ </strong >
28+ ({{ resource[item + 'available'] === '-1' ? 'Unlimited' : resource[item + 'available'] }} {{ $t('label.available') }})
29+ <div class =" list-item__vals" >
30+ <div class =" list-item__data" >
31+ {{ $t('label.used') }} / {{ $t('label.limit') }} : {{ resource[item + 'total'] }} / {{ resource[item + 'limit'] === '-1' ? 'Unlimited' : resource[item + 'limit'] }}
4232 </div >
33+ <a-progress
34+ status =" normal"
35+ :percent =" parseFloat(getPercentUsed(resource[item + 'total'], resource[item + 'limit']))"
36+ :format =" p => resource[item + 'limit'] !== '-1' && resource[item + 'limit'] !== 'Unlimited' ? p.toFixed(2) + '%' : ''" />
4337 </div >
44- </a-list-item >
45- </a-list >
46- </a-spin >
38+ </div >
39+ </a-list-item >
40+ </a-list >
4741</template >
4842
4943<script >
50- import { api } from ' @/api'
51-
5244export default {
53- name: ' ResourceCountTab ' ,
45+ name: ' ResourceCountUsageTab ' ,
5446 props: {
5547 resource: {
5648 type: Object ,
@@ -63,106 +55,21 @@ export default {
6355 },
6456 data () {
6557 return {
66- formLoading: false ,
67- resourceData: {
68- type: Object ,
69- required: false
70- },
71- resourceCountData: [' vm' , ' cpu' , ' memory' , ' primarystorage' , ' ip' ,
72- ' volume' , ' secondarystorage' , ' snapshot' ,
73- ' template' , ' network' , ' vpc' , ' project' ]
58+ usageList: [
59+ ' vm' , ' cpu' , ' memory' , ' primarystorage' , ' volume' , ' ip' , ' network' ,
60+ ' vpc' , ' secondarystorage' , ' snapshot' , ' template' , ' project'
61+ ]
7462 }
7563 },
76- mounted () {
77- this .fetchData ()
78- },
7964 watch: {
8065 resource (newData , oldData ) {
8166 if (! newData || ! newData .id ) {
8267 return
8368 }
8469 this .resource = newData
85- this .fetchData ()
8670 }
8771 },
8872 methods: {
89- getResourceData () {
90- const params = {}
91- if (this .$route .meta .name === ' account' ) {
92- params .account = this .resource .name
93- params .domainid = this .resource .domainid
94- this .listAccounts (params)
95- } else if (this .$route .meta .name === ' domain' ) {
96- params .id = this .resource .id
97- this .listDomains (params)
98- } else { // project
99- params .id = this .resource .id
100- params .listall = true
101- this .listProjects (params)
102- }
103- },
104- fetchData () {
105- try {
106- this .formLoading = true
107- this .getResourceData ()
108- this .formLoading = false
109- } catch (e) {
110- this .$notification .error ({
111- message: ' Request Failed' ,
112- description: e
113- })
114- this .formLoading = false
115- }
116- },
117- listDomains (params ) {
118- api (' listDomains' , params).then (json => {
119- const domains = json .listdomainsresponse .domain || []
120- this .resourceData = domains[0 ] || {}
121- }).catch (error => {
122- this .handleErrors (error)
123- }).finally (f => {
124- this .loading = false
125- })
126- },
127- listAccounts (params ) {
128- api (' listAccounts' , params).then (json => {
129- const accounts = json .listaccountsresponse .account || []
130- this .resourceData = accounts[0 ] || {}
131- }).catch (error => {
132- this .handleErrors (error)
133- }).finally (f => {
134- this .loading = false
135- })
136- },
137- listProjects (params ) {
138- api (' listProjects' , params).then (json => {
139- const projects = json .listprojectsresponse .project || []
140- this .resourceData = projects[0 ] || {}
141- }).catch (error => {
142- this .handleErrors (error)
143- }).finally (f => {
144- this .loading = false
145- })
146- },
147- handleErrors (error ) {
148- this .$notification .error ({
149- message: ' Request Failed' ,
150- description: error .response .headers [' x-description' ],
151- duration: 0
152- })
153-
154- if ([401 , 405 ].includes (error .response .status )) {
155- this .$router .push ({ path: ' /exception/403' })
156- }
157-
158- if ([430 , 431 , 432 ].includes (error .response .status )) {
159- this .$router .push ({ path: ' /exception/404' })
160- }
161-
162- if ([530 , 531 , 532 , 533 , 534 , 535 , 536 , 537 ].includes (error .response .status )) {
163- this .$router .push ({ path: ' /exception/500' })
164- }
165- },
16673 getPercentUsed (total , limit ) {
16774 return (limit === ' Unlimited' ) ? 0 : (total / limit) * 100
16875 }
@@ -192,6 +99,7 @@ export default {
19299 }
193100
194101 & __vals {
102+ margin-top : 10px ;
195103 @media (min-width : 760px ) {
196104 display : flex ;
197105 }
0 commit comments