@@ -8,20 +8,28 @@ import { useI18n } from 'vue-i18n'
8
8
9
9
const { t } = useI18n ()
10
10
11
- const emptyStore = {
12
- kind: {},
11
+ const emptyStore = function () {
12
+ return {
13
+ name: ' ' ,
14
+ url: ' ' ,
15
+ username: ' ' ,
16
+ password: ' ' ,
17
+ kind: {
18
+ name: ' ' ,
19
+ url: ' '
20
+ },
13
21
properties: [{
14
22
key: ' ' ,
15
23
value: ' '
16
24
}]
17
- } as Store
25
+ } as Store
26
+ }
18
27
const stores = ref ([] as Store [])
19
28
const dialogVisible = ref (false )
20
29
const creatingLoading = ref (false )
21
30
const storeFormRef = ref <FormInstance >()
22
- const store = ref (emptyStore )
23
31
const createAction = ref (true )
24
- const storeForm = reactive (store )
32
+ const storeForm = reactive (emptyStore () )
25
33
26
34
interface Store {
27
35
name: string
@@ -30,6 +38,7 @@ interface Store {
30
38
password: string
31
39
ready: boolean
32
40
kind: {
41
+ name: string
33
42
url: string
34
43
}
35
44
properties: Pair []
@@ -75,14 +84,23 @@ function editStore(name: string) {
75
84
dialogVisible .value = true
76
85
stores .value .forEach ((e : Store ) => {
77
86
if (e .name === name ) {
78
- store . value = e
87
+ setStoreForm ( e )
79
88
}
80
89
})
81
90
createAction .value = false
82
91
}
83
92
93
+ function setStoreForm(store : Store ) {
94
+ storeForm .name = store .name
95
+ storeForm .url = store .url
96
+ storeForm .username = store .username
97
+ storeForm .password = store .password
98
+ storeForm .kind = store .kind
99
+ storeForm .properties = store .properties
100
+ }
101
+
84
102
function addStore() {
85
- store . value = emptyStore
103
+ setStoreForm ( emptyStore ())
86
104
dialogVisible .value = true
87
105
createAction .value = true
88
106
}
@@ -96,14 +114,9 @@ const submitForm = async (formEl: FormInstance | undefined) => {
96
114
if (valid ) {
97
115
creatingLoading .value = true
98
116
99
- // remove empty pair
100
- store .value .properties = store .value .properties .filter (
101
- (e ) => e .key !== ' '
102
- )
103
-
104
117
const requestOptions = {
105
118
method: ' POST' ,
106
- body: JSON .stringify (store . value )
119
+ body: JSON .stringify (storeForm )
107
120
}
108
121
109
122
let api = ' /server.Runner/CreateStore'
@@ -112,22 +125,31 @@ const submitForm = async (formEl: FormInstance | undefined) => {
112
125
}
113
126
114
127
fetch (api , requestOptions )
115
- .then ((response ) => response .json ())
128
+ .then ((response ) => {
129
+ if (! response .ok ) {
130
+ throw new Error (response .statusText )
131
+ } else {
132
+ response .json ()
133
+ }
134
+ })
116
135
.then (() => {
117
- creatingLoading .value = false
118
136
loadStores ()
119
137
dialogVisible .value = false
120
138
formEl .resetFields ()
121
139
})
140
+ .catch ((e ) => {
141
+ ElMessage .error (' Oops, ' + e )
142
+ })
143
+ creatingLoading .value = false
122
144
}
123
145
})
124
146
}
125
147
126
148
function updateKeys() {
127
- const props = store . value .properties
149
+ const props = storeForm .properties
128
150
let lastItem = props [props .length - 1 ]
129
151
if (lastItem .key !== ' ' ) {
130
- store . value .properties .push ({
152
+ storeForm .properties .push ({
131
153
key: ' ' ,
132
154
value: ' '
133
155
})
@@ -209,6 +231,9 @@ function updateKeys() {
209
231
<el-form-item :label =" t('field.password')" prop =" password" >
210
232
<el-input v-model =" storeForm.password" type =" password" test-id =" store-form-password" />
211
233
</el-form-item >
234
+ <el-form-item :label =" t('field.plugin')" prop =" pluginName" >
235
+ <el-input v-model =" storeForm.kind.name" test-id =" store-form-plugin-name" />
236
+ </el-form-item >
212
237
<el-form-item :label =" t('field.plugin')" prop =" plugin" >
213
238
<el-input v-model =" storeForm.kind.url" test-id =" store-form-plugin" />
214
239
</el-form-item >
0 commit comments