1
0
mirror of https://github.com/jhillyerd/inbucket.git synced 2025-12-17 17:47:03 +00:00

ui: Reformat with new elm-format

This commit is contained in:
James Hillyerd
2018-11-12 19:59:15 -08:00
parent c92cd309bc
commit d1954cdd6f
10 changed files with 258 additions and 258 deletions

View File

@@ -18,4 +18,4 @@ date =
Err error ->
fail error
in
string |> andThen convert
string |> andThen convert

View File

@@ -1,10 +1,10 @@
module Data.Session
exposing
( Session
( Msg(..)
, Persistent
, Msg(..)
, decoder
, Session
, decodeValueWithDefault
, decoder
, init
, none
, update
@@ -74,7 +74,7 @@ update msg session =
persistent =
session.persistent
in
{ session | persistent = { persistent | recentMailboxes = recent } }
{ session | persistent = { persistent | recentMailboxes = recent } }
none : Msg

View File

@@ -1,8 +1,8 @@
module Main exposing (..)
import Data.Session as Session exposing (Session, decoder)
import Json.Decode as Decode exposing (Value)
import Html exposing (..)
import Json.Decode as Decode exposing (Value)
import Navigation exposing (Location)
import Page.Home as Home
import Page.Mailbox as Mailbox
@@ -45,7 +45,7 @@ init sessionValue location =
route =
Route.fromLocation location
in
applySession (setRoute route model)
applySession (setRoute route model)
type Msg
@@ -118,17 +118,17 @@ update msg model =
session =
model.session
in
( { model | session = { session | persistent = persistent } }
, Cmd.none
, Session.none
)
( { model | session = { session | persistent = persistent } }
, Cmd.none
, Session.none
)
UpdateSession (Err error) ->
let
_ =
Debug.log "Error decoding session" error
in
( model, Cmd.none, Session.none )
( model, Cmd.none, Session.none )
MailboxNameInput name ->
( { model | mailboxName = name }, Cmd.none, Session.none )
@@ -155,24 +155,24 @@ updatePage msg model =
( newModel, subCmd, sessionMsg ) =
subUpdate model.session subMsg subModel
in
( { model | page = toPage newModel }, Cmd.map toMsg subCmd, sessionMsg )
( { model | page = toPage newModel }, Cmd.map toMsg subCmd, sessionMsg )
in
case ( msg, model.page ) of
( HomeMsg subMsg, Home subModel ) ->
modelUpdate Home HomeMsg Home.update subMsg subModel
case ( msg, model.page ) of
( HomeMsg subMsg, Home subModel ) ->
modelUpdate Home HomeMsg Home.update subMsg subModel
( MailboxMsg subMsg, Mailbox subModel ) ->
modelUpdate Mailbox MailboxMsg Mailbox.update subMsg subModel
( MailboxMsg subMsg, Mailbox subModel ) ->
modelUpdate Mailbox MailboxMsg Mailbox.update subMsg subModel
( MonitorMsg subMsg, Monitor subModel ) ->
modelUpdate Monitor MonitorMsg Monitor.update subMsg subModel
( MonitorMsg subMsg, Monitor subModel ) ->
modelUpdate Monitor MonitorMsg Monitor.update subMsg subModel
( StatusMsg subMsg, Status subModel ) ->
modelUpdate Status StatusMsg Status.update subMsg subModel
( StatusMsg subMsg, Status subModel ) ->
modelUpdate Status StatusMsg Status.update subMsg subModel
( _, _ ) ->
-- Disregard messages destined for the wrong page.
( model, Cmd.none, Session.none )
( _, _ ) ->
-- Disregard messages destined for the wrong page.
( model, Cmd.none, Session.none )
setRoute : Route -> Model -> ( Model, Cmd Msg, Session.Msg )
@@ -192,20 +192,20 @@ setRoute route model =
( subModel, subCmd ) =
Mailbox.init name Nothing
in
( { model | page = Mailbox subModel }
, Cmd.map MailboxMsg subCmd
, Session.none
)
( { model | page = Mailbox subModel }
, Cmd.map MailboxMsg subCmd
, Session.none
)
Route.Message mailbox id ->
let
( subModel, subCmd ) =
Mailbox.init mailbox (Just id)
in
( { model | page = Mailbox subModel }
, Cmd.map MailboxMsg subCmd
, Session.none
)
( { model | page = Mailbox subModel }
, Cmd.map MailboxMsg subCmd
, Session.none
)
Route.Monitor ->
( { model | page = Monitor (Monitor.init model.session.host) }
@@ -217,7 +217,7 @@ setRoute route model =
( { model | page = Status Status.init }
, Cmd.batch
[ Ports.windowTitle "Inbucket Status"
, Cmd.map StatusMsg (Status.load)
, Cmd.map StatusMsg Status.load
]
, Session.none
)
@@ -232,13 +232,13 @@ applySession ( model, cmd, sessionMsg ) =
newModel =
{ model | session = session }
in
if session.persistent == model.session.persistent then
-- No change
( newModel, cmd )
else
( newModel
, Cmd.batch [ cmd, Ports.storeSession session.persistent ]
)
if session.persistent == model.session.persistent then
-- No change
( newModel, cmd )
else
( newModel
, Cmd.batch [ cmd, Ports.storeSession session.persistent ]
)
@@ -267,22 +267,22 @@ view model =
frame =
Page.frame controls model.session
in
case model.page of
Home subModel ->
Html.map HomeMsg (Home.view model.session subModel)
|> frame Page.Other
case model.page of
Home subModel ->
Html.map HomeMsg (Home.view model.session subModel)
|> frame Page.Other
Mailbox subModel ->
Html.map MailboxMsg (Mailbox.view model.session subModel)
|> frame Page.Mailbox
Mailbox subModel ->
Html.map MailboxMsg (Mailbox.view model.session subModel)
|> frame Page.Mailbox
Monitor subModel ->
Html.map MonitorMsg (Monitor.view model.session subModel)
|> frame Page.Monitor
Monitor subModel ->
Html.map MonitorMsg (Monitor.view model.session subModel)
|> frame Page.Monitor
Status subModel ->
Html.map StatusMsg (Status.view model.session subModel)
|> frame Page.Status
Status subModel ->
Html.map StatusMsg (Status.view model.session subModel)
|> frame Page.Status

View File

@@ -1,8 +1,8 @@
module Page.Home exposing (Model, Msg, init, update, view)
import Data.Session as Session exposing (Session)
import Html exposing (..)
import Html.Attributes exposing (..)
import Data.Session as Session exposing (Session)
-- MODEL --

View File

@@ -4,9 +4,8 @@ import Data.Message as Message exposing (Message)
import Data.MessageHeader as MessageHeader exposing (MessageHeader)
import Data.Session as Session exposing (Session)
import Date exposing (Date)
import DateFormat.Relative as Relative
import DateFormat
import Json.Decode as Decode exposing (Decoder)
import DateFormat.Relative as Relative
import Html exposing (..)
import Html.Attributes
exposing
@@ -24,6 +23,7 @@ import Html.Attributes
import Html.Events exposing (..)
import Http exposing (Error)
import HttpUtil
import Json.Decode as Decode exposing (Decoder)
import Json.Encode as Encode
import Ports
import Route
@@ -111,10 +111,10 @@ subscriptions model =
_ ->
Sub.none
in
Sub.batch
[ Time.every (30 * Time.second) Tick
, subSeen
]
Sub.batch
[ Time.every (30 * Time.second) Tick
, subSeen
]
@@ -175,13 +175,13 @@ update session msg model =
| state = ShowingList (MessageList headers Nothing "") NoMessage
}
in
case selection of
Just id ->
-- Recurse to select message id.
update session (ViewMessage id) newModel
case selection of
Just id ->
-- Recurse to select message id.
update session (ViewMessage id) newModel
Nothing ->
( newModel, Cmd.none, Session.AddRecent model.mailboxName )
Nothing ->
( newModel, Cmd.none, Session.AddRecent model.mailboxName )
_ ->
( model, Cmd.none, Session.none )
@@ -270,21 +270,21 @@ updateMessageResult model message =
else
model.bodyMode
in
case model.state of
LoadingList _ ->
( model, Cmd.none, Session.none )
case model.state of
LoadingList _ ->
( model, Cmd.none, Session.none )
ShowingList list _ ->
( { model
| state =
ShowingList
{ list | selected = Just message.id }
(ShowingMessage (VisibleMessage message Nothing))
, bodyMode = bodyMode
}
, Task.perform OpenedTime Time.now
, Session.none
)
ShowingList list _ ->
( { model
| state =
ShowingList
{ list | selected = Just message.id }
(ShowingMessage (VisibleMessage message Nothing))
, bodyMode = bodyMode
}
, Task.perform OpenedTime Time.now
, Session.none
)
updatePurge : Model -> ( Model, Cmd Msg, Session.Msg )
@@ -296,15 +296,15 @@ updatePurge model =
|> HttpUtil.delete
|> Http.send PurgeResult
in
case model.state of
ShowingList list _ ->
( { model | state = ShowingList (MessageList [] Nothing "") NoMessage }
, cmd
, Session.none
)
case model.state of
ShowingList list _ ->
( { model | state = ShowingList (MessageList [] Nothing "") NoMessage }
, cmd
, Session.none
)
_ ->
( model, cmd, Session.none )
_ ->
( model, cmd, Session.none )
updateSearchInput : Model -> String -> ( Model, Cmd Msg, Session.Msg )
@@ -316,18 +316,18 @@ updateSearchInput model searchInput =
else
""
in
case model.state of
LoadingList _ ->
( model, Cmd.none, Session.none )
case model.state of
LoadingList _ ->
( model, Cmd.none, Session.none )
ShowingList list messageState ->
( { model
| searchInput = searchInput
, state = ShowingList { list | searchFilter = searchFilter } messageState
}
, Cmd.none
, Session.none
)
ShowingList list messageState ->
( { model
| searchInput = searchInput
, state = ShowingList { list | searchFilter = searchFilter } messageState
}
, Cmd.none
, Session.none
)
{-| Set the selected message in our model.
@@ -343,19 +343,19 @@ updateSelected model id =
newList =
{ list | selected = Just id }
in
case messageState of
NoMessage ->
{ model | state = ShowingList newList LoadingMessage }
case messageState of
NoMessage ->
{ model | state = ShowingList newList LoadingMessage }
LoadingMessage ->
{ model | state = ShowingList newList LoadingMessage }
LoadingMessage ->
{ model | state = ShowingList newList LoadingMessage }
ShowingMessage visible ->
-- Use Transitioning state to prevent blank message flicker.
{ model | state = ShowingList newList (Transitioning visible) }
ShowingMessage visible ->
-- Use Transitioning state to prevent blank message flicker.
{ model | state = ShowingList newList (Transitioning visible) }
Transitioning visible ->
{ model | state = ShowingList newList (Transitioning visible) }
Transitioning visible ->
{ model | state = ShowingList newList (Transitioning visible) }
updateDeleteMessage : Model -> Message -> ( Model, Cmd Msg, Session.Msg )
@@ -371,18 +371,18 @@ updateDeleteMessage model message =
filter f messageList =
{ messageList | headers = List.filter f messageList.headers }
in
case model.state of
ShowingList list _ ->
( { model
| state =
ShowingList (filter (\x -> x.id /= message.id) list) NoMessage
}
, cmd
, Session.none
)
case model.state of
ShowingList list _ ->
( { model
| state =
ShowingList (filter (\x -> x.id /= message.id) list) NoMessage
}
, cmd
, Session.none
)
_ ->
( model, cmd, Session.none )
_ ->
( model, cmd, Session.none )
updateMarkMessageSeen : Model -> Message -> ( Model, Cmd Msg, Session.Msg )
@@ -410,19 +410,19 @@ updateMarkMessageSeen model message =
map f messageList =
{ messageList | headers = List.map f messageList.headers }
in
( { model
| state =
ShowingList (map updateSeen list)
(ShowingMessage
{ visible
| message = { message | seen = True }
, markSeenAt = Nothing
}
)
}
, command
, Session.None
)
( { model
| state =
ShowingList (map updateSeen list)
(ShowingMessage
{ visible
| message = { message | seen = True }
, markSeenAt = Nothing
}
)
}
, command
, Session.None
)
_ ->
( model, Cmd.none, Session.none )
@@ -434,8 +434,8 @@ getList mailboxName =
url =
"/api/v1/mailbox/" ++ mailboxName
in
Http.get url (Decode.list MessageHeader.decoder)
|> Http.send ListResult
Http.get url (Decode.list MessageHeader.decoder)
|> Http.send ListResult
getMessage : String -> MessageID -> Cmd Msg
@@ -444,8 +444,8 @@ getMessage mailboxName id =
url =
"/serve/m/" ++ mailboxName ++ "/" ++ id
in
Http.get url Message.decoder
|> Http.send MessageResult
Http.get url Message.decoder
|> Http.send MessageResult
@@ -526,26 +526,26 @@ viewMessage message bodyMode =
sourceUrl message =
"/serve/m/" ++ message.mailbox ++ "/" ++ message.id ++ "/source"
in
div []
[ div [ class "button-bar" ]
[ button [ class "danger", onClick (DeleteMessage message) ] [ text "Delete" ]
, a
[ href (sourceUrl message), target "_blank" ]
[ button [] [ text "Source" ] ]
]
, dl [ id "message-header" ]
[ dt [] [ text "From:" ]
, dd [] [ text message.from ]
, dt [] [ text "To:" ]
, dd [] (List.map text message.to)
, dt [] [ text "Date:" ]
, dd [] [ verboseDate message.date ]
, dt [] [ text "Subject:" ]
, dd [] [ text message.subject ]
]
, messageBody message bodyMode
, attachments message
div []
[ div [ class "button-bar" ]
[ button [ class "danger", onClick (DeleteMessage message) ] [ text "Delete" ]
, a
[ href (sourceUrl message), target "_blank" ]
[ button [] [ text "Source" ] ]
]
, dl [ id "message-header" ]
[ dt [] [ text "From:" ]
, dd [] [ text message.from ]
, dt [] [ text "To:" ]
, dd [] (List.map text message.to)
, dt [] [ text "Date:" ]
, dd [] [ verboseDate message.date ]
, dt [] [ text "Subject:" ]
, dd [] [ text message.subject ]
]
, messageBody message bodyMode
, attachments message
]
messageBody : Message -> Body -> Html Msg
@@ -571,17 +571,17 @@ messageBody message bodyMode =
else
[ safeHtml, plainText ]
in
div [ class "tab-panel" ]
[ nav [ class "tab-bar" ] tabs
, article [ class "message-body" ]
[ case bodyMode of
SafeHtmlBody ->
div [ property "innerHTML" (Encode.string message.html) ] []
div [ class "tab-panel" ]
[ nav [ class "tab-bar" ] tabs
, article [ class "message-body" ]
[ case bodyMode of
SafeHtmlBody ->
div [ property "innerHTML" (Encode.string message.html) ] []
TextBody ->
div [ property "innerHTML" (Encode.string message.text) ] []
]
TextBody ->
div [ property "innerHTML" (Encode.string message.text) ] []
]
]
attachments : Message -> Html Msg
@@ -590,10 +590,10 @@ attachments message =
baseUrl =
"/serve/m/attach/" ++ message.mailbox ++ "/" ++ message.id ++ "/"
in
if List.isEmpty message.attachments then
div [] []
else
table [ class "attachments well" ] (List.map (attachmentRow baseUrl) message.attachments)
if List.isEmpty message.attachments then
div [] []
else
table [ class "attachments well" ] (List.map (attachmentRow baseUrl) message.attachments)
attachmentRow : String -> Message.Attachment -> Html Msg
@@ -602,13 +602,13 @@ attachmentRow baseUrl attach =
url =
baseUrl ++ attach.id ++ "/" ++ attach.fileName
in
tr []
[ td []
[ a [ href url, target "_blank" ] [ text attach.fileName ]
, text (" (" ++ attach.contentType ++ ") ")
]
, td [] [ a [ href url, downloadAs attach.fileName, class "button" ] [ text "Download" ] ]
tr []
[ td []
[ a [ href url, target "_blank" ] [ text attach.fileName ]
, text (" (" ++ attach.contentType ++ ") ")
]
, td [] [ a [ href url, downloadAs attach.fileName, class "button" ] [ text "Download" ] ]
]
relativeDate : Model -> Date -> Html Msg
@@ -651,4 +651,4 @@ filterMessageList list =
String.contains list.searchFilter (String.toLower header.subject)
|| String.contains list.searchFilter (String.toLower header.from)
in
List.filter matches list.headers
List.filter matches list.headers

View File

@@ -5,17 +5,17 @@ import Data.Session as Session exposing (Session)
import Date exposing (Date)
import DateFormat
exposing
( format
, monthNameFirstThree
( amPmUppercase
, dayOfMonthFixed
, format
, hourNumber
, minuteFixed
, amPmUppercase
, monthNameFirstThree
)
import Json.Decode exposing (decodeString)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events as Events
import Json.Decode exposing (decodeString)
import Route
import WebSocket

View File

@@ -7,7 +7,7 @@ import Html exposing (..)
import Html.Attributes exposing (..)
import Http exposing (Error)
import HttpUtil
import Sparkline exposing (sparkline, Point, DataSet, Size)
import Sparkline exposing (DataSet, Point, Size, sparkline)
import Svg.Attributes as SvgAttrib
import Time exposing (Time)
@@ -69,7 +69,7 @@ init =
initDataSet : DataSet
initDataSet =
List.range 0 59
|> List.map (\x -> ( toFloat (x), 0 ))
|> List.map (\x -> ( toFloat x, 0 ))
load : Cmd Msg
@@ -116,52 +116,52 @@ updateMetrics metrics model =
x =
model.xCounter
in
{ model
| metrics = Just metrics
, xCounter = x + 1
, sysMem = updateLocalMetric model.sysMem x metrics.sysMem
, heapSize = updateLocalMetric model.heapSize x metrics.heapSize
, heapUsed = updateLocalMetric model.heapUsed x metrics.heapUsed
, heapObjects = updateLocalMetric model.heapObjects x metrics.heapObjects
, goRoutines = updateLocalMetric model.goRoutines x metrics.goRoutines
, webSockets = updateLocalMetric model.webSockets x metrics.webSockets
, smtpConnOpen = updateLocalMetric model.smtpConnOpen x metrics.smtpConnOpen
, smtpConnTotal =
updateRemoteTotal
model.smtpConnTotal
metrics.smtpConnTotal
metrics.smtpConnHist
, smtpReceivedTotal =
updateRemoteTotal
model.smtpReceivedTotal
metrics.smtpReceivedTotal
metrics.smtpReceivedHist
, smtpErrorsTotal =
updateRemoteTotal
model.smtpErrorsTotal
metrics.smtpErrorsTotal
metrics.smtpErrorsHist
, smtpWarnsTotal =
updateRemoteTotal
model.smtpWarnsTotal
metrics.smtpWarnsTotal
metrics.smtpWarnsHist
, retentionDeletesTotal =
updateRemoteTotal
model.retentionDeletesTotal
metrics.retentionDeletesTotal
metrics.retentionDeletesHist
, retainedCount =
updateRemoteMetric
model.retainedCount
metrics.retainedCount
metrics.retainedCountHist
, retainedSize =
updateRemoteMetric
model.retainedSize
metrics.retainedSize
metrics.retainedSizeHist
}
{ model
| metrics = Just metrics
, xCounter = x + 1
, sysMem = updateLocalMetric model.sysMem x metrics.sysMem
, heapSize = updateLocalMetric model.heapSize x metrics.heapSize
, heapUsed = updateLocalMetric model.heapUsed x metrics.heapUsed
, heapObjects = updateLocalMetric model.heapObjects x metrics.heapObjects
, goRoutines = updateLocalMetric model.goRoutines x metrics.goRoutines
, webSockets = updateLocalMetric model.webSockets x metrics.webSockets
, smtpConnOpen = updateLocalMetric model.smtpConnOpen x metrics.smtpConnOpen
, smtpConnTotal =
updateRemoteTotal
model.smtpConnTotal
metrics.smtpConnTotal
metrics.smtpConnHist
, smtpReceivedTotal =
updateRemoteTotal
model.smtpReceivedTotal
metrics.smtpReceivedTotal
metrics.smtpReceivedHist
, smtpErrorsTotal =
updateRemoteTotal
model.smtpErrorsTotal
metrics.smtpErrorsTotal
metrics.smtpErrorsHist
, smtpWarnsTotal =
updateRemoteTotal
model.smtpWarnsTotal
metrics.smtpWarnsTotal
metrics.smtpWarnsHist
, retentionDeletesTotal =
updateRemoteTotal
model.retentionDeletesTotal
metrics.retentionDeletesTotal
metrics.retentionDeletesHist
, retainedCount =
updateRemoteMetric
model.retainedCount
metrics.retainedCount
metrics.retainedCountHist
, retainedSize =
updateRemoteMetric
model.retainedSize
metrics.retainedSize
metrics.retainedSizeHist
}
{-| Update a single Metric, with history tracked locally.
@@ -171,8 +171,8 @@ updateLocalMetric metric x value =
{ metric
| value = value
, history =
(Maybe.withDefault [] (List.tail metric.history))
++ [ ( x, (toFloat value) ) ]
Maybe.withDefault [] (List.tail metric.history)
++ [ ( x, toFloat value ) ]
}
@@ -320,11 +320,11 @@ graphChange data =
Just point ->
Tuple.first point
in
sparkline graphSize
[ Sparkline.Bar 2.5 data |> barStyle
, Sparkline.ZeroLine |> zeroStyle
, Sparkline.Domain [ ( x, 0 ), ( x, 1 ) ]
]
sparkline graphSize
[ Sparkline.Bar 2.5 data |> barStyle
, Sparkline.ZeroLine |> zeroStyle
, Sparkline.Domain [ ( x, 0 ), ( x, 1 ) ]
]
{-| Zero based area graph, for charting absolute values relative to 0.
@@ -341,11 +341,11 @@ graphZero data =
Just point ->
Tuple.first point
in
sparkline graphSize
[ Sparkline.Area data |> areaStyle
, Sparkline.ZeroLine |> zeroStyle
, Sparkline.Domain [ ( x, 0 ), ( x, 1 ) ]
]
sparkline graphSize
[ Sparkline.Area data |> areaStyle
, Sparkline.ZeroLine |> zeroStyle
, Sparkline.Domain [ ( x, 0 ), ( x, 1 ) ]
]
framePanel : String -> List (Html a) -> Html a
@@ -368,7 +368,7 @@ changeList numbers =
tail =
List.tail numbers |> Maybe.withDefault []
in
List.map2 (-) tail numbers
List.map2 (-) tail numbers
{-| Pad the front of a list with 0s to make it at least 60 elements long.
@@ -379,10 +379,10 @@ zeroPadList numbers =
needed =
60 - List.length numbers
in
if needed > 0 then
(List.repeat needed 0) ++ numbers
else
numbers
if needed > 0 then
List.repeat needed 0 ++ numbers
else
numbers
{-| Format an Int with thousands separators.
@@ -395,6 +395,6 @@ fmtInt n =
if String.length str <= 3 then
str
else
(thousands (String.slice 0 -3 str)) ++ "," ++ (String.right 3 str)
thousands (String.slice 0 -3 str) ++ "," ++ String.right 3 str
in
thousands (toString n)
thousands (toString n)

View File

@@ -49,7 +49,7 @@ routeToString page =
Status ->
[ "status" ]
in
"/#/" ++ String.join "/" pieces
"/#/" ++ String.join "/" pieces

View File

@@ -10,8 +10,8 @@ import Html.Attributes
, href
, id
, placeholder
, type_
, selected
, type_
, value
)
import Html.Events as Events
@@ -101,13 +101,13 @@ navbarRecent page controls =
else
controls.recentOptions
in
li
[ id "navbar-recent"
, classList [ ( "navbar-dropdown", True ), ( "navbar-active", active ) ]
]
[ span [] [ text title ]
, div [ class "navbar-dropdown-content" ] (List.map recentItemLink items)
]
li
[ id "navbar-recent"
, classList [ ( "navbar-dropdown", True ), ( "navbar-active", active ) ]
]
[ span [] [ text title ]
, div [ class "navbar-dropdown-content" ] (List.map recentItemLink items)
]
isActive : ActivePage -> Route -> Bool

View File

@@ -1,7 +1,7 @@
module Tests exposing (..)
import Test exposing (..)
import Expect
import Test exposing (..)
-- Check out http://package.elm-lang.org/packages/elm-community/elm-test/latest to learn more about testing in Elm!