From cb70c350370dbf8e8bf32d9cd9b02cc53e2aed1e Mon Sep 17 00:00:00 2001 From: shiqstone Date: Wed, 21 Apr 2021 12:22:34 +0800 Subject: [PATCH] refactor, fix bug and update i18n(management), to be continue --- conf/lang/en-us.ini | 118 ++++++++++++++++++++- conf/lang/zh-cn.ini | 116 +++++++++++++++++++- controllers/BaseController.go | 12 ++- controllers/ManagerController.go | 163 +++++++++++++---------------- models/TeamMember.go | 17 ++- views/manager/attach_detailed.tpl | 48 ++++----- views/manager/attach_list.tpl | 26 ++--- views/manager/books.tpl | 40 +++---- views/manager/config.tpl | 8 +- views/manager/edit_book.tpl | 142 ++++++++++++------------- views/manager/edit_users.tpl | 46 ++++---- views/manager/index.tpl | 16 +-- views/manager/itemsets.tpl | 76 +++++++------- views/manager/label_list.tpl | 20 ++-- views/manager/setting.tpl | 50 ++++----- views/manager/team.tpl | 56 +++++----- views/manager/team_book_list.tpl | 34 +++--- views/manager/team_member_list.tpl | 50 ++++----- views/manager/users.tpl | 94 ++++++++--------- views/manager/widgets.tpl | 20 ++-- 20 files changed, 690 insertions(+), 462 deletions(-) diff --git a/conf/lang/en-us.ini b/conf/lang/en-us.ini index 9727a633..3f700021 100644 --- a/conf/lang/en-us.ini +++ b/conf/lang/en-us.ini @@ -29,6 +29,8 @@ confirm_password = Confirm password new_account = Create New Account setting = Setting save = Save +edit = Edit +delete = Delete cancel = Cancel create = Create confirm_delete = Confirm @@ -42,6 +44,14 @@ administrator = Administrator editor = Editor observer = Observer back = Back +detail = Detail +admin_right = Reading, writing and management +editor_right = Reading and writing +observer_right = Reading only +yes = yes +no = no +read = Read +generate = Generate [message] tips = Tips @@ -190,10 +200,22 @@ origin_pwd_empty = The origin password cannot be empty new_pwd_empty = The new password cannot be empty confirm_pwd_empty = The confirm password cannot be empty pwd_length = Password must be between 6-18 characters +pwd_length_tips = Password must be between 6-50 characters wrong_origin_pwd = The origin password incorrect wrong_confirm_pwd = The confirm passwrod incorrect same_pwd = The new password must different from the origin pwd_encrypt_failed = Password encryption failed +team_name_empty = Team name cannot be emtpy +proj_empty = Project cannot be empty +site_name_empty = Site name cannot be empty +proj_space_name_empty = Project space name cannot be empty +proj_space_id_empty = Project space id cannot be empty +proj_space_id_tips = The project space id can only consist of letters and numbers and be between 2-100 characters +project_order_desc = Number only, sort from largest to smallest +project_label_desc = Allows up to 10 labels, use ";" to separate multiple tags +cannot_change_own_status = Cannot change own status +cannot_change_super_status = Cannot change super administrator status +cannot_change_super_priv = Cannot change super administrator permissions [blog] author = Author @@ -246,7 +268,10 @@ make_private = Into Privete history_record_amount = Number of history records corp_id = corp name text_editor = editor +project_label = Project Label +project_order = Project Order access_pass = Access Password +access_token = Access Token auto_publish = Auto publish enable_export = Enable Export enable_share = Enable Share @@ -429,7 +454,7 @@ no_result = No search result first = first last = last prev = prev -next = +next = next [uc] user_center = User Center @@ -444,6 +469,95 @@ description = Description description_tips = Description cannot exceed 500 characters avatar = Avatar change_avatar = Change avatar +password = Password origin_pwd = Origin password new_pwd = New password -confirm_pwd = Confirm password \ No newline at end of file +confirm_pwd = Confirm password +role = Role +type = Type +status = Status +super_admin = Super administrator +admin = Administrator +user = User +normal = Normal +disable = Disable +enable = Enable +create_user = Create User +edit_user = Edit User +pwd_tips = Please leave it blank if you do not change the password, only local users can change the password + +[mgr] +dashboard_menu = Dashboard +user_menu = User +team_menu = Team +project_menu = Project +project_space_menu = Project Space +comment_menu = Comment +config_menu = Configure +attachment_menu = Attachment +label_menu = Label +dashboard_mgr = Dashboard +user_mgr = User Management +team_mgr = Team Management +project_mgr = Project Management +project_space_mgr = Project Space Management +comment_mgr = Comment Management +config_mgr = Configure Management +config_file = Configure File +attachment_mgr = Attachment Management +label_mgr = Label Management +label_name = Label name +used_quantity = Used Quantity +proj_amount = Number Of Project +blog_amount = Number Of Blog +member_amount = Number Of Member +comment_amount = Number Of Comment +attachment_amount = Number Of Attachment +member_mgr = Member Management +add_member = Add Member +create_team = Create Team +team_name = Team Name +proj = Project +member = Member +edit_team = Edit Team +team_member_mgr = Team Member Management +team_proj = Team Project +add_proj = Add Project +proj_name = Project name +proj_author = Project author +join_time = Join Time +join_proj = Join +file_name = File name +is_exist = Is Exist +exist = Exist +deleted = Deleted +proj_blog_name = Project/Blog name +doc_name = Document name +file_path = File path +download_url = Download URL +file_size = File size +upload_time = Upload time +download = Download +download_title = Download to local +attachment_name = Attachment name +site_name = Site Name +domain_icp = Domain ICP +site_desc = Site Description +site_desc_tips = Description cannot exceed 500 characters +enable_anonymous_access = Enable anonymous access +enable = Enable +disable = Disable +enable_register = Enable Registration +enable_captcha = Enable Captcha +enable_doc_his = Enable Document Historic +proj_space_name = Project space name +proj_space_id = Project space ID +create_proj_space = Create Project Space +edit_proj_space = Edit Project Space +proj_list = Project List +edit_proj = Edit Project +create_time = Create Time +creator = Creator +doc_amount = Number of Document +last_edit = Last Edit +delete_project = Delete Project \ No newline at end of file diff --git a/conf/lang/zh-cn.ini b/conf/lang/zh-cn.ini index bc09fc90..9f16be0c 100644 --- a/conf/lang/zh-cn.ini +++ b/conf/lang/zh-cn.ini @@ -29,6 +29,8 @@ confirm_password = 确认密码 new_account = 用户注册 setting = 设置 save = 保存 +edit = 编辑 +delete = 删除 cancel = 取消 create = 创建 confirm_delete = 确定删除 @@ -42,6 +44,14 @@ administrator = 管理员 editor = 编辑者 observer = 观察者 back = 返回 +detail = 详情 +admin_right = 拥有阅读、写作和管理权限 +editor_right = 拥有阅读和写作权限 +observer_right = 拥有阅读权限 +yes = 是 +no = 否 +read = 阅读 +generate = 生成 [message] tips = 友情提示 @@ -190,10 +200,22 @@ origin_pwd_empty = 原密码不能为空 new_pwd_empty = 新密码不能为空 confirm_pwd_empty = 确认密码不能为空 pwd_length = 密码必须在6-18字之间 +pwd_length_tips = 密码必须在6-50个字符之间 wrong_origin_pwd = 原始密码不正确 wrong_confirm_pwd = 确认密码不正确 same_pwd = 新密码不能和原始密码相同 pwd_encrypt_failed = 密码加密失败 +team_name_empty = 团队名称不能为空 +proj_empty = 项目不能为空 +site_name_empty = 网站标题不能为空 +proj_space_name_empty = 项目空间名称不能为空 +proj_space_id_empty = 项目空间标识不能为空 +proj_space_id_tips = 项目空间标识只能由字母和数字组成且在2-100字符之间 +project_order_desc = 只能是数字,序号越大排序越靠前 +project_label_desc = 最多允许添加10个标签,多个标签请用“;”分割 +cannot_change_own_status = 不能变更自己的状态 +cannot_change_super_status = 不能变更超级管理员的状态 +cannot_change_super_priv = 不能变更超级管理员的权限 [blog] author = 作者 @@ -246,7 +268,10 @@ make_private = 转为私有 history_record_amount = 历史记录数量 corp_id = 公司名称 text_editor = 编辑器 +project_label = 项目标签 +project_order = 项目排序 access_pass = 访问密码 +access_token = 访问令牌 auto_publish = 自动发布 enable_export = 开启导出 enable_share = 开启分享 @@ -444,6 +469,95 @@ description = 描述 description_tips = 描述不能超过500字 avatar = 头像 change_avatar = 修改头像 +password = 密码 origin_pwd = 原始密码 new_pwd = 新密码 -confirm_pwd = 确认密码 \ No newline at end of file +confirm_pwd = 确认密码 +role = 角色 +type = 类型 +status = 状态 +super_admin = 超级管理员 +admin = 管理员 +user = 普通用户 +normal = 正常 +disable = 禁用 +enable = 启用 +create_user = 创建用户 +edit_user = 编辑用户 +pwd_tips = 不修改密码请留空,只支持本地用户修改密码 + +[mgr] +dashboard_menu = 仪表盘 +user_menu = 用户管理 +team_menu = 团队管理 +project_menu = 项目管理 +project_space_menu = 项目空间管理 +comment_menu = 评论管理 +config_menu = 配置管理 +attachment_menu = 附件管理 +label_menu = 标签管理 +dashboard_mgr = 仪表盘 +user_mgr = 用户管理 +team_mgr = 团队管理 +project_mgr = 项目管理 +project_space_mgr = 项目空间管理 +comment_mgr = 评论管理 +config_mgr = 配置管理 +config_file = 配置文件 +attachment_mgr = 附件管理 +label_mgr = 标签管理 +label_name = 标签名称 +used_quantity = 使用数量 +proj_amount = 项目数量 +blog_amount = 文章数量 +member_amount = 成员数量 +comment_amount = 评论数量 +attachment_amount = 附件数量 +member_mgr = 成员管理 +add_member = 添加成员 +create_team = 创建团队 +team_name = 团队名称 +proj = 项目 +member = 成员 +edit_team = 编辑团队 +team_member_mgr = 团队用户管理 +team_proj = 团队项目 +add_proj = 添加项目 +proj_name = 项目名称 +proj_author = 项目作者 +join_time = 加入时间 +join_proj = 加入项目 +file_name = 文件名称 +is_exist = 是否存在 +exist = 存在 +deleted = 已删除 +proj_blog_name = 项目/文章名称 +doc_name = 文档名称 +file_path = 文件路径 +download_url = 下载路径 +file_size = 文件大小 +upload_time = 上传时间 +download = 下载 +download_title = 下载到本地 +attachment_name = 附件名称 +site_name = 网站标题 +domain_icp = 域名备案 +site_desc = 网站描述 +site_desc_tips = 描述信息不超过500个字符 +enable_anonymous_access = 启用匿名访问 +enable = 开启 +disable = 关闭 +enable_register = 启用注册 +enable_captcha = 启用验证码 +enable_doc_his = 启用文档历史 +proj_space_name = 项目空间名称 +proj_space_id = 项目空间标识 +create_proj_space = 创建项目空间 +edit_proj_space = 编辑项目空间 +proj_list = 项目列表 +edit_proj = 编辑项目 +create_time = 创建时间 +creator = 创建者 +doc_amount = 文档数量 +last_edit = 最后编辑 +delete_project = 删除项目 \ No newline at end of file diff --git a/controllers/BaseController.go b/controllers/BaseController.go index 82ae8332..706acea7 100644 --- a/controllers/BaseController.go +++ b/controllers/BaseController.go @@ -3,19 +3,21 @@ package controllers import ( "bytes" "encoding/json" - "github.com/astaxie/beego/logs" - "github.com/beego/i18n" "io" "strings" "time" + "github.com/astaxie/beego/logs" + "github.com/beego/i18n" + + "html/template" + "io/ioutil" + "path/filepath" + "github.com/astaxie/beego" "github.com/mindoc-org/mindoc/conf" "github.com/mindoc-org/mindoc/models" "github.com/mindoc-org/mindoc/utils" - "html/template" - "io/ioutil" - "path/filepath" ) type BaseController struct { diff --git a/controllers/ManagerController.go b/controllers/ManagerController.go index a11f9689..907630e6 100644 --- a/controllers/ManagerController.go +++ b/controllers/ManagerController.go @@ -16,6 +16,7 @@ import ( "github.com/astaxie/beego" "github.com/astaxie/beego/logs" "github.com/astaxie/beego/orm" + "github.com/beego/i18n" "github.com/mindoc-org/mindoc/conf" "github.com/mindoc-org/mindoc/models" "github.com/mindoc-org/mindoc/utils" @@ -40,17 +41,17 @@ func (c *ManagerController) Index() { c.TplName = "manager/index.tpl" c.Data["Model"] = models.NewDashboard().Query() + c.Data["Action"] = "index" } // 用户列表. func (c *ManagerController) Users() { c.Prepare() c.TplName = "manager/users.tpl" - + c.Data["Action"] = "users" pageIndex, _ := c.GetInt("page", 0) members, totalCount, err := models.NewMember().FindToPager(pageIndex, conf.PageSize) - if err != nil { c.Data["ErrorMessage"] = err.Error() return @@ -68,7 +69,6 @@ func (c *ManagerController) Users() { } b, err := json.Marshal(members) - if err != nil { c.Data["Result"] = template.JS("[]") } else { @@ -89,16 +89,16 @@ func (c *ManagerController) CreateMember() { status, _ := c.GetInt("status", 0) if ok, err := regexp.MatchString(conf.RegexpAccount, account); account == "" || !ok || err != nil { - c.JsonResult(6001, "账号只能由英文字母数字组成,且在3-50个字符") + c.JsonResult(6001, i18n.Tr(c.Lang, "message.username_invalid_format")) } if l := strings.Count(password1, ""); password1 == "" || l > 50 || l < 6 { - c.JsonResult(6002, "密码必须在6-50个字符之间") + c.JsonResult(6002, i18n.Tr(c.Lang, "message.pwd_length_tips")) } if password1 != password2 { - c.JsonResult(6003, "确认密码不正确") + c.JsonResult(6003, i18n.Tr(c.Lang, "message.wrong_confirm_pwd")) } if ok, err := regexp.MatchString(conf.RegexpEmail, email); !ok || err != nil || email == "" { - c.JsonResult(6004, "邮箱格式不正确") + c.JsonResult(6004, i18n.Tr(c.Lang, "message.email_invalid_format")) } if role != 0 && role != 1 && role != 2 { role = 1 @@ -110,7 +110,7 @@ func (c *ManagerController) CreateMember() { member := models.NewMember() if _, err := member.FindByAccount(account); err == nil && member.MemberId > 0 { - c.JsonResult(6005, "账号已存在") + c.JsonResult(6005, i18n.Tr(c.Lang, "message.account_existed")) } member.Account = account @@ -139,7 +139,7 @@ func (c *ManagerController) UpdateMemberStatus() { status, _ := c.GetInt("status", 0) if member_id <= 0 { - c.JsonResult(6001, "参数错误") + c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error")) } if status != 0 && status != 1 { status = 0 @@ -147,19 +147,19 @@ func (c *ManagerController) UpdateMemberStatus() { member := models.NewMember() if _, err := member.Find(member_id); err != nil { - c.JsonResult(6002, "用户不存在") + c.JsonResult(6002, i18n.Tr(c.Lang, "message.user_not_existed")) } if member.MemberId == c.Member.MemberId { - c.JsonResult(6004, "不能变更自己的状态") + c.JsonResult(6004, i18n.Tr(c.Lang, "message.cannot_change_own_status")) } if member.Role == conf.MemberSuperRole { - c.JsonResult(6005, "不能变更超级管理员的状态") + c.JsonResult(6005, i18n.Tr(c.Lang, "message.cannot_change_super_status")) } member.Status = status if err := member.Update(); err != nil { logs.Error("", err) - c.JsonResult(6003, "用户状态设置失败") + c.JsonResult(6003, i18n.Tr(c.Lang, "message.failed")) } c.JsonResult(0, "ok", member) } @@ -171,26 +171,26 @@ func (c *ManagerController) ChangeMemberRole() { memberId, _ := c.GetInt("member_id", 0) role, _ := c.GetInt("role", 0) if memberId <= 0 { - c.JsonResult(6001, "参数错误") + c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error")) } if role != int(conf.MemberAdminRole) && role != int(conf.MemberGeneralRole) { - c.JsonResult(6001, "用户权限不正确") + c.JsonResult(6001, i18n.Tr(c.Lang, "message.no_permission")) } member := models.NewMember() if _, err := member.Find(memberId); err != nil { - c.JsonResult(6002, "用户不存在") + c.JsonResult(6002, i18n.Tr(c.Lang, "message.user_not_existed")) } if member.MemberId == c.Member.MemberId { - c.JsonResult(6004, "不能变更自己的权限") + c.JsonResult(6004, i18n.Tr(c.Lang, "message.cannot_change_own_priv")) } if member.Role == conf.MemberSuperRole { - c.JsonResult(6005, "不能变更超级管理员的权限") + c.JsonResult(6005, i18n.Tr(c.Lang, "message.cannot_change_super_priv")) } member.Role = conf.SystemRole(role) if err := member.Update(); err != nil { - c.JsonResult(6003, "用户权限设置失败") + c.JsonResult(6003, i18n.Tr(c.Lang, "message.failed")) } member.Lang = c.Lang member.ResolveRoleName() @@ -201,7 +201,7 @@ func (c *ManagerController) ChangeMemberRole() { func (c *ManagerController) EditMember() { c.Prepare() c.TplName = "manager/edit_users.tpl" - + c.Data["Action"] = "users" member_id, _ := c.GetInt(":id", 0) if member_id <= 0 { @@ -209,7 +209,6 @@ func (c *ManagerController) EditMember() { } member, err := models.NewMember().Find(member_id) - if err != nil { logs.Error(err) c.Abort("404") @@ -225,7 +224,7 @@ func (c *ManagerController) EditMember() { member.Description = description member.RealName = c.GetString("real_name") if password1 != "" && password2 != password1 { - c.JsonResult(6001, "确认密码不正确") + c.JsonResult(6001, i18n.Tr(c.Lang, "message.wrong_confirm_pwd")) } if password1 != "" && member.AuthMethod != conf.AuthMethodLDAP { member.Password = password1 @@ -237,7 +236,7 @@ func (c *ManagerController) EditMember() { password, err := utils.PasswordHash(password1) if err != nil { logs.Error(err) - c.JsonResult(6003, "对用户密码加密时出错") + c.JsonResult(6003, i18n.Tr(c.Lang, "message.pwd_encrypt_failed")) } member.Password = password } @@ -256,30 +255,28 @@ func (c *ManagerController) DeleteMember() { member_id, _ := c.GetInt("id", 0) if member_id <= 0 { - c.JsonResult(404, "参数错误") + c.JsonResult(404, i18n.Tr(c.Lang, "message.param_error")) } member, err := models.NewMember().Find(member_id) - if err != nil { logs.Error(err) - c.JsonResult(500, "用户不存在") + c.JsonResult(500, i18n.Tr(c.Lang, "message.user_not_existed")) } if member.Role == conf.MemberSuperRole { c.JsonResult(500, "不能删除超级管理员") } - superMember, err := models.NewMember().FindByFieldFirst("role", 0) + superMember, err := models.NewMember().FindByFieldFirst("role", 0) if err != nil { logs.Error(err) c.JsonResult(5001, "未能找到超级管理员") } err = models.NewMember().Delete(member_id, superMember.MemberId) - if err != nil { logs.Error(err) - c.JsonResult(5002, "删除失败") + c.JsonResult(5002, i18n.Tr(c.Lang, "message.failed")) } c.JsonResult(0, "ok") } @@ -288,7 +285,7 @@ func (c *ManagerController) DeleteMember() { func (c *ManagerController) Books() { c.Prepare() c.TplName = "manager/books.tpl" - + c.Data["Action"] = "books" pageIndex, _ := c.GetInt("page", 1) books, totalCount, err := models.NewBookResult().FindToPager(pageIndex, conf.PageSize) @@ -319,7 +316,7 @@ func (c *ManagerController) EditBook() { c.Prepare() c.TplName = "manager/edit_book.tpl" - + c.Data["Action"] = "books" identify := c.GetString(":key") if identify == "" { @@ -329,8 +326,8 @@ func (c *ManagerController) EditBook() { if err != nil { c.Abort("500") } - if c.Ctx.Input.IsPost() { + if c.Ctx.Input.IsPost() { bookName := strings.TrimSpace(c.GetString("book_name")) description := strings.TrimSpace(c.GetString("description", "")) commentStatus := c.GetString("comment_status") @@ -345,7 +342,7 @@ func (c *ManagerController) EditBook() { itemId, _ := c.GetInt("itemId") if strings.Count(description, "") > 500 { - c.JsonResult(6004, "项目描述不能大于500字") + c.JsonResult(6004, i18n.Tr(c.Lang, "message.project_desc_tips")) } if commentStatus != "open" && commentStatus != "closed" && commentStatus != "group_only" && commentStatus != "registered_only" { commentStatus = "closed" @@ -357,7 +354,7 @@ func (c *ManagerController) EditBook() { } } if !models.NewItemsets().Exist(itemId) { - c.JsonResult(6006, "项目空间不存在") + c.JsonResult(6006, i18n.Tr(c.Lang, "message.project_space_not_exist")) } book.Publisher = publisher book.HistoryCount = historyCount @@ -391,7 +388,7 @@ func (c *ManagerController) EditBook() { } if err := book.Update(); err != nil { - c.JsonResult(6006, "保存失败") + c.JsonResult(6006, i18n.Tr(c.Lang, "message.failed")) } c.JsonResult(0, "ok") } @@ -411,18 +408,18 @@ func (c *ManagerController) DeleteBook() { bookId, _ := c.GetInt("book_id", 0) if bookId <= 0 { - c.JsonResult(6001, "参数错误") + c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error")) } book := models.NewBook() err := book.ThoroughDeleteBook(bookId) if err == orm.ErrNoRows { - c.JsonResult(6002, "项目不存在") + c.JsonResult(6002, i18n.Tr(c.Lang, "message.item_not_exist")) } if err != nil { logs.Error("删除失败 -> ", err) - c.JsonResult(6003, "删除失败") + c.JsonResult(6003, i18n.Tr(c.Lang, "message.failed")) } c.JsonResult(0, "ok") } @@ -437,7 +434,7 @@ func (c *ManagerController) CreateToken() { book, err := models.NewBook().FindByFieldFirst("identify", identify) if err != nil { - c.JsonResult(6001, "项目不存在") + c.JsonResult(6001, i18n.Tr(c.Lang, "message.item_not_exist")) } if action == "create" { @@ -448,14 +445,14 @@ func (c *ManagerController) CreateToken() { book.PrivateToken = string(utils.Krand(conf.GetTokenSize(), utils.KC_RAND_KIND_ALL)) if err := book.Update(); err != nil { logs.Error("生成阅读令牌失败 => ", err) - c.JsonResult(6003, "生成阅读令牌失败") + c.JsonResult(6003, i18n.Tr(c.Lang, "message.failed")) } c.JsonResult(0, "ok", conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken)) } else { book.PrivateToken = "" if err := book.Update(); err != nil { logs.Error("CreateToken => ", err) - c.JsonResult(6004, "删除令牌失败") + c.JsonResult(6004, i18n.Tr(c.Lang, "message.failed")) } c.JsonResult(0, "ok", "") } @@ -465,7 +462,7 @@ func (c *ManagerController) CreateToken() { func (c *ManagerController) Setting() { c.Prepare() c.TplName = "manager/setting.tpl" - + c.Data["Action"] = "setting" options, err := models.NewOption().All() if c.Ctx.Input.IsPost() { @@ -484,7 +481,6 @@ func (c *ManagerController) Setting() { for _, item := range options { c.Data[item.OptionName] = item.OptionValue } - } // Transfer 转让项目. @@ -493,16 +489,16 @@ func (c *ManagerController) Transfer() { account := c.GetString("account") if account == "" { - c.JsonResult(6004, "接受者账号不能为空") + c.JsonResult(6004, i18n.Tr(c.Lang, "message.receive_account_empty")) } member, err := models.NewMember().FindByAccount(account) if err != nil { logs.Error("FindByAccount => ", err) - c.JsonResult(6005, "接受用户不存在") + c.JsonResult(6005, i18n.Tr(c.Lang, "message.receive_account_not_exist")) } if member.Status != 0 { - c.JsonResult(6006, "接受用户已被禁用") + c.JsonResult(6006, i18n.Tr(c.Lang, "message.receive_account_disabled")) } if !c.Member.IsAdministrator() { @@ -550,7 +546,7 @@ func (c *ManagerController) DeleteComment() { comment_id, _ := c.GetInt("comment_id", 0) if comment_id <= 0 { - c.JsonResult(6001, "参数错误") + c.JsonResult(6001, i18n.Tr(c.Lang, "message.param_error")) } comment := models.NewComment() @@ -574,7 +570,7 @@ func (c *ManagerController) PrivatelyOwned() { identify := c.GetString("identify") if status != "open" && status != "close" { - c.JsonResult(6003, "参数错误") + c.JsonResult(6003, i18n.Tr(c.Lang, "message.param_error")) } state := 0 if status == "open" { @@ -600,7 +596,7 @@ func (c *ManagerController) PrivatelyOwned() { if err != nil { logs.Error("PrivatelyOwned => ", err) - c.JsonResult(6004, "保存失败") + c.JsonResult(6004, i18n.Tr(c.Lang, "message.failed")) } c.JsonResult(0, "ok") } @@ -609,6 +605,7 @@ func (c *ManagerController) PrivatelyOwned() { func (c *ManagerController) AttachList() { c.Prepare() c.TplName = "manager/attach_list.tpl" + c.Data["Action"] = "attach" pageIndex, _ := c.GetInt("page", 1) @@ -639,14 +636,14 @@ func (c *ManagerController) AttachList() { func (c *ManagerController) AttachDetailed() { c.Prepare() c.TplName = "manager/attach_detailed.tpl" - attach_id, _ := strconv.Atoi(c.Ctx.Input.Param(":id")) + c.Data["Action"] = "attach" + attach_id, _ := strconv.Atoi(c.Ctx.Input.Param(":id")) if attach_id <= 0 { c.Abort("404") } attach, err := models.NewAttachmentResult().Find(attach_id) - if err != nil { logs.Error("AttachDetailed => ", err) if err == orm.ErrNoRows { @@ -691,11 +688,10 @@ func (c *ManagerController) AttachDelete() { func (c *ManagerController) LabelList() { c.Prepare() c.TplName = "manager/label_list.tpl" - + c.Data["Action"] = "label" pageIndex, _ := c.GetInt("page", 1) labels, totalCount, err := models.NewLabel().FindToPager(pageIndex, conf.PageSize) - if err != nil { c.ShowErrorPage(50001, err.Error()) } @@ -713,13 +709,12 @@ func (c *ManagerController) LabelList() { //删除标签 func (c *ManagerController) LabelDelete() { labelId, err := strconv.Atoi(c.Ctx.Input.Param(":id")) - if err != nil { logs.Error("获取删除标签参数时出错:", err) - c.JsonResult(50001, "参数错误") + c.JsonResult(50001, i18n.Tr(c.Lang, "message.param_error")) } if labelId <= 0 { - c.JsonResult(50001, "参数错误") + c.JsonResult(50001, i18n.Tr(c.Lang, "message.param_error")) } label, err := models.NewLabel().FindFirst("label_id", labelId) @@ -737,6 +732,7 @@ func (c *ManagerController) LabelDelete() { func (c *ManagerController) Config() { c.Prepare() c.TplName = "manager/config.tpl" + c.Data["Action"] = "config" if c.Ctx.Input.IsPost() { content := strings.TrimSpace(c.GetString("configFileTextArea")) if content == "" { @@ -774,11 +770,10 @@ func (c *ManagerController) Config() { func (c *ManagerController) Team() { c.Prepare() c.TplName = "manager/team.tpl" - + c.Data["Action"] = "team" pageIndex, _ := c.GetInt("page", 0) teams, totalCount, err := models.NewTeam().FindToPager(pageIndex, conf.PageSize) - if err != nil && err != orm.ErrNoRows { c.ShowErrorPage(500, err.Error()) } @@ -796,7 +791,6 @@ func (c *ManagerController) Team() { } b, err := json.Marshal(teams) - if err != nil { c.Data["Result"] = template.JS("[]") } else { @@ -810,7 +804,7 @@ func (c *ManagerController) TeamCreate() { teamName := c.GetString("teamName") if teamName == "" { - c.JsonResult(5001, "团队名称不能为空") + c.JsonResult(5001, i18n.Tr(c.Lang, "message.team_name_empty")) } team := models.NewTeam() @@ -831,10 +825,10 @@ func (c *ManagerController) TeamEdit() { teamId, _ := c.GetInt("teamId") if teamName == "" { - c.JsonResult(5001, "团队名称不能为空") + c.JsonResult(5001, i18n.Tr(c.Lang, "message.team_name_empty")) } if teamId <= 0 { - c.JsonResult(5002, "团队标识不能为空") + c.JsonResult(5002, i18n.Tr(c.Lang, "message.team_id_empty")) } team, err := models.NewTeam().First(teamId) @@ -847,19 +841,16 @@ func (c *ManagerController) TeamEdit() { c.CheckJsonError(5004, err) c.JsonResult(0, "OK", team) - } func (c *ManagerController) TeamDelete() { c.Prepare() teamId, _ := c.GetInt("teamId") - if teamId <= 0 { - c.JsonResult(5002, "团队标识不能为空") + c.JsonResult(5002, i18n.Tr(c.Lang, "message.team_id_empty")) } err := models.NewTeam().Delete(teamId) - c.CheckJsonError(5001, err) c.JsonResult(0, "OK") @@ -868,23 +859,21 @@ func (c *ManagerController) TeamDelete() { func (c *ManagerController) TeamMemberList() { c.Prepare() c.TplName = "manager/team_member_list.tpl" + c.Data["Action"] = "team" teamId, _ := strconv.Atoi(c.Ctx.Input.Param(":id")) + if teamId <= 0 { + c.ShowErrorPage(500, i18n.Tr(c.Lang, "message.param_error")) + } pageIndex, _ := c.GetInt("page", 0) - if teamId <= 0 { - c.ShowErrorPage(500, "参数错误") - } - team, err := models.NewTeam().First(teamId) - if err == orm.ErrNoRows { c.ShowErrorPage(404, "团队不存在") } c.CheckErrorResult(500, err) c.Data["Model"] = team - teams, totalCount, err := models.NewTeamMember().FindToPager(teamId, pageIndex, conf.PageSize) - + teams, totalCount, err := models.NewTeamMember().SetLang(c.Lang).FindToPager(teamId, pageIndex, conf.PageSize) if err != nil && err != orm.ErrNoRows { c.ShowErrorPage(500, err.Error()) } @@ -902,7 +891,6 @@ func (c *ManagerController) TeamMemberList() { } b, err := json.Marshal(teams) - if err != nil { logs.Error("编码 JSON 结果失败 ->", err) c.Data["Result"] = template.JS("[]") @@ -919,7 +907,7 @@ func (c *ManagerController) TeamSearchMember() { keyword := strings.TrimSpace(c.GetString("q")) if teamId <= 0 { - c.JsonResult(500, "参数错误") + c.JsonResult(500, i18n.Tr(c.Lang, "message.param_error")) } searchResult, err := models.NewTeamMember().FindNotJoinMemberByAccount(teamId, keyword, 10) @@ -937,7 +925,7 @@ func (c *ManagerController) TeamMemberAdd() { roleId, _ := c.GetInt("roleId") if teamId <= 0 || memberId <= 0 || roleId <= 0 || roleId > int(conf.BookObserver) { - c.JsonResult(5001, "参数不正确") + c.JsonResult(5001, i18n.Tr(c.Lang, "message.system_error")) } teamMember := models.NewTeamMember() @@ -966,7 +954,7 @@ func (c *ManagerController) TeamMemberDelete() { } err = teamMember.Delete(teamMember.TeamMemberId) if err != nil { - c.JsonResult(5002, "删除失败") + c.JsonResult(5002, i18n.Tr(c.Lang, "message.failed")) } c.JsonResult(0, "ok") } @@ -977,7 +965,7 @@ func (c *ManagerController) TeamChangeMemberRole() { roleId, _ := c.GetInt("roleId") teamId, _ := c.GetInt("teamId") if memberId <= 0 || roleId <= 0 || teamId <= 0 || roleId > int(conf.BookObserver) { - c.JsonResult(5001, "参数错误") + c.JsonResult(5001, i18n.Tr(c.Lang, "message.param_error")) } teamMember, err := models.NewTeamMember().ChangeRoleId(teamId, memberId, conf.BookRole(roleId)) @@ -994,12 +982,12 @@ func (c *ManagerController) TeamChangeMemberRole() { func (c *ManagerController) TeamBookList() { c.Prepare() c.TplName = "manager/team_book_list.tpl" - + c.Data["Action"] = "team" teamId, _ := strconv.Atoi(c.Ctx.Input.Param(":id")) pageIndex, _ := c.GetInt("page", 0) if teamId <= 0 { - c.JsonResult(5002, "团队标识不能为空") + c.JsonResult(5002, i18n.Tr(c.Lang, "message.team_id_empty")) } team, err := models.NewTeam().First(teamId) @@ -1029,7 +1017,6 @@ func (c *ManagerController) TeamBookList() { } b, err := json.Marshal(teams) - if err != nil { logs.Error("编码 JSON 结果失败 ->", err) c.Data["Result"] = template.JS("[]") @@ -1046,7 +1033,7 @@ func (c *ManagerController) TeamBookAdd() { bookId, _ := c.GetInt("bookId") if teamId <= 0 || bookId <= 0 { - c.JsonResult(500, "参数错误") + c.JsonResult(500, i18n.Tr(c.Lang, "message.param_error")) } teamRel := models.NewTeamRelationship() teamRel.BookId = bookId @@ -1070,7 +1057,7 @@ func (c *ManagerController) TeamSearchBook() { keyword := strings.TrimSpace(c.GetString("q")) if teamId <= 0 { - c.JsonResult(500, "参数错误") + c.JsonResult(500, i18n.Tr(c.Lang, "message.param_error")) } searchResult, err := models.NewTeamRelationship().FindNotJoinBookByName(teamId, keyword, 10) @@ -1088,13 +1075,13 @@ func (c *ManagerController) TeamBookDelete() { teamRelationshipId, _ := c.GetInt("teamRelId") if teamRelationshipId <= 0 { - c.JsonResult(500, "参数错误") + c.JsonResult(500, i18n.Tr(c.Lang, "message.param_error")) } err := models.NewTeamRelationship().Delete(teamRelationshipId) if err != nil { - c.JsonResult(5001, "删除失败") + c.JsonResult(5001, i18n.Tr(c.Lang, "message.failed")) } c.JsonResult(0, "OK") } @@ -1103,6 +1090,7 @@ func (c *ManagerController) TeamBookDelete() { func (c *ManagerController) Itemsets() { c.Prepare() c.TplName = "manager/itemsets.tpl" + c.Data["Action"] = "itemsets" pageIndex, _ := c.GetInt("page", 0) items, totalCount, err := models.NewItemsets().FindToPager(pageIndex, conf.PageSize) @@ -1124,7 +1112,6 @@ func (c *ManagerController) Itemsets() { } c.Data["Lists"] = items - } //编辑或添加项目空间. @@ -1134,14 +1121,14 @@ func (c *ManagerController) ItemsetsEdit() { itemName := strings.TrimSpace(c.GetString("itemName")) itemKey := strings.TrimSpace(c.GetString("itemKey")) if itemName == "" || itemKey == "" { - c.JsonResult(5001, "参数错误") + c.JsonResult(5001, i18n.Tr(c.Lang, "message.param_error")) } var item *models.Itemsets var err error if itemId > 0 { if item, err = models.NewItemsets().First(itemId); err != nil { if err == orm.ErrNoRows { - c.JsonResult(5002, "项目空间不存在") + c.JsonResult(5002, i18n.Tr(c.Lang, "message.project_space_not_exist")) } else { c.JsonResult(5003, "查询项目空间出错") } diff --git a/models/TeamMember.go b/models/TeamMember.go index 64ca4207..0fe68a20 100644 --- a/models/TeamMember.go +++ b/models/TeamMember.go @@ -2,7 +2,9 @@ package models import ( "errors" + "github.com/astaxie/beego/logs" + "github.com/beego/i18n" "github.com/astaxie/beego/orm" "github.com/mindoc-org/mindoc/conf" @@ -18,6 +20,7 @@ type TeamMember struct { Account string `orm:"-" json:"account"` RealName string `orm:"-" json:"real_name"` Avatar string `orm:"-" json:"avatar"` + Lang string `orm:"-"` } // TableName 获取对应数据库表名. @@ -46,6 +49,11 @@ func NewTeamMember() *TeamMember { return &TeamMember{} } +func (m *TeamMember) SetLang(lang string) *TeamMember { + m.Lang = lang + return m +} + func (m *TeamMember) First(id int, cols ...string) (*TeamMember, error) { if id <= 0 { return nil, errors.New("参数错误") @@ -173,6 +181,7 @@ func (m *TeamMember) FindToPager(teamId, pageIndex, pageSize int) (list []*TeamM //将来优化 for _, item := range list { + item.Lang = m.Lang item.Include() } return @@ -187,13 +196,13 @@ func (m *TeamMember) Include() *TeamMember { m.Avatar = member.Avatar } if m.RoleId == 0 { - m.RoleName = "创始人" + m.RoleName = i18n.Tr(m.Lang, "common.creator") //"创始人" } else if m.RoleId == 1 { - m.RoleName = "管理员" + m.RoleName = i18n.Tr(m.Lang, "common.administrator") //"管理员" } else if m.RoleId == 2 { - m.RoleName = "编辑者" + m.RoleName = i18n.Tr(m.Lang, "common.editor") //"编辑者" } else if m.RoleId == 3 { - m.RoleName = "观察者" + m.RoleName = i18n.Tr(m.Lang, "common.observer") //"观察者" } return m } diff --git a/views/manager/attach_detailed.tpl b/views/manager/attach_detailed.tpl index 07cbc29d..98a980ae 100644 --- a/views/manager/attach_detailed.tpl +++ b/views/manager/attach_detailed.tpl @@ -5,7 +5,7 @@ - 附件管理 - Powered by MinDoc + {{i18n .Lang "mgr.attachment_mgr"}} - Powered by MinDoc @@ -24,61 +24,61 @@ {{template "widgets/header.tpl" .}}
- {{template "manager/widgets.tpl" "attach"}} + {{template "manager/widgets.tpl" .}}
- 附件管理 + {{i18n .Lang "mgr.attachment_mgr"}}
- - + +
- + {{if .Model.IsExist }} - + {{else}} - + {{end}}
- - + +
{{if ne .Model.BookId 0}}
- - + +
{{end}}
- - + +
- - + +
- - + +
- - + +
- - + +
diff --git a/views/manager/attach_list.tpl b/views/manager/attach_list.tpl index 89daddf6..e8598e4a 100644 --- a/views/manager/attach_list.tpl +++ b/views/manager/attach_list.tpl @@ -5,7 +5,7 @@ - 附件管理 - Powered by MinDoc + {{i18n .Lang "mgr.attachment_mgr"}} - Powered by MinDoc @@ -24,11 +24,11 @@ {{template "widgets/header.tpl" .}}
- {{template "manager/widgets.tpl" "attach"}} + {{template "manager/widgets.tpl" .}}
- 附件管理 + {{i18n .Lang "mgr.attachment_mgr"}}
@@ -37,11 +37,11 @@ # - 附件名称 - 项目/文章名称 - 文件大小 - 是否存在 - 操作 + {{i18n .Lang "mgr.attachment_name"}} + {{i18n .Lang "mgr.proj_blog_name"}} + {{i18n .Lang "mgr.file_size"}} + {{i18n .Lang "mgr.is_exist"}} + {{i18n .Lang "common.operate"}} @@ -51,15 +51,15 @@ {{$item.FileName}} {{$item.BookName}} {{$item.FileShortSize}} - {{ if $item.IsExist }} 是{{else}}否{{end}} + {{ if $item.IsExist }} {{i18n $.Lang "commont.yes"}}{{else}}{{i18n $.Lang "common.no"}}{{end}} - - 详情 + + {{i18n $.Lang "common.detail"}} {{else}} - 暂无数据 + {{i18n .Lang "message.no_data"}} {{end}} @@ -97,7 +97,7 @@ } }, error : function () { - layer.msg("服务器异常"); + layer.msg({{i18n .Lang "message.system_error"}}); }, complete : function () { $this.button("reset"); diff --git a/views/manager/books.tpl b/views/manager/books.tpl index 5d78faa9..9e398add 100644 --- a/views/manager/books.tpl +++ b/views/manager/books.tpl @@ -5,7 +5,7 @@ - 项目管理 - Powered by MinDoc + {{i18n .Lang "mgr.project_mgrt"}} - Powered by MinDoc @@ -24,11 +24,11 @@ {{template "widgets/header.tpl" .}}
-{{template "manager/widgets.tpl" "books"}} + {{template "manager/widgets.tpl" .}}
- 项目列表 + {{i18n .Lang "mgr.proj_list"}}
@@ -38,7 +38,7 @@
- + {{date_format $item.CreateTime "2006-01-02 15:04:05"}} - {{if eq $item.RealName "" }}{{$item.CreateName}}{{else}}{{$item.RealName}}{{end}} - {{$item.DocCount}} + {{if eq $item.RealName "" }}{{$item.CreateName}}{{else}}{{$item.RealName}}{{end}} + {{$item.DocCount}} {{if ne $item.LastModifyText ""}} - 最后编辑: {{$item.LastModifyText}} + {{i18n .Lang "mgr.last_edit"}}: {{$item.LastModifyText}} {{end}}
{{else}} -
暂无数据
+
{{i18n .Lang "message.no_data"}}
{{end}}