From 292cf049e230e14b3ae7463fb675b87822d05e6e Mon Sep 17 00:00:00 2001 From: Dandy Cheung Date: Wed, 20 Dec 2017 16:16:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=86=E5=9C=A8=E6=AF=8F?= =?UTF-8?q?=E7=AF=87=E6=96=87=E6=A1=A3=E6=A0=87=E9=A2=98=E4=B8=8B=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=8E=9F=E5=A7=8B=E4=BD=9C=E8=80=85=E3=80=81=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=97=B6=E9=97=B4=E5=92=8C=E6=9C=80=E5=90=8E=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=97=B6=E9=97=B4=E7=9A=84=E5=8A=9F=E8=83=BD=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/document.go | 72 ++++++++++------- routers/router.go | 138 ++++++++++++++++---------------- static/css/kancloud.css | 16 +++- static/js/kancloud.js | 2 + views/document/default_read.tpl | 1 + 5 files changed, 130 insertions(+), 99 deletions(-) diff --git a/controllers/document.go b/controllers/document.go index a5a9b98d..dbbb8c65 100644 --- a/controllers/document.go +++ b/controllers/document.go @@ -16,8 +16,6 @@ import ( "bytes" - "log" - "github.com/PuerkitoBio/goquery" "github.com/astaxie/beego" "github.com/astaxie/beego/orm" @@ -126,10 +124,11 @@ func (c *DocumentController) Index() { c.Data["Model"] = bookResult c.Data["Result"] = template.HTML(tree) c.Data["Title"] = "概要" - c.Data["Content"] = template.HTML( blackfriday.MarkdownBasic([]byte(bookResult.Description))) + c.Data["Content"] = template.HTML(blackfriday.MarkdownBasic([]byte(bookResult.Description))) + c.Data["Info"] = "" - c.Data["DocumentId"] = "0" // added by dandycheung, 2017-12-08, for exporting - log.Println("DocumentController.Index(): c.Data[\"DocumentId\"] = ", 0) + c.Data["DocumentId"] = "0" // added by dandycheung, 2017-12-08, for exporting + beego.Info("DocumentController.Index(): c.Data[\"DocumentId\"] = ", 0) } //阅读文档. @@ -139,8 +138,8 @@ func (c *DocumentController) Read() { token := c.GetString("token") id := c.GetString(":id") - c.Data["DocumentId"] = id // added by dandycheung, 2017-12-08, for exporting - log.Println("DocumentController.Read(): c.Data[\"DocumentId\"] = ", id, ", IsAjax = ", c.IsAjax()) + c.Data["DocumentId"] = id // added by dandycheung, 2017-12-08, for exporting + beego.Info("DocumentController.Read(): c.Data[\"DocumentId\"] = ", id, ", IsAjax = ", c.IsAjax()) if identify == "" || id == "" { c.Abort("404") @@ -200,15 +199,33 @@ func (c *DocumentController) Read() { } } + + // assemble doc info, added by dandycheung, 2017-12-20 + docInfo := "" + docCreator, err := models.NewMember().Find(doc.MemberId) + if err == nil { + docInfo += docCreator.Account + } + + docInfo += " 创建于 " + docInfo += doc.CreateTime.Format("2006-01-02 15:04") + + if doc.ModifyTime != doc.CreateTime { + docInfo += ";更新于 " + docInfo += doc.ModifyTime.Format("2006-01-02 15:04") + } + if c.IsAjax() { var data struct { DocTitle string `json:"doc_title"` Body string `json:"body"` Title string `json:"title"` + DocInfo string `json:"doc_info"` } data.DocTitle = doc.DocumentName data.Body = doc.Release data.Title = doc.DocumentName + " - Powered by MinDoc" + data.DocInfo = docInfo c.JsonResult(0, "ok", data) } @@ -223,6 +240,7 @@ func (c *DocumentController) Read() { c.Data["Model"] = bookResult c.Data["Result"] = template.HTML(tree) c.Data["Title"] = doc.DocumentName + c.Data["Info"] = docInfo c.Data["Content"] = template.HTML(doc.Release) } @@ -753,17 +771,17 @@ func (c *DocumentController) ExportBook() { func (c *DocumentController) GetDocumentById(id string) (doc *models.Document, err error) { doc = models.NewDocument() - if doc_id, err := strconv.Atoi(id); err == nil { - doc, err = doc.Find(doc_id) - if err != nil { - return nil, err - } - } else { - doc, err = doc.FindByFieldFirst("identify", id) - if err != nil { + if doc_id, err := strconv.Atoi(id); err == nil { + doc, err = doc.Find(doc_id) + if err != nil { return nil, err - } - } + } + } else { + doc, err = doc.FindByFieldFirst("identify", id) + if err != nil { + return nil, err + } + } return doc, nil } @@ -1121,10 +1139,10 @@ func (c *DocumentController) RestoreHistory() { c.JsonResult(0, "ok", doc) } -func (c *DocumentController) Compare() { +func (c *DocumentController) Compare() { c.Prepare() c.TplName = "document/compare.tpl" - history_id ,_ := strconv.Atoi(c.Ctx.Input.Param(":id")) + history_id, _ := strconv.Atoi(c.Ctx.Input.Param(":id")) identify := c.Ctx.Input.Param(":key") book_id := 0 @@ -1155,18 +1173,18 @@ func (c *DocumentController) Compare() { } if history_id <= 0 { - c.ShowErrorPage(60002,"参数错误") + c.ShowErrorPage(60002, "参数错误") } - history,err := models.NewDocumentHistory().Find(history_id) + history, err := models.NewDocumentHistory().Find(history_id) if err != nil { - beego.Error("DocumentController.Compare => ",err) - c.ShowErrorPage(60003,err.Error()) + beego.Error("DocumentController.Compare => ", err) + c.ShowErrorPage(60003, err.Error()) } - doc,err := models.NewDocument().Find(history.DocumentId) + doc, err := models.NewDocument().Find(history.DocumentId) if doc.BookId != book_id { - c.ShowErrorPage(60002,"参数错误") + c.ShowErrorPage(60002, "参数错误") } c.Data["HistoryId"] = history_id c.Data["DocumentId"] = doc.DocumentId @@ -1174,7 +1192,7 @@ func (c *DocumentController) Compare() { if editor == "markdown" { c.Data["HistoryContent"] = history.Markdown c.Data["Content"] = doc.Markdown - }else{ + } else { c.Data["HistoryContent"] = template.HTML(history.Content) c.Data["Content"] = template.HTML(doc.Content) } @@ -1188,7 +1206,7 @@ func RecursiveFun(parent_id int, prefix, dpath string, c *DocumentController, bo for _, sub := range docs { if sub.ParentId == item.DocumentId { - prefix += strconv.Itoa(item.ParentId) + strconv.Itoa(item.OrderSort) + strconv.Itoa(item.DocumentId); + prefix += strconv.Itoa(item.ParentId) + strconv.Itoa(item.OrderSort) + strconv.Itoa(item.DocumentId) RecursiveFun(item.DocumentId, prefix, dpath, c, book, docs, paths) break } diff --git a/routers/router.go b/routers/router.go index 94ef8f25..65ea3408 100644 --- a/routers/router.go +++ b/routers/router.go @@ -5,87 +5,85 @@ import ( "github.com/lifei6671/mindoc/controllers" ) -func init() { - beego.Router("/",&controllers.HomeController{},"*:Index") +func init() { + beego.Router("/", &controllers.HomeController{}, "*:Index") - beego.Router("/login", &controllers.AccountController{},"*:Login") - beego.Router("/logout", &controllers.AccountController{},"*:Logout") - beego.Router("/register", &controllers.AccountController{},"*:Register") - beego.Router("/find_password", &controllers.AccountController{},"*:FindPassword") - beego.Router("/valid_email", &controllers.AccountController{},"post:ValidEmail") - beego.Router("/captcha", &controllers.AccountController{},"*:Captcha") + beego.Router("/login", &controllers.AccountController{}, "*:Login") + beego.Router("/logout", &controllers.AccountController{}, "*:Logout") + beego.Router("/register", &controllers.AccountController{}, "*:Register") + beego.Router("/find_password", &controllers.AccountController{}, "*:FindPassword") + beego.Router("/valid_email", &controllers.AccountController{}, "post:ValidEmail") + beego.Router("/captcha", &controllers.AccountController{}, "*:Captcha") - beego.Router("/manager", &controllers.ManagerController{},"*:Index") - beego.Router("/manager/users", &controllers.ManagerController{},"*:Users") - beego.Router("/manager/users/edit/:id", &controllers.ManagerController{},"*:EditMember") - beego.Router("/manager/member/create", &controllers.ManagerController{},"post:CreateMember") - beego.Router("/manager/member/delete", &controllers.ManagerController{},"post:DeleteMember") - beego.Router("/manager/member/update-member-status",&controllers.ManagerController{},"post:UpdateMemberStatus") - beego.Router("/manager/member/change-member-role", &controllers.ManagerController{},"post:ChangeMemberRole") - beego.Router("/manager/books", &controllers.ManagerController{},"*:Books") - beego.Router("/manager/books/edit/:key", &controllers.ManagerController{},"*:EditBook") - beego.Router("/manager/books/delete", &controllers.ManagerController{},"*:DeleteBook") - beego.Router("/manager/comments", &controllers.ManagerController{},"*:Comments") - beego.Router("/manager/books/token", &controllers.ManagerController{},"post:CreateToken") - beego.Router("/manager/setting",&controllers.ManagerController{},"*:Setting") - beego.Router("/manager/books/transfer", &controllers.ManagerController{},"post:Transfer") - beego.Router("/manager/books/open", &controllers.ManagerController{},"post:PrivatelyOwned") - beego.Router("/manager/attach/list", &controllers.ManagerController{},"*:AttachList") - beego.Router("/manager/attach/detailed/:id", &controllers.ManagerController{},"*:AttachDetailed") - beego.Router("/manager/attach/delete", &controllers.ManagerController{},"post:AttachDelete") + beego.Router("/manager", &controllers.ManagerController{}, "*:Index") + beego.Router("/manager/users", &controllers.ManagerController{}, "*:Users") + beego.Router("/manager/users/edit/:id", &controllers.ManagerController{}, "*:EditMember") + beego.Router("/manager/member/create", &controllers.ManagerController{}, "post:CreateMember") + beego.Router("/manager/member/delete", &controllers.ManagerController{}, "post:DeleteMember") + beego.Router("/manager/member/update-member-status", &controllers.ManagerController{}, "post:UpdateMemberStatus") + beego.Router("/manager/member/change-member-role", &controllers.ManagerController{}, "post:ChangeMemberRole") + beego.Router("/manager/books", &controllers.ManagerController{}, "*:Books") + beego.Router("/manager/books/edit/:key", &controllers.ManagerController{}, "*:EditBook") + beego.Router("/manager/books/delete", &controllers.ManagerController{}, "*:DeleteBook") + beego.Router("/manager/comments", &controllers.ManagerController{}, "*:Comments") + beego.Router("/manager/books/token", &controllers.ManagerController{}, "post:CreateToken") + beego.Router("/manager/setting", &controllers.ManagerController{}, "*:Setting") + beego.Router("/manager/books/transfer", &controllers.ManagerController{}, "post:Transfer") + beego.Router("/manager/books/open", &controllers.ManagerController{}, "post:PrivatelyOwned") + beego.Router("/manager/attach/list", &controllers.ManagerController{}, "*:AttachList") + beego.Router("/manager/attach/detailed/:id", &controllers.ManagerController{}, "*:AttachDetailed") + beego.Router("/manager/attach/delete", &controllers.ManagerController{}, "post:AttachDelete") + beego.Router("/setting", &controllers.SettingController{}, "*:Index") + beego.Router("/setting/password", &controllers.SettingController{}, "*:Password") + beego.Router("/setting/upload", &controllers.SettingController{}, "*:Upload") - beego.Router("/setting", &controllers.SettingController{},"*:Index") - beego.Router("/setting/password", &controllers.SettingController{},"*:Password") - beego.Router("/setting/upload", &controllers.SettingController{},"*:Upload") + beego.Router("/book", &controllers.BookController{}, "*:Index") + beego.Router("/book/:key/dashboard", &controllers.BookController{}, "*:Dashboard") + beego.Router("/book/:key/setting", &controllers.BookController{}, "*:Setting") + beego.Router("/book/:key/users", &controllers.BookController{}, "*:Users") + beego.Router("/book/:key/release", &controllers.BookController{}, "post:Release") + beego.Router("/book/:key/sort", &controllers.BookController{}, "post:SaveSort") - beego.Router("/book", &controllers.BookController{},"*:Index") - beego.Router("/book/:key/dashboard", &controllers.BookController{},"*:Dashboard") - beego.Router("/book/:key/setting", &controllers.BookController{},"*:Setting") - beego.Router("/book/:key/users", &controllers.BookController{},"*:Users") - beego.Router("/book/:key/release", &controllers.BookController{},"post:Release") - beego.Router("/book/:key/sort", &controllers.BookController{},"post:SaveSort") + beego.Router("/book/create", &controllers.BookController{}, "*:Create") + beego.Router("/book/users/create", &controllers.BookMemberController{}, "post:AddMember") + beego.Router("/book/users/change", &controllers.BookMemberController{}, "post:ChangeRole") + beego.Router("/book/users/delete", &controllers.BookMemberController{}, "post:RemoveMember") - beego.Router("/book/create", &controllers.BookController{},"*:Create") - beego.Router("/book/users/create", &controllers.BookMemberController{},"post:AddMember") - beego.Router("/book/users/change", &controllers.BookMemberController{},"post:ChangeRole") - beego.Router("/book/users/delete", &controllers.BookMemberController{},"post:RemoveMember") + beego.Router("/book/setting/save", &controllers.BookController{}, "post:SaveBook") + 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/setting/save", &controllers.BookController{},"post:SaveBook") - 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("/api/attach/remove/", &controllers.DocumentController{}, "post:RemoveAttachment") + beego.Router("/api/:key/edit/?:id", &controllers.DocumentController{}, "*:Edit") + beego.Router("/api/upload", &controllers.DocumentController{}, "post:Upload") + beego.Router("/api/:key/create", &controllers.DocumentController{}, "post:Create") + beego.Router("/api/:key/delete", &controllers.DocumentController{}, "post:Delete") + beego.Router("/api/:key/content/?:id", &controllers.DocumentController{}, "*:Content") + beego.Router("/api/:key/compare/:id", &controllers.DocumentController{}, "*:Compare") - beego.Router("/api/attach/remove/", &controllers.DocumentController{},"post:RemoveAttachment") - beego.Router("/api/:key/edit/?:id", &controllers.DocumentController{},"*:Edit") - beego.Router("/api/upload",&controllers.DocumentController{},"post:Upload") - beego.Router("/api/:key/create",&controllers.DocumentController{},"post:Create") - beego.Router("/api/:key/delete", &controllers.DocumentController{},"post:Delete") - beego.Router("/api/:key/content/?:id",&controllers.DocumentController{},"*:Content") - beego.Router("/api/:key/compare/:id", &controllers.DocumentController{},"*:Compare") + beego.Router("/history/get", &controllers.DocumentController{}, "get:History") + beego.Router("/history/delete", &controllers.DocumentController{}, "*:DeleteHistory") + beego.Router("/history/restore", &controllers.DocumentController{}, "*:RestoreHistory") - beego.Router("/history/get", &controllers.DocumentController{},"get:History") - beego.Router("/history/delete", &controllers.DocumentController{},"*:DeleteHistory") - beego.Router("/history/restore", &controllers.DocumentController{},"*:RestoreHistory") + beego.Router("/docs/:key", &controllers.DocumentController{}, "*:Index") + beego.Router("/docs/:key/:id", &controllers.DocumentController{}, "*:Read") + beego.Router("/docs/:key/search", &controllers.DocumentController{}, "post:Search") + beego.Router("/export/:key", &controllers.DocumentController{}, "*:ExportBook") + beego.Router("/export/:key/:id", &controllers.DocumentController{}, "*:ExportDoc") + beego.Router("/qrcode/:key.png", &controllers.DocumentController{}, "get:QrCode") - beego.Router("/docs/:key", &controllers.DocumentController{},"*:Index") - beego.Router("/docs/:key/:id", &controllers.DocumentController{},"*:Read") - beego.Router("/docs/:key/search", &controllers.DocumentController{},"post:Search") - beego.Router("/export/:key", &controllers.DocumentController{},"*:ExportBook") - beego.Router("/export/:key/:id", &controllers.DocumentController{},"*:ExportDoc") - beego.Router("/qrcode/:key.png",&controllers.DocumentController{},"get:QrCode") + beego.Router("/attach_files/:key/:attach_id", &controllers.DocumentController{}, "get:DownloadAttachment") - beego.Router("/attach_files/:key/:attach_id",&controllers.DocumentController{},"get:DownloadAttachment") + 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("/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") - beego.Router("/search",&controllers.SearchController{},"get:Index") - - beego.Router("/tag/:key", &controllers.LabelController{},"get:Index") - beego.Router("/tags", &controllers.LabelController{},"get:List") + beego.Router("/tag/:key", &controllers.LabelController{}, "get:Index") + beego.Router("/tags", &controllers.LabelController{}, "get:List") } - diff --git a/static/css/kancloud.css b/static/css/kancloud.css index 426b67d1..36dcd5b0 100644 --- a/static/css/kancloud.css +++ b/static/css/kancloud.css @@ -417,7 +417,8 @@ table>tbody>tr:hover{ } .manual-article .article-head { position: relative; - zoom:1;padding: 10px 20px + zoom: 1; + padding: 10px 20px } .manual-reader .book-title{ color: #333333; @@ -430,7 +431,7 @@ table>tbody>tr:hover{ .manual-article .article-head h1 { margin: 0; font-size: 20px; - font-weight: 200; + font-weight: 300; text-align: center; line-height: 30px; overflow: hidden; @@ -438,6 +439,17 @@ table>tbody>tr:hover{ white-space: nowrap; color: #444 } +.manual-article .article-head h3 { + margin: 0; + font-size: 12px; + font-weight: 200; + text-align: center; + line-height: 18px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + color: #444 +} .manual-article .article-content{ min-width: 980px; max-width: 98%; diff --git a/static/js/kancloud.js b/static/js/kancloud.js index a333e5ff..2d5e9a2e 100644 --- a/static/js/kancloud.js +++ b/static/js/kancloud.js @@ -33,6 +33,7 @@ function loadDocument($url,$id,$callback) { var body = res.data.body; var doc_title = res.data.doc_title; var title = res.data.title; + var doc_info = res.data.doc_info; $body = body; if (typeof $callback === "function" ){ @@ -41,6 +42,7 @@ function loadDocument($url,$id,$callback) { $("#page-content").html($body); $("title").text(title); $("#article-title").text(doc_title); + $("#article-info").text(doc_info); events.data('body_' + $id,body); events.data('title_' + $id,title); diff --git a/views/document/default_read.tpl b/views/document/default_read.tpl index d10a0ae7..c886ea72 100644 --- a/views/document/default_read.tpl +++ b/views/document/default_read.tpl @@ -128,6 +128,7 @@

{{.Title}}

+

{{.Info}}