Skip to content

Commit 8d18c1e

Browse files
lucas-a-martinsLucas Martins
andauthored
Change resource settings tab to be type based (#10596)
Co-authored-by: Lucas Martins <[email protected]>
1 parent 8af021c commit 8d18c1e

File tree

3 files changed

+55
-120
lines changed

3 files changed

+55
-120
lines changed

ui/src/components/view/SettingsTab.vue

Lines changed: 26 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -17,71 +17,27 @@
1717

1818
<template>
1919
<div>
20-
<a-input-search
21-
style="width: 25vw;float: right;margin-bottom: 10px; z-index: 8;"
22-
:placeholder="$t('label.search')"
23-
v-model:value="filter"
24-
@search="handleSearch" />
25-
26-
<a-list size="large" class="list" :loading="loading || tabLoading">
27-
<a-list-item :key="index" v-for="(item, index) in items" class="item">
28-
<a-list-item-meta>
29-
<template #title style="word-break: break-all">{{ item.name }}</template>
30-
<template #description style="word-break: break-all">{{ item.description }}</template>
31-
</a-list-item-meta>
32-
33-
<div class="item__content">
34-
<a-input
35-
v-focus="editableValueKey === index"
36-
v-if="editableValueKey === index"
37-
class="editable-value value"
38-
:defaultValue="item.value"
39-
v-model:value="editableValue"
40-
@keydown.esc="editableValueKey = null"
41-
@pressEnter="updateData(item)">
42-
</a-input>
43-
<span v-else class="value">
44-
{{ item.value }}
45-
</span>
46-
</div>
47-
48-
<template #actions class="action">
49-
<tooltip-button
50-
:tooltip="$t('label.edit')"
51-
:disabled="!('updateConfiguration' in $store.getters.apis)"
52-
v-if="editableValueKey !== index"
53-
icon="edit-outlined"
54-
@onClick="setEditableSetting(item, index)" />
55-
<tooltip-button
56-
:tooltip="$t('label.cancel')"
57-
@onClick="editableValueKey = null"
58-
v-if="editableValueKey === index"
59-
iconType="CloseCircleTwoTone"
60-
iconTwoToneColor="#f5222d" />
61-
<tooltip-button
62-
:tooltip="$t('label.ok')"
63-
@onClick="updateData(item)"
64-
v-if="editableValueKey === index"
65-
iconType="CheckCircleTwoTone"
66-
iconTwoToneColor="#52c41a" />
67-
<tooltip-button
68-
:tooltip="$t('label.reset.config.value')"
69-
@onClick="resetConfig(item)"
70-
v-if="editableValueKey !== index"
71-
icon="reload-outlined"
72-
:disabled="!('updateConfiguration' in $store.getters.apis)" />
73-
</template>
74-
</a-list-item>
75-
</a-list>
20+
<a-col :span="24">
21+
<a-input-search
22+
style="width: 25vw;float: right;margin-bottom: 10px; z-index: 8;"
23+
:placeholder="$t('label.search')"
24+
v-model:value="filter"
25+
@search="handleSearch" />
26+
<ConfigurationTable
27+
:columns="columns"
28+
:config="items" />
29+
</a-col>
7630
</div>
7731
</template>
7832

7933
<script>
8034
import { api } from '@/api'
8135
import TooltipButton from '@/components/widgets/TooltipButton'
36+
import ConfigurationTable from '@/views/setting/ConfigurationTable.vue'
8237
8338
export default {
8439
components: {
40+
ConfigurationTable,
8541
TooltipButton
8642
},
8743
name: 'SettingsTab',
@@ -112,7 +68,20 @@ export default {
11268
scope: 'zone',
11369
warning: this.$t('message.warn.zone.mtu.update')
11470
}
115-
}
71+
},
72+
columns: [
73+
{
74+
title: 'name',
75+
dataIndex: 'name',
76+
key: 'name'
77+
},
78+
{
79+
title: 'value',
80+
dataIndex: 'value',
81+
key: 'value',
82+
width: '29%'
83+
}
84+
]
11685
}
11786
},
11887
created () {
@@ -167,70 +136,9 @@ export default {
167136
callback()
168137
})
169138
},
170-
updateData (item) {
171-
this.tabLoading = true
172-
api('updateConfiguration', {
173-
[this.scopeKey]: this.resource.id,
174-
name: item.name,
175-
value: this.editableValue
176-
}).then(() => {
177-
var message = `${this.$t('label.setting')} ${item.name} ${this.$t('label.update.to')} ${this.editableValue}`
178-
this.handleSuccessMessage(item, this.$route.meta.name, message)
179-
}).catch(error => {
180-
console.error(error)
181-
this.$message.error(this.$t('message.error.save.setting'))
182-
this.$notification.error({
183-
message: this.$t('label.error'),
184-
description: this.$t('message.error.try.save.setting')
185-
})
186-
}).finally(() => {
187-
this.tabLoading = false
188-
this.fetchData(() => {
189-
this.editableValueKey = null
190-
})
191-
})
192-
},
193-
setEditableSetting (item, index) {
194-
this.editableValueKey = index
195-
this.editableValue = item.value
196-
},
197139
handleSearch (value) {
198140
this.filter = value
199141
this.fetchData()
200-
},
201-
resetConfig (item) {
202-
this.tabLoading = true
203-
api('resetConfiguration', {
204-
[this.scopeKey]: this.resource.id,
205-
name: item.name
206-
}).then(() => {
207-
var message = `${this.$t('label.setting')} ${item.name} ${this.$t('label.reset.config.value')}`
208-
this.handleSuccessMessage(item, this.$route.meta.name, message)
209-
}).catch(error => {
210-
console.error(error)
211-
this.$message.error(this.$t('message.error.reset.config'))
212-
this.$notification.error({
213-
message: this.$t('label.error'),
214-
description: this.$t('message.error.reset.config')
215-
})
216-
}).finally(() => {
217-
this.tabLoading = false
218-
this.fetchData(() => {
219-
this.editableValueKey = null
220-
})
221-
})
222-
},
223-
handleSuccessMessage (config, scope, message) {
224-
var obj = this.warningMessages[config.name]
225-
if (obj && obj.scope === scope) {
226-
var content = obj.warning
227-
if (config.isdynamic) {
228-
content = `this.$t('message.setting.update.delay').\n ${content}`
229-
}
230-
this.$warning({ title: message, content: content })
231-
} else {
232-
this.$messageConfigSuccess(message, config)
233-
}
234142
}
235143
}
236144
}

ui/src/views/setting/ConfigurationTable.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
</template>
3838
</a-table>
3939
<a-pagination
40+
v-if="this.$route.meta.name === 'globalsetting'"
4041
class="config-row-element"
4142
style="margin-top: 10px"
4243
size="small"

ui/src/views/setting/ConfigurationValue.vue

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,35 @@ export default {
222222
data () {
223223
return {
224224
valueLoading: this.loading,
225+
scopeKey: '',
225226
actualValue: null,
226227
editableValue: null,
227228
editableValueKey: null
228229
}
229230
},
230231
created () {
232+
switch (this.$route.meta.name) {
233+
case 'account':
234+
this.scopeKey = 'accountid'
235+
break
236+
case 'domain':
237+
this.scopeKey = 'domainid'
238+
break
239+
case 'zone':
240+
this.scopeKey = 'zoneid'
241+
break
242+
case 'cluster':
243+
this.scopeKey = 'clusterid'
244+
break
245+
case 'storagepool':
246+
this.scopeKey = 'storageid'
247+
break
248+
case 'imagestore':
249+
this.scopeKey = 'imagestoreuuid'
250+
break
251+
default:
252+
this.scopeKey = ''
253+
}
231254
this.setConfigData()
232255
},
233256
watch: {
@@ -253,6 +276,7 @@ export default {
253276
newValue = newValue.join(' ')
254277
}
255278
const params = {
279+
[this.scopeKey]: this.$route.params?.id,
256280
name: configrecord.name,
257281
value: newValue
258282
}
@@ -287,9 +311,11 @@ export default {
287311
resetConfigurationValue (configrecord) {
288312
this.valueLoading = true
289313
this.editableValueKey = null
290-
api('resetConfiguration', {
314+
const params = {
315+
[this.scopeKey]: this.$route.params?.id,
291316
name: configrecord.name
292-
}).then(json => {
317+
}
318+
api('resetConfiguration', params).then(json => {
293319
this.editableValue = this.getEditableValue(json.resetconfigurationresponse.configuration)
294320
this.actualValue = this.editableValue
295321
var newValue = this.editableValue

0 commit comments

Comments
 (0)