mirror of
https://github.com/documize/community.git
synced 2025-07-24 07:39:43 +02:00
Allow doc/section/files links to open in tabs
Closes #233 and might help #236
This commit is contained in:
parent
92696c5181
commit
9e3eac19aa
12 changed files with 886 additions and 743 deletions
|
@ -13,9 +13,12 @@ package link
|
|||
|
||||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/documize/community/core/stringutil"
|
||||
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/core/request"
|
||||
"github.com/documize/community/core/response"
|
||||
|
@ -160,3 +163,55 @@ func (h *Handler) SearchLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
response.WriteJSON(w, payload)
|
||||
}
|
||||
|
||||
// GetLink returns link object for given ID.
|
||||
func (h *Handler) GetLink(w http.ResponseWriter, r *http.Request) {
|
||||
method := "link.GetLink"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
// Param check.
|
||||
linkID := request.Param(r, "linkID")
|
||||
if len(linkID) == 0 {
|
||||
response.WriteMissingDataError(w, method, "linkID")
|
||||
return
|
||||
}
|
||||
|
||||
// Load link record.
|
||||
link, err := h.Store.Link.GetLink(ctx, linkID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
// Check document permissions.
|
||||
if !permission.CanViewDocument(ctx, *h.Store, link.SourceDocumentID) {
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
// Build URL for link
|
||||
url := ""
|
||||
|
||||
// Jump-to-document link type.
|
||||
if link.LinkType == "document" {
|
||||
doc, err := h.Store.Document.Get(ctx, link.TargetDocumentID)
|
||||
if err != nil {
|
||||
response.WriteString(w, url)
|
||||
}
|
||||
url = ctx.GetAppURL(fmt.Sprintf("s/%s/%s/d/%s/%s",
|
||||
doc.SpaceID, doc.SpaceID, doc.RefID, stringutil.MakeSlug(doc.Name)))
|
||||
}
|
||||
|
||||
// Jump-to-section link type.
|
||||
if link.LinkType == "section" || link.LinkType == "tab" {
|
||||
doc, err := h.Store.Document.Get(ctx, link.TargetDocumentID)
|
||||
if err != nil {
|
||||
response.WriteString(w, url)
|
||||
}
|
||||
url = ctx.GetAppURL(fmt.Sprintf("s/%s/%s/d/%s/%s?currentPageId=%s",
|
||||
doc.SpaceID, doc.SpaceID, doc.RefID,
|
||||
stringutil.MakeSlug(doc.Name), link.TargetID))
|
||||
}
|
||||
|
||||
response.WriteString(w, url)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue