Target: ${goal.targetMetricValue} ${unitDisplay} ${goal.targetDate ? `by ${goal.targetDate}` : ''}
Current Progress: ${goal.currentProgressValue.toFixed(1)} ${unitDisplay} (${progressPercent.toFixed(1)}%)
${progressPercent.toFixed(1)}%
Activity Log:
`;
const logTable = document.createElement('table');
logTable.className = 'pgpt-data-table';
logTable.innerHTML = `
| Date | Activity/Milestone | Progress (${unitDisplay}) | Time Spent | Notes | Self-Assessment |
|---|
`;
const logTbody = logTable.getElementsByTagName('tbody')[0];
const logsForThisGoal = pgpt_progressLogs.filter(log => log.goalId == viewGoalId).sort((a,b) => new Date(b.date) - new Date(a.date));
if (logsForThisGoal.length === 0) {
logTbody.innerHTML = `
| No activities logged for this goal yet. |
`;
} else {
logsForThisGoal.forEach(log => {
const row = logTbody.insertRow();
row.insertCell().textContent = log.date;
row.insertCell().textContent = log.activity;
row.insertCell().textContent = log.quantitativeProgress;
row.insertCell().textContent = pgpt_formatMinutesToHHMM(log.timeSpentMinutes);
row.insertCell().textContent = log.notes || '-';
row.insertCell().textContent = log.selfAssessment ? `${log.selfAssessment}/5` : 'N/A';
});
}
container.appendChild(logTable);
}
}
// --- PDF Download ---
function pgpt_downloadPDF() {
const viewGoalId = document.getElementById('pgpt_selectGoalForProgressView').value;
if (!viewGoalId) { alert("Select a goal or 'Overall Summary' to generate PDF."); return; }
const doc = new jsPDF();
const primaryColorPDF = getComputedStyle(document.documentElement).getPropertyValue('--primary-color').trim();
const textColorPDF = getComputedStyle(document.documentElement).getPropertyValue('--text-color').trim();
const whiteColorPDF = '#FFFFFF';
doc.setFontSize(18); doc.setTextColor(primaryColorPDF);
doc.text("Personal Growth Progress Report", 14, 20);
doc.setFontSize(10); doc.setTextColor(textColorPDF);
doc.text(`Report Date: ${PGPT_CONTEXT_DATE_STR}`, 14, 28);
doc.text(`Generated On: ${PGPT_GENERATED_ON_STRING}`, 14, 33);
let currentY = 45;
if (viewGoalId === "overall") {
doc.setFontSize(14); doc.setFont(undefined, 'bold'); doc.setTextColor(primaryColorPDF);
doc.text("Overall Goals Summary", 14, currentY); currentY += 10;
const overallCols = ["Goal Name", "Target", "Current Progress", "% Complete", "Target Date"];
const overallRows = pgpt_growthGoals.map(goal => {
const unit = goal.targetUnit === 'Custom' ? goal.customUnitName : goal.targetUnit;
const perc = goal.targetMetricValue > 0 ? (goal.currentProgressValue / goal.targetMetricValue * 100) : 0;
return [
goal.name,
`${goal.targetMetricValue} ${unit}`,
`${goal.currentProgressValue.toFixed(1)} ${unit}`,
`${perc.toFixed(1)}%`,
goal.targetDate || 'N/A'
];
});
if (overallRows.length > 0) {
doc.autoTable({ head: [overallCols], body: overallRows, startY: currentY, theme: 'grid', headStyles: {fillColor: primaryColorPDF, textColor: whiteColorPDF, fontSize:9}, styles:{fontSize:8}});
} else {
doc.setFontSize(10); doc.setFont(undefined, 'normal'); doc.setTextColor(textColorPDF);
doc.text("No goals defined to summarize.", 16, currentY);
}
} else {
const goal = pgpt_growthGoals.find(g => g.id == viewGoalId);
if (!goal) { alert("Selected goal not found for PDF."); return; }
const unit = goal.targetUnit === 'Custom' ? goal.customUnitName : goal.targetUnit;
const progressPercent = goal.targetMetricValue > 0 ? (goal.currentProgressValue / goal.targetMetricValue * 100) : 0;
doc.setFontSize(14); doc.setFont(undefined, 'bold'); doc.setTextColor(primaryColorPDF);
doc.text(`Progress for: ${goal.name}`, 14, currentY); currentY += 10;
doc.setFontSize(10); doc.setFont(undefined, 'normal'); doc.setTextColor(textColorPDF);
if(goal.description) { doc.text(`Description: ${goal.description}`, 16, currentY); currentY +=5; }
doc.text(`Target: ${goal.targetMetricValue} ${unit} ${goal.targetDate ? `by ${goal.targetDate}` : ''}`, 16, currentY); currentY += 5;
doc.text(`Current Progress: ${goal.currentProgressValue.toFixed(1)} ${unit} (${progressPercent.toFixed(1)}%)`, 16, currentY); currentY += 10;
doc.setFontSize(12); doc.setFont(undefined, 'bold'); doc.setTextColor(primaryColorPDF);
doc.text("Activity Log:", 14, currentY); currentY +=7;
const logs = pgpt_progressLogs.filter(l => l.goalId == viewGoalId).sort((a,b) => new Date(a.date) - new Date(b.date));
const logCols = ["Date", "Activity/Milestone", `Progress (${unit})`, "Time Spent", "Notes", "Self-Assessment"];
const logRows = logs.map(l => [
l.date, l.activity, l.quantitativeProgress, pgpt_formatMinutesToHHMM(l.timeSpentMinutes), l.notes || '-', l.selfAssessment ? `${l.selfAssessment}/5` : 'N/A'
]);
if (logRows.length > 0) {
doc.autoTable({ head: [logCols], body: logRows, startY: currentY, theme: 'grid', headStyles: {fillColor: primaryColorPDF, textColor: whiteColorPDF, fontSize:9}, styles:{fontSize:8, cellPadding:1.5}, columnStyles: { 2: {halign:'right'}, 3:{halign:'center'}, 5:{halign:'center'}} });
} else {
doc.setFontSize(10); doc.setFont(undefined, 'normal'); doc.setTextColor(textColorPDF);
doc.text("No activities logged for this goal.", 16, currentY);
}
}
doc.save(`Personal_Growth_Progress_${viewGoalId === 'overall' ? 'Overall' : pgpt_growthGoals.find(g=>g.id==viewGoalId)?.name.replace(/ /g,'_') || 'Goal'}_${PGPT_CONTEXT_DATE_STR}.pdf`);
}