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

ui: Respect monitor visible config option

This commit is contained in:
James Hillyerd
2018-12-31 14:37:11 -08:00
parent c57260349b
commit 321c5615a5
5 changed files with 33 additions and 7 deletions

View File

@@ -12,6 +12,7 @@ export INBUCKET_SMTP_STOREDOMAINS="important.local"
export INBUCKET_WEB_TEMPLATECACHE="false" export INBUCKET_WEB_TEMPLATECACHE="false"
export INBUCKET_WEB_COOKIEAUTHKEY="not-secret" export INBUCKET_WEB_COOKIEAUTHKEY="not-secret"
export INBUCKET_WEB_UIDIR="ui/dist" export INBUCKET_WEB_UIDIR="ui/dist"
#export INBUCKET_WEB_MONITORVISIBLE="false"
export INBUCKET_STORAGE_TYPE="file" export INBUCKET_STORAGE_TYPE="file"
export INBUCKET_STORAGE_PARAMS="path:/tmp/inbucket" export INBUCKET_STORAGE_PARAMS="path:/tmp/inbucket"
export INBUCKET_STORAGE_RETENTIONPERIOD="3h" export INBUCKET_STORAGE_RETENTIONPERIOD="3h"

View File

@@ -1,4 +1,4 @@
module Data.AppConfig exposing (AppConfig, decoder) module Data.AppConfig exposing (AppConfig, decoder, default)
import Json.Decode as D import Json.Decode as D
import Json.Decode.Pipeline as P import Json.Decode.Pipeline as P
@@ -13,3 +13,8 @@ decoder : D.Decoder AppConfig
decoder = decoder =
D.succeed AppConfig D.succeed AppConfig
|> P.required "monitor-visible" D.bool |> P.required "monitor-visible" D.bool
default : AppConfig
default =
AppConfig True

View File

@@ -13,6 +13,7 @@ module Data.Session exposing
) )
import Browser.Navigation as Nav import Browser.Navigation as Nav
import Data.AppConfig as AppConfig exposing (AppConfig)
import Html exposing (Html) import Html exposing (Html)
import Json.Decode as D import Json.Decode as D
import Json.Decode.Pipeline exposing (..) import Json.Decode.Pipeline exposing (..)
@@ -28,6 +29,7 @@ type alias Session =
, flash : Maybe Flash , flash : Maybe Flash
, routing : Bool , routing : Bool
, zone : Time.Zone , zone : Time.Zone
, config : AppConfig
, persistent : Persistent , persistent : Persistent
} }
@@ -43,13 +45,14 @@ type alias Persistent =
} }
init : Nav.Key -> Url -> Persistent -> Session init : Nav.Key -> Url -> AppConfig -> Persistent -> Session
init key location persistent = init key location config persistent =
{ key = key { key = key
, host = location.host , host = location.host
, flash = Nothing , flash = Nothing
, routing = True , routing = True
, zone = Time.utc , zone = Time.utc
, config = config
, persistent = persistent , persistent = persistent
} }
@@ -61,6 +64,7 @@ initError key location error =
, flash = Just (Flash "Initialization failed" [ ( "Error", error ) ]) , flash = Just (Flash "Initialization failed" [ ( "Error", error ) ])
, routing = True , routing = True
, zone = Time.utc , zone = Time.utc
, config = AppConfig.default
, persistent = Persistent [] , persistent = Persistent []
} }

View File

@@ -52,7 +52,7 @@ init configValue location key =
session = session =
case D.decodeValue configDecoder configValue of case D.decodeValue configDecoder configValue of
Ok config -> Ok config ->
Session.init key location config.session Session.init key location config.appConfig config.session
Err error -> Err error ->
Session.initError key location (D.errorToString error) Session.initError key location (D.errorToString error)
@@ -255,8 +255,20 @@ changeRouteTo route model =
|> updateWith Mailbox MailboxMsg model |> updateWith Mailbox MailboxMsg model
Route.Monitor -> Route.Monitor ->
Monitor.init session if session.config.monitorVisible then
|> updateWith Monitor MonitorMsg model Monitor.init session
|> updateWith Monitor MonitorMsg model
else
let
flash =
{ title = "Unknown route requested"
, table = [ ( "Error", "Monitor disabled by configuration." ) ]
}
in
( applyToModelSession (Session.showFlash flash) model
, Cmd.none
)
Route.Status -> Route.Status ->
Status.init session Status.init session

View File

@@ -44,7 +44,11 @@ frame controls session page modal content =
[ ul [ class "navbar", attribute "role" "navigation" ] [ ul [ class "navbar", attribute "role" "navigation" ]
[ li [ class "navbar-brand" ] [ li [ class "navbar-brand" ]
[ a [ Route.href Route.Home ] [ text "@ inbucket" ] ] [ a [ Route.href Route.Home ] [ text "@ inbucket" ] ]
, navbarLink page Route.Monitor [ text "Monitor" ] , if session.config.monitorVisible then
navbarLink page Route.Monitor [ text "Monitor" ]
else
text ""
, navbarLink page Route.Status [ text "Status" ] , navbarLink page Route.Status [ text "Status" ]
, navbarRecent page controls , navbarRecent page controls
, li [ class "navbar-mailbox" ] , li [ class "navbar-mailbox" ]