html

package
v0.3.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2024 License: MPL-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package html contains code relating specifically to the web UI.

Index

Constants

View Source
const (
	FlashSuccessType flashType = "success"
	FlashWarningType flashType = "warning"
	FlashErrorType   flashType = "error"
)
View Source
const (
	// number of items in a paginated result to show on a single page
	PageSize int = 100
)

Variables

This section is empty.

Functions

func AddStaticHandler

func AddStaticHandler(logger logr.Logger, r *mux.Router, devMode bool) error

AddStaticHandler adds a handler to router serving static assets (JS, CSS, etc) from within go binary. Enabling developer mode sources files from local disk instead and starts a live reload server, which reloads the browser whenever static files change.

func Error

func Error(w http.ResponseWriter, err string, code int, devMode bool)

func FlashError

func FlashError(w http.ResponseWriter, msg string)

FlashError helper writes a single flash error message

func FlashSuccess

func FlashSuccess(w http.ResponseWriter, msg string)

FlashSuccess helper writes a single flash success message

func FlashWarning

func FlashWarning(w http.ResponseWriter, msg string)

FlashWarning helper writes a single flash warning message

func MarkdownToHTML

func MarkdownToHTML(md []byte) template.HTML

func NewRenderer

func NewRenderer(devMode bool) (*renderer, error)

NewRenderer constructs a renderer. If developer mode is enabled then templates are loaded from disk every time a template is rendered.

func PopFlashes

func PopFlashes(r *http.Request) ([]flash, error)

PopFlashes pops all flash messages off the stack

func ReturnUserOriginalPage

func ReturnUserOriginalPage(w http.ResponseWriter, r *http.Request)

ReturnUserOriginalPage returns a user to the original page they tried to access before they were redirected to the login page.

func SendUserToLoginPage

func SendUserToLoginPage(w http.ResponseWriter, r *http.Request)

SendUserToLoginPage sends user to the login prompt page, saving the original path they tried to access so it can return them there after login.

func SetCookie

func SetCookie(w http.ResponseWriter, name, value string, expiry *time.Time)

SetCookie sets a cookie on the http response. A nil expiry sets no expiry, and a zero expiry sets it to be purged from the browser.

func UIRouter

func UIRouter(r *mux.Router) *mux.Router

UIRouter wraps the given router with a router suitable for web UI routes.

Types

type DropDownUIWidth string
const (
	NarrowDropDown DropDownUIWidth = "narrow"
	WideDropDown   DropDownUIWidth = "wide"
)
type DropdownUI struct {
	// Name to send along with value in the POST form
	Name string
	// Existing values to NOT show in the dropdown
	Existing []string
	// Available values to show in the dropdown
	Available []string
	// Action is the form action URL
	Action string
	// Placeholder to show in the input element.
	Placeholder string
	// Width: "narrow" or "wide"
	Width DropDownUIWidth
}

DropdownUI populates a search/dropdown UI component.

type FlashStack

type FlashStack []flash

FlashStack is a stack of flash messages

func (*FlashStack) Push

func (s *FlashStack) Push(t flashType, msg string)

func (FlashStack) Write

func (s FlashStack) Write(w http.ResponseWriter)

type Renderer

type Renderer interface {
	// contains filtered or unexported methods
}

Renderer renders pages and templates

type SitePage

type SitePage struct {
	Title               string // page title
	Version             string // otf version string in footer
	CurrentOrganization string
	// contains filtered or unexported fields
}

SitePage contains data shared by all pages when rendering templates.

func NewSitePage

func NewSitePage(r *http.Request, title string) SitePage

func (SitePage) CurrentPath

func (v SitePage) CurrentPath() string

func (SitePage) CurrentURL

func (v SitePage) CurrentURL() string

func (SitePage) CurrentUser

func (v SitePage) CurrentUser() authz.Subject

func (SitePage) Flashes

func (v SitePage) Flashes() ([]flash, error)

Directories

Path Synopsis
Package paths provides rails-style path helpers for use with the web app.
Package paths provides rails-style path helpers for use with the web app.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL