Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch language on the front end #189

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor(deepsource): improve code quality
cg33 committed Feb 16, 2022
commit 70c44d1160a3c1a909d8b07d0f0b020dc6648292
2 changes: 1 addition & 1 deletion examples/gin/main.go
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ func main() {
Port: "3306",
User: "root",
Pwd: "root",
Name: "goadmin",
Name: "godmin",
MaxIdleCon: 50,
MaxOpenCon: 150,
Driver: config.DriverMysql,
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@ github.com/360EntSecGroup-Skylar/excelize v1.4.1/go.mod h1:vnax29X2usfl7HHkBrX5E
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/GoAdminGroup/html v0.0.1 h1:SdWNWl4OKPsvDk2GDp5ZKD6ceWoN8n4Pj6cUYxavUd0=
github.com/GoAdminGroup/html v0.0.1/go.mod h1:A1laTJaOx8sQ64p2dE8IqtstDeCNBHEazrEp7hR5VvM=
github.com/GoAdminGroup/themes v0.0.27 h1:mm1JBSF2ucK8Yv2PH5w4+gzqisIPo2Q9t4+ICn8460M=
github.com/GoAdminGroup/themes v0.0.27/go.mod h1:ABCOeBeibfg9DxAsGVa1NzYK9/nIbHT/BuFrCRIKo8A=
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e h1:n+DcnTNkQnHlwpsrHoQtkrJIO7CBx029fw6oR4vIob4=
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e/go.mod h1:Bdzq+51GR4/0DIhaICZEOm+OHvXGwwB2trKZ8B4Y6eQ=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
@@ -89,8 +87,6 @@ github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b h1:j7+1HpAFS1zy5+Q4qx1fWh90gTKwiN4QCGoY9TWyyO4=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
@@ -184,8 +180,6 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c h1:jceGD5YNJGgGMkJz79agzOln1K9TaZUjv5ird16qniQ=
golang.org/x/sys v0.0.0-20200219091948-cb0a6d8edb6c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
2 changes: 1 addition & 1 deletion modules/auth/auth.go
Original file line number Diff line number Diff line change
@@ -161,7 +161,7 @@ type Service struct {
P Processor
}

func (s *Service) Name() string {
func (*Service) Name() string {
return "auth"
}

16 changes: 8 additions & 8 deletions modules/config/config.go
Original file line number Diff line number Diff line change
@@ -393,7 +393,7 @@ type Config struct {

AssetRootPath string `json:"asset_root_path,omitempty" yaml:"asset_root_path,omitempty" ini:"asset_root_path,omitempty"`

URLFormat URLFormat `json:"url_format,omitempty" yaml:"url_format,omitempty" ini:"url_format,omitempty"`
URLFormat *URLFormat `json:"url_format,omitempty" yaml:"url_format,omitempty" ini:"url_format,omitempty"`

prefix string `json:"-" yaml:"-" ini:"-"`
lock sync.RWMutex `json:"-" yaml:"-" ini:"-"`
@@ -438,7 +438,7 @@ type URLFormat struct {
Update string `json:"update,omitempty" yaml:"update,omitempty" ini:"update,omitempty"`
}

func (f URLFormat) SetDefault() URLFormat {
func (f *URLFormat) SetDefault() {
f.Detail = utils.SetDefault(f.Detail, "", "/info/:__prefix/detail")
f.ShowEdit = utils.SetDefault(f.ShowEdit, "", "/info/:__prefix/edit")
f.ShowCreate = utils.SetDefault(f.ShowCreate, "", "/info/:__prefix/new")
@@ -448,7 +448,6 @@ func (f URLFormat) SetDefault() URLFormat {
f.Export = utils.SetDefault(f.Export, "", "/export/:__prefix")
f.Info = utils.SetDefault(f.Info, "", "/info/:__prefix")
f.Update = utils.SetDefault(f.Update, "", "/update/:__prefix")
return f
}

type ExtraInfo map[string]interface{}
@@ -951,7 +950,8 @@ func SetDefault(cfg *Config) *Config {
} else {
cfg.prefix = cfg.UrlPrefix
}
cfg.URLFormat = cfg.URLFormat.SetDefault()
cfg.URLFormat = new(URLFormat)
cfg.URLFormat.SetDefault()
return cfg
}

@@ -1012,8 +1012,8 @@ func AssertPrefix() string {
return _global.AssertPrefix()
}

// GetIndexURL get the index url with prefix.
func GetIndexURL() string {
// GetFullIndexURL get the index url with prefix.
func GetFullIndexURL() string {
return _global.GetIndexURL()
}

@@ -1036,7 +1036,7 @@ func Url(suffix string) string {
return _global.Url(suffix)
}

func GetURLFormats() URLFormat {
func GetURLFormats() *URLFormat {
return _global.URLFormat
}

@@ -1332,7 +1332,7 @@ type Service struct {
C *Config
}

func (s *Service) Name() string {
func (*Service) Name() string {
return "config"
}

2 changes: 1 addition & 1 deletion modules/ui/ui.go
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ type Service struct {

const ServiceKey = "ui"

func (s *Service) Name() string {
func (*Service) Name() string {
return "ui"
}

2 changes: 1 addition & 1 deletion plugins/admin/admin.go
Original file line number Diff line number Diff line change
@@ -65,7 +65,7 @@ func (admin *Admin) InitPlugin(services service.List) {
}

func (admin *Admin) GetIndexURL() string {
return config.GetIndexURL()
return config.GetFullIndexURL()
}

func (admin *Admin) GetInfo() plugins.Info {
2 changes: 1 addition & 1 deletion plugins/admin/controller/api_list.go
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ func (h *Handler) ApiList(ctx *context.Context) {
params := parameter.GetParam(ctx.Request.URL, panel.GetInfo().DefaultPageSize, panel.GetInfo().SortField,
panel.GetInfo().GetSort())

panel, panelInfo, urls, err := h.showTableData(ctx, prefix, params, panel, "api_")
panel, panelInfo, urls, err := h._showTableData(ctx, prefix, params, panel, "api_")
if err != nil {
response.Error(ctx, err.Error())
return
7 changes: 2 additions & 5 deletions plugins/admin/controller/detail.go
Original file line number Diff line number Diff line change
@@ -126,16 +126,13 @@ $('.delete-btn').on('click', function (event) {
title = detail.Title

if title == "" {
title = info.Title + language.Get("Detail")
}
if desc == "" {
desc = panel.GetInfo().Description + language.GetUser("Detail", user.Id)
title = info.Title + language.GetUser("Detail", user.Id)
}

desc = detail.Description

if desc == "" {
desc = info.Description + language.Get("Detail")
desc = info.Description + language.GetUser("Detail", user.Id)
}
}

12 changes: 6 additions & 6 deletions plugins/admin/controller/edit.go
Original file line number Diff line number Diff line change
@@ -28,10 +28,10 @@ import (
// ShowForm show form page.
func (h *Handler) ShowForm(ctx *context.Context) {
param := guard.GetShowFormParam(ctx)
h.showForm(ctx, "", param.Prefix, param.Param, false)
h._showForm(ctx, "", param.Prefix, param.Param, false)
}

func (h *Handler) showForm(ctx *context.Context, alert template2.HTML, prefix string, param parameter.Parameters, isEdit bool, animation ...bool) {
func (h *Handler) _showForm(ctx *context.Context, alert template2.HTML, prefix string, param parameter.Parameters, isEdit bool, animation ...bool) {

panel := h.table(prefix, ctx)

@@ -147,7 +147,7 @@ func (h *Handler) EditForm(ctx *context.Context) {
if ctx.WantJSON() {
response.Error(ctx, err.Error())
} else {
h.showForm(ctx, aAlert().Warning(err.Error()), param.Prefix, param.Param, true)
h._showForm(ctx, aAlert().Warning(err.Error()), param.Prefix, param.Param, true)
}
return
}
@@ -177,7 +177,7 @@ func (h *Handler) EditForm(ctx *context.Context) {
"token": h.authSrv().AddToken(),
})
} else {
h.showForm(ctx, aAlert().Warning(err.Error()), param.Prefix, param.Param, true)
h._showForm(ctx, aAlert().Warning(err.Error()), param.Prefix, param.Param, true)
}
return
}
@@ -203,7 +203,7 @@ func (h *Handler) EditForm(ctx *context.Context) {
}

if isEditUrl(param.PreviousPath, param.Prefix) {
h.showForm(ctx, param.Alert, param.Prefix, param.Param, true, false)
h._showForm(ctx, param.Alert, param.Prefix, param.Param, true, false)
return
}

@@ -223,7 +223,7 @@ func (h *Handler) EditForm(ctx *context.Context) {
return
}

buf := h.showTable(ctx, param.Prefix, param.Param.DeletePK().DeleteEditPk(), nil)
buf := h._showTable(ctx, param.Prefix, param.Param.DeletePK().DeleteEditPk(), nil)

ctx.HTML(http.StatusOK, buf.String())
ctx.AddHeader(constant.PjaxUrlHeader, param.PreviousPath)
2 changes: 1 addition & 1 deletion plugins/admin/controller/new.go
Original file line number Diff line number Diff line change
@@ -164,7 +164,7 @@ func (h *Handler) NewForm(ctx *context.Context) {
return
}

buf := h.showTable(ctx, param.Prefix, param.Param, nil)
buf := h._showTable(ctx, param.Prefix, param.Param, nil)

ctx.HTML(http.StatusOK, buf.String())
ctx.AddHeader(constant.PjaxUrlHeader, h.routePathWithPrefix("info", param.Prefix)+param.Param.GetRouteParamStr())
8 changes: 4 additions & 4 deletions plugins/admin/controller/show.go
Original file line number Diff line number Diff line change
@@ -57,11 +57,11 @@ func (h *Handler) ShowInfo(ctx *context.Context) {
params := parameter.GetParam(ctx.Request.URL, panel.GetInfo().DefaultPageSize, panel.GetInfo().SortField,
panel.GetInfo().GetSort())

buf := h.showTable(ctx, prefix, params, panel)
buf := h._showTable(ctx, prefix, params, panel)
ctx.HTML(http.StatusOK, buf.String())
}

func (h *Handler) showTableData(ctx *context.Context, prefix string, params parameter.Parameters,
func (h *Handler) _showTableData(ctx *context.Context, prefix string, params parameter.Parameters,
panel table.Table, urlNamePrefix string) (table.Table, table.PanelInfo, []string, error) {
if panel == nil {
panel = h.table(prefix, ctx)
@@ -97,9 +97,9 @@ func (h *Handler) showTableData(ctx *context.Context, prefix string, params para
return panel, panelInfo, []string{editUrl, newUrl, deleteUrl, exportUrl, detailUrl, infoUrl, updateUrl}, nil
}

func (h *Handler) showTable(ctx *context.Context, prefix string, params parameter.Parameters, panel table.Table) *bytes.Buffer {
func (h *Handler) _showTable(ctx *context.Context, prefix string, params parameter.Parameters, panel table.Table) *bytes.Buffer {

panel, panelInfo, urls, err := h.showTableData(ctx, prefix, params, panel, "")
panel, panelInfo, urls, err := h._showTableData(ctx, prefix, params, panel, "")
if err != nil {
return h.Execute(ctx, auth.Auth(ctx),
template.WarningPanelWithDescAndTitle(err.Error(), errors.Msg, errors.Msg), "",
24 changes: 12 additions & 12 deletions plugins/admin/modules/table/generators.go
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ func NewSystemTable(conn db.Connection, c *config.Config) *SystemTable {
return &SystemTable{conn: conn, c: c}
}

func (s *SystemTable) GetManagerTable(ctx *context.Context) (managerTable Table) {
func (s *SystemTable) GetManagerTable(_ *context.Context) (managerTable Table) {
managerTable = NewDefaultTable(DefaultConfigWithDriver(config.GetDatabases().GetDefault().Driver))

info := managerTable.GetInfo().AddXssJsFilter().HideFilterArea()
@@ -352,7 +352,7 @@ func (s *SystemTable) GetManagerTable(ctx *context.Context) (managerTable Table)
return
}

func (s *SystemTable) GetNormalManagerTable(ctx *context.Context) (managerTable Table) {
func (s *SystemTable) GetNormalManagerTable(_ *context.Context) (managerTable Table) {
managerTable = NewDefaultTable(DefaultConfigWithDriver(config.GetDatabases().GetDefault().Driver))

info := managerTable.GetInfo().AddXssJsFilter().HideFilterArea()
@@ -452,16 +452,16 @@ func (s *SystemTable) GetNormalManagerTable(ctx *context.Context) (managerTable
})
m := []types.FieldOption{}
m = append(m, types.FieldOption{
Text: language.CN,
Text: language.CN,
Value: "zh",
}, types.FieldOption{
Text: language.EN,
Text: language.EN,
Value: "en",
}, types.FieldOption{
Text: language.JP,
Text: language.JP,
Value: "jp",
}, types.FieldOption{
Text: language.TC,
Text: language.TC,
Value: "tc",
})
formList.AddField(lg("language"), "language", db.Varchar, form.SelectSingle).FieldOptions(m).FieldNotAllowAdd()
@@ -535,7 +535,7 @@ func (s *SystemTable) GetNormalManagerTable(ctx *context.Context) (managerTable
return
}

func (s *SystemTable) GetPermissionTable(ctx *context.Context) (permissionTable Table) {
func (s *SystemTable) GetPermissionTable(_ *context.Context) (permissionTable Table) {
permissionTable = NewDefaultTable(DefaultConfigWithDriver(config.GetDatabases().GetDefault().Driver))

info := permissionTable.GetInfo().AddXssJsFilter().HideFilterArea()
@@ -673,7 +673,7 @@ func (s *SystemTable) GetPermissionTable(ctx *context.Context) (permissionTable
return
}

func (s *SystemTable) GetRolesTable(ctx *context.Context) (roleTable Table) {
func (s *SystemTable) GetRolesTable(_ *context.Context) (roleTable Table) {
roleTable = NewDefaultTable(DefaultConfigWithDriver(config.GetDatabases().GetDefault().Driver))

info := roleTable.GetInfo().AddXssJsFilter().HideFilterArea()
@@ -830,7 +830,7 @@ func (s *SystemTable) GetRolesTable(ctx *context.Context) (roleTable Table) {
return
}

func (s *SystemTable) GetOpTable(ctx *context.Context) (opTable Table) {
func (s *SystemTable) GetOpTable(_ *context.Context) (opTable Table) {
opTable = NewDefaultTable(Config{
Driver: config.GetDatabases().GetDefault().Driver,
CanAdd: false,
@@ -1054,7 +1054,7 @@ func (s *SystemTable) GetMenuTable(ctx *context.Context) (menuTable Table) {
return
}

func (s *SystemTable) GetSiteTable(ctx *context.Context) (siteTable Table) {
func (s *SystemTable) GetSiteTable(_ *context.Context) (siteTable Table) {
siteTable = NewDefaultTable(DefaultConfigWithDriver(config.GetDatabases().GetDefault().Driver).
SetOnlyUpdateForm().
SetGetDataFun(func(params parameter.Parameters) (i []map[string]interface{}, i2 int) {
@@ -1398,7 +1398,7 @@ func (s *SystemTable) GetGenerateForm(ctx *context.Context) (generateTool Table)
formList.AddField(lgWithScore("connection", "tool"), "conn", db.Varchar, form.SelectSingle).
FieldOptions(ops).
FieldOnChooseAjax("table", "/tool/choose/conn",
func(ctx *context.Context) (success bool, msg string, data interface{}) {
func(_ *context.Context) (success bool, msg string, data interface{}) {
connName := ctx.FormValue("value")
if connName == "" {
return false, "wrong parameter", nil
@@ -1417,7 +1417,7 @@ func (s *SystemTable) GetGenerateForm(ctx *context.Context) (generateTool Table)
})
formList.AddField(lgWithScore("table", "tool"), "table", db.Varchar, form.SelectSingle).
FieldOnChooseAjax("xxxx", "/tool/choose/table",
func(ctx *context.Context) (success bool, msg string, data interface{}) {
func(_ *context.Context) (success bool, msg string, data interface{}) {

var (
tableName = ctx.FormValue("value")
2 changes: 1 addition & 1 deletion template/types/page.go
Original file line number Diff line number Diff line change
@@ -154,7 +154,7 @@ func NewPage(param *NewPageParam) *Page {
Logo: logo,
MiniLogo: config.GetMiniLogo(),
ColorScheme: config.GetColorScheme(),
IndexUrl: config.GetIndexURL(),
IndexUrl: config.GetFullIndexURL(),
CdnUrl: config.GetAssetUrl(),
CustomHeadHtml: config.GetCustomHeadHtml(),
CustomFootHtml: config.GetCustomFootHtml() + param.NavButtonsJS,