mirror of
https://github.com/mindoc-org/mindoc.git
synced 2025-12-19 19:57:09 +08:00
feat:1、实现空节点功能,当文档标记为空目录时不加载内容页无法编辑内容
2、实现HTTP接口方式登录, 3、优化markdown编辑器部分功能
This commit is contained in:
@@ -2,26 +2,27 @@ package models
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"html/template"
|
||||
"math"
|
||||
"fmt"
|
||||
"github.com/astaxie/beego/orm"
|
||||
"github.com/lifei6671/mindoc/conf"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"math"
|
||||
)
|
||||
|
||||
type DocumentTree struct {
|
||||
DocumentId int `json:"id"`
|
||||
DocumentName string `json:"text"`
|
||||
ParentId interface{} `json:"parent"`
|
||||
Identify string `json:"identify"`
|
||||
BookIdentify string `json:"-"`
|
||||
Version int64 `json:"version"`
|
||||
State *DocumentSelected `json:"-"`
|
||||
AAttrs map[string]interface{} `json:"a_attr"`
|
||||
DocumentId int `json:"id"`
|
||||
DocumentName string `json:"text"`
|
||||
ParentId interface{} `json:"parent"`
|
||||
Identify string `json:"identify"`
|
||||
BookIdentify string `json:"-"`
|
||||
Version int64 `json:"version"`
|
||||
State *DocumentSelected `json:"-"`
|
||||
AAttrs map[string]interface{} `json:"a_attr"`
|
||||
}
|
||||
type DocumentSelected struct {
|
||||
Selected bool `json:"selected"`
|
||||
Opened bool `json:"opened"`
|
||||
Disabled bool `json:"disabled"`
|
||||
}
|
||||
|
||||
//获取项目的文档树状结构
|
||||
@@ -32,7 +33,10 @@ func (item *Document) FindDocumentTree(bookId int) ([]*DocumentTree, error) {
|
||||
|
||||
var docs []*Document
|
||||
|
||||
count, err := o.QueryTable(item).Filter("book_id", bookId).OrderBy("order_sort", "document_id").Limit(math.MaxInt32).All(&docs, "document_id", "version", "document_name", "parent_id", "identify","is_open")
|
||||
count, err := o.QueryTable(item).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
|
||||
@@ -42,13 +46,19 @@ func (item *Document) FindDocumentTree(bookId int) ([]*DocumentTree, error) {
|
||||
trees = make([]*DocumentTree, count)
|
||||
|
||||
for index, item := range docs {
|
||||
tree := &DocumentTree{}
|
||||
tree := &DocumentTree{
|
||||
AAttrs: map[string]interface{}{"is_open": false, "opened": 0},
|
||||
}
|
||||
if index == 0 {
|
||||
tree.State = &DocumentSelected{Selected: true, Opened: true}
|
||||
tree.AAttrs = map[string]interface{}{ "is_open": true}
|
||||
}else if item.IsOpen == 1 {
|
||||
tree.AAttrs = map[string]interface{}{"is_open": true, "opened": 1}
|
||||
} else if item.IsOpen == 1 {
|
||||
tree.State = &DocumentSelected{Selected: false, Opened: true}
|
||||
tree.AAttrs = map[string]interface{}{ "is_open": true}
|
||||
tree.AAttrs = map[string]interface{}{"is_open": true, "opened": 1}
|
||||
}
|
||||
if item.IsOpen == 2 {
|
||||
tree.State = &DocumentSelected{Selected: false, Opened: false, Disabled: true}
|
||||
tree.AAttrs = map[string]interface{}{"disabled": true, "opened": 2}
|
||||
}
|
||||
tree.DocumentId = item.DocumentId
|
||||
tree.Identify = item.Identify
|
||||
@@ -115,7 +125,7 @@ func getDocumentTree(array []*DocumentTree, parentId int, selectedId int, select
|
||||
if item.DocumentId == selectedParentId || (item.State != nil && item.State.Opened) {
|
||||
selectedLi = ` class="jstree-open"`
|
||||
}
|
||||
buf.WriteString(fmt.Sprintf("<li id=\"%d\"%s><a href=\"",item.DocumentId,selectedLi))
|
||||
buf.WriteString(fmt.Sprintf("<li id=\"%d\"%s><a href=\"", item.DocumentId, selectedLi))
|
||||
if item.Identify != "" {
|
||||
uri := conf.URLFor("DocumentController.Read", ":key", item.BookIdentify, ":id", item.Identify)
|
||||
buf.WriteString(uri)
|
||||
@@ -123,9 +133,11 @@ func getDocumentTree(array []*DocumentTree, parentId int, selectedId int, select
|
||||
uri := conf.URLFor("DocumentController.Read", ":key", item.BookIdentify, ":id", item.DocumentId)
|
||||
buf.WriteString(uri)
|
||||
}
|
||||
buf.WriteString(fmt.Sprintf("\" title=\"%s\"",template.HTMLEscapeString(item.DocumentName)))
|
||||
buf.WriteString(fmt.Sprintf(" data-version=\"%d\"%s>%s</a>",item.Version,selected,template.HTMLEscapeString(item.DocumentName)))
|
||||
|
||||
buf.WriteString(fmt.Sprintf("\" title=\"%s\"", template.HTMLEscapeString(item.DocumentName)))
|
||||
if item.State != nil && item.State.Disabled {
|
||||
buf.WriteString(" disabled=\"true\"")
|
||||
}
|
||||
buf.WriteString(fmt.Sprintf(" data-version=\"%d\"%s>%s</a>", item.Version, selected, template.HTMLEscapeString(item.DocumentName)))
|
||||
|
||||
for _, sub := range array {
|
||||
if p, ok := sub.ParentId.(int); ok && p == item.DocumentId {
|
||||
|
||||
Reference in New Issue
Block a user