From 7e25e65336ed3176ec690c4dac621738533113d8 Mon Sep 17 00:00:00 2001 From: Andy Heathershaw Date: Mon, 6 Aug 2018 14:02:45 +0100 Subject: [PATCH] #19: The user profile grid is now much more Github-like --- .../Controllers/Gallery/UserController.php | 28 +++++ resources/assets/css/gallery.css | 30 +++++- .../user_profile_activity_grid.blade.php | 100 ++++++++++++++++-- 3 files changed, 147 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/Gallery/UserController.php b/app/Http/Controllers/Gallery/UserController.php index 31dc1dd..014420b 100644 --- a/app/Http/Controllers/Gallery/UserController.php +++ b/app/Http/Controllers/Gallery/UserController.php @@ -33,11 +33,14 @@ class UserController extends Controller $cameras = $this->getCamerasUsedInAlbums($albumIDs); $activity = $this->getActivityDatesInAlbums($albumIDs); + $daysInMonth = $this->getDaysInMonths(); + return Theme::render('gallery.user_profile', [ 'activity_taken' => $this->constructActivityGrid($activity['taken']), 'activity_uploaded' => $this->constructActivityGrid($activity['uploaded']), 'albums' => $albums, 'cameras' => $cameras, + 'month_days' => $daysInMonth, 'user' => $user ]); } @@ -170,4 +173,29 @@ class UserController extends Controller ->orderBy('camera_software') ->get(); } + + private function getDaysInMonths() + { + $results = []; + + $lastYearFrom = new \DateTime(); + $lastYearFrom->sub(new \DateInterval('P1Y')); + $lastYearFrom->sub(new \DateInterval(sprintf('P%dD', $lastYearFrom->format('d') - 1))); + + $today = new \DateTime(); + $current = clone $lastYearFrom; + + while ($current < $today) + { + $year = intval($current->format('Y')); + $month = intval($current->format('m')); + + $daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year); + $results[$year][$current->format('M')] = $daysInMonth; + + $current->add(new \DateInterval('P1M')); + } + + return $results; + } } \ No newline at end of file diff --git a/resources/assets/css/gallery.css b/resources/assets/css/gallery.css index e17da91..e25d6b9 100644 --- a/resources/assets/css/gallery.css +++ b/resources/assets/css/gallery.css @@ -2,13 +2,41 @@ font-size: smaller; } -.activity-grid th,td { +.activity-grid th, +.activity-grid td { padding: 5px !important; text-align: center; } .activity-grid td { color: #fff; + height: 20px; +} + +.activity-grid .has-activity { + background-color: #1e90ff; +} + +.activity-grid .invalid-date { + background-color: #e5e5e5; +} + +.activity-grid .no-activity { + background-color: #fff; +} + +.activity-grid th:first-child, +.activity-grid td:first-child { + border-left: 1px solid #dee2e6; +} + +.activity-grid th, +.activity-grid td { + border-right: 1px solid #dee2e6; +} + +.activity-grid tr:last-child td { + border-bottom: 1px solid #dee2e6; } .album-slideshow-container #image-preview { diff --git a/resources/views/themes/base/partials/user_profile_activity_grid.blade.php b/resources/views/themes/base/partials/user_profile_activity_grid.blade.php index 41e479c..1a77242 100644 --- a/resources/views/themes/base/partials/user_profile_activity_grid.blade.php +++ b/resources/views/themes/base/partials/user_profile_activity_grid.blade.php @@ -1,26 +1,106 @@ - + @php + $i = 0; + @endphp @foreach ($activity as $year => $months) @foreach ($months as $month => $dates) - + + @php + $i++ + @endphp @endforeach @endforeach - @for ($i = 1; $i <= 31; $i++) + {{-- Output a table containing columns for days 1-7, 8-14, 15-21, 22-28, 29-31 (if applicable) --}} + @for ($row = 0; $row < 7; $row++) - @foreach ($activity as $year => $months) @foreach ($months as $month => $dates) - @if (isset($dates[$i]) && $dates[$i] > 0) - - @elseif (isset($dates[$i]) && $dates[$i] == 0) - - @else - + @php + $day1 = $row + 1; + $day2 = $row + 8; + $day3 = $row + 15; + $day4 = $row + 22; + $day5 = $row + 29; + @endphp + + @if (ceil($month_days[$year][$month] / 7) >= 1) + @if ($day1 <= $month_days[$year][$month]) + @if (isset($dates[$day1]) && $dates[$day1] > 0) + + @else + + @endif + @else + + @endif + @endif + + @if (ceil($month_days[$year][$month] / 7) >= 2) + @if ($day2 <= $month_days[$year][$month]) + @if (isset($dates[$day2]) && $dates[$day2] > 0) + + @else + + @endif + @else + + @endif + @endif + + @if (ceil($month_days[$year][$month] / 7) >= 3) + @if ($day3 <= $month_days[$year][$month]) + @if (isset($dates[$day3]) && $dates[$day3] > 0) + + @else + + @endif + @else + + @endif + @endif + + @if (ceil($month_days[$year][$month] / 7) >= 4) + @if ($day4 <= $month_days[$year][$month]) + @if (isset($dates[$day4]) && $dates[$day4] > 0) + + @else + + @endif + @else + + @endif + @endif + + @if (ceil($month_days[$year][$month] / 7) >= 5) + @if ($day5 <= $month_days[$year][$month]) + @if (isset($dates[$day5]) && $dates[$day5] > 0) + + @else + + @endif + @else + + @endif @endif @endforeach @endforeach
{{ $month }}@if ($month == 'Jan')
{{ $year }}@endif
{{ $month }}@if ($i == 0 || $i == 12 || $month == 'Jan')
{{ $year }}@endif
{{ $i }}{{ $dates[$i] }}   + + + + + + + + + + + + + + +