action_bar

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

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

Go to latest
Published: Sep 4, 2020 License: MIT Imports: 14 Imported by: 0

README

ActionBar

ActionBar is dependant on QOR Admin. It provides an action bar on the top of frontend page. The bar contains:

  • Switcher of Preview and Edit mode
  • Login/Logout links
  • Additional links in a menu

GoDoc

Usage

import "github.com/ecletus/admin"
import "github.com/ecletus/action_bar"

func main() {
  Admin := admin.New(&qor.Config{DB: db})

  // Register Global ActionBar object
  // Auth is admin.Auth interface, you need to define a struct and implements interface's functions
  ActionBar = action_bar.New(Admin, Auth)
  ActionBar.RegisterAction(&action_bar.Action{Name: "Admin Dashboard", Link: "/admin"})

  // Then use Render to render action bar in view
  ActionBar.Render(writer, request)

  // Make resource able be edit in frontend directly
  // 1. Add action_bar funcmap to view
  //    ActionBar.FuncMap(writer, request)
  // 2. Using funcmap render_edit_button in template
  //    {{ render_edit_button .Product }}
  // 3. then you will see a `Edit` button in product show page and user could edit product' info in frontend
}

Online Demo, you will see a bar at the top of homepage.

License

Released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PKG       = path_helpers.GetCalledDir()
	I18NGROUP = i18nmod.PkgToGroup(PKG)
)

Functions

This section is empty.

Types

type Action

type Action struct {
	EditModeOnly bool
	Inline       bool
	Name         string
	Link         string
}

func (Action) InlineAction

func (action Action) InlineAction() bool

func (Action) ToHTML

func (action Action) ToHTML(context *admin.Context) template.HTML

type ActionBar

type ActionBar struct {
	Admin         *admin.Admin
	GlobalActions []ActionInterface
	// contains filtered or unexported fields
}

ActionBar stores configuration about a action bar.

func New

func New(admin *admin.Admin) *ActionBar

New will create an ActionBar object

func (*ActionBar) Actions

func (bar *ActionBar) Actions(actions ...ActionInterface) *ActionBar

Actions register actions

func (*ActionBar) EditMode

func (bar *ActionBar) EditMode(context *admin.Context) bool

EditMode return whether current mode is `Preview` or `Edit`

func (*ActionBar) FuncMap

func (bar *ActionBar) FuncMap(context *admin.Context) template.FuncMap

FuncMap will return helper to render inline edit button

func (*ActionBar) PrepareAdmin

func (bar *ActionBar) PrepareAdmin(Admin *admin.Admin)

func (*ActionBar) RegisterAction

func (bar *ActionBar) RegisterAction(action ActionInterface)

RegisterAction register global action

func (*ActionBar) Render

func (bar *ActionBar) Render(context *admin.Context) template.HTML

Render will return the HTML of the bar, used this function to render the bar in frontend page's template or layout

func (*ActionBar) RenderEditButton

func (bar *ActionBar) RenderEditButton(context *admin.Context, title string, link string) template.HTML

func (*ActionBar) RenderEditButtonWithResource

func (bar *ActionBar) RenderEditButtonWithResource(context *admin.Context, value interface{}, resources ...*admin.Resource) template.HTML

type ActionInterface

type ActionInterface interface {
	InlineAction() bool
	ToHTML(*admin.Context) template.HTML
}

type EditResourceAction

type EditResourceAction struct {
	EditModeOnly bool
	Inline       bool
	Value        interface{}
	Resource     *admin.Resource
}

func (EditResourceAction) InlineAction

func (action EditResourceAction) InlineAction() bool

func (EditResourceAction) ToHTML

func (action EditResourceAction) ToHTML(context *admin.Context) template.HTML

type HTMLAction

type HTMLAction struct {
	EditModeOnly bool
	HTML         template.HTML
}

func (HTMLAction) InlineAction

func (action HTMLAction) InlineAction() bool

func (HTMLAction) ToHTML

func (action HTMLAction) ToHTML(context *admin.Context) template.HTML

type Plugin

type Plugin struct {
	plug.EventDispatcher
	admin_plugin.AdminNames
}

Jump to

Keyboard shortcuts

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