|
| 1 | +<template> |
| 2 | + <a-list size="large" class="list" :loading="loading"> |
| 3 | + <a-list-item :key="index" v-for="(item, index) in items" class="item"> |
| 4 | + <a-list-item-meta> |
| 5 | + <span slot="title" style="word-break: break-all"><strong>{{ item.name }}</strong></span> |
| 6 | + <span slot="description" style="word-break: break-all">{{ item.description }}</span> |
| 7 | + </a-list-item-meta> |
| 8 | + |
| 9 | + <div class="item__content"> |
| 10 | + <a-input |
| 11 | + v-if="editableValueKey === index" |
| 12 | + class="editable-value value" |
| 13 | + :defaultValue="item.value" |
| 14 | + v-model="editableValue" |
| 15 | + @keydown.esc="editableValueKey = null" |
| 16 | + @pressEnter="updateData(item)"> |
| 17 | + </a-input> |
| 18 | + <span v-else class="value"> |
| 19 | + {{ item.value }} |
| 20 | + </span> |
| 21 | + </div> |
| 22 | + |
| 23 | + <div slot="actions" class="action"> |
| 24 | + <a-button |
| 25 | + shape="circle" |
| 26 | + v-if="editableValueKey !== index" |
| 27 | + icon="edit" |
| 28 | + @click="setEditableSetting(item, index)" /> |
| 29 | + <a-button |
| 30 | + shape="circle" |
| 31 | + size="default" |
| 32 | + @click="editableValueKey = null" |
| 33 | + v-if="editableValueKey === index" > |
| 34 | + <a-icon type="close-circle" theme="twoTone" twoToneColor="#f5222d" /> |
| 35 | + </a-button> |
| 36 | + <a-button |
| 37 | + shape="circle" |
| 38 | + @click="updateData(item)" |
| 39 | + v-if="editableValueKey === index" > |
| 40 | + <a-icon type="check-circle" theme="twoTone" twoToneColor="#52c41a" /> |
| 41 | + </a-button> |
| 42 | + </div> |
| 43 | + </a-list-item> |
| 44 | + </a-list> |
| 45 | +</template> |
| 46 | + |
| 47 | +<script> |
| 48 | +import { api } from '@/api' |
| 49 | +
|
| 50 | +export default { |
| 51 | + name: 'SettingsTab', |
| 52 | + props: { |
| 53 | + resource: { |
| 54 | + type: Object, |
| 55 | + required: true |
| 56 | + }, |
| 57 | + loading: { |
| 58 | + type: Boolean, |
| 59 | + required: true |
| 60 | + } |
| 61 | + }, |
| 62 | + data () { |
| 63 | + return { |
| 64 | + items: [], |
| 65 | + scopeKey: '', |
| 66 | + editableValueKey: null, |
| 67 | + editableValue: '' |
| 68 | + } |
| 69 | + }, |
| 70 | + beforeMount () { |
| 71 | + switch (this.$route.meta.name) { |
| 72 | + case 'account': |
| 73 | + this.scopeKey = 'accountid' |
| 74 | + break |
| 75 | + case 'domain': |
| 76 | + this.scopeKey = 'domainid' |
| 77 | + break |
| 78 | + case 'zone': |
| 79 | + this.scopeKey = 'zoneid' |
| 80 | + break |
| 81 | + case 'cluster': |
| 82 | + this.scopeKey = 'clusterid' |
| 83 | + break |
| 84 | + case 'storagepool': |
| 85 | + this.scopeKey = 'storageid' |
| 86 | + break |
| 87 | + case 'imagestore': |
| 88 | + this.scopeKey = 'imagestoreuuid' |
| 89 | + break |
| 90 | + default: |
| 91 | + this.scopeKey = '' |
| 92 | + } |
| 93 | + }, |
| 94 | + mounted () { |
| 95 | + this.fetchData() |
| 96 | + }, |
| 97 | + watch: { |
| 98 | + resource: newItem => { |
| 99 | + if (!newItem.id) return |
| 100 | + this.fetchData() |
| 101 | + } |
| 102 | + }, |
| 103 | + methods: { |
| 104 | + fetchData (callback) { |
| 105 | + this.loading = true |
| 106 | + api('listConfigurations', { |
| 107 | + [this.scopeKey]: this.resource.id, |
| 108 | + listAll: true |
| 109 | + }).then(response => { |
| 110 | + this.items = response.listconfigurationsresponse.configuration |
| 111 | + }).catch(error => { |
| 112 | + console.error(error) |
| 113 | + this.$message.error('There was an error loading these settings.') |
| 114 | + }).finally(() => { |
| 115 | + this.loading = false |
| 116 | + if (!callback) return |
| 117 | + callback() |
| 118 | + }) |
| 119 | + }, |
| 120 | + updateData (item) { |
| 121 | + this.loading = true |
| 122 | + api('updateConfiguration', { |
| 123 | + [this.scopeKey]: this.resource.id, |
| 124 | + name: item.name, |
| 125 | + value: this.editableValue |
| 126 | + }).then(() => { |
| 127 | + this.$message.success('Setting ' + item.name + ' updated to ' + this.editableValue) |
| 128 | + }).catch(error => { |
| 129 | + console.error(error) |
| 130 | + this.$message.error('There was an error saving this setting.') |
| 131 | + this.$notification.error({ |
| 132 | + message: 'Error', |
| 133 | + description: 'There was an error saving this setting. Please try again later.' |
| 134 | + }) |
| 135 | + }).finally(() => { |
| 136 | + this.loading = false |
| 137 | + this.fetchData(() => { |
| 138 | + this.editableValueKey = null |
| 139 | + }) |
| 140 | + }) |
| 141 | + }, |
| 142 | + setEditableSetting (item, index) { |
| 143 | + this.editableValueKey = index |
| 144 | + this.editableValue = item.value |
| 145 | + } |
| 146 | + } |
| 147 | +} |
| 148 | +</script> |
| 149 | + |
| 150 | +<style scoped lang="scss"> |
| 151 | + .list { |
| 152 | + } |
| 153 | + .editable-value { |
| 154 | +
|
| 155 | + @media (min-width: 760px) { |
| 156 | + text-align: right; |
| 157 | + margin-left: 40px; |
| 158 | + margin-right: -40px; |
| 159 | + } |
| 160 | +
|
| 161 | + } |
| 162 | + .item { |
| 163 | + display: flex; |
| 164 | + flex-direction: column; |
| 165 | + align-items: stretch; |
| 166 | +
|
| 167 | + @media (min-width: 760px) { |
| 168 | + flex-direction: row; |
| 169 | + } |
| 170 | +
|
| 171 | + &__content { |
| 172 | + width: 100%; |
| 173 | + display: flex; |
| 174 | + word-break: break-all; |
| 175 | +
|
| 176 | + @media (min-width: 760px) { |
| 177 | + width: auto; |
| 178 | + } |
| 179 | +
|
| 180 | + } |
| 181 | +
|
| 182 | + } |
| 183 | + .action { |
| 184 | + margin-top: 20px; |
| 185 | + margin-left: -12px; |
| 186 | +
|
| 187 | + @media (min-width: 480px) { |
| 188 | + margin-left: -24px; |
| 189 | + } |
| 190 | +
|
| 191 | + @media (min-width: 760px) { |
| 192 | + margin-top: 0; |
| 193 | + margin-left: 0; |
| 194 | + } |
| 195 | +
|
| 196 | + } |
| 197 | +
|
| 198 | + .value { |
| 199 | + margin-top: 20px; |
| 200 | +
|
| 201 | + @media (min-width: 760px) { |
| 202 | + margin-top: 0; |
| 203 | + } |
| 204 | +
|
| 205 | + } |
| 206 | +
|
| 207 | +</style> |
0 commit comments