admin: refine template settings actions

This commit is contained in:
2026-04-06 12:18:25 +09:00
parent 47638b8b3e
commit fd3f61ca2b
4 changed files with 153 additions and 18 deletions

View File

@@ -11,6 +11,7 @@ const props = defineProps({
openTemplateCreateModal: { type: Function, required: true },
openTemplateSourceImportModal: { type: Function, required: true },
openTemplateLibraryItemModal: { type: Function, required: true },
openTemplateBulkTagModal: { type: Function, required: true },
isTemplateLoading: { type: Boolean, required: true },
hasSelectedTemplate: { type: Boolean, required: true },
selectedTemplate: { type: Object, default: null },
@@ -20,6 +21,7 @@ const props = defineProps({
templateMetaSaving: { type: Boolean, required: true },
canSaveTemplateMeta: { type: Boolean, required: true },
saveTemplateMeta: { type: Function, required: true },
canBulkTagTemplateItems: { type: Boolean, required: true },
canApplyThumbnail: { type: Boolean, required: true },
templateVisibilitySaving: { type: Boolean, required: true },
thumbFileInputRef: { type: Function, required: true },
@@ -172,8 +174,9 @@ function setThumbFileElement(el) {
</label>
<div class="templateSettingsCard__actions">
<button class="btn btn--ghost" :disabled="!props.canSaveTemplateMeta || props.templateMetaSaving" @click="props.saveTemplateMeta">
{{ props.templateMetaSaving ? '저장중...' : '템플릿 메타 저장' }}
{{ props.templateMetaSaving ? '저장중...' : '이름/주소 저장' }}
</button>
<button class="btn btn--ghost" :disabled="!props.canBulkTagTemplateItems" @click="props.openTemplateBulkTagModal">기본 아이템 공통 태그</button>
<button class="btn btn--ghost" @click="props.openTemplateLibraryItemModal">개별 아이템 검색</button>
<button class="btn btn--ghost" @click="props.openTemplateSourceImportModal">기존 템플릿 가져오기</button>
<button class="btn" :disabled="!props.canApplyThumbnail" @click="props.uploadThumbnail">썸네일 적용</button>
@@ -252,19 +255,17 @@ function setThumbFileElement(el) {
<div v-if="!props.selectedTemplate?.items?.length" class="hint">아직 등록된 기본 아이템이 없어요.</div>
<div v-else :ref="setTemplateItemListElement" class="thumbGrid">
<div v-for="item in props.selectedTemplate.items" :key="item.id" class="thumbCard" :data-template-item-id="item.id">
<img class="thumb thumb--template" :src="toApiUrl(item.src)" :alt="item.label" draggable="false" />
<input v-model="item.draftLabel" class="input input--labelEdit" placeholder="아이템 이름" data-no-drag />
<div class="thumbCard__actions">
<button
class="btn btn--ghost btn--small"
data-no-drag
:disabled="item.isSavingLabel || !item.draftLabel?.trim() || item.draftLabel.trim() === item.label"
@click="props.saveTemplateItemLabel(item)"
>
{{ item.isSavingLabel ? '저장중...' : '이름 저장' }}
</button>
<button class="btn btn--danger btn--small" data-no-drag @click="props.removeTemplateItem(item.id)">아이템 삭제</button>
<div class="thumbCard__media">
<img class="thumb thumb--template" :src="toApiUrl(item.src)" :alt="item.label" draggable="false" />
<button class="thumbCard__deleteBtn" type="button" data-no-drag @click="props.removeTemplateItem(item.id)">X</button>
</div>
<input
v-model="item.draftLabel"
class="input input--labelEdit"
placeholder="아이템 이름"
data-no-drag
@keydown.enter.prevent="props.saveTemplateItemLabel(item)"
/>
</div>
</div>
</div>

View File

@@ -79,6 +79,9 @@ const templateLibraryItemQuery = ref('')
const templateLibraryItemResults = ref([])
const templateLibraryItemSelectedIds = ref([])
const templateLibraryItemLoading = ref(false)
const templateBulkTagModalOpen = ref(false)
const templateBulkTagDrafts = ref([])
const templateBulkTagSaving = ref(false)
const previewModalOpen = ref(false)
const previewTierList = ref(null)
const adminTierListManageModalOpen = ref(false)
@@ -219,6 +222,7 @@ const canSaveTemplateMeta = computed(() => {
)
})
const canApplyThumbnail = computed(() => !!thumbFile.value && !!selectedTemplateId.value)
const canBulkTagTemplateItems = computed(() => !!selectedTemplate.value?.items?.length)
const canAddItem = computed(() => uploadItemDrafts.value.length > 0 && uploadItemDrafts.value.every((item) => !!item.label.trim()) && !!selectedTemplateId.value)
const stagedRequestDraftCount = computed(() => uploadItemDrafts.value.filter((item) => item.kind === 'request').length)
const appliedRequestItemCount = computed(() => {
@@ -365,6 +369,7 @@ const isAnyModalOpen = computed(
importModalOpen.value ||
templateSourceImportModalOpen.value ||
templateLibraryItemModalOpen.value ||
templateBulkTagModalOpen.value ||
templatePickerModalOpen.value ||
customItemModalOpen.value ||
customItemDeleteModalOpen.value ||
@@ -1319,7 +1324,7 @@ async function saveTemplateMeta() {
templateMetaDraftName.value = nextTemplate.name || selectedTemplate.value.template.name || ''
templateMetaDraftSlug.value = nextTemplate.slug || selectedTemplate.value.template.slug || selectedTemplate.value.template.id || ''
await refreshTemplates()
success.value = '템플릿 메타를 저장했어요.'
success.value = '템플릿 이름과 주소를 저장했어요.'
} catch (e) {
const errorCode = e?.data?.error || ''
if (errorCode === 'topic_slug_taken') {
@@ -1330,12 +1335,69 @@ async function saveTemplateMeta() {
error.value = 'slug는 영문 소문자, 숫자, 하이픈만 사용할 수 있어요.'
return
}
error.value = '템플릿 메타를 저장하지 못했어요.'
error.value = '템플릿 이름과 주소를 저장하지 못했어요.'
} finally {
templateMetaSaving.value = false
}
}
function openTemplateBulkTagModal() {
resetMessages()
if (!selectedTemplate.value?.items?.length) {
error.value = '태그를 추가할 기본 아이템이 없어요.'
return
}
templateBulkTagDrafts.value = []
templateBulkTagSaving.value = false
templateBulkTagModalOpen.value = true
}
function closeTemplateBulkTagModal() {
templateBulkTagModalOpen.value = false
templateBulkTagDrafts.value = []
templateBulkTagSaving.value = false
}
async function applyTemplateBulkTags() {
resetMessages()
if (!selectedTemplateId.value || !selectedTemplate.value?.items?.length) {
error.value = '태그를 적용할 템플릿을 먼저 선택해주세요.'
return
}
const nextTags = parseAdminTagsText(templateBulkTagDrafts.value)
if (!nextTags.length) {
error.value = '추가할 태그를 하나 이상 입력해주세요.'
return
}
try {
templateBulkTagSaving.value = true
const items = selectedTemplate.value.items || []
let updatedCount = 0
for (const item of items) {
const mergedTags = Array.from(new Set([...(Array.isArray(item.tags) ? item.tags : []), ...nextTags]))
if (JSON.stringify(mergedTags) === JSON.stringify(Array.isArray(item.tags) ? item.tags : [])) continue
const data = await api.updateAdminTemplateItem(selectedTemplateId.value, item.id, {
label: item.label,
tags: mergedTags,
})
item.tags = Array.isArray(data.item?.tags) ? data.item.tags : mergedTags
updatedCount += 1
}
closeTemplateBulkTagModal()
success.value = updatedCount
? `기본 아이템 ${updatedCount}개에 공통 태그를 추가했어요.`
: '이미 같은 태그가 들어 있어서 바뀐 항목이 없었어요.'
} catch (e) {
error.value = '기본 아이템 공통 태그 추가에 실패했어요.'
} finally {
templateBulkTagSaving.value = false
}
}
async function toggleSelectedTemplateVisibility(nextValue) {
if (!selectedTemplate.value?.template?.id || templateVisibilitySaving.value) return
const previous = !!selectedTemplate.value.template.isPublic
@@ -2033,6 +2095,7 @@ function openUserProfile(user) {
:open-template-create-modal="openTemplateCreateModal"
:open-template-source-import-modal="openTemplateSourceImportModal"
:open-template-library-item-modal="openTemplateLibraryItemModal"
:open-template-bulk-tag-modal="openTemplateBulkTagModal"
:is-template-loading="isTemplateLoading"
:has-selected-template="hasSelectedTemplate"
:selected-template="selectedTemplate"
@@ -2042,6 +2105,7 @@ function openUserProfile(user) {
:template-meta-saving="templateMetaSaving"
:can-save-template-meta="canSaveTemplateMeta"
:save-template-meta="saveTemplateMeta"
:can-bulk-tag-template-items="canBulkTagTemplateItems"
:can-apply-thumbnail="canApplyThumbnail"
:template-visibility-saving="templateVisibilitySaving"
:thumb-file-input-ref="setThumbFileInputRef"
@@ -2362,6 +2426,27 @@ function openUserProfile(user) {
</div>
</div>
<div v-if="templateBulkTagModalOpen" class="modalOverlay" @click.self="closeTemplateBulkTagModal">
<div class="modalCard" role="dialog" aria-modal="true">
<div class="modalCard__title">기본 아이템 공통 태그</div>
<div class="modalCard__desc">
현재 템플릿의 기본 아이템 전체에 같은 태그를 번에 추가합니다. 이미 있는 태그는 중복 저장하지 않아요.
</div>
<div class="modalCard__form">
<label class="field">
<span class="field__label">추가할 태그</span>
<TagBadgeInput v-model="templateBulkTagDrafts" placeholder="태그 입력 후 Enter" :disabled="templateBulkTagSaving" />
</label>
</div>
<div class="modalCard__actions">
<button class="btn btn--ghost" :disabled="templateBulkTagSaving" @click="closeTemplateBulkTagModal">취소</button>
<button class="btn btn--primary" :disabled="templateBulkTagSaving || !templateBulkTagDrafts.length" @click="applyTemplateBulkTags">
{{ templateBulkTagSaving ? '적용중...' : '공통 태그 추가' }}
</button>
</div>
</div>
</div>
<div v-if="customItemModalOpen" class="modalOverlay" @click.self="closeCustomItemModal">
<div class="modalCard modalCard--customItem" role="dialog" aria-modal="true">
<div v-if="modalTargetCustomItem" class="customItemModal">
@@ -3571,6 +3656,7 @@ function openUserProfile(user) {
grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
gap: 18px;
align-items: center;
min-width: 0;
}
.adminUiScope .templateSettingsCard__media {
min-width: 0;
@@ -3579,6 +3665,7 @@ function openUserProfile(user) {
display: grid;
gap: 14px;
align-content: center;
min-width: 0;
}
.adminUiScope .templateSettingsCard__meta {
color: var(--theme-text-soft);
@@ -3592,9 +3679,20 @@ function openUserProfile(user) {
align-items: center;
gap: 10px;
flex-wrap: wrap;
min-width: 0;
}
.adminUiScope .templateSettingsCard__actions > .btn {
flex: 0 0 auto;
max-width: 100%;
white-space: normal;
}
.adminUiScope .templateMetaForm,
.adminUiScope .templateMetaField {
min-width: 0;
}
.adminUiScope .templateMetaField .input {
width: 100%;
min-width: 0;
}
.adminUiScope .selectedThumb {
width: min(100%, 256px);
@@ -3822,6 +3920,7 @@ function openUserProfile(user) {
gap: 12px;
}
.adminUiScope .thumbCard {
position: relative;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 16px;
background: var(--theme-surface-soft);
@@ -3832,6 +3931,9 @@ function openUserProfile(user) {
-webkit-user-drag: none;
touch-action: none;
}
.adminUiScope .thumbCard__media {
position: relative;
}
.adminUiScope .thumbCard:active {
cursor: grabbing;
}
@@ -3854,10 +3956,25 @@ function openUserProfile(user) {
opacity: 0.9;
word-break: break-word;
}
.adminUiScope .thumbCard__actions {
margin-top: 10px;
.adminUiScope .thumbCard__deleteBtn {
position: absolute;
top: 8px;
right: 8px;
width: 28px;
height: 28px;
display: grid;
gap: 8px;
place-items: center;
border-radius: 999px;
border: 1px solid rgba(255, 255, 255, 0.14);
background: rgba(9, 13, 22, 0.82);
color: var(--theme-text);
font-size: 11px;
font-weight: 900;
cursor: pointer;
z-index: 2;
}
.adminUiScope .thumbCard__deleteBtn:hover {
background: rgba(190, 24, 24, 0.9);
}
.adminUiScope .thumbLabel--preview {
text-align: center;
@@ -5050,6 +5167,10 @@ function openUserProfile(user) {
.adminUiScope .modalCard__form--search {
grid-template-columns: 1fr;
}
.adminUiScope .templateSettingsCard__actions > .btn,
.adminUiScope .templateSettingsCard__actions > a.btn {
width: 100%;
}
.adminUiScope.adminSidebar {
display: none;
}