// Action register action for qor resource
Action register action for qor resource
// Action register action for qor resource
func (res *Resource) Action(action *Action) *Action {
	for _, a := range res.Actions {
		if a.Name == action.Name {
			if action.Label != "" {
				a.Label = action.Label
			}
			if action.Method != "" {
				a.Method = action.Method
			}
			if action.URL != nil {
				a.URL = action.URL
			}
			if action.URLOpenType != "" {
				a.URLOpenType = action.URLOpenType
			}
			if action.Visible != nil {
				a.Visible = action.Visible
			}
			if action.Handler != nil {
				a.Handler = action.Handler
			}
			if len(action.Modes) != 0 {
				a.Modes = action.Modes
			}
			if action.Resource != nil {
				a.Resource = action.Resource
			}
			if action.Permission != nil {
				a.Permission = action.Permission
			}
			*action = *a
			return a
		}
	}
	if action.Label == "" {
		action.Label = utils.HumanizeString(action.Name)
	}
	if action.Method == "" {
		if action.URL != nil {
			action.Method = "GET"
		} else {
			action.Method = "PUT"
		}
	}
	if action.URLOpenType == "" {
		if action.Resource != nil {
			action.URLOpenType = "bottomsheet"
		} else if action.Method == "GET" {
			action.URLOpenType = "_blank"
		}
	}
	res.Actions = append(res.Actions, action)
	{
		actionController := &Controller{Admin: res.GetAdmin(), action: action}
		primaryKeyParams := res.ParamIDName()
		if action.Resource != nil {
			res.RegisterRoute("GET", path.Join("!action", action.ToParam()), actionController.Action, &RouteConfig{Permissioner: action, PermissionMode: roles.Update})
			res.RegisterRoute("GET", path.Join(primaryKeyParams, action.ToParam()), actionController.Action, &RouteConfig{Permissioner: action, PermissionMode: roles.Update})
		}
		if action.Handler != nil {
			res.RegisterRoute("PUT", path.Join("!action", action.ToParam()), actionController.Action, &RouteConfig{Permissioner: action, PermissionMode: roles.Update})
			res.RegisterRoute("PUT", path.Join(primaryKeyParams, action.ToParam()), actionController.Action, &RouteConfig{Permissioner: action, PermissionMode: roles.Update})
		}
	}
	return action
}
func ( res * Resource ) Action ( action * Action ) * Action { for _ , a := range res . Actions { if a . Name == action . Name { if action . Label != " " { a . Label = action . Label } if action . Method != " " { a . Method = action . Method } if action . URL != nil { a . URL = action . URL } if action . URLOpenType != " " { a . URLOpenType = action . URLOpenType } if action . Visible != nil { a . Visible = action . Visible } if action . Handler != nil { a . Handler = action . Handler } if len ( action . Modes ) != 0 { a . Modes = action . Modes } if action . Resource != nil { a . Resource = action . Resource } if action . Permission != nil { a . Permission = action . Permission } * action = * a return a } } if action . Label == " " { action . Label = utils . HumanizeString ( action . Name ) } if action . Method == " " { if action . URL != nil { action . Method = " " } else { action . Method = " " } } if action . URLOpenType == " " { if action . Resource != nil { action . URLOpenType = " " } else if action . Method == " " { action . URLOpenType = " " } } res . Actions = append ( res . Actions , action ) { actionController := & Controller { Admin : res . GetAdmin ( ) , action : action } primaryKeyParams := res . ParamIDName ( ) if action . Resource != nil { res . RegisterRoute ( " " , path . Join ( " " , action . ToParam ( ) ) , actionController . Action , & RouteConfig { Permissioner : action , PermissionMode : roles . Update } ) res . RegisterRoute ( " " , path . Join ( primaryKeyParams , action . ToParam ( ) ) , actionController . Action , & RouteConfig { Permissioner : action , PermissionMode : roles . Update } ) } if action . Handler != nil { res . RegisterRoute ( " " , path . Join ( " " , action . ToParam ( ) ) , actionController . Action , & RouteConfig { Permissioner : action , PermissionMode : roles . Update } ) res . RegisterRoute ( " " , path . Join ( primaryKeyParams , action . ToParam ( ) ) , actionController . Action , & RouteConfig { Permissioner : action , PermissionMode : roles . Update } ) } } return action }
Action register action for qor resource
Action register action for qor resource
// Register Actions into Router // Bulk Action // Single Resource Action // Bulk Action // Single Resource action