MCPcopy Index your code
hub / github.com/TruthHun/BookStack / FindDocumentTree

Method FindDocumentTree

models/document_tree.go:32–82  ·  view source on GitHub ↗

获取书籍的文档树状结构

(bookId int, selectedId int, isEdit ...bool)

Source from the content-addressed store, hash-verified

30
31// 获取书籍的文档树状结构
32func (m *Document) FindDocumentTree(bookId int, selectedId int, isEdit ...bool) ([]*DocumentTree, error) {
33 o := orm.NewOrm()
34
35 trees := make([]*DocumentTree, 0)
36
37 var docs []*Document
38
39 count, err := o.QueryTable(m).Filter("book_id", bookId).OrderBy("order_sort", "identify").Limit(5000).All(&docs, "document_id", "version", "document_name", "parent_id", "identify")
40 if err != nil {
41 return trees, err
42 }
43 book, _ := NewBook().Find(bookId)
44
45 trees = make([]*DocumentTree, count)
46
47 for index, item := range docs {
48 tree := &DocumentTree{}
49 if selectedId > 0 {
50 if selectedId == item.DocumentId {
51 tree.State = &DocumentSelected{Selected: true, Opened: true}
52 }
53 } else {
54 if index == 0 {
55 tree.State = &DocumentSelected{Selected: true, Opened: true}
56 }
57 }
58
59 tree.DocumentId = item.DocumentId
60 tree.Identify = item.Identify
61 tree.Version = item.Version
62 tree.BookIdentify = book.Identify
63 if item.ParentId > 0 {
64 tree.ParentId = item.ParentId
65 } else {
66 tree.ParentId = "#"
67 }
68 idf := item.Identify
69 if idf == "" {
70 idf = strconv.Itoa(item.DocumentId)
71 }
72 if len(isEdit) > 0 && isEdit[0] == true {
73 tree.DocumentName = item.DocumentName + "<small class='text-danger'>(" + idf + ")</small>"
74 } else {
75 tree.DocumentName = item.DocumentName
76 }
77
78 trees[index] = tree
79 }
80
81 return trees, nil
82}
83
84func (m *Document) CreateDocumentTreeForHtml(bookId, selectedId int) (string, error) {
85 trees, err := m.FindDocumentTree(bookId, selectedId)

Callers 2

EditMethod · 0.80

Calls 3

NewBookFunction · 0.85
AllMethod · 0.45
FindMethod · 0.45

Tested by

no test coverage detected