feat: Templates (#1399)

* Migrations
* New from template
* fix: Don't allow public share of template
* chore: Template badges
* fix: Collection active
* feat: New doc button on template list item
* feat: New template menu
* fix: Sorting
* feat: Templates onboarding notice
* fix: New doc button showing on archived/deleted templates
This commit is contained in:
Tom Moor
2020-08-08 15:18:37 -07:00
committed by GitHub
parent 59c24aba7c
commit 869fc086d6
51 changed files with 1007 additions and 327 deletions

View File

@@ -98,6 +98,7 @@ const Document = sequelize.define(
},
},
version: DataTypes.SMALLINT,
template: DataTypes.BOOLEAN,
editorVersion: DataTypes.STRING,
text: DataTypes.TEXT,
@@ -142,6 +143,10 @@ Document.associate = models => {
as: "team",
foreignKey: "teamId",
});
Document.belongsTo(models.Document, {
as: "document",
foreignKey: "templateId",
});
Document.belongsTo(models.User, {
as: "createdBy",
foreignKey: "createdById",
@@ -431,20 +436,28 @@ Document.searchForUser = async (
// Hooks
Document.addHook("beforeSave", async model => {
if (!model.publishedAt) return;
if (!model.publishedAt || model.template) {
return;
}
const collection = await Collection.findByPk(model.collectionId);
if (!collection || collection.type !== "atlas") return;
if (!collection || collection.type !== "atlas") {
return;
}
await collection.updateDocument(model);
model.collection = collection;
});
Document.addHook("afterCreate", async model => {
if (!model.publishedAt) return;
if (!model.publishedAt || model.template) {
return;
}
const collection = await Collection.findByPk(model.collectionId);
if (!collection || collection.type !== "atlas") return;
if (!collection || collection.type !== "atlas") {
return;
}
await collection.addDocumentToStructure(model);
model.collection = collection;