6
6
<h5 class =" modal-title" >Create New Software catalog</h5 >
7
7
<button type =" button" class =" btn-close" data-bs-dismiss =" modal" aria-label =" Close" ></button >
8
8
</div >
9
- <div class =" modal-body" >
9
+ <div class =" modal-body" style = " max-height : calc ( 100 vh - 200 px ); overflow-y : auto ; " >
10
10
<div class =" mb-3" >
11
11
<label class =" form-label" >Title</label >
12
12
<input type =" text" class =" form-control" id =" sc-title" name =" title" placeholder =" Application name" v-model =" catalogDto.catalogTitle" />
22
22
<div class =" mb-3" >
23
23
<label class =" form-label" >Category</label >
24
24
<select class =" form-select" id =" sc-category" v-model =" catalogDto.catalogCategory" >
25
- <option value =" server " selected >SERVER</option >
26
- <option value =" was " >WAS</option >
27
- <option value =" db " >DB</option >
28
- <option value =" util " >UTIL</option >
29
- <option value =" observability " >OBSERVABILITY</option >
25
+ <option value =" SERVER " selected >SERVER</option >
26
+ <option value =" WAS " >WAS</option >
27
+ <option value =" DB " >DB</option >
28
+ <option value =" UTIL " >UTIL</option >
29
+ <option value =" OBSERVABILITY " >OBSERVABILITY</option >
30
30
</select >
31
31
</div >
32
32
<div class =" mb-3" >
38
38
<div class =" mb-3" >
39
39
<label class =" form-label" >Reference</label >
40
40
<select class =" form-select" id =" sc-reference-1" v-model =" ref.referenceType" >
41
- <option value =" url" selected >URL</option >
42
- <option value =" manifest" >manifest</option >
43
- <option value =" workflow" >workflow</option >
44
- <option value =" image" >image</option >
45
- <option value =" etc" >etc</option >
41
+ <option value =" URL" >URL</option >
42
+ <option value =" MANIFEST" >MANIFEST</option >
43
+ <option value =" WORKFLOW" >WORKFLOW</option >
44
+ <option value =" IMAGE" >IMAGE</option >
45
+ <option value =" HOMEPAGE" >HOMEPAGE</option >
46
+ <option value =" TAG" >TAG</option >
47
+ <option value =" ETC" >ETC</option >
46
48
</select >
47
49
</div >
48
50
</div >
96
98
import type { Repository } from ' ../../type/type' ;
97
99
import { ref } from ' vue' ;
98
100
import { useToast } from ' vue-toastification' ;
99
- import { createCatalog } from ' @/api/softwareCatalog' ;
100
- import { onMounted } from ' vue' ;
101
- import { computed } from ' vue' ;
102
- import { watch } from ' vue' ;
101
+ import { createCatalog } from ' @/api/softwareCatalog' ;
102
+ import { onMounted , watch , computed } from ' vue' ;
103
+ import axios from ' axios'
104
+
105
+ /**
106
+ * @Title Props / Emit
107
+ */
108
+ interface Props {
109
+ mode: String
110
+ catalogIdx: Number
111
+ }
103
112
104
113
const toast = useToast ()
105
114
const catalogDto = ref ({} as any );
106
115
const refData = ref ([] as any )
107
116
const files = ref ([] as any )
108
117
109
- const emit = defineEmits ([' get-list' ])
118
+ const splitUrl = window .location .host .split (' :' );
119
+ const baseUrl = window .location .protocol + ' //' + splitUrl [0 ] + ' :18084'
120
+ // const baseUrl = "http://210.217.178.130:18084";
110
121
122
+ const emit = defineEmits ([' get-list' ])
123
+ const props = defineProps <Props >()
124
+ const catalogIdx = computed (() => props .catalogIdx );
125
+ watch (catalogIdx , async () => {
126
+ await setInit ();
127
+ });
111
128
onMounted (async () => {
112
129
await setInit ()
113
130
})
114
131
115
132
const setInit = async () => {
116
- console .log (" setInit" )
117
- catalogDto .value = {
118
- " catalogIdx" : null ,
119
- " catalogTitle" : " " ,
120
- " catalogDescription" : " " ,
121
- " catalogSummary" : " " ,
122
- " catalogCategory" : " " ,
123
- " catalogRefData" : []
124
- }
125
- refData .value = [];
126
- refData .value .push (
127
- {
128
- " catalogRefIdx" : null ,
129
- " catalogIdx" : null ,
130
- " referncetIdx" : null ,
131
- " referenceValue" : " " ,
132
- " referenceDescription" : " " ,
133
- " referenceType" : " url"
133
+ console .log (" setInit props.catalogIdx : " , props .catalogIdx )
134
+ console .log (" porps.mode : " , props .mode )
135
+ if (props .mode == ' update' ) {
136
+ await _getSoftwareCatalogDetail ()
137
+ } else {
138
+ catalogDto .value = {
139
+ " catalogIdx" : null ,
140
+ " catalogTitle" : " " ,
141
+ " catalogDescription" : " " ,
142
+ " catalogSummary" : " " ,
143
+ " catalogCategory" : " " ,
144
+ " catalogRefData" : []
134
145
}
135
- )
146
+ refData .value = [];
147
+ refData .value .push (
148
+ {
149
+ " catalogRefIdx" : null ,
150
+ " catalogIdx" : null ,
151
+ " referncetIdx" : 0 ,
152
+ " referenceValue" : " " ,
153
+ " referenceDescription" : " " ,
154
+ " referenceType" : " url"
155
+ }
156
+ )
157
+ }
158
+ }
159
+
160
+ const _getSoftwareCatalogDetail = async () => {
161
+ try {
162
+ const response = await axios .get (baseUrl + ' /catalog/software/' + props .catalogIdx );
163
+ console .log (" response : " , response )
164
+
165
+ catalogDto .value = response .data
166
+ refData .value = response .data .catalogRefData ;
167
+ } catch (error ) {
168
+ console .log (error )
169
+ toast .error (' 데이터를 가져올 수 없습니다.' )
170
+ }
136
171
}
137
172
138
173
const addRef = () => {
139
174
console .log (" addRef" );
140
175
refData .value .push ({
141
176
" catalogRefIdx" : null ,
142
177
" catalogIdx" : null ,
143
- " referncetIdx" : null ,
178
+ " referncetIdx" : 0 ,
144
179
" referenceValue" : " " ,
145
180
" referenceDescription" : " " ,
146
181
" referenceType" : " url"
@@ -158,16 +193,31 @@ const handleFileChange = (event: any) => {
158
193
}
159
194
160
195
const createSoftwareCatalog = async () => {
161
- const formData = new FormData ();
162
- formData .append (' iconFile' , files .value );
163
- formData .append (' catalogDto' , catalogDto .value );
196
+ if (props .mode == ' new' ) {
197
+ const formData = new FormData ();
198
+ formData .append (' iconFile' , files .value );
199
+
200
+ catalogDto .value .catalogRefData = refData .value ;
201
+ formData .append (' catalogDto' , new Blob ([JSON .stringify (catalogDto .value )], {
202
+ type: ' application/json'
203
+ }));
204
+
205
+ const response = await axios .post (baseUrl + ' /catalog/software' , formData , {
206
+ headers: {
207
+ ' Content-Type' : ' multipart/form-data'
208
+ }
209
+ });
210
+
211
+ if (response .data ) {
212
+ toast .success (' 등록되었습니다.' )
213
+ emit (' get-list' )
214
+ } else {
215
+ toast .error (' 등록 할 수 없습니다.' )
216
+ }
217
+ } else {
218
+ const response = await axios .put (baseUrl + ' /catalog/software' )
219
+ }
164
220
165
- const { data } = await createCatalog (formData );
166
- if (data )
167
- toast .success (' 등록되었습니다.' )
168
- else
169
- toast .error (' 등록 할 수 없습니다.' )
170
- emit (' get-list' )
171
221
}
172
222
173
223
</script >
0 commit comments