diff --git a/controllers/ManagerController.go b/controllers/ManagerController.go index 25c17820..8fb89254 100644 --- a/controllers/ManagerController.go +++ b/controllers/ManagerController.go @@ -19,6 +19,7 @@ import ( "github.com/lifei6671/mindoc/utils/filetil" "github.com/lifei6671/mindoc/utils/pagination" "gopkg.in/russross/blackfriday.v2" + "time" ) type ManagerController struct { @@ -29,7 +30,7 @@ func (c *ManagerController) Prepare() { c.BaseController.Prepare() if !c.Member.IsAdministrator() { - c.Abort("403") + c.ShowErrorPage(403,"用户权限不足") } } @@ -742,20 +743,66 @@ func (c *ManagerController) MemberGroupList() { } c.Data["TotalPages"] = int(math.Ceil(float64(totalCount) / float64(conf.PageSize))) - c.Data["Lists"] = memberGroupList + b, err := json.Marshal(memberGroupList) + + if err != nil { + c.Data["Result"] = template.JS("[]") + } else { + c.Data["Result"] = template.JS(string(b)) + } } + //编辑或添加用户组 func (c *ManagerController) MemberGroupEdit() { c.Prepare() c.TplName = "manager/member_group_edit.tpl" - if c.Ctx.Input.IsPost() { - + if c.Member.Role != 0 { + c.ShowErrorPage(500,"只有超级管理员才能编辑或添加用户组") } - groupId,_ := c.GetInt("group_id",0) + groupId,_ := strconv.Atoi(c.Ctx.Input.Param(":id")) memberGroup := models.NewMemberGroup() var err error + + if c.Ctx.Input.IsPost() { + groupId,_ := c.GetInt("group_id",0) + + groupName := strings.TrimSpace(c.GetString("group_name")) + if groupName == "" { + if c.Ctx.Input.IsAjax() { + c.JsonResult(6002,"用户组名称不能为空") + }else{ + c.ShowErrorPage(500,"用户组名称不能为空") + } + } + if groupId > 0 { + memberGroup,err = models.NewMemberGroup().FindFirst(groupId) + if err != nil { + beego.Error("查询用户组失败",err) + if c.Ctx.Input.IsAjax() { + c.JsonResult(6001,"未查到指定的用户组信息") + }else{ + c.ShowErrorPage(500,"用户组名称不能为空") + } + } + + memberGroup.GroupName = groupName + memberGroup.ModifyAt = c.Member.MemberId + }else{ + memberGroup.GroupName = groupName + memberGroup.CreateTime = time.Now() + memberGroup.CreateAt = c.Member.MemberId + } + if err := memberGroup.InsertOrUpdate(); err != nil { + beego.Error("保存用户组失败 =>",err) + c.JsonResult(500,"保存失败") + }else{ + c.JsonResult(0,"保存成功",memberGroup) + } + + } + if groupId > 0 { memberGroup,err = memberGroup.FindFirst(groupId) if err != nil { @@ -767,17 +814,43 @@ func (c *ManagerController) MemberGroupEdit() { } +//删除用户组 +func (c *ManagerController) MemberGroupDelete() { + c.Prepare() + + if c.Member.Role != 0 { + c.JsonResult(5001,"只有超级管理员才能删除用户组") + } + + groupId,err := c.GetInt("group_id",0) + + if err != nil { + beego.Error("获取参数失败 =>",err) + c.JsonResult(5001,"获取用户组参数失败") + } + err = models.NewMemberGroup().Delete(groupId) + if err != nil { + beego.Error("删除用户组失败 =>",err) + c.JsonResult(5001,"删除用户组失败") + } + c.JsonResult(0,"删除成功") +} + //用户组成员列表 func (c *ManagerController) MemberGroupMemberList() { c.Prepare() - c.TplName = "manager/member_group_member_list.gohtml" + c.TplName = "manager/member_group_member_list.tpl" pageIndex, _ := c.GetInt("page", 1) - groupId,_ := c.GetInt("group_id",0) + groupId,_ := strconv.Atoi(c.Ctx.Input.Param(":id")) if groupId <= 0 { c.ShowErrorPage(404,"用户组参数不能为空") } + memberGroup,err := models.NewMemberGroup().FindFirst(groupId) + if err != nil { + c.ShowErrorPage(404,"用户组不存在") + } memberGroupMemberList ,totalCount,err := models.NewMemberGroupMembers().FindToPager(pageIndex,conf.PageSize,groupId) if err != nil { @@ -791,10 +864,17 @@ func (c *ManagerController) MemberGroupMemberList() { } c.Data["TotalPages"] = int(math.Ceil(float64(totalCount) / float64(conf.PageSize))) - c.Data["Lists"] = memberGroupMemberList + b, err := json.Marshal(memberGroupMemberList) + if err != nil { + c.Data["Result"] = template.JS("[]") + } else { + c.Data["Result"] = template.JS(string(b)) + } + c.Data["Model"] = memberGroup } +//添加用户组成员 func (c *ManagerController) MemberGroupMemberEdit() { c.Prepare() } diff --git a/models/MemberGroupModel.go b/models/MemberGroupModel.go index cab6caf0..bfaf9c08 100644 --- a/models/MemberGroupModel.go +++ b/models/MemberGroupModel.go @@ -10,11 +10,15 @@ import ( type MemberGroup struct { GroupId int `orm:"column(group_id);pk;auto;unique;" json:"group_id"` GroupName string `orm:"column(group_name);size(255);" json:"group_name"` - GroupNumber int `orm:"column(group_number);" json:"group_number"` + GroupNumber int `orm:"column(group_number);default(0)" json:"group_number"` CreateTime time.Time `orm:"type(datetime);column(create_time);auto_now_add" json:"create_time"` CreateAt int `orm:"type(int);column(create_at)" json:"create_at"` + CreateName string `orm:"-" json:"create_name"` + CreateRealName string `orm:"-" json:"create_real_name"` ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now" json:"modify_time"` ModifyAt int `orm:"column(modify_at);type(int)" json:"-"` + ModifyName string `orm:"-" json:"modify_name"` + ModifyRealName string `orm:"-" json:"modify_real_name"` } @@ -45,6 +49,25 @@ func (m *MemberGroup) FindFirst(id int) (*MemberGroup,error){ beego.Error("查询用户组时出错 =>",err) return m,err } + createMember,err := NewMember().Find(m.CreateAt); + if err != nil { + beego.Error("查询用户组创建人失败 =>",err) + }else{ + + m.CreateName = createMember.Account + m.CreateRealName = createMember.RealName + } + + if m.ModifyAt > 0 { + modifyMember, err := NewMember().Find(m.ModifyAt) + if err != nil { + beego.Error("查询用户组修改人失败 =>",err) + }else{ + + m.ModifyName = modifyMember.Account + m.ModifyRealName = modifyMember.RealName + } + } return m,nil } @@ -52,12 +75,19 @@ func (m *MemberGroup) FindFirst(id int) (*MemberGroup,error){ func (m *MemberGroup) Delete(id int) error { o := orm.NewOrm() + o.Begin() _,err := o.QueryTable(m.TableNameWithPrefix()).Filter("group_id",id).Delete() if err != nil { + o.Rollback() beego.Error("删除用户组失败 =>",err) } - return err + _,err = o.QueryTable(NewMemberGroupMembers().TableNameWithPrefix()).Filter("group_id",id).Delete() + if err != nil { + o.Rollback() + beego.Error("删除用户组失败 =>",err) + } + return o.Commit() } //分页查询用户组 @@ -71,7 +101,7 @@ func (m *MemberGroup) FindByPager(pageIndex, pageSize int) ([]*MemberGroup,int,e offset := (pageIndex - 1) * pageSize var memberGroups []*MemberGroup totalCount := 0 - _,err := o.QueryTable(m.TableNameWithPrefix()).Offset(offset).Limit(pageSize).All(&memberGroups) + _,err := o.QueryTable(m.TableNameWithPrefix()).OrderBy("-group_id").Offset(offset).Limit(pageSize).All(&memberGroups) if err != nil { beego.Error("分页查询用户组失败 =>",err) @@ -83,10 +113,53 @@ func (m *MemberGroup) FindByPager(pageIndex, pageSize int) ([]*MemberGroup,int,e totalCount = int(i) } } + memberIds := make([]int,0) + + for _,memberGroup := range memberGroups { + if memberGroup.CreateAt > 0 { + memberIds = append(memberIds,memberGroup.CreateAt) + } + if memberGroup.ModifyAt > 0 { + memberIds = append(memberIds,memberGroup.ModifyAt) + } + } + + var members []*Member + + _,err = o.QueryTable(NewMember().TableNameWithPrefix()).Filter("member_id__in",memberIds).All(&members,"member_id","account","real_name") + + if err != nil { + beego.Error("查询用户组信息时出错 =>",err) + }else { + for _,memberGroup := range memberGroups { + for _,member := range members { + if memberGroup.ModifyAt == member.MemberId { + memberGroup.ModifyRealName = member.RealName + memberGroup.ModifyName = member.Account + } + if memberGroup.CreateAt == member.MemberId { + memberGroup.CreateRealName = member.RealName + memberGroup.CreateName = member.Account + } + } + } + } return memberGroups,totalCount,err } +//添加或更新用户组信息 +func (m *MemberGroup) InsertOrUpdate(cols...string) error { + o := orm.NewOrm() + var err error + if m.GroupId > 0 { + _,err = o.Update(m, cols...) + }else{ + _,err = o.Insert(m) + } + return err +} + @@ -100,5 +173,3 @@ func (m *MemberGroup) FindByPager(pageIndex, pageSize int) ([]*MemberGroup,int,e - - diff --git a/models/document.go b/models/document.go index 0174ab9d..ddc3bc72 100644 --- a/models/document.go +++ b/models/document.go @@ -92,7 +92,7 @@ func (m *Document) InsertOrUpdate(cols ...string) error { if m.Identify == "" { book := NewBook() identify := "docs" - if err := o.QueryTable(book.TableNameWithPrefix()).One(book,"identify");err == nil { + if err := o.QueryTable(book.TableNameWithPrefix()).Filter("book_id",m.BookId).One(book,"identify");err == nil { identify = book.Identify } m.Identify = fmt.Sprintf("%s-%d%d",identify,m.BookId,time.Now().Unix()) diff --git a/routers/router.go b/routers/router.go index e624346e..80bd1490 100644 --- a/routers/router.go +++ b/routers/router.go @@ -37,9 +37,11 @@ func init() { beego.Router("/manager/label/delete/:id", &controllers.ManagerController{},"post:LabelDelete") beego.Router("/manager/user_groups", &controllers.ManagerController{},"*:MemberGroupList") beego.Router("/manager/user_groups/edit/?:id", &controllers.ManagerController{},"*:MemberGroupEdit") - beego.Router("/manager/user_group_member", &controllers.ManagerController{},"*:MemberGroupMemberList") + beego.Router("/manager/user_group/delete/", &controllers.ManagerController{},"*:MemberGroupDelete") + beego.Router("/manager/user_group_member/:id", &controllers.ManagerController{},"*:MemberGroupMemberList") beego.Router("/manager/user_group_member/edit/?:id", &controllers.ManagerController{},"*:MemberGroupMemberEdit") + beego.Router("/setting", &controllers.SettingController{}, "*:Index") beego.Router("/setting/password", &controllers.SettingController{}, "*:Password") beego.Router("/setting/upload", &controllers.SettingController{}, "*:Upload") diff --git a/static/js/markdown.js b/static/js/markdown.js index fccf96d1..31692d28 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -1,4 +1,5 @@ $(function () { + window.isLoad = true; editormd.katexURL = { js : window.baseUrl + "/static/katex/katex", css : window.baseUrl + "/static/katex/katex" @@ -163,7 +164,11 @@ $(function () { window.isLoad = true; try { window.editor.clear(); - window.editor.insertValue(res.data.markdown); + if(res.data.markdown !== ""){ + window.editor.insertValue(res.data.markdown); + }else{ + window.isLoad = true; + } window.editor.setCursor({line: 0, ch: 0}); }catch(e){ console.log(e); @@ -256,6 +261,8 @@ $(function () { * @param $is_change */ function resetEditorChanged($is_change) { + // console.log($is_change); + // console.log(window.isLoad); if ($is_change && !window.isLoad) { var type = window.treeCatalog.get_type(window.selectNode); if(type === "lock"){ diff --git a/views/manager/attach_detailed.tpl b/views/manager/attach_detailed.tpl index 204974de..dcb320a1 100644 --- a/views/manager/attach_detailed.tpl +++ b/views/manager/attach_detailed.tpl @@ -26,12 +26,7 @@
diff --git a/views/manager/attach_list.tpl b/views/manager/attach_list.tpl index b97e8dd7..509d03ea 100644 --- a/views/manager/attach_list.tpl +++ b/views/manager/attach_list.tpl @@ -26,13 +26,7 @@
diff --git a/views/manager/books.tpl b/views/manager/books.tpl index 9d717d11..693c1430 100644 --- a/views/manager/books.tpl +++ b/views/manager/books.tpl @@ -26,13 +26,7 @@
diff --git a/views/manager/edit_book.tpl b/views/manager/edit_book.tpl index f7d2f4c2..1e6a3222 100644 --- a/views/manager/edit_book.tpl +++ b/views/manager/edit_book.tpl @@ -29,13 +29,7 @@
diff --git a/views/manager/edit_users.tpl b/views/manager/edit_users.tpl index 7815a65b..790f1c54 100644 --- a/views/manager/edit_users.tpl +++ b/views/manager/edit_users.tpl @@ -25,13 +25,7 @@
diff --git a/views/manager/label_list.tpl b/views/manager/label_list.tpl index dc589329..694402f5 100644 --- a/views/manager/label_list.tpl +++ b/views/manager/label_list.tpl @@ -26,14 +26,7 @@
diff --git a/views/manager/manager_widgets.tpl.tpl b/views/manager/manager_widgets.tpl.tpl index 02d10fda..14016501 100644 --- a/views/manager/manager_widgets.tpl.tpl +++ b/views/manager/manager_widgets.tpl.tpl @@ -1,8 +1,8 @@ 仪表盘 - 用户管理 - 用户组管理 - 项目管理 + 用户管理 + 用户组管理 + 项目管理 {{/*
  • 评论管理
  • */}} 配置管理 - 附件管理 + 附件管理 标签管理 diff --git a/views/manager/member_group_edit.tpl b/views/manager/member_group_edit.tpl new file mode 100644 index 00000000..ea66e458 --- /dev/null +++ b/views/manager/member_group_edit.tpl @@ -0,0 +1,89 @@ + + + + + + + + 编辑用户组 - Powered by MinDoc + + + + + + + + + + +
    +{{template "widgets/header.tpl" .}} +
    +
    +
    + +
    +
    +
    +
    + 编辑用户组 +
    +
    +
    +
    + +
    + + +
    +
    + + +
    +
    + +
    + +
    +
    +
    +
    +{{template "widgets/footer.tpl" .}} +
    + + + + + + + + + \ No newline at end of file diff --git a/views/manager/member_group_list.tpl b/views/manager/member_group_list.tpl index 8c6c0f4e..fb30ee2c 100644 --- a/views/manager/member_group_list.tpl +++ b/views/manager/member_group_list.tpl @@ -43,7 +43,7 @@
    -
    +
    @@ -65,15 +65,13 @@ ${item.group_id} ${item.group_name} ${item.group_number} - ${item.create_time} - ${item.create_at} - ${modify_time} + ${(new Date(item.create_time)).format("yyyy-MM-dd hh:mm:ss")} + ${item.create_name} + ${(new Date(item.modify_time)).format("yyyy-MM-dd hh:mm:ss")} - - 编辑 - - - + 成员 + 编辑 + @@ -90,7 +88,7 @@ {{template "widgets/footer.tpl" .}}
    - + + @@ -170,114 +129,50 @@ }).on("hidden.bs.modal",function () { $(this).find("form").html(window.addMemberDialogModalHtml); }); - $("#addMemberDialogForm").ajaxForm({ + $("#addMemberGroupDialogForm").ajaxForm({ beforeSubmit : function () { - var account = $.trim($("#account").val()); - if(account === ""){ - return showError("账号不能为空"); + var group_name = $.trim($("#group_name").val()); + if(group_name === ""){ + return showError("用户组名称不能为空"); } - var password1 = $.trim($("#password1").val()); - var password2 = $("#password2").val(); - if (password1 === "") { - return showError("密码不能为空"); - } - if (password1 !== password2) { - return showError("确认密码不正确"); - } - var email = $.trim($("#email").val()); - - if (email === "") { - return showError("邮箱不能为空"); - } - $("#btnAddMember").button("loading"); + $("#btnAddMemberGroup").button("loading"); return true; }, success : function (res) { if(res.errcode === 0){ app.lists.splice(0,0,res.data); - $("#addMemberDialogModal").modal("hide"); + $("#addMemberGroupDialogModal").modal("hide"); }else{ showError(res.message); } - $("#btnAddMember").button("reset"); + $("#btnAddMemberGroup").button("reset"); }, error : function () { showError("服务器异常"); - $("#btnAddMember").button("reset"); + $("#btnAddMemberGroup").button("reset"); } }); - var app = new Vue({ - el : "#userList", + window.app = new Vue({ + el : "#memberGroupList", data : { lists : {{.Result}} }, delimiters : ['${','}'], methods : { - setMemberStatus : function (id,status,e) { + deleteMemberGroup : function (id,status,e) { var $this = this; $.ajax({ - url : "{{urlfor "ManagerController.UpdateMemberStatus"}}", + url : "{{urlfor "ManagerController.MemberGroupDelete"}}", type : "post", - data : { "member_id":id,"status" : status}, + data : { "group_id":id }, dataType : "json", success : function (res) { if (res.errcode === 0) { for (var index in $this.lists) { var item = $this.lists[index]; - - if (item.member_id === id) { - console.log(item); - $this.lists[index].status = status; - break; - //$this.lists.splice(index,1,item); - } - } - } else { - alert("操作失败:" + res.message); - } - } - }) - - }, - setMemberRole : function (member_id, role) { - var $this = this; - $.ajax({ - url :"{{urlfor "ManagerController.ChangeMemberRole"}}", - dataType :"json", - type :"post", - data : { "member_id" : member_id,"role" : role }, - success : function (res) { - if(res.errcode === 0){ - for (var index in $this.lists) { - var item = $this.lists[index]; - - if (item.member_id === member_id) { - - $this.lists.splice(index,1,res.data); - break; - } - } - }else{ - alert("操作失败:" + res.message); - } - } - }) - }, - deleteMember : function (id, e) { - var $this = this; - $.ajax({ - url : "{{urlfor "ManagerController.DeleteMember"}}", - type : "post", - data : { "id":id }, - dataType : "json", - success : function (res) { - if (res.errcode === 0) { - - for (var index in $this.lists) { - var item = $this.lists[index]; - if (item.member_id == id) { + if (item.group_id == id) { console.log(item); $this.lists.splice(index,1); break; @@ -288,7 +183,6 @@ } } }); - } } }); diff --git a/views/manager/member_group_member_list.tpl b/views/manager/member_group_member_list.tpl new file mode 100644 index 00000000..011dd53e --- /dev/null +++ b/views/manager/member_group_member_list.tpl @@ -0,0 +1,341 @@ + + + + + + + + {{.Model.GroupName}} - 用户组成员管理 - Powered by MinDoc + + + + + + + + + + + + +
    +{{template "widgets/header.tpl" .}} +
    +
    +
    + + +
    +
    +
    +
    + {{.Model.GroupName}} - 用户组成员管理 + {{if eq .Member.Role 0}} + + {{end}} +
    +
    +
    +
    + + + +
    +
    +
    +
    +
    +{{template "widgets/footer.tpl" .}} +
    + + + + + + + + + + \ No newline at end of file diff --git a/views/manager/setting.tpl b/views/manager/setting.tpl index 46d82a80..21f90ed6 100644 --- a/views/manager/setting.tpl +++ b/views/manager/setting.tpl @@ -25,14 +25,7 @@
    diff --git a/views/manager/users.tpl b/views/manager/users.tpl index 32eb54de..0739adc2 100644 --- a/views/manager/users.tpl +++ b/views/manager/users.tpl @@ -29,14 +29,7 @@
    @@ -254,7 +247,7 @@ } }); - var app = new Vue({ + window.app = new Vue({ el : "#userList", data : { lists : {{.Result}}