Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
16c3a9fd44 | ||
|
|
473359c645 | ||
|
|
334710065c | ||
|
|
ee9326d7a5 | ||
|
|
2c34650ceb | ||
|
|
9f1e258180 | ||
|
|
0c21e6c1c0 | ||
|
|
a6144f67ec | ||
|
|
e351fe5b56 | ||
|
|
d3aff4a110 | ||
|
|
c0dd6b5dd6 | ||
|
|
5bba499251 | ||
|
|
96f2f2f7e0 | ||
|
|
2bf3bc4865 | ||
|
|
95175d2c57 | ||
|
|
3f71d75a99 | ||
|
|
8becb8cea4 | ||
|
|
d1fd5f68e7 | ||
|
|
d0ea7cf3c6 | ||
|
|
05990d537a |
8
.gitignore
vendored
8
.gitignore
vendored
@@ -254,8 +254,10 @@ paket-files/
|
|||||||
|
|
||||||
# Compiled files / application
|
# Compiled files / application
|
||||||
src/api/build
|
src/api/build
|
||||||
src/public/index.html
|
src/api/MyPrayerJournal.Api/wwwroot/favicon.ico
|
||||||
src/public/static
|
src/api/MyPrayerJournal.Api/wwwroot/index.html
|
||||||
src/config.json
|
src/api/MyPrayerJournal.Api/wwwroot/css
|
||||||
|
src/api/MyPrayerJournal.Api/wwwroot/js
|
||||||
|
src/api/MyPrayerJournal.Api/appsettings.development.json
|
||||||
/build
|
/build
|
||||||
src/*.exe
|
src/*.exe
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
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")_.
|
||||||
|
|
||||||
myPrayerJournal was borne of out of a personal desire I (Daniel) 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.
|
||||||
|
|
||||||
## Futher Reading
|
## Futher Reading
|
||||||
|
|
||||||
The documentation for the site is at <https://danieljsummers.github.io/myPrayerJournal/>.
|
The documentation for the site is at <https://bit-badger.github.io/myPrayerJournal/>.
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
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")_.
|
||||||
|
|
||||||
myPrayerJournal was borne of out of a personal desire I (Daniel) 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.
|
||||||
|
|
||||||
## Finding the Site
|
## Finding the Site
|
||||||
|
|
||||||
@@ -16,15 +16,19 @@ 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 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
|
## 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
|
||||||
|
|
||||||
@@ -32,18 +36,20 @@ The second button for each request has a pencil icon. This allows you to edit th
|
|||||||
|
|
||||||
## Adding Notes
|
## 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.
|
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 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.
|
|
||||||
|
|
||||||
## Final Notes
|
## Final Notes
|
||||||
|
|
||||||
- myPrayerJournal is currently in public beta. If you encounter errors, please [file an issue on GitHub](https://github.com/danieljsummers/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.
|
- If you encounter errors, please [file an issue on GitHub](https://github.com/bit-badger/myPrayerJournal/issues) with as much detail as possible. You can also provide suggestions, or browse the list of currently open issues.
|
||||||
- Prayer requests and their history are securely backed up nightly along with other Bit Badger Solutions data.
|
- Prayer 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.
|
- 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.
|
||||||
|
|||||||
283
src/api/MyPrayerJournal.Api/Data.fs
Normal file
283
src/api/MyPrayerJournal.Api/Data.fs
Normal file
@@ -0,0 +1,283 @@
|
|||||||
|
namespace MyPrayerJournal
|
||||||
|
|
||||||
|
open FSharp.Control.Tasks.ContextInsensitive
|
||||||
|
open Microsoft.EntityFrameworkCore
|
||||||
|
|
||||||
|
/// Helpers for this file
|
||||||
|
[<AutoOpen>]
|
||||||
|
module private Helpers =
|
||||||
|
|
||||||
|
/// Convert any item to an option (Option.ofObj does not work for non-nullable types)
|
||||||
|
let toOption<'T> (x : 'T) = match box x with null -> None | _ -> Some x
|
||||||
|
|
||||||
|
|
||||||
|
/// Entities for use in the data model for myPrayerJournal
|
||||||
|
[<AutoOpen>]
|
||||||
|
module Entities =
|
||||||
|
|
||||||
|
open FSharp.EFCore.OptionConverter
|
||||||
|
open System.Collections.Generic
|
||||||
|
|
||||||
|
/// Type alias for a Collision-resistant Unique IDentifier
|
||||||
|
type Cuid = string
|
||||||
|
|
||||||
|
/// Request ID is a CUID
|
||||||
|
type RequestId = Cuid
|
||||||
|
|
||||||
|
/// User ID is a string (the "sub" part of the JWT)
|
||||||
|
type UserId = string
|
||||||
|
|
||||||
|
/// History is a record of action taken on a prayer request, including updates to its text
|
||||||
|
type [<CLIMutable; NoComparison; NoEquality>] History =
|
||||||
|
{ /// The ID of the request to which this history entry applies
|
||||||
|
requestId : RequestId
|
||||||
|
/// The time when this history entry was made
|
||||||
|
asOf : int64
|
||||||
|
/// The status for this history entry
|
||||||
|
status : string
|
||||||
|
/// The text of the update, if applicable
|
||||||
|
text : string option
|
||||||
|
}
|
||||||
|
with
|
||||||
|
/// An empty history entry
|
||||||
|
static member empty =
|
||||||
|
{ requestId = ""
|
||||||
|
asOf = 0L
|
||||||
|
status = ""
|
||||||
|
text = None
|
||||||
|
}
|
||||||
|
|
||||||
|
static member configureEF (mb : ModelBuilder) =
|
||||||
|
mb.Entity<History> (
|
||||||
|
fun m ->
|
||||||
|
m.ToTable "history" |> ignore
|
||||||
|
m.HasKey ("requestId", "asOf") |> ignore
|
||||||
|
m.Property(fun e -> e.requestId).IsRequired () |> ignore
|
||||||
|
m.Property(fun e -> e.asOf).IsRequired () |> ignore
|
||||||
|
m.Property(fun e -> e.status).IsRequired() |> ignore
|
||||||
|
m.Property(fun e -> e.text) |> ignore)
|
||||||
|
|> ignore
|
||||||
|
let typ = mb.Model.FindEntityType(typeof<History>)
|
||||||
|
let prop = typ.FindProperty("text")
|
||||||
|
mb.Model.FindEntityType(typeof<History>).FindProperty("text").SetValueConverter (OptionConverter<string> ())
|
||||||
|
|
||||||
|
/// Note is a note regarding a prayer request that does not result in an update to its text
|
||||||
|
and [<CLIMutable; NoComparison; NoEquality>] Note =
|
||||||
|
{ /// The ID of the request to which this note applies
|
||||||
|
requestId : RequestId
|
||||||
|
/// The time when this note was made
|
||||||
|
asOf : int64
|
||||||
|
/// The text of the notes
|
||||||
|
notes : string
|
||||||
|
}
|
||||||
|
with
|
||||||
|
/// An empty note
|
||||||
|
static member empty =
|
||||||
|
{ requestId = ""
|
||||||
|
asOf = 0L
|
||||||
|
notes = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
static member configureEF (mb : ModelBuilder) =
|
||||||
|
mb.Entity<Note> (
|
||||||
|
fun m ->
|
||||||
|
m.ToTable "note" |> ignore
|
||||||
|
m.HasKey ("requestId", "asOf") |> ignore
|
||||||
|
m.Property(fun e -> e.requestId).IsRequired () |> ignore
|
||||||
|
m.Property(fun e -> e.asOf).IsRequired () |> ignore
|
||||||
|
m.Property(fun e -> e.notes).IsRequired () |> ignore)
|
||||||
|
|> ignore
|
||||||
|
|
||||||
|
/// Request is the identifying record for a prayer request
|
||||||
|
and [<CLIMutable; NoComparison; NoEquality>] Request =
|
||||||
|
{ /// The ID of the request
|
||||||
|
requestId : RequestId
|
||||||
|
/// The time this request was initially entered
|
||||||
|
enteredOn : int64
|
||||||
|
/// The ID of the user to whom this request belongs ("sub" from the JWT)
|
||||||
|
userId : string
|
||||||
|
/// The time at which this request should reappear in the user's journal by manual user choice
|
||||||
|
snoozedUntil : int64
|
||||||
|
/// The time at which this request should reappear in the user's journal by recurrence
|
||||||
|
showAfter : int64
|
||||||
|
/// The type of recurrence for this request
|
||||||
|
recurType : string
|
||||||
|
/// How many of the recurrence intervals should occur between appearances in the journal
|
||||||
|
recurCount : int16
|
||||||
|
/// The history entries for this request
|
||||||
|
history : ICollection<History>
|
||||||
|
/// The notes for this request
|
||||||
|
notes : ICollection<Note>
|
||||||
|
}
|
||||||
|
with
|
||||||
|
/// An empty request
|
||||||
|
static member empty =
|
||||||
|
{ requestId = ""
|
||||||
|
enteredOn = 0L
|
||||||
|
userId = ""
|
||||||
|
snoozedUntil = 0L
|
||||||
|
showAfter = 0L
|
||||||
|
recurType = "immediate"
|
||||||
|
recurCount = 0s
|
||||||
|
history = List<History> ()
|
||||||
|
notes = List<Note> ()
|
||||||
|
}
|
||||||
|
|
||||||
|
static member configureEF (mb : ModelBuilder) =
|
||||||
|
mb.Entity<Request> (
|
||||||
|
fun m ->
|
||||||
|
m.ToTable "request" |> ignore
|
||||||
|
m.HasKey(fun e -> e.requestId :> obj) |> ignore
|
||||||
|
m.Property(fun e -> e.requestId).IsRequired () |> ignore
|
||||||
|
m.Property(fun e -> e.enteredOn).IsRequired () |> ignore
|
||||||
|
m.Property(fun e -> e.userId).IsRequired () |> ignore
|
||||||
|
m.Property(fun e -> e.snoozedUntil).IsRequired () |> ignore
|
||||||
|
m.Property(fun e -> e.showAfter).IsRequired () |> ignore
|
||||||
|
m.Property(fun e -> e.recurType).IsRequired() |> ignore
|
||||||
|
m.Property(fun e -> e.recurCount).IsRequired() |> ignore
|
||||||
|
m.HasMany(fun e -> e.history :> IEnumerable<History>)
|
||||||
|
.WithOne()
|
||||||
|
.HasForeignKey(fun e -> e.requestId :> obj)
|
||||||
|
|> ignore
|
||||||
|
m.HasMany(fun e -> e.notes :> IEnumerable<Note>)
|
||||||
|
.WithOne()
|
||||||
|
.HasForeignKey(fun e -> e.requestId :> obj)
|
||||||
|
|> ignore)
|
||||||
|
|> ignore
|
||||||
|
|
||||||
|
/// JournalRequest is the form of a prayer request returned for the request journal display. It also contains
|
||||||
|
/// properties that may be filled for history and notes
|
||||||
|
[<CLIMutable; NoComparison; NoEquality>]
|
||||||
|
type JournalRequest =
|
||||||
|
{ /// The ID of the request
|
||||||
|
requestId : RequestId
|
||||||
|
/// The ID of the user to whom the request belongs
|
||||||
|
userId : string
|
||||||
|
/// The current text of the request
|
||||||
|
text : string
|
||||||
|
/// The last time action was taken on the request
|
||||||
|
asOf : int64
|
||||||
|
/// The last status for the request
|
||||||
|
lastStatus : string
|
||||||
|
/// The time that this request should reappear in the user's journal
|
||||||
|
snoozedUntil : int64
|
||||||
|
/// The time after which this request should reappear in the user's journal by configured recurrence
|
||||||
|
showAfter : int64
|
||||||
|
/// The type of recurrence for this request
|
||||||
|
recurType : string
|
||||||
|
/// How many of the recurrence intervals should occur between appearances in the journal
|
||||||
|
recurCount : int16
|
||||||
|
/// History entries for the request
|
||||||
|
history : History list
|
||||||
|
/// Note entries for the request
|
||||||
|
notes : Note list
|
||||||
|
}
|
||||||
|
with
|
||||||
|
static member configureEF (mb : ModelBuilder) =
|
||||||
|
mb.Query<JournalRequest> (
|
||||||
|
fun m ->
|
||||||
|
m.ToView "journal" |> ignore
|
||||||
|
m.Ignore(fun e -> e.history :> obj) |> ignore
|
||||||
|
m.Ignore(fun e -> e.notes :> obj) |> ignore)
|
||||||
|
|> ignore
|
||||||
|
|
||||||
|
|
||||||
|
open System.Linq
|
||||||
|
open System.Threading.Tasks
|
||||||
|
|
||||||
|
/// Data context
|
||||||
|
type AppDbContext (opts : DbContextOptions<AppDbContext>) =
|
||||||
|
inherit DbContext (opts)
|
||||||
|
|
||||||
|
[<DefaultValue>]
|
||||||
|
val mutable private history : DbSet<History>
|
||||||
|
[<DefaultValue>]
|
||||||
|
val mutable private notes : DbSet<Note>
|
||||||
|
[<DefaultValue>]
|
||||||
|
val mutable private requests : DbSet<Request>
|
||||||
|
[<DefaultValue>]
|
||||||
|
val mutable private journal : DbQuery<JournalRequest>
|
||||||
|
|
||||||
|
member this.History
|
||||||
|
with get () = this.history
|
||||||
|
and set v = this.history <- v
|
||||||
|
member this.Notes
|
||||||
|
with get () = this.notes
|
||||||
|
and set v = this.notes <- v
|
||||||
|
member this.Requests
|
||||||
|
with get () = this.requests
|
||||||
|
and set v = this.requests <- v
|
||||||
|
member this.Journal
|
||||||
|
with get () = this.journal
|
||||||
|
and set v = this.journal <- v
|
||||||
|
|
||||||
|
override __.OnModelCreating (mb : ModelBuilder) =
|
||||||
|
base.OnModelCreating mb
|
||||||
|
[ History.configureEF
|
||||||
|
Note.configureEF
|
||||||
|
Request.configureEF
|
||||||
|
JournalRequest.configureEF
|
||||||
|
]
|
||||||
|
|> List.iter (fun x -> x mb)
|
||||||
|
|
||||||
|
/// Register a disconnected entity with the context, having the given state
|
||||||
|
member private this.RegisterAs<'TEntity when 'TEntity : not struct> state e =
|
||||||
|
this.Entry<'TEntity>(e).State <- state
|
||||||
|
|
||||||
|
/// Add an entity instance to the context
|
||||||
|
member this.AddEntry e =
|
||||||
|
this.RegisterAs EntityState.Added e
|
||||||
|
|
||||||
|
/// Update the entity instance's values
|
||||||
|
member this.UpdateEntry e =
|
||||||
|
this.RegisterAs EntityState.Modified e
|
||||||
|
|
||||||
|
/// Retrieve all answered requests for the given user
|
||||||
|
member this.AnsweredRequests userId : JournalRequest seq =
|
||||||
|
upcast this.Journal
|
||||||
|
.Where(fun r -> r.userId = userId && r.lastStatus = "Answered")
|
||||||
|
.OrderByDescending(fun r -> r.asOf)
|
||||||
|
|
||||||
|
/// Retrieve the user's current journal
|
||||||
|
member this.JournalByUserId userId : JournalRequest seq =
|
||||||
|
upcast this.Journal
|
||||||
|
.Where(fun r -> r.userId = userId && r.lastStatus <> "Answered")
|
||||||
|
.OrderBy(fun r -> r.showAfter)
|
||||||
|
|
||||||
|
/// Retrieve a request by its ID and user ID
|
||||||
|
member this.TryRequestById reqId userId =
|
||||||
|
task {
|
||||||
|
let! req = this.Requests.AsNoTracking().FirstOrDefaultAsync(fun r -> r.requestId = reqId && r.userId = userId)
|
||||||
|
return toOption req
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retrieve notes for a request by its ID and user ID
|
||||||
|
member this.NotesById reqId userId =
|
||||||
|
task {
|
||||||
|
match! this.TryRequestById reqId userId with
|
||||||
|
| Some _ -> return this.Notes.AsNoTracking().Where(fun n -> n.requestId = reqId) |> List.ofSeq
|
||||||
|
| None -> return []
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retrieve a journal request by its ID and user ID
|
||||||
|
member this.TryJournalById reqId userId =
|
||||||
|
task {
|
||||||
|
let! req = this.Journal.FirstOrDefaultAsync(fun r -> r.requestId = reqId && r.userId = userId)
|
||||||
|
return toOption req
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retrieve a request, including its history and notes, by its ID and user ID
|
||||||
|
member this.TryFullRequestById requestId userId =
|
||||||
|
task {
|
||||||
|
match! this.TryJournalById requestId userId with
|
||||||
|
| Some req ->
|
||||||
|
let! fullReq =
|
||||||
|
this.Requests.AsNoTracking()
|
||||||
|
.Include(fun r -> r.history)
|
||||||
|
.Include(fun r -> r.notes)
|
||||||
|
.FirstOrDefaultAsync(fun r -> r.requestId = requestId && r.userId = userId)
|
||||||
|
match toOption fullReq with
|
||||||
|
| Some _ -> return Some { req with history = List.ofSeq fullReq.history; notes = List.ofSeq fullReq.notes }
|
||||||
|
| None -> return None
|
||||||
|
| None -> return None
|
||||||
|
}
|
||||||
320
src/api/MyPrayerJournal.Api/Handlers.fs
Normal file
320
src/api/MyPrayerJournal.Api/Handlers.fs
Normal file
@@ -0,0 +1,320 @@
|
|||||||
|
/// HTTP handlers for the myPrayerJournal API
|
||||||
|
[<RequireQualifiedAccess>]
|
||||||
|
module MyPrayerJournal.Api.Handlers
|
||||||
|
|
||||||
|
open Giraffe
|
||||||
|
open MyPrayerJournal
|
||||||
|
open System
|
||||||
|
|
||||||
|
/// Handler to return Vue files
|
||||||
|
module Vue =
|
||||||
|
|
||||||
|
/// The application index page
|
||||||
|
let app : HttpHandler = htmlFile "wwwroot/index.html"
|
||||||
|
|
||||||
|
|
||||||
|
/// Handlers for error conditions
|
||||||
|
module Error =
|
||||||
|
|
||||||
|
open Microsoft.Extensions.Logging
|
||||||
|
|
||||||
|
/// Handle errors
|
||||||
|
let error (ex : Exception) (log : ILogger) =
|
||||||
|
log.LogError (EventId(), ex, "An unhandled exception has occurred while executing the request.")
|
||||||
|
clearResponse >=> setStatusCode 500 >=> json ex.Message
|
||||||
|
|
||||||
|
/// Handle 404s from the API, sending known URL paths to the Vue app so that they can be handled there
|
||||||
|
let notFound : HttpHandler =
|
||||||
|
fun next ctx ->
|
||||||
|
[ "/journal"; "/legal"; "/request"; "/user" ]
|
||||||
|
|> List.filter ctx.Request.Path.Value.StartsWith
|
||||||
|
|> List.length
|
||||||
|
|> function
|
||||||
|
| 0 -> (setStatusCode 404 >=> json ([ "error", "not found" ] |> dict)) next ctx
|
||||||
|
| _ -> Vue.app next ctx
|
||||||
|
|
||||||
|
|
||||||
|
/// Handler helpers
|
||||||
|
[<AutoOpen>]
|
||||||
|
module private Helpers =
|
||||||
|
|
||||||
|
open Microsoft.AspNetCore.Http
|
||||||
|
open System.Threading.Tasks
|
||||||
|
open System.Security.Claims
|
||||||
|
|
||||||
|
/// Get the database context from DI
|
||||||
|
let db (ctx : HttpContext) =
|
||||||
|
ctx.GetService<AppDbContext> ()
|
||||||
|
|
||||||
|
/// Get the user's "sub" claim
|
||||||
|
let user (ctx : HttpContext) =
|
||||||
|
ctx.User.Claims |> Seq.tryFind (fun u -> u.Type = ClaimTypes.NameIdentifier)
|
||||||
|
|
||||||
|
/// Get the current user's ID
|
||||||
|
// NOTE: this may raise if you don't run the request through the authorize handler first
|
||||||
|
let userId ctx =
|
||||||
|
((user >> Option.get) ctx).Value
|
||||||
|
|
||||||
|
/// Return a 201 CREATED response
|
||||||
|
let created next ctx =
|
||||||
|
setStatusCode 201 next ctx
|
||||||
|
|
||||||
|
/// The "now" time in JavaScript
|
||||||
|
let jsNow () =
|
||||||
|
DateTime.UtcNow.Subtract(DateTime (1970, 1, 1, 0, 0, 0)).TotalSeconds |> int64 |> (*) 1000L
|
||||||
|
|
||||||
|
/// Handler to return a 403 Not Authorized reponse
|
||||||
|
let notAuthorized : HttpHandler =
|
||||||
|
setStatusCode 403 >=> fun _ _ -> Task.FromResult<HttpContext option> None
|
||||||
|
|
||||||
|
/// Handler to require authorization
|
||||||
|
let authorize : HttpHandler =
|
||||||
|
fun next ctx -> match user ctx with Some _ -> next ctx | None -> notAuthorized next ctx
|
||||||
|
|
||||||
|
/// Flip JSON result so we can pipe into it
|
||||||
|
let asJson<'T> next ctx (o : 'T) =
|
||||||
|
json o next ctx
|
||||||
|
|
||||||
|
|
||||||
|
/// Strongly-typed models for post requests
|
||||||
|
module Models =
|
||||||
|
|
||||||
|
/// A history entry addition (AKA request update)
|
||||||
|
[<CLIMutable>]
|
||||||
|
type HistoryEntry =
|
||||||
|
{ /// The status of the history update
|
||||||
|
status : string
|
||||||
|
/// The text of the update
|
||||||
|
updateText : string
|
||||||
|
}
|
||||||
|
|
||||||
|
/// An additional note
|
||||||
|
[<CLIMutable>]
|
||||||
|
type NoteEntry =
|
||||||
|
{ /// The notes being added
|
||||||
|
notes : string
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Recurrence update
|
||||||
|
[<CLIMutable>]
|
||||||
|
type Recurrence =
|
||||||
|
{ /// The recurrence type
|
||||||
|
recurType : string
|
||||||
|
/// The recurrence cound
|
||||||
|
recurCount : int16
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A prayer request
|
||||||
|
[<CLIMutable>]
|
||||||
|
type Request =
|
||||||
|
{ /// The text of the request
|
||||||
|
requestText : string
|
||||||
|
/// The recurrence type
|
||||||
|
recurType : string
|
||||||
|
/// The recurrence count
|
||||||
|
recurCount : int16
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Reset the "showAfter" property on a request
|
||||||
|
[<CLIMutable>]
|
||||||
|
type Show =
|
||||||
|
{ /// The time after which the request should appear
|
||||||
|
showAfter : int64
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The time until which a request should not appear in the journal
|
||||||
|
[<CLIMutable>]
|
||||||
|
type SnoozeUntil =
|
||||||
|
{ /// The time at which the request should reappear
|
||||||
|
until : int64
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// /api/journal URLs
|
||||||
|
module Journal =
|
||||||
|
|
||||||
|
/// GET /api/journal
|
||||||
|
let journal : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
userId ctx
|
||||||
|
|> (db ctx).JournalByUserId
|
||||||
|
|> asJson next ctx
|
||||||
|
|
||||||
|
|
||||||
|
/// /api/request URLs
|
||||||
|
module Request =
|
||||||
|
|
||||||
|
open NCuid
|
||||||
|
|
||||||
|
/// Ticks per recurrence
|
||||||
|
let private recurrence =
|
||||||
|
[ "immediate", 0L
|
||||||
|
"hours", 3600000L
|
||||||
|
"days", 86400000L
|
||||||
|
"weeks", 604800000L
|
||||||
|
]
|
||||||
|
|> Map.ofList
|
||||||
|
|
||||||
|
/// POST /api/request
|
||||||
|
let add : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
let! r = ctx.BindJsonAsync<Models.Request> ()
|
||||||
|
let db = db ctx
|
||||||
|
let reqId = Cuid.Generate ()
|
||||||
|
let usrId = userId ctx
|
||||||
|
let now = jsNow ()
|
||||||
|
{ Request.empty with
|
||||||
|
requestId = reqId
|
||||||
|
userId = usrId
|
||||||
|
enteredOn = now
|
||||||
|
showAfter = now
|
||||||
|
recurType = r.recurType
|
||||||
|
recurCount = r.recurCount
|
||||||
|
}
|
||||||
|
|> db.AddEntry
|
||||||
|
{ History.empty with
|
||||||
|
requestId = reqId
|
||||||
|
asOf = now
|
||||||
|
status = "Created"
|
||||||
|
text = Some r.requestText
|
||||||
|
}
|
||||||
|
|> db.AddEntry
|
||||||
|
let! _ = db.SaveChangesAsync ()
|
||||||
|
match! db.TryJournalById reqId usrId with
|
||||||
|
| Some req -> return! (setStatusCode 201 >=> json req) next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// POST /api/request/[req-id]/history
|
||||||
|
let addHistory reqId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
let db = db ctx
|
||||||
|
match! db.TryRequestById reqId (userId ctx) with
|
||||||
|
| Some req ->
|
||||||
|
let! hist = ctx.BindJsonAsync<Models.HistoryEntry> ()
|
||||||
|
let now = jsNow ()
|
||||||
|
{ History.empty with
|
||||||
|
requestId = reqId
|
||||||
|
asOf = now
|
||||||
|
status = hist.status
|
||||||
|
text = match hist.updateText with null | "" -> None | x -> Some x
|
||||||
|
}
|
||||||
|
|> db.AddEntry
|
||||||
|
match hist.status with
|
||||||
|
| "Prayed" ->
|
||||||
|
db.UpdateEntry { req with showAfter = now + (recurrence.[req.recurType] * int64 req.recurCount) }
|
||||||
|
| _ -> ()
|
||||||
|
let! _ = db.SaveChangesAsync ()
|
||||||
|
return! created next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// POST /api/request/[req-id]/note
|
||||||
|
let addNote reqId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
let db = db ctx
|
||||||
|
match! db.TryRequestById reqId (userId ctx) with
|
||||||
|
| Some _ ->
|
||||||
|
let! notes = ctx.BindJsonAsync<Models.NoteEntry> ()
|
||||||
|
{ Note.empty with
|
||||||
|
requestId = reqId
|
||||||
|
asOf = jsNow ()
|
||||||
|
notes = notes.notes
|
||||||
|
}
|
||||||
|
|> db.AddEntry
|
||||||
|
let! _ = db.SaveChangesAsync ()
|
||||||
|
return! created next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// GET /api/requests/answered
|
||||||
|
let answered : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
userId ctx
|
||||||
|
|> (db ctx).AnsweredRequests
|
||||||
|
|> asJson next ctx
|
||||||
|
|
||||||
|
/// GET /api/request/[req-id]
|
||||||
|
let get reqId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
match! (db ctx).TryJournalById reqId (userId ctx) with
|
||||||
|
| Some req -> return! json req next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// GET /api/request/[req-id]/full
|
||||||
|
let getFull reqId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
match! (db ctx).TryFullRequestById reqId (userId ctx) with
|
||||||
|
| Some req -> return! json req next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// GET /api/request/[req-id]/notes
|
||||||
|
let getNotes reqId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
let! notes = (db ctx).NotesById reqId (userId ctx)
|
||||||
|
return! json notes next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// PATCH /api/request/[req-id]/show
|
||||||
|
let show reqId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
let db = db ctx
|
||||||
|
match! db.TryRequestById reqId (userId ctx) with
|
||||||
|
| Some req ->
|
||||||
|
let! show = ctx.BindJsonAsync<Models.Show> ()
|
||||||
|
{ req with showAfter = show.showAfter }
|
||||||
|
|> db.UpdateEntry
|
||||||
|
let! _ = db.SaveChangesAsync ()
|
||||||
|
return! setStatusCode 204 next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// PATCH /api/request/[req-id]/snooze
|
||||||
|
let snooze reqId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
let db = db ctx
|
||||||
|
match! db.TryRequestById reqId (userId ctx) with
|
||||||
|
| Some req ->
|
||||||
|
let! until = ctx.BindJsonAsync<Models.SnoozeUntil> ()
|
||||||
|
{ req with snoozedUntil = until.until; showAfter = until.until }
|
||||||
|
|> db.UpdateEntry
|
||||||
|
let! _ = db.SaveChangesAsync ()
|
||||||
|
return! setStatusCode 204 next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
|
|
||||||
|
/// PATCH /api/request/[req-id]/recurrence
|
||||||
|
let updateRecurrence reqId : HttpHandler =
|
||||||
|
authorize
|
||||||
|
>=> fun next ctx ->
|
||||||
|
task {
|
||||||
|
let db = db ctx
|
||||||
|
match! db.TryRequestById reqId (userId ctx) with
|
||||||
|
| Some req ->
|
||||||
|
let! recur = ctx.BindJsonAsync<Models.Recurrence> ()
|
||||||
|
{ req with recurType = recur.recurType; recurCount = recur.recurCount }
|
||||||
|
|> db.UpdateEntry
|
||||||
|
let! _ = db.SaveChangesAsync ()
|
||||||
|
return! setStatusCode 204 next ctx
|
||||||
|
| None -> return! Error.notFound next ctx
|
||||||
|
}
|
||||||
30
src/api/MyPrayerJournal.Api/MyPrayerJournal.Api.fsproj
Normal file
30
src/api/MyPrayerJournal.Api/MyPrayerJournal.Api.fsproj
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Data.fs" />
|
||||||
|
<Compile Include="Handlers.fs" />
|
||||||
|
<Compile Include="Program.fs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="FSharp.EFCore.OptionConverter" Version="1.0.0" />
|
||||||
|
<PackageReference Include="Giraffe" Version="1.1.0" />
|
||||||
|
<PackageReference Include="Giraffe.TokenRouter" Version="0.1.0-beta-110" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.App" />
|
||||||
|
<PackageReference Include="NCuid.NetCore" Version="1.0.1" />
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="2.1.1.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Update="FSharp.Core" Version="4.5.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="wwwroot\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
127
src/api/MyPrayerJournal.Api/Program.fs
Normal file
127
src/api/MyPrayerJournal.Api/Program.fs
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
namespace MyPrayerJournal.Api
|
||||||
|
|
||||||
|
open Microsoft.AspNetCore.Builder
|
||||||
|
open Microsoft.AspNetCore.Hosting
|
||||||
|
open System
|
||||||
|
|
||||||
|
|
||||||
|
/// Configuration functions for the application
|
||||||
|
module Configure =
|
||||||
|
|
||||||
|
open Giraffe
|
||||||
|
open Giraffe.TokenRouter
|
||||||
|
open Microsoft.AspNetCore.Authentication.JwtBearer
|
||||||
|
open Microsoft.AspNetCore.Server.Kestrel.Core
|
||||||
|
open Microsoft.EntityFrameworkCore
|
||||||
|
open Microsoft.Extensions.Configuration
|
||||||
|
open Microsoft.Extensions.DependencyInjection
|
||||||
|
open Microsoft.Extensions.Logging
|
||||||
|
open MyPrayerJournal
|
||||||
|
|
||||||
|
/// Set up the configuration for the app
|
||||||
|
let configuration (ctx : WebHostBuilderContext) (cfg : IConfigurationBuilder) =
|
||||||
|
cfg.SetBasePath(ctx.HostingEnvironment.ContentRootPath)
|
||||||
|
.AddJsonFile("appsettings.json", optional = true, reloadOnChange = true)
|
||||||
|
.AddJsonFile(sprintf "appsettings.%s.json" ctx.HostingEnvironment.EnvironmentName)
|
||||||
|
.AddEnvironmentVariables()
|
||||||
|
|> ignore
|
||||||
|
|
||||||
|
/// Configure Kestrel from appsettings.json
|
||||||
|
let kestrel (ctx : WebHostBuilderContext) (opts : KestrelServerOptions) =
|
||||||
|
(ctx.Configuration.GetSection >> opts.Configure >> ignore) "Kestrel"
|
||||||
|
|
||||||
|
/// Configure dependency injection
|
||||||
|
let services (sc : IServiceCollection) =
|
||||||
|
use sp = sc.BuildServiceProvider()
|
||||||
|
let cfg = sp.GetRequiredService<IConfiguration> ()
|
||||||
|
sc.AddGiraffe()
|
||||||
|
.AddAuthentication(
|
||||||
|
/// Use HTTP "Bearer" authentication with JWTs
|
||||||
|
fun opts ->
|
||||||
|
opts.DefaultAuthenticateScheme <- JwtBearerDefaults.AuthenticationScheme
|
||||||
|
opts.DefaultChallengeScheme <- JwtBearerDefaults.AuthenticationScheme)
|
||||||
|
.AddJwtBearer(
|
||||||
|
/// Configure JWT options with Auth0 options from configuration
|
||||||
|
fun opts ->
|
||||||
|
let jwtCfg = cfg.GetSection "Auth0"
|
||||||
|
opts.Authority <- sprintf "https://%s/" jwtCfg.["Domain"]
|
||||||
|
opts.Audience <- jwtCfg.["Id"])
|
||||||
|
|> ignore
|
||||||
|
sc.AddDbContext<AppDbContext>(fun opts -> opts.UseNpgsql(cfg.GetConnectionString "mpj") |> ignore)
|
||||||
|
|> ignore
|
||||||
|
|
||||||
|
/// Routes for the available URLs within myPrayerJournal
|
||||||
|
let webApp =
|
||||||
|
router Handlers.Error.notFound [
|
||||||
|
route "/" Handlers.Vue.app
|
||||||
|
subRoute "/api/" [
|
||||||
|
GET [
|
||||||
|
route "journal" Handlers.Journal.journal
|
||||||
|
subRoute "request" [
|
||||||
|
route "s/answered" Handlers.Request.answered
|
||||||
|
routef "/%s/full" Handlers.Request.getFull
|
||||||
|
routef "/%s/notes" Handlers.Request.getNotes
|
||||||
|
routef "/%s" Handlers.Request.get
|
||||||
|
]
|
||||||
|
]
|
||||||
|
PATCH [
|
||||||
|
subRoute "request" [
|
||||||
|
routef "/%s/recurrence" Handlers.Request.updateRecurrence
|
||||||
|
routef "/%s/show" Handlers.Request.show
|
||||||
|
routef "/%s/snooze" Handlers.Request.snooze
|
||||||
|
]
|
||||||
|
]
|
||||||
|
POST [
|
||||||
|
subRoute "request" [
|
||||||
|
route "" Handlers.Request.add
|
||||||
|
routef "/%s/history" Handlers.Request.addHistory
|
||||||
|
routef "/%s/note" Handlers.Request.addNote
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
/// Configure the web application
|
||||||
|
let application (app : IApplicationBuilder) =
|
||||||
|
let env = app.ApplicationServices.GetService<IHostingEnvironment> ()
|
||||||
|
match env.IsDevelopment () with
|
||||||
|
| true -> app.UseDeveloperExceptionPage ()
|
||||||
|
| false -> app.UseGiraffeErrorHandler Handlers.Error.error
|
||||||
|
|> function
|
||||||
|
| a ->
|
||||||
|
a.UseAuthentication()
|
||||||
|
.UseStaticFiles()
|
||||||
|
.UseGiraffe webApp
|
||||||
|
|> ignore
|
||||||
|
|
||||||
|
/// Configure logging
|
||||||
|
let logging (log : ILoggingBuilder) =
|
||||||
|
let env = log.Services.BuildServiceProvider().GetService<IHostingEnvironment> ()
|
||||||
|
match env.IsDevelopment () with
|
||||||
|
| true -> log
|
||||||
|
| false -> log.AddFilter(fun l -> l > LogLevel.Information)
|
||||||
|
|> function l -> l.AddConsole().AddDebug()
|
||||||
|
|> ignore
|
||||||
|
|
||||||
|
|
||||||
|
module Program =
|
||||||
|
|
||||||
|
open System.IO
|
||||||
|
|
||||||
|
let exitCode = 0
|
||||||
|
|
||||||
|
let CreateWebHostBuilder _ =
|
||||||
|
let contentRoot = Directory.GetCurrentDirectory ()
|
||||||
|
WebHostBuilder()
|
||||||
|
.UseContentRoot(contentRoot)
|
||||||
|
.ConfigureAppConfiguration(Configure.configuration)
|
||||||
|
.UseKestrel(Configure.kestrel)
|
||||||
|
.UseWebRoot(Path.Combine (contentRoot, "wwwroot"))
|
||||||
|
.ConfigureServices(Configure.services)
|
||||||
|
.ConfigureLogging(Configure.logging)
|
||||||
|
.Configure(Action<IApplicationBuilder> Configure.application)
|
||||||
|
|
||||||
|
[<EntryPoint>]
|
||||||
|
let main args =
|
||||||
|
CreateWebHostBuilder(args).Build().Run()
|
||||||
|
exitCode
|
||||||
27
src/api/MyPrayerJournal.Api/Properties/launchSettings.json
Normal file
27
src/api/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/api/MyPrayerJournal.Api/appsettings.json
Normal file
9
src/api/MyPrayerJournal.Api/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Kestrel": {
|
||||||
|
"EndPoints": {
|
||||||
|
"Http": {
|
||||||
|
"Url": "http://localhost:3000"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
25
src/api/MyPrayerJournal.sln
Normal file
25
src/api/MyPrayerJournal.sln
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 15
|
||||||
|
VisualStudioVersion = 15.0.27703.2035
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "MyPrayerJournal.Api", "MyPrayerJournal.Api\MyPrayerJournal.Api.fsproj", "{E0E5240C-00DC-428A-899A-DA4F06625B8A}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{E0E5240C-00DC-428A-899A-DA4F06625B8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{E0E5240C-00DC-428A-899A-DA4F06625B8A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{E0E5240C-00DC-428A-899A-DA4F06625B8A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{E0E5240C-00DC-428A-899A-DA4F06625B8A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {7EAB6243-94B3-49A5-BA64-7F01B8BE7CB9}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
@@ -1,366 +0,0 @@
|
|||||||
// Package data contains data access functions for myPrayerJournal.
|
|
||||||
package data
|
|
||||||
|
|
||||||
import (
|
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
// Register the PostgreSQL driver.
|
|
||||||
_ "github.com/lib/pq"
|
|
||||||
"github.com/lucsky/cuid"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
currentRequestSQL = `
|
|
||||||
SELECT "requestId", "text", "asOf", "lastStatus"
|
|
||||||
FROM mpj.journal`
|
|
||||||
journalSQL = `
|
|
||||||
SELECT "requestId", "text", "asOf", "lastStatus"
|
|
||||||
FROM mpj.journal
|
|
||||||
WHERE "userId" = $1
|
|
||||||
AND "lastStatus" <> 'Answered'`
|
|
||||||
)
|
|
||||||
|
|
||||||
// db is a connection to the database for the entire application.
|
|
||||||
var db *sql.DB
|
|
||||||
|
|
||||||
// Settings holds the PostgreSQL configuration for myPrayerJournal.
|
|
||||||
type Settings struct {
|
|
||||||
Host string `json:"host"`
|
|
||||||
Port int `json:"port"`
|
|
||||||
User string `json:"user"`
|
|
||||||
Password string `json:"password"`
|
|
||||||
DbName string `json:"dbname"`
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Data Access */
|
|
||||||
|
|
||||||
// Retrieve a basic request
|
|
||||||
func retrieveRequest(reqID, userID string) (*Request, bool) {
|
|
||||||
req := Request{}
|
|
||||||
err := db.QueryRow(`
|
|
||||||
SELECT "requestId", "enteredOn"
|
|
||||||
FROM mpj.request
|
|
||||||
WHERE "requestId" = $1
|
|
||||||
AND "userId" = $2`, reqID, userID).Scan(
|
|
||||||
&req.ID, &req.EnteredOn,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
if err != sql.ErrNoRows {
|
|
||||||
log.Print(err)
|
|
||||||
}
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
req.UserID = userID
|
|
||||||
return &req, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unix time in JavaScript Date.now() precision.
|
|
||||||
func jsNow() int64 {
|
|
||||||
return time.Now().UnixNano() / int64(1000000)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop through rows and create journal requests from them.
|
|
||||||
func makeJournal(rows *sql.Rows, userID string) []JournalRequest {
|
|
||||||
var out []JournalRequest
|
|
||||||
for rows.Next() {
|
|
||||||
req := JournalRequest{}
|
|
||||||
err := rows.Scan(&req.RequestID, &req.Text, &req.AsOf, &req.LastStatus)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
out = append(out, req)
|
|
||||||
}
|
|
||||||
if rows.Err() != nil {
|
|
||||||
log.Print(rows.Err())
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddHistory creates a history entry for a prayer request, given the status and updated text.
|
|
||||||
func AddHistory(userID, reqID, status, text string) int {
|
|
||||||
if _, ok := retrieveRequest(reqID, userID); !ok {
|
|
||||||
return 404
|
|
||||||
}
|
|
||||||
_, err := db.Exec(`
|
|
||||||
INSERT INTO mpj.history
|
|
||||||
("requestId", "asOf", "status", "text")
|
|
||||||
VALUES
|
|
||||||
($1, $2, $3, NULLIF($4, ''))`,
|
|
||||||
reqID, jsNow(), status, text)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return 500
|
|
||||||
}
|
|
||||||
return 204
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddNew stores a new prayer request and its initial history record.
|
|
||||||
func AddNew(userID, text string) (*JournalRequest, bool) {
|
|
||||||
id := cuid.New()
|
|
||||||
now := jsNow()
|
|
||||||
tx, err := db.Begin()
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
tx.Rollback()
|
|
||||||
} else {
|
|
||||||
tx.Commit()
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
_, err = tx.Exec(
|
|
||||||
`INSERT INTO mpj.request ("requestId", "enteredOn", "userId") VALUES ($1, $2, $3)`,
|
|
||||||
id, now, userID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
_, err = tx.Exec(
|
|
||||||
`INSERT INTO mpj.history ("requestId", "asOf", "status", "text") VALUES ($1, $2, 'Created', $3)`,
|
|
||||||
id, now, text)
|
|
||||||
if err != nil {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
return &JournalRequest{RequestID: id, Text: text, AsOf: now, LastStatus: `Created`}, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddNote adds a note to a prayer request.
|
|
||||||
func AddNote(userID, reqID, note string) int {
|
|
||||||
if _, ok := retrieveRequest(reqID, userID); !ok {
|
|
||||||
return 404
|
|
||||||
}
|
|
||||||
_, err := db.Exec(`
|
|
||||||
INSERT INTO mpj.note
|
|
||||||
("requestId", "asOf", "notes")
|
|
||||||
VALUES
|
|
||||||
($1, $2, $3)`,
|
|
||||||
reqID, jsNow(), note)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return 500
|
|
||||||
}
|
|
||||||
return 204
|
|
||||||
}
|
|
||||||
|
|
||||||
// Answered retrieves all answered requests for the given user.
|
|
||||||
func Answered(userID string) []JournalRequest {
|
|
||||||
rows, err := db.Query(currentRequestSQL+
|
|
||||||
` WHERE "userId" = $1
|
|
||||||
AND "lastStatus" = 'Answered'
|
|
||||||
ORDER BY "asOf" DESC`,
|
|
||||||
userID)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
return makeJournal(rows, userID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ByID retrieves a journal request by its ID.
|
|
||||||
func ByID(userID, reqID string) (*JournalRequest, bool) {
|
|
||||||
req := JournalRequest{}
|
|
||||||
err := db.QueryRow(currentRequestSQL+
|
|
||||||
` WHERE "requestId" = $1
|
|
||||||
AND "userId" = $2`,
|
|
||||||
reqID, userID).Scan(
|
|
||||||
&req.RequestID, &req.Text, &req.AsOf, &req.LastStatus,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
if err == sql.ErrNoRows {
|
|
||||||
return nil, true
|
|
||||||
}
|
|
||||||
log.Print(err)
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
return &req, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect establishes a connection to the database.
|
|
||||||
func Connect(s *Settings) bool {
|
|
||||||
connStr := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",
|
|
||||||
s.Host, s.Port, s.User, s.Password, s.DbName)
|
|
||||||
var err error
|
|
||||||
db, err = sql.Open("postgres", connStr)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
err = db.Ping()
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
log.Printf("Connected to postgres://%s@%s:%d/%s\n", s.User, s.Host, s.Port, s.DbName)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
// FullByID retrieves a journal request, including its full history and notes.
|
|
||||||
func FullByID(userID, reqID string) (*JournalRequest, bool) {
|
|
||||||
req, ok := ByID(userID, reqID)
|
|
||||||
if !ok {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
hRows, err := db.Query(`
|
|
||||||
SELECT "asOf", "status", COALESCE("text", '') AS "text"
|
|
||||||
FROM mpj.history
|
|
||||||
WHERE "requestId" = $1
|
|
||||||
ORDER BY "asOf"`,
|
|
||||||
reqID)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
defer hRows.Close()
|
|
||||||
for hRows.Next() {
|
|
||||||
hist := History{}
|
|
||||||
err = hRows.Scan(&hist.AsOf, &hist.Status, &hist.Text)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
req.History = append(req.History, hist)
|
|
||||||
}
|
|
||||||
if hRows.Err() != nil {
|
|
||||||
log.Print(hRows.Err())
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
req.Notes, err = NotesByID(userID, reqID)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
return req, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Journal retrieves the current user's active prayer journal.
|
|
||||||
func Journal(userID string) []JournalRequest {
|
|
||||||
rows, err := db.Query(journalSQL+` ORDER BY "asOf"`, userID)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
return makeJournal(rows, userID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NotesByID retrieves the notes for a given prayer request
|
|
||||||
func NotesByID(userID, reqID string) ([]Note, error) {
|
|
||||||
if _, ok := retrieveRequest(reqID, userID); !ok {
|
|
||||||
return nil, sql.ErrNoRows
|
|
||||||
}
|
|
||||||
rows, err := db.Query(`
|
|
||||||
SELECT "asOf", "notes"
|
|
||||||
FROM mpj.note
|
|
||||||
WHERE "requestId" = $1
|
|
||||||
ORDER BY "asOf" DESC`,
|
|
||||||
reqID)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer rows.Close()
|
|
||||||
var notes []Note
|
|
||||||
for rows.Next() {
|
|
||||||
note := Note{}
|
|
||||||
err = rows.Scan(¬e.AsOf, ¬e.Notes)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
notes = append(notes, note)
|
|
||||||
}
|
|
||||||
if rows.Err() != nil {
|
|
||||||
log.Print(rows.Err())
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return notes, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
/* DDL */
|
|
||||||
|
|
||||||
// EnsureDB makes sure we have a known state of data structures.
|
|
||||||
func EnsureDB() {
|
|
||||||
tableSQL := func(table string) string {
|
|
||||||
return fmt.Sprintf(`SELECT 1 FROM pg_tables WHERE schemaname='mpj' AND tablename='%s'`, table)
|
|
||||||
}
|
|
||||||
indexSQL := func(table, index string) string {
|
|
||||||
return fmt.Sprintf(`SELECT 1 FROM pg_indexes WHERE schemaname='mpj' AND tablename='%s' AND indexname='%s'`,
|
|
||||||
table, index)
|
|
||||||
}
|
|
||||||
check := func(name, test, fix string) {
|
|
||||||
count := 0
|
|
||||||
err := db.QueryRow(test).Scan(&count)
|
|
||||||
if err != nil {
|
|
||||||
if err == sql.ErrNoRows {
|
|
||||||
log.Printf("Fixing up %s...\n", name)
|
|
||||||
_, err = db.Exec(fix)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
check(`myPrayerJournal Schema`, `SELECT 1 FROM pg_namespace WHERE nspname='mpj'`,
|
|
||||||
`CREATE SCHEMA mpj;
|
|
||||||
COMMENT ON SCHEMA mpj IS 'myPrayerJournal data'`)
|
|
||||||
if _, err := db.Exec(`SET search_path TO mpj`); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
check(`request Table`, tableSQL(`request`),
|
|
||||||
`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'`)
|
|
||||||
check(`history Table`, tableSQL(`history`),
|
|
||||||
`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'`)
|
|
||||||
check(`note Table`, tableSQL(`note`),
|
|
||||||
`CREATE TABLE mpj.note (
|
|
||||||
"requestId" varchar(25) NOT NULL REFERENCES mpj.request,
|
|
||||||
"asOf" bigint NOT NULL,
|
|
||||||
"notes" text NOT NULL,
|
|
||||||
PRIMARY KEY ("requestId", "asOf"));
|
|
||||||
COMMENT ON TABLE mpj.note IS 'Notes regarding a request'`)
|
|
||||||
check(`request.userId Index`, indexSQL(`request`, `idx_request_userId`),
|
|
||||||
`CREATE INDEX "idx_request_userId" ON mpj.request ("userId");
|
|
||||||
COMMENT ON INDEX "idx_request_userId" IS 'Requests are retrieved by user'`)
|
|
||||||
check(`journal View`, `SELECT 1 FROM pg_views WHERE schemaname='mpj' AND viewname='journal'`,
|
|
||||||
`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'`)
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
package data
|
|
||||||
|
|
||||||
// History is a record of action taken on a prayer request, including updates to its text.
|
|
||||||
type History struct {
|
|
||||||
RequestID string `json:"requestId"`
|
|
||||||
AsOf int64 `json:"asOf"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
Text string `json:"text"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note is a note regarding a prayer request that does not result in an update to its text.
|
|
||||||
type Note struct {
|
|
||||||
RequestID string `json:"requestId"`
|
|
||||||
AsOf int64 `json:"asOf"`
|
|
||||||
Notes string `json:"notes"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Request is the identifying record for a prayer request.
|
|
||||||
type Request struct {
|
|
||||||
ID string `json:"requestId"`
|
|
||||||
EnteredOn int64 `json:"enteredOn"`
|
|
||||||
UserID string `json:"userId"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
|
||||||
type JournalRequest struct {
|
|
||||||
RequestID string `json:"requestId"`
|
|
||||||
Text string `json:"text"`
|
|
||||||
AsOf int64 `json:"asOf"`
|
|
||||||
LastStatus string `json:"lastStatus"`
|
|
||||||
History []History `json:"history,omitempty"`
|
|
||||||
Notes []Note `json:"notes,omitempty"`
|
|
||||||
}
|
|
||||||
@@ -1,182 +0,0 @@
|
|||||||
package routes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"database/sql"
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/danieljsummers/myPrayerJournal/src/api/data"
|
|
||||||
jwt "github.com/dgrijalva/jwt-go"
|
|
||||||
routing "github.com/go-ozzo/ozzo-routing"
|
|
||||||
)
|
|
||||||
|
|
||||||
/* Support */
|
|
||||||
|
|
||||||
// Set the content type, the HTTP error code, and return the error message.
|
|
||||||
func sendError(c *routing.Context, err error) error {
|
|
||||||
w := c.Response
|
|
||||||
w.Header().Set("Content-Type", "application/json; encoding=UTF-8")
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
if err := json.NewEncoder(w).Encode(map[string]string{"error": err.Error()}); err != nil {
|
|
||||||
log.Print("Error creating error JSON: " + err.Error())
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the content type and return the JSON to the user.
|
|
||||||
func sendJSON(c *routing.Context, result interface{}) error {
|
|
||||||
w := c.Response
|
|
||||||
w.Header().Set("Content-Type", "application/json; encoding=UTF-8")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
if err := json.NewEncoder(w).Encode(result); err != nil {
|
|
||||||
return sendError(c, err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send an HTTP 404 response.
|
|
||||||
func notFound(c *routing.Context) error {
|
|
||||||
c.Response.WriteHeader(404)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the request body as JSON.
|
|
||||||
func parseJSON(c *routing.Context) (map[string]interface{}, error) {
|
|
||||||
payload := make(map[string]interface{})
|
|
||||||
if err := json.NewDecoder(c.Request.Body).Decode(&payload); err != nil {
|
|
||||||
log.Println("Error decoding JSON:", err)
|
|
||||||
return payload, err
|
|
||||||
}
|
|
||||||
return payload, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// userID is a convenience function to extract the subscriber ID from the user's JWT.
|
|
||||||
// NOTE: Do not call this from public routes; there are a lot of type assertions that won't be true if the request
|
|
||||||
// hasn't gone through the authorization process.
|
|
||||||
func userID(c *routing.Context) string {
|
|
||||||
return c.Request.Context().Value("user").(*jwt.Token).Claims.(jwt.MapClaims)["sub"].(string)
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Handlers */
|
|
||||||
|
|
||||||
// GET: /api/journal/
|
|
||||||
func journal(c *routing.Context) error {
|
|
||||||
reqs := data.Journal(userID(c))
|
|
||||||
if reqs == nil {
|
|
||||||
reqs = []data.JournalRequest{}
|
|
||||||
}
|
|
||||||
return sendJSON(c, reqs)
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST: /api/request/
|
|
||||||
func requestAdd(c *routing.Context) error {
|
|
||||||
payload, err := parseJSON(c)
|
|
||||||
if err != nil {
|
|
||||||
return sendError(c, err)
|
|
||||||
}
|
|
||||||
result, ok := data.AddNew(userID(c), payload["requestText"].(string))
|
|
||||||
if !ok {
|
|
||||||
return sendError(c, errors.New("error adding request"))
|
|
||||||
}
|
|
||||||
return sendJSON(c, result)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: /api/request/<id>
|
|
||||||
func requestGet(c *routing.Context) error {
|
|
||||||
request, ok := data.ByID(userID(c), c.Param("id"))
|
|
||||||
if !ok {
|
|
||||||
return sendError(c, errors.New("error retrieving request"))
|
|
||||||
}
|
|
||||||
if request == nil {
|
|
||||||
return notFound(c)
|
|
||||||
}
|
|
||||||
return sendJSON(c, request)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: /api/request/<id>/complete
|
|
||||||
func requestGetComplete(c *routing.Context) error {
|
|
||||||
request, ok := data.FullByID(userID(c), c.Param("id"))
|
|
||||||
if !ok {
|
|
||||||
return sendError(c, errors.New("error retrieving request"))
|
|
||||||
}
|
|
||||||
var err error
|
|
||||||
request.Notes, err = data.NotesByID(userID(c), c.Param("id"))
|
|
||||||
if err != nil {
|
|
||||||
return sendError(c, err)
|
|
||||||
}
|
|
||||||
return sendJSON(c, request)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: /api/request/<id>/full
|
|
||||||
func requestGetFull(c *routing.Context) error {
|
|
||||||
request, ok := data.FullByID(userID(c), c.Param("id"))
|
|
||||||
if !ok {
|
|
||||||
return sendError(c, errors.New("error retrieving request"))
|
|
||||||
}
|
|
||||||
return sendJSON(c, request)
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST: /api/request/<id>/history
|
|
||||||
func requestAddHistory(c *routing.Context) error {
|
|
||||||
payload, err := parseJSON(c)
|
|
||||||
if err != nil {
|
|
||||||
return sendError(c, err)
|
|
||||||
}
|
|
||||||
c.Response.WriteHeader(
|
|
||||||
data.AddHistory(userID(c), c.Param("id"), payload["status"].(string), payload["updateText"].(string)))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// POST: /api/request/<id>/note
|
|
||||||
func requestAddNote(c *routing.Context) error {
|
|
||||||
payload, err := parseJSON(c)
|
|
||||||
if err != nil {
|
|
||||||
return sendError(c, err)
|
|
||||||
}
|
|
||||||
c.Response.WriteHeader(data.AddNote(userID(c), c.Param("id"), payload["notes"].(string)))
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: /api/request/<id>/notes
|
|
||||||
func requestGetNotes(c *routing.Context) error {
|
|
||||||
notes, err := data.NotesByID(userID(c), c.Param("id"))
|
|
||||||
if err != nil {
|
|
||||||
if err == sql.ErrNoRows {
|
|
||||||
return notFound(c)
|
|
||||||
}
|
|
||||||
return sendError(c, err)
|
|
||||||
}
|
|
||||||
if notes == nil {
|
|
||||||
notes = []data.Note{}
|
|
||||||
}
|
|
||||||
return sendJSON(c, notes)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: /api/request/answered
|
|
||||||
func requestsAnswered(c *routing.Context) error {
|
|
||||||
reqs := data.Answered(userID(c))
|
|
||||||
if reqs == nil {
|
|
||||||
reqs = []data.JournalRequest{}
|
|
||||||
}
|
|
||||||
return sendJSON(c, reqs)
|
|
||||||
}
|
|
||||||
|
|
||||||
// GET: /*
|
|
||||||
func staticFiles(c *routing.Context) error {
|
|
||||||
// serve index for known routes handled client-side by the app
|
|
||||||
r := c.Request
|
|
||||||
w := c.Response
|
|
||||||
for _, prefix := range ClientPrefixes {
|
|
||||||
if strings.HasPrefix(r.URL.Path, prefix) {
|
|
||||||
w.Header().Add("Content-Type", "text/html")
|
|
||||||
http.ServeFile(w, r, "./public/index.html")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 404 here is fine; quit hacking, y'all...
|
|
||||||
http.ServeFile(w, r, "./public"+r.URL.Path)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
package routes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/auth0/go-jwt-middleware"
|
|
||||||
jwt "github.com/dgrijalva/jwt-go"
|
|
||||||
"github.com/go-ozzo/ozzo-routing"
|
|
||||||
"github.com/go-ozzo/ozzo-routing/fault"
|
|
||||||
)
|
|
||||||
|
|
||||||
// AuthConfig contains the Auth0 configuration passed from the "auth" JSON object.
|
|
||||||
type AuthConfig struct {
|
|
||||||
Domain string `json:"domain"`
|
|
||||||
ClientID string `json:"id"`
|
|
||||||
ClientSecret string `json:"secret"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// JWKS is a structure into which the JSON Web Key Set is unmarshaled.
|
|
||||||
type JWKS struct {
|
|
||||||
Keys []JWK `json:"keys"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// JWK is a structure into which a single JSON Web Key is unmarshaled.
|
|
||||||
type JWK struct {
|
|
||||||
Kty string `json:"kty"`
|
|
||||||
Kid string `json:"kid"`
|
|
||||||
Use string `json:"use"`
|
|
||||||
N string `json:"n"`
|
|
||||||
E string `json:"e"`
|
|
||||||
X5c []string `json:"x5c"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// authCfg is the Auth0 configuration provided at application startup.
|
|
||||||
var authCfg *AuthConfig
|
|
||||||
|
|
||||||
// jwksBytes is a cache of the JSON Web Key Set for this domain.
|
|
||||||
var jwksBytes = make([]byte, 0)
|
|
||||||
|
|
||||||
// getPEMCert is a function to get the applicable certificate for a JSON Web Token.
|
|
||||||
func getPEMCert(token *jwt.Token) (string, error) {
|
|
||||||
cert := ""
|
|
||||||
|
|
||||||
if len(jwksBytes) == 0 {
|
|
||||||
resp, err := http.Get(fmt.Sprintf("https://%s/.well-known/jwks.json", authCfg.Domain))
|
|
||||||
if err != nil {
|
|
||||||
return cert, err
|
|
||||||
}
|
|
||||||
defer resp.Body.Close()
|
|
||||||
|
|
||||||
if jwksBytes, err = ioutil.ReadAll(resp.Body); err != nil {
|
|
||||||
return cert, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
jwks := JWKS{}
|
|
||||||
if err := json.Unmarshal(jwksBytes, &jwks); err != nil {
|
|
||||||
return cert, err
|
|
||||||
}
|
|
||||||
for k, v := range jwks.Keys[0].X5c {
|
|
||||||
if token.Header["kid"] == jwks.Keys[k].Kid {
|
|
||||||
cert = fmt.Sprintf("-----BEGIN CERTIFICATE-----\n%s\n-----END CERTIFICATE-----", v)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if cert == "" {
|
|
||||||
err := errors.New("unable to find appropriate key")
|
|
||||||
return cert, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return cert, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// authZero is an instance of Auth0's JWT middlware. Since it doesn't support the http.HandlerFunc sig, it is wrapped
|
|
||||||
// below; it's defined outside that function, though, so it does not get recreated every time.
|
|
||||||
var authZero = jwtmiddleware.New(jwtmiddleware.Options{
|
|
||||||
ValidationKeyGetter: func(token *jwt.Token) (interface{}, error) {
|
|
||||||
if checkAud := token.Claims.(jwt.MapClaims).VerifyAudience(authCfg.ClientID, false); !checkAud {
|
|
||||||
return token, errors.New("invalid audience")
|
|
||||||
}
|
|
||||||
iss := fmt.Sprintf("https://%s/", authCfg.Domain)
|
|
||||||
if checkIss := token.Claims.(jwt.MapClaims).VerifyIssuer(iss, false); !checkIss {
|
|
||||||
return token, errors.New("invalid issuer")
|
|
||||||
}
|
|
||||||
|
|
||||||
cert, err := getPEMCert(token)
|
|
||||||
if err != nil {
|
|
||||||
panic(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
result, _ := jwt.ParseRSAPublicKeyFromPEM([]byte(cert))
|
|
||||||
return result, nil
|
|
||||||
},
|
|
||||||
SigningMethod: jwt.SigningMethodRS256,
|
|
||||||
})
|
|
||||||
|
|
||||||
// authMiddleware is a wrapper for the Auth0 middleware above with a signature ozzo-routing recognizes.
|
|
||||||
func authMiddleware(c *routing.Context) error {
|
|
||||||
return authZero.CheckJWT(c.Response, c.Request)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRouter returns a configured router to handle all incoming requests.
|
|
||||||
func NewRouter(cfg *AuthConfig) *routing.Router {
|
|
||||||
authCfg = cfg
|
|
||||||
router := routing.New()
|
|
||||||
router.Use(fault.Recovery(log.Printf))
|
|
||||||
for _, route := range routes {
|
|
||||||
if route.IsPublic {
|
|
||||||
router.To(route.Method, route.Pattern, route.Func)
|
|
||||||
} else {
|
|
||||||
router.To(route.Method, route.Pattern, authMiddleware, route.Func)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return router
|
|
||||||
}
|
|
||||||
@@ -1,99 +0,0 @@
|
|||||||
// Package routes contains endpoint handlers for the myPrayerJournal API.
|
|
||||||
package routes
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
routing "github.com/go-ozzo/ozzo-routing"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Route is a route served in the application.
|
|
||||||
type Route struct {
|
|
||||||
Name string
|
|
||||||
Method string
|
|
||||||
Pattern string
|
|
||||||
Func routing.Handler
|
|
||||||
IsPublic bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Routes is the collection of all routes served in the application.
|
|
||||||
type Routes []Route
|
|
||||||
|
|
||||||
// routes is the actual list of routes for the application.
|
|
||||||
var routes = Routes{
|
|
||||||
Route{
|
|
||||||
"Journal",
|
|
||||||
http.MethodGet,
|
|
||||||
"/api/journal/",
|
|
||||||
journal,
|
|
||||||
false,
|
|
||||||
},
|
|
||||||
Route{
|
|
||||||
"AddNewRequest",
|
|
||||||
http.MethodPost,
|
|
||||||
"/api/request/",
|
|
||||||
requestAdd,
|
|
||||||
false,
|
|
||||||
},
|
|
||||||
// Must be above GetRequestByID
|
|
||||||
Route{
|
|
||||||
"GetAnsweredRequests",
|
|
||||||
http.MethodGet,
|
|
||||||
"/api/request/answered",
|
|
||||||
requestsAnswered,
|
|
||||||
false,
|
|
||||||
},
|
|
||||||
Route{
|
|
||||||
"GetRequestByID",
|
|
||||||
http.MethodGet,
|
|
||||||
"/api/request/<id>",
|
|
||||||
requestGet,
|
|
||||||
false,
|
|
||||||
},
|
|
||||||
Route{
|
|
||||||
"GetCompleteRequestByID",
|
|
||||||
http.MethodGet,
|
|
||||||
"/api/request/<id>/complete",
|
|
||||||
requestGetComplete,
|
|
||||||
false,
|
|
||||||
},
|
|
||||||
Route{
|
|
||||||
"GetFullRequestByID",
|
|
||||||
http.MethodGet,
|
|
||||||
"/api/request/<id>/full",
|
|
||||||
requestGetFull,
|
|
||||||
false,
|
|
||||||
},
|
|
||||||
Route{
|
|
||||||
"AddNewHistoryEntry",
|
|
||||||
http.MethodPost,
|
|
||||||
"/api/request/<id>/history",
|
|
||||||
requestAddHistory,
|
|
||||||
false,
|
|
||||||
},
|
|
||||||
Route{
|
|
||||||
"AddNewNote",
|
|
||||||
http.MethodPost,
|
|
||||||
"/api/request/<id>/note",
|
|
||||||
requestAddNote,
|
|
||||||
false,
|
|
||||||
},
|
|
||||||
Route{
|
|
||||||
"GetNotesForRequest",
|
|
||||||
http.MethodGet,
|
|
||||||
"/api/request/<id>/notes",
|
|
||||||
requestGetNotes,
|
|
||||||
false,
|
|
||||||
},
|
|
||||||
// keep this route last
|
|
||||||
Route{
|
|
||||||
"StaticFiles",
|
|
||||||
http.MethodGet,
|
|
||||||
"/*",
|
|
||||||
staticFiles,
|
|
||||||
true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClientPrefixes is a list of known route prefixes handled by the Vue app.
|
|
||||||
var ClientPrefixes = []string{"/answered", "/journal", "/user"}
|
|
||||||
@@ -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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/app/.gitignore
vendored
15
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.js
|
||||||
@@ -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,35 +0,0 @@
|
|||||||
require('./check-versions')()
|
|
||||||
|
|
||||||
process.env.NODE_ENV = 'production'
|
|
||||||
|
|
||||||
var ora = require('ora')
|
|
||||||
var rm = require('rimraf')
|
|
||||||
var path = require('path')
|
|
||||||
var chalk = require('chalk')
|
|
||||||
var webpack = require('webpack')
|
|
||||||
var config = require('../config')
|
|
||||||
var webpackConfig = require('./webpack.prod.conf')
|
|
||||||
|
|
||||||
var spinner = ora('building for production...')
|
|
||||||
spinner.start()
|
|
||||||
|
|
||||||
rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
|
|
||||||
if (err) throw err
|
|
||||||
webpack(webpackConfig, function (err, stats) {
|
|
||||||
spinner.stop()
|
|
||||||
if (err) throw err
|
|
||||||
process.stdout.write(stats.toString({
|
|
||||||
colors: true,
|
|
||||||
modules: false,
|
|
||||||
children: false,
|
|
||||||
chunks: false,
|
|
||||||
chunkModules: false
|
|
||||||
}) + '\n\n')
|
|
||||||
|
|
||||||
console.log(chalk.cyan(' Build complete.\n'))
|
|
||||||
console.log(chalk.yellow(
|
|
||||||
' Tip: built files are meant to be served over an HTTP server.\n' +
|
|
||||||
' Opening index.html over file:// won\'t work.\n'
|
|
||||||
))
|
|
||||||
})
|
|
||||||
})
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
var chalk = require('chalk')
|
|
||||||
var semver = require('semver')
|
|
||||||
var packageConfig = require('../package.json')
|
|
||||||
var shell = require('shelljs')
|
|
||||||
function exec (cmd) {
|
|
||||||
return require('child_process').execSync(cmd).toString().trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
var versionRequirements = [
|
|
||||||
{
|
|
||||||
name: 'node',
|
|
||||||
currentVersion: semver.clean(process.version),
|
|
||||||
versionRequirement: packageConfig.engines.node
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
if (shell.which('npm')) {
|
|
||||||
versionRequirements.push({
|
|
||||||
name: 'npm',
|
|
||||||
currentVersion: exec('npm --version'),
|
|
||||||
versionRequirement: packageConfig.engines.npm
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = function () {
|
|
||||||
var warnings = []
|
|
||||||
for (var i = 0; i < versionRequirements.length; i++) {
|
|
||||||
var mod = versionRequirements[i]
|
|
||||||
if (!semver.satisfies(mod.currentVersion, mod.versionRequirement)) {
|
|
||||||
warnings.push(mod.name + ': ' +
|
|
||||||
chalk.red(mod.currentVersion) + ' should be ' +
|
|
||||||
chalk.green(mod.versionRequirement)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (warnings.length) {
|
|
||||||
console.log('')
|
|
||||||
console.log(chalk.yellow('To use this template, you must update following to modules:'))
|
|
||||||
console.log()
|
|
||||||
for (var i = 0; i < warnings.length; i++) {
|
|
||||||
var warning = warnings[i]
|
|
||||||
console.log(' ' + warning)
|
|
||||||
}
|
|
||||||
console.log()
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
/* eslint-disable */
|
|
||||||
require('eventsource-polyfill')
|
|
||||||
var hotClient = require('webpack-hot-middleware/client?noInfo=true&reload=true')
|
|
||||||
|
|
||||||
hotClient.subscribe(function (event) {
|
|
||||||
if (event.action === 'reload') {
|
|
||||||
window.location.reload()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
require('./check-versions')()
|
|
||||||
|
|
||||||
var config = require('../config')
|
|
||||||
if (!process.env.NODE_ENV) {
|
|
||||||
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV)
|
|
||||||
}
|
|
||||||
|
|
||||||
var opn = require('opn')
|
|
||||||
var path = require('path')
|
|
||||||
var express = require('express')
|
|
||||||
var webpack = require('webpack')
|
|
||||||
var proxyMiddleware = require('http-proxy-middleware')
|
|
||||||
var webpackConfig = process.env.NODE_ENV === 'testing'
|
|
||||||
? require('./webpack.prod.conf')
|
|
||||||
: require('./webpack.dev.conf')
|
|
||||||
|
|
||||||
// default port where dev server listens for incoming traffic
|
|
||||||
var port = process.env.PORT || config.dev.port
|
|
||||||
// automatically open browser, if not set will be false
|
|
||||||
var autoOpenBrowser = !!config.dev.autoOpenBrowser
|
|
||||||
// Define HTTP proxies to your custom API backend
|
|
||||||
// https://github.com/chimurai/http-proxy-middleware
|
|
||||||
var proxyTable = config.dev.proxyTable
|
|
||||||
|
|
||||||
var app = express()
|
|
||||||
var compiler = webpack(webpackConfig)
|
|
||||||
|
|
||||||
var devMiddleware = require('webpack-dev-middleware')(compiler, {
|
|
||||||
publicPath: webpackConfig.output.publicPath,
|
|
||||||
quiet: true
|
|
||||||
})
|
|
||||||
|
|
||||||
var hotMiddleware = require('webpack-hot-middleware')(compiler, {
|
|
||||||
log: () => {},
|
|
||||||
heartbeat: 2000
|
|
||||||
})
|
|
||||||
// force page reload when html-webpack-plugin template changes
|
|
||||||
compiler.plugin('compilation', function (compilation) {
|
|
||||||
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) {
|
|
||||||
hotMiddleware.publish({ action: 'reload' })
|
|
||||||
cb()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
// proxy api requests
|
|
||||||
Object.keys(proxyTable).forEach(function (context) {
|
|
||||||
var options = proxyTable[context]
|
|
||||||
if (typeof options === 'string') {
|
|
||||||
options = { target: options }
|
|
||||||
}
|
|
||||||
app.use(proxyMiddleware(options.filter || context, options))
|
|
||||||
})
|
|
||||||
|
|
||||||
// handle fallback for HTML5 history API
|
|
||||||
app.use(require('connect-history-api-fallback')())
|
|
||||||
|
|
||||||
// serve webpack bundle output
|
|
||||||
app.use(devMiddleware)
|
|
||||||
|
|
||||||
// enable hot-reload and state-preserving
|
|
||||||
// compilation error display
|
|
||||||
app.use(hotMiddleware)
|
|
||||||
|
|
||||||
// serve pure static assets
|
|
||||||
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory)
|
|
||||||
app.use(staticPath, express.static('./static'))
|
|
||||||
|
|
||||||
var uri = 'http://localhost:' + port
|
|
||||||
|
|
||||||
var _resolve
|
|
||||||
var readyPromise = new Promise(resolve => {
|
|
||||||
_resolve = resolve
|
|
||||||
})
|
|
||||||
|
|
||||||
console.log('> Starting dev server...')
|
|
||||||
devMiddleware.waitUntilValid(() => {
|
|
||||||
console.log('> Listening at ' + uri + '\n')
|
|
||||||
// when env is testing, don't need open it
|
|
||||||
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
|
|
||||||
opn(uri)
|
|
||||||
}
|
|
||||||
_resolve()
|
|
||||||
})
|
|
||||||
|
|
||||||
var server = app.listen(port)
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
ready: readyPromise,
|
|
||||||
close: () => {
|
|
||||||
server.close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
var path = require('path')
|
|
||||||
var config = require('../config')
|
|
||||||
var ExtractTextPlugin = require('extract-text-webpack-plugin')
|
|
||||||
|
|
||||||
exports.assetsPath = function (_path) {
|
|
||||||
var assetsSubDirectory = process.env.NODE_ENV === 'production'
|
|
||||||
? config.build.assetsSubDirectory
|
|
||||||
: config.dev.assetsSubDirectory
|
|
||||||
return path.posix.join(assetsSubDirectory, _path)
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.cssLoaders = function (options) {
|
|
||||||
options = options || {}
|
|
||||||
|
|
||||||
var cssLoader = {
|
|
||||||
loader: 'css-loader',
|
|
||||||
options: {
|
|
||||||
minimize: process.env.NODE_ENV === 'production',
|
|
||||||
sourceMap: options.sourceMap
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// generate loader string to be used with extract text plugin
|
|
||||||
function generateLoaders (loader, loaderOptions) {
|
|
||||||
var loaders = [cssLoader]
|
|
||||||
if (loader) {
|
|
||||||
loaders.push({
|
|
||||||
loader: loader + '-loader',
|
|
||||||
options: Object.assign({}, loaderOptions, {
|
|
||||||
sourceMap: options.sourceMap
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract CSS when that option is specified
|
|
||||||
// (which is the case during production build)
|
|
||||||
if (options.extract) {
|
|
||||||
return ExtractTextPlugin.extract({
|
|
||||||
use: loaders,
|
|
||||||
fallback: 'vue-style-loader'
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
return ['vue-style-loader'].concat(loaders)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://vue-loader.vuejs.org/en/configurations/extract-css.html
|
|
||||||
return {
|
|
||||||
css: generateLoaders(),
|
|
||||||
postcss: generateLoaders(),
|
|
||||||
less: generateLoaders('less'),
|
|
||||||
sass: generateLoaders('sass', { indentedSyntax: true }),
|
|
||||||
scss: generateLoaders('sass'),
|
|
||||||
stylus: generateLoaders('stylus'),
|
|
||||||
styl: generateLoaders('stylus')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate loaders for standalone style files (outside of .vue)
|
|
||||||
exports.styleLoaders = function (options) {
|
|
||||||
var output = []
|
|
||||||
var loaders = exports.cssLoaders(options)
|
|
||||||
for (var extension in loaders) {
|
|
||||||
var loader = loaders[extension]
|
|
||||||
output.push({
|
|
||||||
test: new RegExp('\\.' + extension + '$'),
|
|
||||||
use: loader
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
var utils = require('./utils')
|
|
||||||
var config = require('../config')
|
|
||||||
var isProduction = process.env.NODE_ENV === 'production'
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
loaders: utils.cssLoaders({
|
|
||||||
sourceMap: isProduction
|
|
||||||
? config.build.productionSourceMap
|
|
||||||
: config.dev.cssSourceMap,
|
|
||||||
extract: isProduction
|
|
||||||
}),
|
|
||||||
transformToRequire: {
|
|
||||||
video: 'src',
|
|
||||||
source: 'src',
|
|
||||||
img: 'src',
|
|
||||||
image: 'xlink:href'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
var path = require('path')
|
|
||||||
var utils = require('./utils')
|
|
||||||
var config = require('../config')
|
|
||||||
var vueLoaderConfig = require('./vue-loader.conf')
|
|
||||||
|
|
||||||
function resolve (dir) {
|
|
||||||
return path.join(__dirname, '..', dir)
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
entry: {
|
|
||||||
app: './src/main.js'
|
|
||||||
},
|
|
||||||
output: {
|
|
||||||
path: config.build.assetsRoot,
|
|
||||||
filename: '[name].js',
|
|
||||||
publicPath: process.env.NODE_ENV === 'production'
|
|
||||||
? config.build.assetsPublicPath
|
|
||||||
: config.dev.assetsPublicPath
|
|
||||||
},
|
|
||||||
resolve: {
|
|
||||||
extensions: ['.js', '.vue', '.json'],
|
|
||||||
alias: {
|
|
||||||
'vue$': 'vue/dist/vue.esm.js',
|
|
||||||
'@': resolve('src')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
module: {
|
|
||||||
rules: [
|
|
||||||
{
|
|
||||||
test: /\.(js|vue)$/,
|
|
||||||
loader: 'eslint-loader',
|
|
||||||
enforce: 'pre',
|
|
||||||
include: [resolve('src'), resolve('test')],
|
|
||||||
options: {
|
|
||||||
formatter: require('eslint-friendly-formatter')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.vue$/,
|
|
||||||
loader: 'vue-loader',
|
|
||||||
options: vueLoaderConfig
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.js$/,
|
|
||||||
loader: 'babel-loader',
|
|
||||||
include: [resolve('src'), resolve('test')]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
|
|
||||||
loader: 'url-loader',
|
|
||||||
options: {
|
|
||||||
limit: 10000,
|
|
||||||
name: utils.assetsPath('img/[name].[hash:7].[ext]')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
|
|
||||||
loader: 'url-loader',
|
|
||||||
options: {
|
|
||||||
limit: 10000,
|
|
||||||
name: utils.assetsPath('media/[name].[hash:7].[ext]')
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
|
|
||||||
loader: 'url-loader',
|
|
||||||
options: {
|
|
||||||
limit: 10000,
|
|
||||||
name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
var utils = require('./utils')
|
|
||||||
var webpack = require('webpack')
|
|
||||||
var config = require('../config')
|
|
||||||
var merge = require('webpack-merge')
|
|
||||||
var baseWebpackConfig = require('./webpack.base.conf')
|
|
||||||
var HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
||||||
var FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
|
|
||||||
|
|
||||||
// add hot-reload related code to entry chunks
|
|
||||||
Object.keys(baseWebpackConfig.entry).forEach(function (name) {
|
|
||||||
baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name])
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = merge(baseWebpackConfig, {
|
|
||||||
module: {
|
|
||||||
rules: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap })
|
|
||||||
},
|
|
||||||
// cheap-module-eval-source-map is faster for development
|
|
||||||
devtool: '#cheap-module-eval-source-map',
|
|
||||||
plugins: [
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
'process.env': config.dev.env
|
|
||||||
}),
|
|
||||||
// https://github.com/glenjamin/webpack-hot-middleware#installation--usage
|
|
||||||
new webpack.HotModuleReplacementPlugin(),
|
|
||||||
new webpack.NoEmitOnErrorsPlugin(),
|
|
||||||
// https://github.com/ampedandwired/html-webpack-plugin
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
filename: 'index.html',
|
|
||||||
template: 'index.html',
|
|
||||||
inject: true
|
|
||||||
}),
|
|
||||||
new FriendlyErrorsPlugin()
|
|
||||||
]
|
|
||||||
})
|
|
||||||
@@ -1,125 +0,0 @@
|
|||||||
var path = require('path')
|
|
||||||
var utils = require('./utils')
|
|
||||||
var webpack = require('webpack')
|
|
||||||
var config = require('../config')
|
|
||||||
var merge = require('webpack-merge')
|
|
||||||
var baseWebpackConfig = require('./webpack.base.conf')
|
|
||||||
var CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
||||||
var HtmlWebpackPlugin = require('html-webpack-plugin')
|
|
||||||
var ExtractTextPlugin = require('extract-text-webpack-plugin')
|
|
||||||
var OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
|
|
||||||
|
|
||||||
var env = process.env.NODE_ENV === 'testing'
|
|
||||||
? require('../config/test.env')
|
|
||||||
: config.build.env
|
|
||||||
|
|
||||||
var webpackConfig = merge(baseWebpackConfig, {
|
|
||||||
module: {
|
|
||||||
rules: utils.styleLoaders({
|
|
||||||
sourceMap: config.build.productionSourceMap,
|
|
||||||
extract: true
|
|
||||||
}),
|
|
||||||
noParse: [/moment.js/]
|
|
||||||
},
|
|
||||||
devtool: config.build.productionSourceMap ? '#source-map' : false,
|
|
||||||
output: {
|
|
||||||
path: config.build.assetsRoot,
|
|
||||||
filename: utils.assetsPath('js/[name].[chunkhash].js'),
|
|
||||||
chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
// http://vuejs.github.io/vue-loader/en/workflow/production.html
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
'process.env': env
|
|
||||||
}),
|
|
||||||
new webpack.optimize.UglifyJsPlugin({
|
|
||||||
compress: {
|
|
||||||
warnings: false
|
|
||||||
},
|
|
||||||
sourceMap: true
|
|
||||||
}),
|
|
||||||
// extract css into its own file
|
|
||||||
new ExtractTextPlugin({
|
|
||||||
filename: utils.assetsPath('css/[name].[contenthash].css')
|
|
||||||
}),
|
|
||||||
// Compress extracted CSS. We are using this plugin so that possible
|
|
||||||
// duplicated CSS from different components can be deduped.
|
|
||||||
new OptimizeCSSPlugin({
|
|
||||||
cssProcessorOptions: {
|
|
||||||
safe: true
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
// generate dist index.html with correct asset hash for caching.
|
|
||||||
// you can customize output by editing /index.html
|
|
||||||
// see https://github.com/ampedandwired/html-webpack-plugin
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
filename: process.env.NODE_ENV === 'testing'
|
|
||||||
? 'index.html'
|
|
||||||
: config.build.index,
|
|
||||||
template: 'index.html',
|
|
||||||
inject: true,
|
|
||||||
minify: {
|
|
||||||
removeComments: true,
|
|
||||||
collapseWhitespace: true,
|
|
||||||
removeAttributeQuotes: true
|
|
||||||
// more options:
|
|
||||||
// https://github.com/kangax/html-minifier#options-quick-reference
|
|
||||||
},
|
|
||||||
// necessary to consistently work with multiple chunks via CommonsChunkPlugin
|
|
||||||
chunksSortMode: 'dependency'
|
|
||||||
}),
|
|
||||||
// split vendor js into its own file
|
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
|
||||||
name: 'vendor',
|
|
||||||
minChunks: function (module, count) {
|
|
||||||
// any required modules inside node_modules are extracted to vendor
|
|
||||||
return (
|
|
||||||
module.resource &&
|
|
||||||
/\.js$/.test(module.resource) &&
|
|
||||||
module.resource.indexOf(
|
|
||||||
path.join(__dirname, '../node_modules')
|
|
||||||
) === 0
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
// extract webpack runtime and module manifest to its own file in order to
|
|
||||||
// prevent vendor hash from being updated whenever app bundle is updated
|
|
||||||
new webpack.optimize.CommonsChunkPlugin({
|
|
||||||
name: 'manifest',
|
|
||||||
chunks: ['vendor']
|
|
||||||
}),
|
|
||||||
// copy custom static assets
|
|
||||||
new CopyWebpackPlugin([
|
|
||||||
{
|
|
||||||
from: path.resolve(__dirname, '../static'),
|
|
||||||
to: config.build.assetsSubDirectory,
|
|
||||||
ignore: ['.*']
|
|
||||||
}
|
|
||||||
])
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
if (config.build.productionGzip) {
|
|
||||||
var CompressionWebpackPlugin = require('compression-webpack-plugin')
|
|
||||||
|
|
||||||
webpackConfig.plugins.push(
|
|
||||||
new CompressionWebpackPlugin({
|
|
||||||
asset: '[path].gz[query]',
|
|
||||||
algorithm: 'gzip',
|
|
||||||
test: new RegExp(
|
|
||||||
'\\.(' +
|
|
||||||
config.build.productionGzipExtensions.join('|') +
|
|
||||||
')$'
|
|
||||||
),
|
|
||||||
threshold: 10240,
|
|
||||||
minRatio: 0.8
|
|
||||||
})
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.build.bundleAnalyzerReport) {
|
|
||||||
var BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
|
|
||||||
webpackConfig.plugins.push(new BundleAnalyzerPlugin())
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = webpackConfig
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
// This is the webpack config used for unit tests.
|
|
||||||
|
|
||||||
var utils = require('./utils')
|
|
||||||
var webpack = require('webpack')
|
|
||||||
var merge = require('webpack-merge')
|
|
||||||
var baseConfig = require('./webpack.base.conf')
|
|
||||||
|
|
||||||
var webpackConfig = merge(baseConfig, {
|
|
||||||
// use inline sourcemap for karma-sourcemap-loader
|
|
||||||
module: {
|
|
||||||
rules: utils.styleLoaders()
|
|
||||||
},
|
|
||||||
devtool: '#inline-source-map',
|
|
||||||
resolveLoader: {
|
|
||||||
alias: {
|
|
||||||
// necessary to to make lang="scss" work in test when using vue-loader's ?inject option
|
|
||||||
// see discussion at https://github.com/vuejs/vue-loader/issues/724
|
|
||||||
'scss-loader': 'sass-loader'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
plugins: [
|
|
||||||
new webpack.DefinePlugin({
|
|
||||||
'process.env': require('../config/test.env')
|
|
||||||
})
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
// no need for app entry during tests
|
|
||||||
delete webpackConfig.entry
|
|
||||||
|
|
||||||
module.exports = webpackConfig
|
|
||||||
@@ -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, '../../public/index.html'),
|
|
||||||
assetsRoot: path.resolve(__dirname, '../../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,107 +1,33 @@
|
|||||||
{
|
{
|
||||||
"name": "my-prayer-journal",
|
"name": "my-prayer-journal",
|
||||||
"version": "0.9.5",
|
"version": "1.0.0",
|
||||||
"description": "myPrayerJournal - Front End",
|
"description": "myPrayerJournal - Front End",
|
||||||
"author": "Daniel J. Summers <daniel@bitbadger.solutions>",
|
"author": "Daniel J. Summers <daniel@bitbadger.solutions>",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "node build/dev-server.js",
|
"serve": "vue-cli-service serve",
|
||||||
"start": "node build/dev-server.js",
|
"build": "vue-cli-service build",
|
||||||
"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 ../api/MyPrayerJournal.Api && dotnet run",
|
||||||
"e2e": "node test/e2e/runner.js",
|
"vue": "vue-cli-service build --modern && cd ../api/MyPrayerJournal.Api && dotnet run"
|
||||||
"test": "npm run unit && npm run e2e",
|
|
||||||
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs",
|
|
||||||
"apistart": "cd .. && go build -o mpj-api.exe && mpj-api.exe",
|
|
||||||
"vue": "node build/build.js prod && cd .. && go build -o mpj-api.exe && mpj-api.exe"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"auth0-js": "^9.3.3",
|
"auth0-js": "^9.7.3",
|
||||||
"axios": "^0.18.0",
|
"axios": "^0.18.0",
|
||||||
"bootstrap": "^4.0.0",
|
|
||||||
"bootstrap-vue": "^1.0.0-beta.9",
|
|
||||||
"moment": "^2.18.1",
|
"moment": "^2.18.1",
|
||||||
"pug": "^2.0.1",
|
|
||||||
"vue": "^2.5.15",
|
"vue": "^2.5.15",
|
||||||
"vue-awesome": "^2.3.3",
|
|
||||||
"vue-progressbar": "^0.7.3",
|
"vue-progressbar": "^0.7.3",
|
||||||
"vue-router": "^3.0.0",
|
"vue-router": "^3.0.0",
|
||||||
"vue-toast": "^3.1.0",
|
"vue-toast": "^3.1.0",
|
||||||
"vuex": "^3.0.0"
|
"vuex": "^3.0.1"
|
||||||
},
|
},
|
||||||
"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": "^3.0.0",
|
||||||
"babel-plugin-istanbul": "^4.1.5",
|
"pug": "^2.0.1",
|
||||||
"babel-plugin-transform-runtime": "^6.22.0",
|
"pug-plain-loader": "^1.0.0",
|
||||||
"babel-preset-env": "^1.3.2",
|
"vue-template-compiler": "^2.5.17"
|
||||||
"babel-preset-stage-2": "^6.22.0",
|
}
|
||||||
"babel-register": "^6.26.0",
|
|
||||||
"chai": "^3.5.0",
|
|
||||||
"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,25 +1,25 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
#app
|
#app(role='application')
|
||||||
navigation
|
navigation
|
||||||
#content.container
|
#content
|
||||||
router-view
|
router-view
|
||||||
vue-progress-bar
|
vue-progress-bar
|
||||||
toast(ref='toast')
|
toast(ref='toast')
|
||||||
footer
|
footer.mpj-text-right.mpj-muted-text
|
||||||
p.text-right.text-muted
|
p
|
||||||
| myPrayerJournal v{{ version }}
|
| myPrayerJournal v{{ version }}
|
||||||
br
|
br
|
||||||
em: small.
|
em: small.
|
||||||
#[router-link(:to="{ name: 'PrivacyPolicy' }") Privacy Policy] •
|
#[router-link(:to="{ name: 'PrivacyPolicy' }") Privacy Policy] •
|
||||||
#[router-link(:to="{ name: 'TermsOfService' }") Terms of Service] •
|
#[router-link(:to="{ name: 'TermsOfService' }") Terms of Service] •
|
||||||
#[a(href='https://github.com/danieljsummers/myprayerjournal') Developed] and hosted by
|
#[a(href='https://github.com/bit-badger/myprayerjournal' target='_blank') Developed] and hosted by
|
||||||
#[a(href='https://bitbadger.solutions') Bit Badger Solutions]
|
#[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 Navigation from './components/common/Navigation.vue'
|
||||||
|
|
||||||
import { version } from '../package.json'
|
import { version } from '../package.json'
|
||||||
|
|
||||||
@@ -29,7 +29,7 @@ export default {
|
|||||||
Navigation
|
Navigation
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return { version }
|
return {}
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
this.$refs.toast.setOptions({ position: 'bottom right' })
|
this.$refs.toast.setOptions({ position: 'bottom right' })
|
||||||
@@ -37,6 +37,9 @@ export default {
|
|||||||
computed: {
|
computed: {
|
||||||
toast () {
|
toast () {
|
||||||
return this.$refs.toast
|
return this.$refs.toast
|
||||||
|
},
|
||||||
|
version () {
|
||||||
|
return version.endsWith('.0') ? version.substr(0, version.length - 2) : version
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -45,9 +48,76 @@ export default {
|
|||||||
<style>
|
<style>
|
||||||
html, body {
|
html, body {
|
||||||
background-color: whitesmoke;
|
background-color: whitesmoke;
|
||||||
|
font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
|
||||||
|
font-size: 1rem;
|
||||||
}
|
}
|
||||||
body {
|
body {
|
||||||
padding-top: 60px;
|
padding-top: 50px;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
h1, h2, h3, h4, h5 {
|
||||||
|
font-weight: 500;
|
||||||
|
margin-top: 0;
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
font-size: 2.5rem;
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
font-size: 2rem;
|
||||||
|
}
|
||||||
|
h3 {
|
||||||
|
font-size: 1.75rem;
|
||||||
|
}
|
||||||
|
h4 {
|
||||||
|
font-size: 1.5rem;
|
||||||
|
}
|
||||||
|
h5 {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
}
|
||||||
|
p {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
input, textarea, select {
|
||||||
|
border-radius: .25rem;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
textarea {
|
||||||
|
font-family: "SFMono-Regular",Consolas,"Liberation Mono",Menlo,Courier,monospace;
|
||||||
|
}
|
||||||
|
input, select {
|
||||||
|
font-family: inherit;
|
||||||
|
}
|
||||||
|
button,
|
||||||
|
a[role="button"] {
|
||||||
|
border: solid 1px #050;
|
||||||
|
border-radius: .5rem;
|
||||||
|
background-color: rgb(235, 235, 235);
|
||||||
|
padding: .25rem;
|
||||||
|
font-size: 1rem;
|
||||||
|
}
|
||||||
|
a[role="button"]:link,
|
||||||
|
a[role="button"]:visited {
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
button.primary,
|
||||||
|
a[role="button"].primary {
|
||||||
|
background-color: white;
|
||||||
|
border-width: 3px;
|
||||||
|
}
|
||||||
|
button:hover,
|
||||||
|
a[role="button"]:hover {
|
||||||
|
cursor: pointer;
|
||||||
|
background-color: #050;
|
||||||
|
color: white;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
label {
|
||||||
|
font-variant: small-caps;
|
||||||
|
font-size: 1.1rem;
|
||||||
|
}
|
||||||
|
label.normal {
|
||||||
|
font-variant: unset;
|
||||||
|
font-size: unset;
|
||||||
}
|
}
|
||||||
footer {
|
footer {
|
||||||
border-top: solid 1px lightgray;
|
border-top: solid 1px lightgray;
|
||||||
@@ -59,14 +129,116 @@ footer p {
|
|||||||
}
|
}
|
||||||
a:link, a:visited {
|
a:link, a:visited {
|
||||||
color: #050;
|
color: #050;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
.mpj-main-content {
|
||||||
|
max-width: 60rem;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
.mpj-main-content-wide {
|
||||||
|
margin: .5rem;
|
||||||
|
}
|
||||||
|
@media screen and (max-width: 21rem) {
|
||||||
|
.mpj-main-content-wide {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.mpj-request-text {
|
.mpj-request-text {
|
||||||
white-space: pre-line;
|
white-space: pre-line;
|
||||||
}
|
}
|
||||||
.bg-mpj {
|
.mpj-request-list p {
|
||||||
|
border-top: solid 1px lightgray;
|
||||||
|
}
|
||||||
|
.mpj-request-list p:first-child {
|
||||||
|
border-top: none;
|
||||||
|
}
|
||||||
|
.mpj-request-log {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.mpj-request-log thead th {
|
||||||
|
border-top: solid 1px lightgray;
|
||||||
|
border-bottom: solid 2px lightgray;
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
.mpj-request-log tbody td {
|
||||||
|
border-bottom: dotted 1px lightgray;
|
||||||
|
vertical-align: top;
|
||||||
|
}
|
||||||
|
.mpj-bg {
|
||||||
background-image: -webkit-gradient(linear, left top, left bottom, from(#050), to(whitesmoke));
|
background-image: -webkit-gradient(linear, left top, left bottom, from(#050), to(whitesmoke));
|
||||||
background-image: -webkit-linear-gradient(top, #050, whitesmoke);
|
background-image: -webkit-linear-gradient(top, #050, whitesmoke);
|
||||||
background-image: -moz-linear-gradient(top, #050, whitesmoke);
|
background-image: -moz-linear-gradient(top, #050, whitesmoke);
|
||||||
background-image: linear-gradient(to bottom, #050, whitesmoke);
|
background-image: linear-gradient(to bottom, #050, whitesmoke);
|
||||||
}
|
}
|
||||||
|
.mpj-text-center {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
.mpj-text-nowrap {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
.mpj-text-right {
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
.mpj-muted-text {
|
||||||
|
color: rgba(0, 0, 0, .6);
|
||||||
|
}
|
||||||
|
.mpj-narrow {
|
||||||
|
max-width: 40rem;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
.mpj-skinny {
|
||||||
|
max-width: 20rem;
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
.mpj-full-width {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.mpj-modal {
|
||||||
|
position: fixed;
|
||||||
|
z-index: 8;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
overflow: auto;
|
||||||
|
background-color: rgba(0, 0, 0, .4);
|
||||||
|
}
|
||||||
|
.mpj-modal-content {
|
||||||
|
background-color: whitesmoke;
|
||||||
|
border: solid 1px #050;
|
||||||
|
border-radius: .5rem;
|
||||||
|
animation-name: animatetop;
|
||||||
|
animation-duration: 0.4s;
|
||||||
|
padding: 1rem;
|
||||||
|
margin-top: 4rem;
|
||||||
|
}
|
||||||
|
@keyframes animatetop {
|
||||||
|
from {
|
||||||
|
top: -300px;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
top: 0;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.mpj-modal-content header {
|
||||||
|
margin: -1rem -1rem .5rem;
|
||||||
|
border-radius: .4rem;
|
||||||
|
}
|
||||||
|
.mpj-modal-content header h5 {
|
||||||
|
color: white;
|
||||||
|
margin: 0;
|
||||||
|
padding: 1rem;
|
||||||
|
}
|
||||||
|
.mpj-margin {
|
||||||
|
margin-left: 1rem;
|
||||||
|
margin-right: 1rem;
|
||||||
|
}
|
||||||
|
.material-icons {
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
|
||||||
const http = axios.create({
|
const http = axios.create({
|
||||||
@@ -30,16 +32,18 @@ export default {
|
|||||||
/**
|
/**
|
||||||
* 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 }),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all answered requests, along with the text they had when it was answered
|
* Get all answered requests, along with the text they had when it was answered
|
||||||
*/
|
*/
|
||||||
getAnsweredRequests: () => http.get('request/answered'),
|
getAnsweredRequests: () => http.get('requests/answered'),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a prayer request (full; includes all history)
|
* Get a prayer request (full; includes all history and notes)
|
||||||
* @param {string} requestId The Id of the request to retrieve
|
* @param {string} requestId The Id of the request to retrieve
|
||||||
*/
|
*/
|
||||||
getFullRequest: requestId => http.get(`request/${requestId}/full`),
|
getFullRequest: requestId => http.get(`request/${requestId}/full`),
|
||||||
@@ -56,23 +60,39 @@ export default {
|
|||||||
*/
|
*/
|
||||||
getRequest: requestId => http.get(`request/${requestId}`),
|
getRequest: requestId => http.get(`request/${requestId}`),
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a complete request; equivalent of "full" and "notes" combined
|
|
||||||
*/
|
|
||||||
getRequestComplete: requestId => http.get(`request/${requestId}/complete`),
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all prayer requests and their most recent updates
|
* Get all prayer requests and their most recent updates
|
||||||
*/
|
*/
|
||||||
journal: () => http.get('journal/'),
|
journal: () => http.get('journal'),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show a request after the given date (used for "show now")
|
||||||
|
* @param {string} requestId The ID of the request which should be shown
|
||||||
|
* @param {number} showAfter The ticks after which the request should be shown
|
||||||
|
*/
|
||||||
|
showRequest: (requestId, showAfter) => http.patch(`request/${requestId}/show`, { showAfter }),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Snooze a request until the given time
|
||||||
|
* @param {string} requestId The ID of the prayer request to be snoozed
|
||||||
|
* @param {number} until The ticks until which the request should be snoozed
|
||||||
|
*/
|
||||||
|
snoozeRequest: (requestId, until) => http.patch(`request/${requestId}/snooze`, { until }),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update recurrence for a prayer request
|
||||||
|
* @param {string} requestId The ID of the prayer request for which recurrence is being updated
|
||||||
|
* @param {string} recurType The type of recurrence to set
|
||||||
|
* @param {number} recurCount The number of recurrence intervals to set
|
||||||
|
*/
|
||||||
|
updateRecurrence: (requestId, recurType, recurCount) =>
|
||||||
|
http.patch(`request/${requestId}/recurrence`, { recurType, recurCount }),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a prayer request
|
* Update a prayer request
|
||||||
* @param request The request (should have requestId, status, and updateText properties)
|
* @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: request => http.post(`request/${request.requestId}/history`, {
|
updateRequest: (requestId, status, updateText) => http.post(`request/${requestId}/history`, { status, updateText })
|
||||||
status: request.status,
|
|
||||||
updateText: request.updateText
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import mutations from '@/store/mutation-types'
|
|||||||
var tokenRenewalTimeout
|
var tokenRenewalTimeout
|
||||||
|
|
||||||
export default class AuthService {
|
export default class AuthService {
|
||||||
|
|
||||||
constructor () {
|
constructor () {
|
||||||
this.login = this.login.bind(this)
|
this.login = this.login.bind(this)
|
||||||
this.setSession = this.setSession.bind(this)
|
this.setSession = this.setSession.bind(this)
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
article
|
|
||||||
page-title(title='Answered Request')
|
|
||||||
p(v-if='!request') Loading request...
|
|
||||||
template(v-if='request')
|
|
||||||
p.
|
|
||||||
Answered {{ formatDate(answered) }} (#[date-from-now(:value='answered')])
|
|
||||||
#[small: em.text-muted prayed {{ prayedCount }} times, open {{ openDays }} days]
|
|
||||||
p.mpj-request-text {{ lastText }}
|
|
||||||
b-table(small hover :fields='fields' :items='log')
|
|
||||||
template(slot='action' scope='data').
|
|
||||||
{{ data.item.status }} on #[span.text-nowrap {{ formatDate(data.item.asOf) }}]
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
'use strict'
|
|
||||||
|
|
||||||
import moment from 'moment'
|
|
||||||
|
|
||||||
import api from '@/api'
|
|
||||||
|
|
||||||
const asOfDesc = (a, b) => b.asOf - a.asOf
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'answer-detail',
|
|
||||||
props: {
|
|
||||||
id: {
|
|
||||||
type: String,
|
|
||||||
required: true
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
request: null,
|
|
||||||
fields: [
|
|
||||||
{ key: 'action', label: 'Action' },
|
|
||||||
{ key: 'text', label: 'Update / Notes' }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
answered () {
|
|
||||||
return this.request.history.find(hist => hist.status === 'Answered').asOf
|
|
||||||
},
|
|
||||||
lastText () {
|
|
||||||
return this.request.history
|
|
||||||
.filter(hist => hist.text > '')
|
|
||||||
.sort(asOfDesc)[0].text
|
|
||||||
},
|
|
||||||
log () {
|
|
||||||
return (this.request.notes || [])
|
|
||||||
.map(note => ({ asOf: note.asOf, text: note.notes, status: 'Notes' }))
|
|
||||||
.concat(this.request.history)
|
|
||||||
.sort(asOfDesc)
|
|
||||||
.slice(1)
|
|
||||||
},
|
|
||||||
openDays () {
|
|
||||||
return Math.floor(
|
|
||||||
(this.answered - this.request.history.find(hist => hist.status === 'Created').asOf) / 1000 / 60 / 60 / 24)
|
|
||||||
},
|
|
||||||
prayedCount () {
|
|
||||||
return this.request.history.filter(hist => hist.status === 'Prayed').length
|
|
||||||
}
|
|
||||||
},
|
|
||||||
async mounted () {
|
|
||||||
this.$Progress.start()
|
|
||||||
try {
|
|
||||||
const req = await api.getRequestComplete(this.id)
|
|
||||||
this.request = req.data
|
|
||||||
this.$Progress.finish()
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e)
|
|
||||||
this.$Progress.fail()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
formatDate (asOf) {
|
|
||||||
return moment(asOf).format('LL')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
article
|
article.mpj-main-content(role='main')
|
||||||
page-title(title='Welcome!'
|
page-title(title='Welcome!'
|
||||||
hideOnPage='true')
|
hideOnPage='true')
|
||||||
p
|
p
|
||||||
|
|||||||
@@ -1,23 +1,25 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
article
|
article.mpj-main-content-wide(role='main')
|
||||||
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
|
.mpj-text-center
|
||||||
|
router-link(:to="{ name: 'EditRequest', params: { id: 'new' } }"
|
||||||
|
role='button').
|
||||||
|
#[md-icon(icon='add_box')] Add a New Request
|
||||||
br
|
br
|
||||||
b-row(v-if='journal.length > 0')
|
.mpj-journal(v-if='journal.length > 0')
|
||||||
request-card(v-for='request in journal'
|
request-card(v-for='request in journal'
|
||||||
:key='request.requestId'
|
:key='request.requestId'
|
||||||
:request='request'
|
:request='request'
|
||||||
:events='eventBus'
|
:events='eventBus'
|
||||||
:toast='toast')
|
:toast='toast')
|
||||||
p.text-center(v-if='journal.length === 0'): em.
|
p.text-center(v-else): em.
|
||||||
No requests found; click the “Add a New Request” button to add one
|
No requests found; click the “Add a New Request” button to add one
|
||||||
edit-request(:events='eventBus'
|
|
||||||
:toast='toast')
|
|
||||||
notes-edit(:events='eventBus'
|
notes-edit(:events='eventBus'
|
||||||
:toast='toast')
|
:toast='toast')
|
||||||
full-request(:events='eventBus')
|
snooze-request(:events='eventBus'
|
||||||
|
:toast='toast')
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -25,24 +27,19 @@ 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 FullRequest from './request/FullRequest'
|
|
||||||
import NewRequest from './request/NewRequest'
|
|
||||||
import NotesEdit from './request/NotesEdit'
|
import NotesEdit from './request/NotesEdit'
|
||||||
import RequestCard from './request/RequestCard'
|
import RequestCard from './request/RequestCard'
|
||||||
|
import SnoozeRequest from './request/SnoozeRequest'
|
||||||
|
|
||||||
import actions from '@/store/action-types'
|
import actions from '@/store/action-types'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'journal',
|
name: 'journal',
|
||||||
components: {
|
components: {
|
||||||
EditRequest,
|
|
||||||
FullRequest,
|
|
||||||
NewRequest,
|
|
||||||
NotesEdit,
|
NotesEdit,
|
||||||
RequestCard
|
RequestCard,
|
||||||
|
SnoozeRequest
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
@@ -53,9 +50,6 @@ export default {
|
|||||||
title () {
|
title () {
|
||||||
return `${this.user.given_name}’s Prayer Journal`
|
return `${this.user.given_name}’s Prayer Journal`
|
||||||
},
|
},
|
||||||
journalCardRows () {
|
|
||||||
return chunk(this.journal, 3)
|
|
||||||
},
|
|
||||||
toast () {
|
toast () {
|
||||||
return this.$parent.$refs.toast
|
return this.$parent.$refs.toast
|
||||||
},
|
},
|
||||||
@@ -67,3 +61,12 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.mpj-journal {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row wrap;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: flex-start;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -1,49 +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-navbar-nav
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
...mapState([ 'isAuthenticated' ])
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
logOn () {
|
|
||||||
this.auth0.login()
|
|
||||||
},
|
|
||||||
logOff () {
|
|
||||||
this.auth0.logout(this.$store, this.$router)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
15
src/app/src/components/common/MaterialDesignIcon.vue
Normal file
15
src/app/src/components/common/MaterialDesignIcon.vue
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
i.material-icons(v-html='icon')
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
name: 'md-icon',
|
||||||
|
props: {
|
||||||
|
icon: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
96
src/app/src/components/common/Navigation.vue
Normal file
96
src/app/src/components/common/Navigation.vue
Normal file
@@ -0,0 +1,96 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
nav.mpj-top-nav.mpj-bg(role='menubar')
|
||||||
|
router-link.title(:to="{ name: 'Home' }"
|
||||||
|
role='menuitem')
|
||||||
|
span(style='font-weight:100;') my
|
||||||
|
span(style='font-weight:600;') Prayer
|
||||||
|
span(style='font-weight:700;') Journal
|
||||||
|
router-link(v-if='isAuthenticated'
|
||||||
|
:to="{ name: 'Journal' }"
|
||||||
|
role='menuitem') Journal
|
||||||
|
router-link(v-if='isAuthenticated'
|
||||||
|
:to="{ name: 'ActiveRequests' }"
|
||||||
|
role='menuitem') Active
|
||||||
|
router-link(v-if='hasSnoozed'
|
||||||
|
:to="{ name: 'SnoozedRequests' }"
|
||||||
|
role='menuitem') Snoozed
|
||||||
|
router-link(v-if='isAuthenticated'
|
||||||
|
:to="{ name: 'AnsweredRequests' }"
|
||||||
|
role='menuitem') Answered
|
||||||
|
a(v-if='isAuthenticated'
|
||||||
|
href='#'
|
||||||
|
role='menuitem'
|
||||||
|
@click.stop='logOff()') Log Off
|
||||||
|
a(v-if='!isAuthenticated'
|
||||||
|
href='#'
|
||||||
|
role='menuitem'
|
||||||
|
@click.stop='logOn()') Log On
|
||||||
|
a(href='https://bit-badger.github.io/myPrayerJournal/'
|
||||||
|
target='_blank'
|
||||||
|
role='menuitem'
|
||||||
|
@click.stop='') Docs
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import { mapState } from 'vuex'
|
||||||
|
|
||||||
|
import AuthService from '@/auth/AuthService'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'navigation',
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
auth0: new AuthService()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
hasSnoozed () {
|
||||||
|
return this.isAuthenticated &&
|
||||||
|
Array.isArray(this.journal) &&
|
||||||
|
this.journal.filter(req => req.snoozedUntil > Date.now()).length > 0
|
||||||
|
},
|
||||||
|
...mapState([ 'journal', 'isAuthenticated' ])
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
logOn () {
|
||||||
|
this.auth0.login()
|
||||||
|
},
|
||||||
|
logOff () {
|
||||||
|
this.auth0.logout(this.$store, this.$router)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.mpj-top-nav {
|
||||||
|
position: fixed;
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row wrap;
|
||||||
|
align-items: center;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
padding-left: .5rem;
|
||||||
|
min-height: 50px;
|
||||||
|
}
|
||||||
|
.mpj-top-nav a:link,
|
||||||
|
.mpj-top-nav a:visited {
|
||||||
|
text-decoration: none;
|
||||||
|
color: rgba(255, 255, 255, .75);
|
||||||
|
padding-left: 1rem;
|
||||||
|
}
|
||||||
|
.mpj-top-nav a:link.router-link-active,
|
||||||
|
.mpj-top-nav a:visited.router-link-active,
|
||||||
|
.mpj-top-nav a:hover {
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
.mpj-top-nav .title {
|
||||||
|
font-size: 1.25rem;
|
||||||
|
color: white;
|
||||||
|
padding-left: 1.25rem;
|
||||||
|
padding-right: 1.25rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
59
src/app/src/components/request/ActiveRequests.vue
Normal file
59
src/app/src/components/request/ActiveRequests.vue
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
article.mpj-main-content(role='main')
|
||||||
|
page-title(title='Active Requests')
|
||||||
|
div(v-if='loaded').mpj-request-list
|
||||||
|
p.mpj-text-center(v-if='requests.length === 0'): em.
|
||||||
|
No active requests found; return to #[router-link(:to='{ name: "Journal" } ') your journal]
|
||||||
|
request-list-item(v-for='req in requests'
|
||||||
|
:key='req.requestId'
|
||||||
|
:request='req'
|
||||||
|
:toast='toast')
|
||||||
|
p(v-else) Loading journal...
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import { mapState } from 'vuex'
|
||||||
|
|
||||||
|
import RequestListItem from '@/components/request/RequestListItem'
|
||||||
|
|
||||||
|
import actions from '@/store/action-types'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'active-requests',
|
||||||
|
components: {
|
||||||
|
RequestListItem
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
requests: [],
|
||||||
|
loaded: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
toast () {
|
||||||
|
return this.$parent.$refs.toast
|
||||||
|
},
|
||||||
|
...mapState(['journal', 'isLoadingJournal'])
|
||||||
|
},
|
||||||
|
created () {
|
||||||
|
this.$on('requestUnsnoozed', this.ensureJournal)
|
||||||
|
this.$on('requestNowShown', this.ensureJournal)
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async ensureJournal () {
|
||||||
|
if (!Array.isArray(this.journal)) {
|
||||||
|
this.loaded = false
|
||||||
|
await this.$store.dispatch(actions.LOAD_JOURNAL, this.$Progress)
|
||||||
|
}
|
||||||
|
this.requests = this.journal
|
||||||
|
.sort((a, b) => a.showAfter - b.showAfter)
|
||||||
|
this.loaded = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async mounted () {
|
||||||
|
await this.ensureJournal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -1,30 +1,28 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
article
|
article.mpj-main-content(role='main')
|
||||||
page-title(title='Answered Requests')
|
page-title(title='Answered Requests')
|
||||||
p(v-if='!loaded') Loading answered requests...
|
div(v-if='loaded').mpj-request-list
|
||||||
div(v-if='loaded').mpj-answered-list
|
|
||||||
p.text-center(v-if='requests.length === 0'): em.
|
p.text-center(v-if='requests.length === 0'): em.
|
||||||
No answered requests found; once you have marked one as “Answered”, it will appear here
|
No answered requests found; once you have marked one as “Answered”, it will appear here
|
||||||
p.mpj-request-text(v-for='req in requests' :key='req.requestId')
|
request-list-item(v-for='req in requests'
|
||||||
| {{ req.text }}
|
:key='req.requestId'
|
||||||
br
|
:request='req'
|
||||||
br
|
:toast='toast')
|
||||||
b-btn(:to='{ name: "AnsweredDetail", params: { id: req.requestId }}'
|
p(v-else) Loading answered requests...
|
||||||
size='sm'
|
|
||||||
variant='outline-secondary')
|
|
||||||
icon(name='search')
|
|
||||||
= ' View Full Request'
|
|
||||||
small.text-muted: em.
|
|
||||||
Answered #[date-from-now(:value='req.asOf')]
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
'use static'
|
'use strict'
|
||||||
|
|
||||||
import api from '@/api'
|
import api from '@/api'
|
||||||
|
|
||||||
|
import RequestListItem from '@/components/request/RequestListItem'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'answered',
|
name: 'answered-requests',
|
||||||
|
components: {
|
||||||
|
RequestListItem
|
||||||
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
requests: [],
|
requests: [],
|
||||||
@@ -52,12 +50,3 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
|
||||||
.mpj-answered-list p {
|
|
||||||
border-top: solid 1px lightgray;
|
|
||||||
}
|
|
||||||
.mpj-answered-list p:first-child {
|
|
||||||
border-top: none;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -1,89 +1,204 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
b-modal(v-model='editVisible'
|
article.mpj-main-content(role='main')
|
||||||
header-bg-variant='mpj'
|
page-title(:title='title')
|
||||||
header-text-variant='light'
|
.mpj-narrow
|
||||||
size='lg'
|
label(for='request_text')
|
||||||
title='Edit Prayer Request'
|
| Prayer Request
|
||||||
@edit='openDialog()'
|
br
|
||||||
@shows='focusRequestText')
|
textarea(v-model='form.requestText'
|
||||||
b-form
|
|
||||||
b-form-group(label='Prayer Request'
|
|
||||||
label-for='request_text')
|
|
||||||
b-textarea#request_text(ref='toFocus'
|
|
||||||
v-model='form.requestText'
|
|
||||||
:rows='10'
|
:rows='10'
|
||||||
@blur='trimText()')
|
@blur='trimText()'
|
||||||
b-form-group(label='Also Mark As')
|
autofocus).mpj-full-width
|
||||||
b-radio-group(v-model='form.status'
|
br
|
||||||
buttons)
|
template(v-if='!isNew')
|
||||||
b-radio(value='Updated') Updated
|
label Also Mark As
|
||||||
b-radio(value='Prayed') Prayed
|
br
|
||||||
b-radio(value='Answered') Answered
|
label.normal
|
||||||
div.w-100.text-right(slot='modal-footer')
|
input(v-model='form.status'
|
||||||
b-btn(variant='primary'
|
type='radio'
|
||||||
@click='saveRequest()') Save
|
name='status'
|
||||||
|
value='Updated')
|
||||||
|
| Updated
|
||||||
|
|
|
|
||||||
b-btn(variant='outline-secondary'
|
label.normal
|
||||||
@click='closeDialog()') Cancel
|
input(v-model='form.status'
|
||||||
|
type='radio'
|
||||||
|
name='status'
|
||||||
|
value='Prayed')
|
||||||
|
| Prayed
|
||||||
|
|
|
||||||
|
label.normal
|
||||||
|
input(v-model='form.status'
|
||||||
|
type='radio'
|
||||||
|
name='status'
|
||||||
|
value='Answered')
|
||||||
|
| Answered
|
||||||
|
br
|
||||||
|
label Recurrence
|
||||||
|
|
|
||||||
|
em.mpj-muted-text After prayer, request reappears...
|
||||||
|
br
|
||||||
|
label.normal
|
||||||
|
input(v-model='form.recur.typ'
|
||||||
|
type='radio'
|
||||||
|
name='recur'
|
||||||
|
value='immediate')
|
||||||
|
| Immediately
|
||||||
|
|
|
||||||
|
label.normal
|
||||||
|
input(v-model='form.recur.typ'
|
||||||
|
type='radio'
|
||||||
|
name='recur'
|
||||||
|
value='other')
|
||||||
|
| Every...
|
||||||
|
input(v-model='form.recur.count'
|
||||||
|
type='number'
|
||||||
|
:disabled='!showRecurrence').mpj-recur-count
|
||||||
|
select(v-model='form.recur.other'
|
||||||
|
:disabled='!showRecurrence').mpj-recur-type
|
||||||
|
option(value='hours') hours
|
||||||
|
option(value='days') days
|
||||||
|
option(value='weeks') weeks
|
||||||
|
.mpj-text-right
|
||||||
|
button(:disabled='!isValidRecurrence'
|
||||||
|
@click.stop='saveRequest()').primary.
|
||||||
|
#[md-icon(icon='save')] Save
|
||||||
|
|
|
||||||
|
button(@click.stop='goBack()').
|
||||||
|
#[md-icon(icon='arrow_back')] Cancel
|
||||||
</template>
|
</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',
|
||||||
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'
|
||||||
|
},
|
||||||
|
toast () {
|
||||||
|
return this.$parent.$refs.toast
|
||||||
|
},
|
||||||
|
...mapState(['journal'])
|
||||||
|
},
|
||||||
|
async mounted () {
|
||||||
|
await this.ensureJournal()
|
||||||
|
if (this.id === 'new') {
|
||||||
|
this.title = 'Add Prayer Request'
|
||||||
|
this.isNew = true
|
||||||
this.form.requestId = ''
|
this.form.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.toast.showToast('New prayer request added', { theme: 'success' })
|
||||||
|
} 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.toast.showToast('Request updated and removed from active journal', { theme: 'success' })
|
||||||
} else {
|
} else {
|
||||||
this.toast.showToast('Request updated', { theme: 'success' })
|
this.toast.showToast('Request updated', { theme: 'success' })
|
||||||
}
|
}
|
||||||
this.closeDialog()
|
}
|
||||||
|
this.goBack()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.mpj-recur-count {
|
||||||
|
width: 3rem;
|
||||||
|
border-top-right-radius: 0;
|
||||||
|
border-bottom-right-radius: 0;
|
||||||
|
}
|
||||||
|
.mpj-recur-type {
|
||||||
|
border-top-left-radius: 0;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -1,56 +1,90 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
span
|
article.mpj-main-content(role='main')
|
||||||
b-modal(v-model='historyVisible'
|
page-title(title='Full Prayer Request')
|
||||||
header-bg-variant='mpj'
|
template(v-if='request')
|
||||||
header-text-variant='light'
|
p
|
||||||
size='lg'
|
span(v-if='isAnswered') Answered {{ formatDate(answered) }} (#[date-from-now(:value='answered')])
|
||||||
title='Prayer Request History'
|
small: em.mpj-muted-text prayed {{ prayedCount }} times, open {{ openDays }} days
|
||||||
@shows='focusRequestText')
|
p.mpj-request-text {{ lastText }}
|
||||||
b-list-group(v-if='null !== full'
|
br
|
||||||
flush)
|
table.mpj-request-log
|
||||||
full-request-history(v-for='item in full.history'
|
thead
|
||||||
:key='item.asOf'
|
tr
|
||||||
:history='item')
|
th Action
|
||||||
div.w-100.text-right(slot='modal-footer')
|
th Update / Notes
|
||||||
b-btn(variant='primary'
|
tbody
|
||||||
@click='closeDialog()') Close
|
tr(v-for='item in log' :key='item.asOf')
|
||||||
|
td {{ item.status }} on #[span.mpj-text-nowrap {{ formatDate(item.asOf) }}]
|
||||||
|
td(v-if='item.text').mpj-request-text {{ item.text.fields[0] }}
|
||||||
|
td(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',
|
||||||
components: {
|
|
||||||
FullRequestHistory
|
|
||||||
},
|
|
||||||
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
|
||||||
|
},
|
||||||
|
isAnswered () {
|
||||||
|
return this.request.history.filter(hist => hist.status === 'Answered').length > 0
|
||||||
|
},
|
||||||
|
lastText () {
|
||||||
|
return this.request.history
|
||||||
|
.filter(hist => hist.text)
|
||||||
|
.sort(asOfDesc)[0].text.fields[0]
|
||||||
|
},
|
||||||
|
log () {
|
||||||
|
const allHistory = (this.request.notes || [])
|
||||||
|
.map(note => ({ asOf: note.asOf, text: { case: 'Some', fields: [ note.notes ] }, status: 'Notes' }))
|
||||||
|
.concat(this.request.history)
|
||||||
|
.sort(asOfDesc)
|
||||||
|
// Skip the first entry for answered requests; that info is already displayed
|
||||||
|
return this.isAnswered ? allHistory.slice(1) : allHistory
|
||||||
|
},
|
||||||
|
openDays () {
|
||||||
|
const asOf = this.isAnswered ? this.answered : Date.now()
|
||||||
|
return Math.floor(
|
||||||
|
(asOf - this.request.history.find(hist => hist.status === 'Created').asOf) / 1000 / 60 / 60 / 24)
|
||||||
|
},
|
||||||
|
prayedCount () {
|
||||||
|
return this.request.history.filter(hist => hist.status === 'Prayed').length
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async mounted () {
|
||||||
|
this.$Progress.start()
|
||||||
|
try {
|
||||||
|
const req = await api.getFullRequest(this.id)
|
||||||
|
this.request = req.data
|
||||||
|
this.$Progress.finish()
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
this.$Progress.fail()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
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,28 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
b-list-group-item
|
|
||||||
| {{ history.status }}
|
|
||||||
|
|
|
||||||
small.text-muted {{ asOf }}
|
|
||||||
div(v-if='hasText').mpj-request-text {{ 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()
|
|
||||||
},
|
|
||||||
hasText () {
|
|
||||||
return this.history.text.length > 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
<template lang="pug">
|
|
||||||
div
|
|
||||||
b-btn(@click='openDialog()' size='sm' variant='primary')
|
|
||||||
icon(name='plus')
|
|
||||||
| Add a New Request
|
|
||||||
b-modal(v-model='showNewVisible'
|
|
||||||
header-bg-variant='mpj'
|
|
||||||
header-text-variant='light'
|
|
||||||
size='lg'
|
|
||||||
title='Add a New Prayer Request'
|
|
||||||
@shown='focusRequestText')
|
|
||||||
b-form
|
|
||||||
b-form-group(label='Prayer Request'
|
|
||||||
label-for='request_text')
|
|
||||||
b-textarea#request_text(ref='toFocus'
|
|
||||||
v-model='form.requestText'
|
|
||||||
:rows='10'
|
|
||||||
@blur='trimText()')
|
|
||||||
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>
|
|
||||||
@@ -1,36 +1,33 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
b-modal(v-model='notesVisible'
|
.mpj-modal(v-show='notesVisible')
|
||||||
header-bg-variant='mpj'
|
.mpj-modal-content.mpj-narrow
|
||||||
header-text-variant='light'
|
header.mpj-bg
|
||||||
size='lg'
|
h5 Add Notes to Prayer Request
|
||||||
title='Add Notes to Prayer Request'
|
label
|
||||||
@edit='openDialog()'
|
| Notes
|
||||||
@shows='focusNotes')
|
|
||||||
b-form
|
|
||||||
b-form-group(label='Notes'
|
|
||||||
label-for='notes')
|
|
||||||
b-textarea#notes(ref='toFocus'
|
|
||||||
v-model='form.notes'
|
|
||||||
:rows='10'
|
|
||||||
@blur='trimText()')
|
|
||||||
div(v-if='hasPriorNotes')
|
|
||||||
p.text-center: strong Prior Notes for This Request
|
|
||||||
b-list-group(flush)
|
|
||||||
b-list-group-item(v-for='note in priorNotes'
|
|
||||||
:key='note.asOf')
|
|
||||||
small.text-muted: date-from-now(:value='note.asOf')
|
|
||||||
br
|
br
|
||||||
div.mpj-request-text {{ note.notes }}
|
textarea(v-model='form.notes'
|
||||||
div(v-else-if='noPriorNotes').text-center.text-muted There are no prior notes for this request
|
:rows='10'
|
||||||
div(v-else).text-center
|
@blur='trimText()').mpj-full-width
|
||||||
b-btn(variant='outline-secondary'
|
.mpj-text-right
|
||||||
@click='loadNotes()') Load Prior Notes
|
button(@click='saveNotes()').primary.
|
||||||
div.w-100.text-right(slot='modal-footer')
|
#[md-icon(icon='save')] Save
|
||||||
b-btn(variant='primary'
|
|
||||||
@click='saveNotes()') Save
|
|
||||||
|
|
|
|
||||||
b-btn(variant='outline-secondary'
|
button(@click='closeDialog()').
|
||||||
@click='closeDialog()') Cancel
|
#[md-icon(icon='undo')] Cancel
|
||||||
|
hr
|
||||||
|
div(v-if='hasPriorNotes')
|
||||||
|
p.mpj-text-center: strong Prior Notes for This Request
|
||||||
|
.mpj-note-list
|
||||||
|
p(v-for='note in priorNotes'
|
||||||
|
:key='note.asOf')
|
||||||
|
small.mpj-muted-text: date-from-now(:value='note.asOf')
|
||||||
|
br
|
||||||
|
span.mpj-request-text {{ note.notes }}
|
||||||
|
div(v-else-if='noPriorNotes').mpj-text-center.mpj-muted-text There are no prior notes for this request
|
||||||
|
div(v-else).mpj-text-center
|
||||||
|
button(@click='loadNotes()').
|
||||||
|
#[md-icon(icon='cloud_download')] Load Prior Notes
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -74,15 +71,11 @@ export default {
|
|||||||
this.priorNotesLoaded = false
|
this.priorNotesLoaded = false
|
||||||
this.notesVisible = false
|
this.notesVisible = false
|
||||||
},
|
},
|
||||||
focusNotes (e) {
|
|
||||||
this.$refs.toFocus.focus()
|
|
||||||
},
|
|
||||||
async loadNotes () {
|
async loadNotes () {
|
||||||
this.$Progress.start()
|
this.$Progress.start()
|
||||||
try {
|
try {
|
||||||
const notes = await api.getNotes(this.form.requestId)
|
const notes = await api.getNotes(this.form.requestId)
|
||||||
this.priorNotes = notes.data
|
this.priorNotes = notes.data
|
||||||
console.log(this.priorNotes)
|
|
||||||
this.$Progress.finish()
|
this.$Progress.finish()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
@@ -94,7 +87,6 @@ export default {
|
|||||||
openDialog (request) {
|
openDialog (request) {
|
||||||
this.form.requestId = request.requestId
|
this.form.requestId = request.requestId
|
||||||
this.notesVisible = true
|
this.notesVisible = true
|
||||||
this.focusNotes(null)
|
|
||||||
},
|
},
|
||||||
async saveNotes () {
|
async saveNotes () {
|
||||||
this.$Progress.start()
|
this.$Progress.start()
|
||||||
@@ -114,3 +106,9 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.mpj-note-list p {
|
||||||
|
border-top: dotted 1px lightgray;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -1,15 +1,14 @@
|
|||||||
<template lang="pug">
|
<template lang="pug">
|
||||||
b-col(md='6' lg='4')
|
.mpj-request-card(v-if='shouldDisplay')
|
||||||
.mpj-request-card
|
header.mpj-card-header(role='toolbar').
|
||||||
b-card-header.text-center.py-1.
|
#[button(@click='markPrayed()' title='Pray').primary: md-icon(icon='done')]
|
||||||
#[b-btn(@click='markPrayed()' variant='outline-primary' title='Pray' size='sm'): icon(name='check')]
|
#[button(@click.stop='showEdit()' title='Edit'): md-icon(icon='edit')]
|
||||||
#[b-btn(@click.stop='showEdit()' variant='outline-secondary' title='Edit' size='sm'): icon(name='pencil')]
|
#[button(@click.stop='showNotes()' title='Add Notes'): md-icon(icon='comment')]
|
||||||
#[b-btn(@click.stop='showNotes()' variant='outline-secondary' title='Add Notes' size='sm'): icon(name='file-text-o')]
|
#[button(@click.stop='snooze()' title='Snooze Request'): md-icon(icon='schedule')]
|
||||||
#[b-btn(@click.stop='showFull()' variant='outline-secondary' title='View Full Request' size='sm'): icon(name='search')]
|
div
|
||||||
b-card-body.p-0
|
p.card-text.mpj-request-text
|
||||||
p.card-text.mpj-request-text.mb-1.px-3.pt-3
|
|
||||||
| {{ request.text }}
|
| {{ request.text }}
|
||||||
p.card-text.p-0.pr-1.text-right: small.text-muted: em
|
p.as-of.mpj-text-right: small.mpj-muted-text: em
|
||||||
= '(last activity '
|
= '(last activity '
|
||||||
date-from-now(:value='request.asOf')
|
date-from-now(:value='request.asOf')
|
||||||
| )
|
| )
|
||||||
@@ -27,6 +26,12 @@ export default {
|
|||||||
toast: { required: true },
|
toast: { required: true },
|
||||||
events: { required: true }
|
events: { required: true }
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
shouldDisplay () {
|
||||||
|
const now = Date.now()
|
||||||
|
return Math.max(now, this.request.showAfter, this.request.snoozedUntil) === now
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async markPrayed () {
|
async markPrayed () {
|
||||||
await this.$store.dispatch(actions.UPDATE_REQUEST, {
|
await this.$store.dispatch(actions.UPDATE_REQUEST, {
|
||||||
@@ -38,13 +43,13 @@ export default {
|
|||||||
this.toast.showToast('Request marked as prayed', { theme: 'success' })
|
this.toast.showToast('Request marked as prayed', { theme: 'success' })
|
||||||
},
|
},
|
||||||
showEdit () {
|
showEdit () {
|
||||||
this.events.$emit('edit', this.request)
|
this.$router.push({ name: 'EditRequest', params: { id: this.request.requestId } })
|
||||||
},
|
|
||||||
showFull () {
|
|
||||||
this.events.$emit('full', this.request.requestId)
|
|
||||||
},
|
},
|
||||||
showNotes () {
|
showNotes () {
|
||||||
this.events.$emit('notes', this.request)
|
this.events.$emit('notes', this.request)
|
||||||
|
},
|
||||||
|
snooze () {
|
||||||
|
this.events.$emit('snooze', this.request.requestId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,6 +59,35 @@ export default {
|
|||||||
.mpj-request-card {
|
.mpj-request-card {
|
||||||
border: solid 1px darkgray;
|
border: solid 1px darkgray;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
margin-bottom: 15px;
|
width: 20rem;
|
||||||
|
margin: .5rem;
|
||||||
|
}
|
||||||
|
@media screen and (max-width: 20rem) {
|
||||||
|
.mpj-request-card {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.mpj-card-header {
|
||||||
|
display: flex;
|
||||||
|
flex-flow: row;
|
||||||
|
justify-content: center;
|
||||||
|
background-image: -webkit-gradient(linear, left top, left bottom, from(lightgray), to(whitesmoke));
|
||||||
|
background-image: -webkit-linear-gradient(top, lightgray, whitesmoke);
|
||||||
|
background-image: -moz-linear-gradient(top, lightgray, whitesmoke);
|
||||||
|
background-image: linear-gradient(to bottom, lightgray, whitesmoke);
|
||||||
|
}
|
||||||
|
.mpj-card-header button {
|
||||||
|
margin: .25rem;
|
||||||
|
padding: 0 .25rem;
|
||||||
|
}
|
||||||
|
.mpj-card-header button .material-icons {
|
||||||
|
font-size: 1.3rem;
|
||||||
|
}
|
||||||
|
.mpj-request-card .card-text {
|
||||||
|
margin-left: 1rem;
|
||||||
|
margin-right: 1rem;
|
||||||
|
}
|
||||||
|
.mpj-request-card .as-of {
|
||||||
|
margin-right: .25rem;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
86
src/app/src/components/request/RequestListItem.vue
Normal file
86
src/app/src/components/request/RequestListItem.vue
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
p.mpj-request-text
|
||||||
|
| {{ request.text }}
|
||||||
|
br
|
||||||
|
br
|
||||||
|
button(@click='viewFull'
|
||||||
|
title='View Full Request').
|
||||||
|
#[md-icon(icon='description')] View Full Request
|
||||||
|
|
|
||||||
|
template(v-if='!isAnswered')
|
||||||
|
button(@click='editRequest'
|
||||||
|
title='Edit Request').
|
||||||
|
#[md-icon(icon='edit')] Edit Request
|
||||||
|
|
|
||||||
|
template(v-if='isSnoozed')
|
||||||
|
button(@click='cancelSnooze()').
|
||||||
|
#[md-icon(icon='restore')] Cancel Snooze
|
||||||
|
|
|
||||||
|
template(v-if='isPending')
|
||||||
|
button(@click='showNow()').
|
||||||
|
#[md-icon(icon='restore')] Show Now
|
||||||
|
br(v-if='isSnoozed || isPending || isAnswered')
|
||||||
|
small(v-if='isSnoozed').mpj-muted-text: em.
|
||||||
|
Snooze expires #[date-from-now(:value='request.snoozedUntil')]
|
||||||
|
small(v-if='isPending').mpj-muted-text: em.
|
||||||
|
Request scheduled to reappear #[date-from-now(:value='request.showAfter')]
|
||||||
|
small(v-if='isAnswered').mpj-muted-text: em.
|
||||||
|
Answered #[date-from-now(:value='request.asOf')]
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import actions from '@/store/action-types'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'request-list-item',
|
||||||
|
props: {
|
||||||
|
request: { required: true },
|
||||||
|
toast: { required: true }
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
answered () {
|
||||||
|
return this.request.history.find(hist => hist.status === 'Answered').asOf
|
||||||
|
},
|
||||||
|
isAnswered () {
|
||||||
|
return this.request.lastStatus === 'Answered'
|
||||||
|
},
|
||||||
|
isPending () {
|
||||||
|
return !this.isSnoozed && this.request.showAfter > Date.now()
|
||||||
|
},
|
||||||
|
isSnoozed () {
|
||||||
|
return this.request.snoozedUntil > Date.now()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async cancelSnooze () {
|
||||||
|
await this.$store.dispatch(actions.SNOOZE_REQUEST, {
|
||||||
|
progress: this.$Progress,
|
||||||
|
requestId: this.request.requestId,
|
||||||
|
until: 0
|
||||||
|
})
|
||||||
|
this.toast.showToast('Request un-snoozed', { theme: 'success' })
|
||||||
|
this.$parent.$emit('requestUnsnoozed')
|
||||||
|
},
|
||||||
|
editRequest () {
|
||||||
|
this.$router.push({ name: 'EditRequest', params: { id: this.request.requestId } })
|
||||||
|
},
|
||||||
|
async showNow () {
|
||||||
|
await this.$store.dispatch(actions.SHOW_REQUEST_NOW, {
|
||||||
|
progress: this.$Progress,
|
||||||
|
requestId: this.request.requestId,
|
||||||
|
showAfter: Date.now()
|
||||||
|
})
|
||||||
|
this.toast.showToast('Recurrence skipped; request now shows in journal', { theme: 'success' })
|
||||||
|
this.$parent.$emit('requestNowShown')
|
||||||
|
},
|
||||||
|
viewFull () {
|
||||||
|
this.$router.push({ name: 'FullRequest', params: { id: this.request.requestId } })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
71
src/app/src/components/request/SnoozeRequest.vue
Normal file
71
src/app/src/components/request/SnoozeRequest.vue
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
.mpj-modal(v-show='snoozeVisible')
|
||||||
|
.mpj-modal-content.mpj-skinny
|
||||||
|
header.mpj-bg
|
||||||
|
h5 Snooze Prayer Request
|
||||||
|
p.mpj-text-center
|
||||||
|
label
|
||||||
|
= 'Until '
|
||||||
|
input(v-model='form.snoozedUntil'
|
||||||
|
type='date'
|
||||||
|
autofocus)
|
||||||
|
br
|
||||||
|
.mpj-text-right
|
||||||
|
button.primary(:disabled='!isValid'
|
||||||
|
@click='snoozeRequest()').
|
||||||
|
#[md-icon(icon='snooze')] Snooze
|
||||||
|
|
|
||||||
|
button(@click='closeDialog()').
|
||||||
|
#[md-icon(icon='undo')] Cancel
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import actions from '@/store/action-types'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'snooze-request',
|
||||||
|
props: {
|
||||||
|
toast: { required: true },
|
||||||
|
events: { required: true }
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
snoozeVisible: false,
|
||||||
|
form: {
|
||||||
|
requestId: '',
|
||||||
|
snoozedUntil: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
created () {
|
||||||
|
this.events.$on('snooze', this.openDialog)
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
isValid () {
|
||||||
|
return !isNaN(Date.parse(this.form.snoozedUntil))
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
closeDialog () {
|
||||||
|
this.form.requestId = ''
|
||||||
|
this.form.snoozedUntil = ''
|
||||||
|
this.snoozeVisible = false
|
||||||
|
},
|
||||||
|
openDialog (requestId) {
|
||||||
|
this.form.requestId = requestId
|
||||||
|
this.snoozeVisible = true
|
||||||
|
},
|
||||||
|
async snoozeRequest () {
|
||||||
|
await this.$store.dispatch(actions.SNOOZE_REQUEST, {
|
||||||
|
progress: this.$Progress,
|
||||||
|
requestId: this.form.requestId,
|
||||||
|
until: Date.parse(this.form.snoozedUntil)
|
||||||
|
})
|
||||||
|
this.toast.showToast(`Request snoozed until ${this.form.snoozedUntil}`, { theme: 'success' })
|
||||||
|
this.closeDialog()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
59
src/app/src/components/request/SnoozedRequests.vue
Normal file
59
src/app/src/components/request/SnoozedRequests.vue
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<template lang="pug">
|
||||||
|
article.mpj-main-content(role='main')
|
||||||
|
page-title(title='Snoozed Requests')
|
||||||
|
div(v-if='loaded').mpj-request-list
|
||||||
|
p.mpj-text-center(v-if='requests.length === 0'): em.
|
||||||
|
No snoozed requests found; return to #[router-link(:to='{ name: "Journal" } ') your journal]
|
||||||
|
request-list-item(v-for='req in requests'
|
||||||
|
:key='req.requestId'
|
||||||
|
:request='req'
|
||||||
|
:toast='toast')
|
||||||
|
p(v-else) Loading journal...
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
import { mapState } from 'vuex'
|
||||||
|
|
||||||
|
import actions from '@/store/action-types'
|
||||||
|
|
||||||
|
import RequestListItem from '@/components/request/RequestListItem'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'snoozed-requests',
|
||||||
|
components: {
|
||||||
|
RequestListItem
|
||||||
|
},
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
requests: [],
|
||||||
|
loaded: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
toast () {
|
||||||
|
return this.$parent.$refs.toast
|
||||||
|
},
|
||||||
|
...mapState(['journal', 'isLoadingJournal'])
|
||||||
|
},
|
||||||
|
created () {
|
||||||
|
this.$on('requestUnsnoozed', this.ensureJournal)
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async ensureJournal () {
|
||||||
|
if (!Array.isArray(this.journal)) {
|
||||||
|
this.loaded = false
|
||||||
|
await this.$store.dispatch(actions.LOAD_JOURNAL, this.$Progress)
|
||||||
|
}
|
||||||
|
this.requests = this.journal
|
||||||
|
.filter(req => req.snoozedUntil > Date.now())
|
||||||
|
.sort((a, b) => a.snoozedUntil - b.snoozedUntil)
|
||||||
|
this.loaded = true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async mounted () {
|
||||||
|
await this.ensureJournal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -1,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>
|
||||||
|
|||||||
@@ -1,31 +1,18 @@
|
|||||||
// The Vue build version to load with the `import` command
|
|
||||||
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
|
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import BootstrapVue from 'bootstrap-vue'
|
|
||||||
import Icon from 'vue-awesome/components/Icon'
|
|
||||||
import VueProgressBar from 'vue-progressbar'
|
import VueProgressBar from 'vue-progressbar'
|
||||||
import VueToast from 'vue-toast'
|
import VueToast from 'vue-toast'
|
||||||
|
|
||||||
import 'bootstrap-vue/dist/bootstrap-vue.css'
|
|
||||||
import 'bootstrap/dist/css/bootstrap.css'
|
|
||||||
import 'vue-toast/dist/vue-toast.min.css'
|
import 'vue-toast/dist/vue-toast.min.css'
|
||||||
|
|
||||||
// Only import the icons we need; the whole set is ~500K!
|
|
||||||
import 'vue-awesome/icons/check'
|
|
||||||
import 'vue-awesome/icons/file-text-o'
|
|
||||||
import 'vue-awesome/icons/pencil'
|
|
||||||
import 'vue-awesome/icons/plus'
|
|
||||||
import 'vue-awesome/icons/search'
|
|
||||||
|
|
||||||
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 MaterialDesignIcon from './components/common/MaterialDesignIcon'
|
||||||
import PageTitle from './components/common/PageTitle'
|
import PageTitle from './components/common/PageTitle'
|
||||||
|
|
||||||
Vue.config.productionTip = false
|
Vue.config.productionTip = false
|
||||||
|
|
||||||
Vue.use(BootstrapVue)
|
|
||||||
Vue.use(VueProgressBar, {
|
Vue.use(VueProgressBar, {
|
||||||
color: 'yellow',
|
color: 'yellow',
|
||||||
failedColor: 'red',
|
failedColor: 'red',
|
||||||
@@ -37,16 +24,13 @@ Vue.use(VueProgressBar, {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
Vue.component('icon', Icon)
|
|
||||||
Vue.component('date-from-now', DateFromNow)
|
Vue.component('date-from-now', DateFromNow)
|
||||||
|
Vue.component('md-icon', MaterialDesignIcon)
|
||||||
Vue.component('page-title', PageTitle)
|
Vue.component('page-title', PageTitle)
|
||||||
Vue.component('toast', VueToast)
|
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')
|
||||||
})
|
|
||||||
|
|||||||
83
src/app/src/router.js
Normal file
83
src/app/src/router.js
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
import Vue from 'vue'
|
||||||
|
import Router from 'vue-router'
|
||||||
|
|
||||||
|
import ActiveRequests from '@/components/request/ActiveRequests'
|
||||||
|
import AnsweredRequests from '@/components/request/AnsweredRequests'
|
||||||
|
import EditRequest from '@/components/request/EditRequest'
|
||||||
|
import FullRequest from '@/components/request/FullRequest'
|
||||||
|
import Home from '@/components/Home'
|
||||||
|
import Journal from '@/components/Journal'
|
||||||
|
import LogOn from '@/components/user/LogOn'
|
||||||
|
import PrivacyPolicy from '@/components/legal/PrivacyPolicy'
|
||||||
|
import SnoozedRequests from '@/components/request/SnoozedRequests'
|
||||||
|
import TermsOfService from '@/components/legal/TermsOfService'
|
||||||
|
|
||||||
|
Vue.use(Router)
|
||||||
|
|
||||||
|
export default new Router({
|
||||||
|
mode: 'history',
|
||||||
|
base: process.env.BASE_URL,
|
||||||
|
scrollBehavior (to, from, savedPosition) {
|
||||||
|
if (savedPosition) {
|
||||||
|
return savedPosition
|
||||||
|
} else {
|
||||||
|
return { x: 0, y: 0 }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
routes: [
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
name: 'Home',
|
||||||
|
component: Home
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/journal',
|
||||||
|
name: 'Journal',
|
||||||
|
component: Journal
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/legal/privacy-policy',
|
||||||
|
name: 'PrivacyPolicy',
|
||||||
|
component: PrivacyPolicy
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/legal/terms-of-service',
|
||||||
|
name: 'TermsOfService',
|
||||||
|
component: TermsOfService
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/request/:id/edit',
|
||||||
|
name: 'EditRequest',
|
||||||
|
component: EditRequest,
|
||||||
|
props: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/request/:id/full',
|
||||||
|
name: 'FullRequest',
|
||||||
|
component: FullRequest,
|
||||||
|
props: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/requests/active',
|
||||||
|
name: 'ActiveRequests',
|
||||||
|
component: ActiveRequests
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/requests/answered',
|
||||||
|
name: 'AnsweredRequests',
|
||||||
|
component: AnsweredRequests
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/requests/snoozed',
|
||||||
|
name: 'SnoozedRequests',
|
||||||
|
component: SnoozedRequests
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/user/log-on',
|
||||||
|
name: 'LogOn',
|
||||||
|
component: LogOn
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
@@ -1,54 +0,0 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import Router from 'vue-router'
|
|
||||||
|
|
||||||
import Answered from '@/components/Answered'
|
|
||||||
import AnsweredDetail from '@/components/AnsweredDetail'
|
|
||||||
import Home from '@/components/Home'
|
|
||||||
import Journal from '@/components/Journal'
|
|
||||||
import LogOn from '@/components/user/LogOn'
|
|
||||||
import PrivacyPolicy from '@/components/legal/PrivacyPolicy'
|
|
||||||
import TermsOfService from '@/components/legal/TermsOfService'
|
|
||||||
|
|
||||||
Vue.use(Router)
|
|
||||||
|
|
||||||
export default new Router({
|
|
||||||
mode: 'history',
|
|
||||||
routes: [
|
|
||||||
{
|
|
||||||
path: '/',
|
|
||||||
name: 'Home',
|
|
||||||
component: Home
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/answered/:id',
|
|
||||||
name: 'AnsweredDetail',
|
|
||||||
component: AnsweredDetail,
|
|
||||||
props: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/answered',
|
|
||||||
name: 'Answered',
|
|
||||||
component: Answered
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/journal',
|
|
||||||
name: 'Journal',
|
|
||||||
component: Journal
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/legal/privacy-policy',
|
|
||||||
name: 'PrivacyPolicy',
|
|
||||||
component: PrivacyPolicy
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/legal/terms-of-service',
|
|
||||||
name: 'TermsOfService',
|
|
||||||
component: TermsOfService
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: '/user/log-on',
|
|
||||||
name: 'LogOn',
|
|
||||||
component: LogOn
|
|
||||||
}
|
|
||||||
]
|
|
||||||
})
|
|
||||||
@@ -6,5 +6,9 @@ export default {
|
|||||||
/** 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,3 +1,5 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import Vuex from 'vuex'
|
import Vuex from 'vuex'
|
||||||
|
|
||||||
@@ -9,7 +11,7 @@ import actions from './action-types'
|
|||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
|
||||||
this.auth0 = new AuthService()
|
const auth0 = new AuthService()
|
||||||
|
|
||||||
const logError = function (error) {
|
const logError = function (error) {
|
||||||
if (error.response) {
|
if (error.response) {
|
||||||
@@ -34,11 +36,11 @@ export default new Vuex.Store({
|
|||||||
state: {
|
state: {
|
||||||
user: JSON.parse(localStorage.getItem('user_profile') || '{}'),
|
user: JSON.parse(localStorage.getItem('user_profile') || '{}'),
|
||||||
isAuthenticated: (() => {
|
isAuthenticated: (() => {
|
||||||
this.auth0.scheduleRenewal()
|
auth0.scheduleRenewal()
|
||||||
if (this.auth0.isAuthenticated()) {
|
if (auth0.isAuthenticated()) {
|
||||||
api.setBearer(localStorage.getItem('id_token'))
|
api.setBearer(localStorage.getItem('id_token'))
|
||||||
}
|
}
|
||||||
return this.auth0.isAuthenticated()
|
return auth0.isAuthenticated()
|
||||||
})(),
|
})(),
|
||||||
journal: {},
|
journal: {},
|
||||||
isLoadingJournal: false
|
isLoadingJournal: false
|
||||||
@@ -71,10 +73,10 @@ export default new Vuex.Store({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async [actions.ADD_REQUEST] ({ commit }, { progress, requestText }) {
|
async [actions.ADD_REQUEST] ({ commit }, { progress, requestText, recurType, recurCount }) {
|
||||||
progress.start()
|
progress.start()
|
||||||
try {
|
try {
|
||||||
const newRequest = await api.addRequest(requestText)
|
const newRequest = await api.addRequest(requestText, recurType, recurCount)
|
||||||
commit(mutations.REQUEST_ADDED, newRequest.data)
|
commit(mutations.REQUEST_ADDED, newRequest.data)
|
||||||
progress.finish()
|
progress.finish()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -98,10 +100,40 @@ export default new Vuex.Store({
|
|||||||
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.start()
|
||||||
try {
|
try {
|
||||||
await api.updateRequest({ requestId, status, updateText })
|
let oldReq = (state.journal.filter(req => req.requestId === requestId) || [])[0] || {}
|
||||||
|
if (status !== 'Updated' || oldReq.text !== updateText) {
|
||||||
|
await api.updateRequest(requestId, status, updateText)
|
||||||
|
}
|
||||||
|
if (status === 'Updated' && (oldReq.recurType !== recurType || oldReq.recurCount !== recurCount)) {
|
||||||
|
await api.updateRecurrence(requestId, recurType, recurCount)
|
||||||
|
}
|
||||||
|
const request = await api.getRequest(requestId)
|
||||||
|
commit(mutations.REQUEST_UPDATED, request.data)
|
||||||
|
progress.finish()
|
||||||
|
} catch (err) {
|
||||||
|
logError(err)
|
||||||
|
progress.fail()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async [actions.SHOW_REQUEST_NOW] ({ commit }, { progress, requestId, showAfter }) {
|
||||||
|
progress.start()
|
||||||
|
try {
|
||||||
|
await api.showRequest(requestId, showAfter)
|
||||||
|
const request = await api.getRequest(requestId)
|
||||||
|
commit(mutations.REQUEST_UPDATED, request.data)
|
||||||
|
progress.finish()
|
||||||
|
} catch (err) {
|
||||||
|
logError(err)
|
||||||
|
progress.fail()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async [actions.SNOOZE_REQUEST] ({ commit }, { progress, requestId, until }) {
|
||||||
|
progress.start()
|
||||||
|
try {
|
||||||
|
await api.snoozeRequest(requestId, until)
|
||||||
const request = await api.getRequest(requestId)
|
const request = await api.getRequest(requestId)
|
||||||
commit(mutations.REQUEST_UPDATED, request.data)
|
commit(mutations.REQUEST_UPDATED, request.data)
|
||||||
progress.finish()
|
progress.finish()
|
||||||
|
|||||||
@@ -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' }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
9
src/app/vue.config.js
Normal file
9
src/app/vue.config.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
const webpack = require('webpack')
|
||||||
|
module.exports = {
|
||||||
|
outputDir: '../api/MyPrayerJournal.Api/wwwroot',
|
||||||
|
configureWebpack: {
|
||||||
|
plugins: [
|
||||||
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
6138
src/app/yarn.lock
6138
src/app/yarn.lock
File diff suppressed because it is too large
Load Diff
@@ -1,48 +0,0 @@
|
|||||||
// myPrayerJournal API Server
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/danieljsummers/myPrayerJournal/src/api/data"
|
|
||||||
"github.com/danieljsummers/myPrayerJournal/src/api/routes"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Web contains configuration for the web server.
|
|
||||||
type Web struct {
|
|
||||||
Port string `json:"port"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Settings contains configuration for the myPrayerJournal API.
|
|
||||||
type Settings struct {
|
|
||||||
Data *data.Settings `json:"data"`
|
|
||||||
Web *Web `json:"web"`
|
|
||||||
Auth *routes.AuthConfig `json:"auth"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// readSettings parses the JSON configuration file into the Settings struct.
|
|
||||||
func readSettings(f string) *Settings {
|
|
||||||
config, err := os.Open(f)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer config.Close()
|
|
||||||
settings := Settings{}
|
|
||||||
if err = json.NewDecoder(config).Decode(&settings); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
return &settings
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
cfg := readSettings("config.json")
|
|
||||||
if ok := data.Connect(cfg.Data); !ok {
|
|
||||||
log.Fatal("Unable to connect to database; exiting")
|
|
||||||
}
|
|
||||||
data.EnsureDB()
|
|
||||||
log.Printf("myPrayerJournal API listening on %s", cfg.Web.Port)
|
|
||||||
log.Fatal(http.ListenAndServe(cfg.Web.Port, routes.NewRouter(cfg.Auth)))
|
|
||||||
}
|
|
||||||
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