mirror of
https://github.com/documize/community.git
synced 2025-07-19 13:19:43 +02:00
re-vamped links to work with tabs
This commit is contained in:
parent
b68a0ac6d6
commit
e7c4b2f40b
13 changed files with 86 additions and 79 deletions
|
@ -142,6 +142,40 @@ func GetDocumentMeta(w http.ResponseWriter, r *http.Request) {
|
|||
writeSuccessBytes(w, json)
|
||||
}
|
||||
|
||||
// GetDocumentLinks is an endpoint returning the links for a document.
|
||||
func GetDocumentLinks(w http.ResponseWriter, r *http.Request) {
|
||||
method := "GetDocumentLinks"
|
||||
p := request.GetPersister(r)
|
||||
|
||||
params := mux.Vars(r)
|
||||
id := params["documentID"]
|
||||
|
||||
if len(id) == 0 {
|
||||
writeMissingDataError(w, method, "documentID")
|
||||
return
|
||||
}
|
||||
|
||||
oLinks, err := p.GetDocumentOutboundLinks(id)
|
||||
|
||||
if len(oLinks) == 0 {
|
||||
oLinks = []entity.Link{}
|
||||
}
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
writeGeneralSQLError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
json, err := json.Marshal(oLinks)
|
||||
|
||||
if err != nil {
|
||||
writeJSONMarshalError(w, method, "link", err)
|
||||
return
|
||||
}
|
||||
|
||||
writeSuccessBytes(w, json)
|
||||
}
|
||||
|
||||
// GetDocumentsByFolder is an endpoint that returns the documents in a given folder.
|
||||
func GetDocumentsByFolder(w http.ResponseWriter, r *http.Request) {
|
||||
method := "GetDocumentsByFolder"
|
||||
|
|
|
@ -74,7 +74,7 @@ func GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
|||
FolderID: folderID,
|
||||
DocumentID: documentID,
|
||||
TargetID: p.RefID,
|
||||
LinkType: "section",
|
||||
LinkType: p.PageType,
|
||||
Title: p.Title,
|
||||
}
|
||||
pc = append(pc, c)
|
||||
|
|
|
@ -215,6 +215,7 @@ func init() {
|
|||
// Links
|
||||
log.IfErr(Add(RoutePrefixPrivate, "links/{folderID}/{documentID}/{pageID}", []string{"GET", "OPTIONS"}, nil, GetLinkCandidates))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "links", []string{"GET", "OPTIONS"}, nil, SearchLinkCandidates))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "documents/{documentID}/links", []string{"GET", "OPTIONS"}, nil, GetDocumentLinks))
|
||||
|
||||
// Global installation-wide config
|
||||
log.IfErr(Add(RoutePrefixPrivate, "global", []string{"GET", "OPTIONS"}, nil, GetGlobalConfig))
|
||||
|
|
|
@ -237,10 +237,8 @@ func (p *PageMeta) SetDefaults() {
|
|||
|
||||
// DocumentMeta details who viewed the document.
|
||||
type DocumentMeta struct {
|
||||
Viewers []DocumentMetaViewer `json:"viewers"`
|
||||
Editors []DocumentMetaEditor `json:"editors"`
|
||||
InboundLinks []Link `json:"inboundLinks"`
|
||||
OutboundLinks []Link `json:"outboundLinks"`
|
||||
Viewers []DocumentMetaViewer `json:"viewers"`
|
||||
Editors []DocumentMetaEditor `json:"editors"`
|
||||
}
|
||||
|
||||
// DocumentMetaViewer contains the "view" metatdata content.
|
||||
|
|
|
@ -107,13 +107,6 @@ func (p *Persister) GetDocumentMeta(id string) (meta entity.DocumentMeta, err er
|
|||
return
|
||||
}
|
||||
|
||||
meta.OutboundLinks, err = p.GetDocumentOutboundLinks(id)
|
||||
|
||||
if err != nil {
|
||||
log.Error(fmt.Sprintf("Unable to execute GetDocumentOutboundLinks for document %s", id), err)
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ func (p *Persister) SearchLinkCandidates(keywords string) (docs []entity.LinkCan
|
|||
temp = []entity.LinkCandidate{}
|
||||
|
||||
err = Db.Select(&temp,
|
||||
`SELECT p.refid as targetid, p.documentid as documentid, p.title as title, d.title as context, d.labelid as folderid from page p
|
||||
`SELECT p.refid as targetid, p.documentid as documentid, p.title as title, p.pagetype as linktype, d.title as context, d.labelid as folderid from page p
|
||||
LEFT JOIN document d ON d.refid=p.documentid WHERE p.orgid=? AND `+likeQuery+` AND d.labelid IN
|
||||
(SELECT refid from label WHERE orgid=? AND type=2 AND userid=?
|
||||
UNION ALL SELECT refid FROM label a where orgid=? AND type=1 AND refid IN (SELECT labelid from labelrole WHERE orgid=? AND userid='' AND (canedit=1 OR canview=1))
|
||||
|
@ -120,7 +120,7 @@ func (p *Persister) SearchLinkCandidates(keywords string) (docs []entity.LinkCan
|
|||
FolderID: r.FolderID,
|
||||
DocumentID: r.DocumentID,
|
||||
TargetID: r.TargetID,
|
||||
LinkType: "section",
|
||||
LinkType: r.LinkType,
|
||||
Title: r.Title,
|
||||
Context: r.Context,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue