Workable document moving

This commit is contained in:
Jori Lallo
2017-09-04 14:48:56 -07:00
parent 70d352e193
commit 483bf29cc4
14 changed files with 414 additions and 66 deletions

View File

@ -47,11 +47,17 @@ class Document extends BaseModel {
return !!this.lastViewedAt && this.lastViewedAt < this.updatedAt;
}
@computed get pathToDocument(): Array<string> {
@computed get pathToDocument(): Array<{ id: string, title: string }> {
let path;
const traveler = (nodes, previousPath) => {
nodes.forEach(childNode => {
const newPath = [...previousPath, childNode.id];
const newPath = [
...previousPath,
{
id: childNode.id,
title: childNode.title,
},
];
if (childNode.id === this.id) {
path = newPath;
return;
@ -174,6 +180,23 @@ class Document extends BaseModel {
return this;
};
@action move = async (parentDocumentId: ?string) => {
try {
const res = await client.post('/documents.move', {
id: this.id,
parentDocument: parentDocumentId,
});
this.updateData(res.data);
this.emit('documents.move', {
id: this.id,
collectionId: this.collection.id,
});
} catch (e) {
this.errors.add('Error while moving the document');
}
return;
};
@action delete = async () => {
try {
await client.post('/documents.delete', { id: this.id });