Skip to content

Commit 8623e1e

Browse files
committed
fix: certificate selector can not select #375
1 parent bd0bbe9 commit 8623e1e

File tree

5 files changed

+141
-70
lines changed

5 files changed

+141
-70
lines changed
Lines changed: 119 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,132 @@
11
<script setup lang="ts">
2+
import _ from 'lodash'
3+
import type { Ref } from 'vue'
24
import StdTable from '@/components/StdDesign/StdDataDisplay/StdTable.vue'
35
import type Curd from '@/api/curd'
46
import type { Column } from '@/components/StdDesign/types'
57
68
const props = defineProps<{
7-
selectedKey: string | number
8-
value?: string | number
9-
recordValueIndex: string
9+
label?: string
10+
selectedKey: number | number[] | undefined | null
1011
selectionType: 'radio' | 'checkbox'
12+
recordValueIndex: string // to index the value of the record
1113
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1214
api: Curd<any>
1315
columns: Column[]
1416
disableSearch?: boolean
1517
// eslint-disable-next-line @typescript-eslint/no-explicit-any
16-
getParams: any
18+
getParams?: any
1719
description?: string
20+
errorMessages?: string
21+
itemKey?: string // default: id
22+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
23+
value?: any | any[]
24+
disabled?: boolean
25+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
26+
valueApi?: Curd<any>
1827
}>()
1928
20-
const emit = defineEmits(['update:selectedKey', 'changeSelect'])
29+
const emit = defineEmits(['update:selectedKey'])
30+
31+
const getParams = computed(() => {
32+
return props.getParams
33+
})
2134
2235
const visible = ref(false)
23-
const M_value = ref('')
36+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
37+
const M_values = ref([]) as any
38+
39+
const init = _.debounce(_init, 500, {
40+
leading: true,
41+
trailing: false,
42+
})
2443
2544
onMounted(() => {
2645
init()
2746
})
2847
29-
const selected = ref([])
3048
// eslint-disable-next-line @typescript-eslint/no-explicit-any
31-
const record: any = reactive({})
32-
33-
function init() {
34-
if (props.selectedKey && !props.value && props.selectionType === 'radio') {
35-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
36-
props.api.get(props.selectedKey).then((r: any) => {
37-
Object.assign(record, r)
38-
M_value.value = r[props.recordValueIndex]
39-
})
49+
const records = ref([]) as Ref<any[]>
50+
51+
async function _init() {
52+
// valueApi is used to fetch items that are using itemKey as index value
53+
const api = props.valueApi || props.api
54+
55+
M_values.value = []
56+
57+
if (props.selectionType === 'radio') {
58+
// M_values.value = [props.value] // not init value, we need to fetch them from api
59+
if (!props.value && props.selectedKey) {
60+
api.get(props.selectedKey, props.getParams).then(r => {
61+
M_values.value = [r]
62+
records.value = [r]
63+
})
64+
}
65+
}
66+
else if (typeof props.selectedKey === 'object') {
67+
M_values.value = props.value || []
68+
69+
// not init value, we need to fetch them from api
70+
if (!props.value && (props.selectedKey?.length || 0) > 0) {
71+
api.get_list({
72+
...props.getParams,
73+
id: props.selectedKey,
74+
}).then(r => {
75+
M_values.value = r.data
76+
records.value = r.data
77+
})
78+
}
4079
}
4180
}
4281
4382
function show() {
44-
visible.value = true
45-
}
46-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
47-
function onSelect(_selected: any) {
48-
selected.value = _selected
49-
}
50-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
51-
function onSelectedRecord(r: any) {
52-
Object.assign(record, r)
83+
if (!props.disabled)
84+
visible.value = true
5385
}
5486
55-
function ok() {
56-
visible.value = false
57-
if (props.selectionType === 'radio')
58-
emit('update:selectedKey', selected.value[0])
59-
else
60-
emit('update:selectedKey', selected.value)
87+
const selectedKeyBuffer = ref()
6188
62-
M_value.value = record[props.recordValueIndex]
63-
emit('changeSelect', record)
64-
}
89+
if (props.selectionType === 'radio')
90+
selectedKeyBuffer.value = [props.selectedKey]
91+
else
92+
selectedKeyBuffer.value = props.selectedKey
6593
66-
watch(props, () => {
67-
if (!props?.selectedKey)
68-
M_value.value = ''
69-
else if (props.value)
70-
M_value.value = props.value as string
71-
else
72-
init()
73-
})
74-
75-
const _selectedKey = computed({
94+
const computedSelectedKeys = computed({
7695
get() {
77-
return props.selectedKey
96+
if (props.selectionType === 'radio')
97+
return [selectedKeyBuffer.value]
98+
else
99+
return selectedKeyBuffer.value
78100
},
79101
set(v) {
80-
emit('update:selectedKey', v)
102+
selectedKeyBuffer.value = v
81103
},
82104
})
105+
106+
onMounted(() => {
107+
if (props.selectedKey === undefined || props.selectedKey === null) {
108+
if (props.selectionType === 'radio')
109+
emit('update:selectedKey', '')
110+
else
111+
emit('update:selectedKey', [])
112+
}
113+
})
114+
115+
async function ok() {
116+
visible.value = false
117+
emit('update:selectedKey', selectedKeyBuffer.value)
118+
119+
M_values.value = _.clone(records.value)
120+
}
121+
122+
watchEffect(() => {
123+
init()
124+
})
125+
126+
// function clear() {
127+
// M_values.value = []
128+
// emit('update:selectedKey', '')
129+
// }
83130
</script>
84131

85132
<template>
@@ -88,19 +135,23 @@ const _selectedKey = computed({
88135
class="std-selector"
89136
@click="show"
90137
>
91-
<AInput
92-
v-model="_selectedKey"
93-
disabled
94-
hidden
95-
/>
96-
<div class="value">
97-
{{ M_value }}
138+
<div class="chips-container">
139+
<ATag
140+
v-for="(chipText, index) in M_values"
141+
:key="index"
142+
class="mr-1"
143+
color="orange"
144+
:bordered="false"
145+
@click="show"
146+
>
147+
{{ chipText?.[recordValueIndex] }}
148+
</ATag>
98149
</div>
99150
<AModal
100151
:mask="false"
101152
:open="visible"
102153
:cancel-text="$gettext('Cancel')"
103-
:ok-text="$gettext('OK')"
154+
:ok-text="$gettext('Ok')"
104155
:title="$gettext('Selector')"
105156
:width="800"
106157
destroy-on-close
@@ -109,15 +160,16 @@ const _selectedKey = computed({
109160
>
110161
{{ description }}
111162
<StdTable
163+
v-model:selected-row-keys="computedSelectedKeys"
164+
v-model:selected-rows="records"
112165
:api="api"
113166
:columns="columns"
114167
:disable-search="disableSearch"
115168
pithy
169+
:row-key="itemKey"
116170
:get-params="getParams"
117171
:selection-type="selectionType"
118172
disable-query-params
119-
@on-selected="onSelect"
120-
@on-selected-record="onSelectedRecord"
121173
/>
122174
</AModal>
123175
</div>
@@ -126,26 +178,34 @@ const _selectedKey = computed({
126178

127179
<style lang="less" scoped>
128180
.std-selector-container {
129-
height: 39.9px;
181+
min-height: 39.9px;
130182
display: flex;
131183
align-items: flex-start;
132184
133185
.std-selector {
186+
overflow-y: auto;
134187
box-sizing: border-box;
135188
font-variant: tabular-nums;
136189
list-style: none;
137190
font-feature-settings: 'tnum';
138-
height: 32px;
191+
min-height: 32px;
192+
max-height: 100px;
139193
padding: 4px 11px;
140194
font-size: 14px;
141195
line-height: 1.5;
142196
background-image: none;
143197
border: 1px solid #d9d9d9;
144198
border-radius: 4px;
145199
transition: all 0.3s;
146-
margin: 0 10px 0 0;
200+
//margin: 0 10px 0 0;
147201
cursor: pointer;
148202
min-width: 180px;
149203
}
150204
}
205+
206+
.chips-container {
207+
span {
208+
margin: 2px;
209+
}
210+
}
151211
</style>

app/src/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"2.0.0-beta.22","build_id":130,"total_build":334}
1+
{"version":"2.0.0-beta.22","build_id":131,"total_build":335}

app/src/views/dashboard/ServerAnalytic.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ function wsOnMessage(m: MessageEvent) {
214214
:md="8"
215215
>
216216
<RadialBarChart
217+
:key="$gettext('Memory')"
217218
:name="$gettext('Memory')"
218219
:series="[memory.pressure]"
219220
:center-text="memory.used"
@@ -227,6 +228,7 @@ function wsOnMessage(m: MessageEvent) {
227228
:md="8"
228229
>
229230
<RadialBarChart
231+
:key="$gettext('Swap')"
230232
:name="$gettext('Swap')"
231233
:series="[memory.swap_percent]"
232234
:center-text="memory.swap_used"
@@ -240,6 +242,7 @@ function wsOnMessage(m: MessageEvent) {
240242
:md="8"
241243
>
242244
<RadialBarChart
245+
:key="$gettext('Storage')"
243246
:name="$gettext('Storage')"
244247
:series="[disk.percentage]"
245248
:center-text="disk.used"

app/src/views/domain/cert/ChangeCert.vue

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type { Column, JSXElements } from '@/components/StdDesign/types'
1212
const current_server_directives = inject('current_server_directives') as ComputedRef<NgxDirective[]>
1313
const directivesMap = inject('directivesMap') as Ref<Record<string, NgxDirective[]>>
1414
const visible = ref(false)
15-
const record = ref({}) as Ref<Cert>
1615
1716
const columns: Column[] = [{
1817
title: () => $gettext('Name'),
@@ -55,31 +54,39 @@ function open() {
5554
visible.value = true
5655
}
5756
58-
function onSelectedRecord(r: Cert) {
59-
record.value = r
60-
}
57+
const records = ref([]) as Ref<Cert[]>
6158
6259
function ok() {
6360
if (directivesMap.value.ssl_certificate?.[0]) {
64-
directivesMap.value.ssl_certificate[0].params = record.value.ssl_certificate_path
61+
directivesMap.value.ssl_certificate[0].params = records.value[0].ssl_certificate_path
6562
}
6663
else {
6764
current_server_directives?.value.push({
6865
directive: 'ssl_certificate',
69-
params: record.value.ssl_certificate_path,
66+
params: records.value[0].ssl_certificate_path,
7067
})
7168
}
7269
if (directivesMap.value.ssl_certificate_key?.[0]) {
73-
directivesMap.value.ssl_certificate_key[0].params = record.value.ssl_certificate_key_path
70+
directivesMap.value.ssl_certificate_key[0].params = records.value[0].ssl_certificate_key_path
7471
}
7572
else {
7673
current_server_directives?.value.push({
7774
directive: 'ssl_certificate_key',
78-
params: record.value.ssl_certificate_key_path,
75+
params: records.value[0].ssl_certificate_key_path,
7976
})
8077
}
8178
visible.value = false
8279
}
80+
const selectedKeyBuffer = ref({})
81+
82+
const computedSelectedKeys = computed({
83+
get() {
84+
return [selectedKeyBuffer.value]
85+
},
86+
set(v) {
87+
selectedKeyBuffer.value = v
88+
},
89+
})
8390
</script>
8491

8592
<template>
@@ -94,11 +101,12 @@ function ok() {
94101
@ok="ok"
95102
>
96103
<StdTable
104+
v-model:selected-row-keys="computedSelectedKeys"
105+
v-model:selected-rows="records"
97106
:api="cert"
98107
pithy
99108
:columns="columns"
100109
selection-type="radio"
101-
@on-selected-record="onSelectedRecord"
102110
/>
103111
</AModal>
104112
</div>

app/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":"2.0.0-beta.22","build_id":130,"total_build":334}
1+
{"version":"2.0.0-beta.22","build_id":131,"total_build":335}

0 commit comments

Comments
 (0)