refactor: group internship commits by date and update UI to a grid layout

This commit is contained in:
Ümit Tunç
2026-06-06 01:10:13 +03:00
parent 080c39ac88
commit db60909348
2 changed files with 77 additions and 39 deletions
+23 -11
View File
@@ -268,22 +268,34 @@ class CareerController extends Controller
// Sort commits chronological (ascending)
$commits = array_reverse($commits);
// Group commits by date (YYYY-MM-DD)
$grouped = [];
foreach ($commits as $c) {
$dateStr = $c['commit']['author']['date'] ?? '';
if ($dateStr) {
$dateOnly = \Carbon\Carbon::parse($dateStr)->format('Y-m-d');
$grouped[$dateOnly][] = $c;
}
}
// Sort dates chronological (ascending)
ksort($grouped);
// Generate Markdown content
$md = "# Staj Günlüğü - " . $intern->name . "\n";
$md .= "Depo: https://github.com/{$owner}/{$repoName}\n\n";
$day = 1;
foreach ($commits as $c) {
$message = $c['commit']['message'] ?? '';
$dateStr = $c['commit']['author']['date'] ?? '';
$date = $dateStr ? \Carbon\Carbon::parse($dateStr)->format('d.m.Y H:i') : '';
$hash = substr($c['sha'] ?? '', 0, 7);
$md .= "## {$day}. Gün\n";
$md .= "- **Tarih:** {$date}\n";
$md .= "- **Commit:** `{$hash}`\n";
$md .= "- **Mesaj:** {$message}\n\n";
foreach ($grouped as $date => $dayCommits) {
$formattedDate = \Carbon\Carbon::parse($date)->format('d.m.Y');
$md .= "## {$day}. Gün ({$formattedDate})\n";
foreach ($dayCommits as $c) {
$message = trim($c['commit']['message'] ?? '');
$time = \Carbon\Carbon::parse($c['commit']['author']['date'] ?? '')->format('H:i');
$hash = substr($c['sha'] ?? '', 0, 7);
$md .= "- [{$time}] `{$hash}`: {$message}\n";
}
$md .= "\n";
$day++;
}
@@ -394,7 +394,7 @@
Henüz hiç commit bulunamadı veya deponuz tanımlanmadı. Lütfen deponuzu tanımlayın ve commitlerinizi gönderin.
</div>
<div id="commits-timeline" class="hidden relative border-l-2 border-slate-100 ml-4 pl-6 space-y-6">
<div id="commits-timeline" class="hidden grid grid-cols-1 sm:grid-cols-2 gap-6">
<!-- Loaded dynamically by JS -->
</div>
@@ -513,41 +513,67 @@
// Reverse to show in chronological order (Day 1, Day 2...)
commits.reverse();
// Group commits by date (YYYY-MM-DD)
const grouped = {};
commits.forEach(item => {
const dateStr = item.commit.author.date;
if (dateStr) {
const dateOnly = dateStr.substring(0, 10); // "YYYY-MM-DD"
if (!grouped[dateOnly]) {
grouped[dateOnly] = [];
}
grouped[dateOnly].push(item);
}
});
const sortedDates = Object.keys(grouped).sort();
timelineEl.classList.remove('hidden');
commits.forEach((item, index) => {
sortedDates.forEach((date, index) => {
const dayNum = index + 1;
const message = item.commit.message;
const authorDate = new Date(item.commit.author.date);
const formattedDate = authorDate.toLocaleDateString('tr-TR', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit'
});
const shaShort = item.sha.substring(0, 7);
const commitUrl = item.html_url;
const dayCommits = grouped[date];
// Format date as DD.MM.YYYY
const dateParts = date.split('-');
const formattedDate = `${dateParts[2]}.${dateParts[1]}.${dateParts[0]}`;
const commitHtml = `
<div class="relative pl-6 pb-6 last:pb-0">
<div class="absolute -left-[7px] top-1.5 w-3 h-3 rounded-full bg-blue-600 shadow-sm ring-4 ring-white"></div>
<div class="bg-slate-50/60 rounded-2xl p-4 border border-slate-100 hover:border-slate-200 hover:bg-slate-50 transition-all">
<div class="flex flex-wrap items-center justify-between gap-2 mb-2">
<span class="text-xs uppercase font-extrabold tracking-wider text-blue-600 bg-blue-50 px-2.5 py-1 rounded-full">${dayNum}. Gün</span>
<div class="flex items-center gap-2">
<span class="text-xs text-slate-400 font-semibold">${formattedDate}</span>
<a href="${commitUrl}" target="_blank" class="text-xs font-mono font-bold text-slate-500 hover:text-blue-600 bg-white px-2 py-0.5 rounded border border-slate-200/60 transition-colors flex items-center gap-1">
<i class="uil uil-external-link-alt text-[10px]"></i>
${shaShort}
</a>
</div>
// Generate commits list HTML
let commitsListHtml = '';
dayCommits.forEach(c => {
const message = c.commit.message;
const authorDate = new Date(c.commit.author.date);
const timeStr = authorDate.toLocaleTimeString('tr-TR', { hour: '2-digit', minute: '2-digit' });
const shaShort = c.sha.substring(0, 7);
const commitUrl = c.html_url;
commitsListHtml += `
<div class="p-3 bg-white rounded-xl border border-slate-100 hover:border-slate-200 transition-all shadow-sm">
<div class="flex items-center justify-between gap-2 mb-1.5">
<span class="text-[10px] font-bold text-slate-400"><i class="uil uil-clock"></i> ${timeStr}</span>
<a href="${commitUrl}" target="_blank" class="text-[10px] font-mono font-bold text-slate-500 hover:text-blue-600 bg-slate-50 px-2 py-0.5 rounded border border-slate-100 transition-colors">
${shaShort}
</a>
</div>
<p class="text-xs font-bold text-slate-700 leading-relaxed whitespace-pre-line">${escapeHtml(message)}</p>
</div>
`;
});
const dayCardHtml = `
<div class="bg-slate-50/60 border border-slate-100/80 hover:border-blue-100 hover:bg-blue-50/10 rounded-2xl p-5 transition-all flex flex-col justify-between">
<div>
<div class="flex items-center justify-between mb-4 border-b border-slate-100 pb-2.5">
<span class="text-sm font-extrabold text-blue-600 bg-blue-50/60 px-3 py-1 rounded-full">${dayNum}. Gün</span>
<span class="text-xs font-bold text-slate-400"><i class="uil uil-calendar-alt"></i> ${formattedDate}</span>
</div>
<div class="space-y-3">
${commitsListHtml}
</div>
<p class="text-sm font-bold text-slate-700 whitespace-pre-line leading-relaxed">${escapeHtml(message)}</p>
</div>
</div>
`;
timelineEl.insertAdjacentHTML('beforeend', commitHtml);
timelineEl.insertAdjacentHTML('beforeend', dayCardHtml);
});
})
.catch(err => {