summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/stores/actions.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/assets/javascripts/ide/stores/actions.js')
-rw-r--r--app/assets/javascripts/ide/stores/actions.js42
1 files changed, 27 insertions, 15 deletions
diff --git a/app/assets/javascripts/ide/stores/actions.js b/app/assets/javascripts/ide/stores/actions.js
index e32b5ac7bdc..c881f1221e5 100644
--- a/app/assets/javascripts/ide/stores/actions.js
+++ b/app/assets/javascripts/ide/stores/actions.js
@@ -7,7 +7,6 @@ import * as types from './mutation_types';
import { decorateFiles } from '../lib/files';
import { stageKeys } from '../constants';
import service from '../services';
-import router from '../ide_router';
import eventHub from '../eventhub';
export const redirectToUrl = (self, url) => visitUrl(url);
@@ -20,21 +19,25 @@ export const discardAllChanges = ({ state, commit, dispatch }) => {
commit(types.REMOVE_ALL_CHANGES_FILES);
};
-export const closeAllFiles = ({ state, dispatch }) => {
- state.openFiles.forEach(file => dispatch('closeFile', file));
-};
-
export const setResizingStatus = ({ commit }, resizing) => {
commit(types.SET_RESIZING_STATUS, resizing);
};
export const createTempEntry = (
{ state, commit, dispatch, getters },
- { name, type, content = '', base64 = false, binary = false, rawPath = '' },
+ {
+ name,
+ type,
+ content = '',
+ binary = false,
+ rawPath = '',
+ openFile = true,
+ makeFileActive = true,
+ },
) => {
const fullName = name.slice(-1) !== '/' && type === 'tree' ? `${name}/` : name;
- if (state.entries[name] && !state.entries[name].deleted) {
+ if (getters.entryExists(name)) {
flash(
sprintf(__('The name "%{name}" is already taken in this directory.'), {
name: name.split('/').pop(),
@@ -46,7 +49,7 @@ export const createTempEntry = (
true,
);
- return;
+ return undefined;
}
const data = decorateFiles({
@@ -56,7 +59,6 @@ export const createTempEntry = (
type,
tempFile: true,
content,
- base64,
binary,
rawPath,
});
@@ -69,18 +71,31 @@ export const createTempEntry = (
});
if (type === 'blob') {
- commit(types.TOGGLE_FILE_OPEN, file.path);
+ if (openFile) commit(types.TOGGLE_FILE_OPEN, file.path);
commit(types.STAGE_CHANGE, { path: file.path, diffInfo: getters.getDiffInfo(file.path) });
- dispatch('setFileActive', file.path);
+ if (openFile && makeFileActive) dispatch('setFileActive', file.path);
dispatch('triggerFilesChange');
}
if (parentPath && !state.entries[parentPath].opened) {
commit(types.TOGGLE_TREE_OPEN, parentPath);
}
+
+ return file;
};
+export const addTempImage = ({ dispatch, getters }, { name, rawPath = '' }) =>
+ dispatch('createTempEntry', {
+ name: getters.getAvailableFileName(name),
+ type: 'blob',
+ content: rawPath.split('base64,')[1],
+ binary: true,
+ rawPath,
+ openFile: false,
+ makeFileActive: false,
+ });
+
export const scrollToTab = () => {
Vue.nextTick(() => {
const tabs = document.getElementById('tabs');
@@ -239,7 +254,7 @@ export const renameEntry = ({ dispatch, commit, state, getters }, { path, name,
}
if (newEntry.opened) {
- router.push(`/project${newEntry.url}`);
+ dispatch('router/push', `/project${newEntry.url}`, { root: true });
}
}
@@ -297,6 +312,3 @@ export * from './actions/tree';
export * from './actions/file';
export * from './actions/project';
export * from './actions/merge_request';
-
-// prevent babel-plugin-rewire from generating an invalid default during karma tests
-export default () => {};