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