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 @@ ...@@ -27,29 +27,23 @@
let tree = RepoStore; let tree = RepoStore;
if (this.type === 'tree') { if (this.type === 'tree') {
tree = RepoHelper.serializeRepoEntity('tree', { const dirNames = this.entryName.split('/');
name: this.entryName,
path: this.entryName,
icon: 'folder',
tempFile: true,
});
RepoStore.files.push(tree);
RepoHelper.setDirectoryOpen(tree, tree.name); dirNames.forEach((dirName) => {
tree = RepoHelper.findOrCreateEntry('tree', tree, dirName).entry;
});
} }
const file = RepoHelper.serializeRepoEntity('blob', { if ((this.type === 'tree' && tree.tempFile) || this.type === 'blob') {
name: fileName, const file = RepoHelper.findOrCreateEntry('blob', tree, fileName);
path: tree.path ? `${tree.path}/${fileName}` : fileName,
icon: 'file-text-o',
tempFile: true,
}, (this.type === 'tree' ? tree.level + 1 : 0));
tree.files.push(file); if (!file.exists) {
RepoHelper.setFile(file.entry, file.entry);
RepoHelper.setFile(file, file); RepoStore.editMode = true;
RepoStore.editMode = true; RepoStore.toggleBlobView();
RepoStore.toggleBlobView(); }
}
this.toggleModalOpen(); this.toggleModalOpen();
}, },
......
...@@ -157,7 +157,7 @@ const RepoHelper = { ...@@ -157,7 +157,7 @@ const RepoHelper = {
}, },
serializeRepoEntity(type, entity, level = 0) { 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 { return {
id, id,
...@@ -171,7 +171,7 @@ const RepoHelper = { ...@@ -171,7 +171,7 @@ const RepoHelper = {
icon: `fa-${icon}`, icon: `fa-${icon}`,
files: [], files: [],
loading: false, loading: false,
opened: false, opened,
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
lastCommit: last_commit ? { lastCommit: last_commit ? {
url: `${Store.projectUrl}/commit/${last_commit.id}`, url: `${Store.projectUrl}/commit/${last_commit.id}`,
...@@ -225,6 +225,29 @@ const RepoHelper = { ...@@ -225,6 +225,29 @@ const RepoHelper = {
loadingError() { loadingError() {
Flash('Unable to load this content at this time.'); 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; 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