WIP on option / PJson integration
This commit is contained in:
1 parent
3bb4be3127
commit
52ec3f819c
13 files changed
+316
-226
No files matched your search
@@ -1,5 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use BitBadger\InspiredByFSharp\Option;
|
||||
use BitBadger\PDODocument\RemoveFields;
|
||||
use MyPrayerJournal\Table;
|
||||
use MyPrayerJournal\UI\{Component, Layout};
|
||||
@@ -9,7 +10,7 @@ require '../../start.php';
|
||||
$req = validate_request($_GET['id'], ['PATCH'], false);
|
||||
|
||||
RemoveFields::byId(Table::REQUEST, $req->id, ['snoozedUntil']);
|
||||
$req->snoozedUntil = null;
|
||||
$req->snoozedUntil = Option::None();
|
||||
|
||||
// TODO: message
|
||||
Layout::bareHead();
|
||||
|
||||
@@ -31,7 +31,7 @@ Layout::pageHead("$action Prayer Request");?>
|
||||
<input type=hidden name=returnTo value=<?=$cancelLink?>>
|
||||
<div class="form-floating pb-3">
|
||||
<textarea id=requestText name=requestText class=form-control style="min-height: 8rem;"
|
||||
placeholder="Enter the text of the request" autofocus required><?=$req->currentText()?></textarea>
|
||||
placeholder="Enter the text of the request" autofocus required><?=$req->currentText?></textarea>
|
||||
<label for=requestText>Prayer Request</label>
|
||||
</div><br><?php
|
||||
if (!$isNew) { ?>
|
||||
@@ -72,23 +72,23 @@ Layout::pageHead("$action Prayer Request");?>
|
||||
</div>
|
||||
<div class="form-floating mx-2">
|
||||
<input type=number class=form-control id=recurCount name=recurCount placeholder=0 required
|
||||
value=<?=$req->recurrence->interval ?? 0?> style="width:6rem;"<?php
|
||||
if ($req->recurrence->period == RecurrencePeriod::Immediate) echo ' disabled'; ?>>
|
||||
value=<?=$req->recurrence->interval->getOrDefault(0)?> style="width:6rem;"<?php
|
||||
if ($req->recurrence->period === RecurrencePeriod::Immediate) echo ' disabled'; ?>>
|
||||
<label for=recurCount>Count</label>
|
||||
</div>
|
||||
<div class="form-floating mx-2">
|
||||
<select class=form-control id=recurInterval name=recurInterval style="width:6rem;" required<?php
|
||||
if ($req->recurrence->period == RecurrencePeriod::Immediate) echo ' disabled'; ?>>
|
||||
if ($req->recurrence->period === RecurrencePeriod::Immediate) echo ' disabled'; ?>>
|
||||
<option value=<?=RecurrencePeriod::Hours->value?><?php
|
||||
if ($req->recurrence->period == RecurrencePeriod::Hours) echo ' selected'; ?>>
|
||||
if ($req->recurrence->period === RecurrencePeriod::Hours) echo ' selected'; ?>>
|
||||
hours
|
||||
</option>
|
||||
<option value=<?=RecurrencePeriod::Days->value?><?php
|
||||
if ($req->recurrence->period == RecurrencePeriod::Days) echo ' selected'; ?>>
|
||||
if ($req->recurrence->period === RecurrencePeriod::Days) echo ' selected'; ?>>
|
||||
days
|
||||
</option>
|
||||
<option value=<?=RecurrencePeriod::Weeks->value?><?php
|
||||
if ($req->recurrence->period == RecurrencePeriod::Weeks) echo ' selected'; ?>>
|
||||
if ($req->recurrence->period === RecurrencePeriod::Weeks) echo ' selected'; ?>>
|
||||
weeks
|
||||
</option>
|
||||
</select>
|
||||
|
||||
@@ -7,7 +7,7 @@ require '../../start.php';
|
||||
|
||||
$req = validate_request($_GET['id'], ['GET']);
|
||||
|
||||
$answered = $req->isAnswered() ? new DateTimeImmutable($req->history[0]->asOf) : null;
|
||||
$answered = $req->isAnswered ? new DateTimeImmutable($req->history[0]->asOf) : null;
|
||||
$prayed = sizeof(array_filter($req->history, fn(History $hist) => $hist->action == RequestAction::Prayed));
|
||||
$daysOpen =
|
||||
(($answered ?? new DateTimeImmutable('now'))->getTimestamp()
|
||||
@@ -15,10 +15,10 @@ $daysOpen =
|
||||
|
||||
$logs = array_merge(
|
||||
array_map(fn(Note $note) => [new DateTimeImmutable($note->asOf), 'Notes', $note->text], $req->notes),
|
||||
array_map(fn(History $hist) => [new DateTimeImmutable($hist->asOf), $hist->action->value, $hist->text ?? ''],
|
||||
array_map(fn(History $hist) => [new DateTimeImmutable($hist->asOf), $hist->action->value, $hist->text->getOrDefault('')],
|
||||
$req->history));
|
||||
usort($logs, fn($a, $b) => $a[0] > $b[0] ? -1 : 1);
|
||||
if ($req->isAnswered()) array_shift($logs);
|
||||
if ($req->isAnswered) array_shift($logs);
|
||||
|
||||
Layout::pageHead('Full Request');?>
|
||||
<article class="container mt-3">
|
||||
@@ -32,7 +32,7 @@ Layout::pageHead('Full Request');?>
|
||||
} ?>
|
||||
Prayed <?=number_format($prayed)?> times • Open <?=number_format($daysOpen)?> days
|
||||
</h6>
|
||||
<p class=card-text><?=htmlentities($req->currentText())?>
|
||||
<p class=card-text><?=htmlentities($req->currentText)?>
|
||||
</div>
|
||||
<ul class="list-group list-group-flush"><?php
|
||||
foreach ($logs as $log) { ?>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use BitBadger\InspiredByFSharp\Option;
|
||||
use BitBadger\PDODocument\{Document, Patch, RemoveFields};
|
||||
use MyPrayerJournal\{Auth, Table};
|
||||
use MyPrayerJournal\Domain\{History, Recurrence, RecurrencePeriod, Request, RequestAction};
|
||||
@@ -12,16 +13,17 @@ Auth::requireUser(false);
|
||||
$now = new DateTimeImmutable('now');
|
||||
$recurrence = new Recurrence(RecurrencePeriod::from($_POST['recurType'] ?? $_PATCH['recurType']));
|
||||
if ($recurrence->period <> RecurrencePeriod::Immediate) {
|
||||
$recurrence->interval = (int)($_POST['recurCount'] ?? $_PATCH['recurCount']);
|
||||
$recurrence->interval = Option::of((int)($_POST['recurCount'] ?? $_PATCH['recurCount']));
|
||||
}
|
||||
|
||||
switch ($_SERVER['REQUEST_METHOD']) {
|
||||
case 'POST':
|
||||
Document::insert(Table::REQUEST, new Request(
|
||||
enteredOn: $now->format('c'),
|
||||
userId: $_SESSION['user_id'],
|
||||
recurrence: $recurrence,
|
||||
history: [new History($now->format('c'), RequestAction::Created, $_POST['requestText'])]));
|
||||
$req = new Request();
|
||||
$req->enteredOn = $now->format('c');
|
||||
$req->userId = $_SESSION['user_id'];
|
||||
$req->recurrence = $recurrence;
|
||||
$req->history = [new History($now->format('c'), RequestAction::Created, $_POST['requestText'])];
|
||||
Document::insert(Table::REQUEST, $req);
|
||||
//Messages.pushSuccess ctx "Added prayer request" "/journal"
|
||||
see_other('/journal');
|
||||
|
||||
@@ -37,7 +39,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
||||
}
|
||||
// append history
|
||||
$upd8Text = trim($_PATCH['requestText']);
|
||||
$text = empty($upd8Text) || $upd8Text === $req->currentText() ? null : $upd8Text;
|
||||
$text = empty($upd8Text) || $upd8Text === $req->currentText ? null : $upd8Text;
|
||||
array_unshift($req->history, new History($now->format('c'), RequestAction::from($_PATCH['status']), $text));
|
||||
$patch['history'] = $req->history;
|
||||
Patch::byId(Table::REQUEST, $req->id, $patch);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
use MyPrayerJournal\Auth;
|
||||
|
||||
require '../../start.php';
|
||||
require '../../../start.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||
|
||||
Auth::logOn();
|
||||
Reference in new issue
Block a user