From eaf41949d40bb9b6f3370a9b4d5ff46e5ef73d0a Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Sun, 18 Nov 2018 10:37:57 -0800 Subject: [PATCH] ui: Refactor page view/framing to handle titles --- ui/src/Main.elm | 42 ++++++++++++++-------------- ui/src/Page/Home.elm | 24 ++++++++-------- ui/src/Page/Mailbox.elm | 42 ++++++++++++++-------------- ui/src/Page/Monitor.elm | 54 ++++++++++++++++++------------------ ui/src/Page/Status.elm | 61 +++++++++++++++++++++-------------------- ui/src/Ports.elm | 4 --- ui/src/index.js | 5 ---- 7 files changed, 112 insertions(+), 120 deletions(-) diff --git a/ui/src/Main.elm b/ui/src/Main.elm index 08f3f2b..bba9c70 100644 --- a/ui/src/Main.elm +++ b/ui/src/Main.elm @@ -255,10 +255,7 @@ setRoute route model = Route.Status -> ( { model | page = Status Status.init } - , Cmd.batch - [ Ports.windowTitle "Inbucket Status" - , Cmd.map StatusMsg Status.load - ] + , Cmd.map StatusMsg Status.load , Session.none ) in @@ -313,27 +310,30 @@ view model = , recentActive = mailbox } - frame = - Page.frame controls model.session + framePage : + ActivePage + -> (msg -> Msg) + -> { title : String, content : Html msg } + -> Document Msg + framePage page toMsg { title, content } = + Document title + [ content + |> Html.map toMsg + |> Page.frame controls model.session page + ] in - Document "Inbucket Document" - [ case model.page of - Home subModel -> - Html.map HomeMsg (Home.view model.session subModel) - |> frame Page.Other + case model.page of + Home subModel -> + framePage Page.Other HomeMsg (Home.view model.session subModel) - Mailbox subModel -> - Html.map MailboxMsg (Mailbox.view model.session subModel) - |> frame Page.Mailbox + Mailbox subModel -> + framePage Page.Mailbox MailboxMsg (Mailbox.view model.session subModel) - Monitor subModel -> - Html.map MonitorMsg (Monitor.view model.session subModel) - |> frame Page.Monitor + Monitor subModel -> + framePage Page.Monitor MonitorMsg (Monitor.view model.session subModel) - Status subModel -> - Html.map StatusMsg (Status.view model.session subModel) - |> frame Page.Status - ] + Status subModel -> + framePage Page.Status StatusMsg (Status.view model.session subModel) diff --git a/ui/src/Page/Home.elm b/ui/src/Page/Home.elm index 6dbaee2..9611f8c 100644 --- a/ui/src/Page/Home.elm +++ b/ui/src/Page/Home.elm @@ -19,12 +19,7 @@ type alias Model = init : ( Model, Cmd Msg ) init = - ( Model "" - , Cmd.batch - [ Ports.windowTitle "Inbucket" - , cmdGreeting - ] - ) + ( Model "", cmdGreeting ) cmdGreeting : Cmd Msg @@ -57,12 +52,15 @@ update session msg model = -- VIEW -- -view : Session -> Model -> Html Msg +view : Session -> Model -> { title : String, content : Html Msg } view session model = - div [ id "page" ] - [ Html.node "rendered-html" - [ class "greeting" - , property "content" (Encode.string model.greeting) + { title = "Inbucket" + , content = + div [ id "page" ] + [ Html.node "rendered-html" + [ class "greeting" + , property "content" (Encode.string model.greeting) + ] + [] ] - [] - ] + } diff --git a/ui/src/Page/Mailbox.elm b/ui/src/Page/Mailbox.elm index 7efa70e..acb7c52 100644 --- a/ui/src/Page/Mailbox.elm +++ b/ui/src/Page/Mailbox.elm @@ -87,8 +87,7 @@ init mailboxName selection = load : String -> Cmd Msg load mailboxName = Cmd.batch - [ Ports.windowTitle (mailboxName ++ " - Inbucket") - , Task.perform Tick Time.now + [ Task.perform Tick Time.now , getList mailboxName ] @@ -463,29 +462,32 @@ getMessage mailboxName id = -- VIEW -view : Session -> Model -> Html Msg +view : Session -> Model -> { title : String, content : Html Msg } view session model = - div [ id "page", class "mailbox" ] - [ viewMessageList session model - , main_ - [ id "message" ] - [ case model.state of - ShowingList _ NoMessage -> - text - ("Select a message on the left," - ++ " or enter a different username into the box on upper right." - ) + { title = model.mailboxName ++ " - Inbucket" + , content = + div [ id "page", class "mailbox" ] + [ viewMessageList session model + , main_ + [ id "message" ] + [ case model.state of + ShowingList _ NoMessage -> + text + ("Select a message on the left," + ++ " or enter a different username into the box on upper right." + ) - ShowingList _ (ShowingMessage { message }) -> - viewMessage message model.bodyMode + ShowingList _ (ShowingMessage { message }) -> + viewMessage message model.bodyMode - ShowingList _ (Transitioning { message }) -> - viewMessage message model.bodyMode + ShowingList _ (Transitioning { message }) -> + viewMessage message model.bodyMode - _ -> - text "" + _ -> + text "" + ] ] - ] + } viewMessageList : Session -> Model -> Html Msg diff --git a/ui/src/Page/Monitor.elm b/ui/src/Page/Monitor.elm index 27f9263..7fe1ba0 100644 --- a/ui/src/Page/Monitor.elm +++ b/ui/src/Page/Monitor.elm @@ -32,12 +32,7 @@ type alias Model = init : ( Model, Cmd Msg ) init = - ( Model False [] - , Cmd.batch - [ Ports.windowTitle "Inbucket Monitor" - , Ports.monitorCommand True - ] - ) + ( Model False [], Ports.monitorCommand True ) @@ -95,32 +90,35 @@ update session msg model = -- VIEW -view : Session -> Model -> Html Msg +view : Session -> Model -> { title : String, content : Html Msg } view session model = - div [ id "page" ] - [ h1 [] [ text "Monitor" ] - , p [] - [ text "Messages will be listed here shortly after delivery. " - , em [] - [ text - (if model.connected then - "Connected." + { title = "Inbucket Monitor" + , content = + div [ id "page" ] + [ h1 [] [ text "Monitor" ] + , p [] + [ text "Messages will be listed here shortly after delivery. " + , em [] + [ text + (if model.connected then + "Connected." - else - "Disconnected!" - ) + else + "Disconnected!" + ) + ] + ] + , table [ id "monitor" ] + [ thead [] + [ th [] [ text "Date" ] + , th [ class "desktop" ] [ text "From" ] + , th [] [ text "Mailbox" ] + , th [] [ text "Subject" ] + ] + , tbody [] (List.map viewMessage model.messages) ] ] - , table [ id "monitor" ] - [ thead [] - [ th [] [ text "Date" ] - , th [ class "desktop" ] [ text "From" ] - , th [] [ text "Mailbox" ] - , th [] [ text "Subject" ] - ] - , tbody [] (List.map viewMessage model.messages) - ] - ] + } viewMessage : MessageHeader -> Html Msg diff --git a/ui/src/Page/Status.elm b/ui/src/Page/Status.elm index b67d1a4..3f49d03 100644 --- a/ui/src/Page/Status.elm +++ b/ui/src/Page/Status.elm @@ -217,38 +217,41 @@ getMetrics = -- VIEW -- -view : Session -> Model -> Html Msg +view : Session -> Model -> { title : String, content : Html Msg } view session model = - div [ id "page" ] - [ h1 [] [ text "Status" ] - , case model.metrics of - Nothing -> - div [] [ text "Loading metrics..." ] + { title = "Inbucket Status" + , content = + div [ id "page" ] + [ h1 [] [ text "Status" ] + , case model.metrics of + Nothing -> + div [] [ text "Loading metrics..." ] - Just metrics -> - div [] - [ framePanel "General Metrics" - [ viewMetric model.sysMem - , viewMetric model.heapSize - , viewMetric model.heapUsed - , viewMetric model.heapObjects - , viewMetric model.goRoutines - , viewMetric model.webSockets + Just metrics -> + div [] + [ framePanel "General Metrics" + [ viewMetric model.sysMem + , viewMetric model.heapSize + , viewMetric model.heapUsed + , viewMetric model.heapObjects + , viewMetric model.goRoutines + , viewMetric model.webSockets + ] + , framePanel "SMTP Metrics" + [ viewMetric model.smtpConnOpen + , viewMetric model.smtpConnTotal + , viewMetric model.smtpReceivedTotal + , viewMetric model.smtpErrorsTotal + , viewMetric model.smtpWarnsTotal + ] + , framePanel "Storage Metrics" + [ viewMetric model.retentionDeletesTotal + , viewMetric model.retainedCount + , viewMetric model.retainedSize + ] ] - , framePanel "SMTP Metrics" - [ viewMetric model.smtpConnOpen - , viewMetric model.smtpConnTotal - , viewMetric model.smtpReceivedTotal - , viewMetric model.smtpErrorsTotal - , viewMetric model.smtpWarnsTotal - ] - , framePanel "Storage Metrics" - [ viewMetric model.retentionDeletesTotal - , viewMetric model.retainedCount - , viewMetric model.retainedSize - ] - ] - ] + ] + } viewMetric : Metric -> Html Msg diff --git a/ui/src/Ports.elm b/ui/src/Ports.elm index 108c1f0..9d85612 100644 --- a/ui/src/Ports.elm +++ b/ui/src/Ports.elm @@ -3,7 +3,6 @@ port module Ports exposing , monitorMessage , onSessionChange , storeSession - , windowTitle ) import Data.Session exposing (Persistent) @@ -20,6 +19,3 @@ port onSessionChange : (Value -> msg) -> Sub msg port storeSession : Persistent -> Cmd msg - - -port windowTitle : String -> Cmd msg diff --git a/ui/src/index.js b/ui/src/index.js index e929226..70ccdcb 100644 --- a/ui/src/index.js +++ b/ui/src/index.js @@ -34,8 +34,3 @@ function sessionObject() { } return null } - -// Window title. -app.ports.windowTitle.subscribe(function (title) { - document.title = title -})