Notes / snooze, update data migration
- WIP on finishing out request list
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace MyPrayerJournal;
|
||||
|
||||
use BitBadger\PDODocument\{Custom, DocumentException, DocumentList, Find, Mapper\DocumentMapper};
|
||||
use DateTimeImmutable;
|
||||
use Exception;
|
||||
use JsonSerializable;
|
||||
use Visus\Cuid2\Cuid2;
|
||||
@@ -65,6 +66,30 @@ class Request implements JsonSerializable
|
||||
return $this->history[0]->action == RequestAction::Answered;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this request currently snoozed?
|
||||
*
|
||||
* @return bool True if the request is snoozed, false if not
|
||||
* @throws Exception If the snoozed until date/time is not valid
|
||||
*/
|
||||
public function isSnoozed(): bool
|
||||
{
|
||||
return isset($this->snoozedUntil) && new DateTimeImmutable($this->snoozedUntil) > new DateTimeImmutable('now');
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this request currently not shown due to recurrence?
|
||||
*
|
||||
* @return bool True if the request is pending, false if not
|
||||
* @throws Exception If the snoozed or show-after date/times are not valid
|
||||
*/
|
||||
public function isPending(): bool
|
||||
{
|
||||
return !$this->isSnoozed()
|
||||
&& isset($this->showAfter)
|
||||
&& new DateTimeImmutable($this->showAfter) > new DateTimeImmutable('now');
|
||||
}
|
||||
|
||||
public function jsonSerialize(): mixed
|
||||
{
|
||||
$values = [
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
namespace MyPrayerJournal;
|
||||
|
||||
use BitBadger\PDODocument\DocumentException;
|
||||
use BitBadger\PDODocument\DocumentList;
|
||||
use BitBadger\PDODocument\{DocumentException, DocumentList};
|
||||
use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
@@ -44,7 +43,7 @@ class UI
|
||||
['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?>"
|
||||
data-bs-target=#notesModal hx-get="/components/request/add-note?id=<?=$req->id?>"
|
||||
hx-target=#notesBody hx-swap=innerHTML><?=self::icon('comment');?></button>
|
||||
<?=$spacer?>
|
||||
<button type=button class="btn btn-secondary" title="Snooze Request" data-bs-toggle=modal
|
||||
@@ -110,7 +109,7 @@ class UI
|
||||
public static function relativeDate(string $date): void
|
||||
{
|
||||
$parsed = new DateTimeImmutable($date);
|
||||
$inZone = $parsed->setTimezone(new DateTimeZone($_SERVER['HTTP_X_TIME_ZONE'] ?? 'Etc/UTC'));
|
||||
$inZone = $parsed->setTimezone(new DateTimeZone($_REQUEST['time_zone']));
|
||||
echo '<span title="' . date_format($inZone, 'l, F j, Y \a\t g:ia T') . '">'
|
||||
. self::formatDistance('now', $parsed) . '</span>';
|
||||
}
|
||||
@@ -172,11 +171,13 @@ class UI
|
||||
public static function requestList(DocumentList $reqs): void
|
||||
{
|
||||
$btnClass = "btn btn-light mx-2";
|
||||
$restoreBtn = fn(string $id, string $link, string $title) =>
|
||||
'<button class="' . $btnClass. '" hx-patch="/request/' . $link . '?id=' . $id
|
||||
. '" title="' . htmlspecialchars($title) . '">' . self::icon('restore') . '</button>';
|
||||
/// Create a request within the list
|
||||
/* let reqListItem now tz req =
|
||||
let isFuture instant = defaultArg (instant |> Option.map (fun it -> it > now)) false
|
||||
let reqId = RequestId.toString req.RequestId
|
||||
let isSnoozed = isFuture req.SnoozedUntil
|
||||
let isPending = (not isSnoozed) && isFuture req.ShowAfter
|
||||
let restoreBtn (link : string) title =
|
||||
button [ btnClass; _hxPatch $"/request/{reqId}/{link}"; _title title ] [ icon "restore" ] */ ?>
|
||||
@@ -190,9 +191,11 @@ class UI
|
||||
self::pageLink("/request/edit?id=$req->id", self::icon('edit'),
|
||||
['class' => $btnClass, 'title' => 'Edit Request']);
|
||||
}
|
||||
// if isSnoozed then restoreBtn "cancel-snooze" "Cancel Snooze"
|
||||
// elif isPending then restoreBtn "show" "Show Now"
|
||||
|
||||
if ($req->isSnoozed()) {
|
||||
echo $restoreBtn($req->id, 'cancel-snooze', 'Cancel Snooze');
|
||||
} elseif ($req->isPending()) {
|
||||
echo $restoreBtn($req->id, 'show', 'Show Now');
|
||||
}
|
||||
echo '<p class="request-text mb-0">' . $req->currentText();
|
||||
// if isSnoozed || isPending || isAnswered then
|
||||
// br []
|
||||
|
||||
Reference in New Issue
Block a user