|
| 1 | +<template> |
| 2 | + <div class="proxmox-list"> |
| 3 | + <div class="proxmox-title" v-if="title"> |
| 4 | + <a v-if="titleAsLink" class="proxmox-link" :href="clusterUrl" target="_blank"> |
| 5 | + {{ title }} |
| 6 | + </a> |
| 7 | + <span v-if="!titleAsLink">{{ title }}</span> |
| 8 | + </div> |
| 9 | + <div v-for="(item, key) in data" :key="key" class="proxmox-row"> |
| 10 | + <div v-if="item.node" class="proxmox-cell">{{ item.node }}</div> |
| 11 | + <div v-if="item.name" class="proxmox-cell">{{ item.name }}</div> |
| 12 | + <div class="proxmox-cell proxmox-status"><span :class="item.status"></span></div> |
| 13 | + </div> |
| 14 | + <div class="proxmox-footer" v-if="footer"> |
| 15 | + <a v-if="footerAsLink" class="proxmox-link" :href="clusterUrl" target="_blank"> |
| 16 | + {{ footer }} |
| 17 | + </a> |
| 18 | + <span v-if="!footerAsLink">{{ title }}</span> |
| 19 | + </div> |
| 20 | + </div> |
| 21 | +</template> |
| 22 | + |
| 23 | +<script> |
| 24 | +import WidgetMixin from '@/mixins/WidgetMixin'; |
| 25 | +
|
| 26 | +export default { |
| 27 | + mixins: [WidgetMixin], |
| 28 | + components: {}, |
| 29 | + data() { |
| 30 | + return { |
| 31 | + data: [], |
| 32 | + }; |
| 33 | + }, |
| 34 | + computed: { |
| 35 | + clusterUrl() { |
| 36 | + if (!this.options.cluster_url) this.error('The cluster URL is required.'); |
| 37 | + return this.options.cluster_url || ''; |
| 38 | + }, |
| 39 | + userName() { |
| 40 | + if (!this.options.user_name) this.error('The user name is required.'); |
| 41 | + return this.options.user_name || ''; |
| 42 | + }, |
| 43 | + tokenName() { |
| 44 | + if (!this.options.token_name) this.error('The token name is required.'); |
| 45 | + return this.options.token_name || ''; |
| 46 | + }, |
| 47 | + tokenUuid() { |
| 48 | + if (!this.options.token_uuid) this.error('The token uuid is required.'); |
| 49 | + return this.options.token_uuid || ''; |
| 50 | + }, |
| 51 | + node() { |
| 52 | + return this.options.node || ''; |
| 53 | + }, |
| 54 | + nodeData() { |
| 55 | + return this.options.node_data || false; |
| 56 | + }, |
| 57 | + hideTemplates() { |
| 58 | + return this.options.hide_templates || false; |
| 59 | + }, |
| 60 | + title() { |
| 61 | + return this.options.title || ''; |
| 62 | + }, |
| 63 | + titleAsLink() { |
| 64 | + return this.options.title_as_link || false; |
| 65 | + }, |
| 66 | + footer() { |
| 67 | + return this.options.footer || ''; |
| 68 | + }, |
| 69 | + footerAsLink() { |
| 70 | + return this.options.footer_as_link || false; |
| 71 | + }, |
| 72 | + endpoint() { |
| 73 | + if (!this.node) { |
| 74 | + return `${this.clusterUrl}/api2/json/nodes`; |
| 75 | + } |
| 76 | + if (this.nodeData) { |
| 77 | + return `${this.clusterUrl}/api2/json/nodes/${this.node}/${this.nodeData}`; |
| 78 | + } |
| 79 | + return ''; |
| 80 | + }, |
| 81 | + authHeaders() { |
| 82 | + if (this.userName && this.tokenName && this.tokenUuid) { |
| 83 | + return { Authorization: `PVEAPIToken=${this.userName}!${this.tokenName}=${this.tokenUuid}` }; |
| 84 | + } |
| 85 | + return false; |
| 86 | + }, |
| 87 | + }, |
| 88 | + methods: { |
| 89 | + fetchData() { |
| 90 | + const auth = this.authHeaders; |
| 91 | + if (auth) { |
| 92 | + this.startLoading(); |
| 93 | + this.makeRequest(this.endpoint, auth).then(this.processData); |
| 94 | + } |
| 95 | + }, |
| 96 | + processData(data) { |
| 97 | + this.data = data.data.sort((a, b) => a.vmid > b.vmid); |
| 98 | + if (this.hideTemplates) { |
| 99 | + this.data = this.data.filter(item => item.template !== 1); |
| 100 | + } |
| 101 | + this.finishLoading(); |
| 102 | + }, |
| 103 | + }, |
| 104 | +}; |
| 105 | +
|
| 106 | +</script> |
| 107 | + |
| 108 | +<style scoped lang="scss"> |
| 109 | +
|
| 110 | +.proxmox-list { |
| 111 | + .proxmox-title, .proxmox-footer { |
| 112 | + outline: 2px solid transparent; |
| 113 | + border: 1px solid var(--outline-color); |
| 114 | + border-radius: var(--curve-factor); |
| 115 | + box-shadow: var(--item-shadow); |
| 116 | + color: var(--item-text-color); |
| 117 | + margin: .5rem; |
| 118 | + padding: 0.3rem; |
| 119 | + background: var(--item-background); |
| 120 | + text-align: center; |
| 121 | +
|
| 122 | + a { |
| 123 | + text-decoration: none; |
| 124 | + color: var(--item-text-color); |
| 125 | + } |
| 126 | + } |
| 127 | + .proxmox-row { |
| 128 | + display: flex; |
| 129 | + align-items: center; |
| 130 | + justify-content: space-between; |
| 131 | + color: var(--widget-text-color); |
| 132 | + font-size: 1.1rem; |
| 133 | + .proxmox-cell { |
| 134 | + display: inline-block; |
| 135 | + } |
| 136 | + .proxmox-status{ |
| 137 | + .online, .running { |
| 138 | + width: 0.8rem; |
| 139 | + height: 0.8rem; |
| 140 | + border-radius: 50%; |
| 141 | + background-color: var(--success); |
| 142 | + display: block; |
| 143 | + } |
| 144 | + } |
| 145 | + .proxmox-link { |
| 146 | + display: inline-block; |
| 147 | + padding: 0.2rem; |
| 148 | + margin: 0.1rem 0.2rem; |
| 149 | +
|
| 150 | + } |
| 151 | + &:not(:last-child) { |
| 152 | + border-bottom: 1px dashed var(--widget-text-color); |
| 153 | + } |
| 154 | + } |
| 155 | +} |
| 156 | +</style> |
0 commit comments