新增了在每篇文档标题下显示原始作者、创建时间和最后更新时间的功能。

pull/178/head
Dandy Cheung 2017-12-20 16:16:41 +08:00
parent 789d46c340
commit 292cf049e2
5 changed files with 130 additions and 99 deletions

View File

@ -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
}

View File

@ -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")
}

View File

@ -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%;

View File

@ -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);

View File

@ -128,6 +128,7 @@
</div>
<div class="col-md-8 text-center">
<h1 id="article-title">{{.Title}}</h1>
<h3 id="article-info">{{.Info}}</h3>
</div>
<div class="col-md-2">
</div>