Compare commits
76 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac8b39fff9 | ||
|
|
2bf54136ca | ||
|
|
0709cabea1 | ||
|
|
cbd9114599 | ||
|
|
097ee2deb4 | ||
| fa78e86de6 | |||
|
|
ce588b6a43 | ||
|
|
57cd17c734 | ||
|
|
42615dae82 | ||
|
|
68b650e31d | ||
|
|
d738321dc0 | ||
|
|
8995097d68 | ||
|
|
4310fb91fa | ||
|
|
c0def7623f | ||
|
|
ab8fab51c5 | ||
|
|
96717ae7c4 | ||
|
|
b11ff0ff3d | ||
|
|
6486763297 | ||
|
|
e94e28880b | ||
|
|
16c3a9fd44 | ||
|
|
473359c645 | ||
|
|
334710065c | ||
|
|
ee9326d7a5 | ||
|
|
2c34650ceb | ||
|
|
9f1e258180 | ||
|
|
0c21e6c1c0 | ||
|
|
a6144f67ec | ||
|
|
e351fe5b56 | ||
|
|
d3aff4a110 | ||
|
|
c0dd6b5dd6 | ||
|
|
5bba499251 | ||
|
|
96f2f2f7e0 | ||
|
|
2bf3bc4865 | ||
|
|
95175d2c57 | ||
|
|
3f71d75a99 | ||
|
|
8becb8cea4 | ||
|
|
d1fd5f68e7 | ||
|
|
d0ea7cf3c6 | ||
|
|
05990d537a | ||
|
|
67cdd5a9b0 | ||
|
|
650bda6bc5 | ||
|
|
6424cde1b6 | ||
|
|
d429d6c9ac | ||
|
|
91daa387cb | ||
|
|
d57e2e863a | ||
|
|
9de713fc6a | ||
|
|
79ced40470 | ||
|
|
bad430fc37 | ||
|
|
d5a783304e | ||
|
|
a429a2d6c9 | ||
|
|
2b6f7c63d0 | ||
|
|
419c181eff | ||
|
|
9637b38a3f | ||
|
|
59b5574b16 | ||
|
|
b248f7ca7f | ||
|
|
8d84bdb2e6 | ||
|
|
b7406bd827 | ||
|
|
d92ac4430e | ||
|
|
0cde2fb6db | ||
|
|
943492f175 | ||
|
|
df76385d6a | ||
|
|
8c801ea49f | ||
|
|
0807aa300a | ||
|
|
8d8d112fff | ||
|
|
6c4061e07d | ||
|
|
9cdb505bb1 | ||
|
|
40d765fb92 | ||
|
|
56dee71377 | ||
|
|
3c3f0a7981 | ||
|
|
a1ce40ee83 | ||
|
|
b8f1708012 | ||
|
|
69811cbf54 | ||
|
|
b6d72d691b | ||
|
|
6f49a61822 | ||
|
|
4db6d98011 | ||
|
|
3acec3dc25 |
15
.gitignore
vendored
15
.gitignore
vendored
@@ -252,8 +252,15 @@ paket-files/
|
|||||||
.idea/
|
.idea/
|
||||||
*.sln.iml
|
*.sln.iml
|
||||||
|
|
||||||
|
# Ionide VSCode extension
|
||||||
|
.ionide
|
||||||
|
|
||||||
# Compiled files / application
|
# Compiled files / application
|
||||||
src/api/public/index.html
|
src/build
|
||||||
src/api/public/static
|
src/MyPrayerJournal.Api/wwwroot/favicon.ico
|
||||||
src/api/appsettings.json
|
src/MyPrayerJournal.Api/wwwroot/index.html
|
||||||
build/
|
src/MyPrayerJournal.Api/wwwroot/css
|
||||||
|
src/MyPrayerJournal.Api/wwwroot/js
|
||||||
|
src/MyPrayerJournal.Api/appsettings.development.json
|
||||||
|
/build
|
||||||
|
src/*.exe
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
# myPrayerJournal
|
# myPrayerJournal
|
||||||
|
|
||||||
|
## 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")_.
|
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")_.
|
||||||
|
|
||||||
This is borne of out of a personal desire I had to have something that would help me with my 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.
|
||||||
|
|
||||||
It is still a work-in-progress (WIP), but is available for public preview at <https://prayerjournal.me>.
|
## Futher Reading
|
||||||
|
|
||||||
|
The documentation for the site is at <https://bit-badger.github.io/myPrayerJournal/>.
|
||||||
|
|||||||
1
docs/CNAME
Normal file
1
docs/CNAME
Normal file
@@ -0,0 +1 @@
|
|||||||
|
docs.prayerjournal.me
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
## Caveats
|
# Documentation
|
||||||
|
|
||||||
_myPrayerJournal is currently alpha software. There likely will be errors, the way things work may change, and parts of the application are unfinished or need polish. I **will** do my best to not lose any data, though; it is backed up the way other DJS Consulting sites have their data backed up. Throughout this document, current gotchas will be called out with italic text, like this notice._
|
## 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
|
## Finding the Site
|
||||||
|
|
||||||
@@ -12,30 +16,40 @@ myPrayerJournal uses login services using Google or Microsoft accounts. The only
|
|||||||
|
|
||||||
## Your Prayer Journal
|
## Your Prayer Journal
|
||||||
|
|
||||||
Your current requests will be presented in three columns (or one, if you're using a mobile phone). Each request is in its own card, and the buttons at the bottom 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.
|
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
|
## 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.
|
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
|
## 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. 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 goes to the bottom of the list, the next-least-recently-prayed request will take the top spot.
|
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
|
## 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.
|
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
|
## Viewing a Request and Its History
|
||||||
|
|
||||||
myPrayerJournal tracks all of the actions related to a request; the fourth button, with the magnifying glass icon, will show you the entire history, including the text as it changed, and all the times "Prayed" was recorded.
|
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.
|
||||||
|
|
||||||
## Answered Requests
|
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.
|
||||||
|
|
||||||
Next to "Journal" on the top navigation is the word "Answered." This page lists all answered requests, from most recent to least recent, along with the text of the request at the time it was marked as answered. It will also show you when it was marked answered. The button with the magnifying class at the words "Show Full Request" behave the same way as the paragraph immediately preceding this describes. _(This will likely change before a 0.9.x release, but this gives at least some way to find and review answered requests.)_
|
## Final Notes
|
||||||
|
|
||||||
## Known Issues
|
- 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.
|
||||||
See [the GitHub issues list](https://github.com/danieljsummers/myPrayerJournal/issues) for the most up-to-date list.
|
- 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.
|
||||||
|
|
||||||
- _If you try to do something an get an error notification instead of a green checkmark, try logging off and logging back on again. The site currently doesn't check to see if your session has expired, but the server with which it's communicating does._
|
|
||||||
|
|||||||
184
src/MyPrayerJournal.Api/Data.fs
Normal file
184
src/MyPrayerJournal.Api/Data.fs
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
namespace MyPrayerJournal
|
||||||
|
|
||||||
|
open System
|
||||||
|
open System.Collections.Generic
|
||||||
|
|
||||||
|
/// JSON converters for various DUs
|
||||||
|
module Converters =
|
||||||
|
|
||||||
|
open Microsoft.FSharpLu.Json
|
||||||
|
open Newtonsoft.Json
|
||||||
|
|
||||||
|
/// JSON converter for request IDs
|
||||||
|
type RequestIdJsonConverter () =
|
||||||
|
inherit JsonConverter<RequestId> ()
|
||||||
|
override __.WriteJson(writer : JsonWriter, value : RequestId, _ : JsonSerializer) =
|
||||||
|
(RequestId.toString >> writer.WriteValue) value
|
||||||
|
override __.ReadJson(reader: JsonReader, _ : Type, _ : RequestId, _ : bool, _ : JsonSerializer) =
|
||||||
|
(string >> RequestId.fromIdString) reader.Value
|
||||||
|
|
||||||
|
/// JSON converter for user IDs
|
||||||
|
type UserIdJsonConverter () =
|
||||||
|
inherit JsonConverter<UserId> ()
|
||||||
|
override __.WriteJson(writer : JsonWriter, value : UserId, _ : JsonSerializer) =
|
||||||
|
(UserId.toString >> writer.WriteValue) value
|
||||||
|
override __.ReadJson(reader: JsonReader, _ : Type, _ : UserId, _ : bool, _ : JsonSerializer) =
|
||||||
|
(string >> UserId) reader.Value
|
||||||
|
|
||||||
|
/// JSON converter for Ticks
|
||||||
|
type TicksJsonConverter () =
|
||||||
|
inherit JsonConverter<Ticks> ()
|
||||||
|
override __.WriteJson(writer : JsonWriter, value : Ticks, _ : JsonSerializer) =
|
||||||
|
(Ticks.toLong >> writer.WriteValue) value
|
||||||
|
override __.ReadJson(reader: JsonReader, _ : Type, _ : Ticks, _ : bool, _ : JsonSerializer) =
|
||||||
|
(string >> int64 >> Ticks) reader.Value
|
||||||
|
|
||||||
|
/// A sequence of all custom converters needed for myPrayerJournal
|
||||||
|
let all : JsonConverter seq =
|
||||||
|
seq {
|
||||||
|
yield RequestIdJsonConverter ()
|
||||||
|
yield UserIdJsonConverter ()
|
||||||
|
yield TicksJsonConverter ()
|
||||||
|
yield CompactUnionJsonConverter true
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// RavenDB index declarations
|
||||||
|
module Indexes =
|
||||||
|
|
||||||
|
open Raven.Client.Documents.Indexes
|
||||||
|
|
||||||
|
/// Index requests for a journal view
|
||||||
|
type Requests_AsJournal () as this =
|
||||||
|
inherit AbstractJavaScriptIndexCreationTask ()
|
||||||
|
do
|
||||||
|
this.Maps <- HashSet<string> [
|
||||||
|
"""docs.Requests.Select(req => new {
|
||||||
|
requestId = req.Id.Replace("Requests/", ""),
|
||||||
|
userId = req.userId,
|
||||||
|
text = req.history.Where(hist => hist.text != null).OrderByDescending(hist => hist.asOf).First().text,
|
||||||
|
asOf = req.history.OrderByDescending(hist => hist.asOf).First().asOf,
|
||||||
|
lastStatus = req.history.OrderByDescending(hist => hist.asOf).First().status,
|
||||||
|
snoozedUntil = req.snoozedUntil,
|
||||||
|
showAfter = req.showAfter,
|
||||||
|
recurType = req.recurType,
|
||||||
|
recurCount = req.recurCount
|
||||||
|
})"""
|
||||||
|
]
|
||||||
|
this.Fields <-
|
||||||
|
[ "requestId", IndexFieldOptions (Storage = Nullable FieldStorage.Yes)
|
||||||
|
"text", IndexFieldOptions (Storage = Nullable FieldStorage.Yes)
|
||||||
|
"asOf", IndexFieldOptions (Storage = Nullable FieldStorage.Yes)
|
||||||
|
"lastStatus", IndexFieldOptions (Storage = Nullable FieldStorage.Yes)
|
||||||
|
]
|
||||||
|
|> dict
|
||||||
|
|> Dictionary<string, IndexFieldOptions>
|
||||||
|
|
||||||
|
|
||||||
|
/// All data manipulations within myPrayerJournal
|
||||||
|
module Data =
|
||||||
|
|
||||||
|
open FSharp.Control.Tasks.V2.ContextInsensitive
|
||||||
|
open Indexes
|
||||||
|
open Microsoft.FSharpLu
|
||||||
|
open Raven.Client.Documents
|
||||||
|
open Raven.Client.Documents.Linq
|
||||||
|
open Raven.Client.Documents.Session
|
||||||
|
|
||||||
|
/// Add a history entry
|
||||||
|
let addHistory reqId (hist : History) (sess : IAsyncDocumentSession) =
|
||||||
|
sess.Advanced.Patch<Request, History> (
|
||||||
|
RequestId.toString reqId,
|
||||||
|
(fun r -> r.history :> IEnumerable<History>),
|
||||||
|
fun (h : JavaScriptArray<History>) -> h.Add (hist) :> obj)
|
||||||
|
|
||||||
|
/// Add a note
|
||||||
|
let addNote reqId (note : Note) (sess : IAsyncDocumentSession) =
|
||||||
|
sess.Advanced.Patch<Request, Note> (
|
||||||
|
RequestId.toString reqId,
|
||||||
|
(fun r -> r.notes :> IEnumerable<Note>),
|
||||||
|
fun (h : JavaScriptArray<Note>) -> h.Add (note) :> obj)
|
||||||
|
|
||||||
|
/// Add a request
|
||||||
|
let addRequest req (sess : IAsyncDocumentSession) =
|
||||||
|
sess.StoreAsync (req, req.Id)
|
||||||
|
|
||||||
|
/// Retrieve all answered requests for the given user
|
||||||
|
let answeredRequests userId (sess : IAsyncDocumentSession) =
|
||||||
|
task {
|
||||||
|
let! reqs =
|
||||||
|
sess.Query<JournalRequest, Requests_AsJournal>()
|
||||||
|
.Where(fun r -> r.userId = userId && r.lastStatus = "Answered")
|
||||||
|
.OrderByDescending(fun r -> r.asOf)
|
||||||
|
.ProjectInto<JournalRequest>()
|
||||||
|
.ToListAsync ()
|
||||||
|
return List.ofSeq reqs
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retrieve the user's current journal
|
||||||
|
let journalByUserId userId (sess : IAsyncDocumentSession) =
|
||||||
|
task {
|
||||||
|
let! jrnl =
|
||||||
|
sess.Query<JournalRequest, Requests_AsJournal>()
|
||||||
|
.Where(fun r -> r.userId = userId && r.lastStatus <> "Answered")
|
||||||
|
.OrderBy(fun r -> r.asOf)
|
||||||
|
.ProjectInto<JournalRequest>()
|
||||||
|
.ToListAsync()
|
||||||
|
return
|
||||||
|
jrnl
|
||||||
|
|> List.ofSeq
|
||||||
|
|> List.map (fun r -> r.history <- []; r.notes <- []; r)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Save changes in the current document session
|
||||||
|
let saveChanges (sess : IAsyncDocumentSession) =
|
||||||
|
sess.SaveChangesAsync ()
|
||||||
|
|
||||||
|
/// Retrieve a request, including its history and notes, by its ID and user ID
|
||||||
|
let tryFullRequestById reqId userId (sess : IAsyncDocumentSession) =
|
||||||
|
task {
|
||||||
|
let! req = RequestId.toString reqId |> sess.LoadAsync
|
||||||
|
return match Option.fromObject req with Some r when r.userId = userId -> Some r | _ -> None
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Retrieve a request by its ID and user ID (without notes and history)
|
||||||
|
let tryRequestById reqId userId (sess : IAsyncDocumentSession) =
|
||||||
|
task {
|
||||||
|
match! tryFullRequestById reqId userId sess with
|
||||||
|
| Some r -> return Some { r with history = []; notes = [] }
|
||||||
|
| _ -> return None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retrieve notes for a request by its ID and user ID
|
||||||
|
let notesById reqId userId (sess : IAsyncDocumentSession) =
|
||||||
|
task {
|
||||||
|
match! tryFullRequestById reqId userId sess with
|
||||||
|
| Some req -> return req.notes
|
||||||
|
| None -> return []
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retrieve a journal request by its ID and user ID
|
||||||
|
let tryJournalById reqId userId (sess : IAsyncDocumentSession) =
|
||||||
|
task {
|
||||||
|
let! req =
|
||||||
|
sess.Query<Request, Requests_AsJournal>()
|
||||||
|
.Where(fun x -> x.Id = (RequestId.toString reqId) && x.userId = userId)
|
||||||
|
.ProjectInto<JournalRequest>()
|
||||||
|
.FirstOrDefaultAsync ()
|
||||||
|
return Option.fromObject req
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Update the recurrence for a request
|
||||||
|
let updateRecurrence reqId recurType recurCount (sess : IAsyncDocumentSession) =
|
||||||
|
sess.Advanced.Patch<Request, Recurrence> (RequestId.toString reqId, (fun r -> r.recurType), recurType)
|
||||||
|
sess.Advanced.Patch<Request, int16> (RequestId.toString reqId, (fun r -> r.recurCount), recurCount)
|
||||||
|
|
||||||
|
/// Update a snoozed request
|
||||||
|
let updateSnoozed reqId until (sess : IAsyncDocumentSession) =
|
||||||
|
sess.Advanced.Patch<Request, Ticks> (RequestId.toString reqId, (fun r -> r.snoozedUntil), until)
|
||||||
|
sess.Advanced.Patch<Request, Ticks> (RequestId.toString reqId, (fun r -> r.showAfter), until)
|
||||||
|
|
||||||
|
/// Update the "show after" timestamp for a request
|
||||||
|
let updateShowAfter reqId showAfter (sess : IAsyncDocumentSession) =
|
||||||
|
sess.Advanced.Patch<Request, Ticks> (RequestId.toString reqId, (fun r -> r.showAfter), showAfter)
|
||||||
169
src/MyPrayerJournal.Api/Domain.fs
Normal file
169
src/MyPrayerJournal.Api/Domain.fs
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
[<AutoOpen>]
|
||||||
|
/// The data model for myPrayerJournal
|
||||||
|
module MyPrayerJournal.Domain
|
||||||
|
|
||||||
|
open Cuid
|
||||||
|
|
||||||
|
/// Request ID is a CUID
|
||||||
|
type RequestId =
|
||||||
|
| RequestId of Cuid
|
||||||
|
module RequestId =
|
||||||
|
/// The string representation of the request ID
|
||||||
|
let toString x = match x with RequestId y -> (Cuid.toString >> sprintf "Requests/%s") y
|
||||||
|
/// Create a request ID from a string representation
|
||||||
|
let fromIdString (y : string) = (Cuid >> RequestId) <| y.Replace("Requests/", "")
|
||||||
|
|
||||||
|
|
||||||
|
/// User ID is a string (the "sub" part of the JWT)
|
||||||
|
type UserId =
|
||||||
|
| UserId of string
|
||||||
|
module UserId =
|
||||||
|
/// The string representation of the user ID
|
||||||
|
let toString x = match x with UserId y -> y
|
||||||
|
|
||||||
|
|
||||||
|
/// A long integer representing seconds since the epoch
|
||||||
|
type Ticks =
|
||||||
|
| Ticks of int64
|
||||||
|
module Ticks =
|
||||||
|
/// The int64 (long) representation of ticks
|
||||||
|
let toLong x = match x with Ticks y -> y
|
||||||
|
|
||||||
|
|
||||||
|
/// How frequently a request should reappear after it is marked "Prayed"
|
||||||
|
type Recurrence =
|
||||||
|
| Immediate
|
||||||
|
| Hours
|
||||||
|
| Days
|
||||||
|
| Weeks
|
||||||
|
module Recurrence =
|
||||||
|
/// Create a recurrence value from a string
|
||||||
|
let fromString x =
|
||||||
|
match x with
|
||||||
|
| "Immediate" -> Immediate
|
||||||
|
| "Hours" -> Hours
|
||||||
|
| "Days" -> Days
|
||||||
|
| "Weeks" -> Weeks
|
||||||
|
| _ -> invalidOp (sprintf "%s is not a valid recurrence" x)
|
||||||
|
/// The duration of the recurrence
|
||||||
|
let duration x =
|
||||||
|
match x with
|
||||||
|
| Immediate -> 0L
|
||||||
|
| Hours -> 3600000L
|
||||||
|
| Days -> 86400000L
|
||||||
|
| Weeks -> 604800000L
|
||||||
|
|
||||||
|
|
||||||
|
/// The action taken on a request as part of a history entry
|
||||||
|
type RequestAction =
|
||||||
|
| Created
|
||||||
|
| Prayed
|
||||||
|
| Updated
|
||||||
|
| Answered
|
||||||
|
module RequestAction =
|
||||||
|
/// Create a RequestAction from a string
|
||||||
|
let fromString x =
|
||||||
|
match x with
|
||||||
|
| "Created" -> Created
|
||||||
|
| "Prayed" -> Prayed
|
||||||
|
| "Updated" -> Updated
|
||||||
|
| "Answered" -> Answered
|
||||||
|
| _ -> (sprintf "Bad request action %s" >> invalidOp) x
|
||||||
|
|
||||||
|
|
||||||
|
/// History is a record of action taken on a prayer request, including updates to its text
|
||||||
|
[<CLIMutable; NoComparison; NoEquality>]
|
||||||
|
type History =
|
||||||
|
{ /// The time when this history entry was made
|
||||||
|
asOf : Ticks
|
||||||
|
/// The status for this history entry
|
||||||
|
status : RequestAction
|
||||||
|
/// The text of the update, if applicable
|
||||||
|
text : string option
|
||||||
|
}
|
||||||
|
with
|
||||||
|
/// An empty history entry
|
||||||
|
static member empty =
|
||||||
|
{ asOf = Ticks 0L
|
||||||
|
status = Created
|
||||||
|
text = None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Note is a note regarding a prayer request that does not result in an update to its text
|
||||||
|
[<CLIMutable; NoComparison; NoEquality>]
|
||||||
|
type Note =
|
||||||
|
{ /// The time when this note was made
|
||||||
|
asOf : Ticks
|
||||||
|
/// The text of the notes
|
||||||
|
notes : string
|
||||||
|
}
|
||||||
|
with
|
||||||
|
/// An empty note
|
||||||
|
static member empty =
|
||||||
|
{ asOf = Ticks 0L
|
||||||
|
notes = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Request is the identifying record for a prayer request
|
||||||
|
[<CLIMutable; NoComparison; NoEquality>]
|
||||||
|
type Request =
|
||||||
|
{ /// The ID of the request
|
||||||
|
Id : string
|
||||||
|
/// The time this request was initially entered
|
||||||
|
enteredOn : Ticks
|
||||||
|
/// The ID of the user to whom this request belongs ("sub" from the JWT)
|
||||||
|
userId : UserId
|
||||||
|
/// The time at which this request should reappear in the user's journal by manual user choice
|
||||||
|
snoozedUntil : Ticks
|
||||||
|
/// The time at which this request should reappear in the user's journal by recurrence
|
||||||
|
showAfter : Ticks
|
||||||
|
/// The type of recurrence for this request
|
||||||
|
recurType : Recurrence
|
||||||
|
/// How many of the recurrence intervals should occur between appearances in the journal
|
||||||
|
recurCount : int16
|
||||||
|
/// The history entries for this request
|
||||||
|
history : History list
|
||||||
|
/// The notes for this request
|
||||||
|
notes : Note list
|
||||||
|
}
|
||||||
|
with
|
||||||
|
/// An empty request
|
||||||
|
static member empty =
|
||||||
|
{ Id = ""
|
||||||
|
enteredOn = Ticks 0L
|
||||||
|
userId = UserId ""
|
||||||
|
snoozedUntil = Ticks 0L
|
||||||
|
showAfter = Ticks 0L
|
||||||
|
recurType = Immediate
|
||||||
|
recurCount = 0s
|
||||||
|
history = []
|
||||||
|
notes = []
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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.
|
||||||
|
// RavenDB doesn't like the "@"-suffixed properties from record types in a ProjectInto clause
|
||||||
|
[<NoComparison; NoEquality>]
|
||||||
|
type JournalRequest () =
|
||||||
|
/// The ID of the request (just the CUID part)
|
||||||
|
[<DefaultValue>] val mutable requestId : string
|
||||||
|
/// The ID of the user to whom the request belongs
|
||||||
|
[<DefaultValue>] val mutable userId : UserId
|
||||||
|
/// The current text of the request
|
||||||
|
[<DefaultValue>] val mutable text : string
|
||||||
|
/// The last time action was taken on the request
|
||||||
|
[<DefaultValue>] val mutable asOf : Ticks
|
||||||
|
/// The last status for the request
|
||||||
|
[<DefaultValue>] val mutable lastStatus : string
|
||||||
|
/// The time that this request should reappear in the user's journal
|
||||||
|
[<DefaultValue>] val mutable snoozedUntil : Ticks
|
||||||
|
/// The time after which this request should reappear in the user's journal by configured recurrence
|
||||||
|
[<DefaultValue>] val mutable showAfter : Ticks
|
||||||
|
/// The type of recurrence for this request
|
||||||
|
[<DefaultValue>] val mutable recurType : Recurrence
|
||||||
|
/// How many of the recurrence intervals should occur between appearances in the journal
|
||||||
|
[<DefaultValue>] val mutable recurCount : int16
|
||||||
|
/// History entries for the request
|
||||||
|
[<DefaultValue>] val mutable history : History list
|
||||||
|
/// Note entries for the request
|
||||||
|
[<DefaultValue>] val mutable notes : Note list
|
||||||
364
src/MyPrayerJournal.Api/Handlers.fs
Normal file
364
src/MyPrayerJournal.Api/Handlers.fs
Normal file
@@ -0,0 +1,364 @@
|
|||||||
|
/// HTTP handlers for the myPrayerJournal API
|
||||||
|
[<RequireQualifiedAccess>]
|
||||||
|
module MyPrayerJournal.Handlers
|
||||||
|
|
||||||
|
open Giraffe
|
||||||
|
|
||||||
|
/// Handler to return Vue files
|
||||||
|
module Vue =
|
||||||
|
|
||||||
|
/// The application index page
|
||||||
|
let app : HttpHandler = htmlFile "wwwroot/index.html"
|
||||||
|
|
||||||
|
open System
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
|
||||||
|
open Cuid
|
||||||
|
|
||||||
|
/// Handler helpers
|
||||||
|
[<AutoOpen>]
|
||||||
|
module private Helpers =
|
||||||
|
|
||||||
|
open Microsoft.AspNetCore.Http
|
||||||
|
open Raven.Client.Documents
|
||||||
|
open System.Threading.Tasks
|
||||||
|
open System.Security.Claims
|
||||||
|
|
||||||
|
/// Create a RavenDB session
|
||||||
|
let session (ctx : HttpContext) =
|
||||||
|
let sess = ctx.GetService<IDocumentStore>().OpenAsyncSession ()
|
||||||
|
sess.Advanced.WaitForIndexesAfterSaveChanges ()
|
||||||
|
sess
|
||||||
|
|
||||||
|
/// 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 |> UserId
|
||||||
|
|
||||||
|
/// Create a request ID from a string
|
||||||
|
let toReqId x =
|
||||||
|
let reqId =
|
||||||
|
match Cuid.ofString x with
|
||||||
|
| Ok cuid -> cuid
|
||||||
|
| Error msg -> invalidOp msg
|
||||||
|
RequestId reqId
|
||||||
|
|
||||||
|
/// Return a 201 CREATED response
|
||||||
|
let created next ctx =
|
||||||
|
setStatusCode 201 next ctx
|
||||||
|
|
||||||
|
/// The "now" time in JavaScript as Ticks
|
||||||
|
let jsNow () =
|
||||||
|
(int64 >> (*) 1000L >> Ticks) <| DateTime.UtcNow.Subtract(DateTime (1970, 1, 1, 0, 0, 0)).TotalSeconds
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
open FSharp.Control.Tasks.V2.ContextInsensitive
|
||||||
|
|
||||||
|
/// /api/journal URLs
|
||||||
|
module Journal =
|
||||||
|
|
||||||
|
/// GET /api/journal
|
||||||
|
let journal : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
use sess = session ctx
|
||||||
|
let usrId = userId ctx
|
||||||
|
let! jrnl = Data.journalByUserId usrId sess
|
||||||
|
return! json jrnl next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// /api/request URLs
|
||||||
|
module Request =
|
||||||
|
|
||||||
|
/// POST /api/request
|
||||||
|
let add : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
let! r = ctx.BindJsonAsync<Models.Request> ()
|
||||||
|
use sess = session ctx
|
||||||
|
let reqId = (Cuid.generate >> RequestId) ()
|
||||||
|
let usrId = userId ctx
|
||||||
|
let now = jsNow ()
|
||||||
|
do! Data.addRequest
|
||||||
|
{ Request.empty with
|
||||||
|
Id = RequestId.toString reqId
|
||||||
|
userId = usrId
|
||||||
|
enteredOn = now
|
||||||
|
showAfter = Ticks 0L
|
||||||
|
recurType = Recurrence.fromString r.recurType
|
||||||
|
recurCount = r.recurCount
|
||||||
|
history = [
|
||||||
|
{ asOf = now
|
||||||
|
status = Created
|
||||||
|
text = Some r.requestText
|
||||||
|
}
|
||||||
|
]
|
||||||
|
} sess
|
||||||
|
do! Data.saveChanges sess
|
||||||
|
match! Data.tryJournalById reqId usrId sess with
|
||||||
|
| Some req -> return! (setStatusCode 201 >=> json req) next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// POST /api/request/[req-id]/history
|
||||||
|
let addHistory requestId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
use sess = session ctx
|
||||||
|
let usrId = userId ctx
|
||||||
|
let reqId = toReqId requestId
|
||||||
|
match! Data.tryRequestById reqId usrId sess with
|
||||||
|
| Some req ->
|
||||||
|
let! hist = ctx.BindJsonAsync<Models.HistoryEntry> ()
|
||||||
|
let now = jsNow ()
|
||||||
|
let act = RequestAction.fromString hist.status
|
||||||
|
Data.addHistory reqId
|
||||||
|
{ asOf = now
|
||||||
|
status = act
|
||||||
|
text = match hist.updateText with null | "" -> None | x -> Some x
|
||||||
|
} sess
|
||||||
|
match act with
|
||||||
|
| Prayed ->
|
||||||
|
let nextShow =
|
||||||
|
match Recurrence.duration req.recurType with
|
||||||
|
| 0L -> 0L
|
||||||
|
| duration -> (Ticks.toLong now) + (duration * int64 req.recurCount)
|
||||||
|
Data.updateShowAfter reqId (Ticks nextShow) sess
|
||||||
|
| _ -> ()
|
||||||
|
do! Data.saveChanges sess
|
||||||
|
return! created next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// POST /api/request/[req-id]/note
|
||||||
|
let addNote requestId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
use sess = session ctx
|
||||||
|
let usrId = userId ctx
|
||||||
|
let reqId = toReqId requestId
|
||||||
|
match! Data.tryRequestById reqId usrId sess with
|
||||||
|
| Some _ ->
|
||||||
|
let! notes = ctx.BindJsonAsync<Models.NoteEntry> ()
|
||||||
|
Data.addNote reqId { asOf = jsNow (); notes = notes.notes } sess
|
||||||
|
do! Data.saveChanges sess
|
||||||
|
return! created next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// GET /api/requests/answered
|
||||||
|
let answered : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
use sess = session ctx
|
||||||
|
let usrId = userId ctx
|
||||||
|
let! reqs = Data.answeredRequests usrId sess
|
||||||
|
return! json reqs next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// GET /api/request/[req-id]
|
||||||
|
let get requestId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
use sess = session ctx
|
||||||
|
let usrId = userId ctx
|
||||||
|
match! Data.tryJournalById (toReqId requestId) usrId sess with
|
||||||
|
| Some req -> return! json req next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// GET /api/request/[req-id]/full
|
||||||
|
let getFull requestId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
use sess = session ctx
|
||||||
|
let usrId = userId ctx
|
||||||
|
match! Data.tryFullRequestById (toReqId requestId) usrId sess with
|
||||||
|
| Some req -> return! json req next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// GET /api/request/[req-id]/notes
|
||||||
|
let getNotes requestId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
use sess = session ctx
|
||||||
|
let usrId = userId ctx
|
||||||
|
let! notes = Data.notesById (toReqId requestId) usrId sess
|
||||||
|
return! json notes next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// PATCH /api/request/[req-id]/show
|
||||||
|
let show requestId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
use sess = session ctx
|
||||||
|
let usrId = userId ctx
|
||||||
|
let reqId = toReqId requestId
|
||||||
|
match! Data.tryRequestById reqId usrId sess with
|
||||||
|
| Some _ ->
|
||||||
|
Data.updateShowAfter reqId (Ticks 0L) sess
|
||||||
|
do! Data.saveChanges sess
|
||||||
|
return! setStatusCode 204 next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// PATCH /api/request/[req-id]/snooze
|
||||||
|
let snooze requestId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
use sess = session ctx
|
||||||
|
let usrId = userId ctx
|
||||||
|
let reqId = toReqId requestId
|
||||||
|
match! Data.tryRequestById reqId usrId sess with
|
||||||
|
| Some _ ->
|
||||||
|
let! until = ctx.BindJsonAsync<Models.SnoozeUntil> ()
|
||||||
|
Data.updateSnoozed reqId (Ticks until.until) sess
|
||||||
|
do! Data.saveChanges sess
|
||||||
|
return! setStatusCode 204 next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// PATCH /api/request/[req-id]/recurrence
|
||||||
|
let updateRecurrence requestId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
use sess = session ctx
|
||||||
|
let usrId = userId ctx
|
||||||
|
let reqId = toReqId requestId
|
||||||
|
match! Data.tryRequestById reqId usrId sess with
|
||||||
|
| Some _ ->
|
||||||
|
let! recur = ctx.BindJsonAsync<Models.Recurrence> ()
|
||||||
|
let recurrence = Recurrence.fromString recur.recurType
|
||||||
|
Data.updateRecurrence reqId recurrence recur.recurCount sess
|
||||||
|
match recurrence with Immediate -> Data.updateShowAfter reqId (Ticks 0L) sess | _ -> ()
|
||||||
|
do! Data.saveChanges sess
|
||||||
|
return! setStatusCode 204 next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
open Giraffe.TokenRouter
|
||||||
|
|
||||||
|
/// The routes for myPrayerJournal
|
||||||
|
let webApp : HttpHandler =
|
||||||
|
router Error.notFound [
|
||||||
|
route "/" Vue.app
|
||||||
|
subRoute "/api/" [
|
||||||
|
GET [
|
||||||
|
route "journal" Journal.journal
|
||||||
|
subRoute "request" [
|
||||||
|
route "s/answered" Request.answered
|
||||||
|
routef "/%s/full" Request.getFull
|
||||||
|
routef "/%s/notes" Request.getNotes
|
||||||
|
routef "/%s" Request.get
|
||||||
|
]
|
||||||
|
]
|
||||||
|
PATCH [
|
||||||
|
subRoute "request" [
|
||||||
|
routef "/%s/recurrence" Request.updateRecurrence
|
||||||
|
routef "/%s/show" Request.show
|
||||||
|
routef "/%s/snooze" Request.snooze
|
||||||
|
]
|
||||||
|
]
|
||||||
|
POST [
|
||||||
|
subRoute "request" [
|
||||||
|
route "" Request.add
|
||||||
|
routef "/%s/history" Request.addHistory
|
||||||
|
routef "/%s/note" Request.addNote
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
34
src/MyPrayerJournal.Api/MyPrayerJournal.Api.fsproj
Normal file
34
src/MyPrayerJournal.Api/MyPrayerJournal.Api.fsproj
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.2</TargetFramework>
|
||||||
|
<Version>2.0.1.0</Version>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Domain.fs" />
|
||||||
|
<Compile Include="Data.fs" />
|
||||||
|
<Compile Include="Handlers.fs" />
|
||||||
|
<Compile Include="Program.fs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="FunctionalCuid" 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="RavenDb.Client" Version="4.2.1" />
|
||||||
|
<PackageReference Include="TaskBuilder.fs" Version="2.1.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Update="FSharp.Core" Version="4.7.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="wwwroot\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
144
src/MyPrayerJournal.Api/Program.fs
Normal file
144
src/MyPrayerJournal.Api/Program.fs
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
module MyPrayerJournal.Api
|
||||||
|
|
||||||
|
open Microsoft.AspNetCore.Builder
|
||||||
|
open Microsoft.AspNetCore.Hosting
|
||||||
|
open System.IO
|
||||||
|
|
||||||
|
/// Configuration functions for the application
|
||||||
|
module Configure =
|
||||||
|
|
||||||
|
/// Configure the content root
|
||||||
|
let contentRoot root (bldr : IWebHostBuilder) =
|
||||||
|
bldr.UseContentRoot root
|
||||||
|
|
||||||
|
open Microsoft.Extensions.Configuration
|
||||||
|
|
||||||
|
/// Configure the application configuration
|
||||||
|
let appConfiguration (bldr : IWebHostBuilder) =
|
||||||
|
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
|
||||||
|
bldr.ConfigureAppConfiguration configuration
|
||||||
|
|
||||||
|
open Microsoft.AspNetCore.Server.Kestrel.Core
|
||||||
|
|
||||||
|
/// Configure Kestrel from appsettings.json
|
||||||
|
let kestrel (bldr : IWebHostBuilder) =
|
||||||
|
let kestrelOpts (ctx : WebHostBuilderContext) (opts : KestrelServerOptions) =
|
||||||
|
(ctx.Configuration.GetSection >> opts.Configure >> ignore) "Kestrel"
|
||||||
|
bldr.UseKestrel().ConfigureKestrel kestrelOpts
|
||||||
|
|
||||||
|
/// Configure the web root directory
|
||||||
|
let webRoot pathSegments (bldr : IWebHostBuilder) =
|
||||||
|
(Path.Combine >> bldr.UseWebRoot) pathSegments
|
||||||
|
|
||||||
|
open Giraffe
|
||||||
|
open Giraffe.Serialization
|
||||||
|
open Microsoft.AspNetCore.Authentication.JwtBearer
|
||||||
|
open Microsoft.Extensions.DependencyInjection
|
||||||
|
open MyPrayerJournal.Indexes
|
||||||
|
open Newtonsoft.Json
|
||||||
|
open Newtonsoft.Json.Serialization
|
||||||
|
open Raven.Client.Documents
|
||||||
|
open Raven.Client.Documents.Indexes
|
||||||
|
open System.Security.Cryptography.X509Certificates
|
||||||
|
|
||||||
|
/// Configure dependency injection
|
||||||
|
let services (bldr : IWebHostBuilder) =
|
||||||
|
let svcs (sc : IServiceCollection) =
|
||||||
|
/// Custom settings for the JSON serializer (uses compact representation for options and DUs)
|
||||||
|
let jsonSettings =
|
||||||
|
let x = NewtonsoftJsonSerializer.DefaultSettings
|
||||||
|
Converters.all |> List.ofSeq |> List.iter x.Converters.Add
|
||||||
|
x.NullValueHandling <- NullValueHandling.Ignore
|
||||||
|
x.MissingMemberHandling <- MissingMemberHandling.Error
|
||||||
|
x.Formatting <- Formatting.Indented
|
||||||
|
x.ContractResolver <- DefaultContractResolver ()
|
||||||
|
x
|
||||||
|
|
||||||
|
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.AddSingleton<IJsonSerializer> (NewtonsoftJsonSerializer jsonSettings)
|
||||||
|
|> ignore
|
||||||
|
let config = sc.BuildServiceProvider().GetRequiredService<IConfiguration>().GetSection "RavenDB"
|
||||||
|
let store = new DocumentStore ()
|
||||||
|
store.Urls <- [| config.["URL"] |]
|
||||||
|
store.Database <- config.["Database"]
|
||||||
|
match isNull config.["Certificate"] with
|
||||||
|
| true -> ()
|
||||||
|
| false -> store.Certificate <- new X509Certificate2 (config.["Certificate"], config.["Password"])
|
||||||
|
store.Conventions.CustomizeJsonSerializer <- fun x -> Converters.all |> List.ofSeq |> List.iter x.Converters.Add
|
||||||
|
store.Initialize () |> (sc.AddSingleton >> ignore)
|
||||||
|
IndexCreation.CreateIndexes (typeof<Requests_AsJournal>.Assembly, store)
|
||||||
|
bldr.ConfigureServices svcs
|
||||||
|
|
||||||
|
open Microsoft.Extensions.Logging
|
||||||
|
|
||||||
|
/// Configure logging
|
||||||
|
let logging (bldr : IWebHostBuilder) =
|
||||||
|
let logz (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
|
||||||
|
bldr.ConfigureLogging logz
|
||||||
|
|
||||||
|
open System
|
||||||
|
|
||||||
|
/// Configure the web application
|
||||||
|
let application (bldr : IWebHostBuilder) =
|
||||||
|
let appConfig =
|
||||||
|
Action<IApplicationBuilder> (
|
||||||
|
fun (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 Handlers.webApp
|
||||||
|
|> ignore)
|
||||||
|
bldr.Configure appConfig
|
||||||
|
|
||||||
|
/// Compose all the configurations into one
|
||||||
|
let webHost appRoot pathSegments =
|
||||||
|
contentRoot appRoot
|
||||||
|
>> appConfiguration
|
||||||
|
>> kestrel
|
||||||
|
>> webRoot (Array.concat [ [| appRoot |]; pathSegments ])
|
||||||
|
>> services
|
||||||
|
>> logging
|
||||||
|
>> application
|
||||||
|
|
||||||
|
/// Build the web host from the given configuration
|
||||||
|
let buildHost (bldr : IWebHostBuilder) = bldr.Build ()
|
||||||
|
|
||||||
|
let exitCode = 0
|
||||||
|
|
||||||
|
[<EntryPoint>]
|
||||||
|
let main _ =
|
||||||
|
let appRoot = Directory.GetCurrentDirectory ()
|
||||||
|
use host = WebHostBuilder() |> (Configure.webHost appRoot [| "wwwroot" |] >> Configure.buildHost)
|
||||||
|
host.Run ()
|
||||||
|
exitCode
|
||||||
27
src/MyPrayerJournal.Api/Properties/launchSettings.json
Normal file
27
src/MyPrayerJournal.Api/Properties/launchSettings.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/MyPrayerJournal.Api/appsettings.json
Normal file
9
src/MyPrayerJournal.Api/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Kestrel": {
|
||||||
|
"EndPoints": {
|
||||||
|
"Http": {
|
||||||
|
"Url": "http://localhost:3000"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/MyPrayerJournal.sln
Normal file
37
src/MyPrayerJournal.sln
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 16
|
||||||
|
VisualStudioVersion = 16.0.28721.148
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "MyPrayerJournal.Api", "MyPrayerJournal.Api\MyPrayerJournal.Api.fsproj", "{1887D1E1-544A-4F54-B266-38E7867DC842}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Debug|iPhone = Debug|iPhone
|
||||||
|
Debug|iPhoneSimulator = Debug|iPhoneSimulator
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
Release|iPhone = Release|iPhone
|
||||||
|
Release|iPhoneSimulator = Release|iPhoneSimulator
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{1887D1E1-544A-4F54-B266-38E7867DC842}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{1887D1E1-544A-4F54-B266-38E7867DC842}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{1887D1E1-544A-4F54-B266-38E7867DC842}.Debug|iPhone.ActiveCfg = Debug|Any CPU
|
||||||
|
{1887D1E1-544A-4F54-B266-38E7867DC842}.Debug|iPhone.Build.0 = Debug|Any CPU
|
||||||
|
{1887D1E1-544A-4F54-B266-38E7867DC842}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
|
||||||
|
{1887D1E1-544A-4F54-B266-38E7867DC842}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
|
||||||
|
{1887D1E1-544A-4F54-B266-38E7867DC842}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{1887D1E1-544A-4F54-B266-38E7867DC842}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{1887D1E1-544A-4F54-B266-38E7867DC842}.Release|iPhone.ActiveCfg = Release|Any CPU
|
||||||
|
{1887D1E1-544A-4F54-B266-38E7867DC842}.Release|iPhone.Build.0 = Release|Any CPU
|
||||||
|
{1887D1E1-544A-4F54-B266-38E7867DC842}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
|
||||||
|
{1887D1E1-544A-4F54-B266-38E7867DC842}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {8E2447D9-52F0-4A0D-BB61-A83C19353D7C}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
const chalk = require('chalk')
|
|
||||||
|
|
||||||
const { env } = require('./appsettings.json') // process.env.NODE_ENV || 'dev'
|
|
||||||
|
|
||||||
if ('dev' === env) require('babel-register')
|
|
||||||
const src = (env === 'dev') ? './src' : './build'
|
|
||||||
|
|
||||||
const app = require(`${src}/index`).default
|
|
||||||
const db = require(`${src}/db`).default
|
|
||||||
|
|
||||||
const fullEnv = ('dev' === env) ? 'Development' : 'Production'
|
|
||||||
|
|
||||||
const { port } = require('./appsettings.json')
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Log a start-up message for the app
|
|
||||||
* @param {string} status The status to display
|
|
||||||
*/
|
|
||||||
const startupMsg = (status) => {
|
|
||||||
console.log(chalk`{reset myPrayerJournal ${status} | Port: {bold ${port}} | Mode: {bold ${fullEnv}}}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure the database exists before starting up
|
|
||||||
db.verify()
|
|
||||||
.then(() => app.listen(port, () => startupMsg('ready')))
|
|
||||||
.catch(err => {
|
|
||||||
console.log(chalk`\n{reset {bgRed.white.bold || Error connecting to PostgreSQL }}`)
|
|
||||||
for (let key of Object.keys(err)) {
|
|
||||||
console.log(chalk`${key}: {reset {bold ${err[key]}}}`)
|
|
||||||
}
|
|
||||||
console.log('')
|
|
||||||
startupMsg('failed')
|
|
||||||
})
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
import fs from 'fs'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Read and parse a JSON file
|
|
||||||
* @param {string} path The path to the file
|
|
||||||
* @param {string} encoding The encoding of the file (defaults to UTF-8)
|
|
||||||
* @return {*} The parsed contents of the file
|
|
||||||
*/
|
|
||||||
export default (path, encoding = 'utf-8') =>
|
|
||||||
JSON.parse(fs.readFileSync(path, encoding))
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "my-prayer-journal-api",
|
|
||||||
"private": true,
|
|
||||||
"version": "0.8.2",
|
|
||||||
"description": "Server API for myPrayerJournal",
|
|
||||||
"main": "index.js",
|
|
||||||
"author": "Daniel J. Summers <daniel@djs-consulting.com>",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"chalk": "^2.1.0",
|
|
||||||
"cuid": "^1.3.8",
|
|
||||||
"jwks-rsa-koa": "^1.1.3",
|
|
||||||
"koa": "^2.3.0",
|
|
||||||
"koa-bodyparser": "^4.2.0",
|
|
||||||
"koa-jwt": "^3.2.2",
|
|
||||||
"koa-router": "^7.2.1",
|
|
||||||
"koa-send": "^4.1.0",
|
|
||||||
"koa-static": "^4.0.1",
|
|
||||||
"pg": "^7.3.0"
|
|
||||||
},
|
|
||||||
"scripts": {
|
|
||||||
"start": "node app.js",
|
|
||||||
"build": "babel src -d build",
|
|
||||||
"vue": "cd ../app && node build/build.js prod && cd ../api && node app.js"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"babel": "^6.23.0",
|
|
||||||
"babel-cli": "^6.26.0",
|
|
||||||
"babel-preset-env": "^1.6.0",
|
|
||||||
"babel-register": "^6.26.0",
|
|
||||||
"koa-morgan": "^1.0.1"
|
|
||||||
},
|
|
||||||
"babel": {
|
|
||||||
"presets": [
|
|
||||||
[
|
|
||||||
"env",
|
|
||||||
{
|
|
||||||
"targets": {
|
|
||||||
"node": "current"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
import { Pool } from 'pg'
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SQL to check the existence of a table in the mpj schema
|
|
||||||
* @param {string} table The name of the table whose existence should be checked
|
|
||||||
*/
|
|
||||||
const tableSql = table => `SELECT 1 FROM pg_tables WHERE schemaname='mpj' AND tablename='${table}'`
|
|
||||||
|
|
||||||
/**
|
|
||||||
* SQL to determine if an index exists
|
|
||||||
* @param {string} table The name of the table which the given index indexes
|
|
||||||
* @param {string} index The name of the index
|
|
||||||
*/
|
|
||||||
const indexSql = (table, index) =>
|
|
||||||
`SELECT 1 FROM pg_indexes WHERE schemaname='mpj' AND tablename='${table}' AND indexname='${index}'`
|
|
||||||
|
|
||||||
const ddl = [
|
|
||||||
{
|
|
||||||
name: 'myPrayerJournal Schema',
|
|
||||||
check: `SELECT 1 FROM pg_namespace WHERE nspname='mpj'`,
|
|
||||||
fix: `
|
|
||||||
CREATE SCHEMA mpj;
|
|
||||||
COMMENT ON SCHEMA mpj IS 'myPrayerJournal data'`
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'request Table',
|
|
||||||
check: tableSql('request'),
|
|
||||||
fix: `
|
|
||||||
CREATE TABLE mpj.request (
|
|
||||||
"requestId" varchar(25) PRIMARY KEY,
|
|
||||||
"enteredOn" bigint NOT NULL,
|
|
||||||
"userId" varchar(100) NOT NULL);
|
|
||||||
COMMENT ON TABLE mpj.request IS 'Requests'`
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'history Table',
|
|
||||||
check: tableSql('history'),
|
|
||||||
fix: `
|
|
||||||
CREATE TABLE mpj.history (
|
|
||||||
"requestId" varchar(25) NOT NULL REFERENCES mpj.request,
|
|
||||||
"asOf" bigint NOT NULL,
|
|
||||||
"status" varchar(25),
|
|
||||||
"text" text,
|
|
||||||
PRIMARY KEY ("requestId", "asOf"));
|
|
||||||
COMMENT ON TABLE mpj.history IS 'Request update history'`
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'request.userId Index',
|
|
||||||
check: indexSql('request', 'idx_request_userId'),
|
|
||||||
fix: `
|
|
||||||
CREATE INDEX "idx_request_userId" ON mpj.request ("userId");
|
|
||||||
COMMENT ON INDEX "idx_request_userId" IS 'Requests are retrieved by user'`
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'journal View',
|
|
||||||
check: `SELECT 1 FROM pg_views WHERE schemaname='mpj' AND viewname='journal'`,
|
|
||||||
fix: `
|
|
||||||
CREATE 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"
|
|
||||||
FROM mpj.request;
|
|
||||||
COMMENT ON VIEW mpj.journal IS 'Requests with latest text'`
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
export default function (query) {
|
|
||||||
return {
|
|
||||||
/**
|
|
||||||
* Ensure that the database schema, tables, and indexes exist
|
|
||||||
*/
|
|
||||||
ensureDatabase: async () => {
|
|
||||||
for (let item of ddl) {
|
|
||||||
const result = await query(item.check, [])
|
|
||||||
if (1 > result.rowCount) await query(item.fix, [])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
import { Pool, types } from 'pg'
|
|
||||||
|
|
||||||
import appConfig from '../../appsettings.json'
|
|
||||||
import ddl from './ddl'
|
|
||||||
import request from './request'
|
|
||||||
|
|
||||||
/** Pooled PostgreSQL instance */
|
|
||||||
const pool = new Pool(appConfig.pgPool)
|
|
||||||
|
|
||||||
// Return "bigint" (int8) instances as number instead of strings
|
|
||||||
// ref: https://github.com/brianc/node-pg-types
|
|
||||||
types.setTypeParser(20, val => parseInt(val))
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Run a SQL query
|
|
||||||
* @param {string} text The SQL command
|
|
||||||
* @param {*[]} params The parameters for the query
|
|
||||||
*/
|
|
||||||
const query = (text, params) => pool.query(text, params)
|
|
||||||
|
|
||||||
export default {
|
|
||||||
query: query,
|
|
||||||
request: request(pool),
|
|
||||||
verify: ddl(query).ensureDatabase
|
|
||||||
}
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
import { Pool } from 'pg'
|
|
||||||
import cuid from 'cuid'
|
|
||||||
|
|
||||||
const currentRequestSql = `
|
|
||||||
SELECT "requestId", "text", "asOf", "lastStatus"
|
|
||||||
FROM mpj.journal`
|
|
||||||
|
|
||||||
const journalSql = `${currentRequestSql}
|
|
||||||
WHERE "userId" = $1
|
|
||||||
AND "lastStatus" <> 'Answered'`
|
|
||||||
|
|
||||||
const requestNotFound = {
|
|
||||||
requestId: '',
|
|
||||||
text: 'Not Found',
|
|
||||||
asOf: 0
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function (pool) {
|
|
||||||
return {
|
|
||||||
/**
|
|
||||||
* Add a history entry for this request
|
|
||||||
* @param {string} requestId The Id of the request
|
|
||||||
* @param {string} status The status for this history entry
|
|
||||||
* @param {string} updateText The updated text for the request (pass blank if no update)
|
|
||||||
*/
|
|
||||||
addHistory: async (requestId, status, updateText) => {
|
|
||||||
const asOf = Date.now()
|
|
||||||
await pool.query(`
|
|
||||||
INSERT INTO mpj.history
|
|
||||||
("requestId", "asOf", "status", "text")
|
|
||||||
VALUES
|
|
||||||
($1, $2, $3, NULLIF($4, ''))`,
|
|
||||||
[ requestId, asOf, status, updateText ])
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a new prayer request
|
|
||||||
* @param {string} userId The Id of the user
|
|
||||||
* @param {string} requestText The text of the request
|
|
||||||
* @return The created request
|
|
||||||
*/
|
|
||||||
addNew: async (userId, requestText) => {
|
|
||||||
const id = cuid()
|
|
||||||
const enteredOn = Date.now()
|
|
||||||
return (async () => {
|
|
||||||
const client = await pool.connect()
|
|
||||||
try {
|
|
||||||
await client.query('BEGIN')
|
|
||||||
await client.query(
|
|
||||||
'INSERT INTO mpj.request ("requestId", "enteredOn", "userId") VALUES ($1, $2, $3)',
|
|
||||||
[ id, enteredOn, userId ])
|
|
||||||
await client.query(
|
|
||||||
`INSERT INTO mpj.history ("requestId", "asOf", "status", "text") VALUES ($1, $2, 'Created', $3)`,
|
|
||||||
[ id, enteredOn, requestText ])
|
|
||||||
await client.query('COMMIT')
|
|
||||||
} catch (e) {
|
|
||||||
await client.query('ROLLBACK')
|
|
||||||
throw e
|
|
||||||
} finally {
|
|
||||||
client.release()
|
|
||||||
}
|
|
||||||
return { requestId: id, text: requestText, asOf: enteredOn, lastStatus: 'Created' }
|
|
||||||
})().catch(e => {
|
|
||||||
console.error(e.stack)
|
|
||||||
return { requestId: '', text: 'error', asOf: 0, lastStatus: 'Errored' }
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all answered requests with their text as of the "Answered" status
|
|
||||||
* @param {string} userId The Id of the user for whom requests should be retrieved
|
|
||||||
* @return All requests
|
|
||||||
*/
|
|
||||||
answered: async (userId) =>
|
|
||||||
(await pool.query(`${currentRequestSql}
|
|
||||||
WHERE "userId" = $1
|
|
||||||
AND "lastStatus" = 'Answered'
|
|
||||||
ORDER BY "asOf" DESC`,
|
|
||||||
[ userId ])).rows,
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the "current" version of a request by its Id
|
|
||||||
* @param {string} requestId The Id of the request to retrieve
|
|
||||||
* @param {string} userId The Id of the user to which the request belongs
|
|
||||||
* @return The request, or a request-like object indicating that the request was not found
|
|
||||||
*/
|
|
||||||
byId: async (userId, requestId) => {
|
|
||||||
const reqs = await pool.query(`${currentRequestSql}
|
|
||||||
WHERE "requestId" = $1
|
|
||||||
AND "userId" = $2`,
|
|
||||||
[ requestId, userId ])
|
|
||||||
return (0 < reqs.rowCount) ? reqs.rows[0] : requestNotFound
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a prayer request, including its full history, by its Id
|
|
||||||
* @param {string} userId The Id of the user to which the request belongs
|
|
||||||
* @param {string} requestId The Id of the request to retrieve
|
|
||||||
* @return The request, or a request-like object indicating that the request was not found
|
|
||||||
*/
|
|
||||||
fullById: async (userId, requestId) => {
|
|
||||||
const reqResults = await pool.query(`
|
|
||||||
SELECT "requestId", "enteredOn"
|
|
||||||
FROM mpj.request
|
|
||||||
WHERE "requestId" = $1
|
|
||||||
AND "userId" = $2`,
|
|
||||||
[ requestId, userId ])
|
|
||||||
if (0 === reqResults.rowCount) {
|
|
||||||
return requestNotFound
|
|
||||||
}
|
|
||||||
const req = reqResults.rows[0]
|
|
||||||
const history = await pool.query(`
|
|
||||||
SELECT "asOf", "status", COALESCE("text", '') AS "text"
|
|
||||||
FROM mpj.history
|
|
||||||
WHERE "requestId" = $1
|
|
||||||
ORDER BY "asOf"`,
|
|
||||||
[ requestId ])
|
|
||||||
req.history = history.rows
|
|
||||||
return req
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the current requests for a user (i.e., their complete current journal)
|
|
||||||
* @param {string} userId The Id of the user
|
|
||||||
* @return The requests that make up the current journal
|
|
||||||
*/
|
|
||||||
journal: async userId => (await pool.query(`${journalSql} ORDER BY "asOf"`, [ userId ])).rows
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
import Koa from 'koa'
|
|
||||||
import bodyParser from 'koa-bodyparser'
|
|
||||||
import morgan from 'koa-morgan'
|
|
||||||
import send from 'koa-send'
|
|
||||||
import serveFrom from 'koa-static'
|
|
||||||
|
|
||||||
import appConfig from '../appsettings.json'
|
|
||||||
import router from './routes'
|
|
||||||
|
|
||||||
/** Koa app */
|
|
||||||
const app = new Koa()
|
|
||||||
|
|
||||||
if (appConfig.env === 'dev') app.use(morgan('dev'))
|
|
||||||
|
|
||||||
export default app
|
|
||||||
// Serve the Vue files from /public
|
|
||||||
.use(serveFrom('public'))
|
|
||||||
// Parse the body into ctx.request.body, if present
|
|
||||||
.use(bodyParser())
|
|
||||||
// Tie in all the routes
|
|
||||||
.use(router.routes())
|
|
||||||
.use(router.allowedMethods())
|
|
||||||
// Send the index.html file for what would normally get a 404
|
|
||||||
.use(async (ctx, next) => {
|
|
||||||
if (ctx.url.indexOf('/api') === -1) {
|
|
||||||
try {
|
|
||||||
await send(ctx, 'index.html', { root: __dirname + '/../public/' })
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
return await next(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return await next()
|
|
||||||
})
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
import jwt from 'koa-jwt'
|
|
||||||
import jwksRsa from 'jwks-rsa-koa'
|
|
||||||
import Router from 'koa-router'
|
|
||||||
|
|
||||||
import appConfig from '../../appsettings.json'
|
|
||||||
import journal from './journal'
|
|
||||||
import request from './request'
|
|
||||||
|
|
||||||
/** Authentication middleware to verify the access token against the Auth0 JSON Web Key Set */
|
|
||||||
const checkJwt = jwt({
|
|
||||||
// Dynamically provide a signing key
|
|
||||||
// based on the kid in the header and
|
|
||||||
// the singing keys provided by the JWKS endpoint.
|
|
||||||
secret: jwksRsa.koaJwt2Key({
|
|
||||||
cache: true,
|
|
||||||
rateLimit: true,
|
|
||||||
jwksRequestsPerMinute: 5,
|
|
||||||
jwksUri: `https://${appConfig.auth0.domain}/.well-known/jwks.json`
|
|
||||||
}),
|
|
||||||
|
|
||||||
// Validate the audience and the issuer.
|
|
||||||
audience: appConfig.auth0.clientId,
|
|
||||||
issuer: `https://${appConfig.auth0.domain}/`,
|
|
||||||
algorithms: ['RS256']
|
|
||||||
})
|
|
||||||
|
|
||||||
/** /api/journal routes */
|
|
||||||
const journalRoutes = journal(checkJwt)
|
|
||||||
/** /api/request routes */
|
|
||||||
const requestRoutes = request(checkJwt)
|
|
||||||
|
|
||||||
/** Combined router */
|
|
||||||
const router = new Router({ prefix: '/api' })
|
|
||||||
router.use('/journal', journalRoutes.routes(), journalRoutes.allowedMethods())
|
|
||||||
router.use('/request', requestRoutes.routes(), requestRoutes.allowedMethods())
|
|
||||||
|
|
||||||
export default router
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
import Router from 'koa-router'
|
|
||||||
import db from '../db'
|
|
||||||
|
|
||||||
const router = new Router()
|
|
||||||
|
|
||||||
export default function (checkJwt) {
|
|
||||||
|
|
||||||
router.get('/', checkJwt, async (ctx, next) => {
|
|
||||||
const reqs = await db.request.journal(ctx.state.user.sub)
|
|
||||||
ctx.body = reqs
|
|
||||||
return await next()
|
|
||||||
})
|
|
||||||
return router
|
|
||||||
}
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
|
|
||||||
import Router from 'koa-router'
|
|
||||||
import db from '../db'
|
|
||||||
|
|
||||||
const router = new Router()
|
|
||||||
|
|
||||||
export default function (checkJwt) {
|
|
||||||
|
|
||||||
router
|
|
||||||
// Add a new request
|
|
||||||
.post('/', checkJwt, async (ctx, next) => {
|
|
||||||
ctx.body = await db.request.addNew(ctx.state.user.sub, ctx.request.body.requestText)
|
|
||||||
await next()
|
|
||||||
})
|
|
||||||
// Add a request history entry (prayed, updated, answered, etc.)
|
|
||||||
.post('/:id/history', checkJwt, async (ctx, next) => {
|
|
||||||
const body = ctx.request.body
|
|
||||||
await db.request.addHistory(ctx.params.id, body.status, body.updateText)
|
|
||||||
ctx.response.status = 204
|
|
||||||
await next()
|
|
||||||
})
|
|
||||||
// Get a journal-style request by its Id
|
|
||||||
.get('/:id', checkJwt, async (ctx, next) => {
|
|
||||||
const req = await db.request.byId(ctx.state.user.sub, ctx.params.id)
|
|
||||||
if ('Not Found' === req.text) {
|
|
||||||
ctx.response.status = 404
|
|
||||||
} else {
|
|
||||||
ctx.body = req
|
|
||||||
}
|
|
||||||
await next()
|
|
||||||
})
|
|
||||||
// Get a request, along with its full history
|
|
||||||
.get('/:id/full', checkJwt, async (ctx, next) => {
|
|
||||||
const req = await db.request.fullById(ctx.state.user.sub, ctx.params.id)
|
|
||||||
if ('Not Found' === req.text) {
|
|
||||||
ctx.response.status = 404
|
|
||||||
} else {
|
|
||||||
ctx.body = req
|
|
||||||
}
|
|
||||||
await next()
|
|
||||||
})
|
|
||||||
.get('/answered', checkJwt, async (ctx, next) => {
|
|
||||||
ctx.body = await db.request.answered(ctx.state.user.sub)
|
|
||||||
ctx.response.status = 200
|
|
||||||
await next()
|
|
||||||
})
|
|
||||||
|
|
||||||
return router
|
|
||||||
}
|
|
||||||
2194
src/api/yarn.lock
2194
src/api/yarn.lock
File diff suppressed because it is too large
Load Diff
@@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"presets": [
|
|
||||||
["env", {
|
|
||||||
"modules": false,
|
|
||||||
"targets": {
|
|
||||||
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
|
|
||||||
}
|
|
||||||
}],
|
|
||||||
"stage-2"
|
|
||||||
],
|
|
||||||
"plugins": ["transform-runtime"],
|
|
||||||
"env": {
|
|
||||||
"test": {
|
|
||||||
"presets": ["env", "stage-2"],
|
|
||||||
"plugins": ["istanbul"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
3
src/app/.browserslistrc
Normal file
3
src/app/.browserslistrc
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
> 1%
|
||||||
|
last 2 versions
|
||||||
|
not ie <= 8
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
charset = utf-8
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
||||||
end_of_line = lf
|
|
||||||
insert_final_newline = true
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
build/*.js
|
|
||||||
config/*.js
|
|
||||||
@@ -1,27 +1,17 @@
|
|||||||
// http://eslint.org/docs/user-guide/configuring
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
root: true,
|
root: true,
|
||||||
parser: 'babel-eslint',
|
|
||||||
parserOptions: {
|
|
||||||
sourceType: 'module'
|
|
||||||
},
|
|
||||||
env: {
|
env: {
|
||||||
browser: true,
|
node: true
|
||||||
},
|
},
|
||||||
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
|
'extends': [
|
||||||
extends: 'standard',
|
'plugin:vue/essential',
|
||||||
// required to lint *.vue files
|
'@vue/standard'
|
||||||
plugins: [
|
|
||||||
'html'
|
|
||||||
],
|
],
|
||||||
// add your custom rules here
|
rules: {
|
||||||
'rules': {
|
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
|
||||||
// allow paren-less arrow functions
|
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
|
||||||
'arrow-parens': 0,
|
},
|
||||||
// allow async-await
|
parserOptions: {
|
||||||
'generator-star-spacing': 0,
|
parser: 'babel-eslint'
|
||||||
// allow debugger during development
|
|
||||||
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
17
src/app/.gitignore
vendored
17
src/app/.gitignore
vendored
@@ -1,19 +1,24 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
node_modules/
|
node_modules
|
||||||
dist/
|
/dist
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env.local
|
||||||
|
.env.*.local
|
||||||
|
|
||||||
|
# Log files
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
yarn-debug.log*
|
yarn-debug.log*
|
||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
test/unit/coverage
|
|
||||||
test/e2e/reports
|
|
||||||
selenium-debug.log
|
|
||||||
|
|
||||||
# Editor directories and files
|
# Editor directories and files
|
||||||
.idea
|
.idea
|
||||||
|
.vscode
|
||||||
*.suo
|
*.suo
|
||||||
*.ntvs*
|
*.ntvs*
|
||||||
*.njsproj
|
*.njsproj
|
||||||
*.sln
|
*.sln
|
||||||
|
*.sw*
|
||||||
|
|
||||||
# Auth0 settings
|
# Auth0 settings
|
||||||
src/auth/auth0-variables.js
|
src/auth/auth0-variables.*
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
// https://github.com/michael-ciniawsky/postcss-load-config
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"plugins": {
|
plugins: {
|
||||||
// to edit target browsers: use "browserslist" field in package.json
|
autoprefixer: {}
|
||||||
"autoprefixer": {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
src/app/babel.config.js
Normal file
5
src/app/babel.config.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
presets: [
|
||||||
|
'@vue/app'
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
var merge = require('webpack-merge')
|
|
||||||
var prodEnv = require('./prod.env')
|
|
||||||
|
|
||||||
module.exports = merge(prodEnv, {
|
|
||||||
NODE_ENV: '"development"'
|
|
||||||
})
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
// see http://vuejs-templates.github.io/webpack for documentation.
|
|
||||||
var path = require('path')
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
build: {
|
|
||||||
env: require('./prod.env'),
|
|
||||||
index: path.resolve(__dirname, '../../api/public/index.html'),
|
|
||||||
assetsRoot: path.resolve(__dirname, '../../api/public'),
|
|
||||||
assetsSubDirectory: 'static',
|
|
||||||
assetsPublicPath: '/',
|
|
||||||
productionSourceMap: true,
|
|
||||||
// Gzip off by default as many popular static hosts such as
|
|
||||||
// Surge or Netlify already gzip all static assets for you.
|
|
||||||
// Before setting to `true`, make sure to:
|
|
||||||
// npm install --save-dev compression-webpack-plugin
|
|
||||||
productionGzip: false,
|
|
||||||
productionGzipExtensions: ['js', 'css'],
|
|
||||||
// Run the build command with an extra argument to
|
|
||||||
// View the bundle analyzer report after build finishes:
|
|
||||||
// `npm run build --report`
|
|
||||||
// Set to `true` or `false` to always turn it on or off
|
|
||||||
bundleAnalyzerReport: process.env.npm_config_report
|
|
||||||
},
|
|
||||||
dev: {
|
|
||||||
env: require('./dev.env'),
|
|
||||||
port: 8080,
|
|
||||||
autoOpenBrowser: true,
|
|
||||||
assetsSubDirectory: 'static',
|
|
||||||
assetsPublicPath: '/',
|
|
||||||
proxyTable: {},
|
|
||||||
// CSS Sourcemaps off by default because relative paths are "buggy"
|
|
||||||
// with this option, according to the CSS-Loader README
|
|
||||||
// (https://github.com/webpack/css-loader#sourcemaps)
|
|
||||||
// In our experience, they generally work as expected,
|
|
||||||
// just be aware of this issue when enabling this option.
|
|
||||||
cssSourceMap: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
NODE_ENV: '"production"'
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
var merge = require('webpack-merge')
|
|
||||||
var devEnv = require('./dev.env')
|
|
||||||
|
|
||||||
module.exports = merge(devEnv, {
|
|
||||||
NODE_ENV: '"testing"'
|
|
||||||
})
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
<title>myPrayerJournal</title>
|
|
||||||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="app"></div>
|
|
||||||
<!-- built files will be auto injected -->
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@@ -1,104 +1,36 @@
|
|||||||
{
|
{
|
||||||
"name": "my-prayer-journal",
|
"name": "my-prayer-journal",
|
||||||
"version": "0.8.2",
|
"version": "2.0.1",
|
||||||
"description": "myPrayerJournal - Front End",
|
"description": "myPrayerJournal - Front End",
|
||||||
"author": "Daniel J. Summers <daniel@djs-consulting.com>",
|
"author": "Daniel J. Summers <daniel@bitbadger.solutions>",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node build/dev-server.js",
|
"serve": "vue-cli-service serve --port 8081",
|
||||||
"start": "node build/dev-server.js",
|
"build": "vue-cli-service build --modern",
|
||||||
"build": "node build/build.js",
|
"lint": "vue-cli-service lint",
|
||||||
"unit": "cross-env BABEL_ENV=test karma start test/unit/karma.conf.js --single-run",
|
"apistart": "cd ../MyPrayerJournal.Api && dotnet run",
|
||||||
"e2e": "node test/e2e/runner.js",
|
"vue": "vue-cli-service build --modern && cd ../MyPrayerJournal.Api && dotnet run",
|
||||||
"test": "npm run unit && npm run e2e",
|
"publish": "vue-cli-service build --modern && cd ../MyPrayerJournal.Api && dotnet publish -c Release"
|
||||||
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"auth0-js": "^8.10.1",
|
"auth0-js": "^9.7.3",
|
||||||
"axios": "^0.16.2",
|
"axios": "^0.19.0",
|
||||||
"bootstrap-vue": "^1.0.0-beta.9",
|
|
||||||
"moment": "^2.18.1",
|
"moment": "^2.18.1",
|
||||||
"pug": "^2.0.0-rc.4",
|
"vue": "^2.5.15",
|
||||||
"vue": "^2.4.4",
|
"vue-material": "^1.0.0-beta-11",
|
||||||
"vue-awesome": "^2.3.3",
|
"vue-router": "^3.0.0",
|
||||||
"vue-progressbar": "^0.7.3",
|
"vuex": "^3.0.1"
|
||||||
"vue-router": "^2.6.0",
|
|
||||||
"vue-toast": "^3.1.0",
|
|
||||||
"vuex": "^2.4.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^7.1.4",
|
"@vue/cli-plugin-babel": "^3.0.0",
|
||||||
"babel-core": "^6.26.0",
|
"@vue/cli-plugin-eslint": "^3.0.0",
|
||||||
"babel-eslint": "^7.1.1",
|
"@vue/cli-service": "^3.0.0",
|
||||||
"babel-loader": "^7.1.2",
|
"@vue/eslint-config-standard": "^4.0.0",
|
||||||
"babel-plugin-istanbul": "^4.1.5",
|
"node-sass": "^4.12.0",
|
||||||
"babel-plugin-transform-runtime": "^6.22.0",
|
"pug": "^2.0.1",
|
||||||
"babel-preset-env": "^1.3.2",
|
"pug-plain-loader": "^1.0.0",
|
||||||
"babel-preset-stage-2": "^6.22.0",
|
"sass-loader": "^7.3.1",
|
||||||
"babel-register": "^6.26.0",
|
"vue-template-compiler": "^2.5.17",
|
||||||
"chai": "^3.5.0",
|
"webpack-bundle-analyzer": "^3.4.1"
|
||||||
"chalk": "^2.1.0",
|
}
|
||||||
"chromedriver": "^2.32.3",
|
|
||||||
"connect-history-api-fallback": "^1.3.0",
|
|
||||||
"copy-webpack-plugin": "^4.0.1",
|
|
||||||
"cross-env": "^5.0.5",
|
|
||||||
"cross-spawn": "^5.0.1",
|
|
||||||
"css-loader": "^0.28.7",
|
|
||||||
"cssnano": "^3.10.0",
|
|
||||||
"eslint": "^3.19.0",
|
|
||||||
"eslint-config-standard": "^6.2.1",
|
|
||||||
"eslint-friendly-formatter": "^3.0.0",
|
|
||||||
"eslint-loader": "^1.7.1",
|
|
||||||
"eslint-plugin-html": "^3.2.2",
|
|
||||||
"eslint-plugin-promise": "^3.4.0",
|
|
||||||
"eslint-plugin-standard": "^2.0.1",
|
|
||||||
"eventsource-polyfill": "^0.9.6",
|
|
||||||
"express": "^4.15.4",
|
|
||||||
"extract-text-webpack-plugin": "^2.0.0",
|
|
||||||
"file-loader": "^0.11.1",
|
|
||||||
"friendly-errors-webpack-plugin": "^1.1.3",
|
|
||||||
"html-webpack-plugin": "^2.30.1",
|
|
||||||
"http-proxy-middleware": "^0.17.3",
|
|
||||||
"inject-loader": "^3.0.1",
|
|
||||||
"karma": "^1.7.1",
|
|
||||||
"karma-coverage": "^1.1.1",
|
|
||||||
"karma-mocha": "^1.3.0",
|
|
||||||
"karma-phantomjs-launcher": "^1.0.2",
|
|
||||||
"karma-phantomjs-shim": "^1.4.0",
|
|
||||||
"karma-sinon-chai": "^1.3.2",
|
|
||||||
"karma-sourcemap-loader": "^0.3.7",
|
|
||||||
"karma-spec-reporter": "0.0.31",
|
|
||||||
"karma-webpack": "^2.0.2",
|
|
||||||
"lolex": "^1.5.2",
|
|
||||||
"mocha": "^3.5.3",
|
|
||||||
"nightwatch": "^0.9.12",
|
|
||||||
"opn": "^5.1.0",
|
|
||||||
"optimize-css-assets-webpack-plugin": "^2.0.0",
|
|
||||||
"ora": "^1.2.0",
|
|
||||||
"phantomjs-prebuilt": "^2.1.15",
|
|
||||||
"rimraf": "^2.6.2",
|
|
||||||
"selenium-server": "^3.5.3",
|
|
||||||
"semver": "^5.4.1",
|
|
||||||
"shelljs": "^0.7.6",
|
|
||||||
"sinon": "^2.4.1",
|
|
||||||
"sinon-chai": "^2.13.0",
|
|
||||||
"url-loader": "^0.5.8",
|
|
||||||
"vue-loader": "^12.1.0",
|
|
||||||
"vue-style-loader": "^3.0.3",
|
|
||||||
"vue-template-compiler": "^2.4.4",
|
|
||||||
"webpack": "^2.6.1",
|
|
||||||
"webpack-bundle-analyzer": "^2.9.0",
|
|
||||||
"webpack-dev-middleware": "^1.12.0",
|
|
||||||
"webpack-hot-middleware": "^2.19.1",
|
|
||||||
"webpack-merge": "^4.1.0"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 4.0.0",
|
|
||||||
"npm": ">= 3.0.0"
|
|
||||||
},
|
|
||||||
"browserslist": [
|
|
||||||
"> 1%",
|
|
||||||
"last 2 versions",
|
|
||||||
"not ie <= 8"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
src/app/public/favicon.ico
Normal file
BIN
src/app/public/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
19
src/app/public/index.html
Normal file
19
src/app/public/index.html
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<!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,52 +1,158 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
#app
|
#app.page-container
|
||||||
|
md-app(md-waterfall md-mode='fixed-last' role='application')
|
||||||
|
md-app-toolbar.md-large.md-dense.md-primary
|
||||||
|
.md-toolbar-row
|
||||||
|
.md-toolbar-section-start
|
||||||
|
router-link(to='/').md-title
|
||||||
|
span(style='font-weight:100;') my
|
||||||
|
span(style='font-weight:400;') Prayer
|
||||||
|
span(style='font-weight:700;') Journal
|
||||||
navigation
|
navigation
|
||||||
#content.container
|
md-app-content
|
||||||
|
md-progress-bar(v-if='progress.visible'
|
||||||
|
:md-mode='progress.mode')
|
||||||
router-view
|
router-view
|
||||||
vue-progress-bar
|
md-snackbar(:md-active.sync='snackbar.visible'
|
||||||
toast(ref='toast')
|
md-position='center'
|
||||||
|
:md-duration='snackbar.interval'
|
||||||
|
ref='snackbar') {{ snackbar.message }}
|
||||||
footer
|
footer
|
||||||
p.text-right: i myPrayerJournal v0.8.2
|
p.mpj-muted-text.mpj-text-right
|
||||||
|
| myPrayerJournal v{{ version }}
|
||||||
|
br
|
||||||
|
em: small.
|
||||||
|
#[router-link(to='/legal/privacy-policy') Privacy Policy] •
|
||||||
|
#[router-link(to='/legal/terms-of-service') 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>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
import Navigation from './components/Navigation.vue'
|
import Vue from 'vue'
|
||||||
|
|
||||||
|
import Navigation from '@/components/common/Navigation'
|
||||||
|
|
||||||
|
import actions from '@/store/action-types'
|
||||||
|
import { version } from '../package.json'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'app',
|
name: 'app',
|
||||||
components: {
|
components: {
|
||||||
Navigation
|
Navigation
|
||||||
},
|
},
|
||||||
mounted () {
|
data () {
|
||||||
this.$refs.toast.setOptions({ position: 'bottom right' })
|
return {
|
||||||
|
progress: {
|
||||||
|
events: new Vue(),
|
||||||
|
visible: false,
|
||||||
|
mode: 'query'
|
||||||
|
},
|
||||||
|
snackbar: {
|
||||||
|
events: new Vue(),
|
||||||
|
visible: false,
|
||||||
|
message: '',
|
||||||
|
interval: 4000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async mounted () {
|
||||||
|
this.progress.events.$on('show', this.showProgress)
|
||||||
|
this.progress.events.$on('done', this.hideProgress)
|
||||||
|
this.snackbar.events.$on('info', this.showInfo)
|
||||||
|
this.snackbar.events.$on('error', this.showError)
|
||||||
|
await this.$store.dispatch(actions.CHECK_AUTHENTICATION)
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
toast () {
|
version () {
|
||||||
return this.$refs.toast
|
return version.endsWith('.0')
|
||||||
|
? version.endsWith('.0.0')
|
||||||
|
? version.substr(0, version.length - 4)
|
||||||
|
: version.substr(0, version.length - 2)
|
||||||
|
: version
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
showSnackbar (message) {
|
||||||
|
this.snackbar.message = message
|
||||||
|
this.snackbar.visible = true
|
||||||
|
},
|
||||||
|
showInfo (message) {
|
||||||
|
this.snackbar.interval = 4000
|
||||||
|
this.showSnackbar(message)
|
||||||
|
},
|
||||||
|
showError (message) {
|
||||||
|
this.snackbar.interval = Infinity
|
||||||
|
this.showSnackbar(message)
|
||||||
|
},
|
||||||
|
showProgress (mode) {
|
||||||
|
this.progress.mode = mode
|
||||||
|
this.progress.visible = true
|
||||||
|
},
|
||||||
|
hideProgress () {
|
||||||
|
this.progress.visible = false
|
||||||
|
},
|
||||||
|
handleLoginEvent (data) {
|
||||||
|
if (!data.loggedIn) {
|
||||||
|
this.showInfo('Logged out successfully')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
provide () {
|
||||||
|
return {
|
||||||
|
messages: this.snackbar.events,
|
||||||
|
progress: this.progress.events
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style lang="sass">
|
||||||
body {
|
@import "~vue-material/dist/theme/engine"
|
||||||
padding-top: 60px;
|
@include md-register-theme("default", (primary: md-get-palette-color(green, 800), accent: md-get-palette-color(gray, 700)))
|
||||||
}
|
@import "~vue-material/dist/theme/all"
|
||||||
footer {
|
|
||||||
border-top: solid 1px lightgray;
|
html, body
|
||||||
margin-top: 1rem;
|
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
|
||||||
padding: 0 1rem;
|
font-size: 1rem
|
||||||
}
|
p
|
||||||
footer p {
|
margin-bottom: 0
|
||||||
margin: 0;
|
footer
|
||||||
}
|
border-top: solid 1px lightgray
|
||||||
.mpj-page-title {
|
margin: 1rem -1rem 0
|
||||||
border-bottom: solid 1px lightgray;
|
padding: 0 1rem
|
||||||
margin-bottom: 20px;
|
footer p
|
||||||
}
|
margin: 0
|
||||||
.mpj-request-text {
|
.mpj-full-page-card
|
||||||
white-space: pre-line;
|
font-size: 1rem
|
||||||
}
|
line-height: 1.25rem
|
||||||
|
.mpj-main-content
|
||||||
|
max-width: 60rem
|
||||||
|
margin: auto
|
||||||
|
.mpj-request-text
|
||||||
|
white-space: pre-line
|
||||||
|
p.mpj-request-text
|
||||||
|
margin-top: 0
|
||||||
|
.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-valign-top
|
||||||
|
vertical-align: top
|
||||||
|
.mpj-narrow
|
||||||
|
max-width: 40rem
|
||||||
|
margin: auto
|
||||||
|
.mpj-skinny
|
||||||
|
max-width: 20rem
|
||||||
|
margin: auto
|
||||||
|
.mpj-full-width
|
||||||
|
width: 100%
|
||||||
|
.md-progress-bar
|
||||||
|
margin: 24px
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
const http = axios.create({
|
const http = axios.create({
|
||||||
baseURL: 'http://localhost:3000/api/'
|
baseURL: `${location.protocol}//${location.host}/api/`
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -13,32 +15,44 @@ export default {
|
|||||||
* Set the bearer token for all future requests
|
* Set the bearer token for all future requests
|
||||||
* @param {string} token The token to use to identify the user to the server
|
* @param {string} token The token to use to identify the user to the server
|
||||||
*/
|
*/
|
||||||
setBearer: token => { http.defaults.headers.common['authorization'] = `Bearer ${token}` },
|
setBearer: token => { http.defaults.headers.common['Authorization'] = `Bearer ${token}` },
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the bearer token
|
* Remove the bearer token
|
||||||
*/
|
*/
|
||||||
removeBearer: () => delete http.defaults.headers.common['authorization'],
|
removeBearer: () => delete http.defaults.headers.common['Authorization'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all prayer requests and their most recent updates
|
* 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
|
||||||
*/
|
*/
|
||||||
journal: () => http.get('journal/'),
|
addNote: (requestId, notes) => http.post(`request/${requestId}/note`, { notes }),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new prayer request
|
* Add a new prayer request
|
||||||
* @param {string} requestText The text of the request to be added
|
* @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 => http.post('request/', { requestText }),
|
addRequest: (requestText, recurType, recurCount) => http.post('request', { requestText, recurType, recurCount }),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a prayer request
|
* Get all answered requests, along with the text they had when it was answered
|
||||||
* @param request The request (should have requestId, status, and updateText properties)
|
|
||||||
*/
|
*/
|
||||||
updateRequest: request => http.post(`request/${request.requestId}/history`, {
|
getAnsweredRequests: () => http.get('requests/answered'),
|
||||||
status: request.status,
|
|
||||||
updateText: request.updateText
|
/**
|
||||||
}),
|
* 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)
|
* Get a prayer request (journal-style; only latest update)
|
||||||
@@ -47,14 +61,38 @@ export default {
|
|||||||
getRequest: requestId => http.get(`request/${requestId}`),
|
getRequest: requestId => http.get(`request/${requestId}`),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a prayer request (full; includes all history)
|
* Get all prayer requests and their most recent updates
|
||||||
* @param {string} requestId The Id of the request to retrieve
|
|
||||||
*/
|
*/
|
||||||
getFullRequest: requestId => http.get(`request/${requestId}/full`),
|
journal: () => http.get('journal'),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all answered requests, along with the text they had when it was answered
|
* 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
|
||||||
*/
|
*/
|
||||||
getAnsweredRequests: () => http.get('request/answered')
|
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,30 +1,45 @@
|
|||||||
'use strict'
|
'use strict'
|
||||||
|
/* eslint-disable */
|
||||||
import auth0 from 'auth0-js'
|
import auth0 from 'auth0-js'
|
||||||
|
import EventEmitter from 'events'
|
||||||
|
|
||||||
import AUTH_CONFIG from './auth0-variables'
|
import AUTH_CONFIG from './auth0-variables'
|
||||||
import mutations from '@/store/mutation-types'
|
import mutations from '@/store/mutation-types'
|
||||||
|
/* es-lint-enable*/
|
||||||
|
|
||||||
export default class AuthService {
|
// Auth0 web authentication instance to use for our calls
|
||||||
|
const webAuth = new auth0.WebAuth({
|
||||||
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,
|
domain: AUTH_CONFIG.domain,
|
||||||
clientID: AUTH_CONFIG.clientId,
|
clientID: AUTH_CONFIG.clientId,
|
||||||
redirectUri: AUTH_CONFIG.callbackUrl,
|
redirectUri: AUTH_CONFIG.appDomain + AUTH_CONFIG.callbackUrl,
|
||||||
audience: `https://${AUTH_CONFIG.domain}/userinfo`,
|
audience: `https://${AUTH_CONFIG.domain}/userinfo`,
|
||||||
responseType: 'token id_token',
|
responseType: 'token id_token',
|
||||||
scope: 'openid profile email'
|
scope: 'openid profile email'
|
||||||
})
|
})
|
||||||
|
|
||||||
login () {
|
/**
|
||||||
this.auth0.authorize()
|
* A class to handle all authentication calls and determinations
|
||||||
|
*/
|
||||||
|
class AuthService extends EventEmitter {
|
||||||
|
|
||||||
|
// Local storage key for our session data
|
||||||
|
AUTH_SESSION = 'auth-session'
|
||||||
|
|
||||||
|
// Received and calculated values for our ssesion (initially loaded from local storage if present)
|
||||||
|
session = {}
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
this.refreshSession()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the user log in flow
|
||||||
|
*/
|
||||||
|
login (customState) {
|
||||||
|
webAuth.authorize({
|
||||||
|
appState: customState
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -32,7 +47,7 @@ export default class AuthService {
|
|||||||
*/
|
*/
|
||||||
parseHash () {
|
parseHash () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.auth0.parseHash((err, authResult) => {
|
webAuth.parseHash((err, authResult) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err)
|
reject(err)
|
||||||
} else {
|
} else {
|
||||||
@@ -43,65 +58,137 @@ export default class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Promisified userInfo function
|
* Handle authentication replies from Auth0
|
||||||
*
|
*
|
||||||
* @param token The auth token from the login result
|
* @param store The Vuex store
|
||||||
*/
|
*/
|
||||||
userInfo (token) {
|
async handleAuthentication (store) {
|
||||||
|
try {
|
||||||
|
const authResult = await this.parseHash()
|
||||||
|
if (authResult && authResult.accessToken && authResult.idToken) {
|
||||||
|
this.setSession(authResult)
|
||||||
|
store.commit(mutations.USER_LOGGED_ON, this.session.profile)
|
||||||
|
}
|
||||||
|
} catch(err) {
|
||||||
|
console.error(err)
|
||||||
|
alert(`Error: ${err.error}. Check the console for further details.`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up the session and commit it to local storage
|
||||||
|
*
|
||||||
|
* @param authResult The authorization result
|
||||||
|
*/
|
||||||
|
setSession (authResult) {
|
||||||
|
this.session.profile = authResult.idTokenPayload
|
||||||
|
this.session.id.token = authResult.idToken
|
||||||
|
this.session.id.expiry = this.session.profile.exp * 1000
|
||||||
|
this.session.access.token = authResult.accessToken
|
||||||
|
this.session.access.expiry = authResult.expiresIn * 1000 + Date.now()
|
||||||
|
|
||||||
|
localStorage.setItem(this.AUTH_SESSION, JSON.stringify(this.session))
|
||||||
|
|
||||||
|
this.emit('loginEvent', {
|
||||||
|
loggedIn: true,
|
||||||
|
profile: authResult.idTokenPayload,
|
||||||
|
state: authResult.appState || {}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Refresh this instance's session from the one in local storage
|
||||||
|
*/
|
||||||
|
refreshSession () {
|
||||||
|
this.session =
|
||||||
|
localStorage.getItem(this.AUTH_SESSION)
|
||||||
|
? JSON.parse(localStorage.getItem(this.AUTH_SESSION))
|
||||||
|
: { profile: {},
|
||||||
|
id: {
|
||||||
|
token: null,
|
||||||
|
expiry: null
|
||||||
|
},
|
||||||
|
access: {
|
||||||
|
token: null,
|
||||||
|
expiry: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renew authorzation tokens with Auth0
|
||||||
|
*/
|
||||||
|
renewTokens () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.auth0.client.userInfo(token, (err, user) => {
|
this.refreshSession()
|
||||||
|
if (this.session.id.token !== null) {
|
||||||
|
webAuth.checkSession({}, (err, authResult) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
reject(err)
|
reject(err)
|
||||||
} else {
|
} else {
|
||||||
resolve(user)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
handleAuthentication (store, router) {
|
|
||||||
this.parseHash()
|
|
||||||
.then(authResult => {
|
|
||||||
if (authResult && authResult.accessToken && authResult.idToken) {
|
|
||||||
this.setSession(authResult)
|
this.setSession(authResult)
|
||||||
this.userInfo(authResult.accessToken)
|
resolve(authResult)
|
||||||
.then(user => {
|
|
||||||
store.commit(mutations.USER_LOGGED_ON, user)
|
|
||||||
router.replace('/journal')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
} else {
|
||||||
router.replace('/')
|
reject('Not logged in')
|
||||||
console.log(err)
|
}
|
||||||
alert(`Error: ${err.error}. Check the console for further details.`)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
setSession (authResult) {
|
/**
|
||||||
// Set the time that the access token will expire at
|
* Log out of myPrayerJournal
|
||||||
let expiresAt = JSON.stringify(
|
*
|
||||||
authResult.expiresIn * 1000 + new Date().getTime()
|
* @param store The Vuex store
|
||||||
)
|
*/
|
||||||
localStorage.setItem('access_token', authResult.accessToken)
|
logout (store) {
|
||||||
localStorage.setItem('id_token', authResult.idToken)
|
|
||||||
localStorage.setItem('expires_at', expiresAt)
|
|
||||||
}
|
|
||||||
|
|
||||||
logout (store, router) {
|
|
||||||
// Clear access token and ID token from local storage
|
// Clear access token and ID token from local storage
|
||||||
localStorage.removeItem('access_token')
|
localStorage.removeItem(this.AUTH_SESSION)
|
||||||
localStorage.removeItem('id_token')
|
this.refreshSession()
|
||||||
localStorage.removeItem('expires_at')
|
|
||||||
localStorage.setItem('user_profile', JSON.stringify({}))
|
|
||||||
// navigate to the home route
|
|
||||||
store.commit(mutations.USER_LOGGED_OFF)
|
store.commit(mutations.USER_LOGGED_OFF)
|
||||||
router.replace('/')
|
|
||||||
|
webAuth.logout({
|
||||||
|
returnTo: `${AUTH_CONFIG.appDomain}/`,
|
||||||
|
clientID: AUTH_CONFIG.clientId
|
||||||
|
})
|
||||||
|
this.emit('loginEvent', { loggedIn: false })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check expiration for a token (the way it's stored in the session)
|
||||||
|
*/
|
||||||
|
checkExpiry = (it) => it.token && it.expiry && Date.now() < it.expiry
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is there a user authenticated?
|
||||||
|
*/
|
||||||
isAuthenticated () {
|
isAuthenticated () {
|
||||||
// Check whether the current time is past the access token's expiry time
|
return this.checkExpiry(this.session.id)
|
||||||
let expiresAt = JSON.parse(localStorage.getItem('expires_at'))
|
}
|
||||||
return new Date().getTime() < expiresAt
|
|
||||||
|
/**
|
||||||
|
* Is the current access token valid?
|
||||||
|
*/
|
||||||
|
isAccessTokenValid () {
|
||||||
|
return this.checkExpiry(this.session.access)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the user's access token, renewing it if required
|
||||||
|
*/
|
||||||
|
async getAccessToken () {
|
||||||
|
if (this.isAccessTokenValid()) {
|
||||||
|
return this.session.access.token
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
const authResult = await this.renewTokens()
|
||||||
|
return authResult.accessToken
|
||||||
|
} catch (reject) {
|
||||||
|
throw reject
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default new AuthService()
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
article
|
|
||||||
page-title(title='Answered Requests')
|
|
||||||
p(v-if='!loaded') Loading answered requests...
|
|
||||||
div(v-if='loaded')
|
|
||||||
p.mpj-request-text(v-for='req in requests')
|
|
||||||
b-btn(@click='showFull(req.requestId)' size='sm' variant='outline-secondary')
|
|
||||||
icon(name='search')
|
|
||||||
| View Full Request
|
|
||||||
| {{ req.text }}
|
|
||||||
small.text-muted: em.
|
|
||||||
(Answered #[date-from-now(:value='req.asOf')])
|
|
||||||
full-request(:events='eventBus')
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use static'
|
|
||||||
|
|
||||||
import Vue from 'vue'
|
|
||||||
|
|
||||||
import FullRequest from './request/FullRequest'
|
|
||||||
|
|
||||||
import api from '@/api'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'answered',
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
eventBus: new Vue(),
|
|
||||||
requests: [],
|
|
||||||
loaded: false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
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
|
|
||||||
}
|
|
||||||
},
|
|
||||||
components: {
|
|
||||||
FullRequest
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
toast () {
|
|
||||||
return this.$parent.$refs.toast
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
showFull (requestId) {
|
|
||||||
this.eventBus.$emit('full', requestId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,15 +1,16 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
article
|
md-content(role='main').mpj-main-content
|
||||||
page-title(title='Welcome!' hideOnPage='true')
|
page-title(title='Welcome!'
|
||||||
|
hideOnPage=true)
|
||||||
p
|
p
|
||||||
p.
|
p.
|
||||||
myPrayerJournal is a place where individuals can record their prayer requests, record that they prayed for them,
|
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
|
update them as God moves in the situation, and record a final answer received on that request. It also allows
|
||||||
allow individuals to review their answered prayers.
|
individuals to review their answered prayers.
|
||||||
p.
|
p.
|
||||||
This site is currently in very limited alpha, as it is being developed with a core group of test users. If
|
This site is open and available to the general public. To get started, simply click the “Log On” link
|
||||||
this is something in which you are interested, check back around mid-November 2017 for an update on the
|
above, and log on with either a Microsoft or Google account. You can also learn more about the site at the
|
||||||
development progress.
|
“Docs” link, also above.
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
article
|
md-content(role='main').mpj-main-content-wide
|
||||||
page-title(:title='title')
|
page-title(:title='title')
|
||||||
p(v-if='isLoadingJournal') Loading your prayer journal...
|
p(v-if='isLoadingJournal') Loading your prayer journal...
|
||||||
template(v-if='!isLoadingJournal')
|
template(v-else)
|
||||||
new-request
|
md-empty-state(v-if='journal.length === 0'
|
||||||
|
md-icon='done_all'
|
||||||
|
md-label='No Requests to Show'
|
||||||
|
md-description='You have no requests to be shown; see the “Active” link above for snoozed/deferred requests, and the “Answered” link for answered requests')
|
||||||
|
md-button(:to="{ name: 'EditRequest', params: { id: 'new' } }").md-primary.md-raised Add a New Request
|
||||||
|
template(v-else)
|
||||||
|
.mpj-text-center
|
||||||
|
md-button(:to="{ name: 'EditRequest', params: { id: 'new' } }"
|
||||||
|
role='button').md-raised.md-accent #[md-icon add_box] Add a New Request
|
||||||
br
|
br
|
||||||
request-list-item(v-if='journal.length > 0'
|
.mpj-journal
|
||||||
v-for='row in journalCardRows'
|
request-card(v-for='request in journal'
|
||||||
:row='row'
|
:key='request.requestId'
|
||||||
:events='eventBus'
|
:request='request')
|
||||||
:toast='toast'
|
notes-edit
|
||||||
:key='row[0].requestId')
|
snooze-request
|
||||||
p.text-center(v-if='journal.length === 0'): em No requests found; click the "Add a New Request" button to add one
|
|
||||||
edit-request(:events='eventBus' :toast='toast' )
|
|
||||||
full-request(:events='eventBus')
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -21,43 +26,56 @@ article
|
|||||||
|
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import { mapState } from 'vuex'
|
import { mapState } from 'vuex'
|
||||||
import chunk from 'lodash/chunk'
|
|
||||||
|
|
||||||
import EditRequest from './request/EditRequest'
|
import NotesEdit from './request/NotesEdit'
|
||||||
import FullRequest from './request/FullRequest'
|
import RequestCard from './request/RequestCard'
|
||||||
import NewRequest from './request/NewRequest'
|
import SnoozeRequest from './request/SnoozeRequest'
|
||||||
import RequestListItem from './request/RequestListItem'
|
|
||||||
|
|
||||||
import actions from '@/store/action-types'
|
import actions from '@/store/action-types'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'journal',
|
name: 'journal',
|
||||||
|
inject: [
|
||||||
|
'messages',
|
||||||
|
'progress'
|
||||||
|
],
|
||||||
|
components: {
|
||||||
|
NotesEdit,
|
||||||
|
RequestCard,
|
||||||
|
SnoozeRequest
|
||||||
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
eventBus: new Vue()
|
eventBus: new Vue()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
|
||||||
EditRequest,
|
|
||||||
FullRequest,
|
|
||||||
NewRequest,
|
|
||||||
RequestListItem
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
title () {
|
title () {
|
||||||
return `${this.user.given_name}'s Prayer Journal`
|
return `${this.user.given_name}’s Prayer Journal`
|
||||||
},
|
},
|
||||||
journalCardRows () {
|
snackbar () {
|
||||||
return chunk(this.journal, 3)
|
return this.$parent.$refs.snackbar
|
||||||
},
|
|
||||||
toast () {
|
|
||||||
return this.$parent.$refs.toast
|
|
||||||
},
|
},
|
||||||
...mapState(['user', 'journal', 'isLoadingJournal'])
|
...mapState(['user', 'journal', 'isLoadingJournal'])
|
||||||
},
|
},
|
||||||
async created () {
|
async created () {
|
||||||
await this.$store.dispatch(actions.LOAD_JOURNAL, this.$Progress)
|
await this.$store.dispatch(actions.LOAD_JOURNAL, this.progress)
|
||||||
this.toast.showToast(`Loaded ${this.journal.length} prayer requests`, { theme: 'success' })
|
this.messages.$emit('info', `Loaded ${this.journal.length} prayer requests`)
|
||||||
|
},
|
||||||
|
provide () {
|
||||||
|
return {
|
||||||
|
journalEvents: this.eventBus
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style lang="sass">
|
||||||
|
.mpj-journal
|
||||||
|
display: flex
|
||||||
|
flex-flow: row wrap
|
||||||
|
justify-content: center
|
||||||
|
align-items: flex-start
|
||||||
|
.mpj-dialog-content
|
||||||
|
padding: 0 1rem
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
b-navbar(toggleable='sm' type='dark' variant='mpj' fixed='top')
|
|
||||||
b-nav-toggle(target='nav_collapse')
|
|
||||||
b-navbar-brand(to='/')
|
|
||||||
span(style='font-weight:100;') my
|
|
||||||
span(style='font-weight:600;') Prayer
|
|
||||||
span(style='font-weight:700;') Journal
|
|
||||||
b-collapse#nav_collapse(is-nav)
|
|
||||||
b-nav(is-nav-bar)
|
|
||||||
b-nav-item(v-if='isAuthenticated' to='/journal') Journal
|
|
||||||
b-nav-item(v-if='isAuthenticated' to='/answered') Answered
|
|
||||||
b-nav-item(v-if='isAuthenticated'): a(@click.stop='logOff()') Log Off
|
|
||||||
b-nav-item(v-if='!isAuthenticated'): a(@click.stop='logOn()') Log On
|
|
||||||
b-nav-item(href='https://danieljsummers.github.io/myPrayerJournal/' target='_blank' @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()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
logOn () {
|
|
||||||
this.auth0.login()
|
|
||||||
},
|
|
||||||
logOff () {
|
|
||||||
this.auth0.logout(this.$store, this.$router)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
...mapState([ 'isAuthenticated' ])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.bg-mpj {
|
|
||||||
background-color: #1e7e34 !important;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -20,13 +20,16 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
const dt = moment(this.value)
|
|
||||||
return {
|
return {
|
||||||
fromNow: dt.fromNow(),
|
fromNow: moment(this.value).fromNow(),
|
||||||
actual: dt.format('LLLL'),
|
|
||||||
intervalId: null
|
intervalId: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
actual () {
|
||||||
|
return moment(this.value).format('LLLL')
|
||||||
|
}
|
||||||
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
this.intervalId = setInterval(this.updateFromNow, this.interval)
|
this.intervalId = setInterval(this.updateFromNow, this.interval)
|
||||||
this.$watch('value', this.updateFromNow)
|
this.$watch('value', this.updateFromNow)
|
||||||
|
|||||||
59
src/app/src/components/common/Navigation.vue
Normal file
59
src/app/src/components/common/Navigation.vue
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
.md-toolbar-row
|
||||||
|
md-tabs(md-sync-route).md-primary
|
||||||
|
template(v-if='isAuthenticated')
|
||||||
|
md-tab(md-label='Journal'
|
||||||
|
to='/journal')
|
||||||
|
md-tab(md-label='Active'
|
||||||
|
to='/requests/active')
|
||||||
|
md-tab(v-if='hasSnoozed'
|
||||||
|
md-label='Snoozed'
|
||||||
|
to='/requests/snoozed')
|
||||||
|
md-tab(md-label='Answered'
|
||||||
|
to='/requests/answered')
|
||||||
|
md-tab(md-label='Log Off'
|
||||||
|
href='/user/log-off'
|
||||||
|
@click.prevent='logOff()')
|
||||||
|
md-tab(md-label='Docs'
|
||||||
|
href='https://docs.prayerjournal.me'
|
||||||
|
@click.prevent='showHelp()')
|
||||||
|
template(v-else)
|
||||||
|
md-tab(md-label='Log On'
|
||||||
|
href='/user/log-on'
|
||||||
|
@click.prevent='logOn()')
|
||||||
|
md-tab(md-label='Docs'
|
||||||
|
href='https://docs.prayerjournal.me'
|
||||||
|
@click.prevent='showHelp()')
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import { mapState } from 'vuex'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'navigation',
|
||||||
|
data () {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
hasSnoozed () {
|
||||||
|
return this.isAuthenticated &&
|
||||||
|
Array.isArray(this.journal) &&
|
||||||
|
this.journal.filter(req => req.snoozedUntil > Date.now()).length > 0
|
||||||
|
},
|
||||||
|
...mapState([ 'isAuthenticated', 'journal' ])
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
logOn () {
|
||||||
|
this.$auth.login()
|
||||||
|
},
|
||||||
|
logOff () {
|
||||||
|
this.$auth.logout(this.$store, this.$router)
|
||||||
|
},
|
||||||
|
showHelp () {
|
||||||
|
window.open('https://docs.prayerjournal.me', '_blank')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
h2.mpj-page-title(v-if='!hideOnPage' v-html='title')
|
h1(v-if='!hideOnPage'
|
||||||
|
v-html='title').md-title
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -15,13 +16,13 @@ export default {
|
|||||||
default: false
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
|
||||||
document.title = `${this.title} « myPrayerJournal`
|
|
||||||
},
|
|
||||||
watch: {
|
watch: {
|
||||||
title () {
|
title () {
|
||||||
document.title = `${this.title} « myPrayerJournal`
|
document.title = `${this.title.replace('’', "'")} « myPrayerJournal`
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
created () {
|
||||||
|
document.title = `${this.title.replace('’', "'")} « myPrayerJournal`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
59
src/app/src/components/legal/PrivacyPolicy.vue
Normal file
59
src/app/src/components/legal/PrivacyPolicy.vue
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
md-content(role='main').mpj-main-content
|
||||||
|
page-title(title='Privacy Policy'
|
||||||
|
hide-on-page=true)
|
||||||
|
md-card
|
||||||
|
md-card-header
|
||||||
|
.md-title Privacy Policy
|
||||||
|
.md-subhead as of May 21, 2018
|
||||||
|
md-card-content.mpj-full-page-card
|
||||||
|
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>
|
||||||
40
src/app/src/components/legal/TermsOfService.vue
Normal file
40
src/app/src/components/legal/TermsOfService.vue
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
md-content(role='main').mpj-main-content
|
||||||
|
page-title(title='Terms of Service'
|
||||||
|
hide-on-page=true)
|
||||||
|
md-card
|
||||||
|
md-card-header
|
||||||
|
.md-title Terms of Service
|
||||||
|
.md-subhead as of May 21, 2018
|
||||||
|
md-card-content.mpj-full-page-card
|
||||||
|
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>
|
||||||
60
src/app/src/components/request/ActiveRequests.vue
Normal file
60
src/app/src/components/request/ActiveRequests.vue
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
md-content(role='main').mpj-main-content
|
||||||
|
page-title(title='Active Requests'
|
||||||
|
hide-on-page=true)
|
||||||
|
template(v-if='loaded')
|
||||||
|
md-empty-state(v-if='requests.length === 0'
|
||||||
|
md-icon='sentiment_dissatisfied'
|
||||||
|
md-label='No Active Requests'
|
||||||
|
md-description='Your prayer journal has no active requests')
|
||||||
|
md-button(to='/journal').md-primary.md-raised Return to your journal
|
||||||
|
request-list(v-if='requests.length !== 0'
|
||||||
|
title='Active Requests'
|
||||||
|
:requests='requests')
|
||||||
|
p(v-else) Loading journal...
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import { mapState } from 'vuex'
|
||||||
|
|
||||||
|
import RequestList from '@/components/request/RequestList'
|
||||||
|
|
||||||
|
import actions from '@/store/action-types'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'active-requests',
|
||||||
|
inject: ['progress'],
|
||||||
|
components: {
|
||||||
|
RequestList
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
requests: [],
|
||||||
|
loaded: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...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>
|
||||||
53
src/app/src/components/request/AnsweredRequests.vue
Normal file
53
src/app/src/components/request/AnsweredRequests.vue
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
md-content(role='main').mpj-main-content
|
||||||
|
page-title(title='Answered Requests'
|
||||||
|
hide-on-page=true)
|
||||||
|
template(v-if='loaded')
|
||||||
|
md-empty-state(v-if='requests.length === 0'
|
||||||
|
md-icon='sentiment_dissatisfied'
|
||||||
|
md-label='No Answered Requests'
|
||||||
|
md-description='Your prayer journal has no answered requests; once you have marked one as “Answered”, it will appear here')
|
||||||
|
request-list(v-if='requests.length !== 0'
|
||||||
|
title='Answered Requests'
|
||||||
|
:requests='requests')
|
||||||
|
p(v-else) Loading answered requests...
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import api from '@/api'
|
||||||
|
|
||||||
|
import RequestList from '@/components/request/RequestList'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'answered-requests',
|
||||||
|
inject: [
|
||||||
|
'messages',
|
||||||
|
'progress'
|
||||||
|
],
|
||||||
|
components: {
|
||||||
|
RequestList
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
requests: [],
|
||||||
|
loaded: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async mounted () {
|
||||||
|
this.progress.$emit('show', 'query')
|
||||||
|
try {
|
||||||
|
const reqs = await api.getAnsweredRequests()
|
||||||
|
this.requests = reqs.data
|
||||||
|
this.progress.$emit('done')
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err)
|
||||||
|
this.messages.$emit('error', 'Error loading requests; check console for details')
|
||||||
|
this.progress.$emit('done')
|
||||||
|
} finally {
|
||||||
|
this.loaded = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -1,83 +1,173 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
span
|
md-content(role='main').mpj-narrow
|
||||||
//- b-btn(@click='openDialog()' title='Edit' size='sm' variant='outline-secondary'): icon(name='pencil')
|
page-title(:title='title')
|
||||||
b-modal(title='Edit Prayer Request'
|
md-field
|
||||||
v-model='editVisible'
|
label(for='request_text') Prayer Request
|
||||||
size='lg'
|
md-textarea(v-model='form.requestText'
|
||||||
header-bg-variant='dark'
|
@blur='trimText()'
|
||||||
header-text-variant='light'
|
md-autogrow
|
||||||
@edit='openDialog()'
|
autofocus).mpj-full-width
|
||||||
@shows='focusRequestText')
|
br
|
||||||
b-form
|
template(v-if='!isNew')
|
||||||
b-form-group(label='Prayer Request' label-for='request_text')
|
label Also Mark As
|
||||||
b-textarea#request_text(v-model='form.requestText' :rows='10' @blur='trimText()' ref='toFocus')
|
br
|
||||||
b-form-group(label='Also Mark As')
|
md-radio(v-model='form.status'
|
||||||
b-radio-group(v-model='form.status' buttons)
|
value='Updated') Updated
|
||||||
b-radio(value='Updated') Updated
|
md-radio(v-model='form.status'
|
||||||
b-radio(value='Prayed') Prayed
|
value='Prayed') Prayed
|
||||||
b-radio(value='Answered') Answered
|
md-radio(v-model='form.status'
|
||||||
div.w-100.text-right(slot='modal-footer')
|
value='Answered') Answered
|
||||||
b-btn(variant='primary' @click='saveRequest()') Save
|
br
|
||||||
|
label Recurrence
|
||||||
|
|
|
|
||||||
b-btn(variant='outline-secondary' @click='closeDialog()') Cancel
|
em.mpj-muted-text After prayer, request reappears...
|
||||||
|
br
|
||||||
|
.md-layout
|
||||||
|
.md-layout-item.md-size-30
|
||||||
|
md-radio(v-model='form.recur.typ'
|
||||||
|
value='Immediate') Immediately
|
||||||
|
.md-layout-item.md-size-20
|
||||||
|
md-radio(v-model='form.recur.typ'
|
||||||
|
value='other') Every...
|
||||||
|
.md-layout-item.md-size-10
|
||||||
|
md-field(md-inline)
|
||||||
|
label Count
|
||||||
|
md-input(v-model='form.recur.count'
|
||||||
|
type='number'
|
||||||
|
:disabled='!showRecurrence')
|
||||||
|
.md-layout-item.md-size-20
|
||||||
|
md-field
|
||||||
|
label Interval
|
||||||
|
md-select(v-model='form.recur.other'
|
||||||
|
:disabled='!showRecurrence')
|
||||||
|
md-option(value='Hours') hours
|
||||||
|
md-option(value='Days') days
|
||||||
|
md-option(value='Weeks') weeks
|
||||||
|
.mpj-text-right
|
||||||
|
md-button(:disabled='!isValidRecurrence'
|
||||||
|
@click.stop='saveRequest()').md-primary.md-raised #[md-icon save] Save
|
||||||
|
md-button(@click.stop='goBack()').md-raised #[md-icon arrow_back] Cancel
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
import { mapState } from 'vuex'
|
||||||
|
|
||||||
import actions from '@/store/action-types'
|
import actions from '@/store/action-types'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'edit-request',
|
name: 'edit-request',
|
||||||
|
inject: [
|
||||||
|
'messages',
|
||||||
|
'progress'
|
||||||
|
],
|
||||||
props: {
|
props: {
|
||||||
toast: { required: true },
|
id: {
|
||||||
events: { required: true }
|
type: String,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
editVisible: false,
|
title: 'Edit Prayer Request',
|
||||||
|
isNew: false,
|
||||||
form: {
|
form: {
|
||||||
requestId: '',
|
requestId: '',
|
||||||
requestText: '',
|
requestText: '',
|
||||||
status: 'Updated'
|
status: 'Updated',
|
||||||
|
recur: {
|
||||||
|
typ: 'Immediate',
|
||||||
|
other: '',
|
||||||
|
count: ''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
computed: {
|
||||||
this.events.$on('edit', this.openDialog)
|
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
|
||||||
},
|
},
|
||||||
methods: {
|
showRecurrence () {
|
||||||
closeDialog () {
|
return this.form.recur.typ !== 'Immediate'
|
||||||
|
},
|
||||||
|
...mapState(['journal'])
|
||||||
|
},
|
||||||
|
async mounted () {
|
||||||
|
await this.ensureJournal()
|
||||||
|
if (this.id === 'new') {
|
||||||
|
this.title = 'Add Prayer Request'
|
||||||
|
this.isNew = true
|
||||||
this.form.requestId = ''
|
this.form.requestId = ''
|
||||||
this.form.requestText = ''
|
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'
|
this.form.status = 'Updated'
|
||||||
this.editVisible = false
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
focusRequestText (e) {
|
methods: {
|
||||||
this.$refs.toFocus.focus()
|
goBack () {
|
||||||
},
|
this.$router.go(-1)
|
||||||
openDialog (request) {
|
|
||||||
this.form.requestId = request.requestId
|
|
||||||
this.form.requestText = request.text
|
|
||||||
this.editVisible = true
|
|
||||||
this.focusRequestText(null)
|
|
||||||
},
|
},
|
||||||
trimText () {
|
trimText () {
|
||||||
this.form.requestText = this.form.requestText.trim()
|
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 () {
|
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.messages.$emit('info', 'New prayer request added')
|
||||||
|
} else {
|
||||||
await this.$store.dispatch(actions.UPDATE_REQUEST, {
|
await this.$store.dispatch(actions.UPDATE_REQUEST, {
|
||||||
progress: this.$Progress,
|
progress: this.progress,
|
||||||
requestId: this.form.requestId,
|
requestId: this.form.requestId,
|
||||||
updateText: this.form.requestText,
|
updateText: this.form.requestText,
|
||||||
status: this.form.status
|
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') {
|
if (this.form.status === 'Answered') {
|
||||||
this.toast.showToast('Request updated and removed from active journal', { theme: 'success' })
|
this.messages.$emit('info', 'Request updated and removed from active journal')
|
||||||
} else {
|
} else {
|
||||||
this.toast.showToast('Request updated', { theme: 'success' })
|
this.messages.$emit('info', 'Request updated')
|
||||||
}
|
}
|
||||||
this.closeDialog()
|
}
|
||||||
|
this.goBack()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +1,93 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
span
|
md-content(role='main').mpj-main-content
|
||||||
b-modal(title='Prayer Request History'
|
page-title(title='Full Prayer Request'
|
||||||
v-model='historyVisible'
|
hide-on-page=true)
|
||||||
size='lg'
|
md-card(v-if='request')
|
||||||
header-bg-variant='dark'
|
md-card-header
|
||||||
header-text-variant='light'
|
.md-title Full Prayer Request
|
||||||
@shows='focusRequestText')
|
.md-subhead
|
||||||
b-list-group(v-if='null !== full' flush)
|
span(v-if='isAnswered') Answered {{ formatDate(answered) }} (#[date-from-now(:value='answered')]) !{' • '}
|
||||||
full-request-history(v-for='item in full.history' :history='item' :key='item.asOf')
|
| Prayed {{ prayedCount }} times • Open {{ openDays }} days
|
||||||
div.w-100.text-right(slot='modal-footer')
|
md-card-content.mpj-full-page-card
|
||||||
b-btn(variant='primary' @click='closeDialog()') Close
|
p.mpj-request-text {{ lastText }}
|
||||||
|
md-table
|
||||||
|
md-table-row
|
||||||
|
md-table-head Action
|
||||||
|
md-table-head Update / Notes
|
||||||
|
md-table-row(v-for='item in log'
|
||||||
|
:key='item.asOf')
|
||||||
|
md-table-cell.mpj-valign-top {{ item.status }} on #[span.mpj-text-nowrap {{ formatDate(item.asOf) }}]
|
||||||
|
md-table-cell(v-if='item.text').mpj-request-text.mpj-valign-top {{ item.text }}
|
||||||
|
md-table-cell(v-else)
|
||||||
|
p(v-else) Loading request...
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
import FullRequestHistory from './FullRequestHistory'
|
import moment from 'moment'
|
||||||
|
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
|
|
||||||
|
const asOfDesc = (a, b) => b.asOf - a.asOf
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'full-request',
|
name: 'full-request',
|
||||||
|
inject: ['progress'],
|
||||||
props: {
|
props: {
|
||||||
events: { required: true }
|
id: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
historyVisible: false,
|
request: null
|
||||||
full: null
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created () {
|
computed: {
|
||||||
this.events.$on('full', this.openDialog)
|
answered () {
|
||||||
|
return this.request.history.find(hist => hist.status === 'Answered').asOf
|
||||||
},
|
},
|
||||||
components: {
|
isAnswered () {
|
||||||
FullRequestHistory
|
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.$emit('show', 'indeterminate')
|
||||||
|
try {
|
||||||
|
const req = await api.getFullRequest(this.id)
|
||||||
|
this.request = req.data
|
||||||
|
this.progress.$emit('done')
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
this.progress.$emit('done')
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
closeDialog () {
|
formatDate (asOf) {
|
||||||
this.full = null
|
return moment(asOf).format('LL')
|
||||||
this.historyVisible = false
|
|
||||||
},
|
|
||||||
async openDialog (requestId) {
|
|
||||||
this.historyVisible = true
|
|
||||||
this.$Progress.start()
|
|
||||||
const req = await api.getFullRequest(requestId)
|
|
||||||
this.full = req.data
|
|
||||||
this.$Progress.finish()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
b-list-group-item
|
|
||||||
| {{ history.status }} {{ asOf }}
|
|
||||||
span(v-if='0 < history.text.length') » {{ history.text }}
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import moment from 'moment'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'full-request-history',
|
|
||||||
props: {
|
|
||||||
history: { required: true }
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
asOf () {
|
|
||||||
return moment(this.history.asOf).fromNow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,65 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
div
|
|
||||||
b-btn(@click='openDialog()' size='sm' variant='primary')
|
|
||||||
icon(name='plus')
|
|
||||||
| Add a New Request
|
|
||||||
b-modal(title='Add a New Prayer Request'
|
|
||||||
v-model='showNewVisible'
|
|
||||||
size='lg'
|
|
||||||
header-bg-variant='dark'
|
|
||||||
header-text-variant='light'
|
|
||||||
@shown='focusRequestText')
|
|
||||||
b-form
|
|
||||||
b-form-group(label='Prayer Request' label-for='request_text')
|
|
||||||
b-textarea#request_text(v-model='form.requestText' :rows='10' @blur='trimText()' ref='toFocus')
|
|
||||||
div.w-100.text-right(slot='modal-footer')
|
|
||||||
b-btn(variant='primary' @click='saveRequest()') Save
|
|
||||||
|
|
|
||||||
b-btn(variant='outline-secondary' @click='closeDialog()') Cancel
|
|
||||||
toast(ref='toast')
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import actions from '@/store/action-types'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'new-request',
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
showNewVisible: false,
|
|
||||||
form: {
|
|
||||||
requestText: ''
|
|
||||||
},
|
|
||||||
formLabelWidth: '120px'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted () {
|
|
||||||
this.$refs.toast.setOptions({ position: 'bottom right' })
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
closeDialog () {
|
|
||||||
this.form.requestText = ''
|
|
||||||
this.showNewVisible = false
|
|
||||||
},
|
|
||||||
focusRequestText (e) {
|
|
||||||
this.$refs.toFocus.focus()
|
|
||||||
},
|
|
||||||
openDialog () {
|
|
||||||
this.showNewVisible = true
|
|
||||||
},
|
|
||||||
trimText () {
|
|
||||||
this.form.requestText = this.form.requestText.trim()
|
|
||||||
},
|
|
||||||
async saveRequest () {
|
|
||||||
await this.$store.dispatch(actions.ADD_REQUEST, {
|
|
||||||
progress: this.$Progress,
|
|
||||||
requestText: this.form.requestText
|
|
||||||
})
|
|
||||||
this.$refs.toast.showToast('New prayer request added', { theme: 'success' })
|
|
||||||
this.closeDialog()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
118
src/app/src/components/request/NotesEdit.vue
Normal file
118
src/app/src/components/request/NotesEdit.vue
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
md-dialog(:md-active.sync='notesVisible').mpj-note-dialog
|
||||||
|
md-dialog-title Add Notes to Prayer Request
|
||||||
|
md-content.mpj-dialog-content
|
||||||
|
md-field
|
||||||
|
label Notes
|
||||||
|
md-textarea(v-model='form.notes'
|
||||||
|
md-autogrow
|
||||||
|
@blur='trimText()')
|
||||||
|
md-dialog-actions
|
||||||
|
md-button(@click='saveNotes()').md-primary #[md-icon save] Save
|
||||||
|
md-button(@click='closeDialog()') #[md-icon undo] Cancel
|
||||||
|
.mpj-dialog-content
|
||||||
|
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
|
||||||
|
hr
|
||||||
|
md-button(@click='loadNotes()') #[md-icon cloud_download] Load Prior Notes
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import api from '@/api'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'notes-edit',
|
||||||
|
inject: [
|
||||||
|
'journalEvents',
|
||||||
|
'messages',
|
||||||
|
'progress'
|
||||||
|
],
|
||||||
|
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.journalEvents.$on('notes', this.openDialog)
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
closeDialog () {
|
||||||
|
this.form.requestId = ''
|
||||||
|
this.form.notes = ''
|
||||||
|
this.priorNotes = []
|
||||||
|
this.priorNotesLoaded = false
|
||||||
|
this.notesVisible = false
|
||||||
|
},
|
||||||
|
async loadNotes () {
|
||||||
|
this.progress.$emit('show', 'indeterminate')
|
||||||
|
try {
|
||||||
|
const notes = await api.getNotes(this.form.requestId)
|
||||||
|
this.priorNotes = notes.data
|
||||||
|
this.progress.$emit('done')
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
this.progress.$emit('done')
|
||||||
|
} finally {
|
||||||
|
this.priorNotesLoaded = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
openDialog (request) {
|
||||||
|
this.form.requestId = request.requestId
|
||||||
|
this.notesVisible = true
|
||||||
|
},
|
||||||
|
async saveNotes () {
|
||||||
|
this.progress.$emit('show', 'indeterminate')
|
||||||
|
try {
|
||||||
|
await api.addNote(this.form.requestId, this.form.notes)
|
||||||
|
this.progress.$emit('done')
|
||||||
|
this.messages.$emit('info', 'Added notes')
|
||||||
|
this.closeDialog()
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e)
|
||||||
|
this.progress.$emit('done')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
trimText () {
|
||||||
|
this.form.notes = this.form.notes.trim()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="sass">
|
||||||
|
.mpj-note-dialog
|
||||||
|
width: 40rem
|
||||||
|
padding-bottom: 1.5rem
|
||||||
|
@media screen and (max-width: 40rem)
|
||||||
|
@media screen and (max-width: 20rem)
|
||||||
|
.mpj-note-dialog
|
||||||
|
width: 100%
|
||||||
|
.mpj-note-dialog
|
||||||
|
width: 20rem
|
||||||
|
.mpj-note-list p
|
||||||
|
border-top: dotted 1px lightgray
|
||||||
|
</style>
|
||||||
78
src/app/src/components/request/RequestCard.vue
Normal file
78
src/app/src/components/request/RequestCard.vue
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
md-card(v-if='shouldDisplay'
|
||||||
|
md-with-hover).mpj-request-card
|
||||||
|
md-card-actions(md-alignment='space-between')
|
||||||
|
md-button(@click='markPrayed()').md-icon-button.md-raised.md-primary
|
||||||
|
md-icon done
|
||||||
|
md-tooltip(md-direction='top'
|
||||||
|
md-delay=1000) Mark as Prayed
|
||||||
|
span
|
||||||
|
md-button(@click.stop='showEdit()').md-icon-button.md-raised
|
||||||
|
md-icon edit
|
||||||
|
md-tooltip(md-direction='top'
|
||||||
|
md-delay=1000) Edit Request
|
||||||
|
md-button(@click.stop='showNotes()').md-icon-button.md-raised
|
||||||
|
md-icon comment
|
||||||
|
md-tooltip(md-direction='top'
|
||||||
|
md-delay=1000) Add Notes
|
||||||
|
md-button(@click.stop='snooze()').md-icon-button.md-raised
|
||||||
|
md-icon schedule
|
||||||
|
md-tooltip(md-direction='top'
|
||||||
|
md-delay=1000) Snooze Request
|
||||||
|
md-card-content
|
||||||
|
p.mpj-request-text {{ request.text }}
|
||||||
|
p.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',
|
||||||
|
inject: [
|
||||||
|
'journalEvents',
|
||||||
|
'messages',
|
||||||
|
'progress'
|
||||||
|
],
|
||||||
|
props: {
|
||||||
|
request: { 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.messages.$emit('info', 'Request marked as prayed')
|
||||||
|
},
|
||||||
|
showEdit () {
|
||||||
|
this.$router.push({ name: 'EditRequest', params: { id: this.request.requestId } })
|
||||||
|
},
|
||||||
|
showNotes () {
|
||||||
|
this.journalEvents.$emit('notes', this.request)
|
||||||
|
},
|
||||||
|
snooze () {
|
||||||
|
this.journalEvents.$emit('snooze', this.request.requestId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="sass">
|
||||||
|
.mpj-request-card
|
||||||
|
width: 20rem
|
||||||
|
margin-bottom: 1rem
|
||||||
|
@media screen and (max-width: 20rem)
|
||||||
|
.mpj-request-card
|
||||||
|
width: 100%
|
||||||
|
</style>
|
||||||
40
src/app/src/components/request/RequestList.vue
Normal file
40
src/app/src/components/request/RequestList.vue
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
md-table(md-card)
|
||||||
|
md-table-toolbar
|
||||||
|
h1.md-title {{ title }}
|
||||||
|
md-table-row
|
||||||
|
md-table-head Actions
|
||||||
|
md-table-head Request
|
||||||
|
request-list-item(v-for='req in requests'
|
||||||
|
:key='req.requestId'
|
||||||
|
:request='req')
|
||||||
|
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import RequestListItem from '@/components/request/RequestListItem'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'request-list',
|
||||||
|
components: { RequestListItem },
|
||||||
|
props: {
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
requests: {
|
||||||
|
type: Array,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return { }
|
||||||
|
},
|
||||||
|
created () {
|
||||||
|
this.$on('requestUnsnoozed', this.$parent.$emit('requestUnsnoozed'))
|
||||||
|
this.$on('requestNowShown', this.$parent.$emit('requestNowShown'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -1,21 +1,31 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
div
|
md-table-row
|
||||||
b-card-group.w-100(deck)
|
md-table-cell.mpj-action-cell.mpj-valign-top
|
||||||
b-card(v-for='(request, idx) in row' border-variant='dark' no-body)
|
md-button(@click='viewFull').md-icon-button.md-raised
|
||||||
b-card-body.p-0
|
md-icon description
|
||||||
p.card-text.mpj-request-text.mb-1.px-3.pt-3
|
md-tooltip(md-direction='top'
|
||||||
| {{ request.text }}
|
md-delay=250) View Full Request
|
||||||
p.card-text.p-0.pr-1.text-right: small.text-muted: em
|
template(v-if='!isAnswered')
|
||||||
= '(last activity '
|
md-button(@click='editRequest').md-icon-button.md-raised
|
||||||
date-from-now(:value='request.asOf')
|
md-icon edit
|
||||||
| )
|
md-tooltip(md-direction='top'
|
||||||
b-card-footer.text-center.py-1.
|
md-delay=250) Edit Request
|
||||||
#[b-btn(@click='markPrayed(idx)' variant='outline-primary' title='Pray' size='sm'): icon(name='check')]
|
template(v-if='isSnoozed')
|
||||||
#[b-btn(@click.stop='showEdit(request)' variant='outline-secondary' title='Edit' size='sm'): icon(name='pencil')]
|
md-button(@click='cancelSnooze()').md-icon-button.md-raised
|
||||||
#[b-btn(disabled variant='outline-secondary' title='Add Notes' size='sm'): icon(name='file-text-o')]
|
md-icon restore
|
||||||
#[b-btn(@click.stop='showFull(idx)' variant='outline-secondary' title='View Full Request' size='sm'): icon(name='search')]
|
md-tooltip(md-direction='top'
|
||||||
b-card(v-for='it in 3 - row.length')
|
md-delay=250) Cancel Snooze
|
||||||
br
|
template(v-if='isPending')
|
||||||
|
md-button(@click='showNow()').md-icon-button.md-raised
|
||||||
|
md-icon restore
|
||||||
|
md-tooltip(md-direction='top'
|
||||||
|
md-delay=250) Show Now
|
||||||
|
md-table-cell.mpj-valign-top
|
||||||
|
p.mpj-request-text {{ request.text }}
|
||||||
|
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 appears next #[date-from-now(:value='request.showAfter')]
|
||||||
|
small(v-if='isAnswered').mpj-muted-text: em Answered #[date-from-now(:value='request.asOf')]
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -25,27 +35,61 @@ import actions from '@/store/action-types'
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'request-list-item',
|
name: 'request-list-item',
|
||||||
|
inject: [
|
||||||
|
'messages',
|
||||||
|
'progress'
|
||||||
|
],
|
||||||
props: {
|
props: {
|
||||||
row: { required: true },
|
request: { required: true }
|
||||||
toast: { required: true },
|
},
|
||||||
events: { 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: {
|
methods: {
|
||||||
async markPrayed (idx) {
|
async cancelSnooze () {
|
||||||
await this.$store.dispatch(actions.UPDATE_REQUEST, {
|
await this.$store.dispatch(actions.SNOOZE_REQUEST, {
|
||||||
progress: this.$Progress,
|
progress: this.progress,
|
||||||
requestId: this.row[idx].requestId,
|
requestId: this.request.requestId,
|
||||||
status: 'Prayed',
|
until: 0
|
||||||
updateText: ''
|
|
||||||
})
|
})
|
||||||
this.toast.showToast('Request marked as prayed', { theme: 'success' })
|
this.messages.$emit('info', 'Request un-snoozed')
|
||||||
|
this.$parent.$emit('requestUnsnoozed')
|
||||||
},
|
},
|
||||||
showEdit (request) {
|
editRequest () {
|
||||||
this.events.$emit('edit', request)
|
this.$router.push({ name: 'EditRequest', params: { id: this.request.requestId } })
|
||||||
},
|
},
|
||||||
showFull (idx) {
|
async showNow () {
|
||||||
this.events.$emit('full', this.row[idx].requestId)
|
await this.$store.dispatch(actions.SHOW_REQUEST_NOW, {
|
||||||
|
progress: this.progress,
|
||||||
|
requestId: this.request.requestId,
|
||||||
|
showAfter: 0
|
||||||
|
})
|
||||||
|
this.messages.$emit('info', 'Recurrence skipped; request now shows in journal')
|
||||||
|
this.$parent.$emit('requestNowShown')
|
||||||
|
},
|
||||||
|
viewFull () {
|
||||||
|
this.$router.push({ name: 'FullRequest', params: { id: this.request.requestId } })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style lang="sass">
|
||||||
|
.mpj-action-cell
|
||||||
|
width: 1%
|
||||||
|
white-space: nowrap
|
||||||
|
</style>
|
||||||
|
|||||||
69
src/app/src/components/request/SnoozeRequest.vue
Normal file
69
src/app/src/components/request/SnoozeRequest.vue
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
md-dialog(:md-active.sync='snoozeVisible').mpj-skinny
|
||||||
|
md-dialog-title Snooze Prayer Request
|
||||||
|
md-content.mpj-dialog-content
|
||||||
|
span.mpj-text-muted Until
|
||||||
|
md-datepicker(v-model='form.snoozedUntil'
|
||||||
|
:md-disabled-dates='datesInPast'
|
||||||
|
md-immediately)
|
||||||
|
md-dialog-actions
|
||||||
|
md-button(:disabled='!isValid'
|
||||||
|
@click='snoozeRequest()').md-primary #[md-icon snooze] Snooze
|
||||||
|
md-button(@click='closeDialog()') #[md-icon undo] Cancel
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import actions from '@/store/action-types'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'snooze-request',
|
||||||
|
inject: [
|
||||||
|
'journalEvents',
|
||||||
|
'messages',
|
||||||
|
'progress'
|
||||||
|
],
|
||||||
|
props: {
|
||||||
|
events: { required: true }
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
snoozeVisible: false,
|
||||||
|
datesInPast: date => date < new Date(),
|
||||||
|
form: {
|
||||||
|
requestId: '',
|
||||||
|
snoozedUntil: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created () {
|
||||||
|
this.journalEvents.$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.messages.$emit('info', `Request snoozed until ${this.form.snoozedUntil}`)
|
||||||
|
this.closeDialog()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
60
src/app/src/components/request/SnoozedRequests.vue
Normal file
60
src/app/src/components/request/SnoozedRequests.vue
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
article.mpj-main-content(role='main')
|
||||||
|
page-title(title='Snoozed Requests'
|
||||||
|
hide-on-page=true)
|
||||||
|
template(v-if='loaded')
|
||||||
|
md-empty-state(v-if='requests.length === 0'
|
||||||
|
md-icon='sentiment_dissatisfied'
|
||||||
|
md-label='No Snoozed Requests'
|
||||||
|
md-description='Your prayer journal has no snoozed requests')
|
||||||
|
md-button(to='/journal').md-primary.md-raised Return to your journal
|
||||||
|
request-list(v-if='requests.length !== 0'
|
||||||
|
title='Snoozed Requests'
|
||||||
|
:requests='requests')
|
||||||
|
p(v-else) Loading journal...
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import { mapState } from 'vuex'
|
||||||
|
|
||||||
|
import actions from '@/store/action-types'
|
||||||
|
|
||||||
|
import RequestList from '@/components/request/RequestList'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'snoozed-requests',
|
||||||
|
inject: ['progress'],
|
||||||
|
components: {
|
||||||
|
RequestList
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
requests: [],
|
||||||
|
loaded: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
...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,5 +1,5 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
article
|
article.mpj-main-content(role='main')
|
||||||
pageTitle(title='Logging On')
|
pageTitle(title='Logging On')
|
||||||
p Logging you on...
|
p Logging you on...
|
||||||
</template>
|
</template>
|
||||||
@@ -7,14 +7,17 @@ article
|
|||||||
<script>
|
<script>
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
import AuthService from '@/auth/AuthService'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'log-on',
|
name: 'log-on',
|
||||||
created () {
|
inject: ['progress'],
|
||||||
this.$Progress.start()
|
async created () {
|
||||||
new AuthService().handleAuthentication(this.$store, this.$router)
|
this.progress.$emit('show', 'indeterminate')
|
||||||
// Auth service redirects to dashboard, which restarts the progress bar
|
await this.$auth.handleAuthentication(this.$store)
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
handleLoginEvent (data) {
|
||||||
|
this.$router.push(data.state.target || '/journal')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,52 +1,64 @@
|
|||||||
// The Vue build version to load with the `import` command
|
/* eslint-disable */
|
||||||
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
|
|
||||||
|
// Vue packages and components
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import BootstrapVue from 'bootstrap-vue'
|
import { MdApp,
|
||||||
import Icon from 'vue-awesome/components/Icon'
|
MdButton,
|
||||||
import VueProgressBar from 'vue-progressbar'
|
MdCard,
|
||||||
import VueToast from 'vue-toast'
|
MdContent,
|
||||||
|
MdDatepicker,
|
||||||
import 'bootstrap-vue/dist/bootstrap-vue.css'
|
MdDialog,
|
||||||
import 'bootstrap/dist/css/bootstrap.css'
|
MdEmptyState,
|
||||||
import 'vue-toast/dist/vue-toast.min.css'
|
MdField,
|
||||||
|
MdIcon,
|
||||||
// Only import the icons we need; the whole set is ~500K!
|
MdLayout,
|
||||||
import 'vue-awesome/icons/check'
|
MdProgress,
|
||||||
import 'vue-awesome/icons/file-text-o'
|
MdRadio,
|
||||||
import 'vue-awesome/icons/pencil'
|
MdSnackbar,
|
||||||
import 'vue-awesome/icons/plus'
|
MdTable,
|
||||||
import 'vue-awesome/icons/search'
|
MdTabs,
|
||||||
|
MdToolbar,
|
||||||
|
MdTooltip } from 'vue-material/dist/components'
|
||||||
|
|
||||||
|
// myPrayerJournal components
|
||||||
import App from './App'
|
import App from './App'
|
||||||
import router from './router'
|
import router from './router'
|
||||||
import store from './store'
|
import store from './store'
|
||||||
import DateFromNow from './components/common/DateFromNow'
|
import DateFromNow from './components/common/DateFromNow'
|
||||||
import PageTitle from './components/common/PageTitle'
|
import PageTitle from './components/common/PageTitle'
|
||||||
|
import AuthPlugin from './plugins/auth'
|
||||||
|
|
||||||
|
/* eslint-enable */
|
||||||
|
|
||||||
|
// Styles
|
||||||
|
import 'vue-material/dist/vue-material.min.css'
|
||||||
|
import 'vue-material/dist/theme/default.css'
|
||||||
|
|
||||||
Vue.config.productionTip = false
|
Vue.config.productionTip = false
|
||||||
|
|
||||||
Vue.use(BootstrapVue)
|
Vue.use(MdApp)
|
||||||
Vue.use(VueProgressBar, {
|
Vue.use(MdButton)
|
||||||
color: 'yellow',
|
Vue.use(MdCard)
|
||||||
failedColor: 'red',
|
Vue.use(MdContent)
|
||||||
height: '5px',
|
Vue.use(MdDatepicker)
|
||||||
transition: {
|
Vue.use(MdDialog)
|
||||||
speed: '0.2s',
|
Vue.use(MdEmptyState)
|
||||||
opacity: '0.6s',
|
Vue.use(MdField)
|
||||||
termination: 1000
|
Vue.use(MdIcon)
|
||||||
}
|
Vue.use(MdLayout)
|
||||||
})
|
Vue.use(MdProgress)
|
||||||
|
Vue.use(MdRadio)
|
||||||
Vue.component('icon', Icon)
|
Vue.use(MdSnackbar)
|
||||||
|
Vue.use(MdTable)
|
||||||
|
Vue.use(MdTabs)
|
||||||
|
Vue.use(MdToolbar)
|
||||||
|
Vue.use(MdTooltip)
|
||||||
|
Vue.use(AuthPlugin)
|
||||||
Vue.component('date-from-now', DateFromNow)
|
Vue.component('date-from-now', DateFromNow)
|
||||||
Vue.component('page-title', PageTitle)
|
Vue.component('page-title', PageTitle)
|
||||||
Vue.component('toast', VueToast)
|
|
||||||
|
|
||||||
/* eslint-disable no-new */
|
|
||||||
new Vue({
|
new Vue({
|
||||||
el: '#app',
|
|
||||||
router,
|
router,
|
||||||
store,
|
store,
|
||||||
template: '<App/>',
|
render: h => h(App)
|
||||||
components: { App }
|
}).$mount('#app')
|
||||||
})
|
|
||||||
|
|||||||
22
src/app/src/plugins/auth.js
Normal file
22
src/app/src/plugins/auth.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
import authService from '../auth/AuthService'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
install (Vue) {
|
||||||
|
Vue.prototype.$auth = authService
|
||||||
|
|
||||||
|
Vue.mixin({
|
||||||
|
created () {
|
||||||
|
if (this.handleLoginEvent) {
|
||||||
|
authService.addListener('loginEvent', this.handleLoginEvent)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
destroyed () {
|
||||||
|
if (this.handleLoginEvent) {
|
||||||
|
authService.removeListener('loginEvent', this.handleLoginEvent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
83
src/app/src/router.js
Normal file
83
src/app/src/router.js
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
/* eslint-disable */
|
||||||
|
import Vue from 'vue'
|
||||||
|
import Router from 'vue-router'
|
||||||
|
|
||||||
|
import auth from './auth/AuthService'
|
||||||
|
import Home from '@/components/Home'
|
||||||
|
/* eslint-enable */
|
||||||
|
|
||||||
|
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 }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
beforeEach (to, from, next) {
|
||||||
|
if (to.path === '/' || to.path === '/user/log-on' || auth.isAuthenticated()) {
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
auth.login({ target: to.path })
|
||||||
|
},
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
name: 'Home',
|
||||||
|
component: Home
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/journal',
|
||||||
|
name: 'Journal',
|
||||||
|
component: () => import('@/components/Journal')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/legal/privacy-policy',
|
||||||
|
name: 'PrivacyPolicy',
|
||||||
|
component: () => import('@/components/legal/PrivacyPolicy')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/legal/terms-of-service',
|
||||||
|
name: 'TermsOfService',
|
||||||
|
component: () => import('@/components/legal/TermsOfService')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/request/:id/edit',
|
||||||
|
name: 'EditRequest',
|
||||||
|
component: () => import('@/components/request/EditRequest'),
|
||||||
|
props: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/request/:id/full',
|
||||||
|
name: 'FullRequest',
|
||||||
|
component: () => import('@/components/request/FullRequest'),
|
||||||
|
props: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/requests/active',
|
||||||
|
name: 'ActiveRequests',
|
||||||
|
component: () => import('@/components/request/ActiveRequests')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/requests/answered',
|
||||||
|
name: 'AnsweredRequests',
|
||||||
|
component: () => import('@/components/request/AnsweredRequests')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/requests/snoozed',
|
||||||
|
name: 'SnoozedRequests',
|
||||||
|
component: () => import('@/components/request/SnoozedRequests')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/user/log-on',
|
||||||
|
name: 'LogOn',
|
||||||
|
component: () => import('@/components/user/LogOn')
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import Router from 'vue-router'
|
|
||||||
|
|
||||||
import Answered from '@/components/Answered'
|
|
||||||
import Home from '@/components/Home'
|
|
||||||
import Journal from '@/components/Journal'
|
|
||||||
import LogOn from '@/components/user/LogOn'
|
|
||||||
|
|
||||||
Vue.use(Router)
|
|
||||||
|
|
||||||
export default new Router({
|
|
||||||
mode: 'history',
|
|
||||||
routes: [
|
|
||||||
{ path: '/', name: 'Home', component: Home },
|
|
||||||
{ path: '/answered', name: 'Answered', component: Answered },
|
|
||||||
{ path: '/journal', name: 'Journal', component: Journal },
|
|
||||||
{ path: '/user/log-on', name: 'LogOn', component: LogOn }
|
|
||||||
]
|
|
||||||
})
|
|
||||||
@@ -3,8 +3,14 @@
|
|||||||
export default {
|
export default {
|
||||||
/** Action to add a prayer request (pass request text) */
|
/** Action to add a prayer request (pass request text) */
|
||||||
ADD_REQUEST: 'add-request',
|
ADD_REQUEST: 'add-request',
|
||||||
|
/** Action to check if a user is authenticated, refreshing the session first if it exists */
|
||||||
|
CHECK_AUTHENTICATION: 'check-authentication',
|
||||||
/** Action to load the user's prayer journal */
|
/** Action to load the user's prayer journal */
|
||||||
LOAD_JOURNAL: 'load-journal',
|
LOAD_JOURNAL: 'load-journal',
|
||||||
/** Action to update a request */
|
/** Action to update a request */
|
||||||
UPDATE_REQUEST: 'update-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,45 +1,71 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
/* eslint-disable no-multi-spaces */
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
|
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
import AuthService from '@/auth/AuthService'
|
import auth from '@/auth/AuthService'
|
||||||
|
|
||||||
import mutations from './mutation-types'
|
import mutations from './mutation-types'
|
||||||
import actions from './action-types'
|
import actions from './action-types'
|
||||||
|
/* eslint-enable no-multi-spaces */
|
||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
|
||||||
this.auth0 = new AuthService()
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
const logError = function (error) {
|
const logError = function (error) {
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
// The request was made and the server responded with a status code
|
// The request was made and the server responded with a status code
|
||||||
// that falls out of the range of 2xx
|
// that falls out of the range of 2xx
|
||||||
console.log(error.response.data)
|
console.error(error.response.data)
|
||||||
console.log(error.response.status)
|
console.error(error.response.status)
|
||||||
console.log(error.response.headers)
|
console.error(error.response.headers)
|
||||||
} else if (error.request) {
|
} else if (error.request) {
|
||||||
// The request was made but no response was received
|
// The request was made but no response was received
|
||||||
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
||||||
// http.ClientRequest in node.js
|
// http.ClientRequest in node.js
|
||||||
console.log(error.request)
|
console.error(error.request)
|
||||||
} else {
|
} else {
|
||||||
// Something happened in setting up the request that triggered an Error
|
// Something happened in setting up the request that triggered an Error
|
||||||
console.log('Error', error.message)
|
console.error('Error', error.message)
|
||||||
}
|
}
|
||||||
console.log(error.config)
|
console.error(`config: ${error.config}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the "Bearer" authorization header with the current access token
|
||||||
|
*/
|
||||||
|
const setBearer = async function () {
|
||||||
|
try {
|
||||||
|
await auth.getAccessToken()
|
||||||
|
api.setBearer(auth.session.id.token)
|
||||||
|
} catch (err) {
|
||||||
|
if (err === 'Not logged in') {
|
||||||
|
console.warn('API request attempted when user was not logged in')
|
||||||
|
} else {
|
||||||
|
console.error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* eslint-enable no-console */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the sort value for a prayer request
|
||||||
|
* @param x The prayer request
|
||||||
|
*/
|
||||||
|
const sortValue = x => x.showAfter === 0 ? x.asOf : x.showAfter
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sort journal requests either by asOf or showAfter
|
||||||
|
*/
|
||||||
|
const journalSort = (a, b) => sortValue(a) - sortValue(b)
|
||||||
|
|
||||||
export default new Vuex.Store({
|
export default new Vuex.Store({
|
||||||
state: {
|
state: {
|
||||||
user: JSON.parse(localStorage.getItem('user_profile') || '{}'),
|
user: auth.session.profile,
|
||||||
isAuthenticated: (() => {
|
isAuthenticated: auth.isAuthenticated(),
|
||||||
if (this.auth0.isAuthenticated()) {
|
journal: [],
|
||||||
api.setBearer(localStorage.getItem('id_token'))
|
|
||||||
}
|
|
||||||
return this.auth0.isAuthenticated()
|
|
||||||
})(),
|
|
||||||
journal: {},
|
|
||||||
isLoadingJournal: false
|
isLoadingJournal: false
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
@@ -47,7 +73,7 @@ export default new Vuex.Store({
|
|||||||
state.isLoadingJournal = flag
|
state.isLoadingJournal = flag
|
||||||
},
|
},
|
||||||
[mutations.LOADED_JOURNAL] (state, journal) {
|
[mutations.LOADED_JOURNAL] (state, journal) {
|
||||||
state.journal = journal
|
state.journal = journal.sort(journalSort)
|
||||||
},
|
},
|
||||||
[mutations.REQUEST_ADDED] (state, newRequest) {
|
[mutations.REQUEST_ADDED] (state, newRequest) {
|
||||||
state.journal.push(newRequest)
|
state.journal.push(newRequest)
|
||||||
@@ -57,56 +83,101 @@ export default new Vuex.Store({
|
|||||||
if (request.lastStatus !== 'Answered') jrnl.push(request)
|
if (request.lastStatus !== 'Answered') jrnl.push(request)
|
||||||
state.journal = jrnl
|
state.journal = jrnl
|
||||||
},
|
},
|
||||||
|
[mutations.SET_AUTHENTICATION] (state, value) {
|
||||||
|
state.isAuthenticated = value
|
||||||
|
},
|
||||||
[mutations.USER_LOGGED_OFF] (state) {
|
[mutations.USER_LOGGED_OFF] (state) {
|
||||||
state.user = {}
|
state.user = {}
|
||||||
api.removeBearer()
|
api.removeBearer()
|
||||||
state.isAuthenticated = false
|
state.isAuthenticated = false
|
||||||
},
|
},
|
||||||
[mutations.USER_LOGGED_ON] (state, user) {
|
[mutations.USER_LOGGED_ON] (state, user) {
|
||||||
localStorage.setItem('user_profile', JSON.stringify(user))
|
|
||||||
state.user = user
|
state.user = user
|
||||||
api.setBearer(localStorage.getItem('id_token'))
|
|
||||||
state.isAuthenticated = true
|
state.isAuthenticated = true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async [actions.ADD_REQUEST] ({ commit }, { progress, requestText }) {
|
async [actions.ADD_REQUEST] ({ commit }, { progress, requestText, recurType, recurCount }) {
|
||||||
progress.start()
|
progress.$emit('show', 'indeterminate')
|
||||||
try {
|
try {
|
||||||
const newRequest = await api.addRequest(requestText)
|
await setBearer()
|
||||||
|
const newRequest = await api.addRequest(requestText, recurType, recurCount)
|
||||||
commit(mutations.REQUEST_ADDED, newRequest.data)
|
commit(mutations.REQUEST_ADDED, newRequest.data)
|
||||||
progress.finish()
|
progress.$emit('done')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logError(err)
|
logError(err)
|
||||||
progress.fail()
|
progress.$emit('done')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async [actions.CHECK_AUTHENTICATION] ({ commit }) {
|
||||||
|
try {
|
||||||
|
await auth.getAccessToken()
|
||||||
|
commit(mutations.SET_AUTHENTICATION, auth.isAuthenticated())
|
||||||
|
} catch (_) {
|
||||||
|
commit(mutations.SET_AUTHENTICATION, false)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async [actions.LOAD_JOURNAL] ({ commit }, progress) {
|
async [actions.LOAD_JOURNAL] ({ commit }, progress) {
|
||||||
commit(mutations.LOADED_JOURNAL, {})
|
commit(mutations.LOADED_JOURNAL, [])
|
||||||
progress.start()
|
progress.$emit('show', 'query')
|
||||||
commit(mutations.LOADING_JOURNAL, true)
|
commit(mutations.LOADING_JOURNAL, true)
|
||||||
api.setBearer(localStorage.getItem('id_token'))
|
await setBearer()
|
||||||
try {
|
try {
|
||||||
const jrnl = await api.journal()
|
const jrnl = await api.journal()
|
||||||
commit(mutations.LOADED_JOURNAL, jrnl.data)
|
commit(mutations.LOADED_JOURNAL, jrnl.data)
|
||||||
progress.finish()
|
progress.$emit('done')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logError(err)
|
logError(err)
|
||||||
progress.fail()
|
progress.$emit('done')
|
||||||
} finally {
|
} finally {
|
||||||
commit(mutations.LOADING_JOURNAL, false)
|
commit(mutations.LOADING_JOURNAL, false)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async [actions.UPDATE_REQUEST] ({ commit }, { progress, requestId, status, updateText }) {
|
async [actions.UPDATE_REQUEST] ({ commit, state }, { progress, requestId, status, updateText, recurType, recurCount }) {
|
||||||
progress.start()
|
progress.$emit('show', 'indeterminate')
|
||||||
try {
|
try {
|
||||||
await api.updateRequest({ requestId, status, updateText })
|
await setBearer()
|
||||||
|
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)
|
const request = await api.getRequest(requestId)
|
||||||
commit(mutations.REQUEST_UPDATED, request.data)
|
commit(mutations.REQUEST_UPDATED, request.data)
|
||||||
progress.finish()
|
progress.$emit('done')
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logError(err)
|
logError(err)
|
||||||
progress.fail()
|
progress.$emit('done')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async [actions.SHOW_REQUEST_NOW] ({ commit }, { progress, requestId, showAfter }) {
|
||||||
|
progress.$emit('show', 'indeterminate')
|
||||||
|
try {
|
||||||
|
await setBearer()
|
||||||
|
await api.showRequest(requestId, showAfter)
|
||||||
|
const request = await api.getRequest(requestId)
|
||||||
|
commit(mutations.REQUEST_UPDATED, request.data)
|
||||||
|
progress.$emit('done')
|
||||||
|
} catch (err) {
|
||||||
|
logError(err)
|
||||||
|
progress.$emit('done')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async [actions.SNOOZE_REQUEST] ({ commit }, { progress, requestId, until }) {
|
||||||
|
progress.$emit('show', 'indeterminate')
|
||||||
|
try {
|
||||||
|
await setBearer()
|
||||||
|
await api.snoozeRequest(requestId, until)
|
||||||
|
const request = await api.getRequest(requestId)
|
||||||
|
commit(mutations.REQUEST_UPDATED, request.data)
|
||||||
|
progress.$emit('done')
|
||||||
|
} catch (err) {
|
||||||
|
logError(err)
|
||||||
|
progress.$emit('done')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ export default {
|
|||||||
REQUEST_ADDED: 'request-added',
|
REQUEST_ADDED: 'request-added',
|
||||||
/** Mutation to replace a prayer request at the top of the current journal */
|
/** Mutation to replace a prayer request at the top of the current journal */
|
||||||
REQUEST_UPDATED: 'request-updated',
|
REQUEST_UPDATED: 'request-updated',
|
||||||
|
/** Mutation for setting the authentication state */
|
||||||
|
SET_AUTHENTICATION: 'set-authentication',
|
||||||
/** Mutation for logging a user off */
|
/** Mutation for logging a user off */
|
||||||
USER_LOGGED_OFF: 'user-logged-off',
|
USER_LOGGED_OFF: 'user-logged-off',
|
||||||
/** Mutation for logging a user on (pass user) */
|
/** Mutation for logging a user on (pass user) */
|
||||||
|
|||||||
22
src/app/static/silent.html
Normal file
22
src/app/static/silent.html
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<!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,26 +0,0 @@
|
|||||||
// A custom Nightwatch assertion.
|
|
||||||
// the name of the method is the filename.
|
|
||||||
// can be used in tests like this:
|
|
||||||
//
|
|
||||||
// browser.assert.elementCount(selector, count)
|
|
||||||
//
|
|
||||||
// for how to write custom assertions see
|
|
||||||
// http://nightwatchjs.org/guide#writing-custom-assertions
|
|
||||||
exports.assertion = function (selector, count) {
|
|
||||||
this.message = 'Testing if element <' + selector + '> has count: ' + count
|
|
||||||
this.expected = count
|
|
||||||
this.pass = function (val) {
|
|
||||||
return val === this.expected
|
|
||||||
}
|
|
||||||
this.value = function (res) {
|
|
||||||
return res.value
|
|
||||||
}
|
|
||||||
this.command = function (cb) {
|
|
||||||
var self = this
|
|
||||||
return this.api.execute(function (selector) {
|
|
||||||
return document.querySelectorAll(selector).length
|
|
||||||
}, [selector], function (res) {
|
|
||||||
cb.call(self, res)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
require('babel-register')
|
|
||||||
var config = require('../../config')
|
|
||||||
|
|
||||||
// http://nightwatchjs.org/gettingstarted#settings-file
|
|
||||||
module.exports = {
|
|
||||||
src_folders: ['test/e2e/specs'],
|
|
||||||
output_folder: 'test/e2e/reports',
|
|
||||||
custom_assertions_path: ['test/e2e/custom-assertions'],
|
|
||||||
|
|
||||||
selenium: {
|
|
||||||
start_process: true,
|
|
||||||
server_path: require('selenium-server').path,
|
|
||||||
host: '127.0.0.1',
|
|
||||||
port: 4444,
|
|
||||||
cli_args: {
|
|
||||||
'webdriver.chrome.driver': require('chromedriver').path
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
test_settings: {
|
|
||||||
default: {
|
|
||||||
selenium_port: 4444,
|
|
||||||
selenium_host: 'localhost',
|
|
||||||
silent: true,
|
|
||||||
globals: {
|
|
||||||
devServerURL: 'http://localhost:' + (process.env.PORT || config.dev.port)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
chrome: {
|
|
||||||
desiredCapabilities: {
|
|
||||||
browserName: 'chrome',
|
|
||||||
javascriptEnabled: true,
|
|
||||||
acceptSslCerts: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
firefox: {
|
|
||||||
desiredCapabilities: {
|
|
||||||
browserName: 'firefox',
|
|
||||||
javascriptEnabled: true,
|
|
||||||
acceptSslCerts: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
// 1. start the dev server using production config
|
|
||||||
process.env.NODE_ENV = 'testing'
|
|
||||||
var server = require('../../build/dev-server.js')
|
|
||||||
|
|
||||||
server.ready.then(() => {
|
|
||||||
// 2. run the nightwatch test suite against it
|
|
||||||
// to run in additional browsers:
|
|
||||||
// 1. add an entry in test/e2e/nightwatch.conf.json under "test_settings"
|
|
||||||
// 2. add it to the --env flag below
|
|
||||||
// or override the environment flag, for example: `npm run e2e -- --env chrome,firefox`
|
|
||||||
// For more information on Nightwatch's config file, see
|
|
||||||
// http://nightwatchjs.org/guide#settings-file
|
|
||||||
var opts = process.argv.slice(2)
|
|
||||||
if (opts.indexOf('--config') === -1) {
|
|
||||||
opts = opts.concat(['--config', 'test/e2e/nightwatch.conf.js'])
|
|
||||||
}
|
|
||||||
if (opts.indexOf('--env') === -1) {
|
|
||||||
opts = opts.concat(['--env', 'chrome'])
|
|
||||||
}
|
|
||||||
|
|
||||||
var spawn = require('cross-spawn')
|
|
||||||
var runner = spawn('./node_modules/.bin/nightwatch', opts, { stdio: 'inherit' })
|
|
||||||
|
|
||||||
runner.on('exit', function (code) {
|
|
||||||
server.close()
|
|
||||||
process.exit(code)
|
|
||||||
})
|
|
||||||
|
|
||||||
runner.on('error', function (err) {
|
|
||||||
server.close()
|
|
||||||
throw err
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
// For authoring Nightwatch tests, see
|
|
||||||
// http://nightwatchjs.org/guide#usage
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
'default e2e tests': function (browser) {
|
|
||||||
// automatically uses dev Server port from /config.index.js
|
|
||||||
// default: http://localhost:8080
|
|
||||||
// see nightwatch.conf.js
|
|
||||||
const devServer = browser.globals.devServerURL
|
|
||||||
|
|
||||||
browser
|
|
||||||
.url(devServer)
|
|
||||||
.waitForElementVisible('#app', 5000)
|
|
||||||
.assert.elementPresent('.hello')
|
|
||||||
.assert.containsText('h1', 'Welcome to Your Vue.js App')
|
|
||||||
.assert.elementCount('img', 1)
|
|
||||||
.end()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"env": {
|
|
||||||
"mocha": true
|
|
||||||
},
|
|
||||||
"globals": {
|
|
||||||
"expect": true,
|
|
||||||
"sinon": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
|
|
||||||
Vue.config.productionTip = false
|
|
||||||
|
|
||||||
// require all test files (files that ends with .spec.js)
|
|
||||||
const testsContext = require.context('./specs', true, /\.spec$/)
|
|
||||||
testsContext.keys().forEach(testsContext)
|
|
||||||
|
|
||||||
// require all src files except main.js for coverage.
|
|
||||||
// you can also change this to match only the subset of files that
|
|
||||||
// you want coverage for.
|
|
||||||
const srcContext = require.context('../../src', true, /^\.\/(?!main(\.js)?$)/)
|
|
||||||
srcContext.keys().forEach(srcContext)
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
// This is a karma config file. For more details see
|
|
||||||
// http://karma-runner.github.io/0.13/config/configuration-file.html
|
|
||||||
// we are also using it with karma-webpack
|
|
||||||
// https://github.com/webpack/karma-webpack
|
|
||||||
|
|
||||||
var webpackConfig = require('../../build/webpack.test.conf')
|
|
||||||
|
|
||||||
module.exports = function (config) {
|
|
||||||
config.set({
|
|
||||||
// to run in additional browsers:
|
|
||||||
// 1. install corresponding karma launcher
|
|
||||||
// http://karma-runner.github.io/0.13/config/browsers.html
|
|
||||||
// 2. add it to the `browsers` array below.
|
|
||||||
browsers: ['PhantomJS'],
|
|
||||||
frameworks: ['mocha', 'sinon-chai', 'phantomjs-shim'],
|
|
||||||
reporters: ['spec', 'coverage'],
|
|
||||||
files: ['./index.js'],
|
|
||||||
preprocessors: {
|
|
||||||
'./index.js': ['webpack', 'sourcemap']
|
|
||||||
},
|
|
||||||
webpack: webpackConfig,
|
|
||||||
webpackMiddleware: {
|
|
||||||
noInfo: true
|
|
||||||
},
|
|
||||||
coverageReporter: {
|
|
||||||
dir: './coverage',
|
|
||||||
reporters: [
|
|
||||||
{ type: 'lcov', subdir: '.' },
|
|
||||||
{ type: 'text-summary' }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
16
src/app/vue.config.js
Normal file
16
src/app/vue.config.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const webpack = require('webpack')
|
||||||
|
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
||||||
|
module.exports = {
|
||||||
|
outputDir: '../MyPrayerJournal.Api/wwwroot',
|
||||||
|
configureWebpack: {
|
||||||
|
plugins: [
|
||||||
|
// new BundleAnalyzerPlugin(),
|
||||||
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
|
||||||
|
],
|
||||||
|
optimization: {
|
||||||
|
splitChunks: {
|
||||||
|
chunks: 'all'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
10387
src/app/yarn.lock
10387
src/app/yarn.lock
File diff suppressed because it is too large
Load Diff
31
src/sql/16-recurrence.sql
Normal file
31
src/sql/16-recurrence.sql
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
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;
|
||||||
Reference in New Issue
Block a user