pages

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package pages handles parsing the HTML templates used to build the GUI and returning these templates when requested.

Most pages in the app are just a basic shell, with data being injected by API calls. This was done so that pages are more reactive to filters and user activity. The API calls are done via js/ts and Vue objects.

Most pages are returned via the Page() or Show() funcs. Page is used for most pages, see the router in main.go. Show() is used when Page() isn't used and we defined a special http handler for the endpoint. Show() is when we aren't just returning a base HTML page and we are doing some validation or gathering data to inject into a template with Golang templating.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diagnostics

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

Diagnostics shows the diagnostic page. We use an actual page for this instead of just using w.Write() so that we can display diagnostic info from js and css.

func HelpTableOfContents

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

HelpTableOfContents shows the page listing help documents

func License

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

License shows the data for a specific license.

func Login

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

Login shows the login page to the app. This also checks if the user is already logged in and redirects the user to the main logged in page if so.

func Main

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

Main shows the main page of the app.

func Page

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

Page builds and returns a template to w based on the URL path provided in r. This func is used directly in r.Handle() in main.go for pages that don't require any page-specific data to be injected into them. If you need to inject page-specific data, call Show() directly.

func Show

func Show(w http.ResponseWriter, templateName string, injectedData any)

Show renders a template as HTML and writes it to w. ParseTemplates() must have been called first. injectedData is available within the template at the .Data field. templateName should be the path to a template file such as /app/suppliers.html.

The path must match a parsed template name. AKA, does the URL being requested match a file within the website/templates/ directory.

If you don't need to inject any data into the page, call Page() instead.

func ShowError

func ShowError(w http.ResponseWriter, r *http.Request, ep ErrorPage)

ShowError shows the error page with injected data. This this func cleans up the code whereever an error page is called/shown since it is common throughout the app. The first part of this func is similar to getPageConfigData but allows for skipping the user data since we do not use it on the error page.

func UserProfile

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

UserProfile shows the page where a user can view and manage their own user account or profile. For now, user's can only change their passwords since we do not want them to be able to change permissions (for obvious reasons) or alerts (so they get alerts for what admin's deem important).

This does not use Page() since we need to get the minimum password length to build the GUI with.

func Users

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

Users shows the page to manage users.

This does not use Page() since we need to get the minimum password length to build the GUI with.

Types

type Config

type Config struct {
	//Development is passed to each template when rendering the HTML to be sent to
	//the user so that the HTML can be altered based on if you are running your app
	//in a development mode/enviroment.
	//
	//Typically this is used to show a banner on the page, loads extra diagnostic
	//third-party libraries (Vue with devtools support), and uses non-cache busted
	//static files.
	Development bool

	//UseLocalFiles is passed to each template when rendering the HTML to be sent to
	//the user so that the HTML can be altered to use locally hosted third party
	//libraries (JS, CSS) versus libraries retrieve from the internet.
	//
	//This is typically set via config file field.
	UseLocalFiles bool

	//Extension is the extension you use for your template files. The default is
	//".html".
	Extension string

	//TemplateFiles is the fs.FS filesystem that holds the HTML templates to be read
	//and used. This is from os.DirFS or embed.
	TemplateFiles fs.FS

	//StaticFiles is the list of static files used to build the GUI (js, css, images).
	//This is a separate FS that is used for cache busting purposes. See the static()
	//func for more info.
	StaticFiles *hashfs.HFS

	//Debug prints out debugging information if true.
	Debug bool
	// contains filtered or unexported fields
}

Config is the set of configuration settings for working with HTML templates. This also stores the parsed HTML templates after ParseTemplates() is called.

func (*Config) ParseTemplates

func (c *Config) ParseTemplates() (err error)

ParseTemplates parses HTML templates from the config's TemplateFiles and saves the parsed templates for use with Show().

type ErrorPage

type ErrorPage struct {
	PageTitle string //card header

	//These may simply be concatted in the gui but makes code cleaner and more easily reused.
	Topic    string //general topic of the error
	Message  string //what error occured
	Solution string //how to fix or work around the error

	ShowLinkBtn bool   //whether or not a footer button with link is shown
	Link        string //url to use for link, if blank will default to /app/ (main page).
	LinkText    string //text to show on button, if blank will default to Main Menu.
}

ErrorPage is the data used to show messages when an error or unexpected event occurs this stuff is injected into a template to describe to user what occured and how to fix it.

type PageData

type PageData struct {
	UserData    any //username, permissions, etc.
	AppSettings any //whether certain features are used or enabled.
	Data        any //misc. actual data we want to show in the gui.
}

PageData is the format of our data that we inject into a template. This struct is used so we always have a consistent format of data being injected into templates for easy parsing.

This is provided to the injectedData field of Show().

Any is used, instead of defined database types, so that we don't have import loops for ease of use.

Jump to

Keyboard shortcuts

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