Files
document-server/frontend/static/js/book-documents.js
Hyungi Ahn 4038040faa Major UI overhaul and upload system improvements
- Removed hierarchy view and integrated functionality into index.html
- Added book-based document grouping with dedicated book-documents.html page
- Implemented comprehensive multi-file upload system with drag-and-drop reordering
- Added HTML-PDF matching functionality with download capability
- Enhanced upload workflow with 3-step process (File Selection, Book Settings, Order & Match)
- Added book conflict resolution (existing book vs new edition)
- Improved document order adjustment with one-click sort options
- Added modular header component system
- Updated API connectivity for Docker environment
- Enhanced viewer.html with PDF download functionality
- Fixed browser caching issues with version management
- Improved mobile responsiveness and modern UI design
2025-08-25 15:58:30 +09:00

181 lines
5.8 KiB
JavaScript

// 서적 문서 목록 애플리케이션 컴포넌트
window.bookDocumentsApp = () => ({
// 상태 관리
documents: [],
bookInfo: {},
loading: false,
error: '',
// 인증 상태
isAuthenticated: false,
currentUser: null,
// URL 파라미터
bookId: null,
// 초기화
async init() {
console.log('🚀 Book Documents App 초기화 시작');
// URL 파라미터 파싱
this.parseUrlParams();
// 인증 상태 확인
await this.checkAuthStatus();
if (this.isAuthenticated) {
await this.loadBookDocuments();
}
// 헤더 로드
await this.loadHeader();
},
// URL 파라미터 파싱
parseUrlParams() {
const urlParams = new URLSearchParams(window.location.search);
this.bookId = urlParams.get('bookId');
console.log('📖 서적 ID:', this.bookId);
},
// 인증 상태 확인
async checkAuthStatus() {
try {
const user = await window.api.getCurrentUser();
this.isAuthenticated = true;
this.currentUser = user;
console.log('✅ 인증됨:', user.username);
} catch (error) {
console.log('❌ 인증되지 않음');
this.isAuthenticated = false;
this.currentUser = null;
// 로그인 페이지로 리다이렉트하거나 로그인 모달 표시
window.location.href = '/login.html';
}
},
// 헤더 로드
async loadHeader() {
try {
await window.headerLoader.loadHeader();
} catch (error) {
console.error('헤더 로드 실패:', error);
}
},
// 서적 문서 목록 로드
async loadBookDocuments() {
this.loading = true;
this.error = '';
try {
// 모든 문서 가져오기
const allDocuments = await window.api.getDocuments();
if (this.bookId === 'none') {
// 서적 미분류 문서들
this.documents = allDocuments.filter(doc => !doc.book_id);
this.bookInfo = {
title: '서적 미분류',
description: '서적에 속하지 않은 문서들입니다.'
};
} else {
// 특정 서적의 문서들
this.documents = allDocuments.filter(doc => doc.book_id === this.bookId);
if (this.documents.length > 0) {
// 첫 번째 문서에서 서적 정보 추출
const firstDoc = this.documents[0];
this.bookInfo = {
id: firstDoc.book_id,
title: firstDoc.book_title,
author: firstDoc.book_author,
description: firstDoc.book_description || '서적 설명이 없습니다.'
};
} else {
// 서적 정보만 가져오기 (문서가 없는 경우)
try {
this.bookInfo = await window.api.getBook(this.bookId);
} catch (error) {
console.error('서적 정보 로드 실패:', error);
this.bookInfo = {
title: '알 수 없는 서적',
description: '서적 정보를 불러올 수 없습니다.'
};
}
}
}
console.log('📚 서적 문서 로드 완료:', this.documents.length, '개');
} catch (error) {
console.error('서적 문서 로드 실패:', error);
this.error = '문서를 불러오는데 실패했습니다: ' + error.message;
this.documents = [];
} finally {
this.loading = false;
}
},
// 문서 열기
openDocument(documentId) {
// 현재 페이지 정보를 세션 스토리지에 저장
sessionStorage.setItem('previousPage', 'book-documents.html');
// 뷰어로 이동
window.open(`/viewer.html?id=${documentId}&from=book`, '_blank');
},
// 문서 수정
editDocument(doc) {
// TODO: 문서 수정 모달 또는 페이지로 이동
console.log('문서 수정:', doc.title);
alert('문서 수정 기능은 준비 중입니다.');
},
// 문서 삭제
async deleteDocument(documentId) {
if (!confirm('이 문서를 삭제하시겠습니까?')) {
return;
}
try {
await window.api.deleteDocument(documentId);
await this.loadBookDocuments(); // 목록 새로고침
this.showNotification('문서가 삭제되었습니다', 'success');
} catch (error) {
console.error('문서 삭제 실패:', error);
this.showNotification('문서 삭제에 실패했습니다: ' + error.message, 'error');
}
},
// 뒤로가기
goBack() {
window.location.href = 'index.html';
},
// 날짜 포맷팅
formatDate(dateString) {
if (!dateString) return '';
const date = new Date(dateString);
return date.toLocaleDateString('ko-KR', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
},
// 알림 표시
showNotification(message, type = 'info') {
// TODO: 알림 시스템 구현
console.log(`${type.toUpperCase()}: ${message}`);
if (type === 'error') {
alert(message);
}
}
});
// 페이지 로드 시 초기화
document.addEventListener('DOMContentLoaded', () => {
console.log('📄 Book Documents 페이지 로드됨');
});