First cut of Add / Edit / Active / Answered pages
- Centralized UI between UI and Layout classes
This commit is contained in:
1 parent
0b7fa77247
commit
b759c3494e
20 files changed
+528
-96
No files matched your search
@@ -1,54 +1,10 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use MyPrayerJournal\{Auth, Layout, Request, UI};
|
||||
use MyPrayerJournal\{Auth, UI};
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||
require '../../start.php';
|
||||
|
||||
Auth::requireUser(false);
|
||||
Layout::bareHead();
|
||||
|
||||
$reqs = Request::forJournal();
|
||||
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) { ?>
|
||||
<div class=col>
|
||||
<div class="card h-100">
|
||||
<div class="card-header p-0 d-flex" role=toolbar><?php
|
||||
UI::pageLink("/request/edit?id=$req->id", UI::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><?=UI::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><?=UI::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"><?=UI::icon('done');?></button>
|
||||
</div>
|
||||
<div class=card-body>
|
||||
<p class=request-text><?=htmlentities($req->currentText());?>
|
||||
</div>
|
||||
<div class="card-footer text-end text-muted px-1 py-0">
|
||||
<em><?php
|
||||
$lastPrayed = $req->lastPrayed();
|
||||
echo 'last ' . (is_null($lastPrayed) ? 'activity': 'prayed') . ' ';
|
||||
UI::relativeDate($lastPrayed ?? $req->history[0]->asOf); ?>
|
||||
</em>
|
||||
</div>
|
||||
</div>
|
||||
</div><?php
|
||||
} ?>
|
||||
</section><?php
|
||||
} else {
|
||||
UI::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);
|
||||
}
|
||||
|
||||
Layout::bareFoot();
|
||||
UI::journal();
|
||||
+6
-3
@@ -1,8 +1,11 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
require '../start.php';
|
||||
use MyPrayerJournal\Layout;
|
||||
|
||||
page_head('Documentation'); ?>
|
||||
require '../start.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||
|
||||
Layout::pageHead('Documentation'); ?>
|
||||
<article class="container mt-3">
|
||||
<h2 class=mb-3>Documentation</h2>
|
||||
|
||||
@@ -96,4 +99,4 @@ page_head('Documentation'); ?>
|
||||
and strengthen your prayer life.
|
||||
</ul>
|
||||
</article><?php
|
||||
page_foot();
|
||||
Layout::pageFoot();
|
||||
@@ -1,8 +1,11 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
require '../start.php';
|
||||
use MyPrayerJournal\Layout;
|
||||
|
||||
page_head('Welcome'); ?>
|
||||
require '../start.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||
|
||||
Layout::pageHead('Welcome'); ?>
|
||||
<article class="container mt-3">
|
||||
<p>
|
||||
<p>myPrayerJournal is a place where individuals can record their prayer requests, record that they prayed for them,
|
||||
@@ -12,4 +15,4 @@ page_head('Welcome'); ?>
|
||||
On” link above, and log on with either a Microsoft or Google account. You can also learn more about the
|
||||
site at the “Docs” link, also above.
|
||||
</article><?php
|
||||
page_foot();
|
||||
Layout::pageFoot();
|
||||
@@ -1,15 +1,15 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use MyPrayerJournal\Auth;
|
||||
use MyPrayerJournal\UI;
|
||||
use MyPrayerJournal\{Auth, Layout, UI};
|
||||
|
||||
require '../start.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||
|
||||
Auth::requireUser();
|
||||
|
||||
$user = Auth::user();
|
||||
$name = $user['given_name'] ?? 'Your';
|
||||
page_head('Welcome'); ?>
|
||||
Layout::pageHead('Journal'); ?>
|
||||
<article class="container-fluid mt-3">
|
||||
<h2 class=pb-3><?=$name?><?=$name == 'Your' ? '' : '’s'?> Prayer Journal</h2>
|
||||
<p class="pb-3 text-center"><?php
|
||||
@@ -46,5 +46,5 @@ page_head('Welcome'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</article><?php
|
||||
page_foot();
|
||||
Layout::pageFoot();
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
require '../../start.php';
|
||||
use MyPrayerJournal\Layout;
|
||||
|
||||
page_head('Privacy Policy'); ?>
|
||||
require '../../start.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||
|
||||
Layout::pageHead('Privacy Policy'); ?>
|
||||
<article class="container mt-3">
|
||||
<h2 class=mb-2>Privacy Policy</h2>
|
||||
<h6 class="text-muted pb-3">as of May 21<sup>st</sup>, 2018</h6>
|
||||
@@ -66,4 +69,4 @@ page_head('Privacy Policy'); ?>
|
||||
</div>
|
||||
</div>
|
||||
</article><?php
|
||||
page_foot();
|
||||
Layout::pageFoot();
|
||||
@@ -1,10 +1,11 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use MyPrayerJournal\UI;
|
||||
use MyPrayerJournal\{Layout, UI};
|
||||
|
||||
require '../../start.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||
|
||||
page_head('Terms of Service'); ?>
|
||||
Layout::pageHead('Terms of Service'); ?>
|
||||
<article class="container mt-3">
|
||||
<h2 class=mb-2>Terms of Service</h2>
|
||||
<h6 class="text-muted pb-3">as of May 21<sup>st</sup>, 2018</h6>
|
||||
@@ -55,4 +56,4 @@ page_head('Terms of Service'); ?>
|
||||
You may also wish to review our <?php UI::pageLink('/legal/privacy-policy', 'privacy policy'); ?> to learn how
|
||||
we handle your data.
|
||||
</article><?php
|
||||
page_foot();
|
||||
Layout::pageFoot();
|
||||
@@ -0,0 +1,105 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use MyPrayerJournal\{Auth, Layout, RecurrencePeriod, Request, RequestAction, UI};
|
||||
|
||||
require '../../start.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||
|
||||
Auth::requireUser();
|
||||
|
||||
$isNew = $_GET['id'] == 'new';
|
||||
|
||||
$req = match ($isNew) {
|
||||
true => new Request('new'),
|
||||
false => Request::byId($_GET['id'])
|
||||
};
|
||||
if (!$req) not_found();
|
||||
|
||||
$cancelLink = match (true) {
|
||||
str_ends_with($_SERVER['HTTP_REFERER'] ?? '', 'active.php') => '/requests/active',
|
||||
str_ends_with($_SERVER['HTTP_REFERER'] ?? '', 'snoozed.php') => '/requests/snoozed',
|
||||
default => '/journal'
|
||||
};
|
||||
$action = $_GET['id'] == 'new' ? 'Add' : 'Edit';
|
||||
|
||||
Layout::pageHead("$action Prayer Request");?>
|
||||
<article class=container>
|
||||
<h2 class=pb-3><?=$action?> Prayer Request</h2>
|
||||
<form <?=$isNew ? 'hx-post' : 'hx-patch'?>=/request/save hx-target=#top hx-push-url=true>
|
||||
<input type=hidden name=requestId value=<?=$req->id?>>
|
||||
<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>
|
||||
<label for=requestText>Prayer Request</label>
|
||||
</div><br><?php
|
||||
if (!$isNew) { ?>
|
||||
<div class=pb-3>
|
||||
<label>Also Mark As</label><br>
|
||||
<div class="form-check form-check-inline">
|
||||
<input type=radio class=form-check-input id=sU name=status value=<?=RequestAction::Updated->value?>
|
||||
checked>
|
||||
<label for=sU>Updated</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
<input type=radio class=form-check-input id=sP name=status value=<?=RequestAction::Prayed->value?>>
|
||||
<label for=sP>Prayed</label>
|
||||
</div>
|
||||
<div class="form-check form-check-inline">
|
||||
<input type=radio class=form-check-input id=sA name=status
|
||||
value=<?=RequestAction::Answered->value?>>
|
||||
<label for=sA>Answered</label>
|
||||
</div>
|
||||
</div><?php
|
||||
} ?>
|
||||
<div class=row">
|
||||
<div class="col-12 offset-md-2 col-md-8 offset-lg-3 col-lg-6">
|
||||
<p><strong>Recurrence </strong> <em class=text-muted>After prayer, request reappears…</em>
|
||||
<div class="d-flex flex-row flex-wrap justify-content-center align-items-center">
|
||||
<div class="form-check mx-2">
|
||||
<input type=radio class=form-check-input id=rI name=recurType
|
||||
value=<?=RecurrencePeriod::Immediate->value?>
|
||||
onclick="mpj.edit.toggleRecurrence(event)"<?php
|
||||
if ($req->recurrence->period == RecurrencePeriod::Immediate) echo ' checked'; ?>>
|
||||
<label for=rI>Immediately</label>
|
||||
</div>
|
||||
<div class="form-check mx-2">
|
||||
<input type=radio class=form-check-input id=rO name=recurType value=Other
|
||||
onclick="mpj.edit.toggleRecurrence(event)"<?php
|
||||
if ($req->recurrence->period <> RecurrencePeriod::Immediate) echo ' checked'; ?>>
|
||||
<label for=rO>Every…</label>
|
||||
</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'; ?>>
|
||||
<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'; ?>>
|
||||
<option value=<?=RecurrencePeriod::Hours->value?><?php
|
||||
if ($req->recurrence->period == RecurrencePeriod::Hours) echo ' selected'; ?>>
|
||||
hours
|
||||
</option>
|
||||
<option value=<?=RecurrencePeriod::Days->value?><?php
|
||||
if ($req->recurrence->period == RecurrencePeriod::Days) echo ' selected'; ?>>
|
||||
days
|
||||
</option>
|
||||
<option value=<?=RecurrencePeriod::Weeks->value?><?php
|
||||
if ($req->recurrence->period == RecurrencePeriod::Weeks) echo ' selected'; ?>>
|
||||
weeks
|
||||
</option>
|
||||
</select>
|
||||
<label for=recurInterval>Interval</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-end pt-3">
|
||||
<button class="btn btn-primary me-2" type=submit><?=UI::icon('save');?> Save</button><?php
|
||||
UI::pageLink($cancelLink, UI::icon('arrow_back') . ' Cancel', ['class' => 'btn btn-secondary ms-2']); ?>
|
||||
</div>
|
||||
</form>
|
||||
</article><?php
|
||||
Layout::pageFoot();
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use MyPrayerJournal\{Auth, History, Layout, Note, Request, RequestAction, UI};
|
||||
|
||||
require '../../start.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||
|
||||
Auth::requireUser();
|
||||
|
||||
$req = Request::byId($_GET['id']);
|
||||
if (!$req) not_found();
|
||||
|
||||
$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()
|
||||
- (new DateTimeImmutable(end($req->history)->asOf))->getTimestamp()) / 86400;
|
||||
|
||||
$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 ?? ''],
|
||||
$req->history));
|
||||
usort($logs, fn($a, $b) => $a[0] > $b[0] ? -1 : 1);
|
||||
if ($req->isAnswered()) array_shift($logs);
|
||||
|
||||
Layout::pageHead('Full Request');?>
|
||||
<article class="container mt-3">
|
||||
<div class=card>
|
||||
<h5 class=card-header>Full Prayer Request</h5>
|
||||
<div class=card-body>
|
||||
<h6 class="card-subtitle text-muted mb-2"><?php
|
||||
if (!is_null($answered)) { ?>
|
||||
Answered <?=$answered->format('F j, Y')?> (<?php UI::relativeDate($req->history[0]->asOf); ?>)
|
||||
•<?php
|
||||
} ?>
|
||||
Prayed <?=number_format($prayed)?> times • Open <?=number_format($daysOpen)?> days
|
||||
</h6>
|
||||
<p class=card-text><?=htmlentities($req->currentText())?>
|
||||
</div>
|
||||
<ul class="list-group list-group-flush"><?php
|
||||
foreach ($logs as $log) { ?>
|
||||
<li class=list-group-item>
|
||||
<p class=m-0><?=$log[1]?> <small><em><?=$log[0]->format('F j, Y')?></em></small><?php
|
||||
if ($log[2] <> '') echo '<p class="mt-2 mb-0">' . htmlentities($log[2]);
|
||||
} ?>
|
||||
</ul>
|
||||
</div>
|
||||
</article><?php
|
||||
Layout::pageFoot();
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use MyPrayerJournal\{Auth, History, RecurrencePeriod, Request, RequestAction, Table, UI};
|
||||
use BitBadger\PDODocument\Patch;
|
||||
|
||||
require '../../start.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'PATCH') not_found();
|
||||
|
||||
Auth::requireUser(false);
|
||||
|
||||
$req = Request::byId($_GET['id']);
|
||||
if (!$req) not_found();
|
||||
|
||||
$now = new DateTimeImmutable('now');
|
||||
|
||||
array_unshift($req->history, new History($now->format('c'), RequestAction::Prayed));
|
||||
$patch = ['history' => $req->history];
|
||||
|
||||
if ($req->recurrence->period <> RecurrencePeriod::Immediate) {
|
||||
$patch['showAfter'] = $now->add($req->recurrence->interval())->format('c');
|
||||
}
|
||||
Patch::byId(Table::REQUEST, $req->id, $patch);
|
||||
|
||||
UI::journal();
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use MyPrayerJournal\{Auth, History, Recurrence, RecurrencePeriod, Request, RequestAction, Table};
|
||||
use BitBadger\PDODocument\{Document, Patch, RemoveFields};
|
||||
|
||||
require '../../start.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'POST' && $_SERVER['REQUEST_METHOD'] <> 'PATCH') not_found();
|
||||
|
||||
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']);
|
||||
}
|
||||
|
||||
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'])]));
|
||||
//Messages.pushSuccess ctx "Added prayer request" "/journal"
|
||||
header('Location: /journal');
|
||||
http_response_code(303);
|
||||
exit;
|
||||
|
||||
case 'PATCH':
|
||||
$req = Request::byId($_PATCH['requestId']);
|
||||
if (!$req) not_found();
|
||||
$patch = [];
|
||||
// update recurrence if changed
|
||||
if ($recurrence != $req->recurrence) {
|
||||
$patch['recurrence'] = $recurrence;
|
||||
if ($recurrence->period == RecurrencePeriod::Immediate) {
|
||||
RemoveFields::byId(Table::REQUEST, $req->id, ['showAfter']);
|
||||
}
|
||||
}
|
||||
// append history
|
||||
$upd8Text = trim($_PATCH['requestText']);
|
||||
$text = $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);
|
||||
//Messages.pushSuccess ctx "Prayer request updated successfully" nextUrl
|
||||
// TODO: make redirect that filters out non-local URLs
|
||||
header('Location: ' . $_PATCH['returnTo']);
|
||||
http_response_code(303);
|
||||
exit;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use MyPrayerJournal\{Auth, Layout, Request, UI};
|
||||
|
||||
require '../../start.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||
|
||||
Auth::requireUser();
|
||||
|
||||
$reqs = Request::active();
|
||||
|
||||
Layout::pageHead('Active Requests'); ?>
|
||||
<article class="container mt-3">
|
||||
<h2 class=pb-3>Active Requests</h2><?php
|
||||
if ($reqs->hasItems()) {
|
||||
UI::requestList($reqs);
|
||||
} else {
|
||||
UI::noResults('No Active Requests', '/journal', 'Return to your journal',
|
||||
'Your prayer journal has no active requests');
|
||||
} ?>
|
||||
</article><?php
|
||||
Layout::pageFoot();
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use MyPrayerJournal\{Auth, Layout, Request, UI};
|
||||
|
||||
require '../../start.php';
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||
|
||||
Auth::requireUser();
|
||||
|
||||
$reqs = Request::answered();
|
||||
|
||||
Layout::pageHead('Answered Requests'); ?>
|
||||
<article class="container mt-3">
|
||||
<h2 class=pb-3>Answered Requests</h2><?php
|
||||
if ($reqs->hasItems()) {
|
||||
UI::requestList($reqs);
|
||||
} else {
|
||||
UI::noResults('No Answered Requests', '/journal', 'Return to your journal', <<<'TEXT'
|
||||
Your prayer journal has no answered requests; once you have marked one as “Answered”, it will
|
||||
appear here
|
||||
TEXT);
|
||||
} ?>
|
||||
</article><?php
|
||||
Layout::pageFoot();
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
use MyPrayerJournal\Auth;
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||
require '../../start.php';
|
||||
|
||||
Auth::logOn();
|
||||
Reference in new issue
Block a user