2018-11-20 20:47:30 +05:30
|
|
|
import Vue from 'vue';
|
2018-05-09 12:01:36 +05:30
|
|
|
import * as types from './mutation_types';
|
|
|
|
import projectMutations from './mutations/project';
|
|
|
|
import mergeRequestMutation from './mutations/merge_request';
|
|
|
|
import fileMutations from './mutations/file';
|
|
|
|
import treeMutations from './mutations/tree';
|
|
|
|
import branchMutations from './mutations/branch';
|
2018-10-15 14:42:47 +05:30
|
|
|
import { sortTree } from './utils';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
[types.SET_INITIAL_DATA](state, data) {
|
|
|
|
Object.assign(state, data);
|
|
|
|
},
|
|
|
|
[types.TOGGLE_LOADING](state, { entry, forceValue = undefined }) {
|
|
|
|
if (entry.path) {
|
|
|
|
Object.assign(state.entries[entry.path], {
|
|
|
|
loading: forceValue !== undefined ? forceValue : !state.entries[entry.path].loading,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Object.assign(entry, {
|
|
|
|
loading: forceValue !== undefined ? forceValue : !entry.loading,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[types.SET_LEFT_PANEL_COLLAPSED](state, collapsed) {
|
|
|
|
Object.assign(state, {
|
|
|
|
leftPanelCollapsed: collapsed,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[types.SET_RIGHT_PANEL_COLLAPSED](state, collapsed) {
|
|
|
|
Object.assign(state, {
|
|
|
|
rightPanelCollapsed: collapsed,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[types.SET_RESIZING_STATUS](state, resizing) {
|
|
|
|
Object.assign(state, {
|
|
|
|
panelResizing: resizing,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[types.SET_LAST_COMMIT_DATA](state, { entry, lastCommit }) {
|
|
|
|
Object.assign(entry.lastCommit, {
|
|
|
|
id: lastCommit.commit.id,
|
|
|
|
url: lastCommit.commit_path,
|
|
|
|
message: lastCommit.commit.message,
|
|
|
|
author: lastCommit.commit.author_name,
|
|
|
|
updatedAt: lastCommit.commit.authored_date,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[types.SET_LAST_COMMIT_MSG](state, lastCommitMsg) {
|
|
|
|
Object.assign(state, {
|
|
|
|
lastCommitMsg,
|
|
|
|
});
|
|
|
|
},
|
2018-10-15 14:42:47 +05:30
|
|
|
[types.CLEAR_STAGED_CHANGES](state) {
|
|
|
|
Object.assign(state, {
|
|
|
|
stagedFiles: [],
|
|
|
|
});
|
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
[types.SET_ENTRIES](state, entries) {
|
|
|
|
Object.assign(state, {
|
|
|
|
entries,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[types.CREATE_TMP_ENTRY](state, { data, projectId, branchId }) {
|
|
|
|
Object.keys(data.entries).reduce((acc, key) => {
|
|
|
|
const entry = data.entries[key];
|
|
|
|
const foundEntry = state.entries[key];
|
|
|
|
|
|
|
|
if (!foundEntry) {
|
|
|
|
Object.assign(state.entries, {
|
|
|
|
[key]: entry,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const tree = entry.tree.filter(
|
|
|
|
f => foundEntry.tree.find(e => e.path === f.path) === undefined,
|
|
|
|
);
|
|
|
|
Object.assign(foundEntry, {
|
2018-10-15 14:42:47 +05:30
|
|
|
tree: sortTree(foundEntry.tree.concat(tree)),
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return acc.concat(key);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
const foundEntry = state.trees[`${projectId}/${branchId}`].tree.find(
|
|
|
|
e => e.path === data.treeList[0].path,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!foundEntry) {
|
|
|
|
Object.assign(state.trees[`${projectId}/${branchId}`], {
|
2018-10-15 14:42:47 +05:30
|
|
|
tree: sortTree(state.trees[`${projectId}/${branchId}`].tree.concat(data.treeList)),
|
2018-05-09 12:01:36 +05:30
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2018-10-15 14:42:47 +05:30
|
|
|
[types.UPDATE_TEMP_FLAG](state, { path, tempFile }) {
|
|
|
|
Object.assign(state.entries[path], {
|
|
|
|
tempFile,
|
|
|
|
changed: tempFile,
|
|
|
|
});
|
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
[types.UPDATE_VIEWER](state, viewer) {
|
|
|
|
Object.assign(state, {
|
|
|
|
viewer,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[types.UPDATE_DELAY_VIEWER_CHANGE](state, delayViewerUpdated) {
|
|
|
|
Object.assign(state, {
|
|
|
|
delayViewerUpdated,
|
|
|
|
});
|
|
|
|
},
|
2018-10-15 14:42:47 +05:30
|
|
|
[types.UPDATE_ACTIVITY_BAR_VIEW](state, currentActivityView) {
|
|
|
|
Object.assign(state, {
|
|
|
|
currentActivityView,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[types.SET_EMPTY_STATE_SVGS](
|
|
|
|
state,
|
2018-11-18 11:00:15 +05:30
|
|
|
{
|
|
|
|
emptyStateSvgPath,
|
|
|
|
noChangesStateSvgPath,
|
|
|
|
committedStateSvgPath,
|
|
|
|
pipelinesEmptyStateSvgPath,
|
|
|
|
promotionSvgPath,
|
|
|
|
},
|
2018-10-15 14:42:47 +05:30
|
|
|
) {
|
|
|
|
Object.assign(state, {
|
|
|
|
emptyStateSvgPath,
|
|
|
|
noChangesStateSvgPath,
|
|
|
|
committedStateSvgPath,
|
2018-11-08 19:23:39 +05:30
|
|
|
pipelinesEmptyStateSvgPath,
|
2018-11-18 11:00:15 +05:30
|
|
|
promotionSvgPath,
|
2018-10-15 14:42:47 +05:30
|
|
|
});
|
|
|
|
},
|
|
|
|
[types.TOGGLE_FILE_FINDER](state, fileFindVisible) {
|
|
|
|
Object.assign(state, {
|
|
|
|
fileFindVisible,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[types.UPDATE_FILE_AFTER_COMMIT](state, { file, lastCommit }) {
|
|
|
|
const changedFile = state.changedFiles.find(f => f.path === file.path);
|
2018-11-18 11:00:15 +05:30
|
|
|
const { prevPath } = file;
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
Object.assign(state.entries[file.path], {
|
|
|
|
raw: file.content,
|
|
|
|
changed: !!changedFile,
|
|
|
|
staged: false,
|
2018-11-18 11:00:15 +05:30
|
|
|
prevPath: '',
|
|
|
|
moved: false,
|
2018-11-20 20:47:30 +05:30
|
|
|
lastCommitSha: lastCommit.commit.id,
|
2018-10-15 14:42:47 +05:30
|
|
|
});
|
2018-11-18 11:00:15 +05:30
|
|
|
|
|
|
|
if (prevPath) {
|
|
|
|
// Update URLs after file has moved
|
|
|
|
const regex = new RegExp(`${prevPath}$`);
|
|
|
|
|
|
|
|
Object.assign(state.entries[file.path], {
|
|
|
|
rawPath: file.rawPath.replace(regex, file.path),
|
|
|
|
permalink: file.permalink.replace(regex, file.path),
|
|
|
|
commitsPath: file.commitsPath.replace(regex, file.path),
|
|
|
|
blamePath: file.blamePath.replace(regex, file.path),
|
|
|
|
});
|
|
|
|
}
|
2018-10-15 14:42:47 +05:30
|
|
|
},
|
|
|
|
[types.BURST_UNUSED_SEAL](state) {
|
|
|
|
Object.assign(state, {
|
|
|
|
unusedSeal: false,
|
|
|
|
});
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
[types.SET_LINKS](state, links) {
|
|
|
|
Object.assign(state, { links });
|
|
|
|
},
|
|
|
|
[types.CLEAR_PROJECTS](state) {
|
|
|
|
Object.assign(state, { projects: {}, trees: {} });
|
|
|
|
},
|
|
|
|
[types.RESET_OPEN_FILES](state) {
|
|
|
|
Object.assign(state, { openFiles: [] });
|
|
|
|
},
|
|
|
|
[types.SET_ERROR_MESSAGE](state, errorMessage) {
|
|
|
|
Object.assign(state, { errorMessage });
|
|
|
|
},
|
2018-11-18 11:00:15 +05:30
|
|
|
[types.OPEN_NEW_ENTRY_MODAL](state, { type, path }) {
|
|
|
|
Object.assign(state, {
|
|
|
|
entryModal: {
|
|
|
|
type,
|
|
|
|
path,
|
|
|
|
entry: { ...state.entries[path] },
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
[types.DELETE_ENTRY](state, path) {
|
|
|
|
const entry = state.entries[path];
|
2018-11-20 20:47:30 +05:30
|
|
|
const { tempFile = false } = entry;
|
2018-11-18 11:00:15 +05:30
|
|
|
const parent = entry.parentPath
|
|
|
|
? state.entries[entry.parentPath]
|
|
|
|
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
|
|
|
|
|
|
|
|
entry.deleted = true;
|
|
|
|
|
|
|
|
parent.tree = parent.tree.filter(f => f.path !== entry.path);
|
|
|
|
|
|
|
|
if (entry.type === 'blob') {
|
2018-11-20 20:47:30 +05:30
|
|
|
if (tempFile) {
|
|
|
|
state.changedFiles = state.changedFiles.filter(f => f.path !== path);
|
|
|
|
} else {
|
|
|
|
state.changedFiles = state.changedFiles.concat(entry);
|
|
|
|
}
|
2018-11-18 11:00:15 +05:30
|
|
|
}
|
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
[types.RENAME_ENTRY](state, { path, name, entryPath = null, parentPath }) {
|
2018-11-18 11:00:15 +05:30
|
|
|
const oldEntry = state.entries[entryPath || path];
|
2019-07-07 11:18:12 +05:30
|
|
|
const slashedParentPath = parentPath ? `${parentPath}/` : '';
|
|
|
|
const newPath = entryPath
|
|
|
|
? `${slashedParentPath}${oldEntry.name}`
|
|
|
|
: `${slashedParentPath}${name}`;
|
2018-11-18 11:00:15 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
Vue.set(state.entries, newPath, {
|
2018-11-18 11:00:15 +05:30
|
|
|
...oldEntry,
|
|
|
|
id: newPath,
|
2019-07-07 11:18:12 +05:30
|
|
|
key: `${newPath}-${oldEntry.type}-${oldEntry.id}`,
|
2018-11-18 11:00:15 +05:30
|
|
|
path: newPath,
|
|
|
|
name: entryPath ? oldEntry.name : name,
|
|
|
|
tempFile: true,
|
2018-11-20 20:47:30 +05:30
|
|
|
prevPath: oldEntry.tempFile ? null : oldEntry.path,
|
2018-11-18 11:00:15 +05:30
|
|
|
url: oldEntry.url.replace(new RegExp(`${oldEntry.path}/?$`), newPath),
|
|
|
|
tree: [],
|
|
|
|
parentPath,
|
|
|
|
raw: '',
|
2019-07-31 22:56:46 +05:30
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
oldEntry.moved = true;
|
|
|
|
oldEntry.movedPath = newPath;
|
|
|
|
|
|
|
|
const parent = parentPath
|
|
|
|
? state.entries[parentPath]
|
|
|
|
: state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
|
|
|
|
const newEntry = state.entries[newPath];
|
|
|
|
|
|
|
|
parent.tree = sortTree(parent.tree.concat(newEntry));
|
|
|
|
|
|
|
|
if (newEntry.type === 'blob') {
|
|
|
|
state.changedFiles = state.changedFiles.concat(newEntry);
|
|
|
|
}
|
2018-11-20 20:47:30 +05:30
|
|
|
|
|
|
|
if (state.entries[newPath].opened) {
|
|
|
|
state.openFiles.push(state.entries[newPath]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (oldEntry.tempFile) {
|
|
|
|
const filterMethod = f => f.path !== oldEntry.path;
|
|
|
|
|
|
|
|
state.openFiles = state.openFiles.filter(filterMethod);
|
|
|
|
state.changedFiles = state.changedFiles.filter(filterMethod);
|
|
|
|
parent.tree = parent.tree.filter(filterMethod);
|
|
|
|
|
|
|
|
Vue.delete(state.entries, oldEntry.path);
|
|
|
|
}
|
2018-11-18 11:00:15 +05:30
|
|
|
},
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
...projectMutations,
|
|
|
|
...mergeRequestMutation,
|
|
|
|
...fileMutations,
|
|
|
|
...treeMutations,
|
|
|
|
...branchMutations,
|
|
|
|
};
|