Commit fd67a20e authored by Phil Hughes's avatar Phil Hughes

changed adding temp files/directories code to match new structure

this uses the new data structure of adding into the different arrays
which makes the code a lot easier to work with.

Some changes need to be made around commiting & changing the content.

[ci skip]
parent e5cd65a4
......@@ -27,29 +27,23 @@
let tree = RepoStore;
if (this.type === 'tree') {
tree = RepoHelper.serializeRepoEntity('tree', {
name: this.entryName,
path: this.entryName,
icon: 'folder',
tempFile: true,
});
RepoStore.files.push(tree);
const dirNames = this.entryName.split('/');
RepoHelper.setDirectoryOpen(tree, tree.name);
dirNames.forEach((dirName) => {
tree = RepoHelper.findOrCreateEntry('tree', tree, dirName).entry;
});
}
const file = RepoHelper.serializeRepoEntity('blob', {
name: fileName,
path: tree.path ? `${tree.path}/${fileName}` : fileName,
icon: 'file-text-o',
tempFile: true,
}, (this.type === 'tree' ? tree.level + 1 : 0));
if ((this.type === 'tree' && tree.tempFile) || this.type === 'blob') {
const file = RepoHelper.findOrCreateEntry('blob', tree, fileName);
tree.files.push(file);
if (!file.exists) {
RepoHelper.setFile(file.entry, file.entry);
RepoHelper.setFile(file, file);
RepoStore.editMode = true;
RepoStore.toggleBlobView();
}
}
this.toggleModalOpen();
},
......
......@@ -157,7 +157,7 @@ const RepoHelper = {
},
serializeRepoEntity(type, entity, level = 0) {
const { id, url, name, icon, last_commit, tree_url, path, tempFile } = entity;
const { id, url, name, icon, last_commit, tree_url, path, tempFile, opened = false } = entity;
return {
id,
......@@ -171,7 +171,7 @@ const RepoHelper = {
icon: `fa-${icon}`,
files: [],
loading: false,
opened: false,
opened,
// eslint-disable-next-line camelcase
lastCommit: last_commit ? {
url: `${Store.projectUrl}/commit/${last_commit.id}`,
......@@ -225,6 +225,29 @@ const RepoHelper = {
loadingError() {
Flash('Unable to load this content at this time.');
},
findOrCreateEntry(type, tree, name) {
let exists = true;
let foundEntry = tree.files.find(dir => dir.type === type && dir.name === name);
if (!foundEntry) {
foundEntry = RepoHelper.serializeRepoEntity(type, {
name,
path: tree.path ? `${tree.path}/${name}` : name,
icon: type === 'tree' ? 'folder' : 'file-text-o',
tempFile: true,
opened: true,
}, tree.level !== undefined ? tree.level + 1 : 0);
exists = false;
tree.files.push(foundEntry);
}
return {
entry: foundEntry,
exists,
};
},
};
export default RepoHelper;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment