admin

package module
v0.0.0-...-fa4d88c Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2022 License: MIT Imports: 16 Imported by: 4

README

admin Tests codecov

admin is a lightweight Go library to generate form/admin like UIs leveraging Material-UI.

Quick Start

go get github.com/admin-golang/admin
package main

import (
	"log"
	"net/http"
	"net/url"

	"github.com/admin-golang/admin"
	"github.com/admin-golang/admin/icon"
	"github.com/admin-golang/admin/layout"
)

func NewSubscribeFormPage() (admin.Pager, error) {
	sideFormBackgroundImage, err := url.Parse("https://source.unsplash.com/random/?golang")
	if err != nil {
		return nil, err
	}

	return admin.NewSideFormPage(admin.SideFormPageConfig{
		BackgroundImage: sideFormBackgroundImage,
		PageConfig: admin.PageConfig{
			Icon: icon.Icon{
				Type: icon.Email,
			},
			IsDefault: true,
			ID:        "Subscribe",
			URL:       "/subscribe",
			Type:      admin.SideFormPage,
		},
		Form: admin.Form{
			ID: "subscribe",
			Fields: admin.Fields{
				admin.Field{
					ID:         "email",
					Type:       admin.InputText,
					Label:      "Email",
					IsRequired: true,
					Value:      "",
					FullWidth:  true,
				},
			},
			Submit: admin.Submit{
				Label:  "Subscribe",
				URL:    "/subscribe",
				Method: "POST",
			},
		},
	}), nil
}

func main() {
	subscribeFormPage, err := NewSubscribeFormPage()
	if err != nil {
		log.Fatal(err)
	}

	pages := admin.Pages{
		subscribeFormPage,
	}

	admin := admin.New(&admin.Config{
		DebugMode: false,
		UITheme:   admin.MaterialUI,
		Pages:     pages,
		Layout:    layout.New(&layout.Config{}),
	})

	mux := http.NewServeMux()

	mux.Handle("/admin", admin)

	log.Println("[admin-golang] running on port :8080 path: /admin")
	log.Fatal(http.ListenAndServe(":8080", mux))
}
subscribe example

For more complex examples, refer to the examples directory.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Admin

type Admin interface {
	ServeHTTP(w http.ResponseWriter, r *http.Request)
}

func New

func New(config *Config) Admin

type CCardListPage

type CCardListPage struct {
	ParamKey      string
	MainButton    *MainButton
	Title         string
	DataLoader    *dataloader.DataLoader
	Pagination    *PaginationConfig
	ListRowConfig *ListRowConfig
	Header        *PageHeader
	Form          *Form
	// contains filtered or unexported fields
}

func (*CCardListPage) ID

func (p *CCardListPage) ID() string

func (*CCardListPage) Icon

func (p *CCardListPage) Icon() icon.Icon

func (*CCardListPage) IsDefault

func (p *CCardListPage) IsDefault() bool

func (*CCardListPage) NavTabs

func (p *CCardListPage) NavTabs() navigation.NavTabs

func (*CCardListPage) Navigation

func (p *CCardListPage) Navigation() *navigation.Navigation

func (*CCardListPage) PageHeader

func (p *CCardListPage) PageHeader() *PageHeader

func (*CCardListPage) ToolbarEnabled

func (p *CCardListPage) ToolbarEnabled() bool

func (*CCardListPage) Type

func (p *CCardListPage) Type() PageType

func (*CCardListPage) URL

func (p *CCardListPage) URL() string

type CardListPageConfig

type CardListPageConfig struct {
	PageConfig
	ParamKey      string
	MainButton    *MainButton
	Title         string
	DataLoader    *dataloader.DataLoader
	Pagination    *PaginationConfig
	ListRowConfig *ListRowConfig
	Form          *Form
}

type Config

type Config struct {
	DebugMode         bool
	Layout            *layout.Layout
	UITheme           UITheme
	Pages             Pages
	JSXTemplateText   *string
	AdminTemplateText *string
}

type EEditPage

type EEditPage struct {
	DataLoader *dataloader.DataLoader
	Form       Form
	Header     *PageHeader
	// contains filtered or unexported fields
}

func (*EEditPage) ID

func (p *EEditPage) ID() string

func (*EEditPage) Icon

func (p *EEditPage) Icon() icon.Icon

func (*EEditPage) IsDefault

func (p *EEditPage) IsDefault() bool

func (*EEditPage) NavTabs

func (p *EEditPage) NavTabs() navigation.NavTabs

func (*EEditPage) Navigation

func (p *EEditPage) Navigation() *navigation.Navigation

func (*EEditPage) PageHeader

func (p *EEditPage) PageHeader() *PageHeader

func (*EEditPage) ToolbarEnabled

func (p *EEditPage) ToolbarEnabled() bool

func (*EEditPage) Type

func (p *EEditPage) Type() PageType

func (*EEditPage) URL

func (p *EEditPage) URL() string

type EditPageConfig

type EditPageConfig struct {
	PageConfig

	ParamKey   string
	DataLoader *dataloader.DataLoader
	Form       Form
}

type FFormPage

type FFormPage struct {
	Form Form
	// contains filtered or unexported fields
}

func (*FFormPage) ID

func (p *FFormPage) ID() string

func (*FFormPage) Icon

func (p *FFormPage) Icon() icon.Icon

func (*FFormPage) IsDefault

func (p *FFormPage) IsDefault() bool

func (*FFormPage) NavTabs

func (p *FFormPage) NavTabs() navigation.NavTabs

func (*FFormPage) Navigation

func (p *FFormPage) Navigation() *navigation.Navigation

func (*FFormPage) PageHeader

func (p *FFormPage) PageHeader() *PageHeader

func (*FFormPage) ToolbarEnabled

func (p *FFormPage) ToolbarEnabled() bool

func (*FFormPage) Type

func (p *FFormPage) Type() PageType

func (*FFormPage) URL

func (p *FFormPage) URL() string

type Field

type Field struct {
	ID           string    `json:"id"`
	Label        string    `json:"label"`
	Type         FieldType `json:"type"`
	IsRequired   bool
	FullWidth    bool `json:"fullWidth"`
	Value        string
	IsMultiline  bool
	NumberOfRows int
	Fields       Fields
	Width        int `json:"width"`
	Disabled     bool
}

type FieldType

type FieldType uint
const (
	InputPassword FieldType = iota
	InputText
	InputFile
	InputNumber
	InputCents
	InputMulti
	InputCheckbox
	InputSelect
)

type Fields

type Fields []Field

type Form

type Form struct {
	Navigation *navigation.Navigation
	Fields     Fields `json:"fields"`
	ID         string `json:"id"`
	Submit     Submit `json:"submit"`
	Title      string
}

type FormPageConfig

type FormPageConfig struct {
	PageConfig

	Form Form
}
type Header struct {
	Key   string      `json:"key"`
	Value HeaderValue `json:"value"`
}

type HeaderValue

type HeaderValue struct {
	Prefix            string `json:"prefix"`
	AppStateFieldPath string `json:"appStateFieldPath"`
}

type LListPage

type LListPage struct {
	MainButton    *MainButton
	Title         string
	DataLoader    *dataloader.DataLoader
	Pagination    *PaginationConfig
	ListRowConfig *ListRowConfig
	SearchConfig  *ListSearchConfig
	Header        *PageHeader
	// contains filtered or unexported fields
}

func (*LListPage) ID

func (p *LListPage) ID() string

func (*LListPage) Icon

func (p *LListPage) Icon() icon.Icon

func (*LListPage) IsDefault

func (p *LListPage) IsDefault() bool

func (*LListPage) NavTabs

func (p *LListPage) NavTabs() navigation.NavTabs

func (*LListPage) Navigation

func (p *LListPage) Navigation() *navigation.Navigation

func (*LListPage) PageHeader

func (p *LListPage) PageHeader() *PageHeader

func (*LListPage) ToolbarEnabled

func (p *LListPage) ToolbarEnabled() bool

func (*LListPage) Type

func (p *LListPage) Type() PageType

func (*LListPage) URL

func (p *LListPage) URL() string

type ListPageConfig

type ListPageConfig struct {
	PageConfig
	MainButton    *MainButton
	Title         string
	DataLoader    *dataloader.DataLoader
	Pagination    *PaginationConfig
	ListRowConfig *ListRowConfig
	SearchConfig  *ListSearchConfig
}

type ListRowConfig

type ListRowConfig struct {
	DataRowFieldName string
	ParamKey         string
	OnClick          *OnListRowClick
}

type ListSearchConfig

type ListSearchConfig struct {
	InputPlaceholder string
	InputID          string
}

type MainButton

type MainButton struct {
	Label string
	URL   string
}

type OnListRowClick

type OnListRowClick struct {
	RedirectURL string
}

type OnSubmitSuccess

type OnSubmitSuccess struct {
	SetAppState          bool
	SetAppStateFieldName string
	RedirectURL          *RedirectURL `json:"redirectUrl"`
}

type Page

type Page struct {
	Header *PageHeader
	// contains filtered or unexported fields
}

func (*Page) ID

func (p *Page) ID() string

func (*Page) Icon

func (p *Page) Icon() icon.Icon

func (*Page) IsDefault

func (p *Page) IsDefault() bool

func (*Page) NavTabs

func (p *Page) NavTabs() navigation.NavTabs

func (*Page) Navigation

func (p *Page) Navigation() *navigation.Navigation

func (*Page) PageHeader

func (p *Page) PageHeader() *PageHeader

func (*Page) ToolbarEnabled

func (p *Page) ToolbarEnabled() bool

func (*Page) Type

func (p *Page) Type() PageType

func (*Page) URL

func (p *Page) URL() string

type PageConfig

type PageConfig struct {
	ID             string
	Icon           icon.Icon
	IsDefault      bool
	ToolbarEnabled bool
	Type           PageType
	URL            string
	NavTabs        navigation.NavTabs
	Navigation     *navigation.Navigation
	Header         *PageHeader
}
type PageHeader struct {
	ID        string
	FieldName string
}

type PageType

type PageType uint
const (
	DashboardPage PageType = iota
	SideFormPage
	ListPage
	FormPage
	EditPage
	UploadPage
	CardListPage
)

type Pager

type Pager interface {
	IsDefault() bool
	ID() string
	URL() string
	Type() PageType
	Icon() icon.Icon
	ToolbarEnabled() bool
	NavTabs() navigation.NavTabs
	Navigation() *navigation.Navigation
	PageHeader() *PageHeader
}

func NewCardListPage

func NewCardListPage(p CardListPageConfig) Pager

func NewEditPage

func NewEditPage(p EditPageConfig) Pager

func NewFormPage

func NewFormPage(p FormPageConfig) Pager

func NewListPage

func NewListPage(p ListPageConfig) Pager

func NewPage

func NewPage(p PageConfig) Pager

func NewSideFormPage

func NewSideFormPage(p SideFormPageConfig) Pager

func NewUploadPage

func NewUploadPage(p UploadPageConfig) Pager

type Pages

type Pages []Pager

type PaginationConfig

type PaginationConfig struct {
	RowsPerPage int
}

type RedirectURL

type RedirectURL struct {
	URL          string                   `json:"url"`
	SearchParams *navigation.SearchParams `json:"searchParams"`
}

type SSideFormPage

type SSideFormPage struct {
	Form            Form
	BackgroundImage *url.URL
	FooterLabel     string
	// contains filtered or unexported fields
}

func (*SSideFormPage) ID

func (p *SSideFormPage) ID() string

func (*SSideFormPage) Icon

func (p *SSideFormPage) Icon() icon.Icon

func (*SSideFormPage) IsDefault

func (p *SSideFormPage) IsDefault() bool

func (*SSideFormPage) NavTabs

func (p *SSideFormPage) NavTabs() navigation.NavTabs

func (*SSideFormPage) Navigation

func (p *SSideFormPage) Navigation() *navigation.Navigation

func (*SSideFormPage) PageHeader

func (p *SSideFormPage) PageHeader() *PageHeader

func (*SSideFormPage) ToolbarEnabled

func (p *SSideFormPage) ToolbarEnabled() bool

func (*SSideFormPage) Type

func (p *SSideFormPage) Type() PageType

func (*SSideFormPage) URL

func (p *SSideFormPage) URL() string

type SideFormPageConfig

type SideFormPageConfig struct {
	PageConfig

	Form            Form
	BackgroundImage *url.URL
	FooterLabel     string
}

type Submit

type Submit struct {
	Label        string                   `json:"label"`
	URL          string                   `json:"url"`
	SearchParams *navigation.SearchParams `json:"searchParams"`
	Method       string                   `json:"method"`
	Header       *Header                  `json:"header"`
	OnSuccess    *OnSubmitSuccess         `json:"onSuccess"`
}

type UITheme

type UITheme int8
const (
	MaterialUI UITheme = iota + 1
	AntDesignUI
)

type UUploadPage

type UUploadPage struct {
	ParamKey   string
	DataLoader *dataloader.DataLoader
	Form       Form
	Header     *PageHeader
	// contains filtered or unexported fields
}

func (*UUploadPage) ID

func (p *UUploadPage) ID() string

func (*UUploadPage) Icon

func (p *UUploadPage) Icon() icon.Icon

func (*UUploadPage) IsDefault

func (p *UUploadPage) IsDefault() bool

func (*UUploadPage) NavTabs

func (p *UUploadPage) NavTabs() navigation.NavTabs

func (*UUploadPage) Navigation

func (p *UUploadPage) Navigation() *navigation.Navigation

func (*UUploadPage) PageHeader

func (p *UUploadPage) PageHeader() *PageHeader

func (*UUploadPage) ToolbarEnabled

func (p *UUploadPage) ToolbarEnabled() bool

func (*UUploadPage) Type

func (p *UUploadPage) Type() PageType

func (*UUploadPage) URL

func (p *UUploadPage) URL() string

type UploadPageConfig

type UploadPageConfig struct {
	PageConfig

	ParamKey   string
	DataLoader *dataloader.DataLoader
	Form       Form
}

Jump to

Keyboard shortcuts

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