Skip to content

Commit e522658

Browse files
authored
#151 [Breaking Change] Admin 도메인 이관 및 관리자 UI 동기화 (#155)
1 parent afd2152 commit e522658

File tree

17 files changed

+1601
-859
lines changed

17 files changed

+1601
-859
lines changed

src/main/resources/static/js/admin/api/api-common.js

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,43 @@
11
PickeData.existingUrls = { thumbnail: null, charA: null, charB: null };
22
PickeData.scenarioId = null;
33

4-
// [공통] 이미지 서버 업로드 함수
4+
window.applyThumbnailPreview = function(url) {
5+
if (!url) return;
6+
7+
const bgIds = ['thumbnail-preview-bg'];
8+
const placeholderIds = ['thumbnail-placeholder'];
9+
const previewIds = ['intro-bg-img'];
10+
11+
bgIds.forEach((id) => {
12+
const bg = document.getElementById(id);
13+
if (!bg) return;
14+
bg.style.backgroundImage = `url('${url}')`;
15+
bg.style.setProperty('opacity', '1', 'important');
16+
bg.classList.remove('opacity-0');
17+
});
18+
19+
placeholderIds.forEach((id) => {
20+
const placeholder = document.getElementById(id);
21+
if (placeholder) {
22+
placeholder.style.display = 'none';
23+
placeholder.classList.add('hidden');
24+
}
25+
});
26+
27+
previewIds.forEach((id) => {
28+
const target = document.getElementById(id);
29+
if (target) target.style.backgroundImage = `url('${url}')`;
30+
});
31+
};
32+
33+
window.setTargetDateInputs = function(dateValue) {
34+
if (!dateValue) return;
35+
['battle-target-date', 'quiz-target-date', 'poll-target-date'].forEach((id) => {
36+
const input = document.getElementById(id);
37+
if (input) input.value = dateValue;
38+
});
39+
};
40+
541
window.uploadImageToServer = async function(file, category) {
642
if (!file) return null;
743
const formData = new FormData();
@@ -18,10 +54,33 @@ window.uploadImageToServer = async function(file, category) {
1854
const text = await res.text();
1955
try { return JSON.parse(text).result ?? JSON.parse(text).data ?? text; }
2056
catch { return text; }
21-
} catch (e) { console.error("이미지 업로드 실패:", e); return null; }
57+
} catch (e) {
58+
console.error("이미지 업로드 실패:", e);
59+
return null;
60+
}
61+
};
62+
63+
window.uploadImageToLocalDraft = async function(file) {
64+
if (!file) return null;
65+
const formData = new FormData();
66+
formData.append('file', file);
67+
68+
try {
69+
const res = await fetch(PickeData.API.FILE_UPLOAD_LOCAL, {
70+
method: 'POST',
71+
headers: { 'Authorization': `Bearer ${PickeData.token}` },
72+
body: formData
73+
});
74+
if (!res.ok) throw new Error(res.status);
75+
const text = await res.text();
76+
try { return JSON.parse(text).result ?? JSON.parse(text).data ?? text; }
77+
catch { return text; }
78+
} catch (e) {
79+
console.error("로컬 임시 이미지 업로드 실패:", e);
80+
return null;
81+
}
2282
};
2383

24-
// [공통] 페이지 로드 시 초기화 세팅
2584
document.addEventListener("DOMContentLoaded", async () => {
2685
function setupImageUpload(inputId, bgId, placeholderId, targetImgId, fileKey) {
2786
const input = document.getElementById(inputId);
@@ -32,14 +91,45 @@ document.addEventListener("DOMContentLoaded", async () => {
3291
PickeData.uploadedFiles[fileKey] = file;
3392
const url = URL.createObjectURL(file);
3493
PickeData.setPreviewImage(bgId, placeholderId, targetImgId, url);
35-
if(window.updateChatPreview) window.updateChatPreview();
94+
if (window.updateChatPreview) window.updateChatPreview();
3695
});
3796
}
3897

39-
setupImageUpload('thumbnail-upload', 'thumbnail-preview-bg', 'thumbnail-placeholder', 'intro-bg-img', 'thumbnail');
98+
function setupThumbnailUpload(inputId) {
99+
const input = document.getElementById(inputId);
100+
if (!input) return;
101+
input.addEventListener('change', (e) => {
102+
const file = e.target.files[0];
103+
if (!file) return;
104+
PickeData.uploadedFiles.thumbnail = file;
105+
const url = URL.createObjectURL(file);
106+
window.applyThumbnailPreview(url);
107+
});
108+
}
109+
110+
function bindTargetDateInput(inputId) {
111+
const input = document.getElementById(inputId);
112+
if (!input) return;
113+
input.addEventListener('change', (e) => {
114+
const value = e.target.value;
115+
if (!value) return;
116+
PickeData.currentTargetDate = value;
117+
window.setTargetDateInputs(value);
118+
});
119+
}
120+
121+
setupThumbnailUpload('thumbnail-upload');
40122
setupImageUpload('char-a-img-upload', 'char-a-img-bg', 'char-a-img-placeholder', 'intro-char-a-img', 'charA');
41123
setupImageUpload('char-b-img-upload', 'char-b-img-bg', 'char-b-img-placeholder', 'intro-char-b-img', 'charB');
42124

125+
bindTargetDateInput('battle-target-date');
126+
bindTargetDateInput('quiz-target-date');
127+
bindTargetDateInput('poll-target-date');
128+
129+
const today = new Date().toISOString().split('T')[0];
130+
if (!PickeData.currentTargetDate) PickeData.currentTargetDate = today;
131+
window.setTargetDateInputs(PickeData.currentTargetDate);
132+
43133
if (typeof window.fetchAllTags === 'function') await window.fetchAllTags();
44134
if (typeof window.loadContent === 'function') await window.loadContent();
45-
});
135+
});

0 commit comments

Comments
 (0)