Commit fe1871b5 authored by Phil Hughes's avatar Phil Hughes

moved to eventHub to manage creating new files

removed an ID from the CSS
parent 5f988a72
<script> <script>
import RepoHelper from '../../helpers/repo_helper';
import RepoStore from '../../stores/repo_store';
import eventHub from '../../event_hub';
import newModal from './modal.vue'; import newModal from './modal.vue';
export default { export default {
...@@ -9,6 +12,7 @@ ...@@ -9,6 +12,7 @@
return { return {
openModal: false, openModal: false,
modalType: '', modalType: '',
currentPath: RepoStore.path,
}; };
}, },
methods: { methods: {
...@@ -19,6 +23,17 @@ ...@@ -19,6 +23,17 @@
toggleModalOpen() { toggleModalOpen() {
this.openModal = !this.openModal; this.openModal = !this.openModal;
}, },
createNewEntryInStore(name, type) {
RepoHelper.createNewEntry(name, type);
this.toggleModalOpen();
},
},
created() {
eventHub.$on('createNewEntry', this.createNewEntryInStore);
},
beforeDestroy() {
eventHub.$off('createNewEntry', this.createNewEntryInStore);
}, },
}; };
</script> </script>
...@@ -64,6 +79,7 @@ ...@@ -64,6 +79,7 @@
<new-modal <new-modal
v-if="openModal" v-if="openModal"
:type="modalType" :type="modalType"
:current-path="currentPath"
@toggle="toggleModalOpen" @toggle="toggleModalOpen"
/> />
</div> </div>
......
<script> <script>
import { __ } from '../../../locale'; import { __ } from '../../../locale';
import popupDialog from '../../../vue_shared/components/popup_dialog.vue'; import popupDialog from '../../../vue_shared/components/popup_dialog.vue';
import RepoStore from '../../stores/repo_store'; import eventHub from '../../event_hub';
import RepoHelper from '../../helpers/repo_helper';
export default { export default {
props: { props: {
currentPath: {
type: String,
required: true,
},
type: { type: {
type: String, type: String,
required: true, required: true,
...@@ -13,7 +16,7 @@ ...@@ -13,7 +16,7 @@
}, },
data() { data() {
return { return {
entryName: RepoStore.path !== '' ? `${RepoStore.path}/` : '', entryName: this.currentPath !== '' ? `${this.currentPath}/` : '',
}; };
}, },
components: { components: {
...@@ -21,44 +24,7 @@ ...@@ -21,44 +24,7 @@
}, },
methods: { methods: {
createEntryInStore() { createEntryInStore() {
const originalPath = RepoStore.path; eventHub.$emit('createNewEntry', this.entryName, this.type);
let entryName = this.entryName;
if (entryName.indexOf(`${RepoStore.path}/`) !== 0) {
RepoStore.path = '';
} else {
entryName = entryName.replace(`${RepoStore.path}/`, '');
}
if (entryName === '') return;
const fileName = this.type === 'tree' ? '.gitkeep' : entryName;
let tree = RepoStore;
if (this.type === 'tree') {
const dirNames = entryName.split('/');
dirNames.forEach((dirName) => {
if (dirName === '') return;
tree = RepoHelper.findOrCreateEntry('tree', tree, dirName).entry;
});
}
if ((this.type === 'tree' && tree.tempFile) || this.type === 'blob') {
const file = RepoHelper.findOrCreateEntry('blob', tree, fileName);
if (!file.exists) {
RepoHelper.setFile(file.entry, file.entry);
RepoStore.editMode = true;
RepoStore.currentBlobView = 'repo-editor';
}
}
this.toggleModalOpen();
RepoStore.path = originalPath;
}, },
toggleModalOpen() { toggleModalOpen() {
this.$emit('toggle'); this.$emit('toggle');
......
...@@ -39,7 +39,8 @@ export default { ...@@ -39,7 +39,8 @@ export default {
this.dialog.status = status; this.dialog.status = status;
// remove tmp files // remove tmp files
Helper.removeAllTmpFiles(); Helper.removeAllTmpFiles('openedFiles');
Helper.removeAllTmpFiles('files');
}, },
toggleBlobView: Store.toggleBlobView, toggleBlobView: Store.toggleBlobView,
......
...@@ -37,7 +37,7 @@ export default RepoFileButtons; ...@@ -37,7 +37,7 @@ export default RepoFileButtons;
<template> <template>
<div <div
v-if="showButtons" v-if="showButtons"
id="repo-file-buttons" class="repo-file-buttons"
> >
<a <a
:href="activeFile.raw_path" :href="activeFile.raw_path"
......
...@@ -242,7 +242,13 @@ const RepoHelper = { ...@@ -242,7 +242,13 @@ const RepoHelper = {
loadingError() { loadingError() {
Flash('Unable to load this content at this time.'); Flash('Unable to load this content at this time.');
}, },
openEditMode() {
Store.editMode = true;
Store.currentBlobView = 'repo-editor';
},
updateStorePath(path) {
Store.path = path;
},
findOrCreateEntry(type, tree, name) { findOrCreateEntry(type, tree, name) {
let exists = true; let exists = true;
let foundEntry = tree.files.find(dir => dir.type === type && dir.name === name); let foundEntry = tree.files.find(dir => dir.type === type && dir.name === name);
...@@ -267,10 +273,44 @@ const RepoHelper = { ...@@ -267,10 +273,44 @@ const RepoHelper = {
exists, exists,
}; };
}, },
removeAllTmpFiles(storeFilesKey) {
Store[storeFilesKey] = Store[storeFilesKey].filter(f => !f.tempFile);
},
createNewEntry(name, type) {
const originalPath = Store.path;
let entryName = name;
if (entryName.indexOf(`${originalPath}/`) !== 0) {
this.updateStorePath('');
} else {
entryName = entryName.replace(`${originalPath}/`, '');
}
if (entryName === '') return;
const fileName = type === 'tree' ? '.gitkeep' : entryName;
let tree = Store;
if (type === 'tree') {
const dirNames = entryName.split('/');
dirNames.forEach((dirName) => {
if (dirName === '') return;
tree = this.findOrCreateEntry('tree', tree, dirName).entry;
});
}
if ((type === 'tree' && tree.tempFile) || type === 'blob') {
const file = this.findOrCreateEntry('blob', tree, fileName);
if (!file.exists) {
this.setFile(file.entry, file.entry);
this.openEditMode();
}
}
removeAllTmpFiles() { this.updateStorePath(originalPath);
Store.openedFiles = Store.openedFiles.filter(f => !f.tempFile);
Store.files = Store.files.filter(f => !f.tempFile);
}, },
}; };
......
...@@ -185,6 +185,4 @@ const RepoStore = { ...@@ -185,6 +185,4 @@ const RepoStore = {
}, },
}; };
window.RepoStore = RepoStore;
export default RepoStore; export default RepoStore;
...@@ -201,7 +201,7 @@ ...@@ -201,7 +201,7 @@
} }
} }
#repo-file-buttons { .repo-file-buttons {
background-color: $white-light; background-color: $white-light;
padding: 5px 10px; padding: 5px 10px;
border-top: 1px solid $white-normal; border-top: 1px solid $white-normal;
......
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