Skip to content

Commit

Permalink
add divide header to menu
Browse files Browse the repository at this point in the history
  • Loading branch information
cg33 committed Sep 12, 2019
1 parent ed9a0eb commit e4e7c21
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 26 deletions.
Binary file modified examples/datamodel/admin.db
Binary file not shown.
25 changes: 14 additions & 11 deletions examples/datamodel/admin.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# Host: 127.0.0.1 (MySQL 5.7.19)
# Database: godmin
# Generation Time: 2019-09-10 11:59:54 +0000
# Generation Time: 2019-09-12 04:16:47 +0000
# ************************************************************


Expand All @@ -33,6 +33,7 @@ CREATE TABLE `goadmin_menu` (
`title` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
`icon` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
`uri` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`header` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
Expand All @@ -41,15 +42,15 @@ CREATE TABLE `goadmin_menu` (
LOCK TABLES `goadmin_menu` WRITE;
/*!40000 ALTER TABLE `goadmin_menu` DISABLE KEYS */;

INSERT INTO `goadmin_menu` (`id`, `parent_id`, `type`, `order`, `title`, `icon`, `uri`, `created_at`, `updated_at`)
INSERT INTO `goadmin_menu` (`id`, `parent_id`, `type`, `order`, `title`, `icon`, `uri`, `header`, `created_at`, `updated_at`)
VALUES
(1,0,1,2,'Admin','fa-tasks','','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(2,1,1,2,'Users','fa-users','/info/manager','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(3,1,1,3,'Roles','fa-user','/info/roles','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(4,1,1,4,'Permission','fa-ban','/info/permission','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(5,1,1,5,'Menu','fa-bars','/menu','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(6,1,1,6,'Operation log','fa-history','/info/op','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(7,0,1,1,'Dashboard','fa-bar-chart','/','2019-09-10 00:00:00','2019-09-10 00:00:00');
(1,0,1,2,'Admin','fa-tasks','',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(2,1,1,2,'Users','fa-users','/info/manager',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(3,1,1,3,'Roles','fa-user','/info/roles',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(4,1,1,4,'Permission','fa-ban','/info/permission',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(5,1,1,5,'Menu','fa-bars','/menu',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(6,1,1,6,'Operation log','fa-history','/info/op',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(7,0,1,1,'Dashboard','fa-bar-chart','/',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00');

/*!40000 ALTER TABLE `goadmin_menu` ENABLE KEYS */;
UNLOCK TABLES;
Expand Down Expand Up @@ -124,7 +125,9 @@ INSERT INTO `goadmin_role_menu` (`role_id`, `menu_id`, `created_at`, `updated_at
VALUES
(1,1,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(1,7,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(2,7,'2019-09-10 00:00:00','2019-09-10 00:00:00');
(2,7,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(1,8,'2019-09-11 10:20:55','2019-09-11 10:20:55'),
(2,8,'2019-09-11 10:20:55','2019-09-11 10:20:55');

/*!40000 ALTER TABLE `goadmin_role_menu` ENABLE KEYS */;
UNLOCK TABLES;
Expand Down Expand Up @@ -272,7 +275,7 @@ LOCK TABLES `goadmin_users` WRITE;

INSERT INTO `goadmin_users` (`id`, `username`, `password`, `name`, `avatar`, `remember_token`, `created_at`, `updated_at`)
VALUES
(1,'admin','$2a$10$337scQn24ot0RGGJ.MuQc.quVZ/2e/pSwuOQrK6N7K2hs11r2FLlO','admin','','tlNcBVK9AvfYH7WEnwB1RKvocJu8FfRy4um3DJtwdHuJy0dwFsLOgAc0xUfh','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(1,'admin','$2a$10$U3F/NSaf2kaVbyXTBp7ppOn0jZFyRqXRnYXB.AMioCjXl3Ciaj4oy','admin','','tlNcBVK9AvfYH7WEnwB1RKvocJu8FfRy4um3DJtwdHuJy0dwFsLOgAc0xUfh','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(2,'operator','$2a$10$rVqkOzHjN2MdlEprRflb1eGP0oZXuSrbJLOmJagFsCd81YZm0bsh.','Operator','',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00');

/*!40000 ALTER TABLE `goadmin_users` ENABLE KEYS */;
Expand Down
7 changes: 7 additions & 0 deletions modules/menu/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ func ConstructMenuTree(menus []map[string]interface{}, parentId int64) []Item {
title = menus[j]["title"].(string)
}

header, _ := menus[j]["header"].(string)

child := Item{
Name: title,
ID: strconv.FormatInt(menus[j]["id"].(int64), 10),
Url: menus[j]["uri"].(string),
Icon: menus[j]["icon"].(string),
Header: header,
Active: "",
ChildrenList: childList,
}
Expand All @@ -154,11 +157,14 @@ func ConstructMenuTree(menus []map[string]interface{}, parentId int64) []Item {
func GetMenuItemById(id string) Item {
menu, _ := db.Table("goadmin_menu").Find(id)

header, _ := menu["header"].(string)

return Item{
Name: menu["title"].(string),
ID: strconv.FormatInt(menu["id"].(int64), 10),
Url: menu["uri"].(string),
Icon: menu["icon"].(string),
Header: header,
Active: "",
ChildrenList: []Item{},
}
Expand Down Expand Up @@ -194,6 +200,7 @@ type Item struct {
ID string
Url string
Icon string
Header string
Active string
ChildrenList []Item
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/admin/controller/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func EditMenu(ctx *context.Context) {
menuModel.AddRole(roleId)
}

menuModel.Update(param.Title, param.Icon, param.Uri, param.ParentId)
menuModel.Update(param.Title, param.Icon, param.Uri, param.Header, param.ParentId)

menu.SetGlobalMenu(auth.Auth(ctx))

Expand All @@ -94,7 +94,7 @@ func NewMenu(ctx *context.Context) {

user := auth.Auth(ctx)

menuModel := models.Menu().New(param.Title, param.Icon, param.Uri, param.ParentId, (menu.GetGlobalMenu(user)).MaxOrder+1)
menuModel := models.Menu().New(param.Title, param.Icon, param.Uri, param.Header, param.ParentId, (menu.GetGlobalMenu(user)).MaxOrder+1)

for _, roleId := range param.Roles {
menuModel.AddRole(roleId)
Expand Down
25 changes: 14 additions & 11 deletions plugins/admin/data/mysql/admin.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# Host: 127.0.0.1 (MySQL 5.7.19)
# Database: godmin
# Generation Time: 2019-09-10 11:59:54 +0000
# Generation Time: 2019-09-12 04:16:47 +0000
# ************************************************************


Expand All @@ -33,6 +33,7 @@ CREATE TABLE `goadmin_menu` (
`title` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
`icon` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL,
`uri` varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',
`header` varchar(150) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
Expand All @@ -41,15 +42,15 @@ CREATE TABLE `goadmin_menu` (
LOCK TABLES `goadmin_menu` WRITE;
/*!40000 ALTER TABLE `goadmin_menu` DISABLE KEYS */;

INSERT INTO `goadmin_menu` (`id`, `parent_id`, `type`, `order`, `title`, `icon`, `uri`, `created_at`, `updated_at`)
INSERT INTO `goadmin_menu` (`id`, `parent_id`, `type`, `order`, `title`, `icon`, `uri`, `header`, `created_at`, `updated_at`)
VALUES
(1,0,1,2,'Admin','fa-tasks','','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(2,1,1,2,'Users','fa-users','/info/manager','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(3,1,1,3,'Roles','fa-user','/info/roles','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(4,1,1,4,'Permission','fa-ban','/info/permission','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(5,1,1,5,'Menu','fa-bars','/menu','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(6,1,1,6,'Operation log','fa-history','/info/op','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(7,0,1,1,'Dashboard','fa-bar-chart','/','2019-09-10 00:00:00','2019-09-10 00:00:00');
(1,0,1,2,'Admin','fa-tasks','',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(2,1,1,2,'Users','fa-users','/info/manager',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(3,1,1,3,'Roles','fa-user','/info/roles',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(4,1,1,4,'Permission','fa-ban','/info/permission',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(5,1,1,5,'Menu','fa-bars','/menu',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(6,1,1,6,'Operation log','fa-history','/info/op',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(7,0,1,1,'Dashboard','fa-bar-chart','/',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00');

/*!40000 ALTER TABLE `goadmin_menu` ENABLE KEYS */;
UNLOCK TABLES;
Expand Down Expand Up @@ -124,7 +125,9 @@ INSERT INTO `goadmin_role_menu` (`role_id`, `menu_id`, `created_at`, `updated_at
VALUES
(1,1,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(1,7,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(2,7,'2019-09-10 00:00:00','2019-09-10 00:00:00');
(2,7,'2019-09-10 00:00:00','2019-09-10 00:00:00'),
(1,8,'2019-09-11 10:20:55','2019-09-11 10:20:55'),
(2,8,'2019-09-11 10:20:55','2019-09-11 10:20:55');

/*!40000 ALTER TABLE `goadmin_role_menu` ENABLE KEYS */;
UNLOCK TABLES;
Expand Down Expand Up @@ -272,7 +275,7 @@ LOCK TABLES `goadmin_users` WRITE;

INSERT INTO `goadmin_users` (`id`, `username`, `password`, `name`, `avatar`, `remember_token`, `created_at`, `updated_at`)
VALUES
(1,'admin','$2a$10$337scQn24ot0RGGJ.MuQc.quVZ/2e/pSwuOQrK6N7K2hs11r2FLlO','admin','','tlNcBVK9AvfYH7WEnwB1RKvocJu8FfRy4um3DJtwdHuJy0dwFsLOgAc0xUfh','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(1,'admin','$2a$10$U3F/NSaf2kaVbyXTBp7ppOn0jZFyRqXRnYXB.AMioCjXl3Ciaj4oy','admin','','tlNcBVK9AvfYH7WEnwB1RKvocJu8FfRy4um3DJtwdHuJy0dwFsLOgAc0xUfh','2019-09-10 00:00:00','2019-09-10 00:00:00'),
(2,'operator','$2a$10$rVqkOzHjN2MdlEprRflb1eGP0oZXuSrbJLOmJagFsCd81YZm0bsh.','Operator','',NULL,'2019-09-10 00:00:00','2019-09-10 00:00:00');

/*!40000 ALTER TABLE `goadmin_users` ENABLE KEYS */;
Expand Down
Binary file modified plugins/admin/data/sqlite/admin.db
Binary file not shown.
10 changes: 8 additions & 2 deletions plugins/admin/models/menu.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type MenuModel struct {
ParentId int64
Icon string
Uri string
Header string
CreatedAt string
UpdatedAt string
}
Expand All @@ -32,21 +33,23 @@ func (t MenuModel) Find(id interface{}) MenuModel {
return t.MapToModel(item)
}

func (t MenuModel) New(title, icon, uri string, parentId, order int64) MenuModel {
func (t MenuModel) New(title, icon, uri, header string, parentId, order int64) MenuModel {

id, _ := db.Table(t.Table).Insert(dialect.H{
"title": title,
"parent_id": parentId,
"icon": icon,
"uri": uri,
"order": order,
"header": header,
})

t.Id = id
t.Title = title
t.ParentId = parentId
t.Icon = icon
t.Uri = uri
t.Header = header

return t
}
Expand All @@ -57,7 +60,7 @@ func (t MenuModel) Delete() {
Where("menu_id", "=", t.Id).Delete()
}

func (t MenuModel) Update(title, icon, uri string, parentId int64) MenuModel {
func (t MenuModel) Update(title, icon, uri, header string, parentId int64) MenuModel {

_, _ = db.Table(t.Table).
Where("id", "=", t.Id).
Expand All @@ -66,12 +69,14 @@ func (t MenuModel) Update(title, icon, uri string, parentId int64) MenuModel {
"parent_id": parentId,
"icon": icon,
"uri": uri,
"header": header,
})

t.Title = title
t.ParentId = parentId
t.Icon = icon
t.Uri = uri
t.Header = header

return t
}
Expand Down Expand Up @@ -131,6 +136,7 @@ func (t MenuModel) MapToModel(m map[string]interface{}) MenuModel {
t.ParentId = m["parent_id"].(int64)
t.Icon, _ = m["icon"].(string)
t.Uri, _ = m["uri"].(string)
t.Header, _ = m["header"].(string)
t.CreatedAt, _ = m["created_at"].(string)
t.UpdatedAt, _ = m["updated_at"].(string)
return t
Expand Down
2 changes: 2 additions & 0 deletions plugins/admin/modules/guard/menu_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
type MenuEditParam struct {
Id string
Title string
Header string
ParentId int64
Icon string
Uri string
Expand All @@ -34,6 +35,7 @@ func MenuEdit(ctx *context.Context) {
ctx.SetUserValue("edit_menu_param", &MenuEditParam{
Id: ctx.FormValue("id"),
Title: ctx.FormValue("title"),
Header: ctx.FormValue("header"),
ParentId: int64(parentIdInt),
Icon: ctx.FormValue("icon"),
Uri: ctx.FormValue("uri"),
Expand Down
2 changes: 2 additions & 0 deletions plugins/admin/modules/guard/menu_new.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

type MenuNewParam struct {
Title string
Header string
ParentId int64
Icon string
Uri string
Expand All @@ -30,6 +31,7 @@ func MenuNew(ctx *context.Context) {

ctx.SetUserValue("new_menu_param", &MenuNewParam{
Title: ctx.FormValue("title"),
Header: ctx.FormValue("header"),
ParentId: int64(parentIdInt),
Icon: ctx.FormValue("icon"),
Uri: ctx.FormValue("uri"),
Expand Down
19 changes: 19 additions & 0 deletions plugins/admin/modules/table/generators.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,15 @@ func GetMenuTable() (MenuTable Table) {
return model.Value
},
},
{
Head: language.Get("header"),
Field: "header",
TypeName: "varchar",
Sortable: false,
FilterFn: func(model types.RowModel) interface{} {
return model.Value
},
},
{
Head: language.Get("createdAt"),
Field: "created_at",
Expand Down Expand Up @@ -832,6 +841,16 @@ func GetMenuTable() (MenuTable Table) {
FilterFn: func(model types.RowModel) interface{} {
return model.Value
},
}, {
Head: language.Get("header"),
Field: "header",
TypeName: "varchar",
Default: "",
Editable: true,
FormType: form.Text,
FilterFn: func(model types.RowModel) interface{} {
return model.Value
},
}, {
Head: language.Get("icon"),
Field: "icon",
Expand Down
3 changes: 3 additions & 0 deletions template/adminlte/resource/pages/menu.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
{{$UrlPrefix := .UrlPrefix}}
{{range $key, $list := .Menu.GlobalMenuList }}
{{if eq (len $list.ChildrenList) 0}}
{{if $list.Header}}
<li class="header" data-rel="external">{{$list.Header}}</li>
{{end}}
<li class='{{$list.Active}}'>
{{if eq $list.Url "/"}}
<a href='{{$UrlPrefix}}'>
Expand Down
3 changes: 3 additions & 0 deletions template/adminlte/tmpl/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -3540,6 +3540,9 @@ Showing <b>{{.CurPageStartIndex}}</b> to <b>{{.CurPageEndIndex}}</b> of <b>{{.To
{{$UrlPrefix := .UrlPrefix}}
{{range $key, $list := .Menu.GlobalMenuList }}
{{if eq (len $list.ChildrenList) 0}}
{{if $list.Header}}
<li class="header" data-rel="external">{{$list.Header}}</li>
{{end}}
<li class='{{$list.Active}}'>
{{if eq $list.Url "/"}}
<a href='{{$UrlPrefix}}'>
Expand Down

0 comments on commit e4e7c21

Please sign in to comment.