Compare commits
84 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 75680fae00 | |||
| 516a903565 | |||
| 52ec3f819c | |||
| 3bb4be3127 | |||
| 9110643383 | |||
| ff34bb9743 | |||
| 61127676a2 | |||
| 5beeee4819 | |||
| a2feaff4da | |||
| e121701250 | |||
| 20ad50928a | |||
| 9421bb2035 | |||
| d6e8cf66cc | |||
| 2369827033 | |||
| 3ebb03d470 | |||
| b759c3494e | |||
| 0b7fa77247 | |||
| 4ea55d4d25 | |||
| 4aa6e832c7 | |||
| 41853a7645 | |||
| 24c503385e | |||
| b393a86bb5 | |||
| 8ee3c6b483 | |||
| b07532ab50 | |||
| b3f62c2586 | |||
| 20dcaf6e1b | |||
| b9d81fb7aa | |||
| 3df5c71d81 | |||
| c697001736 | |||
|
|
6c28cfc1ec | ||
| 8702723e01 | |||
| d621ede7bb | |||
| a826275510 | |||
| 2a86e41fe3 | |||
| babc77bbd0 | |||
| 997279783f | |||
| 77c85f516c | |||
| ca622aa4b7 | |||
| cce4f17cd8 | |||
| 0bf73e49c9 | |||
| a84d54c095 | |||
|
|
68f4a1b9b2 | ||
| 23ccd3ac67 | |||
| d4823c15f7 | |||
| fc01e79337 | |||
| fa9c902af7 | |||
|
|
ed762ea03e | ||
| 3675af3dca | |||
|
|
1830e01ad6 | ||
|
|
ffe057d7ee | ||
|
|
bafdfb1af5 | ||
|
|
3d907e9569 | ||
|
|
c8ef6e8714 | ||
| 266243423c | |||
| 92a493251a | |||
| c7c63d01f8 | |||
|
|
62a18a8b09 | ||
| d1a9eb62c3 | |||
| 407222d06a | |||
| 044283709c | |||
|
|
be86fbfcba | ||
|
|
63b3037ede | ||
| d239b16d33 | |||
| a9ab0446c4 | |||
| 366ed2ed2f | |||
|
|
fb304c26b6 | ||
|
|
7b11e70e76 | ||
|
|
f50a8ae83e | ||
|
|
aa0864416f | ||
|
|
05a1b7adda | ||
|
|
f833598cdd | ||
|
|
dfd1c59554 | ||
|
|
83b70073e9 | ||
|
|
11025cc39a | ||
|
|
fb908a1cef | ||
|
|
6a6f7b35c7 | ||
| 715df08cbe | |||
|
|
ac8b39fff9 | ||
|
|
2bf54136ca | ||
|
|
0709cabea1 | ||
|
|
cbd9114599 | ||
|
|
097ee2deb4 | ||
| fa78e86de6 | |||
|
|
ce588b6a43 |
266
.gitignore
vendored
266
.gitignore
vendored
@@ -1,266 +1,10 @@
|
|||||||
## Ignore Visual Studio temporary files, build results, and
|
|
||||||
## files generated by popular Visual Studio add-ons.
|
|
||||||
|
|
||||||
# User-specific files
|
|
||||||
*.suo
|
|
||||||
*.user
|
|
||||||
*.userosscache
|
|
||||||
*.sln.docstates
|
|
||||||
|
|
||||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
|
||||||
*.userprefs
|
|
||||||
|
|
||||||
# Build results
|
|
||||||
[Dd]ebug/
|
|
||||||
[Dd]ebugPublic/
|
|
||||||
[Rr]elease/
|
|
||||||
[Rr]eleases/
|
|
||||||
x64/
|
|
||||||
x86/
|
|
||||||
bld/
|
|
||||||
[Bb]in/
|
|
||||||
[Oo]bj/
|
|
||||||
[Ll]og/
|
|
||||||
|
|
||||||
# Visual Studio 2015 cache/options directory
|
|
||||||
.vs/
|
|
||||||
.vscode/
|
|
||||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
|
||||||
#wwwroot/
|
|
||||||
|
|
||||||
# MSTest test Results
|
|
||||||
[Tt]est[Rr]esult*/
|
|
||||||
[Bb]uild[Ll]og.*
|
|
||||||
|
|
||||||
# NUNIT
|
|
||||||
*.VisualState.xml
|
|
||||||
TestResult.xml
|
|
||||||
|
|
||||||
# Build Results of an ATL Project
|
|
||||||
[Dd]ebugPS/
|
|
||||||
[Rr]eleasePS/
|
|
||||||
dlldata.c
|
|
||||||
|
|
||||||
# DNX
|
|
||||||
project.lock.json
|
|
||||||
artifacts/
|
|
||||||
|
|
||||||
*_i.c
|
|
||||||
*_p.c
|
|
||||||
*_i.h
|
|
||||||
*.ilk
|
|
||||||
*.meta
|
|
||||||
*.obj
|
|
||||||
*.pch
|
|
||||||
*.pdb
|
|
||||||
*.pgc
|
|
||||||
*.pgd
|
|
||||||
*.rsp
|
|
||||||
*.sbr
|
|
||||||
*.tlb
|
|
||||||
*.tli
|
|
||||||
*.tlh
|
|
||||||
*.tmp
|
|
||||||
*.tmp_proj
|
|
||||||
*.log
|
|
||||||
*.vspscc
|
|
||||||
*.vssscc
|
|
||||||
.builds
|
|
||||||
*.pidb
|
|
||||||
*.svclog
|
|
||||||
*.scc
|
|
||||||
|
|
||||||
# Chutzpah Test files
|
|
||||||
_Chutzpah*
|
|
||||||
|
|
||||||
# Visual C++ cache files
|
|
||||||
ipch/
|
|
||||||
*.aps
|
|
||||||
*.ncb
|
|
||||||
*.opendb
|
|
||||||
*.opensdf
|
|
||||||
*.sdf
|
|
||||||
*.cachefile
|
|
||||||
*.VC.db
|
|
||||||
*.VC.VC.opendb
|
|
||||||
|
|
||||||
# Visual Studio profiler
|
|
||||||
*.psess
|
|
||||||
*.vsp
|
|
||||||
*.vspx
|
|
||||||
*.sap
|
|
||||||
|
|
||||||
# TFS 2012 Local Workspace
|
|
||||||
$tf/
|
|
||||||
|
|
||||||
# Guidance Automation Toolkit
|
|
||||||
*.gpState
|
|
||||||
|
|
||||||
# ReSharper is a .NET coding add-in
|
|
||||||
_ReSharper*/
|
|
||||||
*.[Rr]e[Ss]harper
|
|
||||||
*.DotSettings.user
|
|
||||||
|
|
||||||
# JustCode is a .NET coding add-in
|
|
||||||
.JustCode
|
|
||||||
|
|
||||||
# TeamCity is a build add-in
|
|
||||||
_TeamCity*
|
|
||||||
|
|
||||||
# DotCover is a Code Coverage Tool
|
|
||||||
*.dotCover
|
|
||||||
|
|
||||||
# NCrunch
|
|
||||||
_NCrunch_*
|
|
||||||
.*crunch*.local.xml
|
|
||||||
nCrunchTemp_*
|
|
||||||
|
|
||||||
# MightyMoose
|
|
||||||
*.mm.*
|
|
||||||
AutoTest.Net/
|
|
||||||
|
|
||||||
# Web workbench (sass)
|
|
||||||
.sass-cache/
|
|
||||||
|
|
||||||
# Installshield output folder
|
|
||||||
[Ee]xpress/
|
|
||||||
|
|
||||||
# DocProject is a documentation generator add-in
|
|
||||||
DocProject/buildhelp/
|
|
||||||
DocProject/Help/*.HxT
|
|
||||||
DocProject/Help/*.HxC
|
|
||||||
DocProject/Help/*.hhc
|
|
||||||
DocProject/Help/*.hhk
|
|
||||||
DocProject/Help/*.hhp
|
|
||||||
DocProject/Help/Html2
|
|
||||||
DocProject/Help/html
|
|
||||||
|
|
||||||
# Click-Once directory
|
|
||||||
publish/
|
|
||||||
|
|
||||||
# Publish Web Output
|
|
||||||
*.[Pp]ublish.xml
|
|
||||||
*.azurePubxml
|
|
||||||
# TODO: Comment the next line if you want to checkin your web deploy settings
|
|
||||||
# but database connection strings (with potential passwords) will be unencrypted
|
|
||||||
*.pubxml
|
|
||||||
*.publishproj
|
|
||||||
|
|
||||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
|
||||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
|
||||||
# in these scripts will be unencrypted
|
|
||||||
PublishScripts/
|
|
||||||
|
|
||||||
# NuGet Packages
|
|
||||||
*.nupkg
|
|
||||||
# The packages folder can be ignored because of Package Restore
|
|
||||||
**/packages/*
|
|
||||||
# except build/, which is used as an MSBuild target.
|
|
||||||
!**/packages/build/
|
|
||||||
# Uncomment if necessary however generally it will be regenerated when needed
|
|
||||||
#!**/packages/repositories.config
|
|
||||||
# NuGet v3's project.json files produces more ignoreable files
|
|
||||||
*.nuget.props
|
|
||||||
*.nuget.targets
|
|
||||||
|
|
||||||
# Microsoft Azure Build Output
|
|
||||||
csx/
|
|
||||||
*.build.csdef
|
|
||||||
|
|
||||||
# Microsoft Azure Emulator
|
|
||||||
ecf/
|
|
||||||
rcf/
|
|
||||||
|
|
||||||
# Windows Store app package directories and files
|
|
||||||
AppPackages/
|
|
||||||
BundleArtifacts/
|
|
||||||
Package.StoreAssociation.xml
|
|
||||||
_pkginfo.txt
|
|
||||||
|
|
||||||
# Visual Studio cache files
|
|
||||||
# files ending in .cache can be ignored
|
|
||||||
*.[Cc]ache
|
|
||||||
# but keep track of directories ending in .cache
|
|
||||||
!*.[Cc]ache/
|
|
||||||
|
|
||||||
# Others
|
|
||||||
ClientBin/
|
|
||||||
~$*
|
|
||||||
*~
|
|
||||||
*.dbmdl
|
|
||||||
*.dbproj.schemaview
|
|
||||||
*.pfx
|
|
||||||
*.publishsettings
|
|
||||||
node_modules/
|
|
||||||
orleans.codegen.cs
|
|
||||||
|
|
||||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
|
||||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
|
||||||
#bower_components/
|
|
||||||
|
|
||||||
# RIA/Silverlight projects
|
|
||||||
Generated_Code/
|
|
||||||
|
|
||||||
# Backup & report files from converting an old project file
|
|
||||||
# to a newer Visual Studio version. Backup files are not needed,
|
|
||||||
# because we have git ;-)
|
|
||||||
_UpgradeReport_Files/
|
|
||||||
Backup*/
|
|
||||||
UpgradeLog*.XML
|
|
||||||
UpgradeLog*.htm
|
|
||||||
|
|
||||||
# SQL Server files
|
|
||||||
*.mdf
|
|
||||||
*.ldf
|
|
||||||
|
|
||||||
# Business Intelligence projects
|
|
||||||
*.rdl.data
|
|
||||||
*.bim.layout
|
|
||||||
*.bim_*.settings
|
|
||||||
|
|
||||||
# Microsoft Fakes
|
|
||||||
FakesAssemblies/
|
|
||||||
|
|
||||||
# GhostDoc plugin setting file
|
|
||||||
*.GhostDoc.xml
|
|
||||||
|
|
||||||
# Node.js Tools for Visual Studio
|
|
||||||
.ntvs_analysis.dat
|
|
||||||
|
|
||||||
# Visual Studio 6 build log
|
|
||||||
*.plg
|
|
||||||
|
|
||||||
# Visual Studio 6 workspace options file
|
|
||||||
*.opt
|
|
||||||
|
|
||||||
# Visual Studio LightSwitch build output
|
|
||||||
**/*.HTMLClient/GeneratedArtifacts
|
|
||||||
**/*.DesktopClient/GeneratedArtifacts
|
|
||||||
**/*.DesktopClient/ModelManifest.xml
|
|
||||||
**/*.Server/GeneratedArtifacts
|
|
||||||
**/*.Server/ModelManifest.xml
|
|
||||||
_Pvt_Extensions
|
|
||||||
|
|
||||||
# Paket dependency manager
|
|
||||||
.paket/paket.exe
|
|
||||||
paket-files/
|
|
||||||
|
|
||||||
# FAKE - F# Make
|
|
||||||
.fake/
|
|
||||||
|
|
||||||
# JetBrains Rider
|
# JetBrains Rider
|
||||||
.idea/
|
.idea/
|
||||||
*.sln.iml
|
*.sln.iml
|
||||||
|
|
||||||
# Ionide VSCode extension
|
# PHP ignore files
|
||||||
.ionide
|
src/vendor
|
||||||
|
src/.env
|
||||||
|
|
||||||
# Compiled files / application
|
# databases
|
||||||
src/api/build
|
src/data/*.db
|
||||||
src/api/MyPrayerJournal.Api/wwwroot/favicon.ico
|
|
||||||
src/api/MyPrayerJournal.Api/wwwroot/index.html
|
|
||||||
src/api/MyPrayerJournal.Api/wwwroot/css
|
|
||||||
src/api/MyPrayerJournal.Api/wwwroot/js
|
|
||||||
src/api/MyPrayerJournal.Api/appsettings.development.json
|
|
||||||
/build
|
|
||||||
src/*.exe
|
|
||||||
|
|||||||
@@ -6,6 +6,6 @@ Journaling has a long history; it helps people remember what happened, and the a
|
|||||||
|
|
||||||
myPrayerJournal was borne of out of a personal desire [Daniel](https://github.com/danieljsummers) had to have something that would help him with his prayer life. When it's time to pray, it's not really time to use an app, so the design goal here is to keep it simple and unobtrusive. It will also help eliminate some of the downsides to a paper prayer journal, like not remembering whether you've prayed for a request, or running out of room to write another update on one.
|
myPrayerJournal was borne of out of a personal desire [Daniel](https://github.com/danieljsummers) had to have something that would help him with his prayer life. When it's time to pray, it's not really time to use an app, so the design goal here is to keep it simple and unobtrusive. It will also help eliminate some of the downsides to a paper prayer journal, like not remembering whether you've prayed for a request, or running out of room to write another update on one.
|
||||||
|
|
||||||
## Futher Reading
|
## Further Reading
|
||||||
|
|
||||||
The documentation for the site is at <https://bit-badger.github.io/myPrayerJournal/>.
|
The documentation for the site is at <https://prayerjournal.me/docs>.
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
docs.prayerjournal.me
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
theme: jekyll-theme-architect
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
# Documentation
|
|
||||||
|
|
||||||
## About myPrayerJournal
|
|
||||||
|
|
||||||
Journaling has a long history; it helps people remember what happened, and the act of writing helps people think about what happened and process it. A prayer journal is not a new concept; it helps you keep track of the requests for which you've prayed, you can use it to pray over things repeatedly, and you can write the result when the answer comes _(or it was "no")_.
|
|
||||||
|
|
||||||
myPrayerJournal was borne of out of a personal desire [Daniel](https://github.com/danieljsummers) had to have something that would help him with his prayer life. When it's time to pray, it's not really time to use an app, so the design goal here is to keep it simple and unobtrusive. It will also help eliminate some of the downsides to a paper prayer journal, like not remembering whether you've prayed for a request, or running out of room to write another update on one.
|
|
||||||
|
|
||||||
## Finding the Site
|
|
||||||
|
|
||||||
The application is at <https://prayerjournal.me>.
|
|
||||||
|
|
||||||
## Signing Up
|
|
||||||
|
|
||||||
myPrayerJournal uses login services using Google or Microsoft accounts. The only information the application stores in its database is your user Id token it receives from these services, so there are no permissions you should have to accept from these provider other than establishing that you can log on with that account. Because of this, you'll want to pick the same one each time; the tokens between the two accounts are different, even if you use the same e-mail address to log on to both.
|
|
||||||
|
|
||||||
## Your Prayer Journal
|
|
||||||
|
|
||||||
Your current requests will be presented in columns (usually three, but it could be more or less, depending on the size of your screen or device). Each request is in its own card, and the buttons at the top of each card apply to that request. The last line of each request also tells you how long it has been since anything has been done on that request. Any time you see something like "a few minutes ago," you can hover over that to see the actual date/time the action was taken.
|
|
||||||
|
|
||||||
## Adding a Request
|
|
||||||
|
|
||||||
To add a request, click the "Add a New Request" button at the top of your journal. Then, enter the text of the request as you see fit; there is no right or wrong way, and you are the only person who will see the text you enter. When you save the request, it will go to the bottom of the list of requests.
|
|
||||||
|
|
||||||
## Setting Request Recurrence
|
|
||||||
|
|
||||||
When you add or update a request, you can choose whether requests go to the bottom of the journal once they have been marked "Prayed" or whether they will reappear after a delay. You can set recurrence in terms of hours, days, or weeks, but it cannot be longer than 365 days. If you decide you want a request to reappear sooner, you can skip the current delay; click the "Active" menu link, find the request in the list (likely near the bottom), and click the "Show Now" button.
|
|
||||||
|
|
||||||
## Praying for Requests
|
|
||||||
|
|
||||||
The first button for each request has a checkmark icon; clicking this button will mark the request as "Prayed" and move it to the bottom of the list (or off, if you've set a recurrence period for the request). This allows you, if you're praying through your requests, to start at the top left (with the request that it's been the longest since you've prayed) and click the button as you pray; when the request move below or away, the next-least-recently-prayed request will take the top spot.
|
|
||||||
|
|
||||||
## Editing Requests
|
|
||||||
|
|
||||||
The second button for each request has a pencil icon. This allows you to edit the text of the request, pretty much the same way you entered it; it starts with the current text, and you can add to it, modify it, or completely replace it. By default, updates will go in with an "Updated" status; you have the option to also mark this update as "Prayed" or "Answered." Answered requests will drop off the journal list.
|
|
||||||
|
|
||||||
## Adding Notes
|
|
||||||
|
|
||||||
The third button for each request has an icon that looks like a speech bubble with lines on it; this lets you record notes about the request. If there is something you want to record that doesn't change the text of the request, this is the place to do it. For example, you may be praying for a long-term health issue, and that person tells you that their status is the same; or, you may want to record something God said to you while you were praying for that request.
|
|
||||||
|
|
||||||
## Snoozing Requests
|
|
||||||
|
|
||||||
There may be a time where a request does not need to appear. The fourth button, with the clock icon, allows you to snooze requests until the day you specify. Additionally, if you have any snoozed requests, a "Snoozed" menu item will appear next to the "Journal" one; this page allows you to see what requests are snoozed, and return them to your journal by canceling the snooze.
|
|
||||||
|
|
||||||
## Viewing a Request and Its History
|
|
||||||
|
|
||||||
myPrayerJournal tracks all of the actions related to a request; from the "Active" and "Answered" menu links (and "Snoozed", if it's showing), there is a "View Full Request" button. That page will show the current text of the request; how many times it has been marked as prayed; how long it has been an active request; and a log of all updates, prayers, and notes you have recorded. That log is listed from most recent to least recent; if you want to read it chronologically, just press the "End" key on your keyboard and read it from the bottom up.
|
|
||||||
|
|
||||||
The "Active" link will show all requests that have not yet been marked answered, including snoozed and recurring requests. If requests are snoozed, or in a recurrence period off the journal, there will be a button where you can return the request to the list (either "Cancel Snooze" or "Show Now"). The "Answered" link shows all requests that have been marked answered. The "Snoozed" link just shows snoozed requests.
|
|
||||||
|
|
||||||
## Final Notes
|
|
||||||
|
|
||||||
- If you encounter errors, please [file an issue on GitHub](https://github.com/bit-badger/myPrayerJournal/issues) with as much detail as possible. You can also provide suggestions, or browse the list of currently open issues.
|
|
||||||
- Prayer requests and their history are securely backed up nightly along with other Bit Badger Solutions data.
|
|
||||||
- Prayer changes things - most of all, the one doing the praying. I pray that this tool enables you to deepen and strengthen your prayer life.
|
|
||||||
9
src/Caddyfile
Normal file
9
src/Caddyfile
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
frankenphp
|
||||||
|
order php_server before file_server
|
||||||
|
}
|
||||||
|
http://localhost:3000 {
|
||||||
|
root * ./public
|
||||||
|
try_files {path} {path}.php
|
||||||
|
php_server
|
||||||
|
}
|
||||||
17
src/Dockerfile
Normal file
17
src/Dockerfile
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS build
|
||||||
|
WORKDIR /mpj
|
||||||
|
COPY ./MyPrayerJournal/MyPrayerJournal.fsproj ./
|
||||||
|
RUN dotnet restore
|
||||||
|
|
||||||
|
COPY ./MyPrayerJournal ./
|
||||||
|
RUN dotnet publish -c Release -r linux-x64
|
||||||
|
RUN rm bin/Release/net8.0/linux-x64/publish/appsettings.*.json || true
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine as final
|
||||||
|
WORKDIR /app
|
||||||
|
RUN apk add --no-cache icu-libs
|
||||||
|
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
|
||||||
|
COPY --from=build /mpj/bin/Release/net8.0/linux-x64/publish/ ./
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
CMD [ "dotnet", "/app/MyPrayerJournal.dll" ]
|
||||||
@@ -1,275 +0,0 @@
|
|||||||
namespace MyPrayerJournal
|
|
||||||
|
|
||||||
open FSharp.Control.Tasks.V2.ContextInsensitive
|
|
||||||
open Microsoft.EntityFrameworkCore
|
|
||||||
open Microsoft.FSharpLu
|
|
||||||
|
|
||||||
/// Entities for use in the data model for myPrayerJournal
|
|
||||||
[<AutoOpen>]
|
|
||||||
module Entities =
|
|
||||||
|
|
||||||
open FSharp.EFCore.OptionConverter
|
|
||||||
open System.Collections.Generic
|
|
||||||
|
|
||||||
/// Type alias for a Collision-resistant Unique IDentifier
|
|
||||||
type Cuid = string
|
|
||||||
|
|
||||||
/// Request ID is a CUID
|
|
||||||
type RequestId = Cuid
|
|
||||||
|
|
||||||
/// User ID is a string (the "sub" part of the JWT)
|
|
||||||
type UserId = string
|
|
||||||
|
|
||||||
/// History is a record of action taken on a prayer request, including updates to its text
|
|
||||||
type [<CLIMutable; NoComparison; NoEquality>] History =
|
|
||||||
{ /// The ID of the request to which this history entry applies
|
|
||||||
requestId : RequestId
|
|
||||||
/// The time when this history entry was made
|
|
||||||
asOf : int64
|
|
||||||
/// The status for this history entry
|
|
||||||
status : string
|
|
||||||
/// The text of the update, if applicable
|
|
||||||
text : string option
|
|
||||||
}
|
|
||||||
with
|
|
||||||
/// An empty history entry
|
|
||||||
static member empty =
|
|
||||||
{ requestId = ""
|
|
||||||
asOf = 0L
|
|
||||||
status = ""
|
|
||||||
text = None
|
|
||||||
}
|
|
||||||
|
|
||||||
static member configureEF (mb : ModelBuilder) =
|
|
||||||
mb.Entity<History> (
|
|
||||||
fun m ->
|
|
||||||
m.ToTable "history" |> ignore
|
|
||||||
m.HasKey ("requestId", "asOf") |> ignore
|
|
||||||
m.Property(fun e -> e.requestId).IsRequired () |> ignore
|
|
||||||
m.Property(fun e -> e.asOf).IsRequired () |> ignore
|
|
||||||
m.Property(fun e -> e.status).IsRequired() |> ignore
|
|
||||||
m.Property(fun e -> e.text) |> ignore)
|
|
||||||
|> ignore
|
|
||||||
let typ = mb.Model.FindEntityType(typeof<History>)
|
|
||||||
let prop = typ.FindProperty("text")
|
|
||||||
mb.Model.FindEntityType(typeof<History>).FindProperty("text").SetValueConverter (OptionConverter<string> ())
|
|
||||||
|
|
||||||
/// Note is a note regarding a prayer request that does not result in an update to its text
|
|
||||||
and [<CLIMutable; NoComparison; NoEquality>] Note =
|
|
||||||
{ /// The ID of the request to which this note applies
|
|
||||||
requestId : RequestId
|
|
||||||
/// The time when this note was made
|
|
||||||
asOf : int64
|
|
||||||
/// The text of the notes
|
|
||||||
notes : string
|
|
||||||
}
|
|
||||||
with
|
|
||||||
/// An empty note
|
|
||||||
static member empty =
|
|
||||||
{ requestId = ""
|
|
||||||
asOf = 0L
|
|
||||||
notes = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
static member configureEF (mb : ModelBuilder) =
|
|
||||||
mb.Entity<Note> (
|
|
||||||
fun m ->
|
|
||||||
m.ToTable "note" |> ignore
|
|
||||||
m.HasKey ("requestId", "asOf") |> ignore
|
|
||||||
m.Property(fun e -> e.requestId).IsRequired () |> ignore
|
|
||||||
m.Property(fun e -> e.asOf).IsRequired () |> ignore
|
|
||||||
m.Property(fun e -> e.notes).IsRequired () |> ignore)
|
|
||||||
|> ignore
|
|
||||||
|
|
||||||
/// Request is the identifying record for a prayer request
|
|
||||||
and [<CLIMutable; NoComparison; NoEquality>] Request =
|
|
||||||
{ /// The ID of the request
|
|
||||||
requestId : RequestId
|
|
||||||
/// The time this request was initially entered
|
|
||||||
enteredOn : int64
|
|
||||||
/// The ID of the user to whom this request belongs ("sub" from the JWT)
|
|
||||||
userId : string
|
|
||||||
/// The time at which this request should reappear in the user's journal by manual user choice
|
|
||||||
snoozedUntil : int64
|
|
||||||
/// The time at which this request should reappear in the user's journal by recurrence
|
|
||||||
showAfter : int64
|
|
||||||
/// The type of recurrence for this request
|
|
||||||
recurType : string
|
|
||||||
/// How many of the recurrence intervals should occur between appearances in the journal
|
|
||||||
recurCount : int16
|
|
||||||
/// The history entries for this request
|
|
||||||
history : ICollection<History>
|
|
||||||
/// The notes for this request
|
|
||||||
notes : ICollection<Note>
|
|
||||||
}
|
|
||||||
with
|
|
||||||
/// An empty request
|
|
||||||
static member empty =
|
|
||||||
{ requestId = ""
|
|
||||||
enteredOn = 0L
|
|
||||||
userId = ""
|
|
||||||
snoozedUntil = 0L
|
|
||||||
showAfter = 0L
|
|
||||||
recurType = "immediate"
|
|
||||||
recurCount = 0s
|
|
||||||
history = List<History> ()
|
|
||||||
notes = List<Note> ()
|
|
||||||
}
|
|
||||||
|
|
||||||
static member configureEF (mb : ModelBuilder) =
|
|
||||||
mb.Entity<Request> (
|
|
||||||
fun m ->
|
|
||||||
m.ToTable "request" |> ignore
|
|
||||||
m.HasKey(fun e -> e.requestId :> obj) |> ignore
|
|
||||||
m.Property(fun e -> e.requestId).IsRequired () |> ignore
|
|
||||||
m.Property(fun e -> e.enteredOn).IsRequired () |> ignore
|
|
||||||
m.Property(fun e -> e.userId).IsRequired () |> ignore
|
|
||||||
m.Property(fun e -> e.snoozedUntil).IsRequired () |> ignore
|
|
||||||
m.Property(fun e -> e.showAfter).IsRequired () |> ignore
|
|
||||||
m.Property(fun e -> e.recurType).IsRequired() |> ignore
|
|
||||||
m.Property(fun e -> e.recurCount).IsRequired() |> ignore
|
|
||||||
m.HasMany(fun e -> e.history :> IEnumerable<History>)
|
|
||||||
.WithOne()
|
|
||||||
.HasForeignKey(fun e -> e.requestId :> obj)
|
|
||||||
|> ignore
|
|
||||||
m.HasMany(fun e -> e.notes :> IEnumerable<Note>)
|
|
||||||
.WithOne()
|
|
||||||
.HasForeignKey(fun e -> e.requestId :> obj)
|
|
||||||
|> ignore)
|
|
||||||
|> ignore
|
|
||||||
|
|
||||||
/// JournalRequest is the form of a prayer request returned for the request journal display. It also contains
|
|
||||||
/// properties that may be filled for history and notes
|
|
||||||
[<CLIMutable; NoComparison; NoEquality>]
|
|
||||||
type JournalRequest =
|
|
||||||
{ /// The ID of the request
|
|
||||||
requestId : RequestId
|
|
||||||
/// The ID of the user to whom the request belongs
|
|
||||||
userId : string
|
|
||||||
/// The current text of the request
|
|
||||||
text : string
|
|
||||||
/// The last time action was taken on the request
|
|
||||||
asOf : int64
|
|
||||||
/// The last status for the request
|
|
||||||
lastStatus : string
|
|
||||||
/// The time that this request should reappear in the user's journal
|
|
||||||
snoozedUntil : int64
|
|
||||||
/// The time after which this request should reappear in the user's journal by configured recurrence
|
|
||||||
showAfter : int64
|
|
||||||
/// The type of recurrence for this request
|
|
||||||
recurType : string
|
|
||||||
/// How many of the recurrence intervals should occur between appearances in the journal
|
|
||||||
recurCount : int16
|
|
||||||
/// History entries for the request
|
|
||||||
history : History list
|
|
||||||
/// Note entries for the request
|
|
||||||
notes : Note list
|
|
||||||
}
|
|
||||||
with
|
|
||||||
static member configureEF (mb : ModelBuilder) =
|
|
||||||
mb.Query<JournalRequest> (
|
|
||||||
fun m ->
|
|
||||||
m.ToView "journal" |> ignore
|
|
||||||
m.Ignore(fun e -> e.history :> obj) |> ignore
|
|
||||||
m.Ignore(fun e -> e.notes :> obj) |> ignore)
|
|
||||||
|> ignore
|
|
||||||
|
|
||||||
|
|
||||||
open System.Linq
|
|
||||||
|
|
||||||
/// Data context
|
|
||||||
type AppDbContext (opts : DbContextOptions<AppDbContext>) =
|
|
||||||
inherit DbContext (opts)
|
|
||||||
|
|
||||||
[<DefaultValue>]
|
|
||||||
val mutable private history : DbSet<History>
|
|
||||||
[<DefaultValue>]
|
|
||||||
val mutable private notes : DbSet<Note>
|
|
||||||
[<DefaultValue>]
|
|
||||||
val mutable private requests : DbSet<Request>
|
|
||||||
[<DefaultValue>]
|
|
||||||
val mutable private journal : DbQuery<JournalRequest>
|
|
||||||
|
|
||||||
member this.History
|
|
||||||
with get () = this.history
|
|
||||||
and set v = this.history <- v
|
|
||||||
member this.Notes
|
|
||||||
with get () = this.notes
|
|
||||||
and set v = this.notes <- v
|
|
||||||
member this.Requests
|
|
||||||
with get () = this.requests
|
|
||||||
and set v = this.requests <- v
|
|
||||||
member this.Journal
|
|
||||||
with get () = this.journal
|
|
||||||
and set v = this.journal <- v
|
|
||||||
|
|
||||||
override __.OnModelCreating (mb : ModelBuilder) =
|
|
||||||
base.OnModelCreating mb
|
|
||||||
[ History.configureEF
|
|
||||||
Note.configureEF
|
|
||||||
Request.configureEF
|
|
||||||
JournalRequest.configureEF
|
|
||||||
]
|
|
||||||
|> List.iter (fun x -> x mb)
|
|
||||||
|
|
||||||
/// Register a disconnected entity with the context, having the given state
|
|
||||||
member private this.RegisterAs<'TEntity when 'TEntity : not struct> state e =
|
|
||||||
this.Entry<'TEntity>(e).State <- state
|
|
||||||
|
|
||||||
/// Add an entity instance to the context
|
|
||||||
member this.AddEntry e =
|
|
||||||
this.RegisterAs EntityState.Added e
|
|
||||||
|
|
||||||
/// Update the entity instance's values
|
|
||||||
member this.UpdateEntry e =
|
|
||||||
this.RegisterAs EntityState.Modified e
|
|
||||||
|
|
||||||
/// Retrieve all answered requests for the given user
|
|
||||||
member this.AnsweredRequests userId : JournalRequest seq =
|
|
||||||
upcast this.Journal
|
|
||||||
.Where(fun r -> r.userId = userId && r.lastStatus = "Answered")
|
|
||||||
.OrderByDescending(fun r -> r.asOf)
|
|
||||||
|
|
||||||
/// Retrieve the user's current journal
|
|
||||||
member this.JournalByUserId userId : JournalRequest seq =
|
|
||||||
upcast this.Journal
|
|
||||||
.Where(fun r -> r.userId = userId && r.lastStatus <> "Answered")
|
|
||||||
.OrderBy(fun r -> r.showAfter)
|
|
||||||
|
|
||||||
/// Retrieve a request by its ID and user ID
|
|
||||||
member this.TryRequestById reqId userId =
|
|
||||||
task {
|
|
||||||
let! req = this.Requests.AsNoTracking().FirstOrDefaultAsync(fun r -> r.requestId = reqId && r.userId = userId)
|
|
||||||
return Option.fromObject req
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieve notes for a request by its ID and user ID
|
|
||||||
member this.NotesById reqId userId =
|
|
||||||
task {
|
|
||||||
match! this.TryRequestById reqId userId with
|
|
||||||
| Some _ -> return this.Notes.AsNoTracking().Where(fun n -> n.requestId = reqId) |> List.ofSeq
|
|
||||||
| None -> return []
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieve a journal request by its ID and user ID
|
|
||||||
member this.TryJournalById reqId userId =
|
|
||||||
task {
|
|
||||||
let! req = this.Journal.FirstOrDefaultAsync(fun r -> r.requestId = reqId && r.userId = userId)
|
|
||||||
return Option.fromObject req
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieve a request, including its history and notes, by its ID and user ID
|
|
||||||
member this.TryFullRequestById requestId userId =
|
|
||||||
task {
|
|
||||||
match! this.TryJournalById requestId userId with
|
|
||||||
| Some req ->
|
|
||||||
let! fullReq =
|
|
||||||
this.Requests.AsNoTracking()
|
|
||||||
.Include(fun r -> r.history)
|
|
||||||
.Include(fun r -> r.notes)
|
|
||||||
.FirstOrDefaultAsync(fun r -> r.requestId = requestId && r.userId = userId)
|
|
||||||
match Option.fromObject fullReq with
|
|
||||||
| Some _ -> return Some { req with history = List.ofSeq fullReq.history; notes = List.ofSeq fullReq.notes }
|
|
||||||
| None -> return None
|
|
||||||
| None -> return None
|
|
||||||
}
|
|
||||||
@@ -1,321 +0,0 @@
|
|||||||
/// HTTP handlers for the myPrayerJournal API
|
|
||||||
[<RequireQualifiedAccess>]
|
|
||||||
module MyPrayerJournal.Api.Handlers
|
|
||||||
|
|
||||||
open FSharp.Control.Tasks.V2.ContextInsensitive
|
|
||||||
open Giraffe
|
|
||||||
open MyPrayerJournal
|
|
||||||
open System
|
|
||||||
|
|
||||||
/// Handler to return Vue files
|
|
||||||
module Vue =
|
|
||||||
|
|
||||||
/// The application index page
|
|
||||||
let app : HttpHandler = htmlFile "wwwroot/index.html"
|
|
||||||
|
|
||||||
|
|
||||||
/// Handlers for error conditions
|
|
||||||
module Error =
|
|
||||||
|
|
||||||
open Microsoft.Extensions.Logging
|
|
||||||
|
|
||||||
/// Handle errors
|
|
||||||
let error (ex : Exception) (log : ILogger) =
|
|
||||||
log.LogError (EventId(), ex, "An unhandled exception has occurred while executing the request.")
|
|
||||||
clearResponse >=> setStatusCode 500 >=> json ex.Message
|
|
||||||
|
|
||||||
/// Handle 404s from the API, sending known URL paths to the Vue app so that they can be handled there
|
|
||||||
let notFound : HttpHandler =
|
|
||||||
fun next ctx ->
|
|
||||||
[ "/journal"; "/legal"; "/request"; "/user" ]
|
|
||||||
|> List.filter ctx.Request.Path.Value.StartsWith
|
|
||||||
|> List.length
|
|
||||||
|> function
|
|
||||||
| 0 -> (setStatusCode 404 >=> json ([ "error", "not found" ] |> dict)) next ctx
|
|
||||||
| _ -> Vue.app next ctx
|
|
||||||
|
|
||||||
|
|
||||||
/// Handler helpers
|
|
||||||
[<AutoOpen>]
|
|
||||||
module private Helpers =
|
|
||||||
|
|
||||||
open Microsoft.AspNetCore.Http
|
|
||||||
open System.Threading.Tasks
|
|
||||||
open System.Security.Claims
|
|
||||||
|
|
||||||
/// Get the database context from DI
|
|
||||||
let db (ctx : HttpContext) =
|
|
||||||
ctx.GetService<AppDbContext> ()
|
|
||||||
|
|
||||||
/// Get the user's "sub" claim
|
|
||||||
let user (ctx : HttpContext) =
|
|
||||||
ctx.User.Claims |> Seq.tryFind (fun u -> u.Type = ClaimTypes.NameIdentifier)
|
|
||||||
|
|
||||||
/// Get the current user's ID
|
|
||||||
// NOTE: this may raise if you don't run the request through the authorize handler first
|
|
||||||
let userId ctx =
|
|
||||||
((user >> Option.get) ctx).Value
|
|
||||||
|
|
||||||
/// Return a 201 CREATED response
|
|
||||||
let created next ctx =
|
|
||||||
setStatusCode 201 next ctx
|
|
||||||
|
|
||||||
/// The "now" time in JavaScript
|
|
||||||
let jsNow () =
|
|
||||||
DateTime.UtcNow.Subtract(DateTime (1970, 1, 1, 0, 0, 0)).TotalSeconds |> int64 |> (*) 1000L
|
|
||||||
|
|
||||||
/// Handler to return a 403 Not Authorized reponse
|
|
||||||
let notAuthorized : HttpHandler =
|
|
||||||
setStatusCode 403 >=> fun _ _ -> Task.FromResult<HttpContext option> None
|
|
||||||
|
|
||||||
/// Handler to require authorization
|
|
||||||
let authorize : HttpHandler =
|
|
||||||
fun next ctx -> match user ctx with Some _ -> next ctx | None -> notAuthorized next ctx
|
|
||||||
|
|
||||||
/// Flip JSON result so we can pipe into it
|
|
||||||
let asJson<'T> next ctx (o : 'T) =
|
|
||||||
json o next ctx
|
|
||||||
|
|
||||||
|
|
||||||
/// Strongly-typed models for post requests
|
|
||||||
module Models =
|
|
||||||
|
|
||||||
/// A history entry addition (AKA request update)
|
|
||||||
[<CLIMutable>]
|
|
||||||
type HistoryEntry =
|
|
||||||
{ /// The status of the history update
|
|
||||||
status : string
|
|
||||||
/// The text of the update
|
|
||||||
updateText : string
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An additional note
|
|
||||||
[<CLIMutable>]
|
|
||||||
type NoteEntry =
|
|
||||||
{ /// The notes being added
|
|
||||||
notes : string
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Recurrence update
|
|
||||||
[<CLIMutable>]
|
|
||||||
type Recurrence =
|
|
||||||
{ /// The recurrence type
|
|
||||||
recurType : string
|
|
||||||
/// The recurrence cound
|
|
||||||
recurCount : int16
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A prayer request
|
|
||||||
[<CLIMutable>]
|
|
||||||
type Request =
|
|
||||||
{ /// The text of the request
|
|
||||||
requestText : string
|
|
||||||
/// The recurrence type
|
|
||||||
recurType : string
|
|
||||||
/// The recurrence count
|
|
||||||
recurCount : int16
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Reset the "showAfter" property on a request
|
|
||||||
[<CLIMutable>]
|
|
||||||
type Show =
|
|
||||||
{ /// The time after which the request should appear
|
|
||||||
showAfter : int64
|
|
||||||
}
|
|
||||||
|
|
||||||
/// The time until which a request should not appear in the journal
|
|
||||||
[<CLIMutable>]
|
|
||||||
type SnoozeUntil =
|
|
||||||
{ /// The time at which the request should reappear
|
|
||||||
until : int64
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// /api/journal URLs
|
|
||||||
module Journal =
|
|
||||||
|
|
||||||
/// GET /api/journal
|
|
||||||
let journal : HttpHandler =
|
|
||||||
authorize
|
|
||||||
>=> fun next ctx ->
|
|
||||||
userId ctx
|
|
||||||
|> (db ctx).JournalByUserId
|
|
||||||
|> asJson next ctx
|
|
||||||
|
|
||||||
|
|
||||||
/// /api/request URLs
|
|
||||||
module Request =
|
|
||||||
|
|
||||||
open NCuid
|
|
||||||
|
|
||||||
/// Ticks per recurrence
|
|
||||||
let private recurrence =
|
|
||||||
[ "immediate", 0L
|
|
||||||
"hours", 3600000L
|
|
||||||
"days", 86400000L
|
|
||||||
"weeks", 604800000L
|
|
||||||
]
|
|
||||||
|> Map.ofList
|
|
||||||
|
|
||||||
/// POST /api/request
|
|
||||||
let add : HttpHandler =
|
|
||||||
authorize
|
|
||||||
>=> fun next ctx ->
|
|
||||||
task {
|
|
||||||
let! r = ctx.BindJsonAsync<Models.Request> ()
|
|
||||||
let db = db ctx
|
|
||||||
let reqId = Cuid.Generate ()
|
|
||||||
let usrId = userId ctx
|
|
||||||
let now = jsNow ()
|
|
||||||
{ Request.empty with
|
|
||||||
requestId = reqId
|
|
||||||
userId = usrId
|
|
||||||
enteredOn = now
|
|
||||||
showAfter = now
|
|
||||||
recurType = r.recurType
|
|
||||||
recurCount = r.recurCount
|
|
||||||
}
|
|
||||||
|> db.AddEntry
|
|
||||||
{ History.empty with
|
|
||||||
requestId = reqId
|
|
||||||
asOf = now
|
|
||||||
status = "Created"
|
|
||||||
text = Some r.requestText
|
|
||||||
}
|
|
||||||
|> db.AddEntry
|
|
||||||
let! _ = db.SaveChangesAsync ()
|
|
||||||
match! db.TryJournalById reqId usrId with
|
|
||||||
| Some req -> return! (setStatusCode 201 >=> json req) next ctx
|
|
||||||
| None -> return! Error.notFound next ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
/// POST /api/request/[req-id]/history
|
|
||||||
let addHistory reqId : HttpHandler =
|
|
||||||
authorize
|
|
||||||
>=> fun next ctx ->
|
|
||||||
task {
|
|
||||||
let db = db ctx
|
|
||||||
match! db.TryRequestById reqId (userId ctx) with
|
|
||||||
| Some req ->
|
|
||||||
let! hist = ctx.BindJsonAsync<Models.HistoryEntry> ()
|
|
||||||
let now = jsNow ()
|
|
||||||
{ History.empty with
|
|
||||||
requestId = reqId
|
|
||||||
asOf = now
|
|
||||||
status = hist.status
|
|
||||||
text = match hist.updateText with null | "" -> None | x -> Some x
|
|
||||||
}
|
|
||||||
|> db.AddEntry
|
|
||||||
match hist.status with
|
|
||||||
| "Prayed" ->
|
|
||||||
db.UpdateEntry { req with showAfter = now + (recurrence.[req.recurType] * int64 req.recurCount) }
|
|
||||||
| _ -> ()
|
|
||||||
let! _ = db.SaveChangesAsync ()
|
|
||||||
return! created next ctx
|
|
||||||
| None -> return! Error.notFound next ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
/// POST /api/request/[req-id]/note
|
|
||||||
let addNote reqId : HttpHandler =
|
|
||||||
authorize
|
|
||||||
>=> fun next ctx ->
|
|
||||||
task {
|
|
||||||
let db = db ctx
|
|
||||||
match! db.TryRequestById reqId (userId ctx) with
|
|
||||||
| Some _ ->
|
|
||||||
let! notes = ctx.BindJsonAsync<Models.NoteEntry> ()
|
|
||||||
{ Note.empty with
|
|
||||||
requestId = reqId
|
|
||||||
asOf = jsNow ()
|
|
||||||
notes = notes.notes
|
|
||||||
}
|
|
||||||
|> db.AddEntry
|
|
||||||
let! _ = db.SaveChangesAsync ()
|
|
||||||
return! created next ctx
|
|
||||||
| None -> return! Error.notFound next ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
/// GET /api/requests/answered
|
|
||||||
let answered : HttpHandler =
|
|
||||||
authorize
|
|
||||||
>=> fun next ctx ->
|
|
||||||
userId ctx
|
|
||||||
|> (db ctx).AnsweredRequests
|
|
||||||
|> asJson next ctx
|
|
||||||
|
|
||||||
/// GET /api/request/[req-id]
|
|
||||||
let get reqId : HttpHandler =
|
|
||||||
authorize
|
|
||||||
>=> fun next ctx ->
|
|
||||||
task {
|
|
||||||
match! (db ctx).TryJournalById reqId (userId ctx) with
|
|
||||||
| Some req -> return! json req next ctx
|
|
||||||
| None -> return! Error.notFound next ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
/// GET /api/request/[req-id]/full
|
|
||||||
let getFull reqId : HttpHandler =
|
|
||||||
authorize
|
|
||||||
>=> fun next ctx ->
|
|
||||||
task {
|
|
||||||
match! (db ctx).TryFullRequestById reqId (userId ctx) with
|
|
||||||
| Some req -> return! json req next ctx
|
|
||||||
| None -> return! Error.notFound next ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
/// GET /api/request/[req-id]/notes
|
|
||||||
let getNotes reqId : HttpHandler =
|
|
||||||
authorize
|
|
||||||
>=> fun next ctx ->
|
|
||||||
task {
|
|
||||||
let! notes = (db ctx).NotesById reqId (userId ctx)
|
|
||||||
return! json notes next ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
/// PATCH /api/request/[req-id]/show
|
|
||||||
let show reqId : HttpHandler =
|
|
||||||
authorize
|
|
||||||
>=> fun next ctx ->
|
|
||||||
task {
|
|
||||||
let db = db ctx
|
|
||||||
match! db.TryRequestById reqId (userId ctx) with
|
|
||||||
| Some req ->
|
|
||||||
let! show = ctx.BindJsonAsync<Models.Show> ()
|
|
||||||
{ req with showAfter = show.showAfter }
|
|
||||||
|> db.UpdateEntry
|
|
||||||
let! _ = db.SaveChangesAsync ()
|
|
||||||
return! setStatusCode 204 next ctx
|
|
||||||
| None -> return! Error.notFound next ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
/// PATCH /api/request/[req-id]/snooze
|
|
||||||
let snooze reqId : HttpHandler =
|
|
||||||
authorize
|
|
||||||
>=> fun next ctx ->
|
|
||||||
task {
|
|
||||||
let db = db ctx
|
|
||||||
match! db.TryRequestById reqId (userId ctx) with
|
|
||||||
| Some req ->
|
|
||||||
let! until = ctx.BindJsonAsync<Models.SnoozeUntil> ()
|
|
||||||
{ req with snoozedUntil = until.until; showAfter = until.until }
|
|
||||||
|> db.UpdateEntry
|
|
||||||
let! _ = db.SaveChangesAsync ()
|
|
||||||
return! setStatusCode 204 next ctx
|
|
||||||
| None -> return! Error.notFound next ctx
|
|
||||||
}
|
|
||||||
|
|
||||||
/// PATCH /api/request/[req-id]/recurrence
|
|
||||||
let updateRecurrence reqId : HttpHandler =
|
|
||||||
authorize
|
|
||||||
>=> fun next ctx ->
|
|
||||||
task {
|
|
||||||
let db = db ctx
|
|
||||||
match! db.TryRequestById reqId (userId ctx) with
|
|
||||||
| Some req ->
|
|
||||||
let! recur = ctx.BindJsonAsync<Models.Recurrence> ()
|
|
||||||
{ req with recurType = recur.recurType; recurCount = recur.recurCount }
|
|
||||||
|> db.UpdateEntry
|
|
||||||
let! _ = db.SaveChangesAsync ()
|
|
||||||
return! setStatusCode 204 next ctx
|
|
||||||
| None -> return! Error.notFound next ctx
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>netcoreapp2.2</TargetFramework>
|
|
||||||
<Version>1.2.1.0</Version>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Compile Include="Data.fs" />
|
|
||||||
<Compile Include="Handlers.fs" />
|
|
||||||
<Compile Include="Program.fs" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="FSharp.EFCore.OptionConverter" Version="1.0.0" />
|
|
||||||
<PackageReference Include="Giraffe" Version="3.6.0" />
|
|
||||||
<PackageReference Include="Giraffe.TokenRouter" Version="1.0.0" />
|
|
||||||
<PackageReference Include="Microsoft.AspNetCore.App" />
|
|
||||||
<PackageReference Include="Microsoft.FSharpLu" Version="0.10.29" />
|
|
||||||
<PackageReference Include="Microsoft.FSharpLu.Json" Version="0.10.29" />
|
|
||||||
<PackageReference Include="NCuid.NetCore" Version="1.0.1" />
|
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.2.0" />
|
|
||||||
<PackageReference Include="TaskBuilder.fs" Version="2.1.0" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Update="FSharp.Core" Version="4.6.2" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="wwwroot\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,139 +0,0 @@
|
|||||||
namespace MyPrayerJournal.Api
|
|
||||||
|
|
||||||
open Microsoft.AspNetCore.Builder
|
|
||||||
open Microsoft.AspNetCore.Hosting
|
|
||||||
open System
|
|
||||||
|
|
||||||
/// Configuration functions for the application
|
|
||||||
module Configure =
|
|
||||||
|
|
||||||
open Giraffe
|
|
||||||
open Giraffe.Serialization
|
|
||||||
open Giraffe.TokenRouter
|
|
||||||
open Microsoft.AspNetCore.Authentication.JwtBearer
|
|
||||||
open Microsoft.AspNetCore.Server.Kestrel.Core
|
|
||||||
open Microsoft.EntityFrameworkCore
|
|
||||||
open Microsoft.Extensions.Configuration
|
|
||||||
open Microsoft.Extensions.DependencyInjection
|
|
||||||
open Microsoft.Extensions.Logging
|
|
||||||
open Microsoft.FSharpLu.Json
|
|
||||||
open MyPrayerJournal
|
|
||||||
open Newtonsoft.Json
|
|
||||||
|
|
||||||
/// Set up the configuration for the app
|
|
||||||
let configuration (ctx : WebHostBuilderContext) (cfg : IConfigurationBuilder) =
|
|
||||||
cfg.SetBasePath(ctx.HostingEnvironment.ContentRootPath)
|
|
||||||
.AddJsonFile("appsettings.json", optional = true, reloadOnChange = true)
|
|
||||||
.AddJsonFile(sprintf "appsettings.%s.json" ctx.HostingEnvironment.EnvironmentName)
|
|
||||||
.AddEnvironmentVariables()
|
|
||||||
|> ignore
|
|
||||||
|
|
||||||
/// Configure Kestrel from appsettings.json
|
|
||||||
let kestrel (ctx : WebHostBuilderContext) (opts : KestrelServerOptions) =
|
|
||||||
(ctx.Configuration.GetSection >> opts.Configure >> ignore) "Kestrel"
|
|
||||||
|
|
||||||
/// Custom settings for the JSON serializer (uses compact representation for options and DUs)
|
|
||||||
let jsonSettings =
|
|
||||||
let x = NewtonsoftJsonSerializer.DefaultSettings
|
|
||||||
x.Converters.Add (CompactUnionJsonConverter (true))
|
|
||||||
x.NullValueHandling <- NullValueHandling.Ignore
|
|
||||||
x.MissingMemberHandling <- MissingMemberHandling.Error
|
|
||||||
x.Formatting <- Formatting.Indented
|
|
||||||
x
|
|
||||||
|
|
||||||
/// Configure dependency injection
|
|
||||||
let services (sc : IServiceCollection) =
|
|
||||||
use sp = sc.BuildServiceProvider()
|
|
||||||
let cfg = sp.GetRequiredService<IConfiguration> ()
|
|
||||||
sc.AddGiraffe()
|
|
||||||
.AddAuthentication(
|
|
||||||
/// Use HTTP "Bearer" authentication with JWTs
|
|
||||||
fun opts ->
|
|
||||||
opts.DefaultAuthenticateScheme <- JwtBearerDefaults.AuthenticationScheme
|
|
||||||
opts.DefaultChallengeScheme <- JwtBearerDefaults.AuthenticationScheme)
|
|
||||||
.AddJwtBearer(
|
|
||||||
/// Configure JWT options with Auth0 options from configuration
|
|
||||||
fun opts ->
|
|
||||||
let jwtCfg = cfg.GetSection "Auth0"
|
|
||||||
opts.Authority <- sprintf "https://%s/" jwtCfg.["Domain"]
|
|
||||||
opts.Audience <- jwtCfg.["Id"])
|
|
||||||
|> ignore
|
|
||||||
sc.AddDbContext<AppDbContext>(fun opts -> opts.UseNpgsql(cfg.GetConnectionString "mpj") |> ignore)
|
|
||||||
.AddSingleton<IJsonSerializer>(NewtonsoftJsonSerializer jsonSettings)
|
|
||||||
|> ignore
|
|
||||||
|
|
||||||
/// Routes for the available URLs within myPrayerJournal
|
|
||||||
let webApp =
|
|
||||||
router Handlers.Error.notFound [
|
|
||||||
route "/" Handlers.Vue.app
|
|
||||||
subRoute "/api/" [
|
|
||||||
GET [
|
|
||||||
route "journal" Handlers.Journal.journal
|
|
||||||
subRoute "request" [
|
|
||||||
route "s/answered" Handlers.Request.answered
|
|
||||||
routef "/%s/full" Handlers.Request.getFull
|
|
||||||
routef "/%s/notes" Handlers.Request.getNotes
|
|
||||||
routef "/%s" Handlers.Request.get
|
|
||||||
]
|
|
||||||
]
|
|
||||||
PATCH [
|
|
||||||
subRoute "request" [
|
|
||||||
routef "/%s/recurrence" Handlers.Request.updateRecurrence
|
|
||||||
routef "/%s/show" Handlers.Request.show
|
|
||||||
routef "/%s/snooze" Handlers.Request.snooze
|
|
||||||
]
|
|
||||||
]
|
|
||||||
POST [
|
|
||||||
subRoute "request" [
|
|
||||||
route "" Handlers.Request.add
|
|
||||||
routef "/%s/history" Handlers.Request.addHistory
|
|
||||||
routef "/%s/note" Handlers.Request.addNote
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
|
|
||||||
/// Configure the web application
|
|
||||||
let application (app : IApplicationBuilder) =
|
|
||||||
let env = app.ApplicationServices.GetService<IHostingEnvironment> ()
|
|
||||||
match env.IsDevelopment () with
|
|
||||||
| true -> app.UseDeveloperExceptionPage ()
|
|
||||||
| false -> app.UseGiraffeErrorHandler Handlers.Error.error
|
|
||||||
|> function
|
|
||||||
| a ->
|
|
||||||
a.UseAuthentication()
|
|
||||||
.UseStaticFiles()
|
|
||||||
.UseGiraffe webApp
|
|
||||||
|> ignore
|
|
||||||
|
|
||||||
/// Configure logging
|
|
||||||
let logging (log : ILoggingBuilder) =
|
|
||||||
let env = log.Services.BuildServiceProvider().GetService<IHostingEnvironment> ()
|
|
||||||
match env.IsDevelopment () with
|
|
||||||
| true -> log
|
|
||||||
| false -> log.AddFilter(fun l -> l > LogLevel.Information)
|
|
||||||
|> function l -> l.AddConsole().AddDebug()
|
|
||||||
|> ignore
|
|
||||||
|
|
||||||
|
|
||||||
module Program =
|
|
||||||
|
|
||||||
open System.IO
|
|
||||||
|
|
||||||
let exitCode = 0
|
|
||||||
|
|
||||||
let CreateWebHostBuilder _ =
|
|
||||||
let contentRoot = Directory.GetCurrentDirectory ()
|
|
||||||
WebHostBuilder()
|
|
||||||
.UseContentRoot(contentRoot)
|
|
||||||
.ConfigureAppConfiguration(Configure.configuration)
|
|
||||||
.UseKestrel(Configure.kestrel)
|
|
||||||
.UseWebRoot(Path.Combine (contentRoot, "wwwroot"))
|
|
||||||
.ConfigureServices(Configure.services)
|
|
||||||
.ConfigureLogging(Configure.logging)
|
|
||||||
.Configure(Action<IApplicationBuilder> Configure.application)
|
|
||||||
|
|
||||||
[<EntryPoint>]
|
|
||||||
let main args =
|
|
||||||
CreateWebHostBuilder(args).Build().Run()
|
|
||||||
exitCode
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
{
|
|
||||||
"iisSettings": {
|
|
||||||
"windowsAuthentication": false,
|
|
||||||
"anonymousAuthentication": true,
|
|
||||||
"iisExpress": {
|
|
||||||
"applicationUrl": "http://localhost:61905",
|
|
||||||
"sslPort": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"profiles": {
|
|
||||||
"IIS Express": {
|
|
||||||
"commandName": "IISExpress",
|
|
||||||
"launchBrowser": true,
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"MyPrayerJournal.Api": {
|
|
||||||
"commandName": "Project",
|
|
||||||
"launchBrowser": true,
|
|
||||||
"applicationUrl": "http://localhost:5000",
|
|
||||||
"environmentVariables": {
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"Kestrel": {
|
|
||||||
"EndPoints": {
|
|
||||||
"Http": {
|
|
||||||
"Url": "http://localhost:3000"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio 15
|
|
||||||
VisualStudioVersion = 15.0.27703.2035
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "MyPrayerJournal.Api", "MyPrayerJournal.Api\MyPrayerJournal.Api.fsproj", "{E0E5240C-00DC-428A-899A-DA4F06625B8A}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{E0E5240C-00DC-428A-899A-DA4F06625B8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{E0E5240C-00DC-428A-899A-DA4F06625B8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{E0E5240C-00DC-428A-899A-DA4F06625B8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{E0E5240C-00DC-428A-899A-DA4F06625B8A}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
||||||
SolutionGuid = {7EAB6243-94B3-49A5-BA64-7F01B8BE7CB9}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
> 1%
|
|
||||||
last 2 versions
|
|
||||||
not ie <= 8
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
root: true,
|
|
||||||
env: {
|
|
||||||
node: true
|
|
||||||
},
|
|
||||||
'extends': [
|
|
||||||
'plugin:vue/essential',
|
|
||||||
'@vue/standard'
|
|
||||||
],
|
|
||||||
rules: {
|
|
||||||
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
|
|
||||||
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
|
|
||||||
},
|
|
||||||
parserOptions: {
|
|
||||||
parser: 'babel-eslint'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
24
src/app/.gitignore
vendored
24
src/app/.gitignore
vendored
@@ -1,24 +0,0 @@
|
|||||||
.DS_Store
|
|
||||||
node_modules
|
|
||||||
/dist
|
|
||||||
|
|
||||||
# local env files
|
|
||||||
.env.local
|
|
||||||
.env.*.local
|
|
||||||
|
|
||||||
# Log files
|
|
||||||
npm-debug.log*
|
|
||||||
yarn-debug.log*
|
|
||||||
yarn-error.log*
|
|
||||||
|
|
||||||
# Editor directories and files
|
|
||||||
.idea
|
|
||||||
.vscode
|
|
||||||
*.suo
|
|
||||||
*.ntvs*
|
|
||||||
*.njsproj
|
|
||||||
*.sln
|
|
||||||
*.sw*
|
|
||||||
|
|
||||||
# Auth0 settings
|
|
||||||
src/auth/auth0-variables.js
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
plugins: {
|
|
||||||
autoprefixer: {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) 2017 Daniel J. Summers
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE.
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
presets: [
|
|
||||||
'@vue/app'
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "my-prayer-journal",
|
|
||||||
"version": "1.2.1",
|
|
||||||
"description": "myPrayerJournal - Front End",
|
|
||||||
"author": "Daniel J. Summers <daniel@bitbadger.solutions>",
|
|
||||||
"private": true,
|
|
||||||
"scripts": {
|
|
||||||
"serve": "vue-cli-service serve",
|
|
||||||
"build": "vue-cli-service build --modern",
|
|
||||||
"lint": "vue-cli-service lint",
|
|
||||||
"apistart": "cd ../api/MyPrayerJournal.Api && dotnet run",
|
|
||||||
"vue": "vue-cli-service build --modern && cd ../api/MyPrayerJournal.Api && dotnet run",
|
|
||||||
"publish": "vue-cli-service build --modern && cd ../api/MyPrayerJournal.Api && dotnet publish -c Release"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"auth0-js": "^9.7.3",
|
|
||||||
"axios": "^0.19.0",
|
|
||||||
"moment": "^2.18.1",
|
|
||||||
"vue": "^2.5.15",
|
|
||||||
"vue-progressbar": "^0.7.3",
|
|
||||||
"vue-router": "^3.0.0",
|
|
||||||
"vue-toast": "^3.1.0",
|
|
||||||
"vuex": "^3.0.1"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@vue/cli-plugin-babel": "^3.0.0",
|
|
||||||
"@vue/cli-plugin-eslint": "^3.0.0",
|
|
||||||
"@vue/cli-service": "^3.0.0",
|
|
||||||
"@vue/eslint-config-standard": "^4.0.0",
|
|
||||||
"pug": "^2.0.1",
|
|
||||||
"pug-plain-loader": "^1.0.0",
|
|
||||||
"vue-template-compiler": "^2.5.17"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 KiB |
@@ -1,19 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
||||||
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
|
||||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="preload" as="style">
|
|
||||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
|
||||||
<title>myPrayerJournal</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<noscript>
|
|
||||||
<strong>We're sorry but newapp doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
|
||||||
</noscript>
|
|
||||||
<div id="app"></div>
|
|
||||||
<!-- built files will be auto injected -->
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,244 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
#app(role='application')
|
|
||||||
navigation
|
|
||||||
#content
|
|
||||||
router-view
|
|
||||||
vue-progress-bar
|
|
||||||
toast(ref='toast')
|
|
||||||
footer.mpj-text-right.mpj-muted-text
|
|
||||||
p
|
|
||||||
| myPrayerJournal v{{ version }}
|
|
||||||
br
|
|
||||||
em: small.
|
|
||||||
#[router-link(:to="{ name: 'PrivacyPolicy' }") Privacy Policy] •
|
|
||||||
#[router-link(:to="{ name: 'TermsOfService' }") Terms of Service] •
|
|
||||||
#[a(href='https://github.com/bit-badger/myprayerjournal' target='_blank') Developed] and hosted by
|
|
||||||
#[a(href='https://bitbadger.solutions' target='_blank') Bit Badger Solutions]
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import Navigation from './components/common/Navigation.vue'
|
|
||||||
|
|
||||||
import { version } from '../package.json'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'app',
|
|
||||||
components: {
|
|
||||||
Navigation
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {}
|
|
||||||
},
|
|
||||||
mounted () {
|
|
||||||
this.$refs.toast.setOptions({ position: 'bottom right' })
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
toast () {
|
|
||||||
return this.$refs.toast
|
|
||||||
},
|
|
||||||
version () {
|
|
||||||
return version.endsWith('.0') ? version.substr(0, version.length - 2) : version
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
html, body {
|
|
||||||
background-color: whitesmoke;
|
|
||||||
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
|
|
||||||
font-size: 1rem;
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
padding-top: 50px;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
h1, h2, h3, h4, h5 {
|
|
||||||
font-weight: 500;
|
|
||||||
margin-top: 0;
|
|
||||||
}
|
|
||||||
h1 {
|
|
||||||
font-size: 2.5rem;
|
|
||||||
}
|
|
||||||
h2 {
|
|
||||||
font-size: 2rem;
|
|
||||||
}
|
|
||||||
h3 {
|
|
||||||
font-size: 1.75rem;
|
|
||||||
}
|
|
||||||
h4 {
|
|
||||||
font-size: 1.5rem;
|
|
||||||
}
|
|
||||||
h5 {
|
|
||||||
font-size: 1.25rem;
|
|
||||||
}
|
|
||||||
p {
|
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
|
||||||
input, textarea, select {
|
|
||||||
border-radius: .25rem;
|
|
||||||
font-size: 1rem;
|
|
||||||
}
|
|
||||||
textarea {
|
|
||||||
font-family: "SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace;
|
|
||||||
}
|
|
||||||
input, select {
|
|
||||||
font-family: inherit;
|
|
||||||
}
|
|
||||||
button,
|
|
||||||
a[role="button"] {
|
|
||||||
border: solid 1px #050;
|
|
||||||
border-radius: .5rem;
|
|
||||||
background-color: rgb(235, 235, 235);
|
|
||||||
padding: .25rem;
|
|
||||||
font-size: 1rem;
|
|
||||||
}
|
|
||||||
a[role="button"]:link,
|
|
||||||
a[role="button"]:visited {
|
|
||||||
color: black;
|
|
||||||
}
|
|
||||||
button.primary,
|
|
||||||
a[role="button"].primary {
|
|
||||||
background-color: white;
|
|
||||||
border-width: 3px;
|
|
||||||
}
|
|
||||||
button:hover,
|
|
||||||
a[role="button"]:hover {
|
|
||||||
cursor: pointer;
|
|
||||||
background-color: #050;
|
|
||||||
color: white;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
label {
|
|
||||||
font-variant: small-caps;
|
|
||||||
font-size: 1.1rem;
|
|
||||||
}
|
|
||||||
label.normal {
|
|
||||||
font-variant: unset;
|
|
||||||
font-size: unset;
|
|
||||||
}
|
|
||||||
footer {
|
|
||||||
border-top: solid 1px lightgray;
|
|
||||||
margin-top: 1rem;
|
|
||||||
padding: 0 1rem;
|
|
||||||
}
|
|
||||||
footer p {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
a:link, a:visited {
|
|
||||||
color: #050;
|
|
||||||
text-decoration: none;
|
|
||||||
}
|
|
||||||
a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
.mpj-main-content {
|
|
||||||
max-width: 60rem;
|
|
||||||
margin: auto;
|
|
||||||
}
|
|
||||||
.mpj-main-content-wide {
|
|
||||||
margin: .5rem;
|
|
||||||
}
|
|
||||||
@media screen and (max-width: 21rem) {
|
|
||||||
.mpj-main-content-wide {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.mpj-request-text {
|
|
||||||
white-space: pre-line;
|
|
||||||
}
|
|
||||||
.mpj-request-list p {
|
|
||||||
border-top: solid 1px lightgray;
|
|
||||||
}
|
|
||||||
.mpj-request-list p:first-child {
|
|
||||||
border-top: none;
|
|
||||||
}
|
|
||||||
.mpj-request-log {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
.mpj-request-log thead th {
|
|
||||||
border-top: solid 1px lightgray;
|
|
||||||
border-bottom: solid 2px lightgray;
|
|
||||||
text-align: left;
|
|
||||||
}
|
|
||||||
.mpj-request-log tbody td {
|
|
||||||
border-bottom: dotted 1px lightgray;
|
|
||||||
vertical-align: top;
|
|
||||||
}
|
|
||||||
.mpj-bg {
|
|
||||||
background-image: -webkit-gradient(linear, left top, left bottom, from(#050), to(whitesmoke));
|
|
||||||
background-image: -webkit-linear-gradient(top, #050, whitesmoke);
|
|
||||||
background-image: -moz-linear-gradient(top, #050, whitesmoke);
|
|
||||||
background-image: linear-gradient(to bottom, #050, whitesmoke);
|
|
||||||
}
|
|
||||||
.mpj-text-center {
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
.mpj-text-nowrap {
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
.mpj-text-right {
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
.mpj-muted-text {
|
|
||||||
color: rgba(0, 0, 0, .6);
|
|
||||||
}
|
|
||||||
.mpj-narrow {
|
|
||||||
max-width: 40rem;
|
|
||||||
margin: auto;
|
|
||||||
}
|
|
||||||
.mpj-skinny {
|
|
||||||
max-width: 20rem;
|
|
||||||
margin: auto;
|
|
||||||
}
|
|
||||||
.mpj-full-width {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
.mpj-modal {
|
|
||||||
position: fixed;
|
|
||||||
z-index: 8;
|
|
||||||
left: 0;
|
|
||||||
top: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
overflow: auto;
|
|
||||||
background-color: rgba(0, 0, 0, .4);
|
|
||||||
}
|
|
||||||
.mpj-modal-content {
|
|
||||||
background-color: whitesmoke;
|
|
||||||
border: solid 1px #050;
|
|
||||||
border-radius: .5rem;
|
|
||||||
animation-name: animatetop;
|
|
||||||
animation-duration: 0.4s;
|
|
||||||
padding: 1rem;
|
|
||||||
margin-top: 4rem;
|
|
||||||
}
|
|
||||||
@keyframes animatetop {
|
|
||||||
from {
|
|
||||||
top: -300px;
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
to {
|
|
||||||
top: 0;
|
|
||||||
opacity: 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.mpj-modal-content header {
|
|
||||||
margin: -1rem -1rem .5rem;
|
|
||||||
border-radius: .4rem;
|
|
||||||
}
|
|
||||||
.mpj-modal-content header h5 {
|
|
||||||
color: white;
|
|
||||||
margin: 0;
|
|
||||||
padding: 1rem;
|
|
||||||
}
|
|
||||||
.mpj-margin {
|
|
||||||
margin-left: 1rem;
|
|
||||||
margin-right: 1rem;
|
|
||||||
}
|
|
||||||
.material-icons {
|
|
||||||
vertical-align: middle;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
import axios from 'axios'
|
|
||||||
|
|
||||||
const http = axios.create({
|
|
||||||
baseURL: `${location.protocol}//${location.host}/api/`
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
|
||||||
* API access for myPrayerJournal
|
|
||||||
*/
|
|
||||||
export default {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the bearer token for all future requests
|
|
||||||
* @param {string} token The token to use to identify the user to the server
|
|
||||||
*/
|
|
||||||
setBearer: token => { http.defaults.headers.common['authorization'] = `Bearer ${token}` },
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Remove the bearer token
|
|
||||||
*/
|
|
||||||
removeBearer: () => delete http.defaults.headers.common['authorization'],
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a note for a prayer request
|
|
||||||
* @param {string} requestId The Id of the request to which the note applies
|
|
||||||
* @param {string} notes The notes to be added
|
|
||||||
*/
|
|
||||||
addNote: (requestId, notes) => http.post(`request/${requestId}/note`, { notes }),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a new prayer request
|
|
||||||
* @param {string} requestText The text of the request to be added
|
|
||||||
* @param {string} recurType The type of recurrence for this request
|
|
||||||
* @param {number} recurCount The number of intervals of recurrence
|
|
||||||
*/
|
|
||||||
addRequest: (requestText, recurType, recurCount) => http.post('request', { requestText, recurType, recurCount }),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all answered requests, along with the text they had when it was answered
|
|
||||||
*/
|
|
||||||
getAnsweredRequests: () => http.get('requests/answered'),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a prayer request (full; includes all history and notes)
|
|
||||||
* @param {string} requestId The Id of the request to retrieve
|
|
||||||
*/
|
|
||||||
getFullRequest: requestId => http.get(`request/${requestId}/full`),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get past notes for a prayer request
|
|
||||||
* @param {string} requestId The Id of the request for which notes should be retrieved
|
|
||||||
*/
|
|
||||||
getNotes: requestId => http.get(`request/${requestId}/notes`),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a prayer request (journal-style; only latest update)
|
|
||||||
* @param {string} requestId The Id of the request to retrieve
|
|
||||||
*/
|
|
||||||
getRequest: requestId => http.get(`request/${requestId}`),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all prayer requests and their most recent updates
|
|
||||||
*/
|
|
||||||
journal: () => http.get('journal'),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show a request after the given date (used for "show now")
|
|
||||||
* @param {string} requestId The ID of the request which should be shown
|
|
||||||
* @param {number} showAfter The ticks after which the request should be shown
|
|
||||||
*/
|
|
||||||
showRequest: (requestId, showAfter) => http.patch(`request/${requestId}/show`, { showAfter }),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Snooze a request until the given time
|
|
||||||
* @param {string} requestId The ID of the prayer request to be snoozed
|
|
||||||
* @param {number} until The ticks until which the request should be snoozed
|
|
||||||
*/
|
|
||||||
snoozeRequest: (requestId, until) => http.patch(`request/${requestId}/snooze`, { until }),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update recurrence for a prayer request
|
|
||||||
* @param {string} requestId The ID of the prayer request for which recurrence is being updated
|
|
||||||
* @param {string} recurType The type of recurrence to set
|
|
||||||
* @param {number} recurCount The number of recurrence intervals to set
|
|
||||||
*/
|
|
||||||
updateRecurrence: (requestId, recurType, recurCount) =>
|
|
||||||
http.patch(`request/${requestId}/recurrence`, { recurType, recurCount }),
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update a prayer request
|
|
||||||
* @param {string} requestId The ID of the request to be updated
|
|
||||||
* @param {string} status The status of the update
|
|
||||||
* @param {string} updateText The text of the update (optional)
|
|
||||||
*/
|
|
||||||
updateRequest: (requestId, status, updateText) => http.post(`request/${requestId}/history`, { status, updateText })
|
|
||||||
}
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
import auth0 from 'auth0-js'
|
|
||||||
|
|
||||||
import AUTH_CONFIG from './auth0-variables'
|
|
||||||
import mutations from '@/store/mutation-types'
|
|
||||||
|
|
||||||
var tokenRenewalTimeout
|
|
||||||
|
|
||||||
export default class AuthService {
|
|
||||||
constructor () {
|
|
||||||
this.login = this.login.bind(this)
|
|
||||||
this.setSession = this.setSession.bind(this)
|
|
||||||
this.logout = this.logout.bind(this)
|
|
||||||
this.isAuthenticated = this.isAuthenticated.bind(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
auth0 = new auth0.WebAuth({
|
|
||||||
domain: AUTH_CONFIG.domain,
|
|
||||||
clientID: AUTH_CONFIG.clientId,
|
|
||||||
redirectUri: AUTH_CONFIG.appDomain + AUTH_CONFIG.callbackUrl,
|
|
||||||
audience: `https://${AUTH_CONFIG.domain}/userinfo`,
|
|
||||||
responseType: 'token id_token',
|
|
||||||
scope: 'openid profile email'
|
|
||||||
})
|
|
||||||
|
|
||||||
login () {
|
|
||||||
this.auth0.authorize()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Promisified parseHash function
|
|
||||||
*/
|
|
||||||
parseHash () {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.auth0.parseHash((err, authResult) => {
|
|
||||||
if (err) {
|
|
||||||
reject(err)
|
|
||||||
} else {
|
|
||||||
resolve(authResult)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Promisified userInfo function
|
|
||||||
*
|
|
||||||
* @param token The auth token from the login result
|
|
||||||
*/
|
|
||||||
userInfo (token) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.auth0.client.userInfo(token, (err, user) => {
|
|
||||||
if (err) {
|
|
||||||
reject(err)
|
|
||||||
} else {
|
|
||||||
resolve(user)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
handleAuthentication (store, router) {
|
|
||||||
this.parseHash()
|
|
||||||
.then(authResult => {
|
|
||||||
if (authResult && authResult.accessToken && authResult.idToken) {
|
|
||||||
this.setSession(authResult)
|
|
||||||
this.userInfo(authResult.accessToken)
|
|
||||||
.then(user => {
|
|
||||||
store.commit(mutations.USER_LOGGED_ON, user)
|
|
||||||
router.replace('/journal')
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
router.replace('/')
|
|
||||||
console.log(err)
|
|
||||||
alert(`Error: ${err.error}. Check the console for further details.`)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
scheduleRenewal () {
|
|
||||||
let expiresAt = JSON.parse(localStorage.getItem('expires_at'))
|
|
||||||
let delay = expiresAt - Date.now()
|
|
||||||
if (delay > 0) {
|
|
||||||
tokenRenewalTimeout = setTimeout(() => {
|
|
||||||
this.renewToken()
|
|
||||||
}, delay)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setSession (authResult) {
|
|
||||||
// Set the time that the access token will expire at
|
|
||||||
let expiresAt = JSON.stringify(
|
|
||||||
authResult.expiresIn * 1000 + new Date().getTime()
|
|
||||||
)
|
|
||||||
localStorage.setItem('access_token', authResult.accessToken)
|
|
||||||
localStorage.setItem('id_token', authResult.idToken)
|
|
||||||
localStorage.setItem('expires_at', expiresAt)
|
|
||||||
this.scheduleRenewal()
|
|
||||||
}
|
|
||||||
|
|
||||||
renewToken () {
|
|
||||||
console.log('attempting renewal...')
|
|
||||||
this.auth0.renewAuth(
|
|
||||||
{
|
|
||||||
audience: `https://${AUTH_CONFIG.domain}/userinfo`,
|
|
||||||
redirectUri: `${AUTH_CONFIG.appDomain}/static/silent.html`,
|
|
||||||
usePostMessage: true
|
|
||||||
},
|
|
||||||
(err, result) => {
|
|
||||||
if (err) {
|
|
||||||
console.log(err)
|
|
||||||
} else {
|
|
||||||
this.setSession(result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
logout (store, router) {
|
|
||||||
// Clear access token and ID token from local storage
|
|
||||||
clearTimeout(tokenRenewalTimeout)
|
|
||||||
localStorage.removeItem('access_token')
|
|
||||||
localStorage.removeItem('id_token')
|
|
||||||
localStorage.removeItem('expires_at')
|
|
||||||
localStorage.setItem('user_profile', JSON.stringify({}))
|
|
||||||
// navigate to the home route
|
|
||||||
store.commit(mutations.USER_LOGGED_OFF)
|
|
||||||
router.replace('/')
|
|
||||||
}
|
|
||||||
|
|
||||||
isAuthenticated () {
|
|
||||||
// Check whether the current time is past the access token's expiry time
|
|
||||||
let expiresAt = JSON.parse(localStorage.getItem('expires_at'))
|
|
||||||
return new Date().getTime() < expiresAt
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
article.mpj-main-content(role='main')
|
|
||||||
page-title(title='Welcome!'
|
|
||||||
hideOnPage='true')
|
|
||||||
p
|
|
||||||
p.
|
|
||||||
myPrayerJournal is a place where individuals can record their prayer requests, record that they prayed for them,
|
|
||||||
update them as God moves in the situation, and record a final answer received on that request. It will also allow
|
|
||||||
individuals to review their answered prayers.
|
|
||||||
p.
|
|
||||||
This site is currently in beta, but it is open and available to the general public. To get started, simply click
|
|
||||||
the “Log 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.
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'home'
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
article.mpj-main-content-wide(role='main')
|
|
||||||
page-title(:title='title')
|
|
||||||
p(v-if='isLoadingJournal') Loading your prayer journal...
|
|
||||||
template(v-else)
|
|
||||||
.mpj-text-center
|
|
||||||
router-link(:to="{ name: 'EditRequest', params: { id: 'new' } }"
|
|
||||||
role='button').
|
|
||||||
#[md-icon(icon='add_box')] Add a New Request
|
|
||||||
br
|
|
||||||
.mpj-journal(v-if='journal.length > 0')
|
|
||||||
request-card(v-for='request in journal'
|
|
||||||
:key='request.requestId'
|
|
||||||
:request='request'
|
|
||||||
:events='eventBus'
|
|
||||||
:toast='toast')
|
|
||||||
p.text-center(v-else): em.
|
|
||||||
No requests found; click the “Add a New Request” button to add one
|
|
||||||
notes-edit(:events='eventBus'
|
|
||||||
:toast='toast')
|
|
||||||
snooze-request(:events='eventBus'
|
|
||||||
:toast='toast')
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import Vue from 'vue'
|
|
||||||
import { mapState } from 'vuex'
|
|
||||||
|
|
||||||
import NotesEdit from './request/NotesEdit'
|
|
||||||
import RequestCard from './request/RequestCard'
|
|
||||||
import SnoozeRequest from './request/SnoozeRequest'
|
|
||||||
|
|
||||||
import actions from '@/store/action-types'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'journal',
|
|
||||||
components: {
|
|
||||||
NotesEdit,
|
|
||||||
RequestCard,
|
|
||||||
SnoozeRequest
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
eventBus: new Vue()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
title () {
|
|
||||||
return `${this.user.given_name}’s Prayer Journal`
|
|
||||||
},
|
|
||||||
toast () {
|
|
||||||
return this.$parent.$refs.toast
|
|
||||||
},
|
|
||||||
...mapState(['user', 'journal', 'isLoadingJournal'])
|
|
||||||
},
|
|
||||||
async created () {
|
|
||||||
await this.$store.dispatch(actions.LOAD_JOURNAL, this.$Progress)
|
|
||||||
this.toast.showToast(`Loaded ${this.journal.length} prayer requests`, { theme: 'success' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.mpj-journal {
|
|
||||||
display: flex;
|
|
||||||
flex-flow: row wrap;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: flex-start;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import moment from 'moment'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'date-from-now',
|
|
||||||
props: {
|
|
||||||
tag: {
|
|
||||||
type: String,
|
|
||||||
default: 'span'
|
|
||||||
},
|
|
||||||
value: {
|
|
||||||
type: Number,
|
|
||||||
default: 0
|
|
||||||
},
|
|
||||||
interval: {
|
|
||||||
type: Number,
|
|
||||||
default: 10000
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
fromNow: moment(this.value).fromNow(),
|
|
||||||
intervalId: null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
actual () {
|
|
||||||
return moment(this.value).format('LLLL')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted () {
|
|
||||||
this.intervalId = setInterval(this.updateFromNow, this.interval)
|
|
||||||
this.$watch('value', this.updateFromNow)
|
|
||||||
},
|
|
||||||
beforeDestroy () {
|
|
||||||
clearInterval(this.intervalId)
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
updateFromNow () {
|
|
||||||
let newFromNow = moment(this.value).fromNow()
|
|
||||||
if (newFromNow !== this.fromNow) this.fromNow = newFromNow
|
|
||||||
}
|
|
||||||
},
|
|
||||||
render (createElement) {
|
|
||||||
return createElement(this.tag, {
|
|
||||||
domProps: {
|
|
||||||
title: this.actual,
|
|
||||||
innerText: this.fromNow
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
i.material-icons(v-html='icon')
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
name: 'md-icon',
|
|
||||||
props: {
|
|
||||||
icon: {
|
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
nav.mpj-top-nav.mpj-bg(role='menubar')
|
|
||||||
router-link.title(:to="{ name: 'Home' }"
|
|
||||||
role='menuitem')
|
|
||||||
span(style='font-weight:100;') my
|
|
||||||
span(style='font-weight:600;') Prayer
|
|
||||||
span(style='font-weight:700;') Journal
|
|
||||||
router-link(v-if='isAuthenticated'
|
|
||||||
:to="{ name: 'Journal' }"
|
|
||||||
role='menuitem') Journal
|
|
||||||
router-link(v-if='isAuthenticated'
|
|
||||||
:to="{ name: 'ActiveRequests' }"
|
|
||||||
role='menuitem') Active
|
|
||||||
router-link(v-if='hasSnoozed'
|
|
||||||
:to="{ name: 'SnoozedRequests' }"
|
|
||||||
role='menuitem') Snoozed
|
|
||||||
router-link(v-if='isAuthenticated'
|
|
||||||
:to="{ name: 'AnsweredRequests' }"
|
|
||||||
role='menuitem') Answered
|
|
||||||
a(v-if='isAuthenticated'
|
|
||||||
href='#'
|
|
||||||
role='menuitem'
|
|
||||||
@click.stop='logOff()') Log Off
|
|
||||||
a(v-if='!isAuthenticated'
|
|
||||||
href='#'
|
|
||||||
role='menuitem'
|
|
||||||
@click.stop='logOn()') Log On
|
|
||||||
a(href='https://docs.prayerjournal.me'
|
|
||||||
target='_blank'
|
|
||||||
role='menuitem'
|
|
||||||
@click.stop='') Docs
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import { mapState } from 'vuex'
|
|
||||||
|
|
||||||
import AuthService from '@/auth/AuthService'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'navigation',
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
auth0: new AuthService()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
hasSnoozed () {
|
|
||||||
return this.isAuthenticated &&
|
|
||||||
Array.isArray(this.journal) &&
|
|
||||||
this.journal.filter(req => req.snoozedUntil > Date.now()).length > 0
|
|
||||||
},
|
|
||||||
...mapState([ 'journal', 'isAuthenticated' ])
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
logOn () {
|
|
||||||
this.auth0.login()
|
|
||||||
},
|
|
||||||
logOff () {
|
|
||||||
this.auth0.logout(this.$store, this.$router)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.mpj-top-nav {
|
|
||||||
position: fixed;
|
|
||||||
display: flex;
|
|
||||||
flex-flow: row wrap;
|
|
||||||
align-items: center;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
width: 100%;
|
|
||||||
padding-left: .5rem;
|
|
||||||
min-height: 50px;
|
|
||||||
}
|
|
||||||
.mpj-top-nav a:link,
|
|
||||||
.mpj-top-nav a:visited {
|
|
||||||
text-decoration: none;
|
|
||||||
color: rgba(255, 255, 255, .75);
|
|
||||||
padding-left: 1rem;
|
|
||||||
}
|
|
||||||
.mpj-top-nav a:link.router-link-active,
|
|
||||||
.mpj-top-nav a:visited.router-link-active,
|
|
||||||
.mpj-top-nav a:hover {
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
.mpj-top-nav .title {
|
|
||||||
font-size: 1.25rem;
|
|
||||||
color: white;
|
|
||||||
padding-left: 1.25rem;
|
|
||||||
padding-right: 1.25rem;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
h2.mpj-page-title(v-if='!hideOnPage'
|
|
||||||
v-html='title')
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
export default {
|
|
||||||
name: 'page-title',
|
|
||||||
props: {
|
|
||||||
title: {
|
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
hideOnPage: {
|
|
||||||
type: Boolean,
|
|
||||||
default: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
title () {
|
|
||||||
document.title = `${this.title.replace('’', "'")} « myPrayerJournal`
|
|
||||||
}
|
|
||||||
},
|
|
||||||
created () {
|
|
||||||
document.title = `${this.title.replace('’', "'")} « myPrayerJournal`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.mpj-page-title {
|
|
||||||
border-bottom: solid 1px lightgray;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
article
|
|
||||||
page-title(title='Privacy Policy')
|
|
||||||
p: small: em (as of May 21, 2018)
|
|
||||||
p.
|
|
||||||
The nature of the service is one where privacy is a must. The items below will help you understand the data we
|
|
||||||
collect, access, and store on your behalf as you use this service.
|
|
||||||
hr
|
|
||||||
h3 Third Party Services
|
|
||||||
p.
|
|
||||||
myPrayerJournal utilizes a third-party authentication and identity provider. You should familiarize yourself with
|
|
||||||
the privacy policy for #[a(href='https://auth0.com/privacy' target='_blank') Auth0], as well as your chosen provider
|
|
||||||
(#[a(href='https://privacy.microsoft.com/en-us/privacystatement' target='_blank') Microsoft] or
|
|
||||||
#[a(href='https://policies.google.com/privacy' target='_blank') Google]).
|
|
||||||
hr
|
|
||||||
h3 What We Collect
|
|
||||||
h4 Identifying Data
|
|
||||||
ul
|
|
||||||
li.
|
|
||||||
The only identifying data myPrayerJournal stores is the subscriber (“sub”) field from the token we
|
|
||||||
receive from Auth0, once you have signed in through their hosted service. All information is associated with you
|
|
||||||
via this field.
|
|
||||||
li.
|
|
||||||
While you are signed in, within your browser, the service has access to your first and last names, along with a
|
|
||||||
URL to the profile picture (provided by your selected identity provider). This information is not transmitted to
|
|
||||||
the server, and is removed when “Log Off” is clicked.
|
|
||||||
h4 User Provided Data
|
|
||||||
ul
|
|
||||||
li.
|
|
||||||
myPrayerJournal stores the information you provide, including the text of prayer requests, updates, and notes;
|
|
||||||
and the date/time when certain actions are taken.
|
|
||||||
hr
|
|
||||||
h3 How Your Data Is Accessed / Secured
|
|
||||||
ul
|
|
||||||
li.
|
|
||||||
Your provided data is returned to you, as required, to display your journal or your answered requests.
|
|
||||||
On the server, it is stored in a controlled-access database.
|
|
||||||
li.
|
|
||||||
Your data is backed up, along with other Bit Badger Solutions hosted systems, in a rolling manner; backups are
|
|
||||||
preserved for the prior 7 days, and backups from the 1st and 15th are preserved for 3 months. These backups are
|
|
||||||
stored in a private cloud data repository.
|
|
||||||
li.
|
|
||||||
The data collected and stored is the absolute minimum necessary for the functionality of the service. There are
|
|
||||||
no plans to “monetize” this service, and storing the minimum amount of information means that the
|
|
||||||
data we have is not interesting to purchasers (or those who may have more nefarious purposes).
|
|
||||||
li Access to servers and backups is strictly controlled and monitored for unauthorized access attempts.
|
|
||||||
hr
|
|
||||||
h3 Removing Your Data
|
|
||||||
p.
|
|
||||||
At any time, you may choose to discontinue using this service. Both Microsoft and Google provide ways to revoke
|
|
||||||
access from this application. However, if you want your data removed from the database, please contact daniel at
|
|
||||||
bitbadger.solutions (via e-mail, replacing at with @) prior to doing so, to ensure we can determine which
|
|
||||||
subscriber ID belongs to you.
|
|
||||||
</template>
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
article
|
|
||||||
page-title(title='Terms of Service')
|
|
||||||
p: small: em (as of May 21, 2018)
|
|
||||||
h3 1. Acceptance of Terms
|
|
||||||
p.
|
|
||||||
By accessing this web site, you are agreeing to be bound by these Terms and Conditions, and that you are
|
|
||||||
responsible to ensure that your use of this site complies with all applicable laws. Your continued use of this
|
|
||||||
site implies your acceptance of these terms.
|
|
||||||
h3 2. Description of Service and Registration
|
|
||||||
p.
|
|
||||||
myPrayerJournal is a service that allows individuals to enter and amend their prayer requests. It requires no
|
|
||||||
registration by itself, but access is granted based on a successful login with an external identity provider. See
|
|
||||||
#[router-link(:to="{ name: 'PrivacyPolicy' }") our privacy policy] for details on how that information is accessed
|
|
||||||
and stored.
|
|
||||||
h3 3. Third Party Services
|
|
||||||
p.
|
|
||||||
This service utilizes a third-party service provider for identity management. Review the terms of service for
|
|
||||||
#[a(href='https://auth0.com/terms' target='_blank') Auth0], as well as those for the selected authorization
|
|
||||||
provider (#[a(href='https://www.microsoft.com/en-us/servicesagreement' target='_blank') Microsoft] or
|
|
||||||
#[a(href='https://policies.google.com/terms' target='_blank') Google]).
|
|
||||||
h3 4. Liability
|
|
||||||
p.
|
|
||||||
This service is provided "as is", and no warranty (express or implied) exists. The service and its developers may
|
|
||||||
not be held liable for any damages that may arise through the use of this service.
|
|
||||||
h3 5. Updates to Terms
|
|
||||||
p.
|
|
||||||
These terms and conditions may be updated at any time, and this service does not have the capability to notify
|
|
||||||
users when these change. The date at the top of the page will be updated when any of the text of these terms is
|
|
||||||
updated.
|
|
||||||
hr
|
|
||||||
p.
|
|
||||||
You may also wish to review our #[router-link(:to="{ name: 'PrivacyPolicy' }") privacy policy] to learn how we
|
|
||||||
handle your data.
|
|
||||||
</template>
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
article.mpj-main-content(role='main')
|
|
||||||
page-title(title='Active Requests')
|
|
||||||
div(v-if='loaded').mpj-request-list
|
|
||||||
p.mpj-text-center(v-if='requests.length === 0'): em.
|
|
||||||
No active requests found; return to #[router-link(:to='{ name: "Journal" } ') your journal]
|
|
||||||
request-list-item(v-for='req in requests'
|
|
||||||
:key='req.requestId'
|
|
||||||
:request='req'
|
|
||||||
:toast='toast')
|
|
||||||
p(v-else) Loading journal...
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import { mapState } from 'vuex'
|
|
||||||
|
|
||||||
import RequestListItem from '@/components/request/RequestListItem'
|
|
||||||
|
|
||||||
import actions from '@/store/action-types'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'active-requests',
|
|
||||||
components: {
|
|
||||||
RequestListItem
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
requests: [],
|
|
||||||
loaded: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
toast () {
|
|
||||||
return this.$parent.$refs.toast
|
|
||||||
},
|
|
||||||
...mapState(['journal', 'isLoadingJournal'])
|
|
||||||
},
|
|
||||||
created () {
|
|
||||||
this.$on('requestUnsnoozed', this.ensureJournal)
|
|
||||||
this.$on('requestNowShown', this.ensureJournal)
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
async ensureJournal () {
|
|
||||||
if (!Array.isArray(this.journal)) {
|
|
||||||
this.loaded = false
|
|
||||||
await this.$store.dispatch(actions.LOAD_JOURNAL, this.$Progress)
|
|
||||||
}
|
|
||||||
this.requests = this.journal
|
|
||||||
.sort((a, b) => a.showAfter - b.showAfter)
|
|
||||||
this.loaded = true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async mounted () {
|
|
||||||
await this.ensureJournal()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
article.mpj-main-content(role='main')
|
|
||||||
page-title(title='Answered Requests')
|
|
||||||
div(v-if='loaded').mpj-request-list
|
|
||||||
p.text-center(v-if='requests.length === 0'): em.
|
|
||||||
No answered requests found; once you have marked one as “Answered”, it will appear here
|
|
||||||
request-list-item(v-for='req in requests'
|
|
||||||
:key='req.requestId'
|
|
||||||
:request='req'
|
|
||||||
:toast='toast')
|
|
||||||
p(v-else) Loading answered requests...
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import api from '@/api'
|
|
||||||
|
|
||||||
import RequestListItem from '@/components/request/RequestListItem'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'answered-requests',
|
|
||||||
components: {
|
|
||||||
RequestListItem
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
requests: [],
|
|
||||||
loaded: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
toast () {
|
|
||||||
return this.$parent.$refs.toast
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async mounted () {
|
|
||||||
this.$Progress.start()
|
|
||||||
try {
|
|
||||||
const reqs = await api.getAnsweredRequests()
|
|
||||||
this.requests = reqs.data
|
|
||||||
this.$Progress.finish()
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err)
|
|
||||||
this.toast.showToast('Error loading requests; check console for details', { theme: 'danger' })
|
|
||||||
this.$Progress.fail()
|
|
||||||
} finally {
|
|
||||||
this.loaded = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,204 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
article.mpj-main-content(role='main')
|
|
||||||
page-title(:title='title')
|
|
||||||
.mpj-narrow
|
|
||||||
label(for='request_text')
|
|
||||||
| Prayer Request
|
|
||||||
br
|
|
||||||
textarea(v-model='form.requestText'
|
|
||||||
:rows='10'
|
|
||||||
@blur='trimText()'
|
|
||||||
autofocus).mpj-full-width
|
|
||||||
br
|
|
||||||
template(v-if='!isNew')
|
|
||||||
label Also Mark As
|
|
||||||
br
|
|
||||||
label.normal
|
|
||||||
input(v-model='form.status'
|
|
||||||
type='radio'
|
|
||||||
name='status'
|
|
||||||
value='Updated')
|
|
||||||
| Updated
|
|
||||||
|
|
|
||||||
label.normal
|
|
||||||
input(v-model='form.status'
|
|
||||||
type='radio'
|
|
||||||
name='status'
|
|
||||||
value='Prayed')
|
|
||||||
| Prayed
|
|
||||||
|
|
|
||||||
label.normal
|
|
||||||
input(v-model='form.status'
|
|
||||||
type='radio'
|
|
||||||
name='status'
|
|
||||||
value='Answered')
|
|
||||||
| Answered
|
|
||||||
br
|
|
||||||
label Recurrence
|
|
||||||
|
|
|
||||||
em.mpj-muted-text After prayer, request reappears...
|
|
||||||
br
|
|
||||||
label.normal
|
|
||||||
input(v-model='form.recur.typ'
|
|
||||||
type='radio'
|
|
||||||
name='recur'
|
|
||||||
value='immediate')
|
|
||||||
| Immediately
|
|
||||||
|
|
|
||||||
label.normal
|
|
||||||
input(v-model='form.recur.typ'
|
|
||||||
type='radio'
|
|
||||||
name='recur'
|
|
||||||
value='other')
|
|
||||||
| Every...
|
|
||||||
input(v-model='form.recur.count'
|
|
||||||
type='number'
|
|
||||||
:disabled='!showRecurrence').mpj-recur-count
|
|
||||||
select(v-model='form.recur.other'
|
|
||||||
:disabled='!showRecurrence').mpj-recur-type
|
|
||||||
option(value='hours') hours
|
|
||||||
option(value='days') days
|
|
||||||
option(value='weeks') weeks
|
|
||||||
.mpj-text-right
|
|
||||||
button(:disabled='!isValidRecurrence'
|
|
||||||
@click.stop='saveRequest()').primary.
|
|
||||||
#[md-icon(icon='save')] Save
|
|
||||||
|
|
|
||||||
button(@click.stop='goBack()').
|
|
||||||
#[md-icon(icon='arrow_back')] Cancel
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import { mapState } from 'vuex'
|
|
||||||
|
|
||||||
import actions from '@/store/action-types'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'edit-request',
|
|
||||||
props: {
|
|
||||||
id: {
|
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
title: 'Edit Prayer Request',
|
|
||||||
isNew: false,
|
|
||||||
form: {
|
|
||||||
requestId: '',
|
|
||||||
requestText: '',
|
|
||||||
status: 'Updated',
|
|
||||||
recur: {
|
|
||||||
typ: 'immediate',
|
|
||||||
other: '',
|
|
||||||
count: ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
isValidRecurrence () {
|
|
||||||
if (this.form.recur.typ === 'immediate') return true
|
|
||||||
const count = Number.parseInt(this.form.recur.count)
|
|
||||||
if (isNaN(count) || this.form.recur.other === '') return false
|
|
||||||
if (this.form.recur.other === 'hours' && count > (365 * 24)) return false
|
|
||||||
if (this.form.recur.other === 'days' && count > 365) return false
|
|
||||||
if (this.form.recur.other === 'weeks' && count > 52) return false
|
|
||||||
return true
|
|
||||||
},
|
|
||||||
showRecurrence () {
|
|
||||||
return this.form.recur.typ !== 'immediate'
|
|
||||||
},
|
|
||||||
toast () {
|
|
||||||
return this.$parent.$refs.toast
|
|
||||||
},
|
|
||||||
...mapState(['journal'])
|
|
||||||
},
|
|
||||||
async mounted () {
|
|
||||||
await this.ensureJournal()
|
|
||||||
if (this.id === 'new') {
|
|
||||||
this.title = 'Add Prayer Request'
|
|
||||||
this.isNew = true
|
|
||||||
this.form.requestId = ''
|
|
||||||
this.form.requestText = ''
|
|
||||||
this.form.status = 'Created'
|
|
||||||
this.form.recur.typ = 'immediate'
|
|
||||||
this.form.recur.other = ''
|
|
||||||
this.form.recur.count = ''
|
|
||||||
} else {
|
|
||||||
this.title = 'Edit Prayer Request'
|
|
||||||
this.isNew = false
|
|
||||||
if (this.journal.length === 0) {
|
|
||||||
await this.$store.dispatch(actions.LOAD_JOURNAL, this.$Progress)
|
|
||||||
}
|
|
||||||
const req = this.journal.filter(r => r.requestId === this.id)[0]
|
|
||||||
this.form.requestId = this.id
|
|
||||||
this.form.requestText = req.text
|
|
||||||
this.form.status = 'Updated'
|
|
||||||
if (req.recurType === 'immediate') {
|
|
||||||
this.form.recur.typ = 'immediate'
|
|
||||||
this.form.recur.other = ''
|
|
||||||
this.form.recur.count = ''
|
|
||||||
} else {
|
|
||||||
this.form.recur.typ = 'other'
|
|
||||||
this.form.recur.other = req.recurType
|
|
||||||
this.form.recur.count = req.recurCount
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
goBack () {
|
|
||||||
this.$router.go(-1)
|
|
||||||
},
|
|
||||||
trimText () {
|
|
||||||
this.form.requestText = this.form.requestText.trim()
|
|
||||||
},
|
|
||||||
async ensureJournal () {
|
|
||||||
if (!Array.isArray(this.journal)) {
|
|
||||||
await this.$store.dispatch(actions.LOAD_JOURNAL, this.$Progress)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async saveRequest () {
|
|
||||||
if (this.isNew) {
|
|
||||||
await this.$store.dispatch(actions.ADD_REQUEST, {
|
|
||||||
progress: this.$Progress,
|
|
||||||
requestText: this.form.requestText,
|
|
||||||
recurType: this.form.recur.typ === 'immediate' ? 'immediate' : this.form.recur.other,
|
|
||||||
recurCount: this.form.recur.typ === 'immediate' ? 0 : Number.parseInt(this.form.recur.count)
|
|
||||||
})
|
|
||||||
this.toast.showToast('New prayer request added', { theme: 'success' })
|
|
||||||
} else {
|
|
||||||
await this.$store.dispatch(actions.UPDATE_REQUEST, {
|
|
||||||
progress: this.$Progress,
|
|
||||||
requestId: this.form.requestId,
|
|
||||||
updateText: this.form.requestText,
|
|
||||||
status: this.form.status,
|
|
||||||
recurType: this.form.recur.typ === 'immediate' ? 'immediate' : this.form.recur.other,
|
|
||||||
recurCount: this.form.recur.typ === 'immediate' ? 0 : Number.parseInt(this.form.recur.count)
|
|
||||||
})
|
|
||||||
if (this.form.status === 'Answered') {
|
|
||||||
this.toast.showToast('Request updated and removed from active journal', { theme: 'success' })
|
|
||||||
} else {
|
|
||||||
this.toast.showToast('Request updated', { theme: 'success' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.goBack()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.mpj-recur-count {
|
|
||||||
width: 3rem;
|
|
||||||
border-top-right-radius: 0;
|
|
||||||
border-bottom-right-radius: 0;
|
|
||||||
}
|
|
||||||
.mpj-recur-type {
|
|
||||||
border-top-left-radius: 0;
|
|
||||||
border-bottom-left-radius: 0;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
article.mpj-main-content(role='main')
|
|
||||||
page-title(title='Full Prayer Request')
|
|
||||||
template(v-if='request')
|
|
||||||
p
|
|
||||||
span(v-if='isAnswered') Answered {{ formatDate(answered) }} (#[date-from-now(:value='answered')])
|
|
||||||
small: em.mpj-muted-text prayed {{ prayedCount }} times, open {{ openDays }} days
|
|
||||||
p.mpj-request-text {{ lastText }}
|
|
||||||
br
|
|
||||||
table.mpj-request-log
|
|
||||||
thead
|
|
||||||
tr
|
|
||||||
th Action
|
|
||||||
th Update / Notes
|
|
||||||
tbody
|
|
||||||
tr(v-for='item in log' :key='item.asOf')
|
|
||||||
td {{ item.status }} on #[span.mpj-text-nowrap {{ formatDate(item.asOf) }}]
|
|
||||||
td(v-if='item.text').mpj-request-text {{ item.text }}
|
|
||||||
td(v-else)
|
|
||||||
p(v-else) Loading request...
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import moment from 'moment'
|
|
||||||
|
|
||||||
import api from '@/api'
|
|
||||||
|
|
||||||
const asOfDesc = (a, b) => b.asOf - a.asOf
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'full-request',
|
|
||||||
props: {
|
|
||||||
id: {
|
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
request: null
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
answered () {
|
|
||||||
return this.request.history.find(hist => hist.status === 'Answered').asOf
|
|
||||||
},
|
|
||||||
isAnswered () {
|
|
||||||
return this.request.history.filter(hist => hist.status === 'Answered').length > 0
|
|
||||||
},
|
|
||||||
lastText () {
|
|
||||||
return this.request.history
|
|
||||||
.filter(hist => hist.text)
|
|
||||||
.sort(asOfDesc)[0].text
|
|
||||||
},
|
|
||||||
log () {
|
|
||||||
const allHistory = (this.request.notes || [])
|
|
||||||
.map(note => ({ asOf: note.asOf, text: note.notes, status: 'Notes' }))
|
|
||||||
.concat(this.request.history)
|
|
||||||
.sort(asOfDesc)
|
|
||||||
// Skip the first entry for answered requests; that info is already displayed
|
|
||||||
return this.isAnswered ? allHistory.slice(1) : allHistory
|
|
||||||
},
|
|
||||||
openDays () {
|
|
||||||
const asOf = this.isAnswered ? this.answered : Date.now()
|
|
||||||
return Math.floor(
|
|
||||||
(asOf - this.request.history.find(hist => hist.status === 'Created').asOf) / 1000 / 60 / 60 / 24)
|
|
||||||
},
|
|
||||||
prayedCount () {
|
|
||||||
return this.request.history.filter(hist => hist.status === 'Prayed').length
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async mounted () {
|
|
||||||
this.$Progress.start()
|
|
||||||
try {
|
|
||||||
const req = await api.getFullRequest(this.id)
|
|
||||||
this.request = req.data
|
|
||||||
this.$Progress.finish()
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e)
|
|
||||||
this.$Progress.fail()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
formatDate (asOf) {
|
|
||||||
return moment(asOf).format('LL')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
.mpj-modal(v-show='notesVisible')
|
|
||||||
.mpj-modal-content.mpj-narrow
|
|
||||||
header.mpj-bg
|
|
||||||
h5 Add Notes to Prayer Request
|
|
||||||
label
|
|
||||||
| Notes
|
|
||||||
br
|
|
||||||
textarea(v-model='form.notes'
|
|
||||||
:rows='10'
|
|
||||||
@blur='trimText()').mpj-full-width
|
|
||||||
.mpj-text-right
|
|
||||||
button(@click='saveNotes()').primary.
|
|
||||||
#[md-icon(icon='save')] Save
|
|
||||||
|
|
|
||||||
button(@click='closeDialog()').
|
|
||||||
#[md-icon(icon='undo')] Cancel
|
|
||||||
hr
|
|
||||||
div(v-if='hasPriorNotes')
|
|
||||||
p.mpj-text-center: strong Prior Notes for This Request
|
|
||||||
.mpj-note-list
|
|
||||||
p(v-for='note in priorNotes'
|
|
||||||
:key='note.asOf')
|
|
||||||
small.mpj-muted-text: date-from-now(:value='note.asOf')
|
|
||||||
br
|
|
||||||
span.mpj-request-text {{ note.notes }}
|
|
||||||
div(v-else-if='noPriorNotes').mpj-text-center.mpj-muted-text There are no prior notes for this request
|
|
||||||
div(v-else).mpj-text-center
|
|
||||||
button(@click='loadNotes()').
|
|
||||||
#[md-icon(icon='cloud_download')] Load Prior Notes
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import api from '@/api'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'notes-edit',
|
|
||||||
props: {
|
|
||||||
toast: { required: true },
|
|
||||||
events: { required: true }
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
notesVisible: false,
|
|
||||||
form: {
|
|
||||||
requestId: '',
|
|
||||||
notes: ''
|
|
||||||
},
|
|
||||||
priorNotes: [],
|
|
||||||
priorNotesLoaded: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
hasPriorNotes () {
|
|
||||||
return this.priorNotesLoaded && this.priorNotes.length > 0
|
|
||||||
},
|
|
||||||
noPriorNotes () {
|
|
||||||
return this.priorNotesLoaded && this.priorNotes.length === 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
created () {
|
|
||||||
this.events.$on('notes', this.openDialog)
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
closeDialog () {
|
|
||||||
this.form.requestId = ''
|
|
||||||
this.form.notes = ''
|
|
||||||
this.priorNotes = []
|
|
||||||
this.priorNotesLoaded = false
|
|
||||||
this.notesVisible = false
|
|
||||||
},
|
|
||||||
async loadNotes () {
|
|
||||||
this.$Progress.start()
|
|
||||||
try {
|
|
||||||
const notes = await api.getNotes(this.form.requestId)
|
|
||||||
this.priorNotes = notes.data
|
|
||||||
this.$Progress.finish()
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
this.$Progress.fail()
|
|
||||||
} finally {
|
|
||||||
this.priorNotesLoaded = true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
openDialog (request) {
|
|
||||||
this.form.requestId = request.requestId
|
|
||||||
this.notesVisible = true
|
|
||||||
},
|
|
||||||
async saveNotes () {
|
|
||||||
this.$Progress.start()
|
|
||||||
try {
|
|
||||||
await api.addNote(this.form.requestId, this.form.notes)
|
|
||||||
this.$Progress.finish()
|
|
||||||
this.toast.showToast('Added notes', { theme: 'success' })
|
|
||||||
this.closeDialog()
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e)
|
|
||||||
this.$Progress.fail()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
trimText () {
|
|
||||||
this.form.notes = this.form.notes.trim()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.mpj-note-list p {
|
|
||||||
border-top: dotted 1px lightgray;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
.mpj-request-card(v-if='shouldDisplay')
|
|
||||||
header.mpj-card-header(role='toolbar').
|
|
||||||
#[button(@click='markPrayed()' title='Pray').primary: md-icon(icon='done')]
|
|
||||||
#[button(@click.stop='showEdit()' title='Edit'): md-icon(icon='edit')]
|
|
||||||
#[button(@click.stop='showNotes()' title='Add Notes'): md-icon(icon='comment')]
|
|
||||||
#[button(@click.stop='snooze()' title='Snooze Request'): md-icon(icon='schedule')]
|
|
||||||
div
|
|
||||||
p.card-text.mpj-request-text
|
|
||||||
| {{ request.text }}
|
|
||||||
p.as-of.mpj-text-right: small.mpj-muted-text: em
|
|
||||||
= '(last activity '
|
|
||||||
date-from-now(:value='request.asOf')
|
|
||||||
| )
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import actions from '@/store/action-types'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'request-card',
|
|
||||||
props: {
|
|
||||||
request: { required: true },
|
|
||||||
toast: { required: true },
|
|
||||||
events: { required: true }
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
shouldDisplay () {
|
|
||||||
const now = Date.now()
|
|
||||||
return Math.max(now, this.request.showAfter, this.request.snoozedUntil) === now
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
async markPrayed () {
|
|
||||||
await this.$store.dispatch(actions.UPDATE_REQUEST, {
|
|
||||||
progress: this.$Progress,
|
|
||||||
requestId: this.request.requestId,
|
|
||||||
status: 'Prayed',
|
|
||||||
updateText: ''
|
|
||||||
})
|
|
||||||
this.toast.showToast('Request marked as prayed', { theme: 'success' })
|
|
||||||
},
|
|
||||||
showEdit () {
|
|
||||||
this.$router.push({ name: 'EditRequest', params: { id: this.request.requestId } })
|
|
||||||
},
|
|
||||||
showNotes () {
|
|
||||||
this.events.$emit('notes', this.request)
|
|
||||||
},
|
|
||||||
snooze () {
|
|
||||||
this.events.$emit('snooze', this.request.requestId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.mpj-request-card {
|
|
||||||
border: solid 1px darkgray;
|
|
||||||
border-radius: 5px;
|
|
||||||
width: 20rem;
|
|
||||||
margin: .5rem;
|
|
||||||
}
|
|
||||||
@media screen and (max-width: 20rem) {
|
|
||||||
.mpj-request-card {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.mpj-card-header {
|
|
||||||
display: flex;
|
|
||||||
flex-flow: row;
|
|
||||||
justify-content: center;
|
|
||||||
background-image: -webkit-gradient(linear, left top, left bottom, from(lightgray), to(whitesmoke));
|
|
||||||
background-image: -webkit-linear-gradient(top, lightgray, whitesmoke);
|
|
||||||
background-image: -moz-linear-gradient(top, lightgray, whitesmoke);
|
|
||||||
background-image: linear-gradient(to bottom, lightgray, whitesmoke);
|
|
||||||
}
|
|
||||||
.mpj-card-header button {
|
|
||||||
margin: .25rem;
|
|
||||||
padding: 0 .25rem;
|
|
||||||
}
|
|
||||||
.mpj-card-header button .material-icons {
|
|
||||||
font-size: 1.3rem;
|
|
||||||
}
|
|
||||||
.mpj-request-card .card-text {
|
|
||||||
margin-left: 1rem;
|
|
||||||
margin-right: 1rem;
|
|
||||||
}
|
|
||||||
.mpj-request-card .as-of {
|
|
||||||
margin-right: .25rem;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
p.mpj-request-text
|
|
||||||
| {{ request.text }}
|
|
||||||
br
|
|
||||||
br
|
|
||||||
button(@click='viewFull'
|
|
||||||
title='View Full Request').
|
|
||||||
#[md-icon(icon='description')] View Full Request
|
|
||||||
|
|
|
||||||
template(v-if='!isAnswered')
|
|
||||||
button(@click='editRequest'
|
|
||||||
title='Edit Request').
|
|
||||||
#[md-icon(icon='edit')] Edit Request
|
|
||||||
|
|
|
||||||
template(v-if='isSnoozed')
|
|
||||||
button(@click='cancelSnooze()').
|
|
||||||
#[md-icon(icon='restore')] Cancel Snooze
|
|
||||||
|
|
|
||||||
template(v-if='isPending')
|
|
||||||
button(@click='showNow()').
|
|
||||||
#[md-icon(icon='restore')] Show Now
|
|
||||||
br(v-if='isSnoozed || isPending || isAnswered')
|
|
||||||
small(v-if='isSnoozed').mpj-muted-text: em.
|
|
||||||
Snooze expires #[date-from-now(:value='request.snoozedUntil')]
|
|
||||||
small(v-if='isPending').mpj-muted-text: em.
|
|
||||||
Request scheduled to reappear #[date-from-now(:value='request.showAfter')]
|
|
||||||
small(v-if='isAnswered').mpj-muted-text: em.
|
|
||||||
Answered #[date-from-now(:value='request.asOf')]
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import actions from '@/store/action-types'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'request-list-item',
|
|
||||||
props: {
|
|
||||||
request: { required: true },
|
|
||||||
toast: { required: true }
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
answered () {
|
|
||||||
return this.request.history.find(hist => hist.status === 'Answered').asOf
|
|
||||||
},
|
|
||||||
isAnswered () {
|
|
||||||
return this.request.lastStatus === 'Answered'
|
|
||||||
},
|
|
||||||
isPending () {
|
|
||||||
return !this.isSnoozed && this.request.showAfter > Date.now()
|
|
||||||
},
|
|
||||||
isSnoozed () {
|
|
||||||
return this.request.snoozedUntil > Date.now()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
async cancelSnooze () {
|
|
||||||
await this.$store.dispatch(actions.SNOOZE_REQUEST, {
|
|
||||||
progress: this.$Progress,
|
|
||||||
requestId: this.request.requestId,
|
|
||||||
until: 0
|
|
||||||
})
|
|
||||||
this.toast.showToast('Request un-snoozed', { theme: 'success' })
|
|
||||||
this.$parent.$emit('requestUnsnoozed')
|
|
||||||
},
|
|
||||||
editRequest () {
|
|
||||||
this.$router.push({ name: 'EditRequest', params: { id: this.request.requestId } })
|
|
||||||
},
|
|
||||||
async showNow () {
|
|
||||||
await this.$store.dispatch(actions.SHOW_REQUEST_NOW, {
|
|
||||||
progress: this.$Progress,
|
|
||||||
requestId: this.request.requestId,
|
|
||||||
showAfter: Date.now()
|
|
||||||
})
|
|
||||||
this.toast.showToast('Recurrence skipped; request now shows in journal', { theme: 'success' })
|
|
||||||
this.$parent.$emit('requestNowShown')
|
|
||||||
},
|
|
||||||
viewFull () {
|
|
||||||
this.$router.push({ name: 'FullRequest', params: { id: this.request.requestId } })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
.mpj-modal(v-show='snoozeVisible')
|
|
||||||
.mpj-modal-content.mpj-skinny
|
|
||||||
header.mpj-bg
|
|
||||||
h5 Snooze Prayer Request
|
|
||||||
p.mpj-text-center
|
|
||||||
label
|
|
||||||
= 'Until '
|
|
||||||
input(v-model='form.snoozedUntil'
|
|
||||||
type='date'
|
|
||||||
autofocus)
|
|
||||||
br
|
|
||||||
.mpj-text-right
|
|
||||||
button.primary(:disabled='!isValid'
|
|
||||||
@click='snoozeRequest()').
|
|
||||||
#[md-icon(icon='snooze')] Snooze
|
|
||||||
|
|
|
||||||
button(@click='closeDialog()').
|
|
||||||
#[md-icon(icon='undo')] Cancel
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import actions from '@/store/action-types'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'snooze-request',
|
|
||||||
props: {
|
|
||||||
toast: { required: true },
|
|
||||||
events: { required: true }
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
snoozeVisible: false,
|
|
||||||
form: {
|
|
||||||
requestId: '',
|
|
||||||
snoozedUntil: ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
created () {
|
|
||||||
this.events.$on('snooze', this.openDialog)
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
isValid () {
|
|
||||||
return !isNaN(Date.parse(this.form.snoozedUntil))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
closeDialog () {
|
|
||||||
this.form.requestId = ''
|
|
||||||
this.form.snoozedUntil = ''
|
|
||||||
this.snoozeVisible = false
|
|
||||||
},
|
|
||||||
openDialog (requestId) {
|
|
||||||
this.form.requestId = requestId
|
|
||||||
this.snoozeVisible = true
|
|
||||||
},
|
|
||||||
async snoozeRequest () {
|
|
||||||
await this.$store.dispatch(actions.SNOOZE_REQUEST, {
|
|
||||||
progress: this.$Progress,
|
|
||||||
requestId: this.form.requestId,
|
|
||||||
until: Date.parse(this.form.snoozedUntil)
|
|
||||||
})
|
|
||||||
this.toast.showToast(`Request snoozed until ${this.form.snoozedUntil}`, { theme: 'success' })
|
|
||||||
this.closeDialog()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
article.mpj-main-content(role='main')
|
|
||||||
page-title(title='Snoozed Requests')
|
|
||||||
div(v-if='loaded').mpj-request-list
|
|
||||||
p.mpj-text-center(v-if='requests.length === 0'): em.
|
|
||||||
No snoozed requests found; return to #[router-link(:to='{ name: "Journal" } ') your journal]
|
|
||||||
request-list-item(v-for='req in requests'
|
|
||||||
:key='req.requestId'
|
|
||||||
:request='req'
|
|
||||||
:toast='toast')
|
|
||||||
p(v-else) Loading journal...
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import { mapState } from 'vuex'
|
|
||||||
|
|
||||||
import actions from '@/store/action-types'
|
|
||||||
|
|
||||||
import RequestListItem from '@/components/request/RequestListItem'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'snoozed-requests',
|
|
||||||
components: {
|
|
||||||
RequestListItem
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
requests: [],
|
|
||||||
loaded: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
toast () {
|
|
||||||
return this.$parent.$refs.toast
|
|
||||||
},
|
|
||||||
...mapState(['journal', 'isLoadingJournal'])
|
|
||||||
},
|
|
||||||
created () {
|
|
||||||
this.$on('requestUnsnoozed', this.ensureJournal)
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
async ensureJournal () {
|
|
||||||
if (!Array.isArray(this.journal)) {
|
|
||||||
this.loaded = false
|
|
||||||
await this.$store.dispatch(actions.LOAD_JOURNAL, this.$Progress)
|
|
||||||
}
|
|
||||||
this.requests = this.journal
|
|
||||||
.filter(req => req.snoozedUntil > Date.now())
|
|
||||||
.sort((a, b) => a.snoozedUntil - b.snoozedUntil)
|
|
||||||
this.loaded = true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async mounted () {
|
|
||||||
await this.ensureJournal()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
article.mpj-main-content(role='main')
|
|
||||||
pageTitle(title='Logging On')
|
|
||||||
p Logging you on...
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import AuthService from '@/auth/AuthService'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'log-on',
|
|
||||||
created () {
|
|
||||||
this.$Progress.start()
|
|
||||||
new AuthService().handleAuthentication(this.$store, this.$router)
|
|
||||||
// Auth service redirects to dashboard, which restarts the progress bar
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import VueProgressBar from 'vue-progressbar'
|
|
||||||
import VueToast from 'vue-toast'
|
|
||||||
|
|
||||||
import 'vue-toast/dist/vue-toast.min.css'
|
|
||||||
|
|
||||||
import App from './App'
|
|
||||||
import router from './router'
|
|
||||||
import store from './store'
|
|
||||||
import DateFromNow from './components/common/DateFromNow'
|
|
||||||
import MaterialDesignIcon from './components/common/MaterialDesignIcon'
|
|
||||||
import PageTitle from './components/common/PageTitle'
|
|
||||||
|
|
||||||
Vue.config.productionTip = false
|
|
||||||
|
|
||||||
Vue.use(VueProgressBar, {
|
|
||||||
color: 'yellow',
|
|
||||||
failedColor: 'red',
|
|
||||||
height: '5px',
|
|
||||||
transition: {
|
|
||||||
speed: '0.2s',
|
|
||||||
opacity: '0.6s',
|
|
||||||
termination: 1000
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
Vue.component('date-from-now', DateFromNow)
|
|
||||||
Vue.component('md-icon', MaterialDesignIcon)
|
|
||||||
Vue.component('page-title', PageTitle)
|
|
||||||
Vue.component('toast', VueToast)
|
|
||||||
|
|
||||||
new Vue({
|
|
||||||
router,
|
|
||||||
store,
|
|
||||||
render: h => h(App)
|
|
||||||
}).$mount('#app')
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
import Vue from 'vue'
|
|
||||||
import Router from 'vue-router'
|
|
||||||
|
|
||||||
import ActiveRequests from '@/components/request/ActiveRequests'
|
|
||||||
import AnsweredRequests from '@/components/request/AnsweredRequests'
|
|
||||||
import EditRequest from '@/components/request/EditRequest'
|
|
||||||
import FullRequest from '@/components/request/FullRequest'
|
|
||||||
import Home from '@/components/Home'
|
|
||||||
import Journal from '@/components/Journal'
|
|
||||||
import LogOn from '@/components/user/LogOn'
|
|
||||||
import PrivacyPolicy from '@/components/legal/PrivacyPolicy'
|
|
||||||
import SnoozedRequests from '@/components/request/SnoozedRequests'
|
|
||||||
import TermsOfService from '@/components/legal/TermsOfService'
|
|
||||||
|
|
||||||
Vue.use(Router)
|
|
||||||
|
|
||||||
export default new Router({
|
|
||||||
mode: 'history',
|
|
||||||
base: process.env.BASE_URL,
|
|
||||||
scrollBehavior (to, from, savedPosition) {
|
|
||||||
if (savedPosition) {
|
|
||||||
return savedPosition
|
|
||||||
} else {
|
|
||||||
return { x: 0, y: 0 }
|
|
||||||
}
|
|
||||||
},
|
|
||||||
routes: [
|
|
||||||
{
|
|
||||||
path: '/',
|
|
||||||
name: 'Home',
|
|
||||||
component: Home
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/journal',
|
|
||||||
name: 'Journal',
|
|
||||||
component: Journal
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/legal/privacy-policy',
|
|
||||||
name: 'PrivacyPolicy',
|
|
||||||
component: PrivacyPolicy
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/legal/terms-of-service',
|
|
||||||
name: 'TermsOfService',
|
|
||||||
component: TermsOfService
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/request/:id/edit',
|
|
||||||
name: 'EditRequest',
|
|
||||||
component: EditRequest,
|
|
||||||
props: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/request/:id/full',
|
|
||||||
name: 'FullRequest',
|
|
||||||
component: FullRequest,
|
|
||||||
props: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/requests/active',
|
|
||||||
name: 'ActiveRequests',
|
|
||||||
component: ActiveRequests
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/requests/answered',
|
|
||||||
name: 'AnsweredRequests',
|
|
||||||
component: AnsweredRequests
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/requests/snoozed',
|
|
||||||
name: 'SnoozedRequests',
|
|
||||||
component: SnoozedRequests
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/user/log-on',
|
|
||||||
name: 'LogOn',
|
|
||||||
component: LogOn
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
/** Action to add a prayer request (pass request text) */
|
|
||||||
ADD_REQUEST: 'add-request',
|
|
||||||
/** Action to load the user's prayer journal */
|
|
||||||
LOAD_JOURNAL: 'load-journal',
|
|
||||||
/** Action to update a request */
|
|
||||||
UPDATE_REQUEST: 'update-request',
|
|
||||||
/** Action to skip the remaining recurrence period */
|
|
||||||
SHOW_REQUEST_NOW: 'show-request-now',
|
|
||||||
/** Action to snooze a request */
|
|
||||||
SNOOZE_REQUEST: 'snooze-request'
|
|
||||||
}
|
|
||||||
@@ -1,150 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
import Vue from 'vue'
|
|
||||||
import Vuex from 'vuex'
|
|
||||||
|
|
||||||
import api from '@/api'
|
|
||||||
import AuthService from '@/auth/AuthService'
|
|
||||||
|
|
||||||
import mutations from './mutation-types'
|
|
||||||
import actions from './action-types'
|
|
||||||
|
|
||||||
Vue.use(Vuex)
|
|
||||||
|
|
||||||
const auth0 = new AuthService()
|
|
||||||
|
|
||||||
const logError = function (error) {
|
|
||||||
if (error.response) {
|
|
||||||
// The request was made and the server responded with a status code
|
|
||||||
// that falls out of the range of 2xx
|
|
||||||
console.log(error.response.data)
|
|
||||||
console.log(error.response.status)
|
|
||||||
console.log(error.response.headers)
|
|
||||||
} else if (error.request) {
|
|
||||||
// The request was made but no response was received
|
|
||||||
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
|
||||||
// http.ClientRequest in node.js
|
|
||||||
console.log(error.request)
|
|
||||||
} else {
|
|
||||||
// Something happened in setting up the request that triggered an Error
|
|
||||||
console.log('Error', error.message)
|
|
||||||
}
|
|
||||||
console.log(error.config)
|
|
||||||
}
|
|
||||||
|
|
||||||
export default new Vuex.Store({
|
|
||||||
state: {
|
|
||||||
user: JSON.parse(localStorage.getItem('user_profile') || '{}'),
|
|
||||||
isAuthenticated: (() => {
|
|
||||||
auth0.scheduleRenewal()
|
|
||||||
if (auth0.isAuthenticated()) {
|
|
||||||
api.setBearer(localStorage.getItem('id_token'))
|
|
||||||
}
|
|
||||||
return auth0.isAuthenticated()
|
|
||||||
})(),
|
|
||||||
journal: {},
|
|
||||||
isLoadingJournal: false
|
|
||||||
},
|
|
||||||
mutations: {
|
|
||||||
[mutations.LOADING_JOURNAL] (state, flag) {
|
|
||||||
state.isLoadingJournal = flag
|
|
||||||
},
|
|
||||||
[mutations.LOADED_JOURNAL] (state, journal) {
|
|
||||||
state.journal = journal
|
|
||||||
},
|
|
||||||
[mutations.REQUEST_ADDED] (state, newRequest) {
|
|
||||||
state.journal.push(newRequest)
|
|
||||||
},
|
|
||||||
[mutations.REQUEST_UPDATED] (state, request) {
|
|
||||||
let jrnl = state.journal.filter(it => it.requestId !== request.requestId)
|
|
||||||
if (request.lastStatus !== 'Answered') jrnl.push(request)
|
|
||||||
state.journal = jrnl
|
|
||||||
},
|
|
||||||
[mutations.USER_LOGGED_OFF] (state) {
|
|
||||||
state.user = {}
|
|
||||||
api.removeBearer()
|
|
||||||
state.isAuthenticated = false
|
|
||||||
},
|
|
||||||
[mutations.USER_LOGGED_ON] (state, user) {
|
|
||||||
localStorage.setItem('user_profile', JSON.stringify(user))
|
|
||||||
state.user = user
|
|
||||||
api.setBearer(localStorage.getItem('id_token'))
|
|
||||||
state.isAuthenticated = true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
async [actions.ADD_REQUEST] ({ commit }, { progress, requestText, recurType, recurCount }) {
|
|
||||||
progress.start()
|
|
||||||
try {
|
|
||||||
const newRequest = await api.addRequest(requestText, recurType, recurCount)
|
|
||||||
commit(mutations.REQUEST_ADDED, newRequest.data)
|
|
||||||
progress.finish()
|
|
||||||
} catch (err) {
|
|
||||||
logError(err)
|
|
||||||
progress.fail()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async [actions.LOAD_JOURNAL] ({ commit }, progress) {
|
|
||||||
commit(mutations.LOADED_JOURNAL, {})
|
|
||||||
progress.start()
|
|
||||||
commit(mutations.LOADING_JOURNAL, true)
|
|
||||||
api.setBearer(localStorage.getItem('id_token'))
|
|
||||||
try {
|
|
||||||
const jrnl = await api.journal()
|
|
||||||
commit(mutations.LOADED_JOURNAL, jrnl.data)
|
|
||||||
progress.finish()
|
|
||||||
} catch (err) {
|
|
||||||
logError(err)
|
|
||||||
progress.fail()
|
|
||||||
} finally {
|
|
||||||
commit(mutations.LOADING_JOURNAL, false)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async [actions.UPDATE_REQUEST] ({ commit, state }, { progress, requestId, status, updateText, recurType, recurCount }) {
|
|
||||||
progress.start()
|
|
||||||
try {
|
|
||||||
let oldReq = (state.journal.filter(req => req.requestId === requestId) || [])[0] || {}
|
|
||||||
if (!(status === 'Prayed' && updateText === '')) {
|
|
||||||
if (status !== 'Answered' && (oldReq.recurType !== recurType || oldReq.recurCount !== recurCount)) {
|
|
||||||
await api.updateRecurrence(requestId, recurType, recurCount)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (status !== 'Updated' || oldReq.text !== updateText) {
|
|
||||||
await api.updateRequest(requestId, status, oldReq.text !== updateText ? updateText : '')
|
|
||||||
}
|
|
||||||
const request = await api.getRequest(requestId)
|
|
||||||
commit(mutations.REQUEST_UPDATED, request.data)
|
|
||||||
progress.finish()
|
|
||||||
} catch (err) {
|
|
||||||
logError(err)
|
|
||||||
progress.fail()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async [actions.SHOW_REQUEST_NOW] ({ commit }, { progress, requestId, showAfter }) {
|
|
||||||
progress.start()
|
|
||||||
try {
|
|
||||||
await api.showRequest(requestId, showAfter)
|
|
||||||
const request = await api.getRequest(requestId)
|
|
||||||
commit(mutations.REQUEST_UPDATED, request.data)
|
|
||||||
progress.finish()
|
|
||||||
} catch (err) {
|
|
||||||
logError(err)
|
|
||||||
progress.fail()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async [actions.SNOOZE_REQUEST] ({ commit }, { progress, requestId, until }) {
|
|
||||||
progress.start()
|
|
||||||
try {
|
|
||||||
await api.snoozeRequest(requestId, until)
|
|
||||||
const request = await api.getRequest(requestId)
|
|
||||||
commit(mutations.REQUEST_UPDATED, request.data)
|
|
||||||
progress.finish()
|
|
||||||
} catch (err) {
|
|
||||||
logError(err)
|
|
||||||
progress.fail()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
getters: {},
|
|
||||||
modules: {}
|
|
||||||
})
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
/** Mutation for when the user's prayer journal is being loaded */
|
|
||||||
LOADING_JOURNAL: 'loading-journal',
|
|
||||||
/** Mutation for when the user's prayer journal has been loaded */
|
|
||||||
LOADED_JOURNAL: 'journal-loaded',
|
|
||||||
/** Mutation for adding a new prayer request (pass text) */
|
|
||||||
REQUEST_ADDED: 'request-added',
|
|
||||||
/** Mutation to replace a prayer request at the top of the current journal */
|
|
||||||
REQUEST_UPDATED: 'request-updated',
|
|
||||||
/** Mutation for logging a user off */
|
|
||||||
USER_LOGGED_OFF: 'user-logged-off',
|
|
||||||
/** Mutation for logging a user on (pass user) */
|
|
||||||
USER_LOGGED_ON: 'user-logged-on'
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<script src="https://cdn.auth0.com/js/auth0/8.9/auth0.min.js"></script>
|
|
||||||
<script>
|
|
||||||
var webAuth = new auth0.WebAuth({
|
|
||||||
domain: 'djs-consulting.auth0.com',
|
|
||||||
clientID: 'Of2s0RQCQ3mt3dwIkOBY5h85J9sXbF2n',
|
|
||||||
scope: 'openid profile email',
|
|
||||||
responseType: 'token id_token',
|
|
||||||
redirectUri: location.protocol + '//' + location.host + '/static/silent.html'
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
webAuth.parseHash(window.location.hash, function (err, response) {
|
|
||||||
parent.postMessage(err || response, location.protocol + '//' + location.host);
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
<body></body>
|
|
||||||
</html>
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
const webpack = require('webpack')
|
|
||||||
module.exports = {
|
|
||||||
outputDir: '../api/MyPrayerJournal.Api/wwwroot',
|
|
||||||
configureWebpack: {
|
|
||||||
plugins: [
|
|
||||||
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
8599
src/app/yarn.lock
8599
src/app/yarn.lock
File diff suppressed because it is too large
Load Diff
27
src/composer.json
Normal file
27
src/composer.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"name": "bit-badger/my-prayer-journal",
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.4",
|
||||||
|
"ext-pdo": "*",
|
||||||
|
"ext-sqlite3": "*",
|
||||||
|
"auth0/auth0-php": "^8.11",
|
||||||
|
"bit-badger/pdo-document": "^2",
|
||||||
|
"guzzlehttp/guzzle": "^7.8",
|
||||||
|
"guzzlehttp/psr7": "^2.6",
|
||||||
|
"http-interop/http-factory-guzzle": "^1.2",
|
||||||
|
"square/pjson": "^0.5",
|
||||||
|
"vlucas/phpdotenv": "^5.6"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"MyPrayerJournal\\": "lib/",
|
||||||
|
"MyPrayerJournal\\Domain\\": "lib/Domain",
|
||||||
|
"MyPrayerJournal\\UI\\": "lib/UI"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"allow-plugins": {
|
||||||
|
"php-http/discovery": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
2443
src/composer.lock
generated
Normal file
2443
src/composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
55
src/convert-from-v3.php
Normal file
55
src/convert-from-v3.php
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
use BitBadger\PDODocument\{AutoId, Configuration, Custom, Definition, Document, Mode};
|
||||||
|
use BitBadger\PDODocument\Mapper\ArrayMapper;
|
||||||
|
use MyPrayerJournal\Domain\{History, Note, Recurrence, RecurrencePeriod, Request, RequestAction};
|
||||||
|
use MyPrayerJournal\Table;
|
||||||
|
|
||||||
|
require 'start.php';
|
||||||
|
|
||||||
|
echo 'Retrieving v3 requests...' . PHP_EOL;
|
||||||
|
|
||||||
|
Configuration::resetPDO();
|
||||||
|
Configuration::useDSN('pgsql:host=localhost;user=mpj;password=devpassword;dbname=mpj');
|
||||||
|
$reqs = Custom::array('SELECT data FROM mpj.request', [], new ArrayMapper());
|
||||||
|
|
||||||
|
echo 'Found ' . sizeof($reqs) . ' requests; migrating to v4...' . PHP_EOL;
|
||||||
|
|
||||||
|
Configuration::resetPDO();
|
||||||
|
Configuration::useDSN('sqlite:./data/mpj.db');
|
||||||
|
Configuration::$autoId = AutoId::RandomString;
|
||||||
|
Configuration::$idStringLength = 12;
|
||||||
|
|
||||||
|
Definition::ensureTable(Table::REQUEST);
|
||||||
|
|
||||||
|
/** Convert dates to the same format */
|
||||||
|
function convertDate(string $date): string
|
||||||
|
{
|
||||||
|
return new DateTimeImmutable($date)->format('c');
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($reqs as $reqJson) {
|
||||||
|
$req = json_decode($reqJson['data']);
|
||||||
|
$recurParts = explode(' ', $req->recurrence);
|
||||||
|
$recurPeriod = RecurrencePeriod::from(end($recurParts));
|
||||||
|
$recur = match ($recurPeriod) {
|
||||||
|
RecurrencePeriod::Immediate => new Recurrence(RecurrencePeriod::Immediate),
|
||||||
|
default => new Recurrence($recurPeriod, (int)$recurParts[0])
|
||||||
|
};
|
||||||
|
Document::insert(Table::REQUEST, new Request(
|
||||||
|
enteredOn: convertDate($req->enteredOn),
|
||||||
|
userId: $req->userId,
|
||||||
|
snoozedUntil: property_exists($req, 'snoozedUntil') ? convertDate($req->snoozedUntil) : null,
|
||||||
|
showAfter: property_exists($req, 'showAfter') ? convertDate($req->showAfter) : null,
|
||||||
|
recurrence: $recur,
|
||||||
|
history: array_map(fn(stdClass $hist) =>
|
||||||
|
new History(
|
||||||
|
asOf: convertDate($hist->asOf),
|
||||||
|
action: RequestAction::from($hist->status),
|
||||||
|
text: property_exists($hist, 'text') ? $hist->text : null),
|
||||||
|
$req->history),
|
||||||
|
notes: array_map(fn(stdClass $note) =>
|
||||||
|
new Note(convertDate($note->asOf), $note->notes), $req->notes ?? [])));
|
||||||
|
}
|
||||||
|
|
||||||
|
echo PHP_EOL . 'done' . PHP_EOL;
|
||||||
94
src/lib/Auth.php
Normal file
94
src/lib/Auth.php
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MyPrayerJournal;
|
||||||
|
|
||||||
|
use Auth0\SDK\Auth0;
|
||||||
|
use Auth0\SDK\Exception\ConfigurationException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* myPrayerJournal-specific authorization functions
|
||||||
|
*/
|
||||||
|
class Auth
|
||||||
|
{
|
||||||
|
/** @var Auth0|null The Auth0 client to use for requests (initialized on first use) */
|
||||||
|
private static ?Auth0 $auth0 = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current Auth0 client
|
||||||
|
*
|
||||||
|
* @return Auth0 The current Auth0 client
|
||||||
|
*/
|
||||||
|
public static function client(): Auth0
|
||||||
|
{
|
||||||
|
if (is_null(self::$auth0)) {
|
||||||
|
self::$auth0 = new Auth0([
|
||||||
|
'domain' => $_ENV['AUTH0_DOMAIN'],
|
||||||
|
'clientId' => $_ENV['AUTH0_CLIENT_ID'],
|
||||||
|
'clientSecret' => $_ENV['AUTH0_CLIENT_SECRET'],
|
||||||
|
'cookieSecret' => $_ENV['AUTH0_COOKIE_SECRET']
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return self::$auth0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the logged on user information
|
||||||
|
*
|
||||||
|
* @return array|null The user information (null if no user is logged on)
|
||||||
|
*/
|
||||||
|
public static function user(): ?array
|
||||||
|
{
|
||||||
|
return self::client()->getUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initiate a log on with Auth0
|
||||||
|
*
|
||||||
|
* @throws ConfigurationException If the Auth0 client is not configured correctly
|
||||||
|
*/
|
||||||
|
public static function logOn(): never
|
||||||
|
{
|
||||||
|
$params = match (true) {
|
||||||
|
$_SERVER['PHP_SELF'] <> '/user/log-on.php' => ['redirectUri' => $_SERVER['PHP_SELF']],
|
||||||
|
default => []
|
||||||
|
};
|
||||||
|
|
||||||
|
self::client()->clear();
|
||||||
|
header('Location: ' . self::client()->login($_ENV['AUTH0_BASE_URL'] . '/user/log-on/success', $params));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log off from this application and Auth0
|
||||||
|
*
|
||||||
|
* @throws ConfigurationException If the Auth0 client is not configured correctly
|
||||||
|
*/
|
||||||
|
public static function logOff(): never
|
||||||
|
{
|
||||||
|
session_destroy();
|
||||||
|
header('Location: ' . self::client()->logout($_ENV['AUTH0_BASE_URL']));
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Require a user be logged on
|
||||||
|
*
|
||||||
|
* @param bool $redirect Whether to redirect to log on if there is not a user logged on
|
||||||
|
* @return void If it returns, there is a user logged on; if not, we will be redirected to log on
|
||||||
|
* @throws ConfigurationException If the Auth0 client is not configured correctly
|
||||||
|
*/
|
||||||
|
public static function requireUser(bool $redirect = true): void
|
||||||
|
{
|
||||||
|
if (is_null(self::user())) {
|
||||||
|
if ($redirect) self::logOn();
|
||||||
|
http_response_code(403);
|
||||||
|
die('Not Authorized');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
53
src/lib/Domain/History.php
Normal file
53
src/lib/Domain/History.php
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MyPrayerJournal\Domain;
|
||||||
|
|
||||||
|
use BitBadger\InspiredByFSharp\Option;
|
||||||
|
use Square\Pjson\{Json, JsonSerialize};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A record of an action taken on a request
|
||||||
|
*/
|
||||||
|
class History
|
||||||
|
{
|
||||||
|
use JsonSerialize;
|
||||||
|
|
||||||
|
/** @var string The date/time this entry was made */
|
||||||
|
#[Json]
|
||||||
|
public string $asOf = '';
|
||||||
|
|
||||||
|
/** @var RequestAction The action taken for this history entry */
|
||||||
|
#[Json]
|
||||||
|
public RequestAction $action;
|
||||||
|
|
||||||
|
/** @var string|null The text for this history entry (optional) */
|
||||||
|
#[Json('text', omit_empty: true)]
|
||||||
|
private ?string $dbText {
|
||||||
|
get => $this->text->unwrap();
|
||||||
|
set { $this->text = Option::of($value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Option<string> The text for this history entry */
|
||||||
|
public Option $text {
|
||||||
|
get => $this->text ?? Option::None();
|
||||||
|
set { $this->text = $value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $asOf The date/time this entry was made
|
||||||
|
* @param RequestAction $action The action taken for this history entry
|
||||||
|
* @param string|null $text The text for this history entry (optional)
|
||||||
|
*/
|
||||||
|
public function __construct(string $asOf, RequestAction $action, ?string $text = null)
|
||||||
|
{
|
||||||
|
$this->asOf = $asOf;
|
||||||
|
$this->action = $action;
|
||||||
|
$this->dbText = $text;
|
||||||
|
}
|
||||||
|
}
|
||||||
39
src/lib/Domain/Note.php
Normal file
39
src/lib/Domain/Note.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MyPrayerJournal\Domain;
|
||||||
|
|
||||||
|
use BitBadger\InspiredByFSharp\Option;
|
||||||
|
use BitBadger\PDODocument\DocumentException;
|
||||||
|
use Square\Pjson\{Json, JsonSerialize};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A note entered on a prayer request
|
||||||
|
*/
|
||||||
|
class Note
|
||||||
|
{
|
||||||
|
use JsonSerialize;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $asOf The date/time this note was recorded
|
||||||
|
* @param string $text The text of the note
|
||||||
|
*/
|
||||||
|
public function __construct(#[Json] public string $asOf, #[Json] public string $text) { }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve notes for a given request
|
||||||
|
*
|
||||||
|
* @param string $id The ID of the request for which notes should be retrieved
|
||||||
|
* @return array|Note[] The notes for the request, or an empty array if the request was not found
|
||||||
|
* @throws DocumentException If any is encountered
|
||||||
|
*/
|
||||||
|
public static function byRequestId(string $id): array
|
||||||
|
{
|
||||||
|
return Request::byId($id)->map(fn(Request $it) => Option::Some($it->notes))->getOrDefault([]);
|
||||||
|
}
|
||||||
|
}
|
||||||
67
src/lib/Domain/Recurrence.php
Normal file
67
src/lib/Domain/Recurrence.php
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MyPrayerJournal\Domain;
|
||||||
|
|
||||||
|
use BitBadger\InspiredByFSharp\Option;
|
||||||
|
use DateInterval;
|
||||||
|
use Square\Pjson\{Json, JsonSerialize};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The recurrence for a prayer request
|
||||||
|
*/
|
||||||
|
class Recurrence
|
||||||
|
{
|
||||||
|
use JsonSerialize;
|
||||||
|
|
||||||
|
/** @var RecurrencePeriod The recurrence period */
|
||||||
|
#[Json]
|
||||||
|
public RecurrencePeriod $period {
|
||||||
|
get => $this->period ?? RecurrencePeriod::Immediate;
|
||||||
|
set { $this->period = $value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var int|null How many of the periods will pass before the request is visible again */
|
||||||
|
#[Json('interval', omit_empty: true)]
|
||||||
|
private ?int $dbInterval {
|
||||||
|
get => $this->interval->unwrap();
|
||||||
|
set { $this->interval = Option::of($value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Option<int> How many of the periods will pass before the request is visible again */
|
||||||
|
public Option $interval {
|
||||||
|
get => $this->interval ?? Option::None();
|
||||||
|
set { $this->interval = $value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param RecurrencePeriod $period The recurrence period
|
||||||
|
* @param int|null $interval How many of the periods will pass before the request is visible again
|
||||||
|
*/
|
||||||
|
public function __construct(RecurrencePeriod $period, ?int $interval = null)
|
||||||
|
{
|
||||||
|
$this->period = $period;
|
||||||
|
$this->dbInterval = $interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the date/time interval for this recurrence
|
||||||
|
*
|
||||||
|
* @return DateInterval The interval matching the recurrence
|
||||||
|
*/
|
||||||
|
public function interval(): DateInterval
|
||||||
|
{
|
||||||
|
$period = match ($this->period) {
|
||||||
|
RecurrencePeriod::Immediate => 'T0S',
|
||||||
|
RecurrencePeriod::Hours => "T{$this->interval->value}H",
|
||||||
|
RecurrencePeriod::Days => "{$this->interval->value}D",
|
||||||
|
RecurrencePeriod::Weeks => ($this->interval->value * 7) . 'D'
|
||||||
|
};
|
||||||
|
return new DateInterval("P$period");
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/lib/Domain/RecurrencePeriod.php
Normal file
27
src/lib/Domain/RecurrencePeriod.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MyPrayerJournal\Domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of recurrence a request can have
|
||||||
|
*/
|
||||||
|
enum RecurrencePeriod: string
|
||||||
|
{
|
||||||
|
/** Requests, once prayed, are available again immediately */
|
||||||
|
case Immediate = 'Immediate';
|
||||||
|
|
||||||
|
/** Requests, once prayed, appear again in a number of hours */
|
||||||
|
case Hours = 'Hours';
|
||||||
|
|
||||||
|
/** Requests, once prayed, appear again in a number of days */
|
||||||
|
case Days = 'Days';
|
||||||
|
|
||||||
|
/** Requests, once prayed, appear again in a number of weeks */
|
||||||
|
case Weeks = 'Weeks';
|
||||||
|
}
|
||||||
204
src/lib/Domain/Request.php
Normal file
204
src/lib/Domain/Request.php
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MyPrayerJournal\Domain;
|
||||||
|
|
||||||
|
use BitBadger\InspiredByFSharp\Option;
|
||||||
|
use BitBadger\PDODocument\{Custom, DocumentException, DocumentList, Find};
|
||||||
|
use BitBadger\PDODocument\Mapper\DocumentMapper;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use Exception;
|
||||||
|
use MyPrayerJournal\Table;
|
||||||
|
use Square\Pjson\{Json, JsonSerialize};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A prayer request
|
||||||
|
*/
|
||||||
|
class Request
|
||||||
|
{
|
||||||
|
use JsonSerialize;
|
||||||
|
|
||||||
|
/** @var string The ID for the request */
|
||||||
|
#[Json]
|
||||||
|
public string $id = '';
|
||||||
|
|
||||||
|
/** @var string The date/time this request was originally entered */
|
||||||
|
#[Json]
|
||||||
|
public string $enteredOn = '';
|
||||||
|
|
||||||
|
/** @var string The ID of the user to whom this request belongs */
|
||||||
|
#[Json]
|
||||||
|
public string $userId = '';
|
||||||
|
|
||||||
|
/** @var string|null The date/time the snooze expires for this request (null = not snoozed) */
|
||||||
|
#[Json('snoozedUntil', omit_empty: true)]
|
||||||
|
private ?string $dbSnoozedUntil {
|
||||||
|
get => $this->snoozedUntil->unwrap();
|
||||||
|
set { $this->snoozedUntil = Option::of($value); }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Option<string> The date/time the snooze expires for this request (None = not snoozed) */
|
||||||
|
public Option $snoozedUntil {
|
||||||
|
get => $this->snoozedUntil ?? Option::None();
|
||||||
|
set { $this->snoozedUntil = $value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var string|null The date/time the current recurrence period is over (null = immediate) */
|
||||||
|
#[Json(omit_empty: true)]
|
||||||
|
public ?string $showAfter = null;
|
||||||
|
|
||||||
|
/** @var Recurrence The recurrence for this request */
|
||||||
|
#[Json]
|
||||||
|
public Recurrence $recurrence {
|
||||||
|
get => $this->recurrence ?? new Recurrence(RecurrencePeriod::Immediate);
|
||||||
|
set => $this->recurrence = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var History[] The history of this request */
|
||||||
|
#[Json(type: History::class)]
|
||||||
|
public array $history = [];
|
||||||
|
|
||||||
|
/** @param Note[] $notes Notes regarding this request */
|
||||||
|
#[Json(type: Note::class)]
|
||||||
|
public array $notes = [];
|
||||||
|
|
||||||
|
/** The current text for this request */
|
||||||
|
public string $currentText {
|
||||||
|
get => Option::of(array_find($this->history, fn(History $it) => $it->text->isSome))
|
||||||
|
->map(fn(History $it) => $it->text->value)
|
||||||
|
->getOrDefault('');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var Option<string> The date/time this request was last marked as prayed */
|
||||||
|
public Option $lastPrayed {
|
||||||
|
get => Option::of(array_find($this->history, fn(History $it) => $it->action === RequestAction::Prayed))
|
||||||
|
->map(fn(History $it) => $it->asOf);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Has this request been answered? */
|
||||||
|
public bool $isAnswered {
|
||||||
|
get => $this->history[0]->action === RequestAction::Answered;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Is this request currently snoozed? */
|
||||||
|
public bool $isSnoozed {
|
||||||
|
get => $this->snoozedUntil->isSome
|
||||||
|
&& new DateTimeImmutable($this->snoozedUntil->value) > 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 bool $isPending {
|
||||||
|
get => !$this->isSnoozed
|
||||||
|
&& isset($this->showAfter)
|
||||||
|
&& new DateTimeImmutable($this->showAfter) > new DateTimeImmutable('now');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find a request by its ID
|
||||||
|
*
|
||||||
|
* @param string $id The ID of the request
|
||||||
|
* @return Option<Request> The request (if it is found and belongs to the current user)
|
||||||
|
* @throws DocumentException If any is encountered
|
||||||
|
*/
|
||||||
|
public static function byId(string $id): Option
|
||||||
|
{
|
||||||
|
return Find::byId(Table::REQUEST, $id, self::class)
|
||||||
|
->map(fn(Request $it) => $it->userId === $_SESSION['user_id'] ? $it : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the user's active journal requests
|
||||||
|
*
|
||||||
|
* @return DocumentList<Request> The requests for the user's journal
|
||||||
|
* @throws DocumentException If any is encountered
|
||||||
|
*/
|
||||||
|
public static function forJournal(): DocumentList
|
||||||
|
{
|
||||||
|
$table = Table::REQUEST;
|
||||||
|
return Custom::list(<<<SQL
|
||||||
|
SELECT data, (
|
||||||
|
SELECT h.value->>'asOf' as_of
|
||||||
|
FROM $table i LEFT JOIN json_each(i.data, '$.history') h
|
||||||
|
WHERE r.data->>'id' = i.data->>'id' AND h.value->>'action' = 'Prayed'
|
||||||
|
LIMIT 1) last_prayed
|
||||||
|
FROM $table r
|
||||||
|
WHERE data->>'userId' = :userId
|
||||||
|
AND data->>'$.history[0].action' <> 'Answered'
|
||||||
|
AND (data->>'snoozedUntil' IS NULL OR data->>'snoozedUntil' < datetime('now'))
|
||||||
|
AND (data->>'showAfter' IS NULL OR data->>'showAfter' < datetime('now'))
|
||||||
|
ORDER BY coalesce(last_prayed, data->>'snoozedUntil', data->>'showAfter', data->>'$.history[0].asOf')
|
||||||
|
SQL, [':userId' => $_SESSION['user_id']], new DocumentMapper(self::class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get either the user's active or answered requests
|
||||||
|
*
|
||||||
|
* @param bool $active True to retrieve active requests, false to retrieve answered requests
|
||||||
|
* @param bool $snoozed True to retrieve only snoozed requests
|
||||||
|
* @return DocumentList<Request> The requests matching the criteria
|
||||||
|
* @throws DocumentException If any is encountered
|
||||||
|
*/
|
||||||
|
private static function forUser(bool $active = true, bool $snoozed = false): DocumentList
|
||||||
|
{
|
||||||
|
$table = Table::REQUEST;
|
||||||
|
$op = $active ? '<>' : '=';
|
||||||
|
$extra = $snoozed ? "AND datetime(data->>'snoozedUntil') > datetime('now')" : '';
|
||||||
|
$order = $active
|
||||||
|
? "coalesce(data->>'snoozedUntil', data->>'showAfter', last_prayed, data->>'$.history[0].asOf')"
|
||||||
|
: "data->>'$.history[0].asOf' DESC";
|
||||||
|
return Custom::list(<<<SQL
|
||||||
|
SELECT data, (
|
||||||
|
SELECT h.value->>'asOf' as_of
|
||||||
|
FROM $table i LEFT JOIN json_each(i.data, '$.history') h
|
||||||
|
WHERE r.data->>'id' = i.data->>'id' AND h.value->>'action' = 'Prayed'
|
||||||
|
LIMIT 1) last_prayed
|
||||||
|
FROM $table r
|
||||||
|
WHERE data->>'userId' = :userId
|
||||||
|
AND data->>'$.history[0].action' $op 'Answered' $extra
|
||||||
|
ORDER BY $order
|
||||||
|
SQL, [':userId' => $_SESSION['user_id']], new DocumentMapper(self::class));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of active requests for a user
|
||||||
|
*
|
||||||
|
* @return DocumentList<Request> The user's active requests
|
||||||
|
* @throws DocumentException If any is encountered
|
||||||
|
*/
|
||||||
|
public static function active(): DocumentList
|
||||||
|
{
|
||||||
|
return self::forUser();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of answered requests for a user
|
||||||
|
*
|
||||||
|
* @return DocumentList<Request> The user's answered requests
|
||||||
|
* @throws DocumentException If any is encountered
|
||||||
|
*/
|
||||||
|
public static function answered(): DocumentList
|
||||||
|
{
|
||||||
|
return self::forUser(active: false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of snoozed requests for a user
|
||||||
|
*
|
||||||
|
* @return DocumentList<Request> The user's snoozed requests
|
||||||
|
* @throws DocumentException If any is encountered
|
||||||
|
*/
|
||||||
|
public static function snoozed(): DocumentList
|
||||||
|
{
|
||||||
|
return self::forUser(snoozed: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
27
src/lib/Domain/RequestAction.php
Normal file
27
src/lib/Domain/RequestAction.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MyPrayerJournal\Domain;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An action taken on a prayer request
|
||||||
|
*/
|
||||||
|
enum RequestAction: string
|
||||||
|
{
|
||||||
|
/** The request was created */
|
||||||
|
case Created = 'Created';
|
||||||
|
|
||||||
|
/** The request was marked as having been prayed for */
|
||||||
|
case Prayed = 'Prayed';
|
||||||
|
|
||||||
|
/** The request was updated */
|
||||||
|
case Updated = 'Updated';
|
||||||
|
|
||||||
|
/** The request was marked as answered */
|
||||||
|
case Answered = 'Answered';
|
||||||
|
}
|
||||||
18
src/lib/Table.php
Normal file
18
src/lib/Table.php
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MyPrayerJournal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constants for table names
|
||||||
|
*/
|
||||||
|
class Table
|
||||||
|
{
|
||||||
|
/** @var string The prayer request table used by myPrayerJournal */
|
||||||
|
const string REQUEST = 'request';
|
||||||
|
}
|
||||||
179
src/lib/UI/Component.php
Normal file
179
src/lib/UI/Component.php
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MyPrayerJournal\UI;
|
||||||
|
|
||||||
|
use BitBadger\PDODocument\{DocumentException, DocumentList};
|
||||||
|
use DateTimeImmutable;
|
||||||
|
use DateTimeZone;
|
||||||
|
use Exception;
|
||||||
|
use MyPrayerJournal\Domain\Request;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User interface building blocks
|
||||||
|
*/
|
||||||
|
class Component
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Generate a material icon
|
||||||
|
*
|
||||||
|
* @param string $name The name of the material icon
|
||||||
|
* @return string The material icon wrapped in a `span` tag
|
||||||
|
*/
|
||||||
|
public static function icon(string $name): string {
|
||||||
|
return "<span class=material-icons>$name</span>";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the journal items for the current user
|
||||||
|
*
|
||||||
|
* @throws DocumentException If any is encountered
|
||||||
|
*/
|
||||||
|
public static function journal(): void
|
||||||
|
{
|
||||||
|
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) {
|
||||||
|
$lastPrayed = $req->lastPrayed;
|
||||||
|
$lastActivity = $lastPrayed->getOrDefault($req->history[0]->asOf); ?>
|
||||||
|
<div class=col>
|
||||||
|
<div class="card h-100">
|
||||||
|
<div class="card-header p-0 d-flex" role=toolbar>
|
||||||
|
<?=self::pageLink("/request/edit?id=$req->id", self::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-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
|
||||||
|
data-bs-target=#snoozeModal hx-get="/components/request/snooze?id=<?=$req->id?>"
|
||||||
|
hx-target=#snoozeBody hx-swap=innerHTML><?=self::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"><?=self::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>last <?=$lastPrayed->map(fn() => 'prayed')->getOrDefault('activity')?>
|
||||||
|
<?=self::relativeDate($lastPrayed->getOrDefault($req->history[0]->asOf))?>
|
||||||
|
</em>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div><?php
|
||||||
|
} ?>
|
||||||
|
</section><?php
|
||||||
|
} else {
|
||||||
|
Component::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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a card when there are no results found
|
||||||
|
*/
|
||||||
|
public static function noResults(string $heading, string $link, string $buttonText, string $text): void
|
||||||
|
{ ?>
|
||||||
|
<div class=card>
|
||||||
|
<h5 class=card-header><?=$heading?></h5>
|
||||||
|
<div class="card-body text-center">
|
||||||
|
<p class=card-text><?=$text?></p>
|
||||||
|
<?=self::pageLink($link, $buttonText, ['class' => 'btn btn-primary'])?>
|
||||||
|
</div>
|
||||||
|
</div><?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a link to a page within myPrayerJournal
|
||||||
|
*
|
||||||
|
* @param string $href The URL for the link
|
||||||
|
* @param string $text The text for the link
|
||||||
|
* @param array $attrs Any additional attributes that should be placed on the `a` tag
|
||||||
|
*/
|
||||||
|
public static function pageLink(string $href, string $text, array $attrs = []): string
|
||||||
|
{
|
||||||
|
$extraAttrs = array_reduce(array_keys($attrs),
|
||||||
|
fn($acc, $key) => $acc . sprintf(' %s="%s"', $key, $attrs[$key]), '');
|
||||||
|
return sprintf('<a href="%s" hx-get="%s" hx-target=#top hx-swap=innerHTML hx-push-url=true%s>%s</a>', $href,
|
||||||
|
$href, $extraAttrs, $text);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a relative date with a tooltip with the actual date/time
|
||||||
|
*
|
||||||
|
* @return string The HTML for the relative date
|
||||||
|
* @throws Exception If the date/time cannot be parsed
|
||||||
|
*/
|
||||||
|
public static function relativeDate(string $date): string
|
||||||
|
{
|
||||||
|
$parsed = new DateTimeImmutable($date);
|
||||||
|
$iso = $parsed->format('c');
|
||||||
|
$title = $parsed->setTimezone(new DateTimeZone($_REQUEST['time_zone']))->format('l, F j, Y \a\t g:ia T');
|
||||||
|
return "<relative-date-time title=\"$title\" interval=10000>$iso</relative-date-time>";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render a request list item
|
||||||
|
*
|
||||||
|
* @param Request $req The request on which the list items should be based
|
||||||
|
* @throws Exception If date/time values cannot be parsed
|
||||||
|
*/
|
||||||
|
public static function requestItem(Request $req): void
|
||||||
|
{
|
||||||
|
$btnClass = "btn btn-light mx-2";
|
||||||
|
$restoreBtn = fn(string $id, string $link, string $title) => sprintf(
|
||||||
|
'<button class="%s" hx-patch="/request/%s?id=%s" title="%s" hx-target=#req-%s hx-swap=outerHTML>%s</button>',
|
||||||
|
$btnClass, $link, $id, htmlspecialchars($title), $id, self::icon('restore')); ?>
|
||||||
|
<div class="list-group-item px-0 d-flex flex-row align-items-start" id=req-<?=$req->id?>><?php
|
||||||
|
echo self::pageLink("/request/full?id=$req->id", self::icon('description'),
|
||||||
|
['class' => $btnClass, 'title' => 'View Full Request']);
|
||||||
|
if (!$req->isAnswered) {
|
||||||
|
echo self::pageLink("/request/edit?id=$req->id", self::icon('edit'),
|
||||||
|
['class' => $btnClass, 'title' => 'Edit Request']);
|
||||||
|
}
|
||||||
|
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">' . htmlentities($req->currentText);
|
||||||
|
if ($req->isSnoozed || $req->isPending || $req->isAnswered) { ?>
|
||||||
|
<br>
|
||||||
|
<small class=text-muted><em><?php
|
||||||
|
echo match (true) {
|
||||||
|
$req->isSnoozed => 'Snooze expires ' . self::relativeDate($req->snoozedUntil->value),
|
||||||
|
$req->isPending => 'Request appears next ' . self::relativeDate($req->showAfter),
|
||||||
|
default => 'Answered ' . self::relativeDate($req->history[0]->asOf)
|
||||||
|
};?>
|
||||||
|
</em></small><?php
|
||||||
|
} ?>
|
||||||
|
</div><?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render the given list of requests
|
||||||
|
*
|
||||||
|
* @param DocumentList<Request> $reqs The list of requests to render
|
||||||
|
* @throws Exception If date/time instances are not valid
|
||||||
|
*/
|
||||||
|
public static function requestList(DocumentList $reqs): void
|
||||||
|
{
|
||||||
|
echo '<div class=list-group>';
|
||||||
|
$reqs->iter(self::requestItem(...));
|
||||||
|
echo '</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
187
src/lib/UI/Layout.php
Normal file
187
src/lib/UI/Layout.php
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace MyPrayerJournal\UI;
|
||||||
|
|
||||||
|
use BitBadger\PDODocument\Custom;
|
||||||
|
use BitBadger\PDODocument\Mapper\ExistsMapper;
|
||||||
|
use MyPrayerJournal\Table;
|
||||||
|
|
||||||
|
class Layout
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Generate the heading for a bare result
|
||||||
|
*/
|
||||||
|
public static function bareHead(): void
|
||||||
|
{
|
||||||
|
echo '<!DOCTYPE html><html lang=en><head><title></title></head><body>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the end of a bare result
|
||||||
|
*/
|
||||||
|
public static function bareFoot(): void
|
||||||
|
{
|
||||||
|
echo '</body></html>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is this an htmx request?
|
||||||
|
*
|
||||||
|
* @return bool True if this is an htmx request, false if not
|
||||||
|
*/
|
||||||
|
private static function isHtmx(): bool
|
||||||
|
{
|
||||||
|
return key_exists('HTTP_HX_REQUEST', $_SERVER) && !key_exists('HTTP_HX_HISTORY_RESTORE_REQUEST', $_SERVER);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the `DOCTYPE` declaration, `html`, and `head` tags for the page
|
||||||
|
*
|
||||||
|
* @param string $title The title of the page
|
||||||
|
*/
|
||||||
|
public static function htmlHead(string $title): void
|
||||||
|
{
|
||||||
|
if (self::isHtmx()) {
|
||||||
|
echo "<!DOCTYPE html><html lang=en><head lang=en><title>$title « myPrayerJournal</title></head>";
|
||||||
|
} else {
|
||||||
|
echo <<<HEAD
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang=en>
|
||||||
|
<head>
|
||||||
|
<meta name=viewport content="width=device-width, initial-scale=1">
|
||||||
|
<meta name=description content="Online prayer journal - free w/Google or Microsoft account">
|
||||||
|
<meta name=htmx-config content='{"historyCacheSize":0}'>
|
||||||
|
<title>$title « myPrayerJournal</title>
|
||||||
|
<link href=https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css rel=stylesheet
|
||||||
|
integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
|
||||||
|
crossorigin=anonymous>
|
||||||
|
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel=stylesheet>
|
||||||
|
<link href=/_/style.css rel=stylesheet>
|
||||||
|
</head>
|
||||||
|
HEAD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function navLink(string $url, string $text): void
|
||||||
|
{
|
||||||
|
$classAttr = match (true) {
|
||||||
|
str_starts_with($_SERVER['PHP_SELF'], $url) => ['class' => 'is-active-route'],
|
||||||
|
default => []
|
||||||
|
};
|
||||||
|
echo '<li class=nav-item>' . Component::pageLink($url, $text, $classAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default navigation bar, which will load the items on page load, and whenever a refresh event occurs
|
||||||
|
*/
|
||||||
|
public static function navBar(): void
|
||||||
|
{
|
||||||
|
$table = Table::REQUEST;
|
||||||
|
$hasSnoozed = key_exists('user_id', $_SESSION)
|
||||||
|
? Custom::scalar(<<<SQL
|
||||||
|
SELECT EXISTS (
|
||||||
|
SELECT 1 FROM $table
|
||||||
|
WHERE data->>'userId' = :userId AND datetime(data->>'snoozedUntil') > datetime('now'))
|
||||||
|
SQL, [':userId' => $_SESSION['user_id']], new ExistsMapper())
|
||||||
|
: false; ?>
|
||||||
|
<nav class="navbar navbar-dark" role="navigation">
|
||||||
|
<div class=container-fluid>
|
||||||
|
<?=Component::pageLink('/',
|
||||||
|
'<span class=m>my</span><span class=p>Prayer</span><span class=j>Journal</span>',
|
||||||
|
['class' => 'navbar-brand'])?>
|
||||||
|
<ul class="navbar-nav me-auto d-flex flex-row"><?php
|
||||||
|
if (key_exists('user_id', $_SESSION)) {
|
||||||
|
self::navLink('/journal', 'Journal');
|
||||||
|
self::navLink('/requests/active', 'Active');
|
||||||
|
if ($hasSnoozed) self::navLink('/requests/snoozed', 'Snoozed');
|
||||||
|
self::navLink('/requests/answered', 'Answered'); ?>
|
||||||
|
<li class=nav-item><a href=/user/log-off>Log Off</a><?php
|
||||||
|
} else { ?>
|
||||||
|
<li class=nav-item><a href=/user/log-on>Log On</a><?php
|
||||||
|
}
|
||||||
|
self::navLink('/docs', 'Docs'); ?>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</nav><?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Drop .0 or .0.0 from the end of the version to format it for display
|
||||||
|
*
|
||||||
|
* @return string The version of the application for user display
|
||||||
|
*/
|
||||||
|
private static function displayVersion(): string {
|
||||||
|
[$major, $minor, $rev] = explode('.', MPJ_VERSION);
|
||||||
|
$minor = $minor == '0' ? '' : ".$minor";
|
||||||
|
$rev = match (true) {
|
||||||
|
$rev == '0' => '',
|
||||||
|
str_starts_with($rev, '0-') => substr($rev, 1),
|
||||||
|
default => ".$rev"
|
||||||
|
};
|
||||||
|
return "v$major$minor$rev";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create the footer
|
||||||
|
*/
|
||||||
|
public static function htmlFoot(): void
|
||||||
|
{ ?>
|
||||||
|
<footer class=container-fluid>
|
||||||
|
<p class="text-muted text-end">
|
||||||
|
myPrayerJournal <?=self::displayVersion();?><br>
|
||||||
|
<em><small>
|
||||||
|
<?=Component::pageLink('/legal/privacy-policy', 'Privacy Policy')?> •
|
||||||
|
<?=Component::pageLink('/legal/terms-of-service', 'Terms of Service')?> •
|
||||||
|
<a href=https://git.bitbadger.solutions/bit-badger/myPrayerJournal target=_blank
|
||||||
|
rel=noopener>Developed</a> and hosted by
|
||||||
|
<a href=https://bitbadger.solutions target=_blank rel=noopener>Bit Badger Solutions</a>
|
||||||
|
</small></em>
|
||||||
|
<script src=https://unpkg.com/htmx.org@2.0.4 crossorigin=anonymous
|
||||||
|
integrity="sha384-HGfztofotfshcF7+8n44JQL2oJmowVChPTg48S+jvZoztPfvwD79OC/LTtG6dMp+"></script>
|
||||||
|
<script>if (!htmx) document.write('<script src=\"/_/htmx.min.js\"><\/script>')</script>
|
||||||
|
<script async src=https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js
|
||||||
|
integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL"
|
||||||
|
crossorigin=anonymous></script>
|
||||||
|
<script>
|
||||||
|
setTimeout(function () {
|
||||||
|
if (!bootstrap) document.write('<script src=\"/_/bootstrap.bundle.min.js\"><\/script>')
|
||||||
|
}, 2000)
|
||||||
|
</script>
|
||||||
|
<script src=/_/mpj.js></script>
|
||||||
|
<script src=/_/relative-date-time.js defer></script>
|
||||||
|
</footer><?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the heading for a full or partial page result
|
||||||
|
*
|
||||||
|
* @param string $title The title of the page
|
||||||
|
*/
|
||||||
|
public static function pageHead(string $title): void
|
||||||
|
{
|
||||||
|
self::htmlHead($title);
|
||||||
|
echo '<body>';
|
||||||
|
if (!self::isHtmx()) echo '<section id=top aria-label="Top navigation">';
|
||||||
|
self::navBar();
|
||||||
|
echo '<main role=main>';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the end of the page for a full or partial page result
|
||||||
|
*/
|
||||||
|
public static function pageFoot(): void
|
||||||
|
{
|
||||||
|
echo '</main>';
|
||||||
|
if (!self::isHtmx()) {
|
||||||
|
echo '</section>';
|
||||||
|
self::htmlFoot();
|
||||||
|
}
|
||||||
|
echo '</body></html>';
|
||||||
|
}
|
||||||
|
}
|
||||||
7
src/public/_/bootstrap.bundle.min.js
vendored
Normal file
7
src/public/_/bootstrap.bundle.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
1
src/public/_/htmx.min.js
vendored
Normal file
1
src/public/_/htmx.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
104
src/public/_/mpj.js
Normal file
104
src/public/_/mpj.js
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
"use strict"
|
||||||
|
|
||||||
|
/** myPrayerJournal script */
|
||||||
|
window.mpj = {
|
||||||
|
/**
|
||||||
|
* Show a message via toast
|
||||||
|
* @param {string} message The message to show
|
||||||
|
*/
|
||||||
|
showToast (message) {
|
||||||
|
const [level, msg] = message.split("|||")
|
||||||
|
|
||||||
|
let header
|
||||||
|
if (level !== "success") {
|
||||||
|
const heading = typ => `<span class="me-auto"><strong>${typ.toUpperCase()}</strong></span>`
|
||||||
|
|
||||||
|
header = document.createElement("div")
|
||||||
|
header.className = "toast-header"
|
||||||
|
header.innerHTML = heading(level === "warning" ? level : "error")
|
||||||
|
|
||||||
|
const close = document.createElement("button")
|
||||||
|
close.type = "button"
|
||||||
|
close.className = "btn-close"
|
||||||
|
close.setAttribute("data-bs-dismiss", "toast")
|
||||||
|
close.setAttribute("aria-label", "Close")
|
||||||
|
header.appendChild(close)
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = document.createElement("div")
|
||||||
|
body.className = "toast-body"
|
||||||
|
body.innerText = msg
|
||||||
|
|
||||||
|
const toastEl = document.createElement("div")
|
||||||
|
toastEl.className = `toast bg-${level === "error" ? "danger" : level} text-white`
|
||||||
|
toastEl.setAttribute("role", "alert")
|
||||||
|
toastEl.setAttribute("aria-live", "assertlive")
|
||||||
|
toastEl.setAttribute("aria-atomic", "true")
|
||||||
|
toastEl.addEventListener("hidden.bs.toast", e => e.target.remove())
|
||||||
|
if (header) toastEl.appendChild(header)
|
||||||
|
|
||||||
|
toastEl.appendChild(body)
|
||||||
|
document.getElementById("toasts").appendChild(toastEl)
|
||||||
|
new bootstrap.Toast(toastEl, { autohide: level === "success" }).show()
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* Load local version of Bootstrap CSS if the CDN load failed
|
||||||
|
*/
|
||||||
|
ensureCss () {
|
||||||
|
let loaded = false
|
||||||
|
for (let i = 0; !loaded && i < document.styleSheets.length; i++) {
|
||||||
|
loaded = document.styleSheets[i].href.endsWith("bootstrap.min.css")
|
||||||
|
}
|
||||||
|
if (!loaded) {
|
||||||
|
const css = document.createElement("link")
|
||||||
|
css.rel = "stylesheet"
|
||||||
|
css.href = "/style/bootstrap.min.css"
|
||||||
|
document.getElementsByTagName("head")[0].appendChild(css)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/** Script for the request edit component */
|
||||||
|
edit: {
|
||||||
|
/**
|
||||||
|
* Toggle the recurrence input fields
|
||||||
|
* @param {Event} e The click event
|
||||||
|
*/
|
||||||
|
toggleRecurrence ({ target }) {
|
||||||
|
const isDisabled = target.value === "Immediate"
|
||||||
|
;["recurCount", "recurInterval"].forEach(it => document.getElementById(it).disabled = isDisabled)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* The time zone of the current browser
|
||||||
|
* @type {string}
|
||||||
|
**/
|
||||||
|
timeZone: undefined,
|
||||||
|
/**
|
||||||
|
* Derive the time zone from the current browser
|
||||||
|
*/
|
||||||
|
deriveTimeZone () {
|
||||||
|
try {
|
||||||
|
this.timeZone = (new Intl.DateTimeFormat()).resolvedOptions().timeZone
|
||||||
|
} catch (_) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
htmx.on("htmx:afterOnLoad", function (evt) {
|
||||||
|
const hdrs = evt.detail.xhr.getAllResponseHeaders()
|
||||||
|
// Show a message if there was one in the response
|
||||||
|
if (hdrs.indexOf("x-toast") >= 0) {
|
||||||
|
mpj.showToast(evt.detail.xhr.getResponseHeader("x-toast"))
|
||||||
|
}
|
||||||
|
// Hide a modal window if requested
|
||||||
|
if (hdrs.indexOf("x-hide-modal") >= 0) {
|
||||||
|
document.getElementById(evt.detail.xhr.getResponseHeader("x-hide-modal") + "Dismiss").click()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
htmx.on("htmx:configRequest", function (evt) {
|
||||||
|
// Send the user's current time zone so that we can display local time
|
||||||
|
if (mpj.timeZone) {
|
||||||
|
evt.detail.headers["X-Time-Zone"] = mpj.timeZone
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
mpj.deriveTimeZone()
|
||||||
121
src/public/_/relative-date-time.js
Normal file
121
src/public/_/relative-date-time.js
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
"use strict"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relative Date/Time Custom HTML Element
|
||||||
|
*
|
||||||
|
* This creates an element that will take the existing date/time and replace it with words (ex. "about a year ago",
|
||||||
|
* "in 3 hours"). It will update based on the interval provided in the tag.
|
||||||
|
*
|
||||||
|
* ```html
|
||||||
|
* <relative-date-time interval=5000>2024-08-22T12:34:56+00:00</relative-date-time>
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
class RelativeDateTime extends HTMLElement {
|
||||||
|
|
||||||
|
static #LessThanXMinutes = Symbol()
|
||||||
|
static #XMinutes = Symbol()
|
||||||
|
static #AboutXHours = Symbol()
|
||||||
|
static #XDays = Symbol()
|
||||||
|
static #AboutXMonths = Symbol()
|
||||||
|
static #XMonths = Symbol()
|
||||||
|
static #AboutXYears = Symbol()
|
||||||
|
static #OverXYears = Symbol()
|
||||||
|
static #AlmostXYears = Symbol()
|
||||||
|
|
||||||
|
static #messages = new Map([
|
||||||
|
[RelativeDateTime.#LessThanXMinutes, ['less than a minute', 'less than %d minutes']],
|
||||||
|
[RelativeDateTime.#XMinutes, ['a minute', '%d minutes']],
|
||||||
|
[RelativeDateTime.#AboutXHours, ['about an hour', 'about %d hours']],
|
||||||
|
[RelativeDateTime.#XDays, ['a day', '%d days']],
|
||||||
|
[RelativeDateTime.#AboutXMonths, ['about a month', 'about %d months']],
|
||||||
|
[RelativeDateTime.#XMonths, ['a month', '%d months']],
|
||||||
|
[RelativeDateTime.#AboutXYears, ['about a year', 'about %d years']],
|
||||||
|
[RelativeDateTime.#OverXYears, ['over a year', 'over %d years']],
|
||||||
|
[RelativeDateTime.#AlmostXYears, ['almost a year', 'almost %d years']],
|
||||||
|
])
|
||||||
|
|
||||||
|
static #aDay = 1440.0
|
||||||
|
static #almost2Days = 2520.0
|
||||||
|
static #aMonth = 43200.0
|
||||||
|
static #twoMonths = 86400.0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The date, parsed from the `innerHTML` of the element
|
||||||
|
* @type Date
|
||||||
|
*/
|
||||||
|
#jsDate
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ID of the interval (set via `setTimeout`, passed to `clearTimeout`)
|
||||||
|
* @type ?number
|
||||||
|
*/
|
||||||
|
#timeOut = null
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
#update() {
|
||||||
|
|
||||||
|
const now = new Date()
|
||||||
|
const minutes = Math.abs((this.#jsDate.getTime() - now.getTime()) / 60 / 1000);
|
||||||
|
const months = Math.round(minutes / RelativeDateTime.#aMonth);
|
||||||
|
const years = Math.floor(months / 12);
|
||||||
|
|
||||||
|
/** @type symbol */
|
||||||
|
let typ
|
||||||
|
/** @type number */
|
||||||
|
let nbr
|
||||||
|
|
||||||
|
if (minutes < 1.0) {
|
||||||
|
typ = RelativeDateTime.#LessThanXMinutes
|
||||||
|
nbr = 1
|
||||||
|
} else if (minutes < 45.0) {
|
||||||
|
typ = RelativeDateTime.#XMinutes
|
||||||
|
nbr = Math.round(minutes)
|
||||||
|
} else if (minutes < 90.0) {
|
||||||
|
typ = RelativeDateTime.#AboutXHours
|
||||||
|
nbr = 1
|
||||||
|
} else if (minutes < RelativeDateTime.#aDay) {
|
||||||
|
typ = RelativeDateTime.#AboutXHours
|
||||||
|
nbr = Math.round(minutes / 60)
|
||||||
|
} else if (minutes < RelativeDateTime.#almost2Days) {
|
||||||
|
typ = RelativeDateTime.#XDays
|
||||||
|
nbr = 1
|
||||||
|
} else if (minutes < RelativeDateTime.#aMonth) {
|
||||||
|
typ = RelativeDateTime.#XDays
|
||||||
|
nbr = Math.round(minutes / RelativeDateTime.#aDay)
|
||||||
|
} else if (minutes < RelativeDateTime.#twoMonths) {
|
||||||
|
typ = RelativeDateTime.#AboutXMonths
|
||||||
|
nbr = Math.round(minutes / RelativeDateTime.#aMonth)
|
||||||
|
} else if (months < 12) {
|
||||||
|
typ = RelativeDateTime.#XMonths
|
||||||
|
nbr = Math.round(minutes / RelativeDateTime.#aMonth)
|
||||||
|
} else if (months % 12 < 3) {
|
||||||
|
typ = RelativeDateTime.#AboutXYears
|
||||||
|
nbr = years
|
||||||
|
} else if (months % 12 < 9) {
|
||||||
|
typ = RelativeDateTime.#OverXYears
|
||||||
|
nbr = years
|
||||||
|
} else {
|
||||||
|
typ = RelativeDateTime.#AlmostXYears
|
||||||
|
nbr = years + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
const tmpl = RelativeDateTime.#messages.get(typ)
|
||||||
|
const message = nbr === 1 ? tmpl[0] : tmpl[1].replace("%d", nbr.toString())
|
||||||
|
this.innerText = this.#jsDate < now ? `${message} ago` : `in ${message}`
|
||||||
|
}
|
||||||
|
|
||||||
|
connectedCallback() {
|
||||||
|
this.#jsDate = new Date(this.innerText)
|
||||||
|
this.#update()
|
||||||
|
this.#timeOut = setInterval(() => this.#update(), parseInt(this.getAttribute("interval")))
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnectedCallback() {
|
||||||
|
if (this.#timeOut) clearInterval(this.#timeOut)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
customElements.define("relative-date-time", RelativeDateTime)
|
||||||
57
src/public/_/style.css
Normal file
57
src/public/_/style.css
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
|
||||||
|
nav {
|
||||||
|
background-color: green;
|
||||||
|
}
|
||||||
|
nav .m {
|
||||||
|
font-weight: 100;
|
||||||
|
}
|
||||||
|
nav .p {
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
nav .j {
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
.nav-item a:link,
|
||||||
|
.nav-item a:visited {
|
||||||
|
padding: .5rem 1rem;
|
||||||
|
margin: 0 .5rem;
|
||||||
|
border-radius: .5rem;
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
.nav-item a:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
background-color: rgba(255, 255, 255, .2);
|
||||||
|
}
|
||||||
|
.nav-item a.is-active-route {
|
||||||
|
border-top-left-radius: 0;
|
||||||
|
border-top-right-radius: 0;
|
||||||
|
border-top: solid 4px rgba(255, 255, 255, .3);
|
||||||
|
}
|
||||||
|
|
||||||
|
form {
|
||||||
|
max-width: 60rem;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
.action-cell .material-icons {
|
||||||
|
font-size: 1.1rem ;
|
||||||
|
}
|
||||||
|
.material-icons {
|
||||||
|
vertical-align: bottom;
|
||||||
|
}
|
||||||
|
#toastHost {
|
||||||
|
position: sticky;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
.request-text {
|
||||||
|
white-space: pre-line
|
||||||
|
}
|
||||||
|
|
||||||
|
footer {
|
||||||
|
border-top: solid 1px lightgray;
|
||||||
|
margin: 1rem -1rem 0;
|
||||||
|
padding: 0 1rem;
|
||||||
|
}
|
||||||
|
footer p {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
17
src/public/components/journal-items.php
Normal file
17
src/public/components/journal-items.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\Auth;
|
||||||
|
use MyPrayerJournal\UI\Component;
|
||||||
|
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||||
|
require '../../start.php';
|
||||||
|
|
||||||
|
Auth::requireUser(false);
|
||||||
|
|
||||||
|
Component::journal();
|
||||||
30
src/public/components/request/add-note.php
Normal file
30
src/public/components/request/add-note.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\UI\Layout;
|
||||||
|
|
||||||
|
require '../../../start.php';
|
||||||
|
|
||||||
|
$req = validate_request($_GET['id'], ['GET'], false);
|
||||||
|
|
||||||
|
Layout::bareHead(); ?>
|
||||||
|
<form hx-post="/request/note?id=<?=$req->id?>">
|
||||||
|
<div class="form-floating pb-3">
|
||||||
|
<textarea id=notes name=notes class=form-control style="min-height: 8rem;" placeholder=Notes autofocus
|
||||||
|
required></textarea>
|
||||||
|
<label for=notes>Notes</label>
|
||||||
|
</div>
|
||||||
|
<p class=text-end><button type=submit class="btn btn-primary">Add Notes</button>
|
||||||
|
</form>
|
||||||
|
<hr style="margin: .5rem -1rem">
|
||||||
|
<div id=priorNotes>
|
||||||
|
<p class="text-center pt-3">
|
||||||
|
<button type=button class="btn btn-secondary" hx-get="/components/request/notes?id=<?=$req->id?>"
|
||||||
|
hx-swap=outerHTML hx-target=#priorNotes>Load Prior Notes</button>
|
||||||
|
</div><?php
|
||||||
|
Layout::bareFoot();
|
||||||
25
src/public/components/request/notes.php
Normal file
25
src/public/components/request/notes.php
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\UI\{Component, Layout};
|
||||||
|
|
||||||
|
require '../../../start.php';
|
||||||
|
|
||||||
|
$req = validate_request($_GET['id'], ['GET'], false);
|
||||||
|
|
||||||
|
Layout::bareHead();?>
|
||||||
|
<p class=text-center><strong>Prior Notes for This Request</strong><?php
|
||||||
|
if (sizeof($req->notes) > 0) {
|
||||||
|
foreach ($req->notes as $note) { ?>
|
||||||
|
<p><small class=text-muted><?=Component::relativeDate($note->asOf)?></small><br>
|
||||||
|
<?=htmlentities($note->text)?><?php
|
||||||
|
}
|
||||||
|
} else { ?>
|
||||||
|
<p class="text-center text-muted">There are no prior notes for this request<?php
|
||||||
|
}
|
||||||
|
Layout::bareFoot();
|
||||||
24
src/public/components/request/snooze.php
Normal file
24
src/public/components/request/snooze.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\UI\Layout;
|
||||||
|
|
||||||
|
require '../../../start.php';
|
||||||
|
|
||||||
|
$req = validate_request($_GET['id'], ['GET'], false);
|
||||||
|
|
||||||
|
Layout::bareHead(); ?>
|
||||||
|
<form hx-patch="/request/snooze?id=<?=$req->id?>" hx-target=#journalItems hx-swap=outerHTML>
|
||||||
|
<div class="form-floating pb-3">
|
||||||
|
<input type=date id=until name=until class=form-control
|
||||||
|
min="<?=new DateTimeImmutable('now')->format('Y-m-d')?>" required>
|
||||||
|
<label for=until>Until</label>
|
||||||
|
</div>
|
||||||
|
<p class="text-end mb-0"><button type=submit class="btn btn-primary">Snooze</button>
|
||||||
|
</form><?php
|
||||||
|
Layout::bareFoot();
|
||||||
108
src/public/docs.php
Normal file
108
src/public/docs.php
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\UI\Layout;
|
||||||
|
|
||||||
|
require '../start.php';
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||||
|
|
||||||
|
Layout::pageHead('Documentation'); ?>
|
||||||
|
<article class="container mt-3">
|
||||||
|
<h2 class=mb-3>Documentation</h2>
|
||||||
|
|
||||||
|
<h3 class="mb-3 mt-4">About myPrayerJournal</h3>
|
||||||
|
<p>Journaling has a long history; it helps people remember what happened, and the act of writing helps people think
|
||||||
|
about what happened and process it. A prayer journal is not a new concept; it helps you keep track of the
|
||||||
|
requests for which you’ve prayed, you can use it to pray over things repeatedly, and you can write the
|
||||||
|
result when the answer comes <em>(or it was “no”)</em>.
|
||||||
|
<p>myPrayerJournal was borne of out of a personal desire
|
||||||
|
<a href=https://daniel.summershome.org target=_blank rel=noopener>Daniel</a> had to have something that would
|
||||||
|
help him with his prayer life. When it’s time to pray, it’s not really time to use an app, so the
|
||||||
|
design goal here is to keep it simple and unobtrusive. It will also help eliminate some of the downsides to a
|
||||||
|
paper prayer journal, like not remembering whether you’ve prayed for a request, or running out of room to
|
||||||
|
write another update on one.
|
||||||
|
|
||||||
|
<h3 class="mb-3 mt-4">Signing Up</h3>
|
||||||
|
<p>myPrayerJournal uses login services using Google or Microsoft accounts. The only information the application
|
||||||
|
stores in its database is your user ID token it receives from these services, so there are no permissions you
|
||||||
|
should have to accept from these provider other than establishing that you can log on with that account. Because
|
||||||
|
of this, you’ll want to pick the same one each time; the tokens between the two accounts are different,
|
||||||
|
even if you use the same e-mail address to log on to both.
|
||||||
|
|
||||||
|
<h3 class="mb-3 mt-4">Your Prayer Journal</h3>
|
||||||
|
<p>Your current requests will be presented in columns (usually three, but it could be more or less, depending on the
|
||||||
|
size of your screen or device). Each request is in its own card, and the buttons at the top of each card apply
|
||||||
|
to that request. The last line of each request also tells you how long it has been since anything has been done
|
||||||
|
on that request. Any time you see something like “a few minutes ago,” you can hover over that to see
|
||||||
|
the actual date/time the action was taken.
|
||||||
|
|
||||||
|
<h3 class="mb-3 mt-4">Adding a Request</h3>
|
||||||
|
<p>To add a request, click the “Add a New Request” button at the top of your journal. Then, enter the
|
||||||
|
text of the request as you see fit; there is no right or wrong way, and you are the only person who will see the
|
||||||
|
text you enter. When you save the request, it will go to the bottom of the list of requests.
|
||||||
|
|
||||||
|
<h3 class="mb-3 mt-4">Setting Request Recurrence</h3>
|
||||||
|
<p>When you add or update a request, you can choose whether requests go to the bottom of the journal once they have
|
||||||
|
been marked “Prayed” or whether they will reappear after a delay. You can set recurrence in terms of
|
||||||
|
hours, days, or weeks, but it cannot be longer than 365 days. If you decide you want a request to reappear
|
||||||
|
sooner, you can skip the current delay; click the “Active” menu link, find the request in the list
|
||||||
|
(likely near the bottom), and click the “Show Now” button.
|
||||||
|
|
||||||
|
<h3 class="mb-3 mt-4">Praying for Requests</h3>
|
||||||
|
<p>The first button for each request has a checkmark icon; clicking this button will mark the request as
|
||||||
|
“Prayed” and move it to the bottom of the list (or off, if you’ve set a recurrence period for
|
||||||
|
the request). This allows you, if you’re praying through your requests, to start at the top left (with the
|
||||||
|
request that it’s been the longest since you’ve prayed) and click the button as you pray; when the
|
||||||
|
request move below or away, the next-least-recently-prayed request will take the top spot.
|
||||||
|
|
||||||
|
<h3 class="mb-3 mt-4">Editing Requests</h3>
|
||||||
|
<p>The second button for each request has a pencil icon. This allows you to edit the text of the request, pretty
|
||||||
|
much the same way you entered it; it starts with the current text, and you can add to it, modify it, or
|
||||||
|
completely replace it. By default, updates will go in with an “Updated” status; you have the option
|
||||||
|
to also mark this update as “Prayed” or “Answered”. Answered requests will drop off the
|
||||||
|
journal list.
|
||||||
|
|
||||||
|
<h3 class="mb-3 mt-4">Adding Notes</h3>
|
||||||
|
<p>The third button for each request has an icon that looks like a speech bubble with lines on it; this lets you
|
||||||
|
record notes about the request. If there is something you want to record that doesn’t change the text of
|
||||||
|
the request, this is the place to do it. For example, you may be praying for a long-term health issue, and that
|
||||||
|
person tells you that their status is the same; or, you may want to record something God said to you while you
|
||||||
|
were praying for that request."
|
||||||
|
|
||||||
|
<h3 class="mb-3 mt-4">Snoozing Requests</h3>
|
||||||
|
<p>There may be a time when a request does not need to appear. The fourth button, with the clock icon, allows you to
|
||||||
|
snooze requests until the day you specify. Additionally, if you have any snoozed requests, a
|
||||||
|
“Snoozed” menu item will appear next to the “Journal” one; this page allows you to see
|
||||||
|
what requests are snoozed, and return them to your journal by canceling the snooze.
|
||||||
|
|
||||||
|
<h3 class="mb-3 mt-4">Viewing a Request and Its History</h3>
|
||||||
|
<p>myPrayerJournal tracks all actions related to a request; from the “Active” and “Answered”
|
||||||
|
menu links (and “Snoozed”, if it’s showing), there is a “View Full Request”
|
||||||
|
button. That page will show the current text of the request; how many times it has been marked as prayed; how
|
||||||
|
long it has been an active request; and a log of all updates, prayers, and notes you have recorded. That log is
|
||||||
|
listed from most recent to least recent; if you want to read it chronologically, press the “End” key
|
||||||
|
on your keyboard and read it from the bottom up.
|
||||||
|
<p>The “Active” link will show all requests that have not yet been marked answered, including snoozed
|
||||||
|
and recurring requests. If requests are snoozed, or in a recurrence period off the journal, there will be a
|
||||||
|
button where you can return the request to the list (either “Cancel Snooze” or “Show
|
||||||
|
Now”). The “Answered” link shows all requests that have been marked answered. The
|
||||||
|
“Snoozed” link only shows snoozed requests.
|
||||||
|
|
||||||
|
<h3 id=notes class="mb-3 mt-4">Final Notes</h3>
|
||||||
|
<ul>
|
||||||
|
<li>If you encounter errors, please
|
||||||
|
<a href=https://git.bitbadger.solutions/bit-badger/myPrayerJournal/issues target=_blank rel=noopener>file an
|
||||||
|
issue</a> (or <a href="mailto:daniel@bitbadger.solutions?subject=myPrayerJournal+Issue">e-mail Daniel</a> if
|
||||||
|
you do not have an account on that server) with as much detail as possible. You can also provide
|
||||||
|
suggestions, or browse the list of currently open issues.
|
||||||
|
<li>Prayer requests and their history are securely backed up nightly along with other Bit Badger Solutions data.
|
||||||
|
<li>Prayer changes things - most of all, the one doing the praying. I pray that this tool enables you to deepen
|
||||||
|
and strengthen your prayer life.
|
||||||
|
</ul>
|
||||||
|
</article><?php
|
||||||
|
Layout::pageFoot();
|
||||||
27
src/public/index.php
Normal file
27
src/public/index.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\UI\Component;use MyPrayerJournal\UI\Layout;
|
||||||
|
|
||||||
|
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,
|
||||||
|
update them as God moves in the situation, and record a final answer received on that request. It also allows
|
||||||
|
individuals to review their answered prayers.
|
||||||
|
<p>This site is open and available for anyone who wants to use it. To get started, simply click the “Log
|
||||||
|
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.
|
||||||
|
<hr>
|
||||||
|
<p><em>This is an in-progress upgrade from v3 to v4; if you encounter errors, see
|
||||||
|
<?=Component::pageLink('/docs#notes', 'the documentation')?> on reporting them.</em>
|
||||||
|
</article><?php
|
||||||
|
Layout::pageFoot();
|
||||||
57
src/public/journal.php
Normal file
57
src/public/journal.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\Auth;
|
||||||
|
use MyPrayerJournal\UI\{Component, Layout};
|
||||||
|
|
||||||
|
require '../start.php';
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||||
|
|
||||||
|
Auth::requireUser();
|
||||||
|
|
||||||
|
$user = Auth::user();
|
||||||
|
$name = $user['given_name'] ?? 'Your';
|
||||||
|
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">
|
||||||
|
<?=Component::pageLink('/request/edit?id=new', Component::icon('add_box') . ' Add a Prayer Request',
|
||||||
|
['class' => 'btn btn-primary'])?>
|
||||||
|
<p hx-get=/components/journal-items hx-swap=outerHTML hx-trigger=load hx-target=this>
|
||||||
|
Loading your prayer journal…
|
||||||
|
<div id=notesModal class="modal fade" tabindex=-1 aria-labelledby=nodesModalLabel aria-hidden=true>
|
||||||
|
<div class="modal-dialog modal-dialog-scrollable">
|
||||||
|
<div class=modal-content>
|
||||||
|
<div class=modal-header>
|
||||||
|
<h5 class=modal-title id=nodesModalLabel>Add Notes to Prayer Request</h5>
|
||||||
|
<button type=button class=btn-close data-bs-dismiss=modal aria-label=Close></button>
|
||||||
|
</div>
|
||||||
|
<div class=modal-body id=notesBody></div>
|
||||||
|
<div class=modal-footer>
|
||||||
|
<button type=button id=notesDismiss class="btn btn-secondary" data-bs-dismiss=modal>Close</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id=snoozeModal class="modal fade" tabindex=-1 aria-labelledby=snoozeModalLabel aria-hidden=true>
|
||||||
|
<div class="modal-dialog modal-sm">
|
||||||
|
<div class=modal-content>
|
||||||
|
<div class=modal-header>
|
||||||
|
<h5 class=modal-title id=snoozeModalLabel>Snooze Prayer Request</h5>
|
||||||
|
<button type=button class=btn-close data-bs-dismiss=modal aria-label=Close></button>
|
||||||
|
</div>
|
||||||
|
<div class=modal-body id=snoozeBody></div>
|
||||||
|
<div class=modal-footer>
|
||||||
|
<button type=button id=snoozeDismiss class="btn btn-secondary" data-bs-dismiss=modal>Close</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article><?php
|
||||||
|
Layout::pageFoot();
|
||||||
|
|
||||||
78
src/public/legal/privacy-policy.php
Normal file
78
src/public/legal/privacy-policy.php
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\UI\Layout;
|
||||||
|
|
||||||
|
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>
|
||||||
|
<p>The nature of the service is one where privacy is a must. The items below will help you understand the data we
|
||||||
|
collect, access, and store on your behalf as you use this service.
|
||||||
|
<div class=card>
|
||||||
|
<div class="list-group list-group-flush">
|
||||||
|
<div class=list-group-item>
|
||||||
|
<h3>Third Party Services</h3>
|
||||||
|
<p class=card-text>
|
||||||
|
myPrayerJournal utilizes a third-party authentication and identity provider. You should familiarize
|
||||||
|
yourself with the privacy policy for
|
||||||
|
<a href=https://auth0.com/privacy target=_blank rel=noopener>Auth0</a>, as well as your chosen
|
||||||
|
provider
|
||||||
|
(<a href=https://privacy.microsoft.com/en-us/privacystatement target=_blank rel=noopener>Microsoft</a>
|
||||||
|
or <a href=https://policies.google.com/privacy target=_blank rel=noopener>Google</a>).
|
||||||
|
</div>
|
||||||
|
<div class=list-group-item>
|
||||||
|
<h3>What We Collect</h3>
|
||||||
|
<h4>Identifying Data</h4>
|
||||||
|
<ul>
|
||||||
|
<li>The only identifying data myPrayerJournal stores is the subscriber (“sub”) field
|
||||||
|
from the token we receive from Auth0, once you have signed in through their hosted service. All
|
||||||
|
information is associated with you via this field.
|
||||||
|
<li>While you are signed in, within your browser, the service has access to your first and last
|
||||||
|
names, along with a URL to the profile picture (provided by your selected identity provider).
|
||||||
|
This information is not transmitted to the server, and is removed when “Log Off” is
|
||||||
|
clicked.
|
||||||
|
</ul>
|
||||||
|
<h4>User Provided Data</h4>
|
||||||
|
<ul class=mb-0>
|
||||||
|
<li>myPrayerJournal stores the information you provide, including the text of prayer requests,
|
||||||
|
updates, and notes; and the date/time when certain actions are taken.
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class=list-group-item>
|
||||||
|
<h3>How Your Data Is Accessed / Secured</h3>
|
||||||
|
<ul class=mb-0>
|
||||||
|
<li>Your provided data is returned to you, as required, to display your journal or your answered
|
||||||
|
requests. On the server, it is stored in a controlled-access database.
|
||||||
|
<li>Your data is backed up, along with other Bit Badger Solutions hosted systems, in a rolling
|
||||||
|
manner; backups are preserved for the prior 7 days, and backups from the 1<sup>st</sup> and
|
||||||
|
15<sup>th</sup> are preserved for 3 months. These backups are stored in a private cloud data
|
||||||
|
repository.
|
||||||
|
<li>The data collected and stored is the absolute minimum necessary for the functionality of the
|
||||||
|
service. There are no plans to “monetize” this service, and storing the minimum
|
||||||
|
amount of information means that the data we have is not interesting to purchasers (or those who
|
||||||
|
may have more nefarious purposes).
|
||||||
|
<li>Access to servers and backups is strictly controlled and monitored for unauthorized access
|
||||||
|
attempts.
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class=list-group-item>
|
||||||
|
<h3>Removing Your Data</h3>
|
||||||
|
<p class=card-text>
|
||||||
|
At any time, you may choose to discontinue using this service. Both Microsoft and Google provide
|
||||||
|
ways to revoke access from this application. However, if you want your data removed from the
|
||||||
|
database, please contact daniel at bitbadger.solutions (via e-mail, replacing at with @) prior to
|
||||||
|
doing so, to ensure we can determine which subscriber ID belongs to you.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</article><?php
|
||||||
|
Layout::pageFoot();
|
||||||
65
src/public/legal/terms-of-service.php
Normal file
65
src/public/legal/terms-of-service.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\UI\{Component, Layout};
|
||||||
|
|
||||||
|
require '../../start.php';
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||||
|
|
||||||
|
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>
|
||||||
|
<div class=card>
|
||||||
|
<div class="list-group list-group-flush">
|
||||||
|
<div class=list-group-item>
|
||||||
|
<h3>1. Acceptance of Terms</h3>
|
||||||
|
<p class=card-text>
|
||||||
|
By accessing this web site, you are agreeing to be bound by these Terms and Conditions, and that you
|
||||||
|
are responsible to ensure that your use of this site complies with all applicable laws. Your
|
||||||
|
continued use of this site implies your acceptance of these terms.
|
||||||
|
</div>
|
||||||
|
<div class=list-group-item>
|
||||||
|
<h3>2. Description of Service and Registration</h3>
|
||||||
|
<p class=card-text>
|
||||||
|
myPrayerJournal is a service that allows individuals to enter and amend their prayer requests. It
|
||||||
|
requires no registration by itself, but access is granted based on a successful login with an
|
||||||
|
external identity provider. See
|
||||||
|
<?=Component::pageLink('/legal/privacy-policy', 'our privacy policy')?> for details on how that
|
||||||
|
information is accessed and stored.
|
||||||
|
</div>
|
||||||
|
<div class=list-group-item>
|
||||||
|
<h3>3. Third Party Services</h3>
|
||||||
|
<p class=card-text>
|
||||||
|
This service utilizes a third-party service provider for identity management. Review the terms of
|
||||||
|
service for <a href=https://auth0.com/terms target=_blank rel=noopener>Auth0</a>, as well as those
|
||||||
|
for the selected authorization provider
|
||||||
|
(<a href=https://www.microsoft.com/en-us/servicesagreement target=_blank rel=noopener>Microsoft</a>
|
||||||
|
or <a href=https://policies.google.com/terms target=_blank rel=noopener>Google</a>).
|
||||||
|
</div>
|
||||||
|
<div class=list-group-item>
|
||||||
|
<h3>4. Liability</h3>
|
||||||
|
<p class=card-text>
|
||||||
|
This service is provided “as is”, and no warranty (express or implied) exists. The
|
||||||
|
service and its developers may not be held liable for any damages that may arise through the use of
|
||||||
|
this service.
|
||||||
|
</div>
|
||||||
|
<div class=list-group-item>
|
||||||
|
<h3>5. Updates to Terms</h3>
|
||||||
|
<p class=card-text>
|
||||||
|
These terms and conditions may be updated at any time, and this service does not have the capability
|
||||||
|
to notify users when these change. The date at the top of the page will be updated when any of the
|
||||||
|
text of these terms is updated."
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<p class=pt-3>
|
||||||
|
You may also wish to review our <?=Component::pageLink('/legal/privacy-policy', 'privacy policy')?> to learn how
|
||||||
|
we handle your data.
|
||||||
|
</article><?php
|
||||||
|
Layout::pageFoot();
|
||||||
24
src/public/request/cancel-snooze.php
Normal file
24
src/public/request/cancel-snooze.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use BitBadger\InspiredByFSharp\Option;
|
||||||
|
use BitBadger\PDODocument\RemoveFields;
|
||||||
|
use MyPrayerJournal\Table;
|
||||||
|
use MyPrayerJournal\UI\{Component, Layout};
|
||||||
|
|
||||||
|
require '../../start.php';
|
||||||
|
|
||||||
|
$req = validate_request($_GET['id'], ['PATCH'], false);
|
||||||
|
|
||||||
|
RemoveFields::byId(Table::REQUEST, $req->id, ['snoozedUntil']);
|
||||||
|
$req->snoozedUntil = Option::None();
|
||||||
|
|
||||||
|
// TODO: message
|
||||||
|
Layout::bareHead();
|
||||||
|
Component::requestItem($req);
|
||||||
|
Layout::bareFoot();
|
||||||
113
src/public/request/edit.php
Normal file
113
src/public/request/edit.php
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\Auth;
|
||||||
|
use MyPrayerJournal\Domain\{RecurrencePeriod, Request, RequestAction};
|
||||||
|
use MyPrayerJournal\UI\{Component, Layout};
|
||||||
|
|
||||||
|
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'])->getOrCall(not_found(...))
|
||||||
|
};
|
||||||
|
|
||||||
|
$cancelLink = match (true) {
|
||||||
|
str_ends_with($_SERVER['HTTP_REFERER'] ?? '', 'active') => '/requests/active',
|
||||||
|
str_ends_with($_SERVER['HTTP_REFERER'] ?? '', 'snoozed') => '/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->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'; ?>>
|
||||||
|
<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><?=Component::icon('save');?> Save</button>
|
||||||
|
<?=Component::pageLink($cancelLink, Component::icon('arrow_back') . ' Cancel',
|
||||||
|
['class' => 'btn btn-secondary ms-2'])?>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</article><?php
|
||||||
|
Layout::pageFoot();
|
||||||
52
src/public/request/full.php
Normal file
52
src/public/request/full.php
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\Domain\{History, Note, RequestAction};
|
||||||
|
use MyPrayerJournal\UI\{Component, Layout};
|
||||||
|
|
||||||
|
require '../../start.php';
|
||||||
|
|
||||||
|
$req = validate_request($_GET['id'], ['GET']);
|
||||||
|
|
||||||
|
$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->getOrDefault('')],
|
||||||
|
$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')?>
|
||||||
|
(<?=Component::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();
|
||||||
21
src/public/request/note.php
Normal file
21
src/public/request/note.php
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use BitBadger\PDODocument\Patch;
|
||||||
|
use MyPrayerJournal\Table;
|
||||||
|
use MyPrayerJournal\Domain\Note;
|
||||||
|
|
||||||
|
require '../../start.php';
|
||||||
|
|
||||||
|
$req = validate_request($_GET['id'], ['POST'], false);
|
||||||
|
|
||||||
|
array_unshift($req->notes, new Note(new DateTimeImmutable('now')->format('c'), $_POST['notes']));
|
||||||
|
Patch::byId(Table::REQUEST, $req->id, ['notes' => $req->notes]);
|
||||||
|
|
||||||
|
hide_modal('notes');
|
||||||
|
http_response_code(202);
|
||||||
27
src/public/request/prayed.php
Normal file
27
src/public/request/prayed.php
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use BitBadger\PDODocument\Patch;
|
||||||
|
use MyPrayerJournal\Table;
|
||||||
|
use MyPrayerJournal\Domain\{History, RecurrencePeriod, RequestAction};
|
||||||
|
use MyPrayerJournal\UI\Component;
|
||||||
|
|
||||||
|
require '../../start.php';
|
||||||
|
|
||||||
|
$req = validate_request($_GET['id'], ['PATCH'], false);
|
||||||
|
$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);
|
||||||
|
|
||||||
|
Component::journal();
|
||||||
54
src/public/request/save.php
Normal file
54
src/public/request/save.php
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
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};
|
||||||
|
|
||||||
|
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 = Option::of((int)($_POST['recurCount'] ?? $_PATCH['recurCount']));
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($_SERVER['REQUEST_METHOD']) {
|
||||||
|
case 'POST':
|
||||||
|
$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');
|
||||||
|
|
||||||
|
case 'PATCH':
|
||||||
|
$req = Request::byId($_PATCH['requestId'])->getOrCall(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 = 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);
|
||||||
|
//Messages.pushSuccess ctx "Prayer request updated successfully" nextUrl
|
||||||
|
see_other($_PATCH['returnTo']);
|
||||||
|
}
|
||||||
23
src/public/request/show.php
Normal file
23
src/public/request/show.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use BitBadger\PDODocument\RemoveFields;
|
||||||
|
use MyPrayerJournal\Table;
|
||||||
|
use MyPrayerJournal\UI\{Component, Layout};
|
||||||
|
|
||||||
|
require '../../start.php';
|
||||||
|
|
||||||
|
$req = validate_request($_GET['id'], ['PATCH'], false);
|
||||||
|
|
||||||
|
RemoveFields::byId(Table::REQUEST, $req->id, ['showAfter']);
|
||||||
|
$req->showAfter = null;
|
||||||
|
|
||||||
|
// TODO: message
|
||||||
|
Layout::bareHead();
|
||||||
|
Component::requestItem($req);
|
||||||
|
Layout::bareFoot();
|
||||||
24
src/public/request/snooze.php
Normal file
24
src/public/request/snooze.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use BitBadger\PDODocument\Patch;
|
||||||
|
use MyPrayerJournal\Table;
|
||||||
|
use MyPrayerJournal\UI\Component;
|
||||||
|
|
||||||
|
require '../../start.php';
|
||||||
|
|
||||||
|
$req = validate_request($_GET['id'], ['PATCH'], false);
|
||||||
|
|
||||||
|
$until = (new DateTimeImmutable($_PATCH['until'] . 'T00:00:00', new DateTimeZone($_REQUEST['time_zone'])))
|
||||||
|
->setTimezone(new DateTimeZone('Etc/UTC'));
|
||||||
|
Patch::byId(Table::REQUEST, $req->id, ['snoozedUntil' => $until->format('c')]);
|
||||||
|
|
||||||
|
// TODO: message
|
||||||
|
|
||||||
|
hide_modal('snooze');
|
||||||
|
Component::journal();
|
||||||
30
src/public/requests/active.php
Normal file
30
src/public/requests/active.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\Auth;
|
||||||
|
use MyPrayerJournal\Domain\Request;
|
||||||
|
use MyPrayerJournal\UI\{Component, Layout};
|
||||||
|
|
||||||
|
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) {
|
||||||
|
Component::requestList($reqs);
|
||||||
|
} else {
|
||||||
|
Component::noResults('No Active Requests', '/journal', 'Return to your journal',
|
||||||
|
'Your prayer journal has no active requests');
|
||||||
|
} ?>
|
||||||
|
</article><?php
|
||||||
|
Layout::pageFoot();
|
||||||
32
src/public/requests/answered.php
Normal file
32
src/public/requests/answered.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\Auth;
|
||||||
|
use MyPrayerJournal\Domain\Request;
|
||||||
|
use MyPrayerJournal\UI\{Component, Layout};
|
||||||
|
|
||||||
|
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) {
|
||||||
|
Component::requestList($reqs);
|
||||||
|
} else {
|
||||||
|
Component::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();
|
||||||
30
src/public/requests/snoozed.php
Normal file
30
src/public/requests/snoozed.php
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\Auth;
|
||||||
|
use MyPrayerJournal\Domain\Request;
|
||||||
|
use MyPrayerJournal\UI\{Component, Layout};
|
||||||
|
|
||||||
|
require '../../start.php';
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||||
|
|
||||||
|
Auth::requireUser();
|
||||||
|
|
||||||
|
$reqs = Request::snoozed();
|
||||||
|
|
||||||
|
Layout::pageHead('Snoozed Requests'); ?>
|
||||||
|
<article class="container mt-3">
|
||||||
|
<h2 class=pb-3>Snoozed Requests</h2><?php
|
||||||
|
if ($reqs->hasItems) {
|
||||||
|
Component::requestList($reqs);
|
||||||
|
} else {
|
||||||
|
Component::noResults('No Snoozed Requests', '/journal', 'Return to your journal',
|
||||||
|
'Your prayer journal has no snoozed requests');
|
||||||
|
} ?>
|
||||||
|
</article><?php
|
||||||
|
Layout::pageFoot();
|
||||||
14
src/public/user/log-off.php
Normal file
14
src/public/user/log-off.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\Auth;
|
||||||
|
|
||||||
|
require '../../start.php';
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||||
|
|
||||||
|
Auth::logOff();
|
||||||
14
src/public/user/log-on/index.php
Normal file
14
src/public/user/log-on/index.php
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\Auth;
|
||||||
|
|
||||||
|
require '../../../start.php';
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] <> 'GET') not_found();
|
||||||
|
|
||||||
|
Auth::logOn();
|
||||||
17
src/public/user/log-on/success.php
Normal file
17
src/public/user/log-on/success.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use MyPrayerJournal\Auth;
|
||||||
|
|
||||||
|
require '../../../start.php';
|
||||||
|
|
||||||
|
Auth::client()->exchange($_ENV['AUTH0_BASE_URL'] . '/user/log-on/success');
|
||||||
|
|
||||||
|
// TODO: get the possible redirect URL
|
||||||
|
header('Location: /journal');
|
||||||
|
exit();
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
ALTER TABLE mpj.request
|
|
||||||
ADD COLUMN "showAfter" BIGINT NOT NULL DEFAULT 0;
|
|
||||||
ALTER TABLE mpj.request
|
|
||||||
ADD COLUMN "recurType" VARCHAR(10) NOT NULL DEFAULT 'immediate';
|
|
||||||
ALTER TABLE mpj.request
|
|
||||||
ADD COLUMN "recurCount" SMALLINT NOT NULL DEFAULT 0;
|
|
||||||
CREATE OR REPLACE VIEW mpj.journal AS
|
|
||||||
SELECT
|
|
||||||
request."requestId",
|
|
||||||
request."userId",
|
|
||||||
(SELECT "text"
|
|
||||||
FROM mpj.history
|
|
||||||
WHERE history."requestId" = request."requestId"
|
|
||||||
AND "text" IS NOT NULL
|
|
||||||
ORDER BY "asOf" DESC
|
|
||||||
LIMIT 1) AS "text",
|
|
||||||
(SELECT "asOf"
|
|
||||||
FROM mpj.history
|
|
||||||
WHERE history."requestId" = request."requestId"
|
|
||||||
ORDER BY "asOf" DESC
|
|
||||||
LIMIT 1) AS "asOf",
|
|
||||||
(SELECT "status"
|
|
||||||
FROM mpj.history
|
|
||||||
WHERE history."requestId" = request."requestId"
|
|
||||||
ORDER BY "asOf" DESC
|
|
||||||
LIMIT 1) AS "lastStatus",
|
|
||||||
request."snoozedUntil",
|
|
||||||
request."showAfter",
|
|
||||||
request."recurType",
|
|
||||||
request."recurCount"
|
|
||||||
FROM mpj.request;
|
|
||||||
90
src/start.php
Normal file
90
src/start.php
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
||||||
|
* @license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Auth0\SDK\Exception\ConfigurationException;
|
||||||
|
use BitBadger\PDODocument\{AutoId, Configuration, Definition, DocumentException};
|
||||||
|
use Dotenv\Dotenv;
|
||||||
|
use MyPrayerJournal\{Auth, Table};
|
||||||
|
use MyPrayerJournal\Domain\Request;
|
||||||
|
|
||||||
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
/** The version of this application */
|
||||||
|
const MPJ_VERSION = '4.0.0-beta2';
|
||||||
|
|
||||||
|
(Dotenv::createImmutable(__DIR__))->load();
|
||||||
|
|
||||||
|
if (php_sapi_name() != 'cli') {
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
$auth0_user = Auth::user();
|
||||||
|
if (!is_null($auth0_user)) {
|
||||||
|
$_SESSION['user_id'] = $auth0_user['sub'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$_REQUEST['time_zone'] = $_SERVER['HTTP_X_TIME_ZONE'] ?? 'Etc/UTC';
|
||||||
|
}
|
||||||
|
|
||||||
|
Configuration::useDSN('sqlite:' . implode(DIRECTORY_SEPARATOR, [__DIR__, 'data', 'mpj.db']));
|
||||||
|
Configuration::$autoId = AutoId::RandomString;
|
||||||
|
Configuration::$idStringLength = 12;
|
||||||
|
|
||||||
|
Definition::ensureTable(Table::REQUEST);
|
||||||
|
Definition::ensureFieldIndex(Table::REQUEST, 'user', ['userId']);
|
||||||
|
|
||||||
|
$_PATCH = [];
|
||||||
|
if ($_SERVER['REQUEST_METHOD'] ?? '' === 'PATCH') parse_str(file_get_contents('php://input'), $_PATCH);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a 404 and exit
|
||||||
|
*/
|
||||||
|
function not_found(): never
|
||||||
|
{
|
||||||
|
http_response_code(404);
|
||||||
|
die('Not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a 303 redirect ("see other" - redirects to a GET)
|
||||||
|
*
|
||||||
|
* @param string $url The URL to which the browser should be redirected
|
||||||
|
*/
|
||||||
|
function see_other(string $url): never
|
||||||
|
{
|
||||||
|
header('Location: ' . (str_starts_with($url, 'http') ? '/' : $url));
|
||||||
|
http_response_code(303);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a header that instructs the browser to close an open modal dialog
|
||||||
|
*
|
||||||
|
* @param string $name The name of the dialog to be closed
|
||||||
|
*/
|
||||||
|
function hide_modal(string $name): void
|
||||||
|
{
|
||||||
|
header("X-Hide-Modal: $name");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate the user, HTTP method, and request
|
||||||
|
*
|
||||||
|
* @param string $id The ID of the prayer request to retrieve
|
||||||
|
* @param array $methods The allowable HTTP methods
|
||||||
|
* @param bool $redirect Whether to redirect not-logged-on users (optional, defaults to true)
|
||||||
|
* @return Request The request (failures will not return)
|
||||||
|
* @throws ConfigurationException|DocumentException If any is encountered
|
||||||
|
*/
|
||||||
|
function validate_request(string $id, array $methods, bool $redirect = true): Request
|
||||||
|
{
|
||||||
|
if (empty(array_filter($methods, fn($it) => $_SERVER['REQUEST_METHOD'] === $it))) not_found();
|
||||||
|
|
||||||
|
Auth::requireUser($redirect);
|
||||||
|
|
||||||
|
return Request::byId($id)->getOrCall(not_found(...));
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user