Changed around line 1
+ class WorkLogManager {
+ constructor() {
+ this.logs = JSON.parse(localStorage.getItem('workLogs')) || [];
+ this.categories = new Set(this.logs.map(log => log.category));
+ this.setupEventListeners();
+ this.updateCategoryList();
+ this.renderLogs();
+ }
+
+ setupEventListeners() {
+ document.getElementById('newLogBtn').addEventListener('click', () => {
+ document.getElementById('logForm').classList.remove('hidden');
+ document.getElementById('logDate').value = new Date().toISOString().slice(0, 16);
+ });
+
+ document.getElementById('workLogForm').addEventListener('submit', (e) => {
+ e.preventDefault();
+ this.saveLog();
+ });
+
+ document.getElementById('cancelBtn').addEventListener('click', () => {
+ document.getElementById('logForm').classList.add('hidden');
+ });
+
+ document.getElementById('searchInput').addEventListener('input', () => this.filterLogs());
+ document.getElementById('filterCategory').addEventListener('change', () => this.filterLogs());
+ document.getElementById('sortDateBtn').addEventListener('click', () => this.toggleSort());
+ document.getElementById('exportBtn').addEventListener('click', () => this.exportLogs());
+ }
+
+ saveLog() {
+ const logData = {
+ id: Date.now(),
+ date: document.getElementById('logDate').value,
+ category: document.getElementById('logCategory').value,
+ tags: document.getElementById('logTags').value.split(',').map(tag => tag.trim()).filter(tag => tag),
+ content: document.getElementById('logContent').value
+ };
+
+ this.logs.unshift(logData);
+ this.updateLocalStorage();
+ this.categories.add(logData.category);
+ this.updateCategoryList();
+ this.renderLogs();
+ document.getElementById('workLogForm').reset();
+ document.getElementById('logForm').classList.add('hidden');
+ }
+
+ updateLocalStorage() {
+ localStorage.setItem('workLogs', JSON.stringify(this.logs));
+ }
+
+ updateCategoryList() {
+ const categorySelect = document.getElementById('filterCategory');
+ const categoryDatalist = document.getElementById('categories');
+
+ categorySelect.innerHTML = '';
+ categoryDatalist.innerHTML = '';
+
+ this.categories.forEach(category => {
+ if (category) {
+ categorySelect.innerHTML += ``;
+ categoryDatalist.innerHTML += `
+ }
+ });
+ }
+
+ renderLogs() {
+ const logEntries = document.getElementById('logEntries');
+ logEntries.innerHTML = '';
+
+ this.logs.forEach(log => {
+ const logElement = document.createElement('div');
+ logElement.className = 'log-entry';
+ logElement.innerHTML = `
+
+
+ ${new Date(log.date).toLocaleString()}
+ ${log.category ? `${log.category}` : ''}
+
+
+
+ ${log.tags.map(tag => `${tag}`).join('')}
+
+
${log.content.replace(/\n/g, '
')}
+ `;
+ logEntries.appendChild(logElement);
+ });
+ }
+
+ editLog(id) {
+ const log = this.logs.find(log => log.id === id);
+ if (log) {
+ document.getElementById('logDate').value = log.date;
+ document.getElementById('logCategory').value = log.category;
+ document.getElementById('logTags').value = log.tags.join(', ');
+ document.getElementById('logContent').value = log.content;
+ document.getElementById('logForm').classList.remove('hidden');
+ this.deleteLog(id);
+ }
+ }
+
+ deleteLog(id) {
+ if (confirm('Are you sure you want to delete this log?')) {
+ this.logs = this.logs.filter(log => log.id !== id);
+ this.updateLocalStorage();
+ this.renderLogs();
+ }
+ }
+
+ filterLogs() {
+ const searchTerm = document.getElementById('searchInput').value.toLowerCase();
+ const categoryFilter = document.getElementById('filterCategory').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.renderFilteredLogs(filtered);
+ }
+
+ renderFilteredLogs(filtered) {
+ const logEntries = document.getElementById('logEntries');
+ logEntries.innerHTML = '';
+ filtered.forEach(log => {
+ // Reuse the same rendering logic as in renderLogs()
+ const logElement = document.createElement('div');
+ logElement.className = 'log-entry';
+ // ... (same innerHTML content as in renderLogs)
+ logEntries.appendChild(logElement);
+ });
+ }
+
+ toggleSort() {
+ this.logs.reverse();
+ this.renderLogs();
+ }
+
+ exportLogs() {
+ const exportData = JSON.stringify(this.logs, null, 2);
+ const blob = new Blob([exportData], { type: 'application/json' });
+ const url = URL.createObjectURL(blob);
+ const a = document.createElement('a');
+ a.href = url;
+ a.download = `work-logs-${new Date().toISOString().slice(0,10)}.json`;
+ document.body.appendChild(a);
+ a.click();
+ document.body.removeChild(a);
+ URL.revokeObjectURL(url);
+ }
+ }
+
+ const workLogManager = new WorkLogManager();