github.com/kotovmak/go-admin@v1.1.1/plugins/admin/modules/guard/export.go (about) 1 package guard 2 3 import ( 4 "strings" 5 6 "github.com/kotovmak/go-admin/context" 7 "github.com/kotovmak/go-admin/modules/errors" 8 "github.com/kotovmak/go-admin/plugins/admin/modules/table" 9 ) 10 11 type ExportParam struct { 12 Panel table.Table 13 Id []string 14 Prefix string 15 IsAll bool 16 } 17 18 func (g *Guard) Export(ctx *context.Context) { 19 panel, prefix := g.table(ctx) 20 if !panel.GetExportable() { 21 alert(ctx, panel, errors.OperationNotAllow, g.conn, g.navBtns) 22 ctx.Abort() 23 return 24 } 25 26 idStr := make([]string, 0) 27 ids := ctx.FormValue("id") 28 if ids != "" { 29 idStr = strings.Split(ctx.FormValue("id"), ",") 30 } 31 32 ctx.SetUserValue(exportParamKey, &ExportParam{ 33 Panel: panel, 34 Id: idStr, 35 Prefix: prefix, 36 IsAll: ctx.FormValue("is_all") == "true", 37 }) 38 ctx.Next() 39 } 40 41 func GetExportParam(ctx *context.Context) *ExportParam { 42 return ctx.UserValue[exportParamKey].(*ExportParam) 43 }