admin

package
v1.6.5 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2024 License: GPL-2.0 Imports: 45 Imported by: 0

Documentation

Overview

templ: version: v0.2.707

templ: version: v0.2.707

Index

Constants

View Source
const (
	RegisterMenuItemHook       = "admin:register_menu_item"
	RegisterFooterMenuItemHook = "admin:register_footer_menu_item"
	RegisterGlobalMedia        = "admin:register_global_media"
	RegisterNavBreadCrumb      = "admin:register_breadcrumb"
	RegisterNavAction          = "admin:register_nav_action"
)
View Source
const BASE_KEY = "admin"

Variables

View Source
var (
	RegisterApp   = AdminSite.RegisterApp
	IsReady       = AdminSite.IsReady
	ConfigureAuth = AdminSite.configureAuth
)
View Source
var AppHandler = func(w http.ResponseWriter, r *http.Request, adminSite *AdminApplication, app *AppDefinition) {
	if app.Options.IndexView != nil {
		var err = views.Invoke(app.Options.IndexView(adminSite, app), w, r)
		assert.Err(err)
		return
	}

	var models = app.Models
	var modelNames = make([]string, models.Len())
	var i = 0
	for front := models.Front(); front != nil; front = front.Next() {
		modelNames[i] = front.Value.Label()
		i++
	}

	var context = NewContext(
		r, adminSite, nil,
	)
	context.SetPage(PageOptions{
		TitleFn:    app.Label,
		SubtitleFn: app.Description,
	})
	context.Set("app", app)
	context.Set("models", modelNames)
	var err = tpl.FRender(w, context, BASE_KEY, "admin/views/apps/index.tmpl")
	assert.Err(err)
}
View Source
var HomeHandler = &views.BaseView{
	AllowedMethods:  []string{http.MethodGet},
	BaseTemplateKey: BASE_KEY,
	TemplateName:    "admin/views/home.tmpl",
	GetContextFn: func(req *http.Request) (ctx.Context, error) {
		var context = NewContext(req, AdminSite, nil)
		context.SetPage(PageOptions{
			TitleFn:    fields.S("Home"),
			SubtitleFn: fields.S("Welcome to the Django Admin"),
		})
		return context, nil
	},
}
View Source
var IS_GITHUB_ACTIONS = true

For now only used to make sure tests pass on github actions This will be removed when the package is properly developed and tested This makes sure that the authentication check is enabled only when running on github actions

View Source
var LoginHandler = &views.FormView[*AdminForm[LoginForm]]{
	BaseView: views.BaseView{
		AllowedMethods:  []string{http.MethodGet, http.MethodPost},
		BaseTemplateKey: "admin",
		TemplateName:    "admin/views/auth/login.tmpl",
		GetContextFn: func(req *http.Request) (ctx.Context, error) {
			var context = ctx.RequestContext(req)
			// context.Set("next", req.URL.Query().Get("next"))
			var loginURL = django.Reverse("admin:login")
			var nextURL = req.URL.Query().Get("next")
			if nextURL != "" {
				var u, err = url.Parse(loginURL)
				if err != nil {
					goto returnContext
				}

				q := u.Query()
				q.Set("next", nextURL)
				u.RawQuery = q.Encode()
				loginURL = u.String()
			}

		returnContext:
			context.Set("LoginURL", loginURL)
			return context, nil
		},
	},
	GetFormFn: func(req *http.Request) *AdminForm[LoginForm] {
		var loginForm = AdminSite.AuthLoginForm(
			req,
		)
		return &AdminForm[LoginForm]{
			Form: loginForm,
		}
	},
	ValidFn: func(req *http.Request, form *AdminForm[LoginForm]) error {
		form.Form.SetRequest(req)
		return form.Form.Login()
	},
	SuccessFn: func(w http.ResponseWriter, req *http.Request, form *AdminForm[LoginForm]) {
		var nextURL = req.URL.Query().Get("next")
		if nextURL == "" {
			nextURL = django.Reverse("admin:home")
		}

		http.Redirect(w, req, nextURL, http.StatusSeeOther)
	},
	CheckPermissions: func(w http.ResponseWriter, req *http.Request) error {
		var user = authentication.Retrieve(req)
		if user != nil && user.IsAuthenticated() {
			return errs.Error("Already authenticated")
		}
		return nil
	},
	FailsPermissions: func(w http.ResponseWriter, req *http.Request, err error) {
		var redirectURL = django.Reverse("admin:home")
		http.Redirect(w, req, redirectURL, http.StatusSeeOther)
	},
}
View Source
var ModelAddHandler = func(w http.ResponseWriter, r *http.Request, adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition) {

	if !permissions.HasObjectPermission(r, model.NewInstance(), "admin:add") {
		autherrors.Fail(
			http.StatusForbidden,
			"Permission denied",
		)
		return
	}

	var instance = model.NewInstance()
	if model.AddView.GetHandler != nil {
		var err = views.Invoke(model.AddView.GetHandler(adminSite, app, model, instance), w, r)
		assert.Err(err)
		return
	}
	var addView = newInstanceView("add", instance, model.AddView, app, model, r)
	views.Invoke(addView, w, r)

}
View Source
var ModelDeleteHandler = func(w http.ResponseWriter, r *http.Request, adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition, instance attrs.Definer) {
	if !permissions.HasObjectPermission(r, instance, "admin:delete") {
		autherrors.Fail(
			http.StatusForbidden,
			"Permission denied",
		)
		return
	}

	if model.DeleteView.GetHandler != nil {
		var err = views.Invoke(model.DeleteView.GetHandler(adminSite, app, model, instance), w, r)
		assert.Err(err)
		return
	}
	w.Write([]byte(model.Name))
	w.Write([]byte("\n"))
	w.Write([]byte("delete"))
}
View Source
var ModelEditHandler = func(w http.ResponseWriter, r *http.Request, adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition, instance attrs.Definer) {
	if !permissions.HasObjectPermission(r, instance, "admin:edit") {
		autherrors.Fail(
			http.StatusForbidden,
			"Permission denied",
		)
		return
	}

	if model.EditView.GetHandler != nil {
		var err = views.Invoke(model.EditView.GetHandler(adminSite, app, model, instance), w, r)
		assert.Err(err)
		return
	}
	var editView = newInstanceView("edit", instance, model.EditView, app, model, r)
	views.Invoke(editView, w, r)

}
View Source
var ModelListHandler = func(w http.ResponseWriter, r *http.Request, adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition) {

	if !permissions.HasObjectPermission(r, model.NewInstance(), "admin:view_list") {
		autherrors.Fail(
			http.StatusForbidden,
			"Permission denied",
		)
		return
	}

	if model.ListView.GetHandler != nil {
		var err = views.Invoke(model.ListView.GetHandler(adminSite, app, model), w, r)
		assert.Err(err)
		return
	}

	var columns = make([]list.ListColumn[attrs.Definer], len(model.ListView.Fields))
	for i, field := range model.ListView.Fields {
		columns[i] = model.GetColumn(model.ListView, field)
	}

	var amount = model.ListView.PerPage
	if amount == 0 {
		amount = 25
	}

	var view = &list.View[attrs.Definer]{
		ListColumns:   columns,
		DefaultAmount: amount,
		BaseView: views.BaseView{
			AllowedMethods:  []string{http.MethodGet, http.MethodPost},
			BaseTemplateKey: BASE_KEY,
			TemplateName:    "admin/views/models/list.tmpl",
			GetContextFn: func(req *http.Request) (ctx.Context, error) {
				var context = NewContext(req, adminSite, nil)
				context.Set("app", app)
				context.Set("model", model)
				return context, nil
			},
		},
		GetListFn: func(amount, offset uint, include []string) ([]attrs.Definer, error) {
			return model.GetList(amount, offset, include)
		},
		TitleFieldColumn: func(lc list.ListColumn[attrs.Definer]) list.ListColumn[attrs.Definer] {
			return list.TitleFieldColumn(lc, func(defs attrs.Definitions, instance attrs.Definer) string {
				var primaryField = defs.Primary()
				if primaryField == nil {
					return ""
				}
				return django.Reverse("admin:apps:model:edit", app.Name, model.Name, primaryField.GetValue())
			})
		},
	}

	views.Invoke(view, w, r)
}

Functions

func LogoutHandler

func LogoutHandler(w http.ResponseWriter, req *http.Request)

func NewAppConfig

func NewAppConfig() django.AppConfig

func NewContext

func NewContext(request *http.Request, site *AdminApplication, context ctx.Context) *adminContext

func RegisterMedia

func RegisterMedia(fn RegisterScriptHookFunc)

func RequiredMiddleware

func RequiredMiddleware(next mux.Handler) mux.Handler

Types

type Action

type Action struct {
	Icon   string
	Target string
	Title  string
	URL    string
}

type AdminApplication

type AdminApplication struct {
	*apps.AppConfig

	// Ordering is the order in which the apps are displayed
	// in the admin interface.
	Ordering []string

	Route *mux.Route

	// Apps is a map of all the apps that are registered
	// with the admin site.
	Apps *orderedmap.OrderedMap[
		string, *AppDefinition,
	]
	// contains filtered or unexported fields
}
var AdminSite *AdminApplication = &AdminApplication{
	AppConfig: apps.NewAppConfig("admin"),
	Apps: orderedmap.NewOrderedMap[
		string, *AppDefinition,
	](),
	Ordering: make([]string, 0),
	Route: mux.NewRoute(
		mux.ANY, "admin/", nil, "admin",
	),
}

func (*AdminApplication) AuthLoginForm

func (a *AdminApplication) AuthLoginForm(r *http.Request, formOpts ...func(forms.Form)) LoginForm

func (*AdminApplication) AuthLogout

func (a *AdminApplication) AuthLogout(r *http.Request) error

func (*AdminApplication) IsReady

func (a *AdminApplication) IsReady() bool

func (*AdminApplication) RegisterApp

func (a *AdminApplication) RegisterApp(name string, appOptions AppOptions, opts ...ModelOptions) *AppDefinition

type AdminForm

type AdminForm[T forms.Form] struct {
	Form   T
	Panels []Panel
}

func NewAdminForm

func NewAdminForm[T forms.Form](form T, panels ...Panel) *AdminForm[T]

func (*AdminForm[T]) AddError

func (a *AdminForm[T]) AddError(name string, errorList ...error)

func (*AdminForm[T]) AddField

func (a *AdminForm[T]) AddField(name string, field fields.Field)

func (*AdminForm[T]) AddFormError

func (a *AdminForm[T]) AddFormError(errorList ...error)

func (*AdminForm[T]) AddWidget

func (a *AdminForm[T]) AddWidget(name string, widget widgets.Widget)

func (*AdminForm[T]) AsP

func (a *AdminForm[T]) AsP() template.HTML

func (*AdminForm[T]) AsUL

func (a *AdminForm[T]) AsUL() template.HTML

func (*AdminForm[T]) BoundErrors

func (a *AdminForm[T]) BoundErrors() *orderedmap.OrderedMap[string, []error]

func (*AdminForm[T]) BoundFields

func (a *AdminForm[T]) BoundFields() *orderedmap.OrderedMap[string, forms.BoundField]

func (*AdminForm[T]) BoundForm

func (a *AdminForm[T]) BoundForm() forms.BoundForm

func (*AdminForm[T]) CleanedData

func (a *AdminForm[T]) CleanedData() map[string]interface{}

func (*AdminForm[T]) DeleteField

func (a *AdminForm[T]) DeleteField(name string) bool

func (*AdminForm[T]) EditContext

func (a *AdminForm[T]) EditContext(key string, context ctx.Context)

func (*AdminForm[T]) ErrorList

func (a *AdminForm[T]) ErrorList() []error

func (*AdminForm[T]) Field

func (a *AdminForm[T]) Field(name string) (fields.Field, bool)

func (*AdminForm[T]) FieldOrder

func (a *AdminForm[T]) FieldOrder() []string

func (*AdminForm[T]) Fields

func (a *AdminForm[T]) Fields() []fields.Field

func (*AdminForm[T]) FullClean

func (a *AdminForm[T]) FullClean()

func (*AdminForm[T]) HasChanged

func (a *AdminForm[T]) HasChanged() bool

func (*AdminForm[T]) InitialData

func (a *AdminForm[T]) InitialData() map[string]interface{}

func (*AdminForm[T]) IsValid

func (a *AdminForm[T]) IsValid() bool

func (*AdminForm[T]) Media

func (a *AdminForm[T]) Media() media.Media

func (*AdminForm[T]) OnFinalize

func (a *AdminForm[T]) OnFinalize(f ...func(forms.Form))

func (*AdminForm[T]) OnInvalid

func (a *AdminForm[T]) OnInvalid(f ...func(forms.Form))

func (*AdminForm[T]) OnValid

func (a *AdminForm[T]) OnValid(f ...func(forms.Form))

func (*AdminForm[T]) Ordering

func (a *AdminForm[T]) Ordering(o []string)

func (*AdminForm[T]) Prefix

func (a *AdminForm[T]) Prefix() string

func (*AdminForm[T]) SetInitial

func (a *AdminForm[T]) SetInitial(initial map[string]interface{})

func (*AdminForm[T]) SetPrefix

func (a *AdminForm[T]) SetPrefix(prefix string)

func (*AdminForm[T]) SetValidators

func (a *AdminForm[T]) SetValidators(validators ...func(forms.Form) []error)

func (*AdminForm[T]) Validate

func (a *AdminForm[T]) Validate()

func (*AdminForm[T]) Widget

func (a *AdminForm[T]) Widget(name string) (widgets.Widget, bool)

func (*AdminForm[T]) Widgets

func (a *AdminForm[T]) Widgets() []widgets.Widget

func (*AdminForm[T]) WithData

func (a *AdminForm[T]) WithData(data url.Values, files map[string][]filesystem.FileHeader, r *http.Request) forms.Form

type AdminModelForm

type AdminModelForm[T modelforms.ModelForm[attrs.Definer]] struct {
	*AdminForm[T]
}

func NewAdminModelForm

func NewAdminModelForm[T modelforms.ModelForm[attrs.Definer]](form T, panels ...Panel) *AdminModelForm[T]

func (*AdminModelForm[T]) Context

func (a *AdminModelForm[T]) Context() context.Context

func (*AdminModelForm[T]) Instance

func (a *AdminModelForm[T]) Instance() attrs.Definer

func (*AdminModelForm[T]) Load

func (a *AdminModelForm[T]) Load()

func (*AdminModelForm[T]) Save

func (a *AdminModelForm[T]) Save() error

func (*AdminModelForm[T]) SetExclude

func (a *AdminModelForm[T]) SetExclude(exclude ...string)

func (*AdminModelForm[T]) SetFields

func (a *AdminModelForm[T]) SetFields(fields ...string)

func (*AdminModelForm[T]) SetInstance

func (a *AdminModelForm[T]) SetInstance(model attrs.Definer)

func (*AdminModelForm[T]) WithContext

func (a *AdminModelForm[T]) WithContext(ctx context.Context)

type AppDefinition

type AppDefinition struct {
	Name    string
	Options AppOptions
	Models  *orderedmap.OrderedMap[
		string, *ModelDefinition,
	]
	Routing func(django.Mux)
}

func (*AppDefinition) Description

func (a *AppDefinition) Description() string

func (*AppDefinition) Label

func (a *AppDefinition) Label() string

func (*AppDefinition) OnReady

func (a *AppDefinition) OnReady(adminSite *AdminApplication)

func (*AppDefinition) Register

func (a *AppDefinition) Register(opts ModelOptions) *ModelDefinition

type AppOptions

type AppOptions struct {
	// RegisterToAdminMenu allows for registering this app to the admin menu by default.
	RegisterToAdminMenu bool

	// Applabel must return a human readable label for the app.
	AppLabel func() string

	// AppDescription must return a human readable description of this app.
	AppDescription func() string

	// MenuLabel must return a human readable label for the menu, this is how the app's name will appear in the admin's navigation.
	MenuLabel func() string

	// MenuIcon must return a string representing the icon to use for the menu.
	//
	// This should be a HTML element, I.E. "<svg>...</svg>".
	MenuIcon func() string

	// MediaFn must return a media.Media object that will be used for this app.
	//
	// It will always be included in the admin's media.
	MediaFn func() media.Media

	// A custom index view for the app.
	//
	// This will override the default index view for the app.
	IndexView func(adminSite *AdminApplication, app *AppDefinition) views.View
}

type AuthConfig

type AuthConfig struct {
	GetLoginForm func(r *http.Request, formOpts ...func(forms.Form)) LoginForm
	Logout       func(r *http.Request) error
}

type BoundFormPanel

type BoundFormPanel[T forms.Form, P Panel] struct {
	forms.BoundField
	Context context.Context
	Panel   P
	Form    T
}

func (*BoundFormPanel[T, P]) Component

func (p *BoundFormPanel[T, P]) Component() templ.Component

func (*BoundFormPanel[T, P]) Render

func (p *BoundFormPanel[T, P]) Render() template.HTML

type BoundMultiPanel

type BoundMultiPanel[T forms.Form] struct {
	LabelFn func() string
	Context context.Context
	Panels  []BoundPanel
	Form    T
}

func (*BoundMultiPanel[T]) Component

func (p *BoundMultiPanel[T]) Component() templ.Component

func (*BoundMultiPanel[T]) Render

func (p *BoundMultiPanel[T]) Render() template.HTML

type BoundPanel

type BoundPanel interface {
	Component() templ.Component
	Render() template.HTML
}

type BoundTitlePanel

type BoundTitlePanel[T forms.Form, P Panel] struct {
	BoundPanel
	Context context.Context
}

func (*BoundTitlePanel[T, P]) Component

func (p *BoundTitlePanel[T, P]) Component() templ.Component

func (*BoundTitlePanel[T, P]) Render

func (p *BoundTitlePanel[T, P]) Render() template.HTML
type BreadCrumb struct {
	Title string
	URL   string
}

type DeleteViewOptions

type DeleteViewOptions struct {

	// GetHandler is a function that returns a views.View for the model.
	//
	// This allows you to have full control over the view used for deleting the model.
	//
	// This does mean that any logic provided by the admin when deleting the model should be implemented by the developer.
	GetHandler func(adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition, instance attrs.Definer) views.View
}

type FormDefiner

type FormDefiner interface {
	attrs.Definer
	AdminForm(r *http.Request, app *AppDefinition, model *ModelDefinition) modelforms.ModelForm[attrs.Definer]
}

type FormViewOptions

type FormViewOptions struct {
	ViewOptions

	// GetForm is a function that returns a modelform.ModelForm for the model.
	GetForm func(req *http.Request, instance attrs.Definer, fields []string) modelforms.ModelForm[attrs.Definer]

	// FormInit is a function that can be used to initialize the form.
	//
	// This may be useful for providing custom form initialization logic.
	FormInit func(instance attrs.Definer, form modelforms.ModelForm[attrs.Definer])

	// GetHandler is a function that returns a views.View for the model.
	//
	// This allows you to have full control over the view used for saving the model.
	//
	// This does mean that any logic provided by the admin when saving the model should be implemented by the developer.
	GetHandler func(adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition, instance attrs.Definer) views.View

	// A custom function for saving the instance.
	//
	// This function will be called when the form is saved and allows for custom logic to be executed when saving the instance.
	SaveInstance func(context.Context, attrs.Definer) error

	// Panels are used to group fields in the form.
	//
	// This allows for a more simple, maintainable and organized form layout.
	Panels []Panel
}

Options for a model-specific form view.

type ListAction

type ListAction[T attrs.Definer] struct {
	Classname string
	Show      func(defs attrs.Definitions, row T) bool
	Text      func(defs attrs.Definitions, row T) string
	URL       func(defs attrs.Definitions, row T) string
}

func (*ListAction[T]) Component

func (l *ListAction[T]) Component(defs attrs.Definitions, row T) templ.Component

func (*ListAction[T]) IsShown

func (l *ListAction[T]) IsShown(defs attrs.Definitions, row T) bool

type ListActionsColumn

type ListActionsColumn[T attrs.Definer] struct {
	Heading func() string
	Actions []*ListAction[T]
}

func (*ListActionsColumn[T]) Component

func (l *ListActionsColumn[T]) Component(defs attrs.Definitions, row T) templ.Component

func (*ListActionsColumn[T]) Header

func (l *ListActionsColumn[T]) Header() templ.Component

type ListViewOptions

type ListViewOptions struct {
	ViewOptions

	// PerPage is the number of items to show per page.
	//
	// This is used for pagination in the list view.
	PerPage uint64

	// Columns are used to define the columns in the list view.
	//
	// This allows for custom rendering logic of the columns in the list view.
	Columns map[string]list.ListColumn[attrs.Definer]

	// Format is a map of field name to a function that formats the field value.
	//
	// I.E. map[string]func(v any) any{"Name": func(v any) any { return strings.ToUpper(v.(string)) }}
	// would uppercase the value of the "Name" field in the list view.
	Format map[string]func(v any) any

	// GetHandler is a function that returns a views.View for the model.
	//
	// This allows you to have full control over the view used for listing the models.
	//
	// This does mean that any logic provided by the admin when listing the models should be implemented by the developer.
	GetHandler func(adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition) views.View
}

type LoginForm

type LoginForm interface {
	forms.Form
	SetRequest(req *http.Request)
	Login() error
}

type ModelDefinition

type ModelDefinition struct {
	ModelOptions
	Name          string
	LabelFn       func() string
	PluralLabelFn func() string
	// contains filtered or unexported fields
}

A struct which is mainly used internally (but can be used by third parties) to easily work with models in admin views.

func (*ModelDefinition) FormatColumn

func (o *ModelDefinition) FormatColumn(field string) any

func (*ModelDefinition) GetColumn

func (o *ModelDefinition) GetColumn(opts ListViewOptions, field string) list.ListColumn[attrs.Definer]

func (*ModelDefinition) GetInstance

func (m *ModelDefinition) GetInstance(identifier any) (attrs.Definer, error)

func (*ModelDefinition) GetLabel

func (o *ModelDefinition) GetLabel(opts ViewOptions, field string, default_ string) func() string

func (*ModelDefinition) GetListInstances

func (m *ModelDefinition) GetListInstances(amount, offset uint) ([]attrs.Definer, error)

func (*ModelDefinition) GetName

func (o *ModelDefinition) GetName() string

func (*ModelDefinition) Label

func (o *ModelDefinition) Label() string

func (*ModelDefinition) ModelFields

func (m *ModelDefinition) ModelFields(opts ViewOptions, instace attrs.Definer) []attrs.Field

func (*ModelDefinition) NewInstance

func (o *ModelDefinition) NewInstance() attrs.Definer

Returns a new instance of the model.

This works the same as calling `reflect.New` on the model type.

func (*ModelDefinition) OnRegister

func (m *ModelDefinition) OnRegister(a *AdminApplication, app *AppDefinition)

func (*ModelDefinition) PluralLabel

func (o *ModelDefinition) PluralLabel() string

type ModelOptions

type ModelOptions struct {
	// Name of the model and how it will be displayed in the admin.
	Name string

	// AddView is the options for the add view of the model.
	//
	// This allows for custom creation logic and formatting form fields / layout.
	AddView FormViewOptions

	// EditView is the options for the edit view of the model.
	//
	// This allows for custom editing logic and formatting form fields / layout.
	EditView FormViewOptions

	// ListView is the options for the list view of the model.
	//
	// This allows for custom listing logic and formatting list columns.
	ListView ListViewOptions

	// DeleteView is the options for the delete view of the model.
	//
	// Any custom logic for deleting the model should be implemented here.
	DeleteView DeleteViewOptions

	// RegisterToAdminMenu is a flag that determines if the model should be automatically registered to the admin menu.
	RegisterToAdminMenu bool

	// Labels for the fields in the model.
	//
	// This provides a simple top- level override for the labels of the fields in the model.
	//
	// Any custom labels for fields implemented in the AddView, EditView or ListView will take precedence over these labels.
	Labels map[string]func() string

	// GetForID is a function that returns a model instance for the given identifier.
	//
	// This is used to get a model instance for the edit and delete views.
	GetForID func(identifier any) (attrs.Definer, error)

	// GetList is a function that returns a list of model instances.
	//
	// This is used to get a (paginated) list of model instances for the list view.
	GetList func(amount, offset uint, include []string) ([]attrs.Definer, error)

	// Model is the object that the above- defined options are for.
	Model attrs.Definer
}

func (*ModelOptions) GetName

func (o *ModelOptions) GetName() string

type PageOptions

type PageOptions struct {
	Request     *http.Request
	TitleFn     func() string
	SubtitleFn  func() string
	MediaFn     func() media.Media
	BreadCrumbs []BreadCrumb
	Actions     []Action
}

func (*PageOptions) GetActions

func (p *PageOptions) GetActions() []Action

func (*PageOptions) GetBreadCrumbs

func (p *PageOptions) GetBreadCrumbs() []BreadCrumb

func (*PageOptions) Subtitle

func (p *PageOptions) Subtitle() string

func (*PageOptions) Title

func (p *PageOptions) Title() string

type Panel

type Panel interface {
	Fields() []string
	Bind(form forms.Form, ctx context.Context, boundFields map[string]forms.BoundField) BoundPanel
}

func FieldPanel

func FieldPanel(fieldname string) Panel

func MultiPanel

func MultiPanel(panels ...Panel) Panel

func TitlePanel

func TitlePanel(panel Panel) Panel

type PanelBoundForm

type PanelBoundForm struct {
	forms.BoundForm
	BoundPanels []BoundPanel
	Panels      []Panel
	Context     context.Context
}

func (*PanelBoundForm) AsP

func (b *PanelBoundForm) AsP() template.HTML

func (*PanelBoundForm) AsUL

func (b *PanelBoundForm) AsUL() template.HTML

func (*PanelBoundForm) ErrorList

func (b *PanelBoundForm) ErrorList() []error

func (*PanelBoundForm) Errors

func (b *PanelBoundForm) Errors() *orderedmap.OrderedMap[string, []error]

func (*PanelBoundForm) Fields

func (b *PanelBoundForm) Fields() []forms.BoundField

func (*PanelBoundForm) Media

func (b *PanelBoundForm) Media() media.Media

type RegisterBreadCrumbHookFunc

type RegisterBreadCrumbHookFunc func(r *http.Request, adminSite *AdminApplication) []BreadCrumb

type RegisterFooterMenuItemHookFunc

type RegisterFooterMenuItemHookFunc func(r *http.Request, adminSite *AdminApplication, items components.Items[menu.MenuItem])

type RegisterMenuItemHookFunc

type RegisterMenuItemHookFunc func(adminSite *AdminApplication, items components.Items[menu.MenuItem])

type RegisterNavActionHookFunc

type RegisterNavActionHookFunc func(r *http.Request, adminSite *AdminApplication) []Action

type RegisterScriptHookFunc

type RegisterScriptHookFunc func(adminSite *AdminApplication) media.Media

type ViewOptions

type ViewOptions struct {
	// Fields to include for the model in the view
	Fields []string

	// Fields to exclude from the model in the view
	Exclude []string

	// Labels for the fields in the view
	//
	// This is a map of field name to a function that returns the label for the field.
	//
	// Allowing for custom labels for fields in the view.
	Labels map[string]func() string
}

Basic options for a model-based view which includes a form.

Directories

Path Synopsis
templ: version: v0.2.707
templ: version: v0.2.707
menu
templ: version: v0.2.707
templ: version: v0.2.707

Jump to

Keyboard shortcuts

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