Workable document moving
This commit is contained in:
@ -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 });
|
||||
|
Reference in New Issue
Block a user