PrayerTracker/src/PrayerTracker.UI/PrayerRequest.fs

371 lines
15 KiB
Forth
Raw Normal View History

2019-02-18 01:25:07 +00:00
module PrayerTracker.Views.PrayerRequest
open Giraffe
open Giraffe.GiraffeViewEngine
open Microsoft.AspNetCore.Http
open NodaTime
open PrayerTracker
open PrayerTracker.Entities
open PrayerTracker.ViewModels
open System
open System.IO
open System.Text
/// View for the prayer request edit page
let edit (m : EditRequest) today ctx vi =
let s = I18N.localizer.Force ()
let pageTitle = match m.isNew () with true -> "Add a New Request" | false -> "Edit Request"
[ form [ _action "/web/prayer-request/save"; _method "post"; _class "pt-center-columns" ] [
2019-02-18 01:25:07 +00:00
csrfToken ctx
input [ _type "hidden"; _name "requestId"; _value (flatGuid m.requestId) ]
2019-02-18 01:25:07 +00:00
div [ _class "pt-field-row" ] [
2019-09-24 01:40:47 +00:00
div [ _class "pt-field" ] [
label [ _for "requestType" ] [ locStr s.["Request Type"] ]
2019-02-18 01:25:07 +00:00
ReferenceList.requestTypeList s
|> Seq.ofList
|> Seq.map (fun (typ, desc) -> typ.code, desc.Value)
2019-02-18 01:25:07 +00:00
|> selectList "requestType" m.requestType [ _required; _autofocus ]
]
2019-09-24 01:40:47 +00:00
div [ _class "pt-field" ] [
label [ _for "requestor" ] [ locStr s.["Requestor / Subject"] ]
2019-02-18 01:25:07 +00:00
input [ _type "text"
_name "requestor"
_id "requestor"
_value (match m.requestor with Some x -> x | None -> "") ]
]
match m.isNew () with
| true ->
2019-09-24 01:40:47 +00:00
div [ _class "pt-field" ] [
label [ _for "enteredDate" ] [ locStr s.["Date"] ]
2019-02-18 01:25:07 +00:00
input [ _type "date"; _name "enteredDate"; _id "enteredDate"; _placeholder today ]
]
| false ->
2019-09-24 01:40:47 +00:00
div [ _class "pt-field" ] [
2019-02-18 01:25:07 +00:00
div [ _class "pt-checkbox-field" ] [
br []
input [ _type "checkbox"; _name "skipDateUpdate"; _id "skipDateUpdate"; _value "True" ]
label [ _for "skipDateUpdate" ] [ locStr s.["Check to not update the date"] ]
2019-02-18 01:25:07 +00:00
br []
small [] [ em [] [ str (s.["Typo Corrections"].Value.ToLower ()); rawText ", etc." ] ]
2019-02-18 01:25:07 +00:00
]
]
]
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [] [ locStr s.["Expiration"] ]
2019-02-18 01:25:07 +00:00
ReferenceList.expirationList s ((m.isNew >> not) ())
|> List.map (fun exp ->
2020-11-16 02:57:09 +00:00
let radioId = $"expiration_{fst exp}"
2019-02-18 01:25:07 +00:00
span [ _class "text-nowrap" ] [
radio "expiration" radioId (fst exp) m.expiration
label [ _for radioId ] [ locStr (snd exp) ]
2019-02-18 01:25:07 +00:00
rawText "     "
])
|> div [ _class "pt-center-text" ]
]
]
div [ _class "pt-field-row" ] [
div [ _class "pt-field pt-editor" ] [
label [ _for "text" ] [ locStr s.["Request"] ]
textarea [ _name "text"; _id "text" ] [ str m.text ]
2019-02-18 01:25:07 +00:00
]
]
div [ _class "pt-field-row" ] [ submit [] "save" s.["Save Request"] ]
]
script [] [ rawText "PT.onLoad(PT.initCKEditor)" ]
]
|> Layout.Content.standard
|> Layout.standard vi pageTitle
/// View for the request e-mail results page
let email m vi =
let s = I18N.localizer.Force ()
2020-11-16 02:57:09 +00:00
let pageTitle = $"""{s.["Prayer Requests"].Value} {m.listGroup.name}"""
2019-02-18 01:25:07 +00:00
let prefs = m.listGroup.preferences
let addresses =
m.recipients
|> List.fold (fun (acc : StringBuilder) mbr -> acc.AppendFormat(", {0} <{1}>", mbr.memberName, mbr.email))
(StringBuilder ())
2020-11-16 02:57:09 +00:00
[ p [ _style $"font-family:{prefs.listFonts};font-size:%i{prefs.textFontSize}pt;" ] [
locStr s.["The request list was sent to the following people, via individual e-mails"]
2019-02-18 01:25:07 +00:00
rawText ":"
br []
small [] [ str (addresses.Remove(0, 2).ToString ()) ]
2019-02-18 01:25:07 +00:00
]
span [ _class "pt-email-heading" ] [ locStr s.["HTML Format"]; rawText ":" ]
2019-02-18 01:25:07 +00:00
div [ _class "pt-email-canvas" ] [ rawText (m.asHtml s) ]
br []
br []
span [ _class "pt-email-heading" ] [ locStr s.["Plain-Text Format"]; rawText ":" ]
div[ _class "pt-email-canvas" ] [ pre [] [ str (m.asText s) ] ]
2019-02-18 01:25:07 +00:00
]
|> Layout.Content.standard
|> Layout.standard vi pageTitle
/// View for a small group's public prayer request list
let list (m : RequestList) vi =
[ br []
I18N.localizer.Force () |> (m.asHtml >> rawText)
]
|> Layout.Content.standard
|> Layout.standard vi "View Request List"
/// View for the prayer request lists page
let lists (grps : SmallGroup list) vi =
let s = I18N.localizer.Force ()
let l = I18N.forView "Requests/Lists"
use sw = new StringWriter ()
let raw = rawLocText sw
2019-09-24 01:40:47 +00:00
[ p [] [
2019-02-18 01:25:07 +00:00
raw l.["The groups listed below have either public or password-protected request lists."]
space
raw l.["Those with list icons are public, and those with log on icons are password-protected."]
space
raw l.["Click the appropriate icon to log on or view the request list."]
]
match grps.Length with
2019-09-24 01:40:47 +00:00
| 0 -> p [] [ raw l.["There are no groups with public or password-protected request lists."] ]
2019-02-18 01:25:07 +00:00
| count ->
2019-09-24 01:40:47 +00:00
tableSummary count s
table [ _class "pt-table pt-action-table" ] [
2019-02-18 01:25:07 +00:00
thead [] [
tr [] [
th [] [ locStr s.["Actions"] ]
th [] [ locStr s.["Church"] ]
th [] [ locStr s.["Group"] ]
2019-02-18 01:25:07 +00:00
]
]
grps
|> List.map (fun grp ->
let grpId = flatGuid grp.smallGroupId
2019-02-18 01:25:07 +00:00
tr [] [
match grp.preferences.isPublic with
| true ->
2020-11-16 02:57:09 +00:00
a [ _href $"/web/prayer-requests/{grpId}/list"; _title s.["View"].Value ] [ icon "list" ]
2019-02-18 01:25:07 +00:00
| false ->
2020-11-16 02:57:09 +00:00
a [ _href $"/web/small-group/log-on/{grpId}"; _title s.["Log On"].Value ]
2019-02-18 01:25:07 +00:00
[ icon "verified_user" ]
|> List.singleton
|> td []
td [] [ str grp.church.name ]
td [] [ str grp.name ]
2019-02-18 01:25:07 +00:00
])
|> tbody []
]
]
|> Layout.Content.standard
|> Layout.standard vi "Request Lists"
/// View for the prayer request maintenance page
let maintain m (ctx : HttpContext) vi =
2019-02-18 01:25:07 +00:00
let s = I18N.localizer.Force ()
let l = I18N.forView "Requests/Maintain"
use sw = new StringWriter ()
let raw = rawLocText sw
let now = m.smallGroup.localDateNow (ctx.GetService<IClock> ())
2019-02-18 01:25:07 +00:00
let typs = ReferenceList.requestTypeList s |> Map.ofList
let updReq (req : PrayerRequest) =
match req.updateRequired now m.smallGroup.preferences.daysToExpire m.smallGroup.preferences.longTermUpdateWeeks with
2019-02-18 01:25:07 +00:00
| true -> "pt-request-update"
| false -> ""
|> _class
let reqExp (req : PrayerRequest) =
_class (match req.isExpired now m.smallGroup.preferences.daysToExpire with true -> "pt-request-expired" | false -> "")
2019-02-18 01:25:07 +00:00
/// Iterate the sequence once, before we render, so we can get the count of it at the top of the table
let requests =
m.requests
2019-02-18 01:25:07 +00:00
|> Seq.map (fun req ->
let reqId = flatGuid req.prayerRequestId
2020-11-16 02:57:09 +00:00
let reqText = htmlToPlainText req.text
let delAction = $"/web/prayer-request/{reqId}/delete"
let delPrompt =
[ s.["Are you sure you want to delete this {0}? This action cannot be undone.",
s.["Prayer Request"].Value.ToLower() ]
.Value
"\\n"
l.["(If the prayer request has been answered, or an event has passed, consider inactivating it instead.)"]
.Value
]
|> String.concat ""
2019-02-18 01:25:07 +00:00
tr [] [
td [] [
2020-11-16 02:57:09 +00:00
a [ _href $"/web/prayer-request/{reqId}/edit"; _title l.["Edit This Prayer Request"].Value ]
2019-02-18 01:25:07 +00:00
[ icon "edit" ]
match req.isExpired now m.smallGroup.preferences.daysToExpire with
2019-02-18 01:25:07 +00:00
| true ->
2020-11-16 02:57:09 +00:00
a [ _href $"/web/prayer-request/{reqId}/restore"
2019-09-24 01:40:47 +00:00
_title l.["Restore This Inactive Request"].Value ]
2019-02-18 01:25:07 +00:00
[ icon "visibility" ]
| false ->
2020-11-16 02:57:09 +00:00
a [ _href $"/web/prayer-request/{reqId}/expire"
2019-09-24 01:40:47 +00:00
_title l.["Expire This Request Immediately"].Value ]
2019-02-18 01:25:07 +00:00
[ icon "visibility_off" ]
2019-09-24 01:40:47 +00:00
a [ _href delAction; _title l.["Delete This Request"].Value;
2020-11-16 02:57:09 +00:00
_onclick $"return PT.confirmDelete('{delAction}','{delPrompt}')" ]
2019-02-18 01:25:07 +00:00
[ icon "delete_forever" ]
]
td [ updReq req ] [
2020-11-16 02:57:09 +00:00
str (req.updatedDate.ToString(s.["MMMM d, yyyy"].Value, Globalization.CultureInfo.CurrentUICulture))
2019-02-18 01:25:07 +00:00
]
td [] [ locStr typs.[req.requestType] ]
td [ reqExp req ] [ str (match req.requestor with Some r -> r | None -> " ") ]
2019-02-18 01:25:07 +00:00
td [] [
2019-09-24 01:40:47 +00:00
match reqText.Length with
| len when len < 60 -> rawText reqText
2020-11-16 02:57:09 +00:00
| _ -> rawText $"{reqText.[0..59]}&hellip;"
2019-02-18 01:25:07 +00:00
]
])
|> List.ofSeq
2019-09-24 01:40:47 +00:00
[ div [ _class "pt-center-text" ] [
br []
2020-11-16 02:57:09 +00:00
a [ _href $"/web/prayer-request/{emptyGuid}/edit"; _title s.["Add a New Request"].Value ]
[ icon "add_circle"; rawText " &nbsp;"; locStr s.["Add a New Request"] ]
2019-09-24 01:40:47 +00:00
rawText " &nbsp; &nbsp; &nbsp; "
a [ _href "/web/prayer-requests/view"; _title s.["View Prayer Request List"].Value ]
[ icon "list"; rawText " &nbsp;"; locStr s.["View Prayer Request List"] ]
match m.searchTerm with
| Some _ ->
2019-09-24 01:40:47 +00:00
rawText " &nbsp; &nbsp; &nbsp; "
a [ _href "/web/prayer-requests"; _title l.["Clear Search Criteria"].Value ]
[ icon "highlight_off"; rawText " &nbsp;"; raw l.["Clear Search Criteria"] ]
| None -> ()
2019-02-18 01:25:07 +00:00
]
2019-09-24 01:40:47 +00:00
form [ _action "/web/prayer-requests"; _method "get"; _class "pt-center-text pt-search-form" ] [
input [ _type "text"
_name "search"
_placeholder l.["Search requests..."].Value
_value (defaultArg m.searchTerm "")
]
space
submit [] "search" s.["Search"]
]
2019-09-24 01:40:47 +00:00
br []
tableSummary requests.Length s
match requests.Length with
| 0 -> ()
| _ ->
2019-09-24 01:40:47 +00:00
table [ _class "pt-table pt-action-table" ] [
thead [] [
tr [] [
th [] [ locStr s.["Actions"] ]
th [] [ locStr s.["Updated Date"] ]
th [] [ locStr s.["Type"] ]
th [] [ locStr s.["Requestor"] ]
th [] [ locStr s.["Request"] ]
]
]
tbody [] requests
2019-02-18 01:25:07 +00:00
]
2019-09-24 01:40:47 +00:00
div [ _class "pt-center-text" ] [
br []
match m.onlyActive with
| Some true ->
2019-09-24 01:40:47 +00:00
raw l.["Inactive requests are currently not shown"]
br []
a [ _href "/web/prayer-requests/inactive" ] [ raw l.["Show Inactive Requests"] ]
| _ ->
match Option.isSome m.onlyActive with
| true ->
2019-09-24 01:40:47 +00:00
raw l.["Inactive requests are currently shown"]
br []
a [ _href "/web/prayer-requests" ] [ raw l.["Do Not Show Inactive Requests"] ]
br []
br []
| false -> ()
2019-09-24 01:40:47 +00:00
let srch = [ match m.searchTerm with Some s -> "search", s | None -> () ]
let pg = defaultArg m.pageNbr 1
2019-09-24 01:40:47 +00:00
let url =
match m.onlyActive with Some true | None -> "" | _ -> "/inactive" |> sprintf "/web/prayer-requests%s"
match pg with
| 1 -> ()
| _ ->
// button (_type "submit" :: attrs) [ icon ico; rawText " &nbsp;"; locStr text ]
let withPage = match pg with 2 -> srch | _ -> ("page", string (pg - 1)) :: srch
2019-09-24 01:40:47 +00:00
a [ _href (makeUrl url withPage) ]
[ icon "keyboard_arrow_left"; space; raw l.["Previous Page"] ]
2019-09-24 01:40:47 +00:00
rawText " &nbsp; &nbsp; "
match requests.Length = m.smallGroup.preferences.pageSize with
| true ->
2019-09-24 01:40:47 +00:00
a [ _href (makeUrl url (("page", string (pg + 1)) :: srch)) ]
[ raw l.["Next Page"]; space; icon "keyboard_arrow_right" ]
| false -> ()
2019-02-18 01:25:07 +00:00
]
2019-09-24 01:40:47 +00:00
form [ _id "DeleteForm"; _action ""; _method "post" ] [ csrfToken ctx ]
2019-02-18 01:25:07 +00:00
]
|> Layout.Content.wide
|> Layout.standard vi (match m.searchTerm with Some _ -> "Search Results" | None -> "Maintain Requests")
2019-02-18 01:25:07 +00:00
/// View for the printable prayer request list
let print m version =
let s = I18N.localizer.Force ()
2020-11-16 02:57:09 +00:00
let pageTitle = $"""{s.["Prayer Requests"].Value} {m.listGroup.name}"""
let imgAlt = $"""{s.["PrayerTracker"].Value} {s.["from Bit Badger Solutions"].Value}"""
2019-02-18 01:25:07 +00:00
article [] [
rawText (m.asHtml s)
br []
hr []
2020-11-16 02:57:09 +00:00
div [ _style $"font-size:70%%;font-family:{m.listGroup.preferences.listFonts};" ] [
img [ _src $"""/img/{s.["footer_en"].Value}.png"""
2019-02-18 01:25:07 +00:00
_style "vertical-align:text-bottom;"
_alt imgAlt
_title imgAlt ]
space
str version
2019-02-18 01:25:07 +00:00
]
]
|> Layout.bare pageTitle
/// View for the prayer request list
let view m vi =
let s = I18N.localizer.Force ()
2020-11-16 02:57:09 +00:00
let pageTitle = $"""{s.["Prayer Requests"].Value} {m.listGroup.name}"""
2019-02-18 01:25:07 +00:00
let spacer = rawText " &nbsp; &nbsp; &nbsp; "
let dtString = m.date.ToString "yyyy-MM-dd"
[ div [ _class "pt-center-text" ] [
2019-09-24 01:40:47 +00:00
br []
a [ _class "pt-icon-link"
2020-11-16 02:57:09 +00:00
_href $"/web/prayer-requests/print/{dtString}"
2019-09-24 01:40:47 +00:00
_title s.["View Printable"].Value ] [
icon "print"; rawText " &nbsp;"; locStr s.["View Printable"]
2019-02-18 01:25:07 +00:00
]
match m.canEmail with
| true ->
2019-09-24 01:40:47 +00:00
spacer
2019-02-18 01:25:07 +00:00
match m.date.DayOfWeek = DayOfWeek.Sunday with
| true -> ()
| false ->
let rec findSunday (date : DateTime) =
match date.DayOfWeek = DayOfWeek.Sunday with
| true -> date
| false -> findSunday (date.AddDays 1.)
let sunday = findSunday m.date
2019-09-24 01:40:47 +00:00
a [ _class "pt-icon-link"
2020-11-16 02:57:09 +00:00
_href $"""/web/prayer-requests/view/{sunday.ToString "yyyy-MM-dd"}"""
2019-09-24 01:40:47 +00:00
_title s.["List for Next Sunday"].Value ] [
icon "update"; rawText " &nbsp;"; locStr s.["List for Next Sunday"]
2019-02-18 01:25:07 +00:00
]
2019-09-24 01:40:47 +00:00
spacer
let emailPrompt = s.["This will e-mail the current list to every member of your group, without further prompting. Are you sure this is what you are ready to do?"].Value
2019-09-24 01:40:47 +00:00
a [ _class "pt-icon-link"
2020-11-16 02:57:09 +00:00
_href $"/web/prayer-requests/email/{dtString}"
2019-09-24 01:40:47 +00:00
_title s.["Send via E-mail"].Value
2020-11-16 02:57:09 +00:00
_onclick $"return PT.requests.view.promptBeforeEmail('{emailPrompt}')" ] [
icon "mail_outline"; rawText " &nbsp;"; locStr s.["Send via E-mail"]
2019-02-18 01:25:07 +00:00
]
2019-09-24 01:40:47 +00:00
spacer
a [ _class "pt-icon-link"; _href "/web/prayer-requests"; _title s.["Maintain Prayer Requests"].Value ] [
icon "compare_arrows"; rawText " &nbsp;"; locStr s.["Maintain Prayer Requests"]
2019-02-18 01:25:07 +00:00
]
| false -> ()
]
br []
rawText (m.asHtml s)
]
|> Layout.Content.standard
|> Layout.standard vi pageTitle