From b4b0a6b4cf6047d4da3e1e6d878147239b3368ba Mon Sep 17 00:00:00 2001 From: Minho Date: Tue, 2 May 2017 18:09:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=90=9C=E7=B4=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/search.go | 92 +++++++++++++++++++++++++++++++ models/document.go | 1 - models/document_search_result.go | 79 ++++++++++++++++++++++++++ routers/router.go | 3 + static/css/main.css | 81 +++++++++++++++++++++++++++ static/images/search_empty.png | Bin 0 -> 2542 bytes static/js/markdown.js | 4 +- views/book/create.tpl | 73 ------------------------ views/book/dashboard.tpl | 10 +++- views/book/index.tpl | 6 +- views/manager/books.tpl | 2 +- views/manager/edit_book.tpl | 2 +- views/manager/index.tpl | 4 +- views/manager/setting.tpl | 2 +- views/manager/users.tpl | 2 +- views/search/index.tpl | 58 +++++++++++++++++++ views/widgets/header.tpl | 10 ++++ 17 files changed, 343 insertions(+), 86 deletions(-) create mode 100644 controllers/search.go create mode 100644 models/document_search_result.go create mode 100644 static/images/search_empty.png delete mode 100644 views/book/create.tpl create mode 100644 views/search/index.tpl diff --git a/controllers/search.go b/controllers/search.go new file mode 100644 index 00000000..d2cc02c8 --- /dev/null +++ b/controllers/search.go @@ -0,0 +1,92 @@ +package controllers + +import ( + "github.com/lifei6671/godoc/models" + "github.com/lifei6671/godoc/conf" + "github.com/lifei6671/godoc/utils" + "github.com/astaxie/beego" + "strings" + "regexp" + "strconv" +) + +type SearchController struct { + BaseController +} + +func (c *SearchController) Index() { + c.Prepare() + c.TplName = "search/index.tpl" + + keyword := c.GetString("keyword") + pageIndex,_ := c.GetInt("page",1) + + c.Data["BaseUrl"] = c.BaseUrl() + + if keyword != "" { + c.Data["Keyword"] = keyword + member_id := 0 + if c.Member != nil { + member_id = c.Member.MemberId + } + search_result,totalCount,err := models.NewDocumentSearchResult().FindToPager(keyword,pageIndex,conf.PageSize,member_id) + + if err != nil { + beego.Error(err) + return + } + if totalCount > 0 { + html := utils.GetPagerHtml(c.Ctx.Request.RequestURI, pageIndex, conf.PageSize, totalCount) + + c.Data["PageHtml"] = html + }else { + c.Data["PageHtml"] = "" + } + if len(search_result) > 0 { + for _,item := range search_result { + item.DocumentName = strings.Replace(item.DocumentName,keyword,"" + keyword + "",-1) + + if item.Description != "" { + src := item.Description + + //将HTML标签全转换成小写 + re, _ := regexp.Compile("\\<[\\S\\s]+?\\>") + src = re.ReplaceAllStringFunc(src, strings.ToLower) + + //去除STYLE + re, _ = regexp.Compile("\\") + src = re.ReplaceAllString(src, "") + + //去除SCRIPT + re, _ = regexp.Compile("\\") + src = re.ReplaceAllString(src, "") + + //去除所有尖括号内的HTML代码,并换成换行符 + re, _ = regexp.Compile("\\<[\\S\\s]+?\\>") + src = re.ReplaceAllString(src, "\n") + + //去除连续的换行符 + re, _ = regexp.Compile("\\s{2,}") + src = re.ReplaceAllString(src, "\n") + + r := []rune(src) + beego.Info(r) + if len(r) > 100 { + src = string(r[:100]) + }else{ + src = string(r) + } + item.Description = strings.Replace(src, keyword, "" + keyword + "", -1) + } + + if item.Identify == ""{ + item.Identify = strconv.Itoa(item.DocumentId) + } + if item.ModifyTime.IsZero() { + item.ModifyTime = item.CreateTime + } + } + } + c.Data["Lists"] = search_result + } +} diff --git a/models/document.go b/models/document.go index fae98513..78ca72df 100644 --- a/models/document.go +++ b/models/document.go @@ -134,4 +134,3 @@ func (m *Document) ReleaseContent(book_id int) { - diff --git a/models/document_search_result.go b/models/document_search_result.go new file mode 100644 index 00000000..cd06364e --- /dev/null +++ b/models/document_search_result.go @@ -0,0 +1,79 @@ +package models + +import ( + "time" + + "github.com/astaxie/beego/orm" +) + +type DocumentSearchResult struct { + DocumentId int `json:"doc_id"` + DocumentName string `json:"doc_name"` + // Identify 文档唯一标识 + Identify string `json:"identify"` + Description string `json:"description"` + Author string `json:"author"` + ModifyTime time.Time `json:"modify_time"` + CreateTime time.Time `json:"create_time"` + BookId int `json:"book_id"` + BookName string `json:"book_name"` + BookIdentify string `json:"book_identify"` + +} + +func NewDocumentSearchResult() *DocumentSearchResult { + return &DocumentSearchResult{} +} + +func (m *DocumentSearchResult) FindToPager(keyword string,page_index,page_size,member_id int) (search_result []*DocumentSearchResult,total_count int,err error) { + o := orm.NewOrm() + + offset := (page_index - 1) * page_size + + if member_id <= 0 { + sql1 := `SELECT count(doc.document_id) as total_count FROM md_documents AS doc + LEFT JOIN md_books as book ON doc.book_id = book.book_id +WHERE book.privately_owned = 0 AND (doc.document_name LIKE '%?%' OR doc.release LIKE '%?%') ` + + sql2 := `SELECT doc.document_id,doc.modify_time,doc.create_time,doc.document_name,doc.identify,doc.release as description,doc.modify_time,book.identify as book_identify,book.book_name,rel.member_id,member.account AS author FROM md_documents AS doc + 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 role_id = 0 + 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 '%?%') + ORDER BY doc.document_id DESC LIMIT ?,? ` + + err = o.Raw(sql1,keyword,keyword).QueryRow(&total_count) + if err != nil{ + return + } + _,err = o.Raw(sql2,keyword,keyword,offset,page_size).QueryRows(&search_result) + if err != nil { + return + } + }else{ + sql1 := `SELECT count(doc.document_id) as total_count FROM md_documents AS doc + LEFT JOIN md_books as book ON doc.book_id = book.book_id + LEFT JOIN md_relationship AS rel ON doc.book_id = rel.book_id AND role_id = 0 +WHERE (book.privately_owned = 0 OR rel.relationship_id > 0) AND (doc.document_name LIKE ? OR doc.release LIKE ?) ` + + sql2 := `SELECT doc.document_id,doc.modify_time,doc.create_time,doc.document_name,doc.identify,doc.release as description,doc.modify_time,book.identify as book_identify,book.book_name,rel.member_id,member.account AS author FROM md_documents AS doc + 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 role_id = 0 + LEFT JOIN md_members as member ON rel.member_id = member.member_id +WHERE (book.privately_owned = 0 OR rel.relationship_id > 0) AND (doc.document_name LIKE ? OR doc.release LIKE ?) + ORDER BY doc.document_id DESC LIMIT ?,? ` + + keyword = "%"+keyword+"%" + + err = o.Raw(sql1,keyword,keyword).QueryRow(&total_count) + if err != nil{ + return + } + _,err = o.Raw(sql2,keyword,keyword,offset,page_size).QueryRows(&search_result) + if err != nil { + return + } + } + return +} + diff --git a/routers/router.go b/routers/router.go index 5b0d0b8a..a36fcc35 100644 --- a/routers/router.go +++ b/routers/router.go @@ -63,4 +63,7 @@ func init() { beego.Router("/comment/create", &controllers.CommentController{},"post:Create") beego.Router("/comment/lists", &controllers.CommentController{},"get:Lists") beego.Router("/comment/index", &controllers.CommentController{},"*:Index") + + beego.Router("/search",&controllers.SearchController{},"get:Index") } + diff --git a/static/css/main.css b/static/css/main.css index 95ceb41a..e138e1a7 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -289,6 +289,87 @@ textarea{ .users-list .list-item .operate{ float: right; } +/**************用户搜索界面样式********************/ +.manual-search-reader .searchbar{ + padding: 8px; +} +.manual-search-reader .manual-body{ + margin-top: 60px; +} +.manual-search-reader .search-head{ + margin: 10px auto; + padding-bottom: 15px; + line-height: 1.5em; + border-bottom: 3px solid #EEEEEE; +} +.manual-search-reader .search-head .search-title{ + font-size: 22px; + font-weight: 300; +} +.manual-search-reader .search-body { + margin-top: 80px; +} +.manual-search-reader .searchbar .search-btn { + display: inline-block; + line-height: 100%; + cursor: pointer; + margin-top: -10px; + margin-left: -45px; + border: 0; + background-color: transparent +} +.manual-search-reader .searchbar .search-btn>i.fa{ + padding: 10px; +} +.manual-search-reader .search-empty .empty-image{ + margin: 5px auto; + display: block; + text-align: center; + opacity: 0.3; + filter: alpha(opacity=30); +} +.manual-search-reader .search-item{ + margin: 0 15px; + padding: 10px 20px; + line-height: 25px; +} +.manual-search-reader .search-item:hover{ + background-color: #F5F5F5; +} +.manual-search-reader .search-item a{ + color: #0886E9; +} +.manual-search-reader .search-item em{ + color: #FF802C; + font-style:normal; +} +.manual-search-reader .search-item .title{ + font-size: 16px; + font-weight: 400; +} +.manual-search-reader .search-item .description{ + color: #666; + line-height: 25px; + min-height: 20px; + font-size: 12px; +} +.manual-search-reader .search-item .site { + overflow: hidden; + text-overflow: ellipsis; + -o-text-overflow: ellipsis; + white-space: nowrap; + max-width: 600px; + color: #008000; + font-size: 12px; +} +.manual-search-reader .search-item .source .item { + display: inline-block; + margin-right: 15px; +} +.manual-search-reader .search-item .source,.manual-search-reader .search-item .source a{ + font-size: 12px; + color: #999999; +} /**************用户登录界面样式*******************/ .login .login-body{ diff --git a/static/images/search_empty.png b/static/images/search_empty.png new file mode 100644 index 0000000000000000000000000000000000000000..c7404a3ccbafa089685d343150fd94de42023eff GIT binary patch literal 2542 zcmcJQc{tSDAIHxu#+ED-g%OvqA6 zB2VZlOEIAorLNM1mT95ewcOm%@ApUdKF{yZ-yi3E&gXny@Av0C=leY0lkMf}2mFiQMHOgOtpWSv5rxkde0Twg6l^A-_nIlH?e=laD(9DLN7^6M%Wi7IzAO zL_7fRLIEK208oo7z2$8sDZs;A9qqx=krRFG07%C<+uKr;o_#FaAHCW^quYjayS2#R zFuYC=SGT&tTBgfMOIGHj48eNVH zt%jQ*b?-b-^!0Zu=e7nFkwBNPZF-{t3vB<2LQusfG^lbGu17O^S{=Av-U9ov&;uX> zI*qWLvy*ejn;U)S!Rm&bc9Vf!Mn2* z9ovv0KO~+)j89m+t%?sRRWKCQHg1^*NyS2VXWe!Zj%D|3O&JhJsLx@)Z%LTj{Y<$G zba^?4oUVBV?Gd~fkPSud2;{SlBxi+Glnuz9=V4>0Efakc>mW5Ye5!lx_Uf^K;Mc1n za~E!*&Z`+T`-s@iUk!xS)&X4|%@~vqV^01eg9edroRp z26OEFikbbvmu9>wXAZ_6$g*^h)>8+b8Lh$Fc1C&R@icDCtj|GvL*K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!7L-g1fV|vU#*7WcgBZwJk{A*ouIvjyuW@h@I*@9#&*=Z5&S^o6E*}=oU I-YzubZw{X;@&Et; literal 0 HcmV?d00001 diff --git a/static/js/markdown.js b/static/js/markdown.js index bbbfc786..a06cd762 100644 --- a/static/js/markdown.js +++ b/static/js/markdown.js @@ -243,7 +243,7 @@ $(function () { if (doc_name === ""){ return showError("目录名称不能为空","#add-error-message") } - window.addDocumentFormIndex = layer.load(1, { shade: [0.1,'#fff'] }); + $("#btnSaveDocument").button("loading"); return true; }, success : function (res) { @@ -266,7 +266,7 @@ $(function () { }else{ showError(res.message,"#add-error-message") } - layer.close(window.addDocumentFormIndex); + $("#btnSaveDocument").button("reset"); } }); diff --git a/views/book/create.tpl b/views/book/create.tpl deleted file mode 100644 index 88932d58..00000000 --- a/views/book/create.tpl +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - 概要 - Powered by MinDoc - - - - - - - - - - - -
- {{template "widgets/header.tpl" .}} -
-
-
- - -
-
-
-
- 项目设置 - - -
-
-
-
-
-
- - -
- -
-
-
- -
-
-
-
-
- {{template "widgets/footer.tpl" .}} -
- - - - - - \ No newline at end of file diff --git a/views/book/dashboard.tpl b/views/book/dashboard.tpl index ab3066c4..da7c73d5 100644 --- a/views/book/dashboard.tpl +++ b/views/book/dashboard.tpl @@ -83,11 +83,15 @@ 担任角色: {{.Model.RoleName}} -
+ {{/*
评论数量: {{.Model.CommentCount}} 条 -
-
{{.Model.Description}}
+
*/}} +
+ 文档标签: + {{.Model.Label}} +
+
{{.Model.Description}}
diff --git a/views/book/index.tpl b/views/book/index.tpl index 5728abab..e8707d42 100644 --- a/views/book/index.tpl +++ b/views/book/index.tpl @@ -168,7 +168,7 @@ @@ -204,16 +204,18 @@ if(description.length > 500){ return showError("描述信息不超过500个字符"); } + $("#btnSaveDocument").button("loading"); return showSuccess(""); }, success : function (res) { - console.log(res); + $("#btnSaveDocument").button("reset"); if(res.errcode === 0){ window.app.lists.splice(0,0,res.data); $("#addBookDialogModal").modal("hide"); }else{ showError(res.message); } + } }); diff --git a/views/manager/books.tpl b/views/manager/books.tpl index 47b412a9..3c2bf686 100644 --- a/views/manager/books.tpl +++ b/views/manager/books.tpl @@ -29,7 +29,7 @@
  • 仪表盘
  • 用户管理
  • 项目管理
  • -
  • 评论管理
  • + {{/*
  • 评论管理
  • */}}
  • 配置管理
  • diff --git a/views/manager/edit_book.tpl b/views/manager/edit_book.tpl index 8411cd6a..187658e9 100644 --- a/views/manager/edit_book.tpl +++ b/views/manager/edit_book.tpl @@ -30,7 +30,7 @@
  • 仪表盘
  • 用户管理
  • 项目管理
  • -
  • 评论管理
  • + {{/*
  • 评论管理
  • */}}
  • 配置管理
  • diff --git a/views/manager/index.tpl b/views/manager/index.tpl index 0671e304..0c02020a 100644 --- a/views/manager/index.tpl +++ b/views/manager/index.tpl @@ -29,7 +29,7 @@
  • 仪表盘
  • 用户管理
  • 项目管理
  • -
  • 评论管理
  • + {{/*
  • 评论管理
  • */}}
  • 配置管理
  • @@ -55,11 +55,13 @@ 会员数量 {{.Model.MemberNumber}} + {{/*
    评论数量 {{.Model.CommentNumber}}
    + */}}
    附件数量 diff --git a/views/manager/setting.tpl b/views/manager/setting.tpl index 1e4c3479..724d2f88 100644 --- a/views/manager/setting.tpl +++ b/views/manager/setting.tpl @@ -28,7 +28,7 @@
  • 仪表盘
  • 用户管理
  • 项目管理
  • -
  • 评论管理
  • + {{/*
  • 评论管理
  • */}}
  • 配置管理
  • diff --git a/views/manager/users.tpl b/views/manager/users.tpl index d6972bf4..98dba9bb 100644 --- a/views/manager/users.tpl +++ b/views/manager/users.tpl @@ -29,7 +29,7 @@
  • 仪表盘
  • 用户管理
  • 项目管理
  • -
  • 评论管理
  • + {{/*
  • 评论管理
  • */}}
  • 配置管理
  • diff --git a/views/search/index.tpl b/views/search/index.tpl new file mode 100644 index 00000000..8074b675 --- /dev/null +++ b/views/search/index.tpl @@ -0,0 +1,58 @@ + + + + + + + + 搜索 - Powered by MinDoc + + + + + + + + + + + +
    + {{template "widgets/header.tpl" .}} +
    +
    + 显示"{{.Keyword}}"的搜索结果 +
    +
    +
    + {{range $index,$item := .Lists}} +
    + +
    + {{str2html $item.Description}} +
    +
    {{$.BaseUrl}}{{urlfor "DocumentController.Read" ":key" $item.BookIdentify ":id" $item.Identify}}
    +
    + 来自:{{$item.BookName}} + 作者:{{$item.Author}} + 更新时间:{{date $item.ModifyTime "Y-m-d H:i:s"}} +
    +
    + {{else}} +
    + +
    + {{end}} +
    +
    +
    +
    + {{template "widgets/footer.tpl" .}} +
    + + + + \ No newline at end of file diff --git a/views/widgets/header.tpl b/views/widgets/header.tpl index 3e3ab51d..34616d8f 100644 --- a/views/widgets/header.tpl +++ b/views/widgets/header.tpl @@ -8,6 +8,15 @@ {{.SITE_NAME}} {{end}} + + {{/* + */}}