diff options
Diffstat (limited to 'app/assets/javascripts/ide/ide_router.js')
-rw-r--r-- | app/assets/javascripts/ide/ide_router.js | 100 |
1 files changed, 12 insertions, 88 deletions
diff --git a/app/assets/javascripts/ide/ide_router.js b/app/assets/javascripts/ide/ide_router.js index c6d7d218e81..3f6101e58f4 100644 --- a/app/assets/javascripts/ide/ide_router.js +++ b/app/assets/javascripts/ide/ide_router.js @@ -3,7 +3,6 @@ import VueRouter from 'vue-router'; import { join as joinPath } from 'path'; import flash from '~/flash'; import store from './stores'; -import { activityBarViews } from './constants'; Vue.use(VueRouter); @@ -74,98 +73,23 @@ router.beforeEach((to, from, next) => { projectId: to.params.project, }) .then(() => { - const fullProjectId = `${to.params.namespace}/${to.params.project}`; - + const basePath = to.params[0] || ''; + const projectId = `${to.params.namespace}/${to.params.project}`; const branchId = to.params.branchid; + const mergeRequestId = to.params.mrid; if (branchId) { - const basePath = to.params[0] || ''; - - store.dispatch('setCurrentBranchId', branchId); - - store.dispatch('getBranchData', { - projectId: fullProjectId, + store.dispatch('openBranch', { + projectId, branchId, + basePath, + }); + } else if (mergeRequestId) { + store.dispatch('openMergeRequest', { + projectId, + mergeRequestId, + targetProjectId: to.query.target_project, }); - - store - .dispatch('getFiles', { - projectId: fullProjectId, - branchId, - }) - .then(() => { - if (basePath) { - const path = basePath.slice(-1) === '/' ? basePath.slice(0, -1) : basePath; - const treeEntryKey = Object.keys(store.state.entries).find( - key => key === path && !store.state.entries[key].pending, - ); - const treeEntry = store.state.entries[treeEntryKey]; - - if (treeEntry) { - store.dispatch('handleTreeEntryAction', treeEntry); - } - } - }) - .catch(e => { - throw e; - }); - } else if (to.params.mrid) { - store - .dispatch('getMergeRequestData', { - projectId: fullProjectId, - targetProjectId: to.query.target_project, - mergeRequestId: to.params.mrid, - }) - .then(mr => { - store.dispatch('updateActivityBarView', activityBarViews.review); - - store.dispatch('getBranchData', { - projectId: fullProjectId, - branchId: mr.source_branch, - }); - - return store.dispatch('getFiles', { - projectId: fullProjectId, - branchId: mr.source_branch, - }); - }) - .then(() => - store.dispatch('getMergeRequestVersions', { - projectId: fullProjectId, - targetProjectId: to.query.target_project, - mergeRequestId: to.params.mrid, - }), - ) - .then(() => - store.dispatch('getMergeRequestChanges', { - projectId: fullProjectId, - targetProjectId: to.query.target_project, - mergeRequestId: to.params.mrid, - }), - ) - .then(mrChanges => { - mrChanges.changes.forEach((change, ind) => { - const changeTreeEntry = store.state.entries[change.new_path]; - - if (changeTreeEntry) { - store.dispatch('setFileMrChange', { - file: changeTreeEntry, - mrChange: change, - }); - - if (ind < 10) { - store.dispatch('getFileData', { - path: change.new_path, - makeFileActive: ind === 0, - }); - } - } - }); - }) - .catch(e => { - flash('Error while loading the merge request. Please try again.'); - throw e; - }); } }) .catch(e => { |