Skip to content

Commit

Permalink
Merge pull request #144 from prometheus/superq/landing_form
Browse files Browse the repository at this point in the history
Add a POST form to the landing page
  • Loading branch information
SuperQ authored Mar 30, 2023
2 parents 5526383 + 9165b70 commit f42e5c7
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
6 changes: 5 additions & 1 deletion web/landing_page.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ body {
header {
background-color: {{.HeaderColor}};
color: #fff;
font-size: 2rem;
font-size: 1rem;
padding: 1rem;
}
main {
padding: 1rem;
}
label {
display: inline-block;
width: {{.Form.Width}}em;
}
26 changes: 26 additions & 0 deletions web/landing_page.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,27 @@ type LandingConfig struct {
CSS string // CSS style tag for the landing page.
Name string // The name of the exporter, generally suffixed by _exporter.
Description string // A short description about the exporter.
Form LandingForm // A POST form.
Links []LandingLinks // Links displayed on the landing page.
Version string // The version displayed.
}

// LandingForm provides a configuration struct for creating a POST form on the landing page.
type LandingForm struct {
Action string
Inputs []LandingFormInput
Width float64
}

// LandingFormInput represents a single form input field.
type LandingFormInput struct {
Label string
Type string
Name string
Placeholder string
Value string
}

type LandingLinks struct {
Address string // The URL the link points to.
Text string // The text of the link.
Expand All @@ -54,6 +71,15 @@ var (

func NewLandingPage(c LandingConfig) (*LandingPageHandler, error) {
var buf bytes.Buffer

length := 0
for _, input := range c.Form.Inputs {
inputLength := len(input.Label)
if inputLength > length {
length = inputLength
}
}
c.Form.Width = (float64(length) + 1) / 2
if c.CSS == "" {
if c.HeaderColor == "" {
// Default to Prometheus orange.
Expand Down
10 changes: 10 additions & 0 deletions web/landing_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ <h1>{{.Name}}</h1>
{{ end }}
</ul>
</div>
{{ if .Form.Action }}
<div>
<form action="{{ .Form.Action}}">
{{ range .Form.Inputs }}
<label>{{ .Label }}:</label>&nbsp;<input type="{{ .Type }}" name="{{ .Name }}" placeholder=" .Placeholder }}" value="{{ .Value }}"><br>
{{ end }}
<input type="submit" value="Submit">
</form>
</div>
{{ end }}
</main>
</body>
</html>

0 comments on commit f42e5c7

Please sign in to comment.