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:
27
server/models/Backlink.js
Normal file
27
server/models/Backlink.js
Normal file
@@ -0,0 +1,27 @@
|
||||
// @flow
|
||||
import { DataTypes, sequelize } from '../sequelize';
|
||||
|
||||
const Backlink = sequelize.define('backlink', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
});
|
||||
|
||||
Backlink.associate = models => {
|
||||
Backlink.belongsTo(models.Document, {
|
||||
as: 'document',
|
||||
foreignKey: 'documentId',
|
||||
});
|
||||
Backlink.belongsTo(models.Document, {
|
||||
as: 'reverseDocument',
|
||||
foreignKey: 'reverseDocumentId',
|
||||
});
|
||||
Backlink.belongsTo(models.User, {
|
||||
as: 'user',
|
||||
foreignKey: 'userId',
|
||||
});
|
||||
};
|
||||
|
||||
export default Backlink;
|
||||
@@ -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;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// @flow
|
||||
import ApiKey from './ApiKey';
|
||||
import Authentication from './Authentication';
|
||||
import Backlink from './Backlink';
|
||||
import Collection from './Collection';
|
||||
import CollectionUser from './CollectionUser';
|
||||
import Document from './Document';
|
||||
@@ -18,6 +19,7 @@ import View from './View';
|
||||
const models = {
|
||||
ApiKey,
|
||||
Authentication,
|
||||
Backlink,
|
||||
Collection,
|
||||
CollectionUser,
|
||||
Document,
|
||||
@@ -43,6 +45,7 @@ Object.keys(models).forEach(modelName => {
|
||||
export {
|
||||
ApiKey,
|
||||
Authentication,
|
||||
Backlink,
|
||||
Collection,
|
||||
CollectionUser,
|
||||
Document,
|
||||
|
||||
Reference in New Issue
Block a user