|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +<template> |
| 19 | + <a-list-item v-if="['host', 'computeoffering'].includes($route.meta.name) && filteredExternalDetails"> |
| 20 | + <div> |
| 21 | + <strong>{{ ['computeoffering'].includes($route.meta.name) ? $t('label.externaldetails') : $t('label.configuration.details') }}</strong> |
| 22 | + <div> |
| 23 | + <object-list-table :data-map="filteredExternalDetails" /> |
| 24 | + </div> |
| 25 | + </div> |
| 26 | + </a-list-item> |
| 27 | + <a-list-item v-else-if="['cluster'].includes($route.meta.name)"> |
| 28 | + <div> |
| 29 | + <strong>{{ $t('label.configuration.details') }}</strong> |
| 30 | + <div> |
| 31 | + <object-list-table :data-map="extensionResourceDetails" /> |
| 32 | + </div> |
| 33 | + </div> |
| 34 | + </a-list-item> |
| 35 | +</template> |
| 36 | + |
| 37 | +<script> |
| 38 | +import { getAPI } from '@/api' |
| 39 | +import ObjectListTable from '@/components/view/ObjectListTable' |
| 40 | +
|
| 41 | +export default { |
| 42 | + name: 'ExternalConfigurationDetails', |
| 43 | + components: { |
| 44 | + ObjectListTable |
| 45 | + }, |
| 46 | + props: { |
| 47 | + resource: { |
| 48 | + type: Object, |
| 49 | + required: true |
| 50 | + } |
| 51 | + }, |
| 52 | + data () { |
| 53 | + return { |
| 54 | + extension: {}, |
| 55 | + loading: false |
| 56 | + } |
| 57 | + }, |
| 58 | + created () { |
| 59 | + this.fetchData() |
| 60 | + }, |
| 61 | + watch: { |
| 62 | + resource: { |
| 63 | + deep: true, |
| 64 | + handler (newItem, oldItem) { |
| 65 | + if (newItem && newItem.id !== oldItem.id) { |
| 66 | + this.fetchData() |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + }, |
| 71 | + computed: { |
| 72 | + filteredExternalDetails () { |
| 73 | + const detailsKeys = { |
| 74 | + host: 'details', |
| 75 | + computeoffering: 'serviceofferingdetails' |
| 76 | + } |
| 77 | + const detailsKey = detailsKeys[this.$route.meta.name] |
| 78 | + if (!detailsKey || !this.resource) { |
| 79 | + return null |
| 80 | + } |
| 81 | + const details = this.resource[detailsKey] |
| 82 | + if (!details || typeof details !== 'object') { |
| 83 | + return null |
| 84 | + } |
| 85 | + const prefix = 'External:' |
| 86 | + const result = {} |
| 87 | + for (const key in details) { |
| 88 | + if (key.startsWith(prefix)) { |
| 89 | + result[key.substring(prefix.length)] = details[key] |
| 90 | + } |
| 91 | + } |
| 92 | + return Object.keys(result).length > 0 ? result : null |
| 93 | + }, |
| 94 | + extensionResourceDetails () { |
| 95 | + if (!this.resource?.id || !this.extension?.resources) { |
| 96 | + return null |
| 97 | + } |
| 98 | + const resource = this.extension.resources.find(r => r.id === this.resource.id) |
| 99 | + if (!resource || !resource.details || typeof resource.details !== 'object') { |
| 100 | + return null |
| 101 | + } |
| 102 | + return resource.details |
| 103 | + } |
| 104 | + }, |
| 105 | + methods: { |
| 106 | + fetchData () { |
| 107 | + if (!['cluster'].includes(this.$route.meta.name)) { |
| 108 | + return |
| 109 | + } |
| 110 | + this.loading = true |
| 111 | + const params = { |
| 112 | + id: this.resource.extensionid, |
| 113 | + details: 'resource' |
| 114 | + } |
| 115 | + getAPI('listExtensions', params).then(json => { |
| 116 | + this.extension = json.listextensionsresponse.extension[0] |
| 117 | + }).catch(error => { |
| 118 | + this.$notifyError(error) |
| 119 | + }).finally(() => { |
| 120 | + this.loading = false |
| 121 | + }) |
| 122 | + } |
| 123 | + } |
| 124 | +} |
| 125 | +</script> |
0 commit comments