mirror of
https://github.com/documize/community.git
synced 2025-07-24 15:49:44 +02:00
detect broken links
This commit is contained in:
parent
ad716a23ba
commit
16b7fd45d7
11 changed files with 148 additions and 108 deletions
|
@ -71,21 +71,26 @@ export default Ember.Component.extend(NotifierMixin, TooltipMixin, {
|
|||
let self = this;
|
||||
|
||||
$("a[data-documize='true']").off('click').on('click', function() {
|
||||
let link = links.getLinkObject(this);
|
||||
let link = links.getLinkObject(self.get('meta.outboundLinks'), this);
|
||||
|
||||
// local link? exists?
|
||||
if (link.linkType === "section" && link.documentId === doc.get('id')) {
|
||||
let exists = self.get('pages').findBy('id', link.targetId);
|
||||
|
||||
if (_.isUndefined(exists) || link.orphan) {
|
||||
self.showNotification('Broken link!');
|
||||
return false;
|
||||
if (_.isUndefined(exists)) {
|
||||
link.orphan = true;
|
||||
} else {
|
||||
self.attrs.gotoPage(link.targetId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (link.orphan) {
|
||||
$(this).addClass('broken-link');
|
||||
self.showNotification('Broken link!');
|
||||
return false;
|
||||
}
|
||||
|
||||
links.linkClick(doc, link);
|
||||
return false;
|
||||
});
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
onAttachmentUpload=(action 'onAttachmentUpload')
|
||||
onDocumentDelete=(action 'onDocumentDelete')}}
|
||||
|
||||
{{document/document-view document=model pages=pages attachments=attachments folder=folder folders=folders
|
||||
{{document/document-view document=model meta=meta pages=pages attachments=attachments folder=folder folders=folders
|
||||
isEditor=isEditor
|
||||
gotoPage=(action 'gotoPage')
|
||||
onAttachmentDeleted=(action 'onAttachmentDeleted')
|
||||
|
|
|
@ -50,7 +50,6 @@ export default Ember.Service.extend({
|
|||
});
|
||||
},
|
||||
|
||||
|
||||
buildLink(link) {
|
||||
let result = "";
|
||||
let href = "";
|
||||
|
@ -59,21 +58,21 @@ export default Ember.Service.extend({
|
|||
|
||||
if (link.linkType === "section" || link.linkType === "document") {
|
||||
href = `/link/${link.linkType}/${link.id}`;
|
||||
result = `<a data-documize='true' data-link-space-id='${link.folderId}' data-link-id='${link.id}' data-link-document-id='${link.documentId}' data-link-target-id='${link.targetId}' data-link-type='${link.linkType}' href='${href}'>${link.title}</a>`;
|
||||
result = `<a data-documize='true' data-link-space-id='${link.folderId}' data-link-id='${link.id}' data-link-target-document-id='${link.documentId}' data-link-target-id='${link.targetId}' data-link-type='${link.linkType}' href='${href}'>${link.title}</a>`;
|
||||
}
|
||||
if (link.linkType === "file") {
|
||||
href = `${endpoint}/public/attachments/${orgId}/${link.targetId}`;
|
||||
result = `<a data-documize='true' data-link-space-id='${link.folderId}' data-link-id='${link.id}' data-link-document-id='${link.documentId}' data-link-target-id='${link.targetId}' data-link-type='${link.linkType}' href='${href}'>${link.title}</a>`;
|
||||
result = `<a data-documize='true' data-link-space-id='${link.folderId}' data-link-id='${link.id}' data-link-target-document-id='${link.documentId}' data-link-target-id='${link.targetId}' data-link-type='${link.linkType}' href='${href}'>${link.title}</a>`;
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
getLinkObject(a) {
|
||||
getLinkObject(outboundLinks, a) {
|
||||
let link = {
|
||||
linkId: a.attributes["data-link-id"].value,
|
||||
linkType: a.attributes["data-link-type"].value,
|
||||
documentId: a.attributes["data-link-document-id"].value,
|
||||
documentId: a.attributes["data-link-target-document-id"].value,
|
||||
folderId: a.attributes["data-link-space-id"].value,
|
||||
targetId: a.attributes["data-link-target-id"].value,
|
||||
url: a.attributes["href"].value,
|
||||
|
@ -82,6 +81,15 @@ export default Ember.Service.extend({
|
|||
|
||||
link.orphan = _.isEmpty(link.linkId) || _.isEmpty(link.documentId) || _.isEmpty(link.folderId) || _.isEmpty(link.targetId);
|
||||
|
||||
// we check latest state of link using database data
|
||||
let existing = outboundLinks.findBy('id', link.linkId);
|
||||
|
||||
if (_.isUndefined(existing)) {
|
||||
link.orphan = true;
|
||||
} else {
|
||||
link.orphan = existing.orphan;
|
||||
}
|
||||
|
||||
return link;
|
||||
},
|
||||
|
||||
|
@ -119,21 +127,12 @@ export default Ember.Service.extend({
|
|||
});
|
||||
|
||||
/*
|
||||
|
||||
The link id's get ZERO'd in Page.Body whenever:
|
||||
- doc is moved to different space
|
||||
- doc is deleted (set to ZERO and marked as orphan)
|
||||
- page is deleted (set to ZERO and marked as orphan)
|
||||
- page is moved to different doc (update data-document-id attribute value)
|
||||
- attachment is deleted (remove HREF)
|
||||
|
||||
link/section/{documentId}/{sectionId}:
|
||||
- if ZERO id show notification
|
||||
- store previous positions -- localStorage, dropdown menu?
|
||||
|
||||
Markdown editor support
|
||||
when attachment deleted:
|
||||
mark as orphan references where link.documentid = document.refId
|
||||
|
||||
permission checks:
|
||||
can view space
|
||||
can view document
|
||||
|
||||
Markdown editor support
|
||||
*/
|
||||
|
|
|
@ -132,6 +132,11 @@ a {
|
|||
}
|
||||
}
|
||||
|
||||
a.broken-link {
|
||||
color: $color-red;
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
a.alt {
|
||||
color: $color-blue;
|
||||
text-decoration: none;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue