action_bar

package module
v0.0.0-...-136e5e2 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2019 License: MIT Imports: 6 Imported by: 25

README

ActionBar

ActionBar is an auxiliary UI plug-in for QOR Admin. It generates a small bar on the top of frontend pages. The bar contains:

  • Switcher of Preview and Edit mode,
  • Login/Logout links,
  • Additional links according to QOR Admin configuration.

GoDoc

Usage

Register ActionBar to QOR Admin

  ActionBar = action_bar.New(Admin)

Then render ActionBar in the view, usually we put it in the view context.

viewCtx["ActionBarTag"] = admin.ActionBar.Render(ctx.Writer, ctx.Request)

// In the template
{{.Result.ActionBarTag}}

Advanced usages

ActionBar has a RegisterAction function to do so. Here's an example that adds admin link to ActionBar.

ActionBar.RegisterAction(&action_bar.Action{Name: "Admin Dashboard", Link: "/admin"})
Be able to edit resource in the front-end directly.

Imagine the administrator of a EC site could edit a product detail in the shopping page rather than edit it in the back-end CMS. The shopping page editing could help the administrator to have a better operation experience. We have integrated this feature to ActionBar. The setup is easy.

First, register view functions. The example uses Render to render the template. So we register functions by Render.RegisterFuncMap. The admin.ActionBar in the example is an instance of QOR Admin.

for key, value := range admin.ActionBar.FuncMap(ctx.Writer, ctx.Request) {
  Render.RegisterFuncMap(key, value)
}

Then render the edit button in the template.

// Assume this is in the product show page
{{ render_edit_button .Product }}

Then you will see a Edit button in the product show page and the administrator could edit product's info in the front-end directly.

Online Demo, you will see a bar at the top of homepage after logged in as an administrator.

License

Released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

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(w http.ResponseWriter, r *http.Request) bool

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

func (*ActionBar) FuncMap

FuncMap will return helper to render inline edit button

func (*ActionBar) RegisterAction

func (bar *ActionBar) RegisterAction(action ActionInterface)

RegisterAction register global action

func (*ActionBar) Render

func (bar *ActionBar) Render(w http.ResponseWriter, r *http.Request) 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(w http.ResponseWriter, r *http.Request, title string, link string) template.HTML

func (*ActionBar) RenderEditButtonWithResource

func (bar *ActionBar) RenderEditButtonWithResource(w http.ResponseWriter, r *http.Request, 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

Jump to

Keyboard shortcuts

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