Changed around line 1
+ class WorkDiary {
+ constructor() {
+ this.logs = JSON.parse(localStorage.getItem('workLogs')) || [];
+ this.initializeElements();
+ this.bindEvents();
+ this.renderLogs();
+ this.updateStats();
+ }
+
+ initializeElements() {
+ this.logDialog = document.getElementById('logDialog');
+ this.logForm = document.getElementById('logForm');
+ this.newLogBtn = document.getElementById('newLogBtn');
+ this.searchInput = document.getElementById('searchInput');
+ this.categoryFilter = document.getElementById('categoryFilter');
+ this.logsList = document.getElementById('logsList');
+ }
+
+ bindEvents() {
+ this.newLogBtn.addEventListener('click', () => this.openNewLogDialog());
+ this.logForm.addEventListener('submit', (e) => this.handleLogSubmit(e));
+ this.searchInput.addEventListener('input', () => this.filterLogs());
+ this.categoryFilter.addEventListener('change', () => this.filterLogs());
+ document.getElementById('cancelBtn').addEventListener('click', () => this.logDialog.close());
+ document.getElementById('exportBtn').addEventListener('click', () => this.exportLogs());
+ document.getElementById('backupBtn').addEventListener('click', () => this.backupData());
+ }
+
+ openNewLogDialog() {
+ document.getElementById('logDate').valueAsDate = new Date();
+ this.logForm.reset();
+ this.logDialog.showModal();
+ }
+
+ handleLogSubmit(e) {
+ e.preventDefault();
+ const formData = new FormData(this.logForm);
+ const log = {
+ id: Date.now(),
+ date: formData.get('logDate'),
+ category: formData.get('logCategory'),
+ content: formData.get('logContent'),
+ tags: formData.get('logTags').split(',').map(tag => tag.trim()),
+ createdAt: new Date().toISOString()
+ };
+
+ this.logs.unshift(log);
+ this.saveLogs();
+ this.renderLogs();
+ this.updateStats();
+ this.logDialog.close();
+ }
+
+ renderLogs() {
+ this.logsList.innerHTML = this.logs
+ .map(log => this.createLogCard(log))
+ .join('');
+ }
+
+ createLogCard(log) {
+ return `
+
+
${new Date(log.date).toLocaleDateString()}
+ ${log.category}
+
+
+ ${log.tags.map(tag => `${tag}`).join('')}
+
+
+ `;
+ }
+
+ filterLogs() {
+ const searchTerm = this.searchInput.value.toLowerCase();
+ const categoryFilter = this.categoryFilter.value;
+
+ const filtered = this.logs.filter(log => {
+ const matchesSearch = log.content.toLowerCase().includes(searchTerm) ||
+ log.tags.some(tag => tag.toLowerCase().includes(searchTerm));
+ const matchesCategory = !categoryFilter || log.category === categoryFilter;
+ return matchesSearch && matchesCategory;
+ });
+
+ this.logsList.innerHTML = filtered
+ .map(log => this.createLogCard(log))
+ .join('');
+ }
+
+ updateStats() {
+ const monthlyStats = document.getElementById('monthlyStats');
+ const categoryStats = document.getElementById('categoryStats');
+
+ const currentMonth = new Date().getMonth();
+ const monthlyCount = this.logs.filter(log =>
+ new Date(log.date).getMonth() === currentMonth
+ ).length;
+
+ const categories = {};
+ this.logs.forEach(log => {
+ categories[log.category] = (categories[log.category] || 0) + 1;
+ });
+
+ monthlyStats.innerHTML = `
This month: ${monthlyCount} logs
`;
+ categoryStats.innerHTML = Object.entries(categories)
+ .map(([category, count]) => `
${category}: ${count}
`)
+ .join('');
+ }
+
+ saveLogs() {
+ localStorage.setItem('workLogs', JSON.stringify(this.logs));
+ }
+
+ exportLogs() {
+ const blob = new Blob([JSON.stringify(this.logs, null, 2)],
+ {type: 'application/json'});
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement('a');
+ a.href = url;
+ a.download = `workdiary-export-${new Date().toISOString().split('T')[0]}.json`;
+ a.click();
+ URL.revokeObjectURL(url);
+ }
+
+ backupData() {
+ const backup = {
+ logs: this.logs,
+ timestamp: new Date().toISOString()
+ };
+ localStorage.setItem('workDiaryBackup', JSON.stringify(backup));
+ alert('Backup created successfully!');
+ }
+ }
+
+ const workDiary = new WorkDiary();