mirror of https://github.com/mindoc-org/mindoc.git
parent
d735ea27ca
commit
1a40caaa6c
|
@ -139,7 +139,7 @@ func (c *BookController) SaveBook() {
|
|||
bookName := strings.TrimSpace(c.GetString("book_name"))
|
||||
description := strings.TrimSpace(c.GetString("description", ""))
|
||||
commentStatus := c.GetString("comment_status")
|
||||
tag := strings.TrimSpace(c.GetString("label"))
|
||||
//tag := strings.TrimSpace(c.GetString("label"))
|
||||
editor := strings.TrimSpace(c.GetString("editor"))
|
||||
autoRelease := strings.TrimSpace(c.GetString("auto_release")) == "on"
|
||||
publisher := strings.TrimSpace(c.GetString("publisher"))
|
||||
|
@ -156,12 +156,7 @@ func (c *BookController) SaveBook() {
|
|||
if commentStatus != "open" && commentStatus != "closed" && commentStatus != "group_only" && commentStatus != "registered_only" {
|
||||
commentStatus = "closed"
|
||||
}
|
||||
if tag != "" {
|
||||
tags := strings.Split(tag, ",")
|
||||
if len(tags) > 10 {
|
||||
c.JsonResult(6005, "最多允许添加10个标签")
|
||||
}
|
||||
}
|
||||
|
||||
if !models.NewItemsets().Exist(itemId) {
|
||||
c.JsonResult(6006, "项目空间不存在")
|
||||
}
|
||||
|
@ -173,7 +168,7 @@ func (c *BookController) SaveBook() {
|
|||
book.Description = description
|
||||
book.CommentStatus = commentStatus
|
||||
book.Publisher = publisher
|
||||
book.Label = tag
|
||||
//book.Label = tag
|
||||
book.Editor = editor
|
||||
book.HistoryCount = historyCount
|
||||
book.IsDownload = 0
|
||||
|
@ -211,7 +206,6 @@ func (c *BookController) SaveBook() {
|
|||
bookResult.BookName = bookName
|
||||
bookResult.Description = description
|
||||
bookResult.CommentStatus = commentStatus
|
||||
bookResult.Label = tag
|
||||
|
||||
beego.Info("用户 [", c.Member.Account, "] 修改了项目 ->", book)
|
||||
|
||||
|
@ -646,49 +640,49 @@ func (c *BookController) Import() {
|
|||
}
|
||||
|
||||
// CreateToken 创建访问来令牌.
|
||||
func (c *BookController) CreateToken() {
|
||||
|
||||
action := c.GetString("action")
|
||||
|
||||
bookResult, err := c.IsPermission()
|
||||
|
||||
if err != nil {
|
||||
if err == models.ErrPermissionDenied {
|
||||
c.JsonResult(403, "权限不足")
|
||||
}
|
||||
if err == orm.ErrNoRows {
|
||||
c.JsonResult(404, "项目不存在")
|
||||
}
|
||||
logs.Error("生成阅读令牌失败 =>", err)
|
||||
c.JsonResult(6002, err.Error())
|
||||
}
|
||||
book := models.NewBook()
|
||||
|
||||
if _, err := book.Find(bookResult.BookId); err != nil {
|
||||
c.JsonResult(6001, "项目不存在")
|
||||
}
|
||||
if action == "create" {
|
||||
if bookResult.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, "生成阅读令牌失败")
|
||||
}
|
||||
beego.Info("用户[", c.Member.Account, "]创建项目令牌 ->", book.PrivateToken)
|
||||
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, "删除令牌失败")
|
||||
}
|
||||
beego.Info("用户[", c.Member.Account, "]创建项目令牌 ->", book.PrivateToken)
|
||||
c.JsonResult(0, "ok", "")
|
||||
}
|
||||
}
|
||||
//func (c *BookController) CreateToken() {
|
||||
//
|
||||
// action := c.GetString("action")
|
||||
//
|
||||
// bookResult, err := c.IsPermission()
|
||||
//
|
||||
// if err != nil {
|
||||
// if err == models.ErrPermissionDenied {
|
||||
// c.JsonResult(403, "权限不足")
|
||||
// }
|
||||
// if err == orm.ErrNoRows {
|
||||
// c.JsonResult(404, "项目不存在")
|
||||
// }
|
||||
// logs.Error("生成阅读令牌失败 =>", err)
|
||||
// c.JsonResult(6002, err.Error())
|
||||
// }
|
||||
// book := models.NewBook()
|
||||
//
|
||||
// if _, err := book.Find(bookResult.BookId); err != nil {
|
||||
// c.JsonResult(6001, "项目不存在")
|
||||
// }
|
||||
// if action == "create" {
|
||||
// if bookResult.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, "生成阅读令牌失败")
|
||||
// }
|
||||
// beego.Info("用户[", c.Member.Account, "]创建项目令牌 ->", book.PrivateToken)
|
||||
// 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, "删除令牌失败")
|
||||
// }
|
||||
// beego.Info("用户[", c.Member.Account, "]创建项目令牌 ->", book.PrivateToken)
|
||||
// c.JsonResult(0, "ok", "")
|
||||
// }
|
||||
//}
|
||||
|
||||
// Delete 删除项目.
|
||||
func (c *BookController) Delete() {
|
||||
|
|
|
@ -40,6 +40,7 @@ func (c *SearchController) Index() {
|
|||
searchResult, totalCount, err := models.NewDocumentSearchResult().FindToPager(sqltil.EscapeLike(keyword), pageIndex, conf.PageSize, memberId)
|
||||
|
||||
if err != nil {
|
||||
beego.Error("搜索失败 ->",err)
|
||||
return
|
||||
}
|
||||
if totalCount > 0 {
|
||||
|
|
|
@ -60,15 +60,33 @@ FROM (
|
|||
LEFT JOIN md_members AS member ON rel.member_id = member.member_id
|
||||
WHERE book.privately_owned = 0 AND (doc.document_name LIKE ? OR doc.release LIKE ?)
|
||||
UNION ALL
|
||||
SELECT
|
||||
book.book_id AS document_id,
|
||||
book.modify_time,
|
||||
book.create_time,
|
||||
book.book_name AS document_name,
|
||||
book.identify,
|
||||
book.description,
|
||||
book.identify AS book_identify,
|
||||
book.book_name,
|
||||
rel.member_id,
|
||||
member.account AS author,
|
||||
'book' AS search_type
|
||||
FROM md_books AS book
|
||||
LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0
|
||||
LEFT JOIN md_members AS member ON rel.member_id = member.member_id
|
||||
WHERE book.privately_owned = 0 AND (book.book_name LIKE ? OR book.description LIKE ?)
|
||||
|
||||
UNION ALL
|
||||
SELECT
|
||||
blog.blog_id,
|
||||
blog.blog_id AS document_id,
|
||||
blog.modify_time,
|
||||
blog.create_time,
|
||||
blog.blog_title,
|
||||
blog.blog_title as document_name,
|
||||
blog.blog_identify,
|
||||
blog.blog_release,
|
||||
blog.blog_identify,
|
||||
blog.blog_title,
|
||||
blog.blog_title as book_name,
|
||||
blog.member_id,
|
||||
member.account,
|
||||
'blog' AS search_type
|
||||
|
@ -97,8 +115,19 @@ LIMIT ?, ?;`
|
|||
}
|
||||
|
||||
totalCount += c
|
||||
//查询项目的数量
|
||||
sql4 := `SELECT count(*) as total_count FROM md_books as book
|
||||
WHERE book.privately_owned = 0 AND (book.book_name LIKE ? OR book.description LIKE ?);`
|
||||
|
||||
_, err = o.Raw(sql2, keyword, keyword,keyword,keyword, offset, pageSize).QueryRows(&searchResult)
|
||||
err = o.Raw(sql4, keyword, keyword).QueryRow(&c)
|
||||
if err != nil {
|
||||
beego.Error("查询搜索结果失败 -> ",err)
|
||||
return
|
||||
}
|
||||
|
||||
totalCount += c
|
||||
|
||||
_, err = o.Raw(sql2, keyword, keyword,keyword,keyword,keyword,keyword, offset, pageSize).QueryRows(&searchResult)
|
||||
if err != nil {
|
||||
beego.Error("查询搜索结果失败 -> ",err)
|
||||
return
|
||||
|
@ -112,7 +141,7 @@ LIMIT ?, ?;`
|
|||
from md_team_relationship as mtr
|
||||
left join md_team_member as mtm on mtm.team_id=mtr.team_id and mtm.member_id=? order by role_id desc )as t group by t.role_id,t.team_member_id,t.book_id) as team
|
||||
on team.book_id = book.book_id
|
||||
WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0 or team.team_member_id > 0) AND (doc.document_name LIKE ? OR doc.release LIKE ?) `
|
||||
WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0 or team.team_member_id > 0) AND (doc.document_name LIKE ? OR doc.release LIKE ?);`
|
||||
|
||||
sql2 := `SELECT *
|
||||
FROM (
|
||||
|
@ -148,14 +177,43 @@ FROM (
|
|||
UNION ALL
|
||||
|
||||
SELECT
|
||||
blog.blog_id,
|
||||
book.book_id AS document_id,
|
||||
book.modify_time,
|
||||
book.create_time,
|
||||
book.book_name AS document_name,
|
||||
book.identify,
|
||||
book.description AS description,
|
||||
book.identify AS book_identify,
|
||||
book.book_name,
|
||||
rel.member_id,
|
||||
member.account AS author,
|
||||
'book' AS search_type
|
||||
FROM md_books AS book
|
||||
LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0
|
||||
LEFT JOIN md_members AS member ON rel.member_id = member.member_id
|
||||
LEFT JOIN md_relationship AS rel1 ON book.book_id = rel1.book_id AND rel1.member_id = ?
|
||||
LEFT JOIN (SELECT *
|
||||
FROM (SELECT
|
||||
book_id,
|
||||
team_member_id,
|
||||
role_id
|
||||
FROM md_team_relationship AS mtr
|
||||
LEFT JOIN md_team_member AS mtm ON mtm.team_id = mtr.team_id AND mtm.member_id = ?
|
||||
ORDER BY role_id DESC) AS t
|
||||
GROUP BY t.role_id, t.team_member_id, t.book_id) AS team
|
||||
ON team.book_id = book.book_id
|
||||
WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0 OR team.team_member_id > 0) AND
|
||||
(book.book_name LIKE ? OR book.description LIKE ?)
|
||||
UNION ALL
|
||||
SELECT
|
||||
blog.blog_id AS document_id,
|
||||
blog.modify_time,
|
||||
blog.create_time,
|
||||
blog.blog_title,
|
||||
blog.blog_identify,
|
||||
blog.blog_release,
|
||||
blog.blog_identify,
|
||||
blog.blog_title,
|
||||
blog.blog_title as document_name,
|
||||
blog.blog_identify as identify,
|
||||
blog.blog_release as description,
|
||||
blog.blog_identify AS book_identify,
|
||||
blog.blog_title as book_name,
|
||||
blog.member_id,
|
||||
member.account,
|
||||
'blog' AS search_type
|
||||
|
@ -185,7 +243,25 @@ LIMIT ?, ?;`
|
|||
}
|
||||
|
||||
totalCount += c
|
||||
_, err = o.Raw(sql2, memberId, memberId, keyword, keyword,memberId,keyword, keyword, offset, pageSize).QueryRows(&searchResult)
|
||||
|
||||
sql4 := `SELECT count(*) as total_count FROM md_books as book
|
||||
LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0
|
||||
LEFT JOIN md_relationship AS rel1 ON book.book_id = rel1.book_id AND rel1.member_id = ?
|
||||
left join (select * from (select book_id,team_member_id,role_id
|
||||
from md_team_relationship as mtr
|
||||
left join md_team_member as mtm on mtm.team_id=mtr.team_id and mtm.member_id=? order by role_id desc )as t group by t.role_id,t.team_member_id,t.book_id) as team
|
||||
on team.book_id = book.book_id
|
||||
WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0 or team.team_member_id > 0) AND (book.book_name LIKE ? OR book.description LIKE ?);`
|
||||
|
||||
err = o.Raw(sql4,memberId, memberId,keyword, keyword).QueryRow(&c)
|
||||
if err != nil {
|
||||
beego.Error("查询搜索结果失败 -> ",err)
|
||||
return
|
||||
}
|
||||
|
||||
totalCount += c
|
||||
|
||||
_, err = o.Raw(sql2, memberId, memberId, keyword, keyword,memberId,memberId,keyword, keyword,memberId,keyword, keyword,offset, pageSize).QueryRows(&searchResult)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -194,13 +270,13 @@ LIMIT ?, ?;`
|
|||
}
|
||||
|
||||
//项目内搜索.
|
||||
func (m *DocumentSearchResult) SearchDocument(keyword string, book_id int) (docs []*DocumentSearchResult, err error) {
|
||||
func (m *DocumentSearchResult) SearchDocument(keyword string, bookId int) (docs []*DocumentSearchResult, err error) {
|
||||
o := orm.NewOrm()
|
||||
|
||||
sql := "SELECT * FROM md_documents WHERE book_id = ? AND (document_name LIKE ? OR `release` LIKE ?) "
|
||||
keyword = "%" + keyword + "%"
|
||||
|
||||
_, err = o.Raw(sql, book_id, keyword, keyword).QueryRows(&docs)
|
||||
_, err = o.Raw(sql, bookId, keyword, keyword).QueryRows(&docs)
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -88,7 +88,6 @@ func init() {
|
|||
beego.Router("/book/setting/open", &controllers.BookController{}, "post:PrivatelyOwned")
|
||||
beego.Router("/book/setting/transfer", &controllers.BookController{}, "post:Transfer")
|
||||
beego.Router("/book/setting/upload", &controllers.BookController{}, "post:UploadCover")
|
||||
beego.Router("/book/setting/token", &controllers.BookController{}, "post:CreateToken")
|
||||
beego.Router("/book/setting/delete", &controllers.BookController{}, "post:Delete")
|
||||
|
||||
beego.Router("/book/team/add", &controllers.BookController{}, "POST:TeamAdd")
|
||||
|
|
|
@ -441,6 +441,19 @@ textarea{
|
|||
font-size: 16px;
|
||||
font-weight: 400;
|
||||
}
|
||||
.manual-search-reader .search-item .title .label{
|
||||
color: #fff;
|
||||
padding-top: .3em;
|
||||
}
|
||||
.manual-search-reader .search-item .title .mark-book{
|
||||
background-color: #009a61;
|
||||
}
|
||||
.manual-search-reader .search-item .title .mark-blog{
|
||||
background-color: #0084FF;
|
||||
}
|
||||
.manual-search-reader .search-item .title .mark-doc{
|
||||
background-color: #337ab7;
|
||||
}
|
||||
.manual-search-reader .search-item .description{
|
||||
color: #666;
|
||||
line-height: 25px;
|
||||
|
|
|
@ -82,11 +82,6 @@
|
|||
<textarea rows="3" class="form-control" name="description" style="height: 90px" placeholder="项目描述">{{.Model.Description}}</textarea>
|
||||
<p class="text">描述信息不超过500个字符,支持Markdown语法</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>标签</label>
|
||||
<input type="text" class="form-control" name="label" placeholder="项目标签" value="{{.Model.Label}}">
|
||||
<p class="text">最多允许添加10个标签,多个标签请用“,”分割</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>编辑器</label>
|
||||
<div class="radio">
|
||||
|
@ -99,18 +94,6 @@
|
|||
</div>
|
||||
</div>
|
||||
{{if eq .Model.PrivatelyOwned 1}}
|
||||
<div class="form-group">
|
||||
<label>访问令牌</label>
|
||||
<div class="row">
|
||||
<div class="col-sm-10">
|
||||
<input type="text" name="token" id="token" class="form-control" placeholder="访问令牌" readonly value="{{.Model.PrivateToken}}">
|
||||
</div>
|
||||
<div class="col-sm-2">
|
||||
<button type="button" class="btn btn-success btn-sm" id="createToken" data-loading-text="生成" data-action="create">生成</button>
|
||||
<button type="button" class="btn btn-danger btn-sm" id="deleteToken" data-loading-text="删除" data-action="delete">删除</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>访问密码</label>
|
||||
<input type="text" name="bPassword" id="bPassword" class="form-control" placeholder="访问密码" value="{{.Model.BookPassword}}">
|
||||
|
|
|
@ -27,9 +27,14 @@
|
|||
<div class="search-item">
|
||||
<div class="title">
|
||||
{{if eq $item.SearchType "document"}}
|
||||
<span class="label mark-doc">文档</span>
|
||||
<a href="{{urlfor "DocumentController.Read" ":key" $item.BookIdentify ":id" $item.Identify}}" title="{{$item.DocumentName}}" target="_blank">{{str2html $item.DocumentName}}</a>
|
||||
{{else if eq $item.SearchType "book"}}
|
||||
<span class="label mark-book">项目</span>
|
||||
<a href="{{urlfor "DocumentController.Index" ":key" $item.Identify}}" title="{{$item.BookName}}" target="_blank"> {{str2html $item.DocumentName}}</a>
|
||||
{{else}}
|
||||
<a href="{{urlfor "BlogController.Index" ":id" $item.DocumentId}}" title="{{$item.DocumentName}}" target="_blank">{{str2html $item.DocumentName}}</a>
|
||||
<span class="label mark-blog">文章</span>
|
||||
<a href="{{urlfor "BlogController.Index" ":id" $item.DocumentId}}" title="{{$item.DocumentName}}" target="_blank"> {{str2html $item.DocumentName}}</a>
|
||||
{{end}}
|
||||
</div>
|
||||
<div class="description">
|
||||
|
@ -38,6 +43,8 @@
|
|||
<div class="source">
|
||||
{{if eq $item.SearchType "document"}}
|
||||
<span class="item">来自项目:<a href="{{urlfor "DocumentController.Index" ":key" $item.BookIdentify}}" target="_blank">{{$item.BookName}}</a></span>
|
||||
{{else if eq $item.SearchType "book"}}
|
||||
<span class="item">项目:<a href="{{urlfor "DocumentController.Index" ":key" $item.Identify}}" target="_blank">{{$item.BookName}}</a></span>
|
||||
{{else}}
|
||||
<span class="item">来自文章:<a href="{{urlfor "BlogController.Index" ":id" $item.DocumentId}}" target="_blank">{{$item.BookName}}</a></span>
|
||||
{{end}}
|
||||
|
|
Loading…
Reference in New Issue