2018-10-15 14:42:47 +05:30
|
|
|
import $ from 'jquery';
|
2018-05-09 12:01:36 +05:30
|
|
|
import Vue from 'vue';
|
2019-09-04 21:01:54 +05:30
|
|
|
import { __, sprintf } from '~/locale';
|
2018-05-09 12:01:36 +05:30
|
|
|
import { visitUrl } from '~/lib/utils/url_utility';
|
|
|
|
import flash from '~/flash';
|
2019-09-04 21:01:54 +05:30
|
|
|
import _ from 'underscore';
|
2018-05-09 12:01:36 +05:30
|
|
|
import * as types from './mutation_types';
|
2019-07-07 11:18:12 +05:30
|
|
|
import { decorateFiles } from '../lib/files';
|
2018-11-20 20:47:30 +05:30
|
|
|
import { stageKeys } from '../constants';
|
2019-09-04 21:01:54 +05:30
|
|
|
import service from '../services';
|
2019-09-30 21:07:59 +05:30
|
|
|
import router from '../ide_router';
|
2019-12-21 20:55:43 +05:30
|
|
|
import eventHub from '../eventhub';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
export const redirectToUrl = (self, url) => visitUrl(url);
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
export const setInitialData = ({ commit }, data) => commit(types.SET_INITIAL_DATA, data);
|
|
|
|
|
|
|
|
export const discardAllChanges = ({ state, commit, dispatch }) => {
|
|
|
|
state.changedFiles.forEach(file => {
|
|
|
|
commit(types.DISCARD_FILE_CHANGES, file.path);
|
|
|
|
|
|
|
|
if (file.tempFile) {
|
|
|
|
dispatch('closeFile', file.path);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
commit(types.REMOVE_ALL_CHANGES_FILES);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const closeAllFiles = ({ state, dispatch }) => {
|
|
|
|
state.openFiles.forEach(file => dispatch('closeFile', file));
|
|
|
|
};
|
|
|
|
|
|
|
|
export const setPanelCollapsedStatus = ({ commit }, { side, collapsed }) => {
|
|
|
|
if (side === 'left') {
|
|
|
|
commit(types.SET_LEFT_PANEL_COLLAPSED, collapsed);
|
|
|
|
} else {
|
|
|
|
commit(types.SET_RIGHT_PANEL_COLLAPSED, collapsed);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
export const toggleRightPanelCollapsed = ({ dispatch, state }, e = undefined) => {
|
|
|
|
if (e) {
|
|
|
|
$(e.currentTarget)
|
|
|
|
.tooltip('hide')
|
|
|
|
.blur();
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch('setPanelCollapsedStatus', {
|
|
|
|
side: 'right',
|
|
|
|
collapsed: !state.rightPanelCollapsed,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
export const setResizingStatus = ({ commit }, resizing) => {
|
|
|
|
commit(types.SET_RESIZING_STATUS, resizing);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const createTempEntry = (
|
|
|
|
{ state, commit, dispatch },
|
2019-07-31 22:56:46 +05:30
|
|
|
{ name, type, content = '', base64 = false, binary = false, rawPath = '' },
|
2018-05-09 12:01:36 +05:30
|
|
|
) =>
|
|
|
|
new Promise(resolve => {
|
|
|
|
const fullName = name.slice(-1) !== '/' && type === 'tree' ? `${name}/` : name;
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
if (state.entries[name] && !state.entries[name].deleted) {
|
2018-05-09 12:01:36 +05:30
|
|
|
flash(
|
|
|
|
`The name "${name.split('/').pop()}" is already taken in this directory.`,
|
|
|
|
'alert',
|
|
|
|
document,
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
const data = decorateFiles({
|
2018-05-09 12:01:36 +05:30
|
|
|
data: [fullName],
|
|
|
|
projectId: state.currentProjectId,
|
2018-11-18 11:00:15 +05:30
|
|
|
branchId: state.currentBranchId,
|
2018-05-09 12:01:36 +05:30
|
|
|
type,
|
|
|
|
tempFile: true,
|
|
|
|
content,
|
2019-07-31 22:56:46 +05:30
|
|
|
base64,
|
|
|
|
binary,
|
|
|
|
rawPath,
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
const { file, parentPath } = data;
|
|
|
|
|
|
|
|
commit(types.CREATE_TMP_ENTRY, {
|
|
|
|
data,
|
|
|
|
projectId: state.currentProjectId,
|
|
|
|
branchId: state.currentBranchId,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (type === 'blob') {
|
|
|
|
commit(types.TOGGLE_FILE_OPEN, file.path);
|
|
|
|
commit(types.ADD_FILE_TO_CHANGED, file.path);
|
|
|
|
dispatch('setFileActive', file.path);
|
2019-09-04 21:01:54 +05:30
|
|
|
dispatch('triggerFilesChange');
|
2019-07-07 11:18:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
if (parentPath && !state.entries[parentPath].opened) {
|
|
|
|
commit(types.TOGGLE_TREE_OPEN, parentPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
resolve(file);
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
export const scrollToTab = () => {
|
|
|
|
Vue.nextTick(() => {
|
|
|
|
const tabs = document.getElementById('tabs');
|
|
|
|
|
|
|
|
if (tabs) {
|
|
|
|
const tabEl = tabs.querySelector('.active .repo-tab');
|
|
|
|
|
|
|
|
tabEl.focus();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
export const stageAllChanges = ({ state, commit, dispatch }) => {
|
|
|
|
const openFile = state.openFiles[0];
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
commit(types.SET_LAST_COMMIT_MSG, '');
|
|
|
|
|
|
|
|
state.changedFiles.forEach(file => commit(types.STAGE_CHANGE, file.path));
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
dispatch('openPendingTab', {
|
|
|
|
file: state.stagedFiles.find(f => f.path === openFile.path),
|
|
|
|
keyPrefix: stageKeys.staged,
|
|
|
|
});
|
2018-10-15 14:42:47 +05:30
|
|
|
};
|
|
|
|
|
2018-11-20 20:47:30 +05:30
|
|
|
export const unstageAllChanges = ({ state, commit, dispatch }) => {
|
|
|
|
const openFile = state.openFiles[0];
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
state.stagedFiles.forEach(file => commit(types.UNSTAGE_CHANGE, file.path));
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
dispatch('openPendingTab', {
|
|
|
|
file: state.changedFiles.find(f => f.path === openFile.path),
|
|
|
|
keyPrefix: stageKeys.unstaged,
|
|
|
|
});
|
2018-10-15 14:42:47 +05:30
|
|
|
};
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
export const updateViewer = ({ commit }, viewer) => {
|
|
|
|
commit(types.UPDATE_VIEWER, viewer);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const updateDelayViewerUpdated = ({ commit }, delay) => {
|
|
|
|
commit(types.UPDATE_DELAY_VIEWER_CHANGE, delay);
|
|
|
|
};
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
export const updateActivityBarView = ({ commit }, view) => {
|
|
|
|
commit(types.UPDATE_ACTIVITY_BAR_VIEW, view);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const setEmptyStateSvgs = ({ commit }, svgs) => {
|
|
|
|
commit(types.SET_EMPTY_STATE_SVGS, svgs);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const setCurrentBranchId = ({ commit }, currentBranchId) => {
|
|
|
|
commit(types.SET_CURRENT_BRANCH, currentBranchId);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const updateTempFlagForEntry = ({ commit, dispatch, state }, { file, tempFile }) => {
|
|
|
|
commit(types.UPDATE_TEMP_FLAG, { path: file.path, tempFile });
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
const parent = file.parentPath && state.entries[file.parentPath];
|
|
|
|
|
|
|
|
if (parent) {
|
|
|
|
dispatch('updateTempFlagForEntry', { file: parent, tempFile });
|
2018-10-15 14:42:47 +05:30
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const toggleFileFinder = ({ commit }, fileFindVisible) =>
|
|
|
|
commit(types.TOGGLE_FILE_FINDER, fileFindVisible);
|
|
|
|
|
|
|
|
export const burstUnusedSeal = ({ state, commit }) => {
|
|
|
|
if (state.unusedSeal) {
|
|
|
|
commit(types.BURST_UNUSED_SEAL);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
export const setLinks = ({ commit }, links) => commit(types.SET_LINKS, links);
|
|
|
|
|
|
|
|
export const setErrorMessage = ({ commit }, errorMessage) =>
|
|
|
|
commit(types.SET_ERROR_MESSAGE, errorMessage);
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
export const openNewEntryModal = ({ commit }, { type, path = '' }) => {
|
|
|
|
commit(types.OPEN_NEW_ENTRY_MODAL, { type, path });
|
|
|
|
|
|
|
|
// open the modal manually so we don't mess around with dropdown/rows
|
|
|
|
$('#ide-new-entry').modal('show');
|
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteEntry = ({ commit, dispatch, state }, path) => {
|
|
|
|
const entry = state.entries[path];
|
2019-12-21 20:55:43 +05:30
|
|
|
const { prevPath, prevName, prevParentPath } = entry;
|
|
|
|
const isTree = entry.type === 'tree';
|
|
|
|
|
|
|
|
if (prevPath) {
|
|
|
|
dispatch('renameEntry', {
|
|
|
|
path,
|
|
|
|
name: prevName,
|
|
|
|
parentPath: prevParentPath,
|
|
|
|
});
|
|
|
|
dispatch('deleteEntry', prevPath);
|
|
|
|
return;
|
|
|
|
}
|
2018-11-18 11:00:15 +05:30
|
|
|
if (state.unusedSeal) dispatch('burstUnusedSeal');
|
|
|
|
if (entry.opened) dispatch('closeFile', entry);
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
if (isTree) {
|
2018-11-18 11:00:15 +05:30
|
|
|
entry.tree.forEach(f => dispatch('deleteEntry', f.path));
|
|
|
|
}
|
|
|
|
|
|
|
|
commit(types.DELETE_ENTRY, path);
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
// Only stage if we're not a directory or a new file
|
|
|
|
if (!isTree && !entry.tempFile) {
|
|
|
|
dispatch('stageChange', path);
|
|
|
|
}
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
dispatch('triggerFilesChange');
|
2018-11-18 11:00:15 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
export const resetOpenFiles = ({ commit }) => commit(types.RESET_OPEN_FILES);
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
export const renameEntry = ({ dispatch, commit, state }, { path, name, parentPath }) => {
|
|
|
|
const entry = state.entries[path];
|
|
|
|
const newPath = parentPath ? `${parentPath}/${name}` : name;
|
2018-11-20 20:47:30 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
commit(types.RENAME_ENTRY, { path, name, parentPath });
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
if (entry.type === 'tree') {
|
2019-12-21 20:55:43 +05:30
|
|
|
state.entries[newPath].tree.forEach(f => {
|
2019-07-07 11:18:12 +05:30
|
|
|
dispatch('renameEntry', {
|
2019-12-21 20:55:43 +05:30
|
|
|
path: f.path,
|
|
|
|
name: f.name,
|
|
|
|
parentPath: newPath,
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
});
|
2019-09-30 21:07:59 +05:30
|
|
|
} else {
|
|
|
|
const newEntry = state.entries[newPath];
|
2019-12-21 20:55:43 +05:30
|
|
|
const isRevert = newPath === entry.prevPath;
|
|
|
|
const isReset = isRevert && !newEntry.changed && !newEntry.tempFile;
|
|
|
|
const isInChanges = state.changedFiles
|
|
|
|
.concat(state.stagedFiles)
|
|
|
|
.some(({ key }) => key === newEntry.key);
|
|
|
|
|
|
|
|
if (isReset) {
|
|
|
|
commit(types.REMOVE_FILE_FROM_STAGED_AND_CHANGED, newEntry);
|
|
|
|
} else if (!isInChanges) {
|
|
|
|
commit(types.ADD_FILE_TO_CHANGED, newPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!newEntry.tempFile) {
|
|
|
|
eventHub.$emit(`editor.update.model.dispose.${entry.key}`);
|
|
|
|
}
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
if (newEntry.opened) {
|
2019-09-30 21:07:59 +05:30
|
|
|
router.push(`/project${newEntry.url}`);
|
|
|
|
}
|
2018-11-18 11:00:15 +05:30
|
|
|
}
|
2019-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
dispatch('triggerFilesChange');
|
2018-11-18 11:00:15 +05:30
|
|
|
};
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
export const getBranchData = ({ commit, state }, { projectId, branchId, force = false } = {}) =>
|
|
|
|
new Promise((resolve, reject) => {
|
|
|
|
const currentProject = state.projects[projectId];
|
|
|
|
if (!currentProject || !currentProject.branches[branchId] || force) {
|
|
|
|
service
|
|
|
|
.getBranchData(projectId, branchId)
|
|
|
|
.then(({ data }) => {
|
|
|
|
const { id } = data.commit;
|
|
|
|
commit(types.SET_BRANCH, {
|
|
|
|
projectPath: projectId,
|
|
|
|
branchName: branchId,
|
|
|
|
branch: data,
|
|
|
|
});
|
|
|
|
commit(types.SET_BRANCH_WORKING_REFERENCE, { projectId, branchId, reference: id });
|
|
|
|
resolve(data);
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
if (e.response.status === 404) {
|
|
|
|
reject(e);
|
|
|
|
} else {
|
|
|
|
flash(
|
|
|
|
__('Error loading branch data. Please try again.'),
|
|
|
|
'alert',
|
|
|
|
document,
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
|
|
|
|
reject(
|
|
|
|
new Error(
|
|
|
|
sprintf(
|
|
|
|
__('Branch not loaded - %{branchId}'),
|
|
|
|
{
|
|
|
|
branchId: `<strong>${_.escape(projectId)}/${_.escape(branchId)}</strong>`,
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
resolve(currentProject.branches[branchId]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
export * from './actions/tree';
|
|
|
|
export * from './actions/file';
|
|
|
|
export * from './actions/project';
|
|
|
|
export * from './actions/merge_request';
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
// prevent babel-plugin-rewire from generating an invalid default during karma tests
|
|
|
|
export default () => {};
|