mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 09:37:02 +00:00
ui: Add greeting.html to Home
This commit is contained in:
@@ -2,7 +2,6 @@ package webui
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@@ -10,23 +9,16 @@ import (
|
|||||||
"github.com/jhillyerd/inbucket/pkg/server/web"
|
"github.com/jhillyerd/inbucket/pkg/server/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RootIndex serves the Inbucket landing page
|
// RootGreeting serves the Inbucket greeting.
|
||||||
func RootIndex(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) {
|
func RootGreeting(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) {
|
||||||
greeting, err := ioutil.ReadFile(ctx.RootConfig.Web.GreetingFile)
|
greeting, err := ioutil.ReadFile(ctx.RootConfig.Web.GreetingFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to load greeting: %v", err)
|
return fmt.Errorf("Failed to load greeting: %v", err)
|
||||||
}
|
}
|
||||||
// Get flash messages, save session
|
|
||||||
errorFlash := ctx.Session.Flashes("errors")
|
w.Header().Set("Content-Type", "text/html")
|
||||||
if err = ctx.Session.Save(req, w); err != nil {
|
_, err = w.Write(greeting)
|
||||||
return err
|
return err
|
||||||
}
|
|
||||||
// Render template
|
|
||||||
return web.RenderTemplate("root/index.html", w, map[string]interface{}{
|
|
||||||
"ctx": ctx,
|
|
||||||
"errorFlash": errorFlash,
|
|
||||||
"greeting": template.HTML(string(greeting)),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RootMonitor serves the Inbucket monitor page
|
// RootMonitor serves the Inbucket monitor page
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import (
|
|||||||
|
|
||||||
// SetupRoutes populates routes for the webui into the provided Router.
|
// SetupRoutes populates routes for the webui into the provided Router.
|
||||||
func SetupRoutes(r *mux.Router) {
|
func SetupRoutes(r *mux.Router) {
|
||||||
r.Path("/").Handler(
|
r.Path("/greeting").Handler(
|
||||||
web.Handler(RootIndex)).Name("RootIndex").Methods("GET")
|
web.Handler(RootGreeting)).Name("RootGreeting").Methods("GET")
|
||||||
r.Path("/monitor").Handler(
|
r.Path("/monitor").Handler(
|
||||||
web.Handler(RootMonitor)).Name("RootMonitor").Methods("GET")
|
web.Handler(RootMonitor)).Name("RootMonitor").Methods("GET")
|
||||||
r.Path("/monitor/{name}").Handler(
|
r.Path("/monitor/{name}").Handler(
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
<h1>Welcome to Inbucket</h1>
|
||||||
|
|
||||||
<p>Inbucket is an email testing service; it will accept email for any email
|
<p>Inbucket is an email testing service; it will accept email for any email
|
||||||
address and make it available to view without a password.</p>
|
address and make it available to view without a password.</p>
|
||||||
|
|
||||||
|
|||||||
@@ -36,8 +36,11 @@ init sessionValue location =
|
|||||||
session =
|
session =
|
||||||
Session.init location (Session.decodeValueWithDefault sessionValue)
|
Session.init location (Session.decodeValueWithDefault sessionValue)
|
||||||
|
|
||||||
|
( subModel, _ ) =
|
||||||
|
Home.init
|
||||||
|
|
||||||
model =
|
model =
|
||||||
{ page = Home Home.init
|
{ page = Home subModel
|
||||||
, session = session
|
, session = session
|
||||||
, mailboxName = ""
|
, mailboxName = ""
|
||||||
}
|
}
|
||||||
@@ -182,8 +185,12 @@ setRoute route model =
|
|||||||
( model, Cmd.none, Session.SetFlash ("Unknown route requested: " ++ hash) )
|
( model, Cmd.none, Session.SetFlash ("Unknown route requested: " ++ hash) )
|
||||||
|
|
||||||
Route.Home ->
|
Route.Home ->
|
||||||
( { model | page = Home Home.init }
|
let
|
||||||
, Ports.windowTitle "Inbucket"
|
( subModel, subCmd ) =
|
||||||
|
Home.init
|
||||||
|
in
|
||||||
|
( { model | page = Home subModel }
|
||||||
|
, Cmd.map HomeMsg subCmd
|
||||||
, Session.none
|
, Session.none
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -3,18 +3,33 @@ module Page.Home exposing (Model, Msg, init, update, view)
|
|||||||
import Data.Session as Session exposing (Session)
|
import Data.Session as Session exposing (Session)
|
||||||
import Html exposing (..)
|
import Html exposing (..)
|
||||||
import Html.Attributes exposing (..)
|
import Html.Attributes exposing (..)
|
||||||
|
import Http
|
||||||
|
import HttpUtil
|
||||||
|
import Json.Encode as Encode
|
||||||
|
import Ports
|
||||||
|
|
||||||
|
|
||||||
-- MODEL --
|
-- MODEL --
|
||||||
|
|
||||||
|
|
||||||
type alias Model =
|
type alias Model =
|
||||||
{}
|
{ greeting : String }
|
||||||
|
|
||||||
|
|
||||||
init : Model
|
init : ( Model, Cmd Msg )
|
||||||
init =
|
init =
|
||||||
{}
|
( Model ""
|
||||||
|
, Cmd.batch
|
||||||
|
[ Ports.windowTitle "Inbucket"
|
||||||
|
, cmdGreeting
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
cmdGreeting : Cmd Msg
|
||||||
|
cmdGreeting =
|
||||||
|
Http.send GreetingResult <|
|
||||||
|
Http.getString "/serve/greeting"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -22,12 +37,17 @@ init =
|
|||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
= Msg
|
= GreetingResult (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 =
|
||||||
( model, Cmd.none, Session.none )
|
case msg of
|
||||||
|
GreetingResult (Ok greeting) ->
|
||||||
|
( Model greeting, Cmd.none, Session.none )
|
||||||
|
|
||||||
|
GreetingResult (Err err) ->
|
||||||
|
( model, Cmd.none, Session.SetFlash (HttpUtil.errorString err) )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -37,6 +57,9 @@ update session msg model =
|
|||||||
view : Session -> Model -> Html Msg
|
view : Session -> Model -> Html Msg
|
||||||
view session model =
|
view session model =
|
||||||
div [ id "page" ]
|
div [ id "page" ]
|
||||||
[ h1 [] [ text "Inbucket" ]
|
[ div
|
||||||
, text "This is the home page"
|
[ class "greeting"
|
||||||
|
, property "innerHTML" (Encode.string model.greeting)
|
||||||
|
]
|
||||||
|
[]
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ time, mark, audio, video {
|
|||||||
vertical-align: baseline;
|
vertical-align: baseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::placeholder {
|
||||||
|
color: var(--placeholder-color);
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: #337ab7;
|
color: #337ab7;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
@@ -46,9 +51,8 @@ body, input, table {
|
|||||||
color: var(--primary-color);
|
color: var(--primary-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
::placeholder {
|
h1, h2, h3, h4, h5, h6, p {
|
||||||
color: var(--placeholder-color);
|
margin-bottom: 10px;
|
||||||
opacity: 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** SHARED */
|
/** SHARED */
|
||||||
@@ -129,6 +133,10 @@ h1 {
|
|||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.greeting {
|
||||||
|
max-width: 1000px;
|
||||||
|
}
|
||||||
|
|
||||||
/** NAV BAR */
|
/** NAV BAR */
|
||||||
|
|
||||||
.navbar,
|
.navbar,
|
||||||
|
|||||||
Reference in New Issue
Block a user