feat: Backlinks (#979)

* feat: backlinks

* feat: add backlinkDocumentId to documents.list

* chore: refactor
fix: create and delete backlink handling

* fix: guard against self links

* feat: basic frontend
fix: race condition

* styling

* test: fix parse ids

* self review

* linting

* feat: Improved link styling

* fix: Increase clickable area at bottom of doc / between references

* perf: global styles are SLOW
This commit is contained in:
Tom Moor
2019-07-07 19:25:45 -07:00
committed by GitHub
parent 599e5c8f5d
commit 091e542406
23 changed files with 538 additions and 89 deletions

View File

@ -32,12 +32,17 @@ const createRevision = (doc, options = {}) => {
// we don't create revisions if identical to previous
if (doc.text === doc.previous('text')) return;
return Revision.create({
title: doc.title,
text: doc.text,
userId: doc.lastModifiedById,
documentId: doc.id,
});
return Revision.create(
{
title: doc.title,
text: doc.text,
userId: doc.lastModifiedById,
documentId: doc.id,
},
{
transaction: options.transaction,
}
);
};
const createUrlId = doc => {
@ -141,6 +146,9 @@ Document.associate = models => {
as: 'revisions',
onDelete: 'cascade',
});
Document.hasMany(models.Backlink, {
as: 'backlinks',
});
Document.hasMany(models.Star, {
as: 'starred',
});
@ -363,16 +371,16 @@ Document.prototype.archiveWithChildren = async function(userId, options) {
return this.save(options);
};
Document.prototype.publish = async function() {
if (this.publishedAt) return this.save();
Document.prototype.publish = async function(options) {
if (this.publishedAt) return this.save(options);
const collection = await Collection.findByPk(this.collectionId);
if (collection.type !== 'atlas') return this.save();
if (collection.type !== 'atlas') return this.save(options);
await collection.addDocumentToStructure(this);
this.publishedAt = new Date();
await this.save();
await this.save(options);
this.collection = collection;
return this;