New Gratitude Entry

Loading prompt...
Existing tags:

Journal Log & Insights

Most Frequent Tags (in current view):

No entries to analyze.

Journal Entries:

    Manage Tags/Categories

    Add New Tag

    Your Custom Tags:

      ${entry.tags && entry.tags.length > 0 ? `
      ${entry.tags.map(t => `${wgj_titleCase(t)}`).join(' ')}
      ` : ''} `; listEl.appendChild(itemDiv); }); wgj_updateTagFrequencyDisplay(filteredEntries); } function wgj_resetFiltersAndSearch(renderLog = true) { document.getElementById('wgj-filterStartDate').value = ''; document.getElementById('wgj-filterEndDate').value = ''; document.getElementById('wgj-filterTags').value = ''; document.getElementById('wgj-filterKeyword').value = ''; wgj_currentLogPage = 1; if(renderLog) wgj_renderJournalLog(); } function wgj_loadMoreLogEntries() { wgj_currentLogPage++; wgj_renderJournalLog(); } function wgj_editEntry(id) { const entry = wgj_entries.find(e => e.id === id); if (!entry) return; const newEntryTabButton = document.querySelector(`.wgj-tab-button[onclick*="'wgj-newEntryTab'"]`); wgj_openTab({currentTarget: newEntryTabButton}, 'wgj-newEntryTab'); document.getElementById('wgj-entryId').value = entry.id; document.getElementById('wgj-entryDate').value = entry.date; document.getElementById('wgj-gratitudeStatement').value = entry.statement; document.getElementById('wgj-entryTags').value = (entry.tags || []).map(t => wgj_titleCase(t)).join(', '); document.getElementById('wgj-feelingIntensity').value = entry.intensity; document.getElementById('wgj-feelingIntensityValue').textContent = entry.intensity; document.getElementById('wgj-cancelEntryEditBtn').style.display = 'inline-block'; } function wgj_deleteEntry(id) { if (confirm("Are you sure you want to delete this gratitude entry?")) { wgj_entries = wgj_entries.filter(e => e.id !== id); wgj_saveData(); wgj_renderJournalLog(); // Re-render current view } } function wgj_showRandomEntry() { const displayEl = document.getElementById('wgj-randomEntryDisplay'); if (wgj_entries.length === 0) { displayEl.innerHTML = '

      No entries in your journal yet to display.

      '; displayEl.style.display = 'block'; return; } const randomIndex = Math.floor(Math.random() * wgj_entries.length); const entry = wgj_entries[randomIndex]; displayEl.style.borderLeftColor = `#${(entry.intensity * 50).toString(16).padStart(2,'0')}B74D`; displayEl.innerHTML = `

      ${entry.statement.replace(/\n/g, '
      ')}

      ${entry.tags && entry.tags.length > 0 ? `
      ${entry.tags.map(t => `${wgj_titleCase(t)}`).join(' ')}
      ` : ''} `; displayEl.style.display = 'block'; } function wgj_updateTagFrequencyDisplay(entriesToAnalyze) { const tagFreq = {}; entriesToAnalyze.forEach(entry => { (entry.tags || []).forEach(tag => { const lowerTag = tag.toLowerCase(); tagFreq[lowerTag] = (tagFreq[lowerTag] || 0) + 1; }); }); const sortedTags = Object.entries(tagFreq).sort(([,a],[,b]) => b-a).slice(0, 10); // Top 10 const displayEl = document.getElementById('wgj-tagFrequencyDisplay'); if (sortedTags.length === 0) { displayEl.innerHTML = 'No tags used in the current view to analyze.'; return; } displayEl.innerHTML = sortedTags.map(([tag, count]) => `${wgj_titleCase(tag)} (${count})` ).join(' '); } // --- Manage Tags Tab --- document.getElementById('wgj-tagManagementForm').onsubmit = (e) => { e.preventDefault(); const tagName = document.getElementById('wgj-newTagName').value.trim(); const lowerTagName = tagName.toLowerCase(); if (!tagName) { alert("Tag name cannot be empty."); return; } if (wgj_tags.some(t => t.name.toLowerCase() === lowerTagName)) { alert("This tag already exists."); return; } wgj_tags.push({ id: wgj_generateId(), name: wgj_titleCase(tagName), isDefault: false }); wgj_saveData(); wgj_renderCustomTagsList(); wgj_displayExistingTagsPreview(); // Refresh tag previews in new entry tab document.getElementById('wgj-tagManagementForm').reset(); }; function wgj_renderCustomTagsList() { const listEl = document.getElementById('wgj-customTagsList'); listEl.innerHTML = ''; const customTags = wgj_tags.filter(t => !t.isDefault); if (customTags.length === 0) { listEl.innerHTML = '
    • No custom tags added yet. Default tags are not listed here.
    • '; return; } customTags.forEach(tag => { const li = document.createElement('li'); li.innerHTML = `${wgj_titleCase(tag.name)}
      `; listEl.appendChild(li); }); } function wgj_deleteCustomTag(tagId) { // Check if tag is used in any entries const tagToDelete = wgj_tags.find(t => t.id === tagId); if (!tagToDelete) return; const isUsed = wgj_entries.some(entry => (entry.tags || []).map(t => t.toLowerCase()).includes(tagToDelete.name.toLowerCase())); if (isUsed) { if (!confirm(`Tag "${wgj_titleCase(tagToDelete.name)}" is used in journal entries. Deleting it will remove it from those entries. Continue?`)) return; // Remove tag from entries wgj_entries.forEach(entry => { entry.tags = (entry.tags || []).filter(t => t.toLowerCase() !== tagToDelete.name.toLowerCase()); }); } else { if (!confirm(`Delete tag "${wgj_titleCase(tagToDelete.name)}"?`)) return; } wgj_tags = wgj_tags.filter(t => t.id !== tagId); wgj_saveData(); wgj_renderCustomTagsList(); wgj_displayExistingTagsPreview(); wgj_renderJournalLog(); // Refresh log as tags might have changed in entries } // --- PDF Download --- document.getElementById('wgj-downloadPdfBtn').onclick = async () => { const range = { // Get range from filter inputs for PDF start: document.getElementById('wgj-filterStartDate').value, end: document.getElementById('wgj-filterEndDate').value }; const filterTagsRawPdf = wgj_parseTags(document.getElementById('wgj-filterTags').value); const filterKeywordPdf = document.getElementById('wgj-filterKeyword').value.toLowerCase(); let entriesForPdf = wgj_entries.filter(entry => { let dateMatch = true; if (range.start && entry.date < range.start) dateMatch = false; if (range.end && entry.date > range.end) dateMatch = false; let tagMatch = true; if (filterTagsRawPdf.length > 0) { tagMatch = filterTagsRawPdf.every(ft => (entry.tags || []).some(et => et.toLowerCase().includes(ft))); } let keywordMatch = true; if (filterKeywordPdf) { keywordMatch = entry.statement.toLowerCase().includes(filterKeywordPdf); } return dateMatch && tagMatch && keywordMatch; }); if (entriesForPdf.length === 0) { alert("No entries match current filters for PDF export."); return; } const { jsPDF } = window.jspdf; const pdf = new jsPDF('p', 'mm', 'a4'); let currentY = 15; const margin = 15; const contentWidth = pdf.internal.pageSize.getWidth() - 2*margin; pdf.setFontSize(18); pdf.setTextColor('#FFB74D'); pdf.text("My Work Gratitude Journal", pdf.internal.pageSize.getWidth() / 2, currentY, { align: 'center' }); currentY += 8; pdf.setFontSize(10); pdf.setTextColor('#A1887F'); let periodText = "All Logged Entries"; if(range.start && range.end) periodText = `Entries from ${new Date(range.start+"T00:00:00").toLocaleDateString()} to ${new Date(range.end+"T00:00:00").toLocaleDateString()}`; else if (range.start) periodText = `Entries from ${new Date(range.start+"T00:00:00").toLocaleDateString()}`; else if (range.end) periodText = `Entries up to ${new Date(range.end+"T00:00:00").toLocaleDateString()}`; if (filterTagsRawPdf.length > 0) periodText += ` | Tags: ${filterTagsRawPdf.map(t => wgj_titleCase(t)).join(', ')}`; if (filterKeywordPdf) periodText += ` | Keyword: "${filterKeywordPdf}"`; pdf.text(periodText, pdf.internal.pageSize.getWidth() / 2, currentY, { align: 'center'}); currentY += 10; entriesForPdf.forEach(entry => { if (currentY > pdf.internal.pageSize.getHeight() - 40) { pdf.addPage(); currentY = margin; } // Check space for new entry pdf.setFontSize(9); pdf.setTextColor('#BF8F00'); // Darker yellow for meta pdf.text(`${new Date(entry.date+"T00:00:00").toLocaleDateString()} | Intensity: ${entry.intensity}/5 | Tags: ${(entry.tags || []).map(t=>wgj_titleCase(t)).join(', ') || 'None'}`, margin, currentY); currentY += 5; pdf.setFontSize(10); pdf.setTextColor('#5D4037'); const statementLines = pdf.splitTextToSize(entry.statement, contentWidth); pdf.text(statementLines, margin, currentY); currentY += (statementLines.length * 5) + 4; // Line height approx 5mm pdf.setDrawColor(255, 224, 178); pdf.line(margin, currentY, contentWidth + margin, currentY); // Separator line currentY += 4; }); pdf.save(`Work_Gratitude_Journal_${new Date().toISOString().slice(0,10)}.pdf`); }; // --- Initial Load --- document.addEventListener('DOMContentLoaded', () => { wgj_openTab(null, wgj_tabs[0]); const firstTabButton = document.querySelector(`.wgj-tab-button[onclick*="'${wgj_tabs[0]}'"]`); if (firstTabButton) firstTabButton.classList.add('active'); else console.error("First tab button not found for initial activation."); wgj_updateNavButtons(); });
      Scroll to Top