Merge branch 'master' into master

pull/790/head
玖亖伍 2022-05-09 18:19:08 +08:00 committed by GitHub
commit a5dfdb4b6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 366 additions and 88 deletions

View File

@ -111,6 +111,7 @@ func RegisterModel() {
new(models.TeamMember), new(models.TeamMember),
new(models.TeamRelationship), new(models.TeamRelationship),
new(models.Itemsets), new(models.Itemsets),
new(models.Comment),
new(models.WorkWeixinAccount), new(models.WorkWeixinAccount),
) )
gob.Register(models.Blog{}) gob.Register(models.Blog{})

View File

@ -518,7 +518,6 @@ func (c *BookController) Create() {
book.Identify = identify book.Identify = identify
book.DocCount = 0 book.DocCount = 0
book.MemberId = c.Member.MemberId book.MemberId = c.Member.MemberId
book.CommentCount = 0
book.Version = time.Now().Unix() book.Version = time.Now().Unix()
book.IsEnableShare = 0 book.IsEnableShare = 0
book.IsUseFirstDocument = 1 book.IsUseFirstDocument = 1
@ -636,7 +635,6 @@ func (c *BookController) Import() {
book.Identify = identify book.Identify = identify
book.DocCount = 0 book.DocCount = 0
book.MemberId = c.Member.MemberId book.MemberId = c.Member.MemberId
book.CommentCount = 0
book.Version = time.Now().Unix() book.Version = time.Now().Unix()
book.ItemId = itemId book.ItemId = itemId

View File

@ -0,0 +1,97 @@
package controllers
import (
"strings"
"time"
"github.com/mindoc-org/mindoc/conf"
"github.com/mindoc-org/mindoc/models"
"github.com/mindoc-org/mindoc/utils/pagination"
)
type CommentController struct {
BaseController
}
func (c *CommentController) Lists() {
docid, _ := c.GetInt("docid", 0)
pageIndex, _ := c.GetInt("page", 1)
// 获取评论、分页
comments, count, pageIndex := models.NewComment().QueryCommentByDocumentId(docid, pageIndex, conf.PageSize, c.Member)
page := pagination.PageUtil(int(count), pageIndex, conf.PageSize, comments)
var data struct {
DocId int `json:"doc_id"`
Page pagination.Page `json:"page"`
}
data.DocId = docid
data.Page = page
c.JsonResult(0, "ok", data)
return
}
func (c *CommentController) Create() {
content := c.GetString("content")
id, _ := c.GetInt("doc_id")
_, err := models.NewDocument().Find(id)
if err != nil {
c.JsonResult(1, "文章不存在")
}
m := models.NewComment()
m.DocumentId = id
if len(c.Member.RealName) != 0 {
m.Author = c.Member.RealName
} else {
m.Author = c.Member.Account
}
m.MemberId = c.Member.MemberId
m.IPAddress = c.Ctx.Request.RemoteAddr
m.IPAddress = strings.Split(m.IPAddress, ":")[0]
m.CommentDate = time.Now()
m.Content = content
m.Insert()
var data struct {
DocId int `json:"doc_id"`
}
data.DocId = id
c.JsonResult(0, "ok", data)
}
func (c *CommentController) Index() {
c.Prepare()
c.TplName = "comment/index.tpl"
}
func (c *CommentController) Delete() {
if c.Ctx.Input.IsPost() {
id, _ := c.GetInt("id", 0)
m, err := models.NewComment().Find(id)
if err != nil {
c.JsonResult(1, "评论不存在")
}
doc, err := models.NewDocument().Find(m.DocumentId)
if err != nil {
c.JsonResult(1, "文章不存在")
}
// 判断是否有权限删除
bookRole, _ := models.NewRelationship().FindForRoleId(doc.BookId, c.Member.MemberId)
if m.CanDelete(c.Member.MemberId, bookRole) {
err := m.Delete()
if err != nil {
c.JsonResult(1, "删除错误")
} else {
c.JsonResult(0, "ok")
}
} else {
c.JsonResult(1, "没有权限删除")
}
}
}

View File

@ -1,19 +0,0 @@
package controllers
type CommentController struct {
BaseController
}
func (c *CommentController) Lists() {
}
func (c *CommentController) Create() {
c.JsonResult(0, "ok")
}
func (c *CommentController) Index() {
c.Prepare()
c.TplName = "comment/index.tpl"
}

View File

@ -541,7 +541,7 @@ WHERE book.privately_owned = 0 or rel.role_id >=0 or team.role_id >=0`
if err != nil { if err != nil {
return return
} }
sql2 := `SELECT book.*,rel1.*,member.account AS create_name,member.real_name FROM md_books AS book sql2 := `SELECT book.*,rel1.*,mdmb.account AS create_name,mdmb.real_name FROM md_books AS book
LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.member_id = ? LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.member_id = ?
left join (select book_id,min(role_id) AS role_id left join (select book_id,min(role_id) AS role_id
from (select book_id,role_id from (select book_id,role_id
@ -549,7 +549,7 @@ WHERE book.privately_owned = 0 or rel.role_id >=0 or team.role_id >=0`
left join md_team_member as mtm on mtm.team_id=mtr.team_id and mtm.member_id=? order by role_id desc ) 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 book_id) as team on team.book_id=book.book_id as t group by book_id) as team on team.book_id=book.book_id
LEFT JOIN md_relationship AS rel1 ON rel1.book_id = book.book_id AND rel1.role_id = 0 LEFT JOIN md_relationship AS rel1 ON rel1.book_id = book.book_id AND rel1.role_id = 0
LEFT JOIN md_members AS member ON rel1.member_id = member.member_id LEFT JOIN md_members AS mdmb ON rel1.member_id = mdmb.member_id
WHERE book.privately_owned = 0 or rel.role_id >=0 or team.role_id >=0 ORDER BY order_index desc,book.book_id DESC LIMIT ?,?` WHERE book.privately_owned = 0 or rel.role_id >=0 or team.role_id >=0 ORDER BY order_index desc,book.book_id DESC LIMIT ?,?`
_, err = o.Raw(sql2, memberId, memberId, offset, pageSize).QueryRows(&books) _, err = o.Raw(sql2, memberId, memberId, offset, pageSize).QueryRows(&books)
@ -563,9 +563,9 @@ WHERE book.privately_owned = 0 or rel.role_id >=0 or team.role_id >=0 ORDER BY o
} }
totalCount = int(count) totalCount = int(count)
sql := `SELECT book.*,rel.*,member.account AS create_name,member.real_name FROM md_books AS book sql := `SELECT book.*,rel.*,mdmb.account AS create_name,mdmb.real_name FROM md_books AS book
LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.role_id = 0 LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.role_id = 0
LEFT JOIN md_members AS member ON rel.member_id = member.member_id LEFT JOIN md_members AS mdmb ON rel.member_id = mdmb.member_id
WHERE book.privately_owned = 0 ORDER BY order_index DESC ,book.book_id DESC LIMIT ?,?` WHERE book.privately_owned = 0 ORDER BY order_index DESC ,book.book_id DESC LIMIT ?,?`
_, err = o.Raw(sql, offset, pageSize).QueryRows(&books) _, err = o.Raw(sql, offset, pageSize).QueryRows(&books)
@ -595,14 +595,14 @@ WHERE (relationship_id > 0 OR book.privately_owned = 0 or team.team_member_id >
if err != nil { if err != nil {
return return
} }
sql2 := `SELECT book.*,rel1.*,member.account AS create_name FROM md_books AS book sql2 := `SELECT book.*,rel1.*,mdmb.account AS create_name FROM md_books AS book
LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.member_id = ? LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.member_id = ?
left join (select * from (select book_id,team_member_id,role_id left join (select * from (select book_id,team_member_id,role_id
from md_team_relationship as mtr 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 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 on team.book_id = book.book_id
LEFT JOIN md_relationship AS rel1 ON rel1.book_id = book.book_id AND rel1.role_id = 0 LEFT JOIN md_relationship AS rel1 ON rel1.book_id = book.book_id AND rel1.role_id = 0
LEFT JOIN md_members AS member ON rel1.member_id = member.member_id LEFT JOIN md_members AS mdmb ON rel1.member_id = mdmb.member_id
WHERE (rel.relationship_id > 0 OR book.privately_owned = 0 or team.team_member_id > 0) WHERE (rel.relationship_id > 0 OR book.privately_owned = 0 or team.team_member_id > 0)
AND book.label LIKE ? ORDER BY order_index DESC ,book.book_id DESC LIMIT ?,?` AND book.label LIKE ? ORDER BY order_index DESC ,book.book_id DESC LIMIT ?,?`
@ -619,9 +619,9 @@ WHERE (relationship_id > 0 OR book.privately_owned = 0 or team.team_member_id >
} }
totalCount = int(count) totalCount = int(count)
sql := `SELECT book.*,rel.*,member.account AS create_name FROM md_books AS book sql := `SELECT book.*,rel.*,mdmb.account AS create_name FROM md_books AS book
LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.role_id = 0 LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.role_id = 0
LEFT JOIN md_members AS member ON rel.member_id = member.member_id LEFT JOIN md_members AS mdmb ON rel.member_id = mdmb.member_id
WHERE book.privately_owned = 0 AND book.label LIKE ? ORDER BY order_index DESC ,book.book_id DESC LIMIT ?,?` WHERE book.privately_owned = 0 AND book.label LIKE ? ORDER BY order_index DESC ,book.book_id DESC LIMIT ?,?`
_, err = o.Raw(sql, keyword, offset, pageSize).QueryRows(&books) _, err = o.Raw(sql, keyword, offset, pageSize).QueryRows(&books)

View File

@ -240,6 +240,17 @@ func (m *BookResult) ToBookResult(book Book) *BookResult {
m.ItemName = item.ItemName m.ItemName = item.ItemName
} }
} }
if m.CommentStatus == "closed" {
m.IsDisplayComment = false
} else if m.CommentStatus == "open" {
m.IsDisplayComment = true
} else if m.CommentStatus == "registered_only" {
// todo
} else if m.CommentStatus == "group_only" {
// todo
} else {
m.IsDisplayComment = false;
}
return m return m
} }

View File

@ -33,6 +33,8 @@ type Comment struct {
ParentId int `orm:"column(parent_id);type(int);default(0)" json:"parent_id"` ParentId int `orm:"column(parent_id);type(int);default(0)" json:"parent_id"`
AgreeCount int `orm:"column(agree_count);type(int);default(0)" json:"agree_count"` AgreeCount int `orm:"column(agree_count);type(int);default(0)" json:"agree_count"`
AgainstCount int `orm:"column(against_count);type(int);default(0)" json:"against_count"` AgainstCount int `orm:"column(against_count);type(int);default(0)" json:"against_count"`
Index int `orm:"-" json:"index"`
ShowDel int `orm:"-" json:"show_del"`
} }
// TableName 获取对应数据库表名. // TableName 获取对应数据库表名.
@ -52,14 +54,41 @@ func (m *Comment) TableNameWithPrefix() string {
func NewComment() *Comment { func NewComment() *Comment {
return &Comment{} return &Comment{}
} }
func (m *Comment) Find(id int) (*Comment, error) {
if id <= 0 {
return m, ErrInvalidParameter
}
o := orm.NewOrm()
err := o.Read(m)
return m, err // 是否有权限删除
func (m *Comment) CanDelete(user_memberid int, user_bookrole conf.BookRole) bool {
return user_memberid == m.MemberId || user_bookrole == conf.BookFounder || user_bookrole == conf.BookAdmin
}
// 根据文档id查询文档评论
func (m *Comment) QueryCommentByDocumentId(doc_id, page, pagesize int, member *Member) (comments []Comment, count int64, ret_page int) {
doc, err := NewDocument().Find(doc_id)
if err != nil {
return
}
o := orm.NewOrm()
count, _ = o.QueryTable(m.TableNameWithPrefix()).Filter("document_id", doc_id).Count()
if -1 == page { // 请求最后一页
var total int = int(count)
if total % pagesize == 0 {
page = total / pagesize
} else {
page = total / pagesize + 1
}
}
offset := (page - 1) * pagesize
ret_page = page
o.QueryTable(m.TableNameWithPrefix()).Filter("document_id", doc_id).OrderBy("comment_date").Offset(offset).Limit(pagesize).All(&comments)
bookRole, _ := NewRelationship().FindForRoleId(doc.BookId, member.MemberId)
for i := 0; i < len(comments); i++ {
comments[i].Index = (i + 1) + (page - 1) * pagesize
if comments[i].CanDelete(member.MemberId, bookRole) {
comments[i].ShowDel = 1
}
}
return
} }
func (m *Comment) Update(cols ...string) error { func (m *Comment) Update(cols ...string) error {
@ -135,3 +164,18 @@ func (m *Comment) Insert() error {
return err return err
} }
// 删除一条评论
func (m *Comment) Delete() error {
o := orm.NewOrm()
_, err := o.Delete(m)
return err
}
func (m *Comment) Find(id int, cols ...string) (*Comment, error) {
o := orm.NewOrm()
if err := o.QueryTable(m.TableNameWithPrefix()).Filter("comment_id", id).One(m, cols...); err != nil {
return m, err
}
return m, nil
}

View File

@ -53,12 +53,12 @@ FROM (
book.identify AS book_identify, book.identify AS book_identify,
book.book_name, book.book_name,
rel.member_id, rel.member_id,
member.account AS author, mdmb.account AS author,
'document' AS search_type 'document' AS search_type
FROM md_documents AS doc FROM md_documents AS doc
LEFT JOIN md_books AS book ON doc.book_id = book.book_id LEFT JOIN md_books AS book ON doc.book_id = book.book_id
LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0 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_members AS mdmb ON rel.member_id = mdmb.member_id
WHERE book.privately_owned = 0 AND (doc.document_name LIKE ? OR doc.release LIKE ?) WHERE book.privately_owned = 0 AND (doc.document_name LIKE ? OR doc.release LIKE ?)
UNION ALL UNION ALL
SELECT SELECT
@ -71,11 +71,11 @@ SELECT
book.identify AS book_identify, book.identify AS book_identify,
book.book_name, book.book_name,
rel.member_id, rel.member_id,
member.account AS author, mdmb.account AS author,
'book' AS search_type 'book' AS search_type
FROM md_books AS book 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 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_members AS mdmb ON rel.member_id = mdmb.member_id
WHERE book.privately_owned = 0 AND (book.book_name LIKE ? OR book.description LIKE ?) WHERE book.privately_owned = 0 AND (book.book_name LIKE ? OR book.description LIKE ?)
UNION ALL UNION ALL
@ -89,10 +89,10 @@ WHERE book.privately_owned = 0 AND (book.book_name LIKE ? OR book.description LI
blog.blog_identify, blog.blog_identify,
blog.blog_title as book_name, blog.blog_title as book_name,
blog.member_id, blog.member_id,
member.account, mdmb.account,
'blog' AS search_type 'blog' AS search_type
FROM md_blogs AS blog FROM md_blogs AS blog
LEFT JOIN md_members AS member ON blog.member_id = member.member_id LEFT JOIN md_members AS mdmb ON blog.member_id = mdmb.member_id
WHERE blog.blog_status = 'public' AND (blog.blog_release LIKE ? OR blog.blog_title LIKE ?) WHERE blog.blog_status = 'public' AND (blog.blog_release LIKE ? OR blog.blog_title LIKE ?)
) AS union_table ) AS union_table
ORDER BY create_time DESC ORDER BY create_time DESC
@ -156,12 +156,12 @@ FROM (
book.identify AS book_identify, book.identify AS book_identify,
book.book_name, book.book_name,
rel.member_id, rel.member_id,
member.account AS author, mdmb.account AS author,
'document' AS search_type 'document' AS search_type
FROM md_documents AS doc FROM md_documents AS doc
LEFT JOIN md_books AS book ON doc.book_id = book.book_id LEFT JOIN md_books AS book ON doc.book_id = book.book_id
LEFT JOIN md_relationship AS rel ON book.book_id = rel.book_id AND rel.role_id = 0 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_members AS mdmb ON rel.member_id = mdmb.member_id
LEFT JOIN md_relationship AS rel1 ON doc.book_id = rel1.book_id AND rel1.member_id = ? LEFT JOIN md_relationship AS rel1 ON doc.book_id = rel1.book_id AND rel1.member_id = ?
LEFT JOIN (SELECT * LEFT JOIN (SELECT *
FROM (SELECT FROM (SELECT
@ -187,11 +187,11 @@ FROM (
book.identify AS book_identify, book.identify AS book_identify,
book.book_name, book.book_name,
rel.member_id, rel.member_id,
member.account AS author, mdmb.account AS author,
'book' AS search_type 'book' AS search_type
FROM md_books AS book 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 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_members AS mdmb ON rel.member_id = mdmb.member_id
LEFT JOIN md_relationship AS rel1 ON book.book_id = rel1.book_id AND rel1.member_id = ? LEFT JOIN md_relationship AS rel1 ON book.book_id = rel1.book_id AND rel1.member_id = ?
LEFT JOIN (SELECT * LEFT JOIN (SELECT *
FROM (SELECT FROM (SELECT
@ -216,10 +216,10 @@ FROM (
blog.blog_identify AS book_identify, blog.blog_identify AS book_identify,
blog.blog_title as book_name, blog.blog_title as book_name,
blog.member_id, blog.member_id,
member.account, mdmb.account,
'blog' AS search_type 'blog' AS search_type
FROM md_blogs AS blog FROM md_blogs AS blog
LEFT JOIN md_members AS member ON blog.member_id = member.member_id LEFT JOIN md_members AS mdmb ON blog.member_id = mdmb.member_id
WHERE (blog.blog_status = 'public' OR blog.member_id = ?) AND blog.blog_type = 0 AND WHERE (blog.blog_status = 'public' OR blog.member_id = ?) AND blog.blog_type = 0 AND
(blog.blog_release LIKE ? OR blog.blog_title LIKE ?) (blog.blog_release LIKE ? OR blog.blog_title LIKE ?)
) AS union_table ) AS union_table

View File

@ -236,7 +236,7 @@ WHERE book.item_id = ? AND (book.privately_owned = 0 or rel.role_id >= 0 or team
logs.Error("查询项目空间时出错 ->", key, err) logs.Error("查询项目空间时出错 ->", key, err)
return return
} }
sql2 := `SELECT book.*,rel1.*,member.account AS create_name FROM md_books AS book sql2 := `SELECT book.*,rel1.*,mdmb.account AS create_name FROM md_books AS book
LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.member_id = ? LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.member_id = ?
left join (select book_id,min(role_id) as role_id from (select book_id,role_id left join (select book_id,min(role_id) as role_id from (select book_id,role_id
from md_team_relationship as mtr from md_team_relationship as mtr
@ -244,7 +244,7 @@ WHERE book.item_id = ? AND (book.privately_owned = 0 or rel.role_id >= 0 or team
as t group by book_id) as team as t group by book_id) as team
on team.book_id = book.book_id on team.book_id = book.book_id
LEFT JOIN md_relationship AS rel1 ON rel1.book_id = book.book_id AND rel1.role_id = 0 LEFT JOIN md_relationship AS rel1 ON rel1.book_id = book.book_id AND rel1.role_id = 0
LEFT JOIN md_members AS member ON rel1.member_id = member.member_id LEFT JOIN md_members AS mdmb ON rel1.member_id = mdmb.member_id
WHERE book.item_id = ? AND (book.privately_owned = 0 or rel.role_id >= 0 or team.role_id >= 0) WHERE book.item_id = ? AND (book.privately_owned = 0 or rel.role_id >= 0 or team.role_id >= 0)
ORDER BY order_index desc,book.book_id DESC LIMIT ?,?` ORDER BY order_index desc,book.book_id DESC LIMIT ?,?`
@ -261,9 +261,9 @@ as t group by book_id) as team
} }
totalCount = int(count) totalCount = int(count)
sql := `SELECT book.*,rel.*,member.account AS create_name FROM md_books AS book sql := `SELECT book.*,rel.*,mdmb.account AS create_name FROM md_books AS book
LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.role_id = 0 LEFT JOIN md_relationship AS rel ON rel.book_id = book.book_id AND rel.role_id = 0
LEFT JOIN md_members AS member ON rel.member_id = member.member_id LEFT JOIN md_members AS mdmb ON rel.member_id = mdmb.member_id
WHERE book.item_id = ? AND book.privately_owned = 0 ORDER BY order_index desc,book.book_id DESC LIMIT ?,?` WHERE book.item_id = ? AND book.privately_owned = 0 ORDER BY order_index desc,book.book_id DESC LIMIT ?,?`
_, err = o.Raw(sql, item.ItemId, offset, pageSize).QueryRows(&books) _, err = o.Raw(sql, item.ItemId, offset, pageSize).QueryRows(&books)

View File

@ -72,9 +72,9 @@ func (m *MemberRelationshipResult) FindForUsersByBookId(lang string, bookId, pag
var members []*MemberRelationshipResult var members []*MemberRelationshipResult
sql1 := "SELECT * FROM md_relationship AS rel LEFT JOIN md_members as member ON rel.member_id = member.member_id WHERE rel.book_id = ? ORDER BY rel.relationship_id DESC LIMIT ?,?" sql1 := "SELECT * FROM md_relationship AS rel LEFT JOIN md_members as mdmb ON rel.member_id = mdmb.member_id WHERE rel.book_id = ? ORDER BY rel.relationship_id DESC LIMIT ?,?"
sql2 := "SELECT count(*) AS total_count FROM md_relationship AS rel LEFT JOIN md_members as member ON rel.member_id = member.member_id WHERE rel.book_id = ?" sql2 := "SELECT count(*) AS total_count FROM md_relationship AS rel LEFT JOIN md_members as mdmb ON rel.member_id = mdmb.member_id WHERE rel.book_id = ?"
var total_count int var total_count int

View File

@ -213,11 +213,11 @@ func (m *TeamMember) FindNotJoinMemberByAccount(teamId int, account string, limi
} }
o := orm.NewOrm() o := orm.NewOrm()
sql := `select member.member_id,member.account,member.real_name,team.team_member_id sql := `select mdmb.member_id,mdmb.account,mdmb.real_name,team.team_member_id
from md_members as member from md_members as mdmb
left join md_team_member as team on team.team_id = ? and member.member_id = team.member_id left join md_team_member as team on team.team_id = ? and mdmb.member_id = team.member_id
where member.account like ? or member.real_name like ? AND team_member_id IS NULL where mdmb.account like ? or mdmb.real_name like ? AND team_member_id IS NULL
order by member.member_id desc order by mdmb.member_id desc
limit ?;` limit ?;`
members := make([]*Member, 0) members := make([]*Member, 0)

View File

@ -16,10 +16,10 @@ func (m *CommentResult) FindForDocumentToPager(doc_id, page_index, page_size int
SELECT SELECT
comment.* , comment.* ,
parent.* , parent.* ,
member.account AS author, mdmb.account AS author,
p_member.account AS reply_account p_member.account AS reply_account
FROM md_comments AS comment FROM md_comments AS comment
LEFT JOIN md_members AS member ON comment.member_id = member.member_id LEFT JOIN md_members AS mdmb ON comment.member_id = mdmb.member_id
LEFT JOIN md_comments AS parent ON comment.parent_id = parent.comment_id LEFT JOIN md_comments AS parent ON comment.parent_id = parent.comment_id
LEFT JOIN md_members AS p_member ON p_member.member_id = parent.member_id LEFT JOIN md_members AS p_member ON p_member.member_id = parent.member_id

View File

@ -251,6 +251,7 @@ func init() {
web.Router("/attach_files/:key/:attach_id", &controllers.DocumentController{}, "get:DownloadAttachment") web.Router("/attach_files/:key/:attach_id", &controllers.DocumentController{}, "get:DownloadAttachment")
web.Router("/comment/create", &controllers.CommentController{}, "post:Create") web.Router("/comment/create", &controllers.CommentController{}, "post:Create")
web.Router("/comment/delete", &controllers.CommentController{}, "post:Delete")
web.Router("/comment/lists", &controllers.CommentController{}, "get:Lists") web.Router("/comment/lists", &controllers.CommentController{}, "get:Lists")
web.Router("/comment/index", &controllers.CommentController{}, "*:Index") web.Router("/comment/index", &controllers.CommentController{}, "*:Index")

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,6 @@ var events = function () {
window.sessionStorage && window.sessionStorage.setItem("MinDoc::LastLoadDocument:" + window.book.identify, $param.$id); window.sessionStorage && window.sessionStorage.setItem("MinDoc::LastLoadDocument:" + window.book.identify, $param.$id);
var prevState = window.history.state || {}; var prevState = window.history.state || {};
if ('pushState' in history) { if ('pushState' in history) {
if ($param.$id) { if ($param.$id) {
prevState.$id === $param.$id || window.history.pushState($param, $param.$id, $param.$url); prevState.$id === $param.$id || window.history.pushState($param, $param.$id, $param.$url);
} else { } else {
@ -43,6 +42,104 @@ var events = function () {
}(); }();
function format($d) {
return $d < 10 ? "0" + $d : "" + $d;
}
function timeFormat($time) {
var span = Date.parse($time)
var date = new Date(span)
var year = date.getFullYear();
var month = format(date.getMonth() + 1);
var day = format(date.getDate());
var hour = format(date.getHours());
var min = format(date.getMinutes());
var sec = format(date.getSeconds());
return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
}
// 点击翻页
function pageClicked($page, $docid) {
$.ajax({
url : "/comment/lists?page=" + $page + "&docid=" + $docid,
type : "GET",
success : function ($res) {
console.log($res.data);
loadComment($res.data.page, $res.data.doc_id);
},
error : function () {
layer.msg("加载失败");
}
});
}
// 加载评论
function loadComment($page, $docid) {
$("#commentList").empty();
var html = ""
var c = $page.List;
for (var i = 0; c && i < c.length; i++) {
html += "<div class=\"comment-item\" data-id=\"" + c[i].comment_id + "\">";
html += "<p class=\"info\"><a class=\"name\">" + c[i].author + "</a><span class=\"date\">" + timeFormat(c[i].comment_date) + "</span></p>";
html += "<div class=\"content\">" + c[i].content + "</div>";
html += "<p class=\"util\">";
if (c[i].show_del == 1) html += "<span class=\"operate toggle\">";
else html += "<span class=\"operate\">";
html += "<span class=\"number\">" + c[i].index + "#</span>";
if (c[i].show_del == 1) html += "<i class=\"delete e-delete glyphicon glyphicon-remove\" style=\"color:red\" onclick=\"onDelComment(" + c[i].comment_id + ")\"></i>";
html += "</span>";
html += "</p>";
html += "</div>";
}
$("#commentList").append(html);
if ($page.TotalPage > 1) {
$("#page").bootstrapPaginator({
currentPage: $page.PageNo,
totalPages: $page.TotalPage,
bootstrapMajorVersion: 3,
size: "middle",
onPageClicked: function(e, originalEvent, type, page){
pageClicked(page, $docid);
}
});
} else {
$("#page").find("li").remove();
}
}
// 删除评论
function onDelComment($id) {
console.log($id);
$.ajax({
url : "/comment/delete",
data : {"id": $id},
type : "POST",
success : function ($res) {
if ($res.errcode == 0) {
layer.msg("删除成功");
$("div[data-id=" + $id + "]").remove();
} else {
layer.msg($res.message);
}
},
error : function () {
layer.msg("删除失败");
}
});
}
// 重新渲染页面
function renderPage($data) {
$("#page-content").html($data.body);
$("title").text($data.title);
$("#article-title").text($data.doc_title);
$("#article-info").text($data.doc_info);
$("#view_count").text("阅读次数:" + $data.view_count);
$("#doc_id").val($data.doc_id);
loadComment($data.page, $data.doc_id);
}
/*** /***
* *
* @param $url * @param $url
@ -53,7 +150,7 @@ function loadDocument($url, $id, $callback) {
$.ajax({ $.ajax({
url : $url, url : $url,
type : "GET", type : "GET",
beforeSend : function (xhr) { beforeSend : function () {
var data = events.data($id); var data = events.data($id);
if(data) { if(data) {
if (typeof $callback === "function") { if (typeof $callback === "function") {
@ -61,11 +158,7 @@ function loadDocument($url, $id, $callback) {
}else if(data.version && data.version != $callback){ }else if(data.version && data.version != $callback){
return true; return true;
} }
$("#page-content").html(data.body); renderPage(data);
$("title").text(data.title);
$("#article-title").text(data.doc_title);
$("#article-info").text(data.doc_info);
$("#view_count").text("阅读次数:" + data.view_count);
events.trigger('article.open', {$url: $url, $id: $id}); events.trigger('article.open', {$url: $url, $id: $id});
@ -75,29 +168,19 @@ function loadDocument($url, $id, $callback) {
NProgress.start(); NProgress.start();
}, },
success : function (res) { success : function ($res) {
if (res.errcode === 0) { if ($res.errcode === 0) {
var body = res.data.body; renderPage($res.data);
var doc_title = res.data.doc_title;
var title = res.data.title;
var doc_info = res.data.doc_info;
var view_count = res.data.view_count;
$body = body; $body = $res.data.body;
if (typeof $callback === "function" ) { if (typeof $callback === "function" ) {
$body = $callback(body); $body = $callback(body);
} }
$("#page-content").html($body); events.data($id, $res.data);
$("title").text(title);
$("#article-title").text(doc_title);
$("#article-info").text(doc_info);
$("#view_count").text("阅读次数:" + view_count);
events.data($id, res.data);
events.trigger('article.open', { $url : $url, $id : $id }); events.trigger('article.open', { $url : $url, $id : $id });
} else if (res.errcode === 6000) { } else if ($res.errcode === 6000) {
window.location.href = "/"; window.location.href = "/";
} else { } else {
layer.msg("加载失败"); layer.msg("加载失败");
@ -129,9 +212,6 @@ function initHighlighting() {
} }
} }
$(function () { $(function () {
$(".view-backtop").on("click", function () { $(".view-backtop").on("click", function () {
$('.manual-right').animate({ scrollTop: '0px' }, 200); $('.manual-right').animate({ scrollTop: '0px' }, 200);
@ -287,4 +367,25 @@ $(function () {
console.log($param); console.log($param);
} }
}; };
// 提交评论
$("#commentForm").ajaxForm({
beforeSubmit : function () {
$("#btnSubmitComment").button("loading");
},
success : function (res) {
if(res.errcode === 0){
layer.msg("保存成功");
}else{
layer.msg("保存失败");
}
$("#btnSubmitComment").button("reset");
$("#commentContent").val("");
pageClicked(-1, res.data.doc_id); // -1 表示请求最后一页
},
error : function () {
layer.msg("服务错误");
$("#btnSubmitComment").button("reset");
}
});
}); });

View File

@ -132,3 +132,29 @@ func (p *Pagination) getLang() string {
} }
return ulang return ulang
} }
type Page struct {
PageNo int `json:"PageNo"`
PageSize int `json:"PageSize"`
TotalPage int `json:"TotalPage"`
TotalCount int `json:"TotalCount"`
FirstPage bool `json:"FirstPage"`
LastPage bool `json:"LastPage"`
List interface{} `json:"List"`
}
func PageUtil(count int, pageNo int, pageSize int, list interface{}) Page {
tp := count / pageSize
if count%pageSize > 0 {
tp = count/pageSize + 1
}
return Page {
PageNo: pageNo,
PageSize: pageSize,
TotalPage: tp,
TotalCount: count,
FirstPage: pageNo == 1,
LastPage: pageNo == tp,
List: list,
}
}

View File

@ -96,6 +96,23 @@
</label> </label>
</div> </div>
</div> </div>
<div class="form-group">
<label>评论</label>
<div class="radio">
<label class="radio-inline">
<input type="radio"{{if eq .Model.CommentStatus "closed"}} checked{{end}} name="comment_status" value="closed"> 关闭评论
</label>
<label class="radio-inline">
<input type="radio"{{if eq .Model.CommentStatus "open"}} checked{{end}} name="comment_status" value="open"> 开启评论
</label>
<!--label class="radio-inline">
<input type="radio"{{if eq .Model.CommentStatus "registered_only"}} checked{{end}} name="comment_status" value="registered_only"> 注册用户可见
</label>
<label class="radio-inline">
<input type="radio"{{if eq .Model.CommentStatus "group_only"}} checked{{end}} name="comment_status" value="group_only"> 成员可见
</label-->
</div>
</div>
{{if eq .Model.PrivatelyOwned 1}} {{if eq .Model.PrivatelyOwned 1}}
<div class="form-group"> <div class="form-group">
<label>{{i18n $.Lang "blog.access_pass"}}</label> <label>{{i18n $.Lang "blog.access_pass"}}</label>