2017-04-19 18:19:27 +08:00
|
|
|
|
package controllers
|
|
|
|
|
|
2017-04-23 12:48:46 +08:00
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"html/template"
|
|
|
|
|
"regexp"
|
2017-05-11 13:39:34 +08:00
|
|
|
|
"strings"
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
2018-03-24 17:24:02 +08:00
|
|
|
|
"math"
|
|
|
|
|
"path/filepath"
|
|
|
|
|
"strconv"
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
"github.com/astaxie/beego"
|
2017-04-23 12:48:46 +08:00
|
|
|
|
"github.com/astaxie/beego/logs"
|
2017-04-23 20:33:21 +08:00
|
|
|
|
"github.com/astaxie/beego/orm"
|
2017-06-14 09:23:29 +08:00
|
|
|
|
"github.com/lifei6671/mindoc/conf"
|
|
|
|
|
"github.com/lifei6671/mindoc/models"
|
|
|
|
|
"github.com/lifei6671/mindoc/utils"
|
2018-03-24 17:24:02 +08:00
|
|
|
|
"github.com/lifei6671/mindoc/utils/filetil"
|
2018-01-26 18:07:55 +08:00
|
|
|
|
"github.com/lifei6671/mindoc/utils/pagination"
|
2018-03-12 18:24:58 +08:00
|
|
|
|
"gopkg.in/russross/blackfriday.v2"
|
2018-09-19 11:32:29 +08:00
|
|
|
|
"io/ioutil"
|
|
|
|
|
"os"
|
2017-04-23 12:48:46 +08:00
|
|
|
|
)
|
|
|
|
|
|
2017-04-19 18:19:27 +08:00
|
|
|
|
type ManagerController struct {
|
|
|
|
|
BaseController
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
|
func (c *ManagerController) Prepare() {
|
2017-05-25 18:18:43 +08:00
|
|
|
|
c.BaseController.Prepare()
|
|
|
|
|
|
|
|
|
|
if !c.Member.IsAdministrator() {
|
|
|
|
|
c.Abort("403")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-25 20:05:59 +08:00
|
|
|
|
func (c *ManagerController) Index() {
|
|
|
|
|
c.TplName = "manager/index.tpl"
|
|
|
|
|
|
|
|
|
|
c.Data["Model"] = models.NewDashboard().Query()
|
2017-04-19 18:19:27 +08:00
|
|
|
|
}
|
2017-04-21 18:20:35 +08:00
|
|
|
|
|
2017-04-23 12:48:46 +08:00
|
|
|
|
// 用户列表.
|
2017-05-11 13:39:34 +08:00
|
|
|
|
func (c *ManagerController) Users() {
|
2017-04-23 12:48:46 +08:00
|
|
|
|
c.Prepare()
|
|
|
|
|
c.TplName = "manager/users.tpl"
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
pageIndex, _ := c.GetInt("page", 0)
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
|
members, totalCount, err := models.NewMember().FindToPager(pageIndex, conf.PageSize)
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Data["ErrorMessage"] = err.Error()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-24 18:25:17 +08:00
|
|
|
|
if totalCount > 0 {
|
2018-03-24 17:24:02 +08:00
|
|
|
|
pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
|
2018-01-26 18:07:55 +08:00
|
|
|
|
c.Data["PageHtml"] = pager.HtmlPages()
|
2018-03-25 19:33:37 +08:00
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
for _, item := range members {
|
2018-03-25 19:33:37 +08:00
|
|
|
|
item.Avatar = conf.URLForWithCdnImage(item.Avatar)
|
|
|
|
|
}
|
2017-05-11 13:39:34 +08:00
|
|
|
|
} else {
|
2017-04-24 18:25:17 +08:00
|
|
|
|
c.Data["PageHtml"] = ""
|
|
|
|
|
}
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
b, err := json.Marshal(members)
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Data["Result"] = template.JS("[]")
|
2017-05-11 13:39:34 +08:00
|
|
|
|
} else {
|
2017-04-23 12:48:46 +08:00
|
|
|
|
c.Data["Result"] = template.JS(string(b))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
// 添加用户.
|
2017-04-23 12:48:46 +08:00
|
|
|
|
func (c *ManagerController) CreateMember() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
|
|
|
|
|
account := strings.TrimSpace(c.GetString("account"))
|
|
|
|
|
password1 := strings.TrimSpace(c.GetString("password1"))
|
|
|
|
|
password2 := strings.TrimSpace(c.GetString("password2"))
|
|
|
|
|
email := strings.TrimSpace(c.GetString("email"))
|
|
|
|
|
phone := strings.TrimSpace(c.GetString("phone"))
|
2017-05-11 13:39:34 +08:00
|
|
|
|
role, _ := c.GetInt("role", 1)
|
|
|
|
|
status, _ := c.GetInt("status", 0)
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if ok, err := regexp.MatchString(conf.RegexpAccount, account); account == "" || !ok || err != nil {
|
|
|
|
|
c.JsonResult(6001, "账号只能由英文字母数字组成,且在3-50个字符")
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if l := strings.Count(password1, ""); password1 == "" || l > 50 || l < 6 {
|
|
|
|
|
c.JsonResult(6002, "密码必须在6-50个字符之间")
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
|
|
|
|
if password1 != password2 {
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(6003, "确认密码不正确")
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if ok, err := regexp.MatchString(conf.RegexpEmail, email); !ok || err != nil || email == "" {
|
|
|
|
|
c.JsonResult(6004, "邮箱格式不正确")
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if role != 0 && role != 1 && role != 2 {
|
2017-04-23 12:48:46 +08:00
|
|
|
|
role = 1
|
|
|
|
|
}
|
|
|
|
|
if status != 0 && status != 1 {
|
|
|
|
|
status = 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
member := models.NewMember()
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if _, err := member.FindByAccount(account); err == nil && member.MemberId > 0 {
|
|
|
|
|
c.JsonResult(6005, "账号已存在")
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
member.Account = account
|
|
|
|
|
member.Password = password1
|
2018-11-05 18:50:01 +08:00
|
|
|
|
member.Role = conf.SystemRole(role)
|
2017-04-23 12:48:46 +08:00
|
|
|
|
member.Avatar = conf.GetDefaultAvatar()
|
|
|
|
|
member.CreateAt = c.Member.MemberId
|
|
|
|
|
member.Email = email
|
2018-03-24 17:24:02 +08:00
|
|
|
|
member.RealName = strings.TrimSpace(c.GetString("real_name", ""))
|
2017-04-23 12:48:46 +08:00
|
|
|
|
if phone != "" {
|
|
|
|
|
member.Phone = phone
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := member.Add(); err != nil {
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(6006, err.Error())
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(0, "ok", member)
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//更新用户状态.
|
2017-05-11 13:39:34 +08:00
|
|
|
|
func (c *ManagerController) UpdateMemberStatus() {
|
2017-04-23 12:48:46 +08:00
|
|
|
|
c.Prepare()
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
member_id, _ := c.GetInt("member_id", 0)
|
|
|
|
|
status, _ := c.GetInt("status", 0)
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
|
|
|
|
if member_id <= 0 {
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(6001, "参数错误")
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
|
|
|
|
if status != 0 && status != 1 {
|
|
|
|
|
status = 0
|
|
|
|
|
}
|
|
|
|
|
member := models.NewMember()
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if _, err := member.Find(member_id); err != nil {
|
|
|
|
|
c.JsonResult(6002, "用户不存在")
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
2017-05-25 18:18:43 +08:00
|
|
|
|
if member.MemberId == c.Member.MemberId {
|
2018-01-26 17:17:38 +08:00
|
|
|
|
c.JsonResult(6004, "不能变更自己的状态")
|
2017-05-25 18:18:43 +08:00
|
|
|
|
}
|
2017-05-25 18:20:49 +08:00
|
|
|
|
if member.Role == conf.MemberSuperRole {
|
2018-01-26 17:17:38 +08:00
|
|
|
|
c.JsonResult(6005, "不能变更超级管理员的状态")
|
2017-05-25 18:20:49 +08:00
|
|
|
|
}
|
2017-04-23 12:48:46 +08:00
|
|
|
|
member.Status = status
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if err := member.Update(); err != nil {
|
|
|
|
|
logs.Error("", err)
|
|
|
|
|
c.JsonResult(6003, "用户状态设置失败")
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(0, "ok", member)
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
//变更用户权限.
|
|
|
|
|
func (c *ManagerController) ChangeMemberRole() {
|
2017-04-25 20:05:59 +08:00
|
|
|
|
c.Prepare()
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
memberId, _ := c.GetInt("member_id", 0)
|
2017-05-11 13:39:34 +08:00
|
|
|
|
role, _ := c.GetInt("role", 0)
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if memberId <= 0 {
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(6001, "参数错误")
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if role != int(conf.MemberAdminRole) && role != int(conf.MemberGeneralRole) {
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(6001, "用户权限不正确")
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
member := models.NewMember()
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if _, err := member.Find(memberId); err != nil {
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(6002, "用户不存在")
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
2017-05-25 18:18:43 +08:00
|
|
|
|
if member.MemberId == c.Member.MemberId {
|
2018-01-26 17:17:38 +08:00
|
|
|
|
c.JsonResult(6004, "不能变更自己的权限")
|
2017-05-25 18:18:43 +08:00
|
|
|
|
}
|
2017-05-25 18:20:49 +08:00
|
|
|
|
if member.Role == conf.MemberSuperRole {
|
2018-01-26 17:17:38 +08:00
|
|
|
|
c.JsonResult(6005, "不能变更超级管理员的权限")
|
2017-05-25 18:20:49 +08:00
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
member.Role = conf.SystemRole(role)
|
2017-04-25 20:05:59 +08:00
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if err := member.Update(); err != nil {
|
|
|
|
|
c.JsonResult(6003, "用户权限设置失败")
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
member.ResolveRoleName()
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(0, "ok", member)
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-07 16:20:55 +08:00
|
|
|
|
//编辑用户信息.
|
2017-05-25 18:18:43 +08:00
|
|
|
|
func (c *ManagerController) EditMember() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
c.TplName = "manager/edit_users.tpl"
|
2017-05-26 14:19:27 +08:00
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
|
member_id, _ := c.GetInt(":id", 0)
|
2017-05-25 18:18:43 +08:00
|
|
|
|
|
|
|
|
|
if member_id <= 0 {
|
|
|
|
|
c.Abort("404")
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
|
member, err := models.NewMember().Find(member_id)
|
2017-05-25 18:18:43 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
beego.Error(err)
|
|
|
|
|
c.Abort("404")
|
|
|
|
|
}
|
|
|
|
|
if c.Ctx.Input.IsPost() {
|
|
|
|
|
password1 := c.GetString("password1")
|
|
|
|
|
password2 := c.GetString("password2")
|
|
|
|
|
email := c.GetString("email")
|
|
|
|
|
phone := c.GetString("phone")
|
|
|
|
|
description := c.GetString("description")
|
|
|
|
|
member.Email = email
|
|
|
|
|
member.Phone = phone
|
|
|
|
|
member.Description = description
|
2018-02-05 09:06:47 +08:00
|
|
|
|
member.RealName = c.GetString("real_name")
|
2017-05-25 18:18:43 +08:00
|
|
|
|
if password1 != "" && password2 != password1 {
|
2018-01-26 17:17:38 +08:00
|
|
|
|
c.JsonResult(6001, "确认密码不正确")
|
2017-05-25 18:18:43 +08:00
|
|
|
|
}
|
2018-01-26 17:17:38 +08:00
|
|
|
|
if password1 != "" && member.AuthMethod != conf.AuthMethodLDAP {
|
2017-05-25 18:18:43 +08:00
|
|
|
|
member.Password = password1
|
|
|
|
|
}
|
2018-01-26 17:17:38 +08:00
|
|
|
|
if err := member.Valid(password1 == ""); err != nil {
|
|
|
|
|
c.JsonResult(6002, err.Error())
|
2017-05-25 18:18:43 +08:00
|
|
|
|
}
|
|
|
|
|
if password1 != "" {
|
2018-01-26 17:17:38 +08:00
|
|
|
|
password, err := utils.PasswordHash(password1)
|
2017-05-25 18:18:43 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
beego.Error(err)
|
2018-01-26 17:17:38 +08:00
|
|
|
|
c.JsonResult(6003, "对用户密码加密时出错")
|
2017-05-25 18:18:43 +08:00
|
|
|
|
}
|
|
|
|
|
member.Password = password
|
|
|
|
|
}
|
2018-01-26 17:17:38 +08:00
|
|
|
|
if err := member.Update(); err != nil {
|
2018-03-22 14:27:23 +08:00
|
|
|
|
c.JsonResult(6004, err.Error())
|
2017-05-25 18:18:43 +08:00
|
|
|
|
}
|
2018-01-26 17:17:38 +08:00
|
|
|
|
c.JsonResult(0, "ok")
|
2017-05-25 18:18:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.Data["Model"] = member
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-07 16:20:55 +08:00
|
|
|
|
//删除一个用户,并将该用户的所有信息转移到超级管理员上.
|
2018-01-26 17:17:38 +08:00
|
|
|
|
func (c *ManagerController) DeleteMember() {
|
2017-07-07 16:20:55 +08:00
|
|
|
|
c.Prepare()
|
2018-01-26 17:17:38 +08:00
|
|
|
|
member_id, _ := c.GetInt("id", 0)
|
2017-07-07 16:20:55 +08:00
|
|
|
|
|
|
|
|
|
if member_id <= 0 {
|
2018-01-26 17:17:38 +08:00
|
|
|
|
c.JsonResult(404, "参数错误")
|
2017-07-07 16:20:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
|
member, err := models.NewMember().Find(member_id)
|
2017-07-07 16:20:55 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
beego.Error(err)
|
2018-01-26 17:17:38 +08:00
|
|
|
|
c.JsonResult(500, "用户不存在")
|
2017-07-07 16:20:55 +08:00
|
|
|
|
}
|
2017-07-10 16:59:49 +08:00
|
|
|
|
if member.Role == conf.MemberSuperRole {
|
2018-01-26 17:17:38 +08:00
|
|
|
|
c.JsonResult(500, "不能删除超级管理员")
|
2017-07-10 16:59:49 +08:00
|
|
|
|
}
|
2018-01-26 17:17:38 +08:00
|
|
|
|
superMember, err := models.NewMember().FindByFieldFirst("role", 0)
|
2017-07-07 16:20:55 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
beego.Error(err)
|
2018-01-26 17:17:38 +08:00
|
|
|
|
c.JsonResult(5001, "未能找到超级管理员")
|
2017-07-07 16:20:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
|
err = models.NewMember().Delete(member_id, superMember.MemberId)
|
2017-07-07 16:20:55 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
beego.Error(err)
|
2018-01-26 17:17:38 +08:00
|
|
|
|
c.JsonResult(5002, "删除失败")
|
2017-07-07 16:20:55 +08:00
|
|
|
|
}
|
2018-01-26 17:17:38 +08:00
|
|
|
|
c.JsonResult(0, "ok")
|
2017-07-07 16:20:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//项目列表.
|
2017-05-11 13:39:34 +08:00
|
|
|
|
func (c *ManagerController) Books() {
|
2017-04-23 12:48:46 +08:00
|
|
|
|
c.Prepare()
|
|
|
|
|
c.TplName = "manager/books.tpl"
|
|
|
|
|
|
2017-04-24 18:25:17 +08:00
|
|
|
|
pageIndex, _ := c.GetInt("page", 1)
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
books, totalCount, err := models.NewBookResult().FindToPager(pageIndex, conf.PageSize)
|
2017-04-24 18:25:17 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Abort("500")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if totalCount > 0 {
|
2018-01-26 18:07:55 +08:00
|
|
|
|
//html := utils.GetPagerHtml(c.Ctx.Request.RequestURI, pageIndex, 8, totalCount)
|
|
|
|
|
|
2018-03-24 17:24:02 +08:00
|
|
|
|
pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
|
2017-04-24 18:25:17 +08:00
|
|
|
|
|
2018-01-26 18:07:55 +08:00
|
|
|
|
c.Data["PageHtml"] = pager.HtmlPages()
|
2017-05-11 13:39:34 +08:00
|
|
|
|
} else {
|
2017-04-24 18:25:17 +08:00
|
|
|
|
c.Data["PageHtml"] = ""
|
|
|
|
|
}
|
2018-03-24 17:24:02 +08:00
|
|
|
|
for i, book := range books {
|
2018-03-12 18:24:58 +08:00
|
|
|
|
books[i].Description = utils.StripTags(string(blackfriday.Run([]byte(book.Description))))
|
2018-03-22 20:45:50 +08:00
|
|
|
|
books[i].ModifyTime = book.ModifyTime.Local()
|
|
|
|
|
books[i].CreateTime = book.CreateTime.Local()
|
2018-03-12 18:24:58 +08:00
|
|
|
|
}
|
2017-04-24 18:25:17 +08:00
|
|
|
|
c.Data["Lists"] = books
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-07 16:20:55 +08:00
|
|
|
|
//编辑项目.
|
2017-05-11 13:39:34 +08:00
|
|
|
|
func (c *ManagerController) EditBook() {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
c.Prepare()
|
|
|
|
|
|
2017-04-24 18:25:17 +08:00
|
|
|
|
c.TplName = "manager/edit_book.tpl"
|
2017-05-26 14:19:27 +08:00
|
|
|
|
|
2017-04-24 18:25:17 +08:00
|
|
|
|
identify := c.GetString(":key")
|
|
|
|
|
|
|
|
|
|
if identify == "" {
|
|
|
|
|
c.Abort("404")
|
|
|
|
|
}
|
2017-05-11 13:39:34 +08:00
|
|
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
2017-04-24 18:25:17 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
c.Abort("500")
|
|
|
|
|
}
|
2017-04-25 20:05:59 +08:00
|
|
|
|
if c.Ctx.Input.IsPost() {
|
|
|
|
|
|
2018-03-22 20:45:50 +08:00
|
|
|
|
bookName := strings.TrimSpace(c.GetString("book_name"))
|
2017-05-11 13:39:34 +08:00
|
|
|
|
description := strings.TrimSpace(c.GetString("description", ""))
|
2018-03-22 20:45:50 +08:00
|
|
|
|
commentStatus := c.GetString("comment_status")
|
2017-04-25 20:05:59 +08:00
|
|
|
|
tag := strings.TrimSpace(c.GetString("label"))
|
2018-03-22 20:45:50 +08:00
|
|
|
|
orderIndex, _ := c.GetInt("order_index", 0)
|
2018-03-23 17:11:20 +08:00
|
|
|
|
isDownload := strings.TrimSpace(c.GetString("is_download")) == "on"
|
|
|
|
|
enableShare := strings.TrimSpace(c.GetString("enable_share")) == "on"
|
2018-03-24 17:24:02 +08:00
|
|
|
|
isUseFirstDocument := strings.TrimSpace(c.GetString("is_use_first_document")) == "on"
|
2018-03-23 17:11:20 +08:00
|
|
|
|
autoRelease := strings.TrimSpace(c.GetString("auto_release")) == "on"
|
|
|
|
|
publisher := strings.TrimSpace(c.GetString("publisher"))
|
2018-03-24 17:24:02 +08:00
|
|
|
|
historyCount, _ := c.GetInt("history_count", 0)
|
2018-11-20 20:55:04 +08:00
|
|
|
|
itemId,_ := c.GetInt("itemId")
|
2017-04-25 20:05:59 +08:00
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if strings.Count(description, "") > 500 {
|
|
|
|
|
c.JsonResult(6004, "项目描述不能大于500字")
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
2018-03-22 20:45:50 +08:00
|
|
|
|
if commentStatus != "open" && commentStatus != "closed" && commentStatus != "group_only" && commentStatus != "registered_only" {
|
|
|
|
|
commentStatus = "closed"
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if tag != "" {
|
|
|
|
|
tags := strings.Split(tag, ";")
|
2017-04-25 20:05:59 +08:00
|
|
|
|
if len(tags) > 10 {
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(6005, "最多允许添加10个标签")
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-20 20:55:04 +08:00
|
|
|
|
if !models.NewItemsets().Exist(itemId) {
|
2018-11-21 11:03:16 +08:00
|
|
|
|
c.JsonResult(6006,"项目空间不存在")
|
2018-11-20 20:55:04 +08:00
|
|
|
|
}
|
2018-03-23 17:11:20 +08:00
|
|
|
|
book.Publisher = publisher
|
|
|
|
|
book.HistoryCount = historyCount
|
2018-03-22 20:45:50 +08:00
|
|
|
|
book.BookName = bookName
|
2017-04-25 20:05:59 +08:00
|
|
|
|
book.Description = description
|
2018-03-22 20:45:50 +08:00
|
|
|
|
book.CommentStatus = commentStatus
|
2017-04-25 20:05:59 +08:00
|
|
|
|
book.Label = tag
|
2018-03-22 20:45:50 +08:00
|
|
|
|
book.OrderIndex = orderIndex
|
2018-11-20 20:55:04 +08:00
|
|
|
|
book.ItemId = itemId
|
|
|
|
|
book.BookPassword = strings.TrimSpace(c.GetString("bPassword"))
|
2017-04-25 20:05:59 +08:00
|
|
|
|
|
2018-03-23 17:11:20 +08:00
|
|
|
|
if autoRelease {
|
|
|
|
|
book.AutoRelease = 1
|
|
|
|
|
} else {
|
|
|
|
|
book.AutoRelease = 0
|
|
|
|
|
}
|
|
|
|
|
if isDownload {
|
|
|
|
|
book.IsDownload = 0
|
2018-03-24 17:24:02 +08:00
|
|
|
|
} else {
|
2018-03-23 17:11:20 +08:00
|
|
|
|
book.IsDownload = 1
|
|
|
|
|
}
|
|
|
|
|
if enableShare {
|
|
|
|
|
book.IsEnableShare = 0
|
2018-03-24 17:24:02 +08:00
|
|
|
|
} else {
|
2018-03-23 17:11:20 +08:00
|
|
|
|
book.IsEnableShare = 1
|
|
|
|
|
}
|
|
|
|
|
if isUseFirstDocument {
|
|
|
|
|
book.IsUseFirstDocument = 1
|
2018-03-24 17:24:02 +08:00
|
|
|
|
} else {
|
2018-03-23 17:11:20 +08:00
|
|
|
|
book.IsUseFirstDocument = 0
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if err := book.Update(); err != nil {
|
|
|
|
|
c.JsonResult(6006, "保存失败")
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(0, "ok")
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
if book.PrivateToken != "" {
|
2018-03-13 19:20:50 +08:00
|
|
|
|
book.PrivateToken = conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken)
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
2018-03-23 17:11:20 +08:00
|
|
|
|
bookResult := models.NewBookResult()
|
|
|
|
|
bookResult.ToBookResult(*book)
|
|
|
|
|
|
|
|
|
|
c.Data["Model"] = bookResult
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-23 20:33:21 +08:00
|
|
|
|
// 删除项目.
|
2017-05-11 13:39:34 +08:00
|
|
|
|
func (c *ManagerController) DeleteBook() {
|
2017-04-23 12:48:46 +08:00
|
|
|
|
c.Prepare()
|
2017-04-23 20:33:21 +08:00
|
|
|
|
|
2018-03-08 16:36:13 +08:00
|
|
|
|
bookId, _ := c.GetInt("book_id", 0)
|
2017-04-23 20:33:21 +08:00
|
|
|
|
|
2018-03-08 16:36:13 +08:00
|
|
|
|
if bookId <= 0 {
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(6001, "参数错误")
|
2017-04-23 20:33:21 +08:00
|
|
|
|
}
|
|
|
|
|
book := models.NewBook()
|
|
|
|
|
|
2018-03-08 16:36:13 +08:00
|
|
|
|
err := book.ThoroughDeleteBook(bookId)
|
2017-04-23 20:33:21 +08:00
|
|
|
|
|
|
|
|
|
if err == orm.ErrNoRows {
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(6002, "项目不存在")
|
2017-04-23 20:33:21 +08:00
|
|
|
|
}
|
|
|
|
|
if err != nil {
|
2018-11-15 19:54:25 +08:00
|
|
|
|
logs.Error("删除失败 -> ", err)
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(6003, "删除失败")
|
2017-04-23 20:33:21 +08:00
|
|
|
|
}
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(0, "ok")
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-25 20:05:59 +08:00
|
|
|
|
// CreateToken 创建访问来令牌.
|
|
|
|
|
func (c *ManagerController) CreateToken() {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
c.Prepare()
|
2017-04-25 20:05:59 +08:00
|
|
|
|
action := c.GetString("action")
|
|
|
|
|
|
|
|
|
|
identify := c.GetString("identify")
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
2017-04-25 20:05:59 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(6001, "项目不存在")
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
if action == "create" {
|
|
|
|
|
|
|
|
|
|
if book.PrivatelyOwned == 0 {
|
|
|
|
|
c.JsonResult(6001, "公开项目不能创建阅读令牌")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
book.PrivateToken = string(utils.Krand(conf.GetTokenSize(), utils.KC_RAND_KIND_ALL))
|
|
|
|
|
if err := book.Update(); err != nil {
|
|
|
|
|
logs.Error("生成阅读令牌失败 => ", err)
|
|
|
|
|
c.JsonResult(6003, "生成阅读令牌失败")
|
|
|
|
|
}
|
2018-03-13 19:20:50 +08:00
|
|
|
|
c.JsonResult(0, "ok", conf.URLFor("DocumentController.Index", ":key", book.Identify, "token", book.PrivateToken))
|
2017-05-11 13:39:34 +08:00
|
|
|
|
} else {
|
2017-04-25 20:05:59 +08:00
|
|
|
|
book.PrivateToken = ""
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if err := book.Update(); err != nil {
|
|
|
|
|
logs.Error("CreateToken => ", err)
|
|
|
|
|
c.JsonResult(6004, "删除令牌失败")
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(0, "ok", "")
|
2017-04-25 20:05:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
//项目设置.
|
2017-04-26 18:17:38 +08:00
|
|
|
|
func (c *ManagerController) Setting() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
c.TplName = "manager/setting.tpl"
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
options, err := models.NewOption().All()
|
2017-04-26 18:17:38 +08:00
|
|
|
|
|
2017-04-30 22:13:12 +08:00
|
|
|
|
if c.Ctx.Input.IsPost() {
|
2017-05-11 13:39:34 +08:00
|
|
|
|
for _, item := range options {
|
2017-04-30 22:13:12 +08:00
|
|
|
|
item.OptionValue = c.GetString(item.OptionName)
|
|
|
|
|
item.InsertOrUpdate()
|
|
|
|
|
}
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(0, "ok")
|
2017-04-30 22:13:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-26 18:17:38 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
c.Abort("500")
|
|
|
|
|
}
|
2017-04-30 22:13:12 +08:00
|
|
|
|
c.Data["SITE_TITLE"] = c.Option["SITE_NAME"]
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
for _, item := range options {
|
2018-03-19 17:46:47 +08:00
|
|
|
|
c.Data[item.OptionName] = item.OptionValue
|
2017-04-26 18:17:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Transfer 转让项目.
|
|
|
|
|
func (c *ManagerController) Transfer() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
account := c.GetString("account")
|
|
|
|
|
|
|
|
|
|
if account == "" {
|
|
|
|
|
c.JsonResult(6004, "接受者账号不能为空")
|
|
|
|
|
}
|
|
|
|
|
member, err := models.NewMember().FindByAccount(account)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
logs.Error("FindByAccount => ", err)
|
|
|
|
|
c.JsonResult(6005, "接受用户不存在")
|
|
|
|
|
}
|
|
|
|
|
if member.Status != 0 {
|
|
|
|
|
c.JsonResult(6006, "接受用户已被禁用")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if !c.Member.IsAdministrator() {
|
|
|
|
|
c.Abort("403")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
identify := c.GetString("identify")
|
|
|
|
|
|
|
|
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JsonResult(6001, err.Error())
|
|
|
|
|
}
|
|
|
|
|
rel, err := models.NewRelationship().FindFounder(book.BookId)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
beego.Error("FindFounder => ", err)
|
|
|
|
|
c.JsonResult(6009, "查询项目创始人失败")
|
|
|
|
|
}
|
|
|
|
|
if member.MemberId == rel.MemberId {
|
|
|
|
|
c.JsonResult(6007, "不能转让给自己")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err = models.NewRelationship().Transfer(book.BookId, rel.MemberId, member.MemberId)
|
2017-04-30 22:13:12 +08:00
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
logs.Error("Transfer => ", err)
|
|
|
|
|
c.JsonResult(6008, err.Error())
|
|
|
|
|
}
|
|
|
|
|
c.JsonResult(0, "ok")
|
2017-04-26 18:17:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
func (c *ManagerController) Comments() {
|
2017-04-23 12:48:46 +08:00
|
|
|
|
c.Prepare()
|
2017-04-25 20:05:59 +08:00
|
|
|
|
c.TplName = "manager/comments.tpl"
|
2017-04-24 18:25:17 +08:00
|
|
|
|
if !c.Member.IsAdministrator() {
|
2017-04-23 12:48:46 +08:00
|
|
|
|
c.Abort("403")
|
|
|
|
|
}
|
2017-04-25 20:05:59 +08:00
|
|
|
|
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-04-23 20:33:21 +08:00
|
|
|
|
//DeleteComment 标记评论为已删除
|
2017-05-11 13:39:34 +08:00
|
|
|
|
func (c *ManagerController) DeleteComment() {
|
2017-04-23 12:48:46 +08:00
|
|
|
|
c.Prepare()
|
2017-05-26 14:19:27 +08:00
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
comment_id, _ := c.GetInt("comment_id", 0)
|
2017-04-23 20:33:21 +08:00
|
|
|
|
|
|
|
|
|
if comment_id <= 0 {
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(6001, "参数错误")
|
2017-04-23 20:33:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comment := models.NewComment()
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if _, err := comment.Find(comment_id); err != nil {
|
|
|
|
|
c.JsonResult(6002, "评论不存在")
|
2017-04-23 20:33:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comment.Approved = 3
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if err := comment.Update("approved"); err != nil {
|
|
|
|
|
c.JsonResult(6003, "删除评论失败")
|
2017-04-23 20:33:21 +08:00
|
|
|
|
}
|
2017-05-11 13:39:34 +08:00
|
|
|
|
c.JsonResult(0, "ok", comment)
|
2017-04-23 12:48:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
//设置项目私有状态.
|
|
|
|
|
func (c *ManagerController) PrivatelyOwned() {
|
2017-05-26 14:19:27 +08:00
|
|
|
|
c.Prepare()
|
2017-05-11 13:39:34 +08:00
|
|
|
|
status := c.GetString("status")
|
|
|
|
|
identify := c.GetString("identify")
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if status != "open" && status != "close" {
|
|
|
|
|
c.JsonResult(6003, "参数错误")
|
|
|
|
|
}
|
|
|
|
|
state := 0
|
|
|
|
|
if status == "open" {
|
|
|
|
|
state = 0
|
|
|
|
|
} else {
|
|
|
|
|
state = 1
|
|
|
|
|
}
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if !c.Member.IsAdministrator() {
|
|
|
|
|
c.Abort("403")
|
|
|
|
|
}
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
book, err := models.NewBook().FindByFieldFirst("identify", identify)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JsonResult(6001, err.Error())
|
|
|
|
|
}
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
book.PrivatelyOwned = state
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
logs.Info("", state, status)
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
err = book.Update()
|
2017-04-23 12:48:46 +08:00
|
|
|
|
|
2017-05-11 13:39:34 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
logs.Error("PrivatelyOwned => ", err)
|
|
|
|
|
c.JsonResult(6004, "保存失败")
|
|
|
|
|
}
|
|
|
|
|
c.JsonResult(0, "ok")
|
|
|
|
|
}
|
2017-06-09 18:14:55 +08:00
|
|
|
|
|
|
|
|
|
//附件列表.
|
|
|
|
|
func (c *ManagerController) AttachList() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
c.TplName = "manager/attach_list.tpl"
|
|
|
|
|
|
|
|
|
|
pageIndex, _ := c.GetInt("page", 1)
|
|
|
|
|
|
|
|
|
|
attachList, totalCount, err := models.NewAttachment().FindToPager(pageIndex, conf.PageSize)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Abort("500")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if totalCount > 0 {
|
2018-03-13 14:14:56 +08:00
|
|
|
|
pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
|
2018-01-26 18:07:55 +08:00
|
|
|
|
c.Data["PageHtml"] = pager.HtmlPages()
|
2017-06-09 18:14:55 +08:00
|
|
|
|
} else {
|
|
|
|
|
c.Data["PageHtml"] = ""
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
|
for _, item := range attachList {
|
2017-06-09 18:14:55 +08:00
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
|
p := filepath.Join(conf.WorkingDirectory, item.FilePath)
|
2017-06-09 18:14:55 +08:00
|
|
|
|
|
2018-03-24 17:24:02 +08:00
|
|
|
|
item.IsExist = filetil.FileExists(p)
|
2017-06-09 18:14:55 +08:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
c.Data["Lists"] = attachList
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//附件详情.
|
2018-01-26 17:17:38 +08:00
|
|
|
|
func (c *ManagerController) AttachDetailed() {
|
2017-06-09 18:14:55 +08:00
|
|
|
|
c.Prepare()
|
|
|
|
|
c.TplName = "manager/attach_detailed.tpl"
|
2018-01-26 17:17:38 +08:00
|
|
|
|
attach_id, _ := strconv.Atoi(c.Ctx.Input.Param(":id"))
|
2017-06-09 18:14:55 +08:00
|
|
|
|
|
|
|
|
|
if attach_id <= 0 {
|
|
|
|
|
c.Abort("404")
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
|
attach, err := models.NewAttachmentResult().Find(attach_id)
|
2017-06-09 18:14:55 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
2018-01-26 17:17:38 +08:00
|
|
|
|
beego.Error("AttachDetailed => ", err)
|
2017-06-09 18:14:55 +08:00
|
|
|
|
if err == orm.ErrNoRows {
|
|
|
|
|
c.Abort("404")
|
2018-01-26 17:17:38 +08:00
|
|
|
|
} else {
|
2017-06-09 18:14:55 +08:00
|
|
|
|
c.Abort("500")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
|
attach.FilePath = filepath.Join(conf.WorkingDirectory, attach.FilePath)
|
2018-03-13 19:20:50 +08:00
|
|
|
|
attach.HttpPath = conf.URLForWithCdnImage(attach.HttpPath)
|
2017-06-09 18:14:55 +08:00
|
|
|
|
|
2018-03-24 17:24:02 +08:00
|
|
|
|
attach.IsExist = filetil.FileExists(attach.FilePath)
|
2017-06-09 18:14:55 +08:00
|
|
|
|
|
|
|
|
|
c.Data["Model"] = attach
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//删除附件.
|
2018-01-26 17:17:38 +08:00
|
|
|
|
func (c *ManagerController) AttachDelete() {
|
2017-06-09 18:14:55 +08:00
|
|
|
|
c.Prepare()
|
2018-07-17 19:13:11 +08:00
|
|
|
|
attachId, _ := c.GetInt("attach_id")
|
2017-06-09 18:14:55 +08:00
|
|
|
|
|
2018-07-17 19:13:11 +08:00
|
|
|
|
if attachId <= 0 {
|
2017-06-09 18:14:55 +08:00
|
|
|
|
c.Abort("404")
|
|
|
|
|
}
|
2018-07-17 19:13:11 +08:00
|
|
|
|
attach, err := models.NewAttachment().Find(attachId)
|
2017-06-09 18:14:55 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
2018-01-26 17:17:38 +08:00
|
|
|
|
beego.Error("AttachDelete => ", err)
|
|
|
|
|
c.JsonResult(6001, err.Error())
|
2017-06-09 18:14:55 +08:00
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
attach.FilePath = filepath.Join(conf.WorkingDirectory, attach.FilePath)
|
2018-07-17 19:13:11 +08:00
|
|
|
|
|
2018-01-26 17:17:38 +08:00
|
|
|
|
if err := attach.Delete(); err != nil {
|
|
|
|
|
beego.Error("AttachDelete => ", err)
|
|
|
|
|
c.JsonResult(6002, err.Error())
|
2017-06-09 18:14:55 +08:00
|
|
|
|
}
|
2018-01-26 17:17:38 +08:00
|
|
|
|
c.JsonResult(0, "ok")
|
2017-06-09 18:14:55 +08:00
|
|
|
|
}
|
2018-02-28 15:47:00 +08:00
|
|
|
|
|
|
|
|
|
//标签列表
|
2018-03-13 14:14:56 +08:00
|
|
|
|
func (c *ManagerController) LabelList() {
|
2018-02-28 15:47:00 +08:00
|
|
|
|
c.Prepare()
|
|
|
|
|
c.TplName = "manager/label_list.tpl"
|
|
|
|
|
|
|
|
|
|
pageIndex, _ := c.GetInt("page", 1)
|
|
|
|
|
|
|
|
|
|
labels, totalCount, err := models.NewLabel().FindToPager(pageIndex, conf.PageSize)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.ShowErrorPage(50001, err.Error())
|
|
|
|
|
}
|
|
|
|
|
if totalCount > 0 {
|
2018-03-13 14:14:56 +08:00
|
|
|
|
pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
|
2018-02-28 15:47:00 +08:00
|
|
|
|
c.Data["PageHtml"] = pager.HtmlPages()
|
|
|
|
|
} else {
|
|
|
|
|
c.Data["PageHtml"] = ""
|
|
|
|
|
}
|
|
|
|
|
c.Data["TotalPages"] = int(math.Ceil(float64(totalCount) / float64(conf.PageSize)))
|
|
|
|
|
|
|
|
|
|
c.Data["Lists"] = labels
|
|
|
|
|
}
|
2018-03-24 17:24:02 +08:00
|
|
|
|
|
2018-02-28 15:47:00 +08:00
|
|
|
|
//删除标签
|
2018-03-24 17:24:02 +08:00
|
|
|
|
func (c *ManagerController) LabelDelete() {
|
|
|
|
|
labelId, err := strconv.Atoi(c.Ctx.Input.Param(":id"))
|
2018-02-28 15:47:00 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
2018-03-24 17:24:02 +08:00
|
|
|
|
beego.Error("获取删除标签参数时出错:", err)
|
|
|
|
|
c.JsonResult(50001, "参数错误")
|
2018-02-28 15:47:00 +08:00
|
|
|
|
}
|
|
|
|
|
if labelId <= 0 {
|
2018-03-24 17:24:02 +08:00
|
|
|
|
c.JsonResult(50001, "参数错误")
|
2018-02-28 15:47:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-24 17:24:02 +08:00
|
|
|
|
label, err := models.NewLabel().FindFirst("label_id", labelId)
|
2018-02-28 15:47:00 +08:00
|
|
|
|
if err != nil {
|
2018-03-24 17:24:02 +08:00
|
|
|
|
beego.Error("查询标签时出错:", err)
|
|
|
|
|
c.JsonResult(50001, "查询标签时出错:"+err.Error())
|
2018-02-28 15:47:00 +08:00
|
|
|
|
}
|
2018-03-24 17:24:02 +08:00
|
|
|
|
if err := label.Delete(); err != nil {
|
|
|
|
|
c.JsonResult(50002, "删除失败:"+err.Error())
|
|
|
|
|
} else {
|
|
|
|
|
c.JsonResult(0, "ok")
|
2018-02-28 15:47:00 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-19 11:32:29 +08:00
|
|
|
|
|
|
|
|
|
func (c *ManagerController) Config() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
c.TplName = "manager/config.tpl"
|
|
|
|
|
if c.Ctx.Input.IsPost() {
|
|
|
|
|
content := strings.TrimSpace(c.GetString("configFileTextArea"))
|
|
|
|
|
if content == "" {
|
2018-11-05 18:50:01 +08:00
|
|
|
|
c.JsonResult(500, "配置文件不能为空")
|
2018-09-19 11:32:29 +08:00
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
tf, err := ioutil.TempFile(os.TempDir(), "mindoc")
|
2018-09-19 11:32:29 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
2018-11-05 18:50:01 +08:00
|
|
|
|
beego.Error("创建临时文件失败 ->", err)
|
|
|
|
|
c.JsonResult(5001, "创建临时文件失败")
|
2018-09-19 11:32:29 +08:00
|
|
|
|
}
|
|
|
|
|
defer tf.Close()
|
|
|
|
|
|
|
|
|
|
tf.WriteString(content)
|
|
|
|
|
|
2018-11-05 18:50:01 +08:00
|
|
|
|
err = beego.LoadAppConfig("ini", tf.Name())
|
2018-09-19 11:32:29 +08:00
|
|
|
|
|
|
|
|
|
if err != nil {
|
2018-11-05 18:50:01 +08:00
|
|
|
|
beego.Error("加载配置文件失败 ->", err)
|
|
|
|
|
c.JsonResult(5002, "加载配置文件失败")
|
2018-09-19 11:32:29 +08:00
|
|
|
|
}
|
|
|
|
|
err = filetil.CopyFile(tf.Name(), conf.ConfigurationFile)
|
|
|
|
|
if err != nil {
|
2018-11-05 18:50:01 +08:00
|
|
|
|
beego.Error("保存配置文件失败 ->", err)
|
|
|
|
|
c.JsonResult(5003, "保存配置文件失败")
|
2018-09-19 11:32:29 +08:00
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
c.JsonResult(0, "保存成功")
|
2018-09-19 11:32:29 +08:00
|
|
|
|
}
|
|
|
|
|
c.Data["ConfigContent"] = ""
|
2018-11-05 18:50:01 +08:00
|
|
|
|
if b, err := ioutil.ReadFile(conf.ConfigurationFile); err == nil {
|
2018-09-19 11:32:29 +08:00
|
|
|
|
c.Data["ConfigContent"] = string(b)
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
|
|
|
|
|
func (c *ManagerController) Team() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
c.TplName = "manager/team.tpl"
|
|
|
|
|
|
|
|
|
|
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())
|
|
|
|
|
}
|
|
|
|
|
if err == orm.ErrNoRows || len(teams) <= 0 {
|
|
|
|
|
c.Data["Result"] = template.JS("[]")
|
|
|
|
|
c.Data["PageHtml"] = ""
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if totalCount > 0 {
|
|
|
|
|
pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
|
|
|
|
|
c.Data["PageHtml"] = pager.HtmlPages()
|
|
|
|
|
} else {
|
|
|
|
|
c.Data["PageHtml"] = ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b, err := json.Marshal(teams)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.Data["Result"] = template.JS("[]")
|
|
|
|
|
} else {
|
|
|
|
|
c.Data["Result"] = template.JS(string(b))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ManagerController) TeamCreate() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
|
|
|
|
|
teamName := c.GetString("teamName")
|
|
|
|
|
|
|
|
|
|
if teamName == "" {
|
|
|
|
|
c.JsonResult(5001, "团队名称不能为空")
|
|
|
|
|
}
|
|
|
|
|
team := models.NewTeam()
|
|
|
|
|
|
|
|
|
|
team.MemberId = c.Member.MemberId
|
|
|
|
|
team.TeamName = teamName
|
|
|
|
|
|
|
|
|
|
if err := team.Save(); err == nil {
|
|
|
|
|
c.JsonResult(0, "OK", team)
|
|
|
|
|
} else {
|
|
|
|
|
c.JsonResult(5002, err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ManagerController) TeamEdit() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
teamName := c.GetString("teamName")
|
|
|
|
|
teamId, _ := c.GetInt("teamId")
|
|
|
|
|
|
|
|
|
|
if teamName == "" {
|
|
|
|
|
c.JsonResult(5001, "团队名称不能为空")
|
|
|
|
|
}
|
|
|
|
|
if teamId <= 0 {
|
|
|
|
|
c.JsonResult(5002, "团队标识不能为空")
|
|
|
|
|
}
|
|
|
|
|
team, err := models.NewTeam().First(teamId)
|
|
|
|
|
|
|
|
|
|
c.CheckJsonError(5003, err)
|
|
|
|
|
|
|
|
|
|
team.TeamName = teamName
|
|
|
|
|
|
|
|
|
|
err = team.Save()
|
|
|
|
|
|
|
|
|
|
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, "团队标识不能为空")
|
|
|
|
|
}
|
|
|
|
|
err := models.NewTeam().Delete(teamId)
|
|
|
|
|
|
|
|
|
|
c.CheckJsonError(5001, err)
|
|
|
|
|
|
2018-11-12 21:01:59 +08:00
|
|
|
|
c.JsonResult(0, "OK")
|
2018-11-05 18:50:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ManagerController) TeamMemberList() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
c.TplName = "manager/team_member_list.tpl"
|
|
|
|
|
teamId, _ := strconv.Atoi(c.Ctx.Input.Param(":id"))
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
if err != nil && err != orm.ErrNoRows {
|
|
|
|
|
c.ShowErrorPage(500, err.Error())
|
|
|
|
|
}
|
|
|
|
|
if err == orm.ErrNoRows || len(teams) <= 0 {
|
|
|
|
|
c.Data["Result"] = template.JS("[]")
|
|
|
|
|
c.Data["PageHtml"] = ""
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if totalCount > 0 {
|
|
|
|
|
pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
|
|
|
|
|
c.Data["PageHtml"] = pager.HtmlPages()
|
|
|
|
|
} else {
|
|
|
|
|
c.Data["PageHtml"] = ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b, err := json.Marshal(teams)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
beego.Error("编码 JSON 结果失败 ->", err)
|
|
|
|
|
c.Data["Result"] = template.JS("[]")
|
|
|
|
|
} else {
|
|
|
|
|
c.Data["Result"] = template.JS(string(b))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//搜索团队用户.
|
|
|
|
|
func (c *ManagerController) TeamSearchMember() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
|
|
|
|
|
teamId, _ := c.GetInt("teamId")
|
|
|
|
|
keyword := strings.TrimSpace(c.GetString("q"))
|
|
|
|
|
|
|
|
|
|
if teamId <= 0 {
|
|
|
|
|
c.JsonResult(500, "参数错误")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
searchResult, err := models.NewTeamMember().FindNotJoinMemberByAccount(teamId, keyword, 10)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JsonResult(500, err.Error())
|
|
|
|
|
}
|
|
|
|
|
c.JsonResult(0, "OK", searchResult)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ManagerController) TeamMemberAdd() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
teamId, _ := c.GetInt("teamId")
|
|
|
|
|
memberId, _ := c.GetInt("memberId")
|
|
|
|
|
roleId, _ := c.GetInt("roleId")
|
|
|
|
|
|
|
|
|
|
if teamId <= 0 || memberId <= 0 || roleId <= 0 || roleId > int(conf.BookObserver) {
|
|
|
|
|
c.JsonResult(5001, "参数不正确")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
teamMember := models.NewTeamMember()
|
|
|
|
|
teamMember.MemberId = memberId
|
|
|
|
|
teamMember.TeamId = teamId
|
|
|
|
|
teamMember.RoleId = conf.BookRole(roleId)
|
|
|
|
|
|
|
|
|
|
if err := teamMember.Save(); err != nil {
|
|
|
|
|
c.CheckJsonError(5001, err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
teamMember.Include()
|
|
|
|
|
|
|
|
|
|
c.JsonResult(0, "OK", teamMember)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ManagerController) TeamMemberDelete() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
memberId, _ := c.GetInt("memberId")
|
|
|
|
|
teamId, _ := c.GetInt("teamId")
|
|
|
|
|
|
|
|
|
|
teamMember, err := models.NewTeamMember().FindFirst(teamId, memberId)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JsonResult(5001, "用户不存在或已禁用")
|
|
|
|
|
}
|
|
|
|
|
err = teamMember.Delete(teamMember.TeamMemberId)
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JsonResult(5002, "删除失败")
|
|
|
|
|
}
|
|
|
|
|
c.JsonResult(0, "ok")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *ManagerController) TeamChangeMemberRole() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
memberId, _ := c.GetInt("memberId")
|
|
|
|
|
roleId, _ := c.GetInt("roleId")
|
|
|
|
|
teamId, _ := c.GetInt("teamId")
|
|
|
|
|
if memberId <= 0 || roleId <= 0 || teamId <= 0 || roleId > int(conf.BookObserver) {
|
|
|
|
|
c.JsonResult(5001, "参数错误")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
teamMember, err := models.NewTeamMember().ChangeRoleId(teamId, memberId, conf.BookRole(roleId))
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JsonResult(5002, err.Error())
|
|
|
|
|
} else {
|
|
|
|
|
c.JsonResult(0, "OK", teamMember)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 18:38:18 +08:00
|
|
|
|
//团队项目列表.
|
2018-11-05 18:50:01 +08:00
|
|
|
|
func (c *ManagerController) TeamBookList() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
c.TplName = "manager/team_book_list.tpl"
|
|
|
|
|
|
2018-11-06 18:38:18 +08:00
|
|
|
|
teamId, _ := strconv.Atoi(c.Ctx.Input.Param(":id"))
|
|
|
|
|
pageIndex, _ := c.GetInt("page", 0)
|
|
|
|
|
|
|
|
|
|
if teamId <= 0 {
|
|
|
|
|
c.JsonResult(5002, "团队标识不能为空")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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.NewTeamRelationship().FindToPager(teamId, pageIndex, conf.PageSize)
|
|
|
|
|
|
|
|
|
|
if err != nil && err != orm.ErrNoRows {
|
|
|
|
|
c.ShowErrorPage(500, err.Error())
|
|
|
|
|
}
|
|
|
|
|
if err == orm.ErrNoRows || len(teams) <= 0 {
|
|
|
|
|
c.Data["Result"] = template.JS("[]")
|
|
|
|
|
c.Data["PageHtml"] = ""
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if totalCount > 0 {
|
|
|
|
|
pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
|
|
|
|
|
c.Data["PageHtml"] = pager.HtmlPages()
|
|
|
|
|
} else {
|
|
|
|
|
c.Data["PageHtml"] = ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
b, err := json.Marshal(teams)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
beego.Error("编码 JSON 结果失败 ->", err)
|
|
|
|
|
c.Data["Result"] = template.JS("[]")
|
|
|
|
|
} else {
|
|
|
|
|
c.Data["Result"] = template.JS(string(b))
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
}
|
2018-11-06 18:38:18 +08:00
|
|
|
|
|
|
|
|
|
//给团队增加项目.
|
2018-11-05 18:50:01 +08:00
|
|
|
|
func (c *ManagerController) TeamBookAdd() {
|
|
|
|
|
c.Prepare()
|
2018-11-06 18:38:18 +08:00
|
|
|
|
|
|
|
|
|
teamId, _ := c.GetInt("teamId")
|
|
|
|
|
bookId, _ := c.GetInt("bookId")
|
|
|
|
|
|
|
|
|
|
if teamId <= 0 || bookId <= 0 {
|
|
|
|
|
c.JsonResult(500, "参数错误")
|
|
|
|
|
}
|
|
|
|
|
teamRel := models.NewTeamRelationship()
|
|
|
|
|
teamRel.BookId = bookId
|
|
|
|
|
teamRel.TeamId = teamId
|
|
|
|
|
|
|
|
|
|
err := teamRel.Save()
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JsonResult(5001, err.Error())
|
|
|
|
|
} else {
|
|
|
|
|
teamRel.Include()
|
|
|
|
|
c.JsonResult(0, "OK", teamRel)
|
|
|
|
|
}
|
2018-11-05 18:50:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-06 18:38:18 +08:00
|
|
|
|
//搜索未参与的项目.
|
|
|
|
|
func (c *ManagerController) TeamSearchBook() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
|
|
|
|
|
teamId, _ := c.GetInt("teamId")
|
|
|
|
|
keyword := strings.TrimSpace(c.GetString("q"))
|
|
|
|
|
|
|
|
|
|
if teamId <= 0 {
|
|
|
|
|
c.JsonResult(500, "参数错误")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
searchResult, err := models.NewTeamRelationship().FindNotJoinBookByName(teamId, keyword, 10)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JsonResult(500, err.Error())
|
|
|
|
|
}
|
|
|
|
|
c.JsonResult(0, "OK", searchResult)
|
|
|
|
|
|
|
|
|
|
}
|
2018-11-20 20:36:14 +08:00
|
|
|
|
|
|
|
|
|
//删除团队项目.
|
2018-11-05 18:50:01 +08:00
|
|
|
|
func (c *ManagerController) TeamBookDelete() {
|
|
|
|
|
c.Prepare()
|
2018-11-06 18:38:18 +08:00
|
|
|
|
teamRelationshipId, _ := c.GetInt("teamRelId")
|
|
|
|
|
|
|
|
|
|
if teamRelationshipId <= 0 {
|
|
|
|
|
c.JsonResult(500, "参数错误")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := models.NewTeamRelationship().Delete(teamRelationshipId)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
c.JsonResult(5001, "删除失败")
|
|
|
|
|
}
|
|
|
|
|
c.JsonResult(0, "OK")
|
2018-11-05 18:50:01 +08:00
|
|
|
|
}
|
2018-11-20 20:36:14 +08:00
|
|
|
|
|
2018-11-21 11:03:16 +08:00
|
|
|
|
//项目空间列表.
|
2018-11-20 20:36:14 +08:00
|
|
|
|
func (c *ManagerController) Itemsets() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
c.TplName = "manager/itemsets.tpl"
|
|
|
|
|
pageIndex, _ := c.GetInt("page", 0)
|
|
|
|
|
|
|
|
|
|
items, totalCount, err := models.NewItemsets().FindToPager(pageIndex, conf.PageSize)
|
|
|
|
|
|
|
|
|
|
if err != nil && err != orm.ErrNoRows {
|
|
|
|
|
c.ShowErrorPage(500, err.Error())
|
|
|
|
|
}
|
|
|
|
|
if err == orm.ErrNoRows || len(items) <= 0 {
|
|
|
|
|
c.Data["Lists"] = items
|
|
|
|
|
c.Data["PageHtml"] = ""
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if totalCount > 0 {
|
|
|
|
|
pager := pagination.NewPagination(c.Ctx.Request, totalCount, conf.PageSize, c.BaseUrl())
|
|
|
|
|
c.Data["PageHtml"] = pager.HtmlPages()
|
|
|
|
|
} else {
|
|
|
|
|
c.Data["PageHtml"] = ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.Data["Lists"] = items
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-21 11:03:16 +08:00
|
|
|
|
//编辑或添加项目空间.
|
2018-11-20 20:36:14 +08:00
|
|
|
|
func (c *ManagerController) ItemsetsEdit() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
itemId, _ := c.GetInt("itemId")
|
2018-11-20 20:55:04 +08:00
|
|
|
|
itemName := strings.TrimSpace(c.GetString("itemName"))
|
|
|
|
|
itemKey := strings.TrimSpace(c.GetString("itemKey"))
|
2018-11-20 20:36:14 +08:00
|
|
|
|
if itemName == "" || itemKey == "" {
|
|
|
|
|
c.JsonResult(5001, "参数错误")
|
|
|
|
|
}
|
|
|
|
|
var item *models.Itemsets
|
|
|
|
|
var err error
|
|
|
|
|
if itemId > 0 {
|
|
|
|
|
if item, err = models.NewItemsets().First(itemId); err != nil {
|
|
|
|
|
if err == orm.ErrNoRows {
|
2018-11-21 11:03:16 +08:00
|
|
|
|
c.JsonResult(5002, "项目空间不存在")
|
2018-11-20 20:36:14 +08:00
|
|
|
|
} else {
|
2018-11-21 11:03:16 +08:00
|
|
|
|
c.JsonResult(5003, "查询项目空间出错")
|
2018-11-20 20:36:14 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
item = models.NewItemsets()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item.ItemKey = itemKey
|
|
|
|
|
item.ItemName = itemName
|
|
|
|
|
item.MemberId = c.Member.MemberId
|
|
|
|
|
item.ModifyAt = c.Member.MemberId
|
|
|
|
|
|
|
|
|
|
if err := item.Save(); err != nil {
|
|
|
|
|
c.JsonResult(5004, err.Error())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.JsonResult(0, "OK")
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-21 11:03:16 +08:00
|
|
|
|
//删除项目空间.
|
2018-11-20 20:36:14 +08:00
|
|
|
|
func (c *ManagerController) ItemsetsDelete() {
|
|
|
|
|
c.Prepare()
|
|
|
|
|
itemId, _ := c.GetInt("itemId")
|
|
|
|
|
|
|
|
|
|
if err := models.NewItemsets().Delete(itemId); err != nil {
|
|
|
|
|
c.JsonResult(5001, err.Error())
|
|
|
|
|
}
|
|
|
|
|
c.JsonResult(0, "OK")
|
|
|
|
|
}
|