Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a POST form to the landing page #144

Merged
merged 1 commit into from
Mar 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{{ is missing for placeholder

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, oops, will followup.

{{ end }}
<input type="submit" value="Submit">
</form>
</div>
{{ end }}
</main>
</body>
</html>