Migrate v3 data; WIP on journal items
This commit is contained in:
64
src/public/components/journal-items.php
Normal file
64
src/public/components/journal-items.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use BitBadger\PDODocument\{Custom, Query};
|
||||
use BitBadger\PDODocument\Mapper\DocumentMapper;
|
||||
use MyPrayerJournal\{Auth,History,Layout,Request,Table};
|
||||
|
||||
require '../../start.php';
|
||||
|
||||
Auth::requireUser(false);
|
||||
bare_head();
|
||||
|
||||
$reqs = Custom::list(
|
||||
Query::selectFromTable(Table::REQUEST) . " WHERE data->>'userId' = :userId AND data->>'$.history[0].action' <> 'Answered'",
|
||||
[':userId' => Auth::user()['sub']], new DocumentMapper(Request::class));
|
||||
|
||||
if ($reqs->hasItems()) { ?>
|
||||
<section id=journalItems class="row row-cols-1 row-cols-md-2 row-cols-lg-3 row-cols-xl-4 g-3" hx-target=this
|
||||
hx-swap=outerHTML aria-label="Prayer Requests"><?php
|
||||
$spacer = '<span> </span>';
|
||||
foreach ($reqs->items() as /** @var Request $req */ $req) {
|
||||
$withText = array_filter($req->history, fn($hist) => isset($hist->text));
|
||||
$text = $withText[array_key_first($withText)]->text; ?>
|
||||
<div class=col>
|
||||
<div class="card h-100">
|
||||
<div class="card-header p-0 d-flex" role=toolbar><?php
|
||||
page_link("/request/edit?id=$req->id", icon('edit'),
|
||||
['class' => 'btn btn-secondary', 'title' => 'Edit Request']); ?>
|
||||
<?=$spacer?>
|
||||
<button type=button class="btn btn-secondary" title="Add Notes" data-bs-toggle=modal
|
||||
data-bs-target=#notesModal hx-get="/components/request/add-notes?id=<?=$req->id?>"
|
||||
hx-target=#notesBody hx-swap=innerHTML><?=icon('comment');?></button>
|
||||
<?=$spacer?>
|
||||
<button type=button class="btn btn-secondary" title="Snooze Request" data-bs-toggle=modal
|
||||
data-bs-target=#snoozeModal hx-get="/components/request/snooze?id=<?=$req->id?>"
|
||||
hx-target=#snoozeBody hx-swap=innerHTML><?=icon('schedule');?></button>
|
||||
<div class=flex-grow-1></div>
|
||||
<button type=button class="btn btn-success w-25" hx-patch="/request/prayed?id=<?=$req->id?>"
|
||||
title="Mark as Prayed"><?=icon('done');?></button>
|
||||
</div>
|
||||
<div class=card-body>
|
||||
<p class=request-text><?=htmlentities($text);?>
|
||||
</div>
|
||||
<div class="card-footer text-end text-muted px-1 py-0">
|
||||
<em>last activity <?=$req->history[0]->asOf?></em>
|
||||
<?php /*
|
||||
TODO: relative time
|
||||
[] [
|
||||
match req.LastPrayed with
|
||||
| Some dt -> str "last prayed "; relativeDate dt now tz
|
||||
| None -> str "last activity "; relativeDate req.AsOf now tz
|
||||
] */ ?>
|
||||
</div>
|
||||
</div>
|
||||
</div><?php
|
||||
} ?>
|
||||
</section><?php
|
||||
} else {
|
||||
Layout::noResults('No Active Requests', '/request/edit?id=new', 'Add a Request', <<<'TEXT'
|
||||
You have no requests to be shown; see the “Active” link above for snoozed or deferred requests, and
|
||||
the “Answered” link for answered requests
|
||||
TEXT);
|
||||
}
|
||||
|
||||
bare_foot();
|
||||
Reference in New Issue
Block a user