mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
ui: Easy renames and refactors
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
module Data.Date exposing (date)
|
module Data.Date exposing (date)
|
||||||
|
|
||||||
import Json.Decode as Decode exposing (..)
|
import Json.Decode exposing (..)
|
||||||
import Time exposing (Posix)
|
import Time exposing (Posix)
|
||||||
|
|
||||||
|
|
||||||
@@ -8,4 +8,4 @@ import Time exposing (Posix)
|
|||||||
-}
|
-}
|
||||||
date : Decoder Posix
|
date : Decoder Posix
|
||||||
date =
|
date =
|
||||||
int |> andThen (Time.millisToPosix >> succeed)
|
int |> map Time.millisToPosix
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module Data.Message exposing (Attachment, Message, attachmentDecoder, decoder)
|
module Data.Message exposing (Attachment, Message, attachmentDecoder, decoder)
|
||||||
|
|
||||||
import Data.Date exposing (date)
|
import Data.Date exposing (date)
|
||||||
import Json.Decode as Decode exposing (..)
|
import Json.Decode exposing (..)
|
||||||
import Json.Decode.Pipeline exposing (..)
|
import Json.Decode.Pipeline exposing (..)
|
||||||
import Time exposing (Posix)
|
import Time exposing (Posix)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module Data.MessageHeader exposing (MessageHeader, decoder)
|
module Data.MessageHeader exposing (MessageHeader, decoder)
|
||||||
|
|
||||||
import Data.Date exposing (date)
|
import Data.Date exposing (date)
|
||||||
import Json.Decode as Decode exposing (..)
|
import Json.Decode exposing (..)
|
||||||
import Json.Decode.Pipeline exposing (..)
|
import Json.Decode.Pipeline exposing (..)
|
||||||
import Time exposing (Posix)
|
import Time exposing (Posix)
|
||||||
|
|
||||||
|
|||||||
@@ -59,4 +59,6 @@ decoder =
|
|||||||
-}
|
-}
|
||||||
decodeIntList : Decoder (List Int)
|
decodeIntList : Decoder (List Int)
|
||||||
decodeIntList =
|
decodeIntList =
|
||||||
map (String.split "," >> List.map (String.toInt >> Maybe.withDefault 0)) string
|
string
|
||||||
|
|> map (String.split ",")
|
||||||
|
|> map (List.map (String.toInt >> Maybe.withDefault 0))
|
||||||
|
|||||||
@@ -1,18 +1,4 @@
|
|||||||
module Main exposing
|
module Main exposing (main)
|
||||||
( Model
|
|
||||||
, Msg(..)
|
|
||||||
, Page(..)
|
|
||||||
, applySession
|
|
||||||
, init
|
|
||||||
, main
|
|
||||||
, pageSubscriptions
|
|
||||||
, sessionChange
|
|
||||||
, setRoute
|
|
||||||
, subscriptions
|
|
||||||
, update
|
|
||||||
, updatePage
|
|
||||||
, view
|
|
||||||
)
|
|
||||||
|
|
||||||
import Browser exposing (Document, UrlRequest)
|
import Browser exposing (Document, UrlRequest)
|
||||||
import Browser.Navigation as Nav
|
import Browser.Navigation as Nav
|
||||||
@@ -73,7 +59,7 @@ type Msg
|
|||||||
| UrlChanged Url
|
| UrlChanged Url
|
||||||
| LinkClicked UrlRequest
|
| LinkClicked UrlRequest
|
||||||
| UpdateSession (Result D.Error Session.Persistent)
|
| UpdateSession (Result D.Error Session.Persistent)
|
||||||
| MailboxNameInput String
|
| OnMailboxNameInput String
|
||||||
| ViewMailbox String
|
| ViewMailbox String
|
||||||
| HomeMsg Home.Msg
|
| HomeMsg Home.Msg
|
||||||
| MailboxMsg Mailbox.Msg
|
| MailboxMsg Mailbox.Msg
|
||||||
@@ -159,7 +145,7 @@ update msg model =
|
|||||||
, Session.SetFlash ("Error decoding session: " ++ D.errorToString error)
|
, Session.SetFlash ("Error decoding session: " ++ D.errorToString error)
|
||||||
)
|
)
|
||||||
|
|
||||||
MailboxNameInput name ->
|
OnMailboxNameInput name ->
|
||||||
( { model | mailboxName = name }, Cmd.none, Session.none )
|
( { model | mailboxName = name }, Cmd.none, Session.none )
|
||||||
|
|
||||||
ViewMailbox name ->
|
ViewMailbox name ->
|
||||||
@@ -303,7 +289,7 @@ view model =
|
|||||||
|
|
||||||
controls =
|
controls =
|
||||||
{ viewMailbox = ViewMailbox
|
{ viewMailbox = ViewMailbox
|
||||||
, mailboxOnInput = MailboxNameInput
|
, mailboxOnInput = OnMailboxNameInput
|
||||||
, mailboxValue = model.mailboxName
|
, mailboxValue = model.mailboxName
|
||||||
, recentOptions = model.session.persistent.recentMailboxes
|
, recentOptions = model.session.persistent.recentMailboxes
|
||||||
, recentActive = mailbox
|
, recentActive = mailbox
|
||||||
|
|||||||
@@ -19,32 +19,31 @@ type alias Model =
|
|||||||
|
|
||||||
init : ( Model, Cmd Msg )
|
init : ( Model, Cmd Msg )
|
||||||
init =
|
init =
|
||||||
|
let
|
||||||
|
cmdGreeting =
|
||||||
|
Http.get
|
||||||
|
{ url = "/serve/greeting"
|
||||||
|
, expect = Http.expectString GreetingLoaded
|
||||||
|
}
|
||||||
|
in
|
||||||
( Model "", cmdGreeting )
|
( Model "", cmdGreeting )
|
||||||
|
|
||||||
|
|
||||||
cmdGreeting : Cmd Msg
|
|
||||||
cmdGreeting =
|
|
||||||
Http.get
|
|
||||||
{ url = "/serve/greeting"
|
|
||||||
, expect = Http.expectString GreetingResult
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- UPDATE --
|
-- UPDATE --
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= GreetingResult (Result Http.Error String)
|
= GreetingLoaded (Result Http.Error String)
|
||||||
|
|
||||||
|
|
||||||
update : Session -> Msg -> Model -> ( Model, Cmd Msg, Session.Msg )
|
update : Session -> Msg -> Model -> ( Model, Cmd Msg, Session.Msg )
|
||||||
update session msg model =
|
update session msg model =
|
||||||
case msg of
|
case msg of
|
||||||
GreetingResult (Ok greeting) ->
|
GreetingLoaded (Ok greeting) ->
|
||||||
( Model greeting, Cmd.none, Session.none )
|
( Model greeting, Cmd.none, Session.none )
|
||||||
|
|
||||||
GreetingResult (Err err) ->
|
GreetingLoaded (Err err) ->
|
||||||
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ module Page.Mailbox exposing (Model, Msg, init, load, subscriptions, update, vie
|
|||||||
import Data.Message as Message exposing (Message)
|
import Data.Message as Message exposing (Message)
|
||||||
import Data.MessageHeader as MessageHeader exposing (MessageHeader)
|
import Data.MessageHeader as MessageHeader exposing (MessageHeader)
|
||||||
import Data.Session as Session exposing (Session)
|
import Data.Session as Session exposing (Session)
|
||||||
import DateFormat
|
import DateFormat as DF
|
||||||
import DateFormat.Relative as Relative
|
import DateFormat.Relative as Relative
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes
|
import Html.Attributes
|
||||||
@@ -106,7 +106,7 @@ subscriptions model =
|
|||||||
Sub.none
|
Sub.none
|
||||||
|
|
||||||
else
|
else
|
||||||
Time.every 250 SeenTick
|
Time.every 250 MarkSeenTick
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
Sub.none
|
Sub.none
|
||||||
@@ -122,20 +122,20 @@ subscriptions model =
|
|||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= ClickMessage MessageID
|
= ListLoaded (Result Http.Error (List MessageHeader))
|
||||||
| DeleteMessage Message
|
| ClickMessage MessageID
|
||||||
| DeleteMessageResult (Result Http.Error ())
|
| OpenMessage MessageID
|
||||||
| ListResult (Result Http.Error (List MessageHeader))
|
| MessageLoaded (Result Http.Error Message)
|
||||||
| MarkSeenResult (Result Http.Error ())
|
|
||||||
| MessageResult (Result Http.Error Message)
|
|
||||||
| MessageBody Body
|
| MessageBody Body
|
||||||
| OpenedTime Posix
|
| OpenedTime Posix
|
||||||
| Purge
|
| MarkSeenTick Posix
|
||||||
| PurgeResult (Result Http.Error ())
|
| MarkedSeen (Result Http.Error ())
|
||||||
| SearchInput String
|
| DeleteMessage Message
|
||||||
| SeenTick Posix
|
| DeletedMessage (Result Http.Error ())
|
||||||
|
| PurgeMailbox
|
||||||
|
| PurgedMailbox (Result Http.Error ())
|
||||||
|
| OnSearchInput String
|
||||||
| Tick Posix
|
| Tick Posix
|
||||||
| ViewMessage MessageID
|
|
||||||
|
|
||||||
|
|
||||||
update : Session -> Msg -> Model -> ( Model, Cmd Msg, Session.Msg )
|
update : Session -> Msg -> Model -> ( Model, Cmd Msg, Session.Msg )
|
||||||
@@ -151,22 +151,19 @@ update session msg model =
|
|||||||
, Session.DisableRouting
|
, Session.DisableRouting
|
||||||
)
|
)
|
||||||
|
|
||||||
ViewMessage id ->
|
OpenMessage id ->
|
||||||
( updateSelected model id
|
updateOpenMessage session model id
|
||||||
, getMessage model.mailboxName id
|
|
||||||
, Session.AddRecent model.mailboxName
|
|
||||||
)
|
|
||||||
|
|
||||||
DeleteMessage message ->
|
DeleteMessage message ->
|
||||||
updateDeleteMessage model message
|
updateDeleteMessage model message
|
||||||
|
|
||||||
DeleteMessageResult (Ok _) ->
|
DeletedMessage (Ok _) ->
|
||||||
( model, Cmd.none, Session.none )
|
( model, Cmd.none, Session.none )
|
||||||
|
|
||||||
DeleteMessageResult (Err err) ->
|
DeletedMessage (Err err) ->
|
||||||
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
||||||
|
|
||||||
ListResult (Ok headers) ->
|
ListLoaded (Ok headers) ->
|
||||||
case model.state of
|
case model.state of
|
||||||
LoadingList selection ->
|
LoadingList selection ->
|
||||||
let
|
let
|
||||||
@@ -177,8 +174,7 @@ update session msg model =
|
|||||||
in
|
in
|
||||||
case selection of
|
case selection of
|
||||||
Just id ->
|
Just id ->
|
||||||
-- Recurse to select message id.
|
updateOpenMessage session newModel id
|
||||||
update session (ViewMessage id) newModel
|
|
||||||
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
( newModel, Cmd.none, Session.AddRecent model.mailboxName )
|
( newModel, Cmd.none, Session.AddRecent model.mailboxName )
|
||||||
@@ -186,25 +182,25 @@ update session msg model =
|
|||||||
_ ->
|
_ ->
|
||||||
( model, Cmd.none, Session.none )
|
( model, Cmd.none, Session.none )
|
||||||
|
|
||||||
ListResult (Err err) ->
|
ListLoaded (Err err) ->
|
||||||
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
||||||
|
|
||||||
MarkSeenResult (Ok _) ->
|
MarkedSeen (Ok _) ->
|
||||||
( model, Cmd.none, Session.none )
|
( model, Cmd.none, Session.none )
|
||||||
|
|
||||||
MarkSeenResult (Err err) ->
|
MarkedSeen (Err err) ->
|
||||||
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
||||||
|
|
||||||
MessageResult (Ok message) ->
|
MessageLoaded (Ok message) ->
|
||||||
updateMessageResult model message
|
updateMessageResult model message
|
||||||
|
|
||||||
MessageResult (Err err) ->
|
MessageLoaded (Err err) ->
|
||||||
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
||||||
|
|
||||||
MessageBody bodyMode ->
|
MessageBody bodyMode ->
|
||||||
( { model | bodyMode = bodyMode }, Cmd.none, Session.none )
|
( { model | bodyMode = bodyMode }, Cmd.none, Session.none )
|
||||||
|
|
||||||
SearchInput searchInput ->
|
OnSearchInput searchInput ->
|
||||||
updateSearchInput model searchInput
|
updateSearchInput model searchInput
|
||||||
|
|
||||||
OpenedTime time ->
|
OpenedTime time ->
|
||||||
@@ -235,16 +231,16 @@ update session msg model =
|
|||||||
_ ->
|
_ ->
|
||||||
( model, Cmd.none, Session.none )
|
( model, Cmd.none, Session.none )
|
||||||
|
|
||||||
Purge ->
|
PurgeMailbox ->
|
||||||
updatePurge model
|
updatePurge model
|
||||||
|
|
||||||
PurgeResult (Ok _) ->
|
PurgedMailbox (Ok _) ->
|
||||||
( model, Cmd.none, Session.none )
|
( model, Cmd.none, Session.none )
|
||||||
|
|
||||||
PurgeResult (Err err) ->
|
PurgedMailbox (Err err) ->
|
||||||
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
||||||
|
|
||||||
SeenTick now ->
|
MarkSeenTick now ->
|
||||||
case model.state of
|
case model.state of
|
||||||
ShowingList _ (ShowingMessage { message, markSeenAt }) ->
|
ShowingList _ (ShowingMessage { message, markSeenAt }) ->
|
||||||
case markSeenAt of
|
case markSeenAt of
|
||||||
@@ -300,7 +296,7 @@ updatePurge model =
|
|||||||
cmd =
|
cmd =
|
||||||
"/api/v1/mailbox/"
|
"/api/v1/mailbox/"
|
||||||
++ model.mailboxName
|
++ model.mailboxName
|
||||||
|> HttpUtil.delete PurgeResult
|
|> HttpUtil.delete PurgedMailbox
|
||||||
in
|
in
|
||||||
case model.state of
|
case model.state of
|
||||||
ShowingList list _ ->
|
ShowingList list _ ->
|
||||||
@@ -372,7 +368,7 @@ updateDeleteMessage model message =
|
|||||||
"/api/v1/mailbox/" ++ message.mailbox ++ "/" ++ message.id
|
"/api/v1/mailbox/" ++ message.mailbox ++ "/" ++ message.id
|
||||||
|
|
||||||
cmd =
|
cmd =
|
||||||
HttpUtil.delete DeleteMessageResult url
|
HttpUtil.delete DeletedMessage url
|
||||||
|
|
||||||
filter f messageList =
|
filter f messageList =
|
||||||
{ messageList | headers = List.filter f messageList.headers }
|
{ messageList | headers = List.filter f messageList.headers }
|
||||||
@@ -411,7 +407,7 @@ updateMarkMessageSeen model message =
|
|||||||
-- desired change in the body.
|
-- desired change in the body.
|
||||||
Encode.object [ ( "seen", Encode.bool True ) ]
|
Encode.object [ ( "seen", Encode.bool True ) ]
|
||||||
|> Http.jsonBody
|
|> Http.jsonBody
|
||||||
|> HttpUtil.patch MarkSeenResult url
|
|> HttpUtil.patch MarkedSeen url
|
||||||
|
|
||||||
map f messageList =
|
map f messageList =
|
||||||
{ messageList | headers = List.map f messageList.headers }
|
{ messageList | headers = List.map f messageList.headers }
|
||||||
@@ -434,6 +430,14 @@ updateMarkMessageSeen model message =
|
|||||||
( model, Cmd.none, Session.none )
|
( model, Cmd.none, Session.none )
|
||||||
|
|
||||||
|
|
||||||
|
updateOpenMessage : Session -> Model -> String -> ( Model, Cmd Msg, Session.Msg )
|
||||||
|
updateOpenMessage session model id =
|
||||||
|
( updateSelected model id
|
||||||
|
, getMessage model.mailboxName id
|
||||||
|
, Session.AddRecent model.mailboxName
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
getList : String -> Cmd Msg
|
getList : String -> Cmd Msg
|
||||||
getList mailboxName =
|
getList mailboxName =
|
||||||
let
|
let
|
||||||
@@ -442,7 +446,7 @@ getList mailboxName =
|
|||||||
in
|
in
|
||||||
Http.get
|
Http.get
|
||||||
{ url = url
|
{ url = url
|
||||||
, expect = Http.expectJson ListResult (Decode.list MessageHeader.decoder)
|
, expect = Http.expectJson ListLoaded (Decode.list MessageHeader.decoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -454,7 +458,7 @@ getMessage mailboxName id =
|
|||||||
in
|
in
|
||||||
Http.get
|
Http.get
|
||||||
{ url = url
|
{ url = url
|
||||||
, expect = Http.expectJson MessageResult Message.decoder
|
, expect = Http.expectJson MessageLoaded Message.decoder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -497,11 +501,11 @@ viewMessageList session model =
|
|||||||
[ input
|
[ input
|
||||||
[ type_ "search"
|
[ type_ "search"
|
||||||
, placeholder "search"
|
, placeholder "search"
|
||||||
, onInput SearchInput
|
, onInput OnSearchInput
|
||||||
, value model.searchInput
|
, value model.searchInput
|
||||||
]
|
]
|
||||||
[]
|
[]
|
||||||
, button [ onClick Purge ] [ text "Purge" ]
|
, button [ onClick PurgeMailbox ] [ text "Purge" ]
|
||||||
]
|
]
|
||||||
, case model.state of
|
, case model.state of
|
||||||
LoadingList _ ->
|
LoadingList _ ->
|
||||||
@@ -633,24 +637,24 @@ relativeDate model date =
|
|||||||
|
|
||||||
verboseDate : Posix -> Html Msg
|
verboseDate : Posix -> Html Msg
|
||||||
verboseDate date =
|
verboseDate date =
|
||||||
DateFormat.format
|
text <|
|
||||||
[ DateFormat.monthNameFull
|
DF.format
|
||||||
, DateFormat.text " "
|
[ DF.monthNameFull
|
||||||
, DateFormat.dayOfMonthSuffix
|
, DF.text " "
|
||||||
, DateFormat.text ", "
|
, DF.dayOfMonthSuffix
|
||||||
, DateFormat.yearNumber
|
, DF.text ", "
|
||||||
, DateFormat.text " "
|
, DF.yearNumber
|
||||||
, DateFormat.hourNumber
|
, DF.text " "
|
||||||
, DateFormat.text ":"
|
, DF.hourNumber
|
||||||
, DateFormat.minuteFixed
|
, DF.text ":"
|
||||||
, DateFormat.text ":"
|
, DF.minuteFixed
|
||||||
, DateFormat.secondFixed
|
, DF.text ":"
|
||||||
, DateFormat.text " "
|
, DF.secondFixed
|
||||||
, DateFormat.amPmUppercase
|
, DF.text " "
|
||||||
]
|
, DF.amPmUppercase
|
||||||
Time.utc
|
]
|
||||||
date
|
Time.utc
|
||||||
|> text
|
date
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,15 +2,7 @@ module Page.Monitor exposing (Model, Msg, init, subscriptions, update, view)
|
|||||||
|
|
||||||
import Data.MessageHeader as MessageHeader exposing (MessageHeader)
|
import Data.MessageHeader as MessageHeader exposing (MessageHeader)
|
||||||
import Data.Session as Session exposing (Session)
|
import Data.Session as Session exposing (Session)
|
||||||
import DateFormat
|
import DateFormat as DF
|
||||||
exposing
|
|
||||||
( amPmUppercase
|
|
||||||
, dayOfMonthFixed
|
|
||||||
, format
|
|
||||||
, hourNumber
|
|
||||||
, minuteFixed
|
|
||||||
, monthNameAbbreviated
|
|
||||||
)
|
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Html.Events as Events
|
import Html.Events as Events
|
||||||
@@ -30,6 +22,11 @@ type alias Model =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type MonitorMessage
|
||||||
|
= Connected Bool
|
||||||
|
| Message MessageHeader
|
||||||
|
|
||||||
|
|
||||||
init : ( Model, Cmd Msg )
|
init : ( Model, Cmd Msg )
|
||||||
init =
|
init =
|
||||||
( Model False [], Ports.monitorCommand True )
|
( Model False [], Ports.monitorCommand True )
|
||||||
@@ -50,7 +47,7 @@ subscriptions model =
|
|||||||
|> D.decodeValue
|
|> D.decodeValue
|
||||||
|> Ports.monitorMessage
|
|> Ports.monitorMessage
|
||||||
in
|
in
|
||||||
Sub.map MonitorResult monitorMessage
|
Sub.map MessageReceived monitorMessage
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -58,25 +55,20 @@ subscriptions model =
|
|||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= MonitorResult (Result D.Error MonitorMessage)
|
= MessageReceived (Result D.Error MonitorMessage)
|
||||||
| OpenMessage MessageHeader
|
| OpenMessage MessageHeader
|
||||||
|
|
||||||
|
|
||||||
type MonitorMessage
|
|
||||||
= Connected Bool
|
|
||||||
| Message MessageHeader
|
|
||||||
|
|
||||||
|
|
||||||
update : Session -> Msg -> Model -> ( Model, Cmd Msg, Session.Msg )
|
update : Session -> Msg -> Model -> ( Model, Cmd Msg, Session.Msg )
|
||||||
update session msg model =
|
update session msg model =
|
||||||
case msg of
|
case msg of
|
||||||
MonitorResult (Ok (Connected status)) ->
|
MessageReceived (Ok (Connected status)) ->
|
||||||
( { model | connected = status }, Cmd.none, Session.none )
|
( { model | connected = status }, Cmd.none, Session.none )
|
||||||
|
|
||||||
MonitorResult (Ok (Message header)) ->
|
MessageReceived (Ok (Message header)) ->
|
||||||
( { model | messages = header :: model.messages }, Cmd.none, Session.none )
|
( { model | messages = header :: model.messages }, Cmd.none, Session.none )
|
||||||
|
|
||||||
MonitorResult (Err err) ->
|
MessageReceived (Err err) ->
|
||||||
( model, Cmd.none, Session.SetFlash (D.errorToString err) )
|
( model, Cmd.none, Session.SetFlash (D.errorToString err) )
|
||||||
|
|
||||||
OpenMessage header ->
|
OpenMessage header ->
|
||||||
@@ -133,16 +125,16 @@ viewMessage message =
|
|||||||
|
|
||||||
shortDate : Posix -> Html Msg
|
shortDate : Posix -> Html Msg
|
||||||
shortDate date =
|
shortDate date =
|
||||||
format
|
DF.format
|
||||||
[ dayOfMonthFixed
|
[ DF.dayOfMonthFixed
|
||||||
, DateFormat.text "-"
|
, DF.text "-"
|
||||||
, monthNameAbbreviated
|
, DF.monthNameAbbreviated
|
||||||
, DateFormat.text " "
|
, DF.text " "
|
||||||
, hourNumber
|
, DF.hourNumber
|
||||||
, DateFormat.text ":"
|
, DF.text ":"
|
||||||
, minuteFixed
|
, DF.minuteFixed
|
||||||
, DateFormat.text " "
|
, DF.text " "
|
||||||
, amPmUppercase
|
, DF.amPmUppercase
|
||||||
]
|
]
|
||||||
Time.utc
|
Time.utc
|
||||||
date
|
date
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import Html exposing (..)
|
|||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
import Http exposing (Error)
|
import Http exposing (Error)
|
||||||
import HttpUtil
|
import HttpUtil
|
||||||
import Sparkline exposing (DataSet, Point, Size, sparkline)
|
import Sparkline as Spark
|
||||||
import Svg.Attributes as SvgAttrib
|
import Svg.Attributes as SvgAttrib
|
||||||
import Time exposing (Posix)
|
import Time exposing (Posix)
|
||||||
|
|
||||||
@@ -40,8 +40,8 @@ type alias Metric =
|
|||||||
{ label : String
|
{ label : String
|
||||||
, value : Int
|
, value : Int
|
||||||
, formatter : Int -> String
|
, formatter : Int -> String
|
||||||
, graph : DataSet -> Html Msg
|
, graph : Spark.DataSet -> Html Msg
|
||||||
, history : DataSet
|
, history : Spark.DataSet
|
||||||
, minutes : Int
|
, minutes : Int
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ init =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
initDataSet : DataSet
|
initDataSet : Spark.DataSet
|
||||||
initDataSet =
|
initDataSet =
|
||||||
List.range 0 59
|
List.range 0 59
|
||||||
|> List.map (\x -> ( toFloat x, 0 ))
|
|> List.map (\x -> ( toFloat x, 0 ))
|
||||||
@@ -92,17 +92,17 @@ subscriptions model =
|
|||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= NewMetrics (Result Http.Error Metrics)
|
= MetricsReceived (Result Http.Error Metrics)
|
||||||
| Tick Posix
|
| Tick Posix
|
||||||
|
|
||||||
|
|
||||||
update : Session -> Msg -> Model -> ( Model, Cmd Msg, Session.Msg )
|
update : Session -> Msg -> Model -> ( Model, Cmd Msg, Session.Msg )
|
||||||
update session msg model =
|
update session msg model =
|
||||||
case msg of
|
case msg of
|
||||||
NewMetrics (Ok metrics) ->
|
MetricsReceived (Ok metrics) ->
|
||||||
( updateMetrics metrics model, Cmd.none, Session.none )
|
( updateMetrics metrics model, Cmd.none, Session.none )
|
||||||
|
|
||||||
NewMetrics (Err err) ->
|
MetricsReceived (Err err) ->
|
||||||
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
||||||
|
|
||||||
Tick time ->
|
Tick time ->
|
||||||
@@ -209,7 +209,7 @@ getMetrics : Cmd Msg
|
|||||||
getMetrics =
|
getMetrics =
|
||||||
Http.get
|
Http.get
|
||||||
{ url = "/debug/vars"
|
{ url = "/debug/vars"
|
||||||
, expect = Http.expectJson NewMetrics Metrics.decoder
|
, expect = Http.expectJson MetricsReceived Metrics.decoder
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -283,7 +283,7 @@ graphNull =
|
|||||||
div [] []
|
div [] []
|
||||||
|
|
||||||
|
|
||||||
graphSize : Size
|
graphSize : Spark.Size
|
||||||
graphSize =
|
graphSize =
|
||||||
{ width = 180
|
{ width = 180
|
||||||
, height = 16
|
, height = 16
|
||||||
@@ -292,25 +292,25 @@ graphSize =
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
areaStyle : Sparkline.Param a -> Sparkline.Param a
|
areaStyle : Spark.Param a -> Spark.Param a
|
||||||
areaStyle =
|
areaStyle =
|
||||||
Sparkline.Style
|
Spark.Style
|
||||||
[ SvgAttrib.fill "rgba(50,100,255,0.3)"
|
[ SvgAttrib.fill "rgba(50,100,255,0.3)"
|
||||||
, SvgAttrib.stroke "rgba(50,100,255,1.0)"
|
, SvgAttrib.stroke "rgba(50,100,255,1.0)"
|
||||||
, SvgAttrib.strokeWidth "1.0"
|
, SvgAttrib.strokeWidth "1.0"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
barStyle : Sparkline.Param a -> Sparkline.Param a
|
barStyle : Spark.Param a -> Spark.Param a
|
||||||
barStyle =
|
barStyle =
|
||||||
Sparkline.Style
|
Spark.Style
|
||||||
[ SvgAttrib.fill "rgba(50,200,50,0.7)"
|
[ SvgAttrib.fill "rgba(50,200,50,0.7)"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
zeroStyle : Sparkline.Param a -> Sparkline.Param a
|
zeroStyle : Spark.Param a -> Spark.Param a
|
||||||
zeroStyle =
|
zeroStyle =
|
||||||
Sparkline.Style
|
Spark.Style
|
||||||
[ SvgAttrib.stroke "rgba(0,0,0,0.2)"
|
[ SvgAttrib.stroke "rgba(0,0,0,0.2)"
|
||||||
, SvgAttrib.strokeWidth "1.0"
|
, SvgAttrib.strokeWidth "1.0"
|
||||||
]
|
]
|
||||||
@@ -318,7 +318,7 @@ zeroStyle =
|
|||||||
|
|
||||||
{-| Bar graph to be used with updateRemoteTotal metrics (change instead of absolute values).
|
{-| Bar graph to be used with updateRemoteTotal metrics (change instead of absolute values).
|
||||||
-}
|
-}
|
||||||
graphChange : DataSet -> Html a
|
graphChange : Spark.DataSet -> Html a
|
||||||
graphChange data =
|
graphChange data =
|
||||||
let
|
let
|
||||||
-- Used with Domain to stop sparkline forgetting about zero; continue scrolling graph.
|
-- Used with Domain to stop sparkline forgetting about zero; continue scrolling graph.
|
||||||
@@ -330,16 +330,16 @@ graphChange data =
|
|||||||
Just point ->
|
Just point ->
|
||||||
Tuple.first point
|
Tuple.first point
|
||||||
in
|
in
|
||||||
sparkline graphSize
|
Spark.sparkline graphSize
|
||||||
[ Sparkline.Bar 2.5 data |> barStyle
|
[ Spark.Bar 2.5 data |> barStyle
|
||||||
, Sparkline.ZeroLine |> zeroStyle
|
, Spark.ZeroLine |> zeroStyle
|
||||||
, Sparkline.Domain [ ( x, 0 ), ( x, 1 ) ]
|
, Spark.Domain [ ( x, 0 ), ( x, 1 ) ]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
{-| Zero based area graph, for charting absolute values relative to 0.
|
{-| Zero based area graph, for charting absolute values relative to 0.
|
||||||
-}
|
-}
|
||||||
graphZero : DataSet -> Html a
|
graphZero : Spark.DataSet -> Html a
|
||||||
graphZero data =
|
graphZero data =
|
||||||
let
|
let
|
||||||
-- Used with Domain to stop sparkline forgetting about zero; continue scrolling graph.
|
-- Used with Domain to stop sparkline forgetting about zero; continue scrolling graph.
|
||||||
@@ -351,10 +351,10 @@ graphZero data =
|
|||||||
Just point ->
|
Just point ->
|
||||||
Tuple.first point
|
Tuple.first point
|
||||||
in
|
in
|
||||||
sparkline graphSize
|
Spark.sparkline graphSize
|
||||||
[ Sparkline.Area data |> areaStyle
|
[ Spark.Area data |> areaStyle
|
||||||
, Sparkline.ZeroLine |> zeroStyle
|
, Spark.ZeroLine |> zeroStyle
|
||||||
, Sparkline.Domain [ ( x, 0 ), ( x, 1 ) ]
|
, Spark.Domain [ ( x, 0 ), ( x, 1 ) ]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,17 +16,20 @@ type Route
|
|||||||
| Status
|
| Status
|
||||||
|
|
||||||
|
|
||||||
routeParser : Parser (Route -> a) a
|
{-| Routes our application handles.
|
||||||
routeParser =
|
-}
|
||||||
oneOf
|
routes : List (Parser (Route -> a) a)
|
||||||
[ map Home top
|
routes =
|
||||||
, map Message (s "m" </> string </> string)
|
[ map Home top
|
||||||
, map Mailbox (s "m" </> string)
|
, map Message (s "m" </> string </> string)
|
||||||
, map Monitor (s "monitor")
|
, map Mailbox (s "m" </> string)
|
||||||
, map Status (s "status")
|
, map Monitor (s "monitor")
|
||||||
]
|
, map Status (s "status")
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
{-| Convert route to a URI.
|
||||||
|
-}
|
||||||
routeToString : Route -> String
|
routeToString : Route -> String
|
||||||
routeToString page =
|
routeToString page =
|
||||||
let
|
let
|
||||||
@@ -72,11 +75,11 @@ newUrl key =
|
|||||||
routeToString >> Navigation.pushUrl key
|
routeToString >> Navigation.pushUrl key
|
||||||
|
|
||||||
|
|
||||||
{-| Returns the Route for a given URL; by matching the path after # (fragment.)
|
{-| Returns the Route for a given URL.
|
||||||
-}
|
-}
|
||||||
fromUrl : Url -> Route
|
fromUrl : Url -> Route
|
||||||
fromUrl location =
|
fromUrl location =
|
||||||
case Parser.parse routeParser location of
|
case Parser.parse (oneOf routes) location of
|
||||||
Nothing ->
|
Nothing ->
|
||||||
Unknown location.path
|
Unknown location.path
|
||||||
|
|
||||||
|
|||||||
@@ -89,13 +89,10 @@ navbarLink session page route linkContent =
|
|||||||
navbarRecent : Session -> ActivePage -> FrameControls msg -> Html msg
|
navbarRecent : Session -> ActivePage -> FrameControls msg -> Html msg
|
||||||
navbarRecent session page controls =
|
navbarRecent session page controls =
|
||||||
let
|
let
|
||||||
recentItemLink mailbox =
|
|
||||||
a [ Route.href session.key (Route.Mailbox mailbox) ] [ text mailbox ]
|
|
||||||
|
|
||||||
active =
|
active =
|
||||||
page == Mailbox
|
page == Mailbox
|
||||||
|
|
||||||
-- Navbar tab title, is current mailbox when active.
|
-- Recent tab title is the name of the current mailbox when active.
|
||||||
title =
|
title =
|
||||||
if active then
|
if active then
|
||||||
controls.recentActive
|
controls.recentActive
|
||||||
@@ -103,20 +100,23 @@ navbarRecent session page controls =
|
|||||||
else
|
else
|
||||||
"Recent Mailboxes"
|
"Recent Mailboxes"
|
||||||
|
|
||||||
-- Items to show in recent list, doesn't include active mailbox.
|
-- Mailboxes to show in recent list, doesn't include active mailbox.
|
||||||
items =
|
recentMailboxes =
|
||||||
if active then
|
if active then
|
||||||
List.tail controls.recentOptions |> Maybe.withDefault []
|
List.tail controls.recentOptions |> Maybe.withDefault []
|
||||||
|
|
||||||
else
|
else
|
||||||
controls.recentOptions
|
controls.recentOptions
|
||||||
|
|
||||||
|
recentLink mailbox =
|
||||||
|
a [ Route.href session.key (Route.Mailbox mailbox) ] [ text mailbox ]
|
||||||
in
|
in
|
||||||
li
|
li
|
||||||
[ id "navbar-recent"
|
[ id "navbar-recent"
|
||||||
, classList [ ( "navbar-dropdown", True ), ( "navbar-active", active ) ]
|
, classList [ ( "navbar-dropdown", True ), ( "navbar-active", active ) ]
|
||||||
]
|
]
|
||||||
[ span [] [ text title ]
|
[ span [] [ text title ]
|
||||||
, div [ class "navbar-dropdown-content" ] (List.map recentItemLink items)
|
, div [ class "navbar-dropdown-content" ] (List.map recentLink recentMailboxes)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user