mirror of
https://github.com/documize/community.git
synced 2025-07-24 15:49:44 +02:00
click handlers for content links
This commit is contained in:
parent
c27de6bcab
commit
899b4f978c
27 changed files with 265 additions and 83 deletions
|
@ -29,6 +29,7 @@ func GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
|||
p := request.GetPersister(r)
|
||||
|
||||
params := mux.Vars(r)
|
||||
folderID := params["folderID"]
|
||||
documentID := params["documentID"]
|
||||
pageID := params["pageID"]
|
||||
|
||||
|
@ -68,6 +69,7 @@ func GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
|||
if p.RefID != pageID {
|
||||
c := entity.LinkCandidate{
|
||||
RefID: util.UniqueID(),
|
||||
FolderID: folderID,
|
||||
DocumentID: documentID,
|
||||
TargetID: p.RefID,
|
||||
LinkType: "section",
|
||||
|
@ -95,6 +97,7 @@ func GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
|||
for _, f := range files {
|
||||
c := entity.LinkCandidate{
|
||||
RefID: util.UniqueID(),
|
||||
FolderID: folderID,
|
||||
DocumentID: documentID,
|
||||
TargetID: f.RefID,
|
||||
LinkType: "file",
|
||||
|
@ -124,13 +127,3 @@ func GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
util.WriteSuccessBytes(w, json)
|
||||
}
|
||||
|
||||
/*
|
||||
DocumentID string `json:"documentId"`
|
||||
PageID string `json:"pageId"`
|
||||
FileID string `json:"fileId"`
|
||||
LinkType string `json:"linkType"`
|
||||
Title string `json:"caption"` // what we label the link
|
||||
Context string `json:"context"` // additional context (e.g. excerpt, parent)
|
||||
|
||||
*/
|
||||
|
|
|
@ -213,7 +213,7 @@ func init() {
|
|||
log.IfErr(Add(RoutePrefixPrivate, "sections/refresh", []string{"GET", "OPTIONS"}, nil, RefreshSections))
|
||||
|
||||
// Links
|
||||
log.IfErr(Add(RoutePrefixPrivate, "links/{documentID}/{pageID}", []string{"GET", "OPTIONS"}, nil, GetLinkCandidates))
|
||||
log.IfErr(Add(RoutePrefixPrivate, "links/{folderID}/{documentID}/{pageID}", []string{"GET", "OPTIONS"}, nil, GetLinkCandidates))
|
||||
|
||||
// Global installation-wide config
|
||||
log.IfErr(Add(RoutePrefixPrivate, "global", []string{"GET", "OPTIONS"}, nil, GetGlobalConfig))
|
||||
|
|
|
@ -347,6 +347,7 @@ type SitemapDocument struct {
|
|||
type Link struct {
|
||||
BaseEntity
|
||||
OrgID string `json:"orgId"`
|
||||
FolderID string `json:"folderId"`
|
||||
UserID string `json:"userId"`
|
||||
LinkType string `json:"linkType"`
|
||||
SourceID string `json:"sourceId"`
|
||||
|
@ -359,6 +360,7 @@ type Link struct {
|
|||
type LinkCandidate struct {
|
||||
RefID string `json:"id"`
|
||||
LinkType string `json:"linkType"`
|
||||
FolderID string `json:"folderId"`
|
||||
DocumentID string `json:"documentId"`
|
||||
TargetID string `json:"targetId"`
|
||||
Title string `json:"title"` // what we label the link
|
||||
|
|
|
@ -27,7 +27,7 @@ func (p *Persister) AddContentLink(l entity.Link) (err error) {
|
|||
l.Created = time.Now().UTC()
|
||||
l.Revised = time.Now().UTC()
|
||||
|
||||
stmt, err := p.Context.Transaction.Preparex("INSERT INTO link (refid, orgid, userid, sourceid, documentid, targetid, linktype, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
||||
stmt, err := p.Context.Transaction.Preparex("INSERT INTO link (refid, orgid, folderid, userid, sourceid, documentid, targetid, linktype, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
||||
defer utility.Close(stmt)
|
||||
|
||||
if err != nil {
|
||||
|
@ -35,7 +35,7 @@ func (p *Persister) AddContentLink(l entity.Link) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
_, err = stmt.Exec(l.RefID, l.OrgID, l.UserID, l.SourceID, l.DocumentID, l.TargetID, l.LinkType, l.Created, l.Revised)
|
||||
_, err = stmt.Exec(l.RefID, l.OrgID, l.FolderID, l.UserID, l.SourceID, l.DocumentID, l.TargetID, l.LinkType, l.Created, l.Revised)
|
||||
|
||||
if err != nil {
|
||||
log.Error("Unable to execute insert for link", err)
|
||||
|
@ -49,7 +49,7 @@ func (p *Persister) AddContentLink(l entity.Link) (err error) {
|
|||
func (p *Persister) GetReferencedLinks(sectionID string) (links []entity.Link, err error) {
|
||||
err = nil
|
||||
|
||||
sql := "SELECT id,refid,orgid,userid,sourceid,documentid,targetid,linktype,orphan,created,revised from link WHERE orgid=? AND sourceid=?"
|
||||
sql := "SELECT id,refid,orgid,folderid,userid,sourceid,documentid,targetid,linktype,orphan,created,revised from link WHERE orgid=? AND sourceid=?"
|
||||
|
||||
err = Db.Select(&links, sql, p.Context.OrgID, sectionID)
|
||||
|
||||
|
@ -65,7 +65,7 @@ func (p *Persister) GetReferencedLinks(sectionID string) (links []entity.Link, e
|
|||
func (p *Persister) GetContentLinksForSection(sectionID string) (links []entity.Link, err error) {
|
||||
err = nil
|
||||
|
||||
sql := "SELECT id,refid,orgid,userid,sourceid,documentid,targetid,linktype,orphan,created,revised from link WHERE orgid=? AND sectionid=?"
|
||||
sql := "SELECT id,refid,orgid,folderid,userid,sourceid,documentid,targetid,linktype,orphan,created,revised from link WHERE orgid=? AND sectionid=?"
|
||||
|
||||
err = Db.Select(&links, sql, p.Context.OrgID, sectionID)
|
||||
|
||||
|
@ -81,7 +81,7 @@ func (p *Persister) GetContentLinksForSection(sectionID string) (links []entity.
|
|||
func (p *Persister) GetContentLinksForDocument(documentID string) (links []entity.Link, err error) {
|
||||
err = nil
|
||||
|
||||
sql := "SELECT id,refid,orgid,userid,sourceid,documentid,targetid,linktype,orphan,created,revised from link WHERE orgid=? AND documentid=?"
|
||||
sql := "SELECT id,refid,orgid,folderid,userid,sourceid,documentid,targetid,linktype,orphan,created,revised from link WHERE orgid=? AND documentid=?"
|
||||
|
||||
err = Db.Select(&links, sql, p.Context.OrgID, documentID)
|
||||
|
||||
|
|
|
@ -287,7 +287,7 @@ func (p *Persister) UpdatePage(page entity.Page, refID, userID string, skipRevis
|
|||
//}
|
||||
//}
|
||||
|
||||
// fimnd any content links
|
||||
// find any content links in the HTML
|
||||
links := util.GetContentLinks(page.Body)
|
||||
|
||||
// delete previous content links for this page
|
||||
|
|
|
@ -14,11 +14,11 @@ package util
|
|||
import "testing"
|
||||
|
||||
func TestHTMLEncoding(t *testing.T) {
|
||||
html(t, "<script>alert('test')</script>", "<script>alert('test')</script>")
|
||||
testHTML(t, "<script>alert('test')</script>", "<script>alert('test')</script>")
|
||||
text(t, "<script>alert('test')</script>", "<script>alert('test')</script>")
|
||||
}
|
||||
|
||||
func html(t *testing.T, in, out string) {
|
||||
func testHTML(t *testing.T, in, out string) {
|
||||
got := EncodeHTMLString(in)
|
||||
if got != out {
|
||||
t.Errorf("EncodeHTMLString `%s` got `%s` expected `%s`\n", in, got, out)
|
||||
|
|
|
@ -60,6 +60,8 @@ func getLink(t html.Token) (ok bool, link entity.Link) {
|
|||
ok = true
|
||||
case "data-link-id":
|
||||
link.RefID = strings.TrimSpace(a.Val)
|
||||
case "data-link-space-id":
|
||||
link.FolderID = strings.TrimSpace(a.Val)
|
||||
case "data-link-document-id":
|
||||
link.DocumentID = strings.TrimSpace(a.Val)
|
||||
case "data-link-target-id":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue