From 72c1f03f41c88ce9002139cbc8aabe4f440b8f2f Mon Sep 17 00:00:00 2001 From: Cameron Ball Date: Sat, 19 Jan 2019 16:49:38 +0800 Subject: [PATCH] Report aesthetics --- src/bootstrap.php | 30 +++++++++++++++++------------- src/report.php | 52 +++++++++++++++++++++++++++++++++++----------------- 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/src/bootstrap.php b/src/bootstrap.php index 332715d..097af20 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -2,7 +2,7 @@ require_once('common.php'); -function tabs($id, $headings, $contents, $justify = false) { +function tabs($id, $headings, $contents, $activeHeading = null, $justify = false) { $slug = function($string) { return str_replace(' ', '', $string); }; @@ -12,35 +12,35 @@ function tabs($id, $headings, $contents, $justify = false) { }; $content = function($content, $id, $active = false) { - return '
' . $content . '
'; + return '
' . $content . '
'; }; $headingAndContent = zipWith(function($heading, $content) { return ['heading' => $heading, 'content' => $content]; }, $headings, $contents); - $smushenated = array_reduce($headingAndContent, function($c, $v) use ($slug, $heading, $content, $id) { + $smushenated = array_reduce($headingAndContent, function($c, $v) use ($slug, $heading, $content, $id, $activeHeading) { return [ - 'headings' => $c['headings'] . $heading($v['heading'], $id . $slug($v['heading']), !$c['headings']), - 'contents' => $c['contents'] . $content($v['content'], $id . $slug($v['heading']), !$c['contents']) + 'headings' => $c['headings'] . $heading($v['heading'], $id . $slug($v['heading']), $v['heading'] == $activeHeading), + 'contents' => $c['contents'] . $content($v['content'], $id . $slug($v['heading']), $v['heading'] == $activeHeading) ]; }, ['headings' => '', 'contents' => '']); return '
' . $smushenated['contents'] . '
'; } -function accordion($id, $headings, $contents) { +function accordion($id, $headings, $contents, $activeHeading = null) { $slug = function($string) { return str_replace(' ', '', strtolower($string)); }; - $a = zipWith(function($heading, $content) use ($slug, $id) { + $a = zipWith(function($heading, $content) use ($slug, $id, $activeHeading) { return '
' . '' . - '
' . + '
' . '
' . $content . '
'; @@ -66,14 +66,15 @@ function table($rows) { function doIt() { $years = array_reverse(range(2018, (int)(new DateTimeImmutable())->format('Y'))); + $today = turnBackTime(new DateTimeImmutable); return tabs( 'year', $years, - map(function($year) { + map(function($year) use ($today) { return accordion( $year, map(∘('strToUpper', getMonthName))(range(1,12)), - map(function($month) use ($year){ + map(function($month) use ($year, $today){ $mondays = range(1, count(getMondaysForMonth($year, $month))); return tabs( $year . $month, @@ -81,12 +82,15 @@ function doIt() { map(function($num) use ($month, $year) { $completedTasksFile = getFilePathForWeek($year, $month, $num, PATH_TO_TASKS_FILES); $completedTasks = file_exists($completedTasksFile) ? lines(trim(file_get_contents($completedTasksFile))) : []; - return table(map(function($task) use($completedTasks) { return [getString($task), in_array($task, $completedTasks) ? '👍😄' : '😱👎']; })(getTasksForTheWeek($year, $month, $num, require 'taskMatrix.php'))); - })($mondays) + return table(map(function($task) use($completedTasks) { return [getString($task), in_array($task, $completedTasks) ? '👍😄' : '👎😱']; })(getTasksForTheWeek($year, $month, $num, require 'taskMatrix.php'))); + })($mondays), + ($year == $today->year && $month == $today->month) ? 'Week ' . $today->weekNum : 'Week 1' ); - })(range(1,12)) + })(range(1,12)), + ($year == $today->year) ? strToUpper(getMonthName($today->month)) : 'JANUARY' ); })($years), + $today->year, true ); } diff --git a/src/report.php b/src/report.php index fc1faa6..83c76c8 100644 --- a/src/report.php +++ b/src/report.php @@ -14,28 +14,46 @@ -
-

The Onion Report

-
-
-
-
+
+

The Onion Report

+
+
+
+
+
+
-- 2.11.0