Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate home page recently played date and time combos to twig #475

Merged
merged 3 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 19 additions & 30 deletions ui/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Zookeeper Online
*
* @author Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2022 Jim Mason <[email protected]>
* @copyright Copyright (C) 1997-2024 Jim Mason <[email protected]>
* @link https://zookeeper.ibinx.com/
* @license GPL-3.0
*
Expand Down Expand Up @@ -47,46 +47,35 @@ public function recentSpins() {
}

protected function makeDatePicker() {
$now = new \DateTime();
$result = "<option value='" . $now->format("Y-m-d") . "'>Today</option>";
$now->modify("-1 days");
$result .= "<option value='" . $now->format("Y-m-d") . "'>Yesterday</option>";
for($i=0; $i<5; $i++) {
$now->modify("-1 days");
$result .= "<option value='" . $now->format("Y-m-d") . "'>" .
$now->format("D M j") . "</option>";
}
$result = array_map(function($i) {
return (new \DateTime())->modify("-$i days");
}, range(0, 6));

return $result;
$this->addVar("dates", $result);
}

protected function makeTimePicker($date=null) {
$now = new \DateTime();
if(!$date || $now->format("Y-m-d") == $date) {
// today
$result = "<option value='now'>Recently Played</option>";
$hour = (int)$now->format("H");
} else {
$result = "<option value='23:59:59'>Before midnight</option>";
$hour = 23;
}
$initial = -1;
} else
$initial = $hour = 23;

$result = array_filter(range(1, $hour), function($i) {
return $i % 3 === 0;
});

do {
if($hour % 3) continue;
$h = sprintf("%02d", $hour);
$ampm = $h >= 12?"pm":"am";
$hx = $h > 12?$hour-12:$hour;
$dh = $h == 12?"noon":($hx.$ampm);
$result .= "<option value='$h:00:00'>Before $dh</option>";
} while(--$hour > 0);
$result[] = $initial;

return $result;
$this->addVar("times", array_reverse($result));
}

public function getTimes() {
$retVal = [];
$retVal['times'] = $this->makeTimePicker($_REQUEST["date"] ?? null);
echo json_encode($retVal);
$this->setTemplate('onnow.html');
$this->makeTimePicker($_REQUEST["date"] ?? null);
echo json_encode([ "times" => $this->render('time') ]);
}

public function emitHome() {
Expand All @@ -102,8 +91,8 @@ public function emitHome() {

private function emitRecentlyPlayed() {
$this->addVar('discogs', true);
$this->addVar('datepicker', $this->makeDatePicker());
$this->addVar('timepicker', $this->makeTimePicker());
$this->makeDatePicker();
$this->makeTimePicker();
}

private function emitTopPlays($numweeks=1, $limit=10) {
Expand Down
24 changes: 22 additions & 2 deletions ui/templates/default/onnow.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,28 @@
<h3>Recently Played on {{ app.station }}</h3>
<div>
<form>
<select id='date'>{{ datepicker | raw }}</select>
<select id='time'>{{ timepicker | raw }}</select>
<select id='date'>
<option value="{{ dates[0] | date("Y-m-d") }}">Today</option>
<option value="{{ dates[1] | date("Y-m-d") }}">Yesterday</option>
{% for day in dates[2:] %}
<option value="{{ day | date("Y-m-d") }}">{{ day | date("D M j") }}</option>
{% endfor %}
</select>
<select id='time'>
{% block time %}
{% if times[0] == -1 %}
<option value='now'>Recently Played</option>
{% else %}
<option value='23:59:59'>Before midnight</option>
{% endif %}
{% for hour in times[1:] %}
{%~ set ampm = hour >= 12 ? "pm" : "am" %}
{%~ set hx = hour > 12 ? hour - 12 : hour %}
{%~ set dh = hour == 12 ? "noon" : hx ~ ampm %}
<option value='{{ "%02d" | format(hour) }}:00:00'>Before {{ dh }}</option>
{% endfor %}
{% endblock %}
</select>
</form>
</div>
</div>
Expand Down
Loading