-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.html
More file actions
568 lines (514 loc) · 20.2 KB
/
admin.html
File metadata and controls
568 lines (514 loc) · 20.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>패션 분석 관리자 페이지</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 20px;
background-color: #f5f5f5;
}
.container {
max-width: 1200px;
margin: 0 auto;
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
margin-bottom: 30px;
}
.section {
margin-bottom: 30px;
padding: 20px;
border: 1px solid #ddd;
border-radius: 5px;
}
.section h2 {
color: #555;
margin-top: 0;
}
button {
background-color: #007bff;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
margin: 5px;
}
button:hover {
background-color: #0056b3;
}
button:disabled {
background-color: #ccc;
cursor: not-allowed;
}
.file-list {
max-height: 400px;
overflow-y: auto;
border: 1px solid #ddd;
padding: 10px;
background-color: #f9f9f9;
}
.file-item {
padding: 10px;
border-bottom: 1px solid #eee;
cursor: pointer;
}
.file-item:hover {
background-color: #e9ecef;
}
.file-item.selected {
background-color: #007bff;
color: white;
}
.file-item .filename {
font-weight: bold;
}
.file-item .details {
font-size: 0.9em;
color: #666;
margin-top: 5px;
}
.file-item {
position: relative;
}
.delete-btn {
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
background: #dc3545;
color: white;
border: none;
border-radius: 4px;
padding: 5px 8px;
cursor: pointer;
font-size: 12px;
opacity: 0.7;
transition: opacity 0.2s ease;
}
.delete-btn:hover {
opacity: 1;
background: #c82333;
}
.file-item:hover .delete-btn {
opacity: 1;
}
.content-viewer {
border: 1px solid #ddd;
padding: 15px;
background-color: #f9f9f9;
max-height: 400px;
overflow-y: auto;
}
.image-viewer {
border: 1px solid #ddd;
padding: 15px;
background-color: #f9f9f9;
text-align: center;
margin-bottom: 15px;
}
.image-viewer img {
max-width: 100%;
max-height: 300px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.image-viewer .no-image {
color: #666;
font-style: italic;
padding: 20px;
}
.situations-editor {
margin-top: 15px;
}
.situation-tag {
display: inline-block;
background-color: #e9ecef;
padding: 5px 10px;
margin: 2px;
border-radius: 15px;
cursor: pointer;
}
.situation-tag:hover {
background-color: #dc3545;
color: white;
}
.situation-input {
padding: 8px;
border: 1px solid #ddd;
border-radius: 4px;
margin-right: 5px;
}
.predefined-tags {
margin: 15px 0;
padding: 15px;
background-color: #f8f9fa;
border-radius: 8px;
border: 1px solid #e9ecef;
}
.predefined-tags h5 {
margin: 0 0 10px 0;
color: #495057;
font-size: 14px;
}
.predefined-tag {
display: inline-block;
background-color: #007bff;
color: white;
padding: 6px 12px;
margin: 3px;
border-radius: 20px;
cursor: pointer;
font-size: 12px;
transition: all 0.2s ease;
}
.predefined-tag:hover {
background-color: #0056b3;
transform: scale(1.05);
}
.predefined-tag.added {
background-color: #28a745;
}
.predefined-tag.added:hover {
background-color: #1e7e34;
}
.loading {
text-align: center;
color: #666;
font-style: italic;
}
.error {
color: #dc3545;
background-color: #f8d7da;
padding: 10px;
border-radius: 4px;
margin: 10px 0;
}
.success {
color: #155724;
background-color: #d4edda;
padding: 10px;
border-radius: 4px;
margin: 10px 0;
}
</style>
</head>
<body>
<div class="container">
<h1>🎨 패션 분석 관리자 페이지</h1>
<!-- JSON 파일 목록 섹션 -->
<div class="section">
<h2>📁 S3 JSON 파일 목록</h2>
<button onclick="loadJsonFiles()">파일 목록 새로고침</button>
<div id="fileList" class="file-list">
<div class="loading">파일 목록을 불러오는 중...</div>
</div>
</div>
<!-- 파일 내용 및 편집 섹션 -->
<div class="section">
<h2>📝 파일 내용 및 편집</h2>
<div id="contentSection" style="display: none;">
<h3 id="selectedFileName"></h3>
<!-- 이미지 뷰어 -->
<div class="image-viewer" id="imageViewer">
<div class="no-image">이미지를 불러오는 중...</div>
</div>
<div class="content-viewer" id="jsonContent"></div>
<div class="situations-editor">
<h4>Situations 태그 편집</h4>
<div id="currentSituations"></div>
<!-- 미리 정의된 태그들 -->
<div class="predefined-tags">
<h5>🎯 빠른 태그 선택 (클릭하여 추가/제거)</h5>
<div id="predefinedTagsContainer">
<!-- JavaScript로 동적 생성 -->
</div>
</div>
<div style="margin-top: 10px;">
<input type="text" id="newSituation" class="situation-input" placeholder="새로운 상황 태그 입력">
<button onclick="addSituation()">추가</button>
<button onclick="updateSituations()">업데이트</button>
</div>
</div>
</div>
<div id="noFileSelected" style="text-align: center; color: #666;">
파일을 선택해주세요
</div>
</div>
<!-- 메시지 영역 -->
<div id="messageArea"></div>
</div>
<script>
const API_BASE = 'http://localhost:6020/api';
let currentSituations = [];
let selectedFilename = '';
// 미리 정의된 태그 목록
const predefinedTags = [
"직장/오피스",
"면접",
"첫 만남/소개팅",
"데이트",
"친구 모임",
"카페/스터디",
"쇼핑/외출",
"일상/데일리",
"결혼식/축하연",
"파티/클럽",
"여행",
"운동/액티비티"
];
// 페이지 로드 시 파일 목록 불러오기
window.onload = function() {
loadJsonFiles();
};
// JSON 파일 목록 불러오기
async function loadJsonFiles() {
const fileList = document.getElementById('fileList');
fileList.innerHTML = '<div class="loading">파일 목록을 불러오는 중...</div>';
try {
const response = await fetch(`${API_BASE}/admin/json-files`);
const data = await response.json();
if (data.success) {
displayFileList(data.data.json_files);
} else {
showError('파일 목록을 불러오는데 실패했습니다: ' + data.message);
}
} catch (error) {
showError('파일 목록을 불러오는데 실패했습니다: ' + error.message);
}
}
// 파일 목록 표시
function displayFileList(files) {
const fileList = document.getElementById('fileList');
if (files.length === 0) {
fileList.innerHTML = '<div class="loading">JSON 파일이 없습니다.</div>';
return;
}
// 수정 시간 순으로 정렬 (오래된 것부터 최신 순)
const sortedFiles = files.sort((a, b) => {
return new Date(a.last_modified) - new Date(b.last_modified);
});
fileList.innerHTML = sortedFiles.map(file => `
<div class="file-item" onclick="selectFile('${file.filename}')">
<div class="filename">${file.filename}</div>
<div class="details">
크기: ${(file.size / 1024).toFixed(1)}KB |
수정일: ${new Date(file.last_modified).toLocaleString()}
</div>
<button class="delete-btn" onclick="deleteFile('${file.filename}', event)" title="이 아웃핏 삭제">🗑️</button>
</div>
`).join('');
}
// 파일 선택
async function selectFile(filename) {
selectedFilename = filename;
// 선택된 파일 하이라이트
document.querySelectorAll('.file-item').forEach(item => {
item.classList.remove('selected');
});
event.target.closest('.file-item').classList.add('selected');
// 파일 내용 불러오기
await loadFileContent(filename);
}
// 파일 내용 불러오기
async function loadFileContent(filename) {
const contentSection = document.getElementById('contentSection');
const noFileSelected = document.getElementById('noFileSelected');
const selectedFileName = document.getElementById('selectedFileName');
const jsonContent = document.getElementById('jsonContent');
contentSection.style.display = 'block';
noFileSelected.style.display = 'none';
selectedFileName.textContent = `파일: ${filename}`;
jsonContent.innerHTML = '<div class="loading">파일 내용을 불러오는 중...</div>';
try {
const response = await fetch(`${API_BASE}/admin/json-content/${filename}`);
const data = await response.json();
if (data.success) {
displayFileContent(data.data.content);
} else {
showError('파일 내용을 불러오는데 실패했습니다: ' + data.message);
}
} catch (error) {
showError('파일 내용을 불러오는데 실패했습니다: ' + error.message);
}
}
// 파일 내용 표시
function displayFileContent(content) {
const jsonContent = document.getElementById('jsonContent');
const currentSituationsDiv = document.getElementById('currentSituations');
const imageViewer = document.getElementById('imageViewer');
// JSON 내용 표시
jsonContent.innerHTML = `<pre>${JSON.stringify(content, null, 2)}</pre>`;
// 이미지 표시
displayImage(content.source_image_url);
// 현재 situations 표시
currentSituations = content.situations || [];
displaySituations();
}
// 이미지 표시
function displayImage(imageUrl) {
const imageViewer = document.getElementById('imageViewer');
if (imageUrl) {
imageViewer.innerHTML = `
<img src="${imageUrl}" alt="패션 이미지" onerror="this.parentElement.innerHTML='<div class=\\'no-image\\'>이미지를 불러올 수 없습니다</div>'">
`;
} else {
// source_image_url이 없는 경우, 파일명으로 이미지 URL 추측
// 여러 확장자 시도
const extensions = ['png', 'jpg', 'jpeg', 'webp', 'gif'];
let imageFound = false;
for (let ext of extensions) {
const testUrl = `https://thefirsttake-combination.s3.ap-northeast-2.amazonaws.com/image/${selectedFilename}.${ext}`;
const img = new Image();
img.onload = function() {
if (!imageFound) {
imageFound = true;
imageViewer.innerHTML = `<img src="${testUrl}" alt="패션 이미지" style="max-width: 100%; max-height: 300px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1);">`;
}
};
img.onerror = function() {
// 마지막 확장자까지 시도했는데 실패한 경우
if (ext === extensions[extensions.length - 1] && !imageFound) {
imageViewer.innerHTML = '<div class="no-image">이미지를 찾을 수 없습니다</div>';
}
};
img.src = testUrl;
}
}
}
// Situations 표시
function displaySituations() {
const currentSituationsDiv = document.getElementById('currentSituations');
currentSituationsDiv.innerHTML = currentSituations.map(situation =>
`<span class="situation-tag" onclick="removeSituation('${situation}')">${situation} ✕</span>`
).join('');
// 미리 정의된 태그들 업데이트
updatePredefinedTags();
}
// 미리 정의된 태그들 표시 및 상태 업데이트
function updatePredefinedTags() {
const container = document.getElementById('predefinedTagsContainer');
container.innerHTML = predefinedTags.map(tag => {
const isAdded = currentSituations.includes(tag);
const className = isAdded ? 'predefined-tag added' : 'predefined-tag';
return `<span class="${className}" onclick="togglePredefinedTag('${tag}')">${tag}</span>`;
}).join('');
}
// 미리 정의된 태그 토글 (추가/제거)
function togglePredefinedTag(tag) {
if (currentSituations.includes(tag)) {
// 이미 있으면 제거
removeSituation(tag);
} else {
// 없으면 추가
if (!currentSituations.includes(tag)) {
currentSituations.push(tag);
displaySituations();
}
}
}
// 상황 태그 추가
function addSituation() {
const input = document.getElementById('newSituation');
const newSituation = input.value.trim();
if (newSituation && !currentSituations.includes(newSituation)) {
currentSituations.push(newSituation);
displaySituations();
input.value = '';
}
}
// 상황 태그 제거
function removeSituation(situation) {
currentSituations = currentSituations.filter(s => s !== situation);
displaySituations();
}
// Situations 업데이트
async function updateSituations() {
if (!selectedFilename) {
showError('파일을 선택해주세요.');
return;
}
try {
const response = await fetch(`${API_BASE}/admin/update-situations/${selectedFilename}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ situations: currentSituations })
});
const data = await response.json();
if (data.success) {
showSuccess('Situations가 성공적으로 업데이트되었습니다!');
// 파일 내용 새로고침
await loadFileContent(selectedFilename);
} else {
showError('업데이트에 실패했습니다: ' + data.message);
}
} catch (error) {
showError('업데이트에 실패했습니다: ' + error.message);
}
}
// 에러 메시지 표시
function showError(message) {
const messageArea = document.getElementById('messageArea');
messageArea.innerHTML = `<div class="error">❌ ${message}</div>`;
setTimeout(() => {
messageArea.innerHTML = '';
}, 5000);
}
// 성공 메시지 표시
function showSuccess(message) {
const messageArea = document.getElementById('messageArea');
messageArea.innerHTML = `<div class="success">✅ ${message}</div>`;
setTimeout(() => {
messageArea.innerHTML = '';
}, 3000);
}
// Enter 키로 상황 태그 추가
document.getElementById('newSituation').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
addSituation();
}
});
// 파일 삭제
async function deleteFile(filename, event) {
// 이벤트 버블링 방지
event.stopPropagation();
// 확인 대화상자
if (!confirm(`정말로 "${filename}" 아웃핏을 삭제하시겠습니까?\n\n⚠️ 이 작업은 되돌릴 수 없습니다.\n- JSON 파일과 이미지 파일이 모두 삭제됩니다.`)) {
return;
}
try {
const response = await fetch(`${API_BASE}/admin/delete-outfit/${filename}`, {
method: 'DELETE'
});
const data = await response.json();
if (data.success) {
showSuccess(`아웃핏 "${filename}"이 성공적으로 삭제되었습니다!`);
// 현재 선택된 파일이 삭제된 파일이면 선택 해제
if (selectedFilename === filename) {
selectedFilename = '';
document.getElementById('contentSection').style.display = 'none';
document.getElementById('noFileSelected').style.display = 'block';
}
// 파일 목록 새로고침
await loadJsonFiles();
} else {
showError('삭제에 실패했습니다: ' + data.message);
}
} catch (error) {
showError('삭제에 실패했습니다: ' + error.message);
}
}
</script>
</body>
</html>