feat:实现项目集功能

This commit is contained in:
lifei6671
2018-11-20 20:36:14 +08:00
parent 4702334604
commit 91df6bb024
17 changed files with 1034 additions and 23 deletions

View File

@@ -144,6 +144,7 @@ func (c *BookController) SaveBook() {
enableShare := strings.TrimSpace(c.GetString("enable_share")) == "on"
isUseFirstDocument := strings.TrimSpace(c.GetString("is_use_first_document")) == "on"
autoSave := strings.TrimSpace(c.GetString("auto_save")) == "on"
itemId,_ := c.GetInt("itemId")
if strings.Count(description, "") > 500 {
c.JsonResult(6004, "项目描述不能大于500字")
@@ -157,6 +158,9 @@ func (c *BookController) SaveBook() {
c.JsonResult(6005, "最多允许添加10个标签")
}
}
if !models.NewItemsets().Exist(itemId) {
c.JsonResult(6006,"项目集不存在")
}
if editor != "markdown" && editor != "html" {
editor = "markdown"
}
@@ -170,6 +174,7 @@ func (c *BookController) SaveBook() {
book.HistoryCount = historyCount
book.IsDownload = 0
book.BookPassword = c.GetString("bPassword")
book.ItemId = itemId
if autoRelease {
book.AutoRelease = 1
@@ -432,6 +437,7 @@ func (c *BookController) Create() {
description := strings.TrimSpace(c.GetString("description", ""))
privatelyOwned, _ := strconv.Atoi(c.GetString("privately_owned"))
commentStatus := c.GetString("comment_status")
itemId, _ := c.GetInt("itemId")
if bookName == "" {
c.JsonResult(6001, "项目名称不能为空")
@@ -451,6 +457,9 @@ func (c *BookController) Create() {
if privatelyOwned != 0 && privatelyOwned != 1 {
privatelyOwned = 1
}
if !models.NewItemsets().Exist(itemId) {
c.JsonResult(6005, "项目集不存在")
}
if commentStatus != "open" && commentStatus != "closed" && commentStatus != "group_only" && commentStatus != "registered_only" {
commentStatus = "closed"
}
@@ -503,6 +512,7 @@ func (c *BookController) Create() {
book.IsUseFirstDocument = 1
book.IsDownload = 1
book.AutoRelease = 0
book.ItemId = itemId
book.Editor = "markdown"
book.Theme = "default"
@@ -563,6 +573,7 @@ func (c *BookController) Import() {
identify := strings.TrimSpace(c.GetString("identify"))
description := strings.TrimSpace(c.GetString("description", ""))
privatelyOwned, _ := strconv.Atoi(c.GetString("privately_owned"))
itemId, _ := c.GetInt("itemId")
if bookName == "" {
c.JsonResult(6001, "项目名称不能为空")
@@ -576,6 +587,9 @@ func (c *BookController) Import() {
if ok, err := regexp.MatchString(`^[a-z]+[a-zA-Z0-9_\-]*$`, identify); !ok || err != nil {
c.JsonResult(6003, "项目标识只能包含小写字母、数字,以及“-”和“_”符号,并且只能小写字母开头")
}
if !models.NewItemsets().Exist(itemId) {
c.JsonResult(6007, "项目集不存在")
}
if strings.Count(identify, "") > 50 {
c.JsonResult(6004, "文档标识不能超过50字")
}
@@ -612,6 +626,7 @@ func (c *BookController) Import() {
book.MemberId = c.Member.MemberId
book.CommentCount = 0
book.Version = time.Now().Unix()
book.ItemId = itemId
book.Editor = "markdown"
book.Theme = "default"
@@ -896,7 +911,7 @@ func (c *BookController) TeamDelete() {
teamId, _ := c.GetInt("teamId")
if teamId <= 0 {
c.JsonResult(5001,"参数错误")
c.JsonResult(5001, "参数错误")
}
book, err := c.IsPermission()
@@ -915,6 +930,7 @@ func (c *BookController) TeamDelete() {
c.JsonResult(0, "OK")
}
//团队搜索.
func (c *BookController) TeamSearch() {
c.Prepare()
@@ -928,7 +944,22 @@ func (c *BookController) TeamSearch() {
searchResult, err := models.NewTeamRelationship().FindNotJoinBookByBookIdentify(book.BookId, keyword, 10)
if err != nil {
c.JsonResult(500, err.Error())
c.JsonResult(500, err.Error(), searchResult)
}
c.JsonResult(0, "OK", searchResult)
}
//项目集搜索.
func (c *BookController) ItemsetsSearch() {
c.Prepare()
keyword := strings.TrimSpace(c.GetString("q"))
searchResult, err := models.NewItemsets().FindItemsetsByName(keyword, 10)
if err != nil {
c.JsonResult(500, err.Error(), searchResult)
}
c.JsonResult(0, "OK", searchResult)

View File

@@ -0,0 +1,87 @@
package controllers
import (
"github.com/lifei6671/mindoc/conf"
"github.com/lifei6671/mindoc/models"
"github.com/astaxie/beego/orm"
"github.com/lifei6671/mindoc/utils/pagination"
"github.com/astaxie/beego"
)
type ItemsetsController struct {
BaseController
}
func (c *ItemsetsController) Prepare() {
c.BaseController.Prepare()
//如果没有开启你们访问则跳转到登录
if !c.EnableAnonymous && c.Member == nil {
c.Redirect(conf.URLFor("AccountController.Login"), 302)
return
}
}
func (c *ItemsetsController) Index() {
c.Prepare()
c.TplName = "items/index.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())
}
c.Data["TotalPages"] = pageIndex
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
}
func (c *ItemsetsController) List() {
c.Prepare()
c.TplName = "items/list.tpl"
itemKey := c.Ctx.Input.Param(":key")
pageIndex, _ := c.GetInt("page", 1)
if itemKey == "" {
c.Abort("404")
}
item, err := models.NewItemsets().FindFirst(itemKey)
if err != nil {
if err == orm.ErrNoRows {
c.Abort("404")
} else {
beego.Error(err)
c.Abort("500")
}
}
memberId := 0
if c.Member != nil {
memberId = c.Member.MemberId
}
searchResult, totalCount, err := models.NewItemsets().FindItemsetsByItemKey(itemKey, pageIndex, conf.PageSize, memberId)
if err != nil && err != orm.ErrNoRows {
c.ShowErrorPage(500, "查询文档列表时出错")
}
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"] = searchResult
c.Data["Model"] = item
}

View File

@@ -1073,6 +1073,8 @@ func (c *ManagerController) TeamSearchBook() {
c.JsonResult(0, "OK", searchResult)
}
//删除团队项目.
func (c *ManagerController) TeamBookDelete() {
c.Prepare()
teamRelationshipId, _ := c.GetInt("teamRelId")
@@ -1088,3 +1090,78 @@ func (c *ManagerController) TeamBookDelete() {
}
c.JsonResult(0, "OK")
}
//项目集列表.
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
}
//编辑或添加项目集.
func (c *ManagerController) ItemsetsEdit() {
c.Prepare()
itemId, _ := c.GetInt("itemId")
itemName := c.GetString("itemName")
itemKey := c.GetString("itemKey")
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 {
c.JsonResult(5002, "项目集不存在")
} else {
c.JsonResult(5003, "查询项目集出错")
}
}
} 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")
}
//删除项目集.
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")
}