mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-18 10:07:02 +00:00
ui: Initial Elm UI import
Merged from https://github.com/jhillyerd/inbucket-elm Uses https://github.com/halfzebra/create-elm-app
This commit is contained in:
44
ui/src/Data/Message.elm
Normal file
44
ui/src/Data/Message.elm
Normal file
@@ -0,0 +1,44 @@
|
||||
module Data.Message exposing (..)
|
||||
|
||||
import Json.Decode as Decode exposing (..)
|
||||
import Json.Decode.Pipeline exposing (..)
|
||||
|
||||
|
||||
type alias Message =
|
||||
{ mailbox : String
|
||||
, id : String
|
||||
, from : String
|
||||
, to : List String
|
||||
, subject : String
|
||||
, date : String
|
||||
, size : Int
|
||||
, seen : Bool
|
||||
, body : Body
|
||||
}
|
||||
|
||||
|
||||
type alias Body =
|
||||
{ text : String
|
||||
, html : String
|
||||
}
|
||||
|
||||
|
||||
decoder : Decoder Message
|
||||
decoder =
|
||||
decode Message
|
||||
|> required "mailbox" string
|
||||
|> required "id" string
|
||||
|> optional "from" string ""
|
||||
|> required "to" (list string)
|
||||
|> optional "subject" string ""
|
||||
|> required "date" string
|
||||
|> required "size" int
|
||||
|> required "seen" bool
|
||||
|> required "body" bodyDecoder
|
||||
|
||||
|
||||
bodyDecoder : Decoder Body
|
||||
bodyDecoder =
|
||||
decode Body
|
||||
|> required "text" string
|
||||
|> required "html" string
|
||||
29
ui/src/Data/MessageHeader.elm
Normal file
29
ui/src/Data/MessageHeader.elm
Normal file
@@ -0,0 +1,29 @@
|
||||
module Data.MessageHeader exposing (..)
|
||||
|
||||
import Json.Decode as Decode exposing (..)
|
||||
import Json.Decode.Pipeline exposing (..)
|
||||
|
||||
|
||||
type alias MessageHeader =
|
||||
{ mailbox : String
|
||||
, id : String
|
||||
, from : String
|
||||
, to : List String
|
||||
, subject : String
|
||||
, date : String
|
||||
, size : Int
|
||||
, seen : Bool
|
||||
}
|
||||
|
||||
|
||||
decoder : Decoder MessageHeader
|
||||
decoder =
|
||||
decode MessageHeader
|
||||
|> required "mailbox" string
|
||||
|> required "id" string
|
||||
|> optional "from" string ""
|
||||
|> required "to" (list string)
|
||||
|> optional "subject" string ""
|
||||
|> required "date" string
|
||||
|> required "size" int
|
||||
|> required "seen" bool
|
||||
62
ui/src/Data/Metrics.elm
Normal file
62
ui/src/Data/Metrics.elm
Normal file
@@ -0,0 +1,62 @@
|
||||
module Data.Metrics exposing (..)
|
||||
|
||||
import Json.Decode as Decode exposing (..)
|
||||
import Json.Decode.Pipeline exposing (..)
|
||||
|
||||
|
||||
type alias Metrics =
|
||||
{ sysMem : Int
|
||||
, heapSize : Int
|
||||
, heapUsed : Int
|
||||
, heapObjects : Int
|
||||
, goRoutines : Int
|
||||
, webSockets : Int
|
||||
, smtpConnOpen : Int
|
||||
, smtpConnTotal : Int
|
||||
, smtpConnHist : List Int
|
||||
, smtpReceivedTotal : Int
|
||||
, smtpReceivedHist : List Int
|
||||
, smtpErrorsTotal : Int
|
||||
, smtpErrorsHist : List Int
|
||||
, smtpWarnsTotal : Int
|
||||
, smtpWarnsHist : List Int
|
||||
, retentionDeletesTotal : Int
|
||||
, retentionDeletesHist : List Int
|
||||
, retainedCount : Int
|
||||
, retainedCountHist : List Int
|
||||
, retainedSize : Int
|
||||
, retainedSizeHist : List Int
|
||||
}
|
||||
|
||||
|
||||
decoder : Decoder Metrics
|
||||
decoder =
|
||||
decode Metrics
|
||||
|> requiredAt [ "memstats", "Sys" ] int
|
||||
|> requiredAt [ "memstats", "HeapSys" ] int
|
||||
|> requiredAt [ "memstats", "HeapAlloc" ] int
|
||||
|> requiredAt [ "memstats", "HeapObjects" ] int
|
||||
|> requiredAt [ "goroutines" ] int
|
||||
|> requiredAt [ "http", "WebSocketConnectsCurrent" ] int
|
||||
|> requiredAt [ "smtp", "ConnectsCurrent" ] int
|
||||
|> requiredAt [ "smtp", "ConnectsTotal" ] int
|
||||
|> requiredAt [ "smtp", "ConnectsHist" ] decodeIntList
|
||||
|> requiredAt [ "smtp", "ReceivedTotal" ] int
|
||||
|> requiredAt [ "smtp", "ReceivedHist" ] decodeIntList
|
||||
|> requiredAt [ "smtp", "ErrorsTotal" ] int
|
||||
|> requiredAt [ "smtp", "ErrorsHist" ] decodeIntList
|
||||
|> requiredAt [ "smtp", "WarnsTotal" ] int
|
||||
|> requiredAt [ "smtp", "WarnsHist" ] decodeIntList
|
||||
|> requiredAt [ "retention", "DeletesTotal" ] int
|
||||
|> requiredAt [ "retention", "DeletesHist" ] decodeIntList
|
||||
|> requiredAt [ "retention", "RetainedCurrent" ] int
|
||||
|> requiredAt [ "retention", "RetainedHist" ] decodeIntList
|
||||
|> requiredAt [ "retention", "RetainedSize" ] int
|
||||
|> requiredAt [ "retention", "SizeHist" ] decodeIntList
|
||||
|
||||
|
||||
{-| Decodes Inbuckets hacky comma-separated-int JSON strings.
|
||||
-}
|
||||
decodeIntList : Decoder (List Int)
|
||||
decodeIntList =
|
||||
map (String.split "," >> List.map (String.toInt >> Result.withDefault 0)) string
|
||||
91
ui/src/Data/Session.elm
Normal file
91
ui/src/Data/Session.elm
Normal file
@@ -0,0 +1,91 @@
|
||||
module Data.Session
|
||||
exposing
|
||||
( Session
|
||||
, Persistent
|
||||
, Msg(..)
|
||||
, decoder
|
||||
, decodeValueWithDefault
|
||||
, init
|
||||
, none
|
||||
, update
|
||||
)
|
||||
|
||||
import Json.Decode as Decode exposing (..)
|
||||
import Json.Decode.Pipeline exposing (..)
|
||||
|
||||
|
||||
type alias Session =
|
||||
{ flash : String
|
||||
, routing : Bool
|
||||
, persistent : Persistent
|
||||
}
|
||||
|
||||
|
||||
type alias Persistent =
|
||||
{ recentMailboxes : List String
|
||||
}
|
||||
|
||||
|
||||
type Msg
|
||||
= None
|
||||
| SetFlash String
|
||||
| ClearFlash
|
||||
| DisableRouting
|
||||
| EnableRouting
|
||||
| AddRecent String
|
||||
|
||||
|
||||
init : Persistent -> Session
|
||||
init persistent =
|
||||
Session "" True persistent
|
||||
|
||||
|
||||
update : Msg -> Session -> Session
|
||||
update msg session =
|
||||
case msg of
|
||||
None ->
|
||||
session
|
||||
|
||||
SetFlash flash ->
|
||||
{ session | flash = flash }
|
||||
|
||||
ClearFlash ->
|
||||
{ session | flash = "" }
|
||||
|
||||
DisableRouting ->
|
||||
{ session | routing = False }
|
||||
|
||||
EnableRouting ->
|
||||
{ session | routing = True }
|
||||
|
||||
AddRecent mailbox ->
|
||||
if List.head session.persistent.recentMailboxes == Just mailbox then
|
||||
session
|
||||
else
|
||||
let
|
||||
recent =
|
||||
session.persistent.recentMailboxes
|
||||
|> List.filter ((/=) mailbox)
|
||||
|> List.take 7
|
||||
|> (::) mailbox
|
||||
|
||||
persistent =
|
||||
session.persistent
|
||||
in
|
||||
{ session | persistent = { persistent | recentMailboxes = recent } }
|
||||
|
||||
|
||||
none : Msg
|
||||
none =
|
||||
None
|
||||
|
||||
|
||||
decoder : Decoder Persistent
|
||||
decoder =
|
||||
decode Persistent
|
||||
|> optional "recentMailboxes" (list string) []
|
||||
|
||||
|
||||
decodeValueWithDefault : Value -> Persistent
|
||||
decodeValueWithDefault =
|
||||
Decode.decodeValue decoder >> Result.withDefault { recentMailboxes = [] }
|
||||
Reference in New Issue
Block a user