github.com/kotovmak/go-admin@v1.1.1/modules/page/page.go (about) 1 // Copyright 2019 GoAdmin Core Team. All rights reserved. 2 // Use of this source code is governed by a Apache-2.0 style 3 // license that can be found in the LICENSE file. 4 5 package page 6 7 import ( 8 "bytes" 9 10 "github.com/kotovmak/go-admin/context" 11 "github.com/kotovmak/go-admin/modules/config" 12 "github.com/kotovmak/go-admin/modules/db" 13 "github.com/kotovmak/go-admin/modules/logger" 14 "github.com/kotovmak/go-admin/modules/menu" 15 "github.com/kotovmak/go-admin/plugins/admin/models" 16 "github.com/kotovmak/go-admin/template" 17 "github.com/kotovmak/go-admin/template/types" 18 ) 19 20 // SetPageContent set and return the panel of page content. 21 func SetPageContent(ctx *context.Context, user models.UserModel, c func(ctx interface{}) (types.Panel, error), conn db.Connection) { 22 23 panel, err := c(ctx) 24 25 if err != nil { 26 logger.Error("SetPageContent", err) 27 panel = template.WarningPanel(err.Error()) 28 } 29 30 tmpl, tmplName := template.Get(config.GetTheme()).GetTemplate(ctx.IsPjax()) 31 32 ctx.AddHeader("Content-Type", "text/html; charset=utf-8") 33 34 buf := new(bytes.Buffer) 35 36 err = tmpl.ExecuteTemplate(buf, tmplName, types.NewPage(&types.NewPageParam{ 37 User: user, 38 Menu: menu.GetGlobalMenu(user, conn, ctx.Lang()).SetActiveClass(config.URLRemovePrefix(ctx.Path())), 39 Panel: panel.GetContent(config.IsProductionEnvironment()), 40 Assets: template.GetComponentAssetImportHTML(), 41 TmplHeadHTML: template.Default().GetHeadHTML(), 42 TmplFootJS: template.Default().GetFootJS(), 43 Iframe: ctx.IsIframe(), 44 })) 45 if err != nil { 46 logger.Error("SetPageContent", err) 47 } 48 ctx.WriteString(buf.String()) 49 }