Added trash
This commit is contained in:
parent
a3171399c0
commit
35cc2952fb
@ -46,7 +46,10 @@ export default {
|
|||||||
'toggleExplorer',
|
'toggleExplorer',
|
||||||
]),
|
]),
|
||||||
newItem(isFolder) {
|
newItem(isFolder) {
|
||||||
const parentId = this.$store.getters['explorer/selectedNodeFolder'].item.id;
|
let parentId = this.$store.getters['explorer/selectedNodeFolder'].item.id;
|
||||||
|
if (parentId === 'trash') {
|
||||||
|
parentId = undefined;
|
||||||
|
}
|
||||||
this.$store.dispatch('explorer/openNode', parentId);
|
this.$store.dispatch('explorer/openNode', parentId);
|
||||||
this.$store.commit('explorer/setNewItem', {
|
this.$store.commit('explorer/setNewItem', {
|
||||||
type: isFolder ? 'folder' : 'file',
|
type: isFolder ? 'folder' : 'file',
|
||||||
@ -55,11 +58,17 @@ export default {
|
|||||||
},
|
},
|
||||||
editItem() {
|
editItem() {
|
||||||
const selectedNode = this.$store.getters['explorer/selectedNode'];
|
const selectedNode = this.$store.getters['explorer/selectedNode'];
|
||||||
this.$store.commit('explorer/setEditingId', selectedNode.item.id);
|
if (selectedNode.item.id !== 'trash') {
|
||||||
|
this.$store.commit('explorer/setEditingId', selectedNode.item.id);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
deleteItem() {
|
deleteItem() {
|
||||||
const selectedNode = this.$store.getters['explorer/selectedNode'];
|
const selectedNode = this.$store.getters['explorer/selectedNode'];
|
||||||
if (!selectedNode.isNil) {
|
if (!selectedNode.isNil) {
|
||||||
|
if (selectedNode.item.id === 'trash' || selectedNode.item.parentId === 'trash') {
|
||||||
|
this.$store.dispatch('modal/trashDeletion');
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.$store.dispatch(selectedNode.isFolder
|
this.$store.dispatch(selectedNode.isFolder
|
||||||
? 'modal/folderDeletion'
|
? 'modal/folderDeletion'
|
||||||
: 'modal/fileDeletion',
|
: 'modal/fileDeletion',
|
||||||
@ -67,16 +76,22 @@ export default {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
if (selectedNode === this.$store.getters['explorer/selectedNode']) {
|
if (selectedNode === this.$store.getters['explorer/selectedNode']) {
|
||||||
if (selectedNode.isFolder) {
|
if (selectedNode.isFolder) {
|
||||||
const recursiveDelete = (folderNode) => {
|
const recursiveMoveToTrash = (folderNode) => {
|
||||||
folderNode.folders.forEach(recursiveDelete);
|
folderNode.folders.forEach(recursiveMoveToTrash);
|
||||||
folderNode.files.forEach((fileNode) => {
|
folderNode.files.forEach((fileNode) => {
|
||||||
this.$store.commit('file/deleteItem', fileNode.item.id);
|
this.$store.commit('file/patchItem', {
|
||||||
|
id: fileNode.item.id,
|
||||||
|
parentId: 'trash',
|
||||||
|
});
|
||||||
});
|
});
|
||||||
this.$store.commit('folder/deleteItem', folderNode.item.id);
|
this.$store.commit('folder/deleteItem', folderNode.item.id);
|
||||||
};
|
};
|
||||||
recursiveDelete(selectedNode);
|
recursiveMoveToTrash(selectedNode);
|
||||||
} else {
|
} else {
|
||||||
this.$store.commit('file/deleteItem', selectedNode.item.id);
|
this.$store.commit('file/patchItem', {
|
||||||
|
id: selectedNode.item.id,
|
||||||
|
parentId: 'trash',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -129,12 +129,11 @@ export default {
|
|||||||
this.$store.commit('explorer/setEditingId', null);
|
this.$store.commit('explorer/setEditingId', null);
|
||||||
},
|
},
|
||||||
setDragSourceId(evt) {
|
setDragSourceId(evt) {
|
||||||
const id = this.node.item.id;
|
if (this.node.noDrag) {
|
||||||
if (id === 'fake') {
|
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.$store.commit('explorer/setDragSourceId', id);
|
this.$store.commit('explorer/setDragSourceId', this.node.item.id);
|
||||||
},
|
},
|
||||||
onDrop() {
|
onDrop() {
|
||||||
const sourceNode = this.$store.getters['explorer/dragSourceNode'];
|
const sourceNode = this.$store.getters['explorer/dragSourceNode'];
|
||||||
|
@ -42,6 +42,7 @@ const nilFileNode = new Node(emptyFile());
|
|||||||
nilFileNode.isNil = true;
|
nilFileNode.isNil = true;
|
||||||
const fakeFileNode = new Node(emptyFile());
|
const fakeFileNode = new Node(emptyFile());
|
||||||
fakeFileNode.item.id = 'fake';
|
fakeFileNode.item.id = 'fake';
|
||||||
|
fakeFileNode.noDrag = true;
|
||||||
|
|
||||||
function getParent(node, getters) {
|
function getParent(node, getters) {
|
||||||
if (node.isNil) {
|
if (node.isNil) {
|
||||||
@ -68,7 +69,13 @@ export default {
|
|||||||
},
|
},
|
||||||
getters: {
|
getters: {
|
||||||
nodeStructure: (state, getters, rootState, rootGetters) => {
|
nodeStructure: (state, getters, rootState, rootGetters) => {
|
||||||
const nodeMap = {};
|
const trashFolderNode = new Node(emptyFolder(), [], true);
|
||||||
|
trashFolderNode.item.id = 'trash';
|
||||||
|
trashFolderNode.item.name = 'Trash';
|
||||||
|
trashFolderNode.noDrag = true;
|
||||||
|
const nodeMap = {
|
||||||
|
trash: trashFolderNode,
|
||||||
|
};
|
||||||
rootGetters['folder/items'].forEach((item) => {
|
rootGetters['folder/items'].forEach((item) => {
|
||||||
nodeMap[item.id] = new Node(item, [], true);
|
nodeMap[item.id] = new Node(item, [], true);
|
||||||
});
|
});
|
||||||
@ -84,6 +91,9 @@ export default {
|
|||||||
const node = nodeMap[id];
|
const node = nodeMap[id];
|
||||||
let parentNode = nodeMap[node.item.parentId];
|
let parentNode = nodeMap[node.item.parentId];
|
||||||
if (!parentNode || !parentNode.isFolder) {
|
if (!parentNode || !parentNode.isFolder) {
|
||||||
|
if (id === 'trash') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
parentNode = rootNode;
|
parentNode = rootNode;
|
||||||
}
|
}
|
||||||
if (node.isFolder) {
|
if (node.isFolder) {
|
||||||
@ -93,6 +103,9 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
rootNode.sortChildren();
|
rootNode.sortChildren();
|
||||||
|
if (trashFolderNode.files.length) {
|
||||||
|
rootNode.folders.unshift(trashFolderNode);
|
||||||
|
}
|
||||||
// Add a fake file at the end of the root folder to always allow drag and drop into it.
|
// Add a fake file at the end of the root folder to always allow drag and drop into it.
|
||||||
rootNode.files.push(fakeFileNode);
|
rootNode.files.push(fakeFileNode);
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user