diff --git a/docs/index.md b/docs/index.md index 8dc436e..86f6a0e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -16,15 +16,19 @@ myPrayerJournal uses login services using Google or Microsoft accounts. The only ## Your Prayer Journal -Your current requests will be presented in three columns (or two or one, 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. +Your current requests will be presented in columns (usually three, but it could be more or less, depending on the size of your screen or device). Each request is in its own card, and the buttons at the top of each card apply to that request. The last line of each request also tells you how long it has been since anything has been done on that request. Any time you see something like "a few minutes ago," you can hover over that to see the actual date/time the action was taken. ## Adding a Request To add a request, click the "Add a New Request" button at the top of your journal. Then, enter the text of the request as you see fit; there is no right or wrong way, and you are the only person who will see the text you enter. When you save the request, it will go to the bottom of the list of requests. +## Setting Request Recurrence + +When you add or update a request, you can choose whether requests go to the bottom of the journal once they have been marked "Prayed" or whether they will reappear after a delay. You can set recurrence in terms of hours, days, or weeks, but it cannot be longer than 365 days. If you decide you want a request to reappear sooner, you can skip the current delay; click the "Active" menu link, find the request in the list (likely near the bottom), and click the "Show Now" button. + ## Praying for Requests -The first button for each request has a checkmark icon; clicking this button will mark the request as "Prayed" and move it to the bottom of the list. 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 @@ -32,22 +36,20 @@ The second button for each request has a pencil icon. This allows you to edit th ## Adding Notes -The third button for each request has an icon that looks like a piece of paper with writing; 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. - -## 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. +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 fifth 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. +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. -## Answered Requests +## Viewing a Request and Its History -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 at the bottom of each request, with the magnifying glass and the words "Show Full Request", link to a page that shows that request's complete history and notes, along with a few statistics about that request. The history and notes are 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. +myPrayerJournal tracks all of the actions related to a request; from the "Active" and "Answered" menu links (and "Snoozed", if it's showing), there is a "View Full Request" button. That page will show the current text of the request; how many times it has been marked as prayed; how long it has been an active request; and a log of all updates, prayers, and notes you have recorded. That log is listed from most recent to least recent; if you want to read it chronologically, just press the "End" key on your keyboard and read it from the bottom up. + +The "Active" link will show all requests that have not yet been marked answered, including snoozed and recurring requests. If requests are snoozed, or in a recurrence period off the journal, there will be a button where you can return the request to the list (either "Cancel Snooze" or "Show Now"). The "Answered" link shows all requests that have been marked answered. The "Snoozed" link just shows snoozed requests. ## Final Notes -- myPrayerJournal is currently in public beta. 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 browse the list of issues to see what has been done and what is still left to do. +- myPrayerJournal is nearing the end of its public beta, approaching its first official release. 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 browse the list of issues to see what has been done and what is still left to do. - Prayer requests and their history are securely backed up nightly along with other Bit Badger Solutions data. - Prayer changes things - most of all, the one doing the praying. I pray that this tool enables you to deepen and strengthen your prayer life. diff --git a/src/api/MyPrayerJournal.Api/Data.fs b/src/api/MyPrayerJournal.Api/Data.fs index fefb8de..3a2d948 100644 --- a/src/api/MyPrayerJournal.Api/Data.fs +++ b/src/api/MyPrayerJournal.Api/Data.fs @@ -88,7 +88,7 @@ module Entities = m.Property(fun e -> e.notes).IsRequired () |> ignore) |> ignore - // Request is the identifying record for a prayer request. + /// Request is the identifying record for a prayer request and [] Request = { /// The ID of the request requestId : RequestId @@ -96,8 +96,14 @@ module Entities = enteredOn : int64 /// The ID of the user to whom this request belongs ("sub" from the JWT) userId : string - /// The time that this request should reappear in the user's journal + /// The time at which this request should reappear in the user's journal by manual user choice snoozedUntil : int64 + /// The time at which this request should reappear in the user's journal by recurrence + showAfter : int64 + /// The type of recurrence for this request + recurType : string + /// How many of the recurrence intervals should occur between appearances in the journal + recurCount : int16 /// The history entries for this request history : ICollection /// The notes for this request @@ -110,6 +116,9 @@ module Entities = enteredOn = 0L userId = "" snoozedUntil = 0L + showAfter = 0L + recurType = "immediate" + recurCount = 0s history = List () notes = List () } @@ -123,6 +132,9 @@ module Entities = m.Property(fun e -> e.enteredOn).IsRequired () |> ignore m.Property(fun e -> e.userId).IsRequired () |> ignore m.Property(fun e -> e.snoozedUntil).IsRequired () |> ignore + m.Property(fun e -> e.showAfter).IsRequired () |> ignore + m.Property(fun e -> e.recurType).IsRequired() |> ignore + m.Property(fun e -> e.recurCount).IsRequired() |> ignore m.HasMany(fun e -> e.history :> IEnumerable) .WithOne() .HasForeignKey(fun e -> e.requestId :> obj) @@ -149,6 +161,12 @@ module Entities = lastStatus : string /// The time that this request should reappear in the user's journal snoozedUntil : int64 + /// The time after which this request should reappear in the user's journal by configured recurrence + showAfter : int64 + /// The type of recurrence for this request + recurType : string + /// How many of the recurrence intervals should occur between appearances in the journal + recurCount : int16 /// History entries for the request history : History list /// Note entries for the request @@ -227,7 +245,7 @@ type AppDbContext (opts : DbContextOptions) = .OrderBy(fun r -> r.asOf) /// Retrieve a request by its ID and user ID - member this.TryRequestById reqId userId : Task = + member this.TryRequestById reqId userId = task { let! req = this.Requests.AsNoTracking().FirstOrDefaultAsync(fun r -> r.requestId = reqId && r.userId = userId) return toOption req @@ -236,8 +254,7 @@ type AppDbContext (opts : DbContextOptions) = /// Retrieve notes for a request by its ID and user ID member this.NotesById reqId userId = task { - let! req = this.TryRequestById reqId userId - match req with + match! this.TryRequestById reqId userId with | Some _ -> return this.Notes.AsNoTracking().Where(fun n -> n.requestId = reqId) |> List.ofSeq | None -> return [] } @@ -250,34 +267,17 @@ type AppDbContext (opts : DbContextOptions) = } /// Retrieve a request, including its history and notes, by its ID and user ID - member this.TryCompleteRequestById requestId userId = + member this.TryFullRequestById requestId userId = task { - let! req = this.TryJournalById requestId userId - match req with - | Some r -> + match! this.TryJournalById requestId userId with + | Some req -> let! fullReq = this.Requests.AsNoTracking() .Include(fun r -> r.history) .Include(fun r -> r.notes) .FirstOrDefaultAsync(fun r -> r.requestId = requestId && r.userId = userId) match toOption fullReq with - | Some _ -> return Some { r with history = List.ofSeq fullReq.history; notes = List.ofSeq fullReq.notes } - | None -> return None - | None -> return None - } - - /// Retrieve a request, including its history, by its ID and user ID - member this.TryFullRequestById requestId userId = - task { - let! req = this.TryJournalById requestId userId - match req with - | Some r -> - let! fullReq = - this.Requests.AsNoTracking() - .Include(fun r -> r.history) - .FirstOrDefaultAsync(fun r -> r.requestId = requestId && r.userId = userId) - match toOption fullReq with - | Some _ -> return Some { r with history = List.ofSeq fullReq.history } + | Some _ -> return Some { req with history = List.ofSeq fullReq.history; notes = List.ofSeq fullReq.notes } | None -> return None | None -> return None } diff --git a/src/api/MyPrayerJournal.Api/Handlers.fs b/src/api/MyPrayerJournal.Api/Handlers.fs index cf41c4c..2991d81 100644 --- a/src/api/MyPrayerJournal.Api/Handlers.fs +++ b/src/api/MyPrayerJournal.Api/Handlers.fs @@ -6,6 +6,14 @@ open Giraffe open MyPrayerJournal open System +/// Handler to return Vue files +module Vue = + + /// The application index page + let app : HttpHandler = htmlFile "wwwroot/index.html" + + +/// Handlers for error conditions module Error = open Microsoft.Extensions.Logging @@ -18,12 +26,12 @@ module Error = /// 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 -> - [ "/answered"; "/journal"; "/snoozed"; "/user" ] + [ "/journal"; "/legal"; "/request"; "/user" ] |> List.filter ctx.Request.Path.Value.StartsWith |> List.length |> function | 0 -> (setStatusCode 404 >=> json ([ "error", "not found" ] |> dict)) next ctx - | _ -> htmlFile "wwwroot/index.html" next ctx + | _ -> Vue.app next ctx /// Handler helpers @@ -87,13 +95,33 @@ module Models = notes : string } + /// Recurrence update + [] + type Recurrence = + { /// The recurrence type + recurType : string + /// The recurrence cound + recurCount : int16 + } + /// A prayer request [] type Request = { /// The text of the request requestText : string + /// The recurrence type + recurType : string + /// The recurrence count + recurCount : int16 } + /// Reset the "showAfter" property on a request + [] + type Show = + { /// The time after which the request should appear + showAfter : int64 + } + /// The time until which a request should not appear in the journal [] type SnoozeUntil = @@ -119,6 +147,15 @@ module Request = open NCuid + /// Ticks per recurrence + let private recurrence = + [ "immediate", 0L + "hours", 3600000L + "days", 86400000L + "weeks", 604800000L + ] + |> Map.ofList + /// POST /api/request let add : HttpHandler = authorize @@ -130,10 +167,12 @@ module Request = let usrId = userId ctx let now = jsNow () { Request.empty with - requestId = reqId - userId = usrId - enteredOn = now - snoozedUntil = 0L + requestId = reqId + userId = usrId + enteredOn = now + showAfter = now + recurType = r.recurType + recurCount = r.recurCount } |> db.AddEntry { History.empty with @@ -144,9 +183,8 @@ module Request = } |> db.AddEntry let! _ = db.SaveChangesAsync () - let! req = db.TryJournalById reqId usrId - match req with - | Some rqst -> return! (setStatusCode 201 >=> json rqst) next ctx + match! db.TryJournalById reqId usrId with + | Some req -> return! (setStatusCode 201 >=> json req) next ctx | None -> return! Error.notFound next ctx } @@ -155,18 +193,22 @@ module Request = authorize >=> fun next ctx -> task { - let db = db ctx - let! req = db.TryRequestById reqId (userId ctx) - match req with - | Some _ -> + let db = db ctx + match! db.TryRequestById reqId (userId ctx) with + | Some req -> let! hist = ctx.BindJsonAsync () + let now = jsNow () { History.empty with requestId = reqId - asOf = jsNow () + asOf = now status = hist.status text = match hist.updateText with null | "" -> None | x -> Some x } |> db.AddEntry + match hist.status with + | "Prayed" -> + db.UpdateEntry { req with showAfter = now + (recurrence.[req.recurType] * int64 req.recurCount) } + | _ -> () let! _ = db.SaveChangesAsync () return! created next ctx | None -> return! Error.notFound next ctx @@ -177,15 +219,14 @@ module Request = authorize >=> fun next ctx -> task { - let db = db ctx - let! req = db.TryRequestById reqId (userId ctx) - match req with + let db = db ctx + match! db.TryRequestById reqId (userId ctx) with | Some _ -> let! notes = ctx.BindJsonAsync () { Note.empty with requestId = reqId - asOf = jsNow () - notes = notes.notes + asOf = jsNow () + notes = notes.notes } |> db.AddEntry let! _ = db.SaveChangesAsync () @@ -206,20 +247,8 @@ module Request = authorize >=> fun next ctx -> task { - let! req = (db ctx).TryJournalById reqId (userId ctx) - match req with - | Some r -> return! json r next ctx - | None -> return! Error.notFound next ctx - } - - /// GET /api/request/[req-id]/complete - let getComplete reqId : HttpHandler = - authorize - >=> fun next ctx -> - task { - let! req = (db ctx).TryCompleteRequestById reqId (userId ctx) - match req with - | Some r -> return! json r next ctx + match! (db ctx).TryJournalById reqId (userId ctx) with + | Some req -> return! json req next ctx | None -> return! Error.notFound next ctx } @@ -228,9 +257,8 @@ module Request = authorize >=> fun next ctx -> task { - let! req = (db ctx).TryFullRequestById reqId (userId ctx) - match req with - | Some r -> return! json r next ctx + match! (db ctx).TryFullRequestById reqId (userId ctx) with + | Some req -> return! json req next ctx | None -> return! Error.notFound next ctx } @@ -243,17 +271,48 @@ module Request = return! json notes next ctx } - /// POST /api/request/[req-id]/snooze - let snooze reqId : HttpHandler = + /// PATCH /api/request/[req-id]/show + let show reqId : HttpHandler = authorize >=> fun next ctx -> task { - let db = db ctx - let! req = db.TryRequestById reqId (userId ctx) - match req with - | Some r -> - let! until = ctx.BindJsonAsync () - { r with snoozedUntil = until.until } + let db = db ctx + match! db.TryRequestById reqId (userId ctx) with + | Some req -> + let! show = ctx.BindJsonAsync () + { req with showAfter = show.showAfter } + |> db.UpdateEntry + let! _ = db.SaveChangesAsync () + return! setStatusCode 204 next ctx + | None -> return! Error.notFound next ctx + } + + /// PATCH /api/request/[req-id]/snooze + let snooze reqId : HttpHandler = + authorize + >=> fun next ctx -> + task { + let db = db ctx + match! db.TryRequestById reqId (userId ctx) with + | Some req -> + let! until = ctx.BindJsonAsync () + { req with snoozedUntil = until.until; showAfter = until.until } + |> db.UpdateEntry + let! _ = db.SaveChangesAsync () + return! setStatusCode 204 next ctx + | None -> return! Error.notFound next ctx + } + + /// PATCH /api/request/[req-id]/recurrence + let updateRecurrence reqId : HttpHandler = + authorize + >=> fun next ctx -> + task { + let db = db ctx + match! db.TryRequestById reqId (userId ctx) with + | Some req -> + let! recur = ctx.BindJsonAsync () + { req with recurType = recur.recurType; recurCount = recur.recurCount } |> db.UpdateEntry let! _ = db.SaveChangesAsync () return! setStatusCode 204 next ctx diff --git a/src/api/MyPrayerJournal.Api/Program.fs b/src/api/MyPrayerJournal.Api/Program.fs index 9aa0ae7..2e21bd3 100644 --- a/src/api/MyPrayerJournal.Api/Program.fs +++ b/src/api/MyPrayerJournal.Api/Program.fs @@ -53,16 +53,22 @@ module Configure = /// Routes for the available URLs within myPrayerJournal let webApp = router Handlers.Error.notFound [ - route "/" (htmlFile "wwwroot/index.html") + route "/" Handlers.Vue.app subRoute "/api/" [ GET [ route "journal" Handlers.Journal.journal subRoute "request" [ - route "s/answered" Handlers.Request.answered - routef "/%s/complete" Handlers.Request.getComplete - routef "/%s/full" Handlers.Request.getFull - routef "/%s/notes" Handlers.Request.getNotes - routef "/%s" Handlers.Request.get + route "s/answered" Handlers.Request.answered + routef "/%s/full" Handlers.Request.getFull + routef "/%s/notes" Handlers.Request.getNotes + routef "/%s" Handlers.Request.get + ] + ] + PATCH [ + subRoute "request" [ + routef "/%s/recurrence" Handlers.Request.updateRecurrence + routef "/%s/show" Handlers.Request.show + routef "/%s/snooze" Handlers.Request.snooze ] ] POST [ @@ -70,7 +76,6 @@ module Configure = route "" Handlers.Request.add routef "/%s/history" Handlers.Request.addHistory routef "/%s/note" Handlers.Request.addNote - routef "/%s/snooze" Handlers.Request.snooze ] ] ] diff --git a/src/app/package.json b/src/app/package.json index 2cb414e..38d794d 100644 --- a/src/app/package.json +++ b/src/app/package.json @@ -17,14 +17,11 @@ "dependencies": { "auth0-js": "^9.7.3", "axios": "^0.18.0", - "bootstrap": "^4.1.3", - "bootstrap-vue": "^2.0.0-rc.11", - "moment": "^2.22.2", - "pug": "^2.0.3", - "vue": "^2.5.17", - "vue-awesome": "^2.3.3", - "vue-progressbar": "^0.7.5", - "vue-router": "^3.0.1", + "moment": "^2.18.1", + "pug": "^2.0.1", + "vue": "^2.5.15", + "vue-progressbar": "^0.7.3", + "vue-router": "^3.0.0", "vue-toast": "^3.1.0", "vuex": "^3.0.1" }, diff --git a/src/app/src/App.vue b/src/app/src/App.vue index c46f8b2..a7e6f02 100644 --- a/src/app/src/App.vue +++ b/src/app/src/App.vue @@ -1,25 +1,28 @@ diff --git a/src/app/src/components/Home.vue b/src/app/src/components/Home.vue index 39b9c8b..41a7e68 100644 --- a/src/app/src/components/Home.vue +++ b/src/app/src/components/Home.vue @@ -1,5 +1,5 @@