mirror of https://github.com/mindoc-org/mindoc.git
feat:实现自定义文档树的展开状态
parent
aa2842cdf8
commit
57a745cc63
|
@ -301,6 +301,7 @@ func (c *DocumentController) Create() {
|
|||
docName := c.GetString("doc_name")
|
||||
parentId, _ := c.GetInt("parent_id", 0)
|
||||
docId, _ := c.GetInt("doc_id", 0)
|
||||
isOpen,_ := c.GetInt("is_open",0)
|
||||
|
||||
if identify == "" {
|
||||
c.JsonResult(6001, "参数错误")
|
||||
|
@ -360,8 +361,14 @@ func (c *DocumentController) Create() {
|
|||
document.DocumentName = docName
|
||||
document.ParentId = parentId
|
||||
|
||||
if isOpen == 1 {
|
||||
document.IsOpen = 1
|
||||
}else{
|
||||
document.IsOpen = 0
|
||||
}
|
||||
|
||||
if err := document.InsertOrUpdate(); err != nil {
|
||||
beego.Error("InsertOrUpdate => ", err)
|
||||
beego.Error("添加或更新文档时出错 -> ", err)
|
||||
c.JsonResult(6005, "保存失败")
|
||||
} else {
|
||||
c.JsonResult(0, "ok", document)
|
||||
|
|
|
@ -21,6 +21,7 @@ type DocumentHistory struct {
|
|||
ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now" json:"modify_time"`
|
||||
ModifyAt int `orm:"column(modify_at);type(int)" json:"-"`
|
||||
Version int64 `orm:"type(bigint);column(version)" json:"version"`
|
||||
IsOpen int `orm:"column(is_open);type(int);default(0)" json:"is_open"`
|
||||
}
|
||||
|
||||
type DocumentHistorySimpleResult struct {
|
||||
|
@ -101,6 +102,7 @@ func (m *DocumentHistory) Restore(historyId, docId, uid int) error {
|
|||
history.Version = time.Now().Unix()
|
||||
history.Action = "restore"
|
||||
history.ActionName = "恢复文档"
|
||||
history.IsOpen = doc.IsOpen
|
||||
|
||||
history.InsertOrUpdate()
|
||||
|
||||
|
@ -109,6 +111,7 @@ func (m *DocumentHistory) Restore(historyId, docId, uid int) error {
|
|||
doc.Markdown = m.Markdown
|
||||
doc.Release = m.Content
|
||||
doc.Version = time.Now().Unix()
|
||||
doc.IsOpen = m.IsOpen
|
||||
|
||||
_, err = o.Update(doc)
|
||||
|
||||
|
|
|
@ -36,7 +36,9 @@ type Document struct {
|
|||
MemberId int `orm:"column(member_id);type(int)" json:"member_id"`
|
||||
ModifyTime time.Time `orm:"column(modify_time);type(datetime);auto_now" json:"modify_time"`
|
||||
ModifyAt int `orm:"column(modify_at);type(int)" json:"-"`
|
||||
Version int64 `orm:"type(bigint);column(version)" json:"version"`
|
||||
Version int64 `orm:"column(version);type(bigint);" json:"version"`
|
||||
//是否展开子目录:0 否/1 是
|
||||
IsOpen int `orm:"column(is_open);type(int);default(0)" json:"is_open"`
|
||||
AttachList []*Attachment `orm:"-" json:"attach"`
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ type DocumentTree struct {
|
|||
BookIdentify string `json:"-"`
|
||||
Version int64 `json:"version"`
|
||||
State *DocumentSelected `json:"state,omitempty"`
|
||||
AAttrs map[string]interface{} `json:"a_attr"`
|
||||
}
|
||||
type DocumentSelected struct {
|
||||
Selected bool `json:"selected"`
|
||||
|
@ -32,7 +33,7 @@ func (m *Document) FindDocumentTree(bookId int) ([]*DocumentTree, error) {
|
|||
|
||||
var docs []*Document
|
||||
|
||||
count, err := o.QueryTable(m).Filter("book_id", bookId).OrderBy("order_sort", "document_id").Limit(math.MaxInt32).All(&docs, "document_id", "version", "document_name", "parent_id", "identify")
|
||||
count, err := o.QueryTable(m).Filter("book_id", bookId).OrderBy("order_sort", "document_id").Limit(math.MaxInt32).All(&docs, "document_id", "version", "document_name", "parent_id", "identify","is_open")
|
||||
|
||||
if err != nil {
|
||||
return trees, err
|
||||
|
@ -45,6 +46,10 @@ func (m *Document) FindDocumentTree(bookId int) ([]*DocumentTree, error) {
|
|||
tree := &DocumentTree{}
|
||||
if index == 0 {
|
||||
tree.State = &DocumentSelected{Selected: true, Opened: true}
|
||||
tree.AAttrs = map[string]interface{}{ "is_open": true}
|
||||
}else if item.IsOpen == 1 {
|
||||
tree.State = &DocumentSelected{Selected: false, Opened: true}
|
||||
tree.AAttrs = map[string]interface{}{ "is_open": true}
|
||||
}
|
||||
tree.DocumentId = item.DocumentId
|
||||
tree.Identify = item.Identify
|
||||
|
@ -107,14 +112,14 @@ func getDocumentTree(array []*DocumentTree, parentId int, selectedId int, select
|
|||
if item.DocumentId == selectedId {
|
||||
selected = ` class="jstree-clicked"`
|
||||
}
|
||||
selected_li := ""
|
||||
if item.DocumentId == selectedParentId {
|
||||
selected_li = ` class="jstree-open"`
|
||||
selectedLi := ""
|
||||
if item.DocumentId == selectedParentId || (item.State != nil && item.State.Opened) {
|
||||
selectedLi = ` class="jstree-open"`
|
||||
}
|
||||
buf.WriteString("<li id=\"")
|
||||
buf.WriteString(strconv.Itoa(item.DocumentId))
|
||||
buf.WriteString("\"")
|
||||
buf.WriteString(selected_li)
|
||||
buf.WriteString(selectedLi)
|
||||
buf.WriteString("><a href=\"")
|
||||
if item.Identify != "" {
|
||||
uri := conf.URLFor("DocumentController.Read", ":key", item.BookIdentify, ":id", item.Identify)
|
||||
|
|
|
@ -109,10 +109,17 @@ function openEditCatalogDialog($node) {
|
|||
var text = $node ? $node.text : '';
|
||||
var parentId = $node && $node.parent !== '#' ? $node.parent : 0;
|
||||
|
||||
|
||||
$then.find("input[name='doc_id']").val(doc_id);
|
||||
$then.find("input[name='parent_id']").val(parentId);
|
||||
$then.find("input[name='doc_name']").val(text);
|
||||
|
||||
if($node.a_attr && $node.a_attr.is_open){
|
||||
$then.find("input[name='is_open'][value='1']").prop("checked","checked");
|
||||
}else{
|
||||
$then.find("input[name='is_open'][value='0']").prop("checked","checked");
|
||||
}
|
||||
|
||||
for (var index in window.documentCategory){
|
||||
var item = window.documentCategory[index];
|
||||
if(item.id === doc_id){
|
||||
|
@ -196,9 +203,11 @@ $("#btnAddDocument").on("click",function () {
|
|||
});
|
||||
//用于还原创建文档的遮罩层
|
||||
$("#addDocumentModal").on("hidden.bs.modal",function () {
|
||||
$(this).find("form").html(window.addDocumentModalFormHtml);
|
||||
// $(this).find("form").html(window.sessionStorage.getItem("addDocumentModal"));
|
||||
}).on("shown.bs.modal",function () {
|
||||
$(this).find("input[name='doc_name']").focus();
|
||||
}).on("show.bs.modal",function () {
|
||||
// window.sessionStorage.setItem("addDocumentModal",$(this).find("form").html())
|
||||
});
|
||||
|
||||
function showError($msg,$id) {
|
||||
|
@ -344,7 +353,6 @@ $(function () {
|
|||
type : "post",
|
||||
data : { "attach_id" : $attach_id},
|
||||
success : function (res) {
|
||||
console.log(res);
|
||||
if(res.errcode === 0){
|
||||
$this.lists = $this.lists.filter(function ($item) {
|
||||
return $item.attachment_id != $attach_id;
|
||||
|
|
|
@ -3,7 +3,7 @@ $(function () {
|
|||
js : window.katex.js,
|
||||
css : window.katex.css
|
||||
};
|
||||
window.addDocumentModalFormHtml = $(this).find("form").html();
|
||||
|
||||
window.editor = editormd("docEditor", {
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
|
@ -256,7 +256,7 @@ $(function () {
|
|||
}
|
||||
|
||||
/**
|
||||
* 添加顶级文档
|
||||
* 添加文档
|
||||
*/
|
||||
$("#addDocumentForm").ajaxForm({
|
||||
beforeSubmit: function () {
|
||||
|
@ -269,11 +269,20 @@ $(function () {
|
|||
},
|
||||
success: function (res) {
|
||||
if (res.errcode === 0) {
|
||||
var data = { "id": res.data.doc_id, 'parent': res.data.parent_id === 0 ? '#' : res.data.parent_id , "text": res.data.doc_name, "identify": res.data.identify, "version": res.data.version };
|
||||
var data = {
|
||||
"id": res.data.doc_id,
|
||||
'parent': res.data.parent_id === 0 ? '#' : res.data.parent_id ,
|
||||
"text": res.data.doc_name,
|
||||
"identify": res.data.identify,
|
||||
"version": res.data.version ,
|
||||
state: { opened: res.data.is_open == 1},
|
||||
a_attr: { is_open: res.data.is_open == 1}
|
||||
};
|
||||
|
||||
var node = window.treeCatalog.get_node(data.id);
|
||||
if (node) {
|
||||
window.treeCatalog.rename_node({ "id": data.id }, data.text);
|
||||
$("#sidebar").jstree(true).get_node(data.id).a_attr.is_open = data.state.opened;
|
||||
} else {
|
||||
window.treeCatalog.create_node(data.parent, data);
|
||||
window.treeCatalog.deselect_all();
|
||||
|
|
|
@ -154,13 +154,27 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-sm-2 control-label">文档标识</label>
|
||||
<label class="col-sm-2 control-label">文档标识 <span class="error-message"> </span></label>
|
||||
<div class="col-sm-10">
|
||||
<input type="text" name="doc_identify" id="documentIdentify" placeholder="文档唯一标识" class="form-control" maxlength="50">
|
||||
<p style="color: #999;font-size: 12px;">文档标识只能包含小写字母、数字,以及“-”和“_”符号,并且只能小写字母开头</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-lg-6">
|
||||
<label>
|
||||
<input type="radio" name="is_open" value="1"> 展开<span class="text">(在阅读时会自动展开节点)</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<label>
|
||||
<input type="radio" name="is_open" value="0" checked> 关闭<span class="text">(在阅读时会关闭节点)</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="clearfix"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<span id="add-error-message" class="error-message"></span>
|
||||
|
@ -223,7 +237,7 @@
|
|||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 显示温度历史 -->
|
||||
<!-- 显示文档历史 -->
|
||||
<div class="modal fade" id="documentHistoryModal" tabindex="-1" role="dialog" aria-labelledby="documentHistoryModalModalLabel">
|
||||
<div class="modal-dialog" role="document">
|
||||
<div class="modal-content">
|
||||
|
@ -317,7 +331,7 @@
|
|||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td colspan="6" class="text-center">暂无数据</td>
|
||||
<td colspan="7" class="text-center">暂无数据</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
Loading…
Reference in New Issue