mirror of
https://github.com/documize/community.git
synced 2025-07-19 13:19:43 +02:00
completed red-line links
This commit is contained in:
parent
16b7fd45d7
commit
7c2051cc7a
8 changed files with 70 additions and 16 deletions
|
@ -70,7 +70,7 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
||||||
let doc = this.get('document');
|
let doc = this.get('document');
|
||||||
let self = this;
|
let self = this;
|
||||||
|
|
||||||
$("a[data-documize='true']").off('click').on('click', function() {
|
$("a[data-documize='true']").off('click').on('click', function(e) {
|
||||||
let link = links.getLinkObject(self.get('meta.outboundLinks'), this);
|
let link = links.getLinkObject(self.get('meta.outboundLinks'), this);
|
||||||
|
|
||||||
// local link? exists?
|
// local link? exists?
|
||||||
|
@ -88,6 +88,8 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
||||||
if (link.orphan) {
|
if (link.orphan) {
|
||||||
$(this).addClass('broken-link');
|
$(this).addClass('broken-link');
|
||||||
self.showNotification('Broken link!');
|
self.showNotification('Broken link!');
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -355,7 +355,7 @@ type Link struct {
|
||||||
SourceDocumentID string `json:"sourceDocumentId"`
|
SourceDocumentID string `json:"sourceDocumentId"`
|
||||||
SourcePageID string `json:"sourcePageId"`
|
SourcePageID string `json:"sourcePageId"`
|
||||||
TargetDocumentID string `json:"targetDocumentId"`
|
TargetDocumentID string `json:"targetDocumentId"`
|
||||||
TargetPageID string `json:"targetPageId"`
|
TargetID string `json:"targetId"`
|
||||||
Orphan bool `json:"orphan"`
|
Orphan bool `json:"orphan"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,5 +102,10 @@ func (p *Persister) GetAttachmentsWithData(docID string) (attachments []entity.A
|
||||||
|
|
||||||
// DeleteAttachment deletes the id record from the database attachment table.
|
// DeleteAttachment deletes the id record from the database attachment table.
|
||||||
func (p *Persister) DeleteAttachment(id string) (rows int64, err error) {
|
func (p *Persister) DeleteAttachment(id string) (rows int64, err error) {
|
||||||
return p.Base.DeleteConstrained(p.Context.Transaction, "attachment", p.Context.OrgID, id)
|
rows, err = p.Base.DeleteConstrained(p.Context.Transaction, "attachment", p.Context.OrgID, id)
|
||||||
|
|
||||||
|
// Mark references to this document as orphaned
|
||||||
|
err = p.MarkOrphanAttachmentLink(id)
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ func (p *Persister) AddContentLink(l entity.Link) (err error) {
|
||||||
l.Created = time.Now().UTC()
|
l.Created = time.Now().UTC()
|
||||||
l.Revised = time.Now().UTC()
|
l.Revised = time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := p.Context.Transaction.Preparex("INSERT INTO link (refid, orgid, folderid, userid, sourcedocumentid, sourcepageid, targetdocumentid, targetpageid, linktype, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
stmt, err := p.Context.Transaction.Preparex("INSERT INTO link (refid, orgid, folderid, userid, sourcedocumentid, sourcepageid, targetdocumentid, targetid, linktype, orphan, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
||||||
defer utility.Close(stmt)
|
defer utility.Close(stmt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -35,7 +35,7 @@ func (p *Persister) AddContentLink(l entity.Link) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = stmt.Exec(l.RefID, l.OrgID, l.FolderID, l.UserID, l.SourceDocumentID, l.SourcePageID, l.TargetDocumentID, l.TargetPageID, l.LinkType, l.Created, l.Revised)
|
_, err = stmt.Exec(l.RefID, l.OrgID, l.FolderID, l.UserID, l.SourceDocumentID, l.SourcePageID, l.TargetDocumentID, l.TargetID, l.LinkType, l.Orphan, l.Created, l.Revised)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Unable to execute insert for link", err)
|
log.Error("Unable to execute insert for link", err)
|
||||||
|
@ -185,7 +185,7 @@ func (p *Persister) GetDocumentOutboundLinks(documentID string) (links []entity.
|
||||||
err = nil
|
err = nil
|
||||||
|
|
||||||
err = Db.Select(&links,
|
err = Db.Select(&links,
|
||||||
`select l.refid, l.orgid, l.folderid, l.userid, l.sourcedocumentid, l.sourcepageid, l.targetdocumentid, l.targetpageid, l.linktype, l.orphan, l.created, l.revised
|
`select l.refid, l.orgid, l.folderid, l.userid, l.sourcedocumentid, l.sourcepageid, l.targetdocumentid, l.targetid, l.linktype, l.orphan, l.created, l.revised
|
||||||
FROM link l
|
FROM link l
|
||||||
WHERE l.orgid=? AND l.sourcedocumentid=?`,
|
WHERE l.orgid=? AND l.sourcedocumentid=?`,
|
||||||
p.Context.OrgID,
|
p.Context.OrgID,
|
||||||
|
@ -202,6 +202,29 @@ func (p *Persister) GetDocumentOutboundLinks(documentID string) (links []entity.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetPageLinks returns outbound links for specified page in document.
|
||||||
|
func (p *Persister) GetPageLinks(documentID, pageID string) (links []entity.Link, err error) {
|
||||||
|
err = nil
|
||||||
|
|
||||||
|
err = Db.Select(&links,
|
||||||
|
`select l.refid, l.orgid, l.folderid, l.userid, l.sourcedocumentid, l.sourcepageid, l.targetdocumentid, l.targetid, l.linktype, l.orphan, l.created, l.revised
|
||||||
|
FROM link l
|
||||||
|
WHERE l.orgid=? AND l.sourcedocumentid=? AND l.sourcepageid=?`,
|
||||||
|
p.Context.OrgID,
|
||||||
|
documentID,
|
||||||
|
pageID)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(links) == 0 {
|
||||||
|
links = []entity.Link{}
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// MarkOrphanDocumentLink marks all link records referencing specified document.
|
// MarkOrphanDocumentLink marks all link records referencing specified document.
|
||||||
func (p *Persister) MarkOrphanDocumentLink(documentID string) (err error) {
|
func (p *Persister) MarkOrphanDocumentLink(documentID string) (err error) {
|
||||||
revised := time.Now().UTC()
|
revised := time.Now().UTC()
|
||||||
|
@ -216,10 +239,6 @@ func (p *Persister) MarkOrphanDocumentLink(documentID string) (err error) {
|
||||||
|
|
||||||
_, err = stmt.Exec(revised, p.Context.OrgID, documentID)
|
_, err = stmt.Exec(revised, p.Context.OrgID, documentID)
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +246,7 @@ func (p *Persister) MarkOrphanDocumentLink(documentID string) (err error) {
|
||||||
func (p *Persister) MarkOrphanPageLink(pageID string) (err error) {
|
func (p *Persister) MarkOrphanPageLink(pageID string) (err error) {
|
||||||
revised := time.Now().UTC()
|
revised := time.Now().UTC()
|
||||||
|
|
||||||
stmt, err := p.Context.Transaction.Preparex("UPDATE link SET orphan=1, revised=? WHERE linktype='section' AND orgid=? AND targetpageid=?")
|
stmt, err := p.Context.Transaction.Preparex("UPDATE link SET orphan=1, revised=? WHERE linktype='section' AND orgid=? AND targetid=?")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -237,10 +256,23 @@ func (p *Persister) MarkOrphanPageLink(pageID string) (err error) {
|
||||||
|
|
||||||
_, err = stmt.Exec(revised, p.Context.OrgID, pageID)
|
_, err = stmt.Exec(revised, p.Context.OrgID, pageID)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarkOrphanAttachmentLink marks all link records referencing specified attachment.
|
||||||
|
func (p *Persister) MarkOrphanAttachmentLink(attachmentID string) (err error) {
|
||||||
|
revised := time.Now().UTC()
|
||||||
|
|
||||||
|
stmt, err := p.Context.Transaction.Preparex("UPDATE link SET orphan=1, revised=? WHERE linktype='file' AND orgid=? AND targetid=?")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer utility.Close(stmt)
|
||||||
|
|
||||||
|
_, err = stmt.Exec(revised, p.Context.OrgID, attachmentID)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -290,6 +290,10 @@ func (p *Persister) UpdatePage(page entity.Page, refID, userID string, skipRevis
|
||||||
// find any content links in the HTML
|
// find any content links in the HTML
|
||||||
links := util.GetContentLinks(page.Body)
|
links := util.GetContentLinks(page.Body)
|
||||||
|
|
||||||
|
// get a copy of previously saved links
|
||||||
|
previousLinks, _ := p.GetPageLinks(page.DocumentID, page.RefID)
|
||||||
|
fmt.Println(len(previousLinks))
|
||||||
|
|
||||||
// delete previous content links for this page
|
// delete previous content links for this page
|
||||||
_, _ = p.DeleteSourcePageLinks(page.RefID)
|
_, _ = p.DeleteSourcePageLinks(page.RefID)
|
||||||
|
|
||||||
|
@ -299,11 +303,22 @@ func (p *Persister) UpdatePage(page entity.Page, refID, userID string, skipRevis
|
||||||
link.OrgID = p.Context.OrgID
|
link.OrgID = p.Context.OrgID
|
||||||
link.UserID = p.Context.UserID
|
link.UserID = p.Context.UserID
|
||||||
link.SourceDocumentID = page.DocumentID
|
link.SourceDocumentID = page.DocumentID
|
||||||
|
link.SourcePageID = page.RefID
|
||||||
|
|
||||||
if link.LinkType == "section" {
|
if link.LinkType == "document" {
|
||||||
link.SourcePageID = page.RefID
|
link.TargetID = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We check if there was a previously saved version of this link.
|
||||||
|
// If we find one, we carry forward the orphan flag.
|
||||||
|
for _, p := range previousLinks {
|
||||||
|
if link.TargetID == p.TargetID && link.LinkType == p.LinkType {
|
||||||
|
link.Orphan = p.Orphan
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// save
|
||||||
err := p.AddContentLink(link)
|
err := p.AddContentLink(link)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -65,7 +65,7 @@ func getLink(t html.Token) (ok bool, link entity.Link) {
|
||||||
case "data-link-target-document-id":
|
case "data-link-target-document-id":
|
||||||
link.TargetDocumentID = strings.TrimSpace(a.Val)
|
link.TargetDocumentID = strings.TrimSpace(a.Val)
|
||||||
case "data-link-target-id":
|
case "data-link-target-id":
|
||||||
link.TargetPageID = strings.TrimSpace(a.Val)
|
link.TargetID = strings.TrimSpace(a.Val)
|
||||||
case "data-link-type":
|
case "data-link-type":
|
||||||
link.LinkType = strings.TrimSpace(a.Val)
|
link.LinkType = strings.TrimSpace(a.Val)
|
||||||
}
|
}
|
||||||
|
|
|
@ -325,7 +325,7 @@ CREATE TABLE IF NOT EXISTS `link` (
|
||||||
`sourcepageid` CHAR(16) NOT NULL COLLATE utf8_bin,
|
`sourcepageid` CHAR(16) NOT NULL COLLATE utf8_bin,
|
||||||
`linktype` CHAR(16) NOT NULL COLLATE utf8_bin,
|
`linktype` CHAR(16) NOT NULL COLLATE utf8_bin,
|
||||||
`targetdocumentid` CHAR(16) NOT NULL COLLATE utf8_bin,
|
`targetdocumentid` CHAR(16) NOT NULL COLLATE utf8_bin,
|
||||||
`targetpageid` CHAR(16) DEFAULT '' COLLATE utf8_bin,
|
`targetid` CHAR(16) NOT NULL DEFAULT '' COLLATE utf8_bin,
|
||||||
`orphan` BOOL NOT NULL DEFAULT 0,
|
`orphan` BOOL NOT NULL DEFAULT 0,
|
||||||
`created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
`created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
`revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
`revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|
|
@ -11,7 +11,7 @@ CREATE TABLE IF NOT EXISTS `link` (
|
||||||
`sourcepageid` CHAR(16) NOT NULL COLLATE utf8_bin,
|
`sourcepageid` CHAR(16) NOT NULL COLLATE utf8_bin,
|
||||||
`linktype` CHAR(16) NOT NULL COLLATE utf8_bin,
|
`linktype` CHAR(16) NOT NULL COLLATE utf8_bin,
|
||||||
`targetdocumentid` CHAR(16) NOT NULL COLLATE utf8_bin,
|
`targetdocumentid` CHAR(16) NOT NULL COLLATE utf8_bin,
|
||||||
`targetpageid` CHAR(16) DEFAULT '' COLLATE utf8_bin,
|
`targetid` CHAR(16) NOT NULL DEFAULT '' COLLATE utf8_bin,
|
||||||
`orphan` BOOL NOT NULL DEFAULT 0,
|
`orphan` BOOL NOT NULL DEFAULT 0,
|
||||||
`created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
`created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
`revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
`revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue