Merge pull request #178 from DigitalUnion/master

增加了导出单篇文档为 PDF 的功能。
This commit is contained in:
Minho 2017-12-21 15:56:55 +08:00 committed by GitHub
commit 4e4035b27a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 452 additions and 267 deletions

10
TODO Normal file
View File

@ -0,0 +1,10 @@
1、把 log 提取出 dbgout 之类的方法;已改作 beego.Info() 调用;
2、把源代码里的 TODO 完成;
3、Export 的两个 URL 应该可以合并,用是否有 :id 来区分;这样 0 号文档输出整个 book 更顺;已完成;
4、统一代码风格空格、命名之类的
5、美化 PDF 的输出格式;
6、自动登录新开标签页而且并不能跳转至起始请求页的问题
7、用户分组管理
8、[自动]展示历史版本;增强历史版本对比显示的能力;
9、[自动]展示作者信息;也许可以和上一需求合并考虑;
10、查看了解评论功能

File diff suppressed because it is too large Load Diff

View File

@ -34,7 +34,6 @@ func init() {
beego.Router("/manager/attach/detailed/:id", &controllers.ManagerController{}, "*:AttachDetailed") beego.Router("/manager/attach/detailed/:id", &controllers.ManagerController{}, "*:AttachDetailed")
beego.Router("/manager/attach/delete", &controllers.ManagerController{}, "post:AttachDelete") beego.Router("/manager/attach/delete", &controllers.ManagerController{}, "post:AttachDelete")
beego.Router("/setting", &controllers.SettingController{}, "*:Index") beego.Router("/setting", &controllers.SettingController{}, "*:Index")
beego.Router("/setting/password", &controllers.SettingController{}, "*:Password") beego.Router("/setting/password", &controllers.SettingController{}, "*:Password")
beego.Router("/setting/upload", &controllers.SettingController{}, "*:Upload") beego.Router("/setting/upload", &controllers.SettingController{}, "*:Upload")
@ -73,7 +72,8 @@ func init() {
beego.Router("/docs/:key", &controllers.DocumentController{}, "*:Index") beego.Router("/docs/:key", &controllers.DocumentController{}, "*:Index")
beego.Router("/docs/:key/:id", &controllers.DocumentController{}, "*:Read") beego.Router("/docs/:key/:id", &controllers.DocumentController{}, "*:Read")
beego.Router("/docs/:key/search", &controllers.DocumentController{}, "post:Search") beego.Router("/docs/:key/search", &controllers.DocumentController{}, "post:Search")
beego.Router("/export/:key", &controllers.DocumentController{},"*:Export") 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("/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")
@ -87,4 +87,3 @@ func init() {
beego.Router("/tag/:key", &controllers.LabelController{}, "get:Index") beego.Router("/tag/:key", &controllers.LabelController{}, "get:Index")
beego.Router("/tags", &controllers.LabelController{}, "get:List") beego.Router("/tags", &controllers.LabelController{}, "get:List")
} }

View File

@ -417,7 +417,8 @@ table>tbody>tr:hover{
} }
.manual-article .article-head { .manual-article .article-head {
position: relative; position: relative;
zoom:1;padding: 10px 20px zoom: 1;
padding: 10px 20px
} }
.manual-reader .book-title{ .manual-reader .book-title{
color: #333333; color: #333333;
@ -430,7 +431,7 @@ table>tbody>tr:hover{
.manual-article .article-head h1 { .manual-article .article-head h1 {
margin: 0; margin: 0;
font-size: 20px; font-size: 20px;
font-weight: 200; font-weight: 300;
text-align: center; text-align: center;
line-height: 30px; line-height: 30px;
overflow: hidden; overflow: hidden;
@ -438,6 +439,17 @@ table>tbody>tr:hover{
white-space: nowrap; white-space: nowrap;
color: #444 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{ .manual-article .article-content{
min-width: 980px; min-width: 980px;
max-width: 98%; max-width: 98%;

View File

@ -12,15 +12,17 @@ function loadDocument($url,$id,$callback) {
var body = events.data('body_' + $id); var body = events.data('body_' + $id);
var title = events.data('title_' + $id); var title = events.data('title_' + $id);
var doc_title = events.data('doc_title_' + $id); var doc_title = events.data('doc_title_' + $id);
var doc_info = events.data('doc_info_' + $id);
if (body && title && doc_title) { if (body && title && doc_title) {
if (typeof $callback === "function") { if (typeof $callback === "function") {
body = $callback(body); body = $callback(body);
} }
$("#page-content").html(body); $("#page-content").html(body);
$("title").text(title); $("title").text(title);
$("#article-title").text(doc_title); $("#article-title").text(doc_title);
$("#article-info").text(doc_info);
events.trigger('article.open', { $url : $url, $init : false, $id : $id }); events.trigger('article.open', { $url : $url, $init : false, $id : $id });
@ -33,21 +35,26 @@ function loadDocument($url,$id,$callback) {
var body = res.data.body; var body = res.data.body;
var doc_title = res.data.doc_title; var doc_title = res.data.doc_title;
var title = res.data.title; var title = res.data.title;
var doc_info = res.data.doc_info;
$body = body; $body = body;
if (typeof $callback === "function" ) { if (typeof $callback === "function" ) {
$body = $callback(body); $body = $callback(body);
} }
$("#page-content").html($body); $("#page-content").html($body);
$("title").text(title); $("title").text(title);
$("#article-title").text(doc_title); $("#article-title").text(doc_title);
$("#article-info").text(doc_info);
events.data('body_' + $id, body); events.data('body_' + $id, body);
events.data('title_' + $id, title); events.data('title_' + $id, title);
events.data('doc_title_' + $id, doc_title); events.data('doc_title_' + $id, doc_title);
events.data('doc_info_' + $id, doc_info);
events.trigger('article.open', { $url : $url, $init : true, $id : $id }); events.trigger('article.open', { $url : $url, $init : true, $id : $id });
} else if (res.errcode === 6000) {
window.location.href = "/";
} else { } else {
layer.msg("加载失败"); layer.msg("加载失败");
} }
@ -103,8 +110,8 @@ $(function () {
if (url === window.location.href) { if (url === window.location.href) {
return false; return false;
} }
loadDocument(url,selected.node.id);
loadDocument(url, selected.node.id);
}); });
$("#slidebar").on("click", function () { $("#slidebar").on("click", function () {
@ -128,17 +135,16 @@ $(function () {
// 处理打开事件 // 处理打开事件
events.on('article.open', function (event, $param) { events.on('article.open', function (event, $param) {
if ('pushState' in history) { if ('pushState' in history) {
if ($param.$init === false) { if ($param.$init === false) {
window.history.replaceState($param, $param.$id, $param.$url); window.history.replaceState($param, $param.$id, $param.$url);
} else { } else {
window.history.pushState($param, $param.$id, $param.$url); window.history.pushState($param, $param.$id, $param.$url);
} }
} else { } else {
window.location.hash = $param.$url; window.location.hash = $param.$url;
} }
initHighlighting(); initHighlighting();
$(".manual-right").scrollTop(0); $(".manual-right").scrollTop(0);
}); });
@ -184,7 +190,6 @@ $(function () {
}); });
window.onpopstate = function (e) { window.onpopstate = function (e) {
var $param = e.state; var $param = e.state;
console.log($param); console.log($param);
if($param.hasOwnProperty("$url")) { if($param.hasOwnProperty("$url")) {

View File

@ -58,7 +58,8 @@
{{if eq .Model.PrivatelyOwned 0}} {{if eq .Model.PrivatelyOwned 0}}
<li><a href="javascript:" data-toggle="modal" data-target="#shareProject">项目分享</a> </li> <li><a href="javascript:" data-toggle="modal" data-target="#shareProject">项目分享</a> </li>
<li role="presentation" class="divider"></li> <li role="presentation" class="divider"></li>
<li><a href="{{urlfor "DocumentController.Export" ":key" .Model.Identify "output" "pdf"}}" target="_blank">项目导出PDF</a> </li> <li><a href="javascript:void(0);" onclick="ExportPdfDoc()">文档导出为 PDF</a> </li>
<li><a href="{{urlfor "DocumentController.ExportBook" ":key" .Model.Identify "output" "pdf"}}" target="_blank">项目导出为 PDF</a> </li>
{{end}} {{end}}
<li><a href="{{urlfor "HomeController.Index"}}" title="返回首页">返回首页</a> </li> <li><a href="{{urlfor "HomeController.Index"}}" title="返回首页">返回首页</a> </li>
@ -127,6 +128,7 @@
</div> </div>
<div class="col-md-8 text-center"> <div class="col-md-8 text-center">
<h1 id="article-title">{{.Title}}</h1> <h1 id="article-title">{{.Title}}</h1>
<h3 id="article-info">{{.Info}}</h3>
</div> </div>
<div class="col-md-2"> <div class="col-md-2">
</div> </div>
@ -234,6 +236,13 @@
<script type="text/javascript" src="/static/js/jquery.highlight.js"></script> <script type="text/javascript" src="/static/js/jquery.highlight.js"></script>
<script type="text/javascript" src="/static/js/kancloud.js"></script> <script type="text/javascript" src="/static/js/kancloud.js"></script>
<script type="text/javascript"> <script type="text/javascript">
active_book_id = {{.Model.Identify}};
active_doc_id = {{.DocumentId}};
$(function () {
$("body").on('article.open', function (event, $param) {
active_doc_id = $param.$id;
});
});
$(function () { $(function () {
$("#searchList").on("click","a",function () { $("#searchList").on("click","a",function () {
var id = $(this).attr("data-id"); var id = $(this).attr("data-id");
@ -245,6 +254,12 @@ $(function () {
}); });
}); });
}); });
function ExportPdfDoc() {
var id = active_book_id;
if(active_doc_id != "0")
id += "/" + active_doc_id;
window.location.href = "/export/" + id + "?output=pdf";
}
</script> </script>
</body> </body>
</html> </html>