2018-03-20 10:12:48 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import VueRouter from 'vue-router';
|
2018-07-19 09:20:26 -04:00
|
|
|
import { join as joinPath } from 'path';
|
2018-03-20 10:12:48 -04:00
|
|
|
import flash from '~/flash';
|
|
|
|
import store from './stores';
|
|
|
|
|
|
|
|
Vue.use(VueRouter);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Routes below /-/ide/:
|
|
|
|
|
|
|
|
/project/h5bp/html5-boilerplate/blob/master
|
|
|
|
/project/h5bp/html5-boilerplate/blob/master/app/js/test.js
|
|
|
|
|
|
|
|
/project/h5bp/html5-boilerplate/mr/123
|
|
|
|
/project/h5bp/html5-boilerplate/mr/123/app/js/test.js
|
|
|
|
|
|
|
|
/workspace/123
|
|
|
|
/workspace/project/h5bp/html5-boilerplate/blob/my-special-branch
|
|
|
|
/workspace/project/h5bp/html5-boilerplate/mr/123
|
|
|
|
|
|
|
|
/ = /workspace
|
|
|
|
|
|
|
|
/settings
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Unfortunately Vue Router doesn't work without at least a fake component
|
|
|
|
// If you do only data handling
|
|
|
|
const EmptyRouterComponent = {
|
|
|
|
render(createElement) {
|
|
|
|
return createElement('div');
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const router = new VueRouter({
|
|
|
|
mode: 'history',
|
|
|
|
base: `${gon.relative_url_root}/-/ide/`,
|
|
|
|
routes: [
|
|
|
|
{
|
2018-07-19 09:20:26 -04:00
|
|
|
path: '/project/:namespace+/:project',
|
2018-03-20 10:12:48 -04:00
|
|
|
component: EmptyRouterComponent,
|
|
|
|
children: [
|
|
|
|
{
|
2018-07-19 09:20:26 -04:00
|
|
|
path: ':targetmode(edit|tree|blob)/:branchid+/-/*',
|
2018-03-20 10:12:48 -04:00
|
|
|
component: EmptyRouterComponent,
|
|
|
|
},
|
2018-07-19 09:20:26 -04:00
|
|
|
{
|
|
|
|
path: ':targetmode(edit|tree|blob)/:branchid+/',
|
|
|
|
redirect: to => joinPath(to.path, '/-/'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ':targetmode(edit|tree|blob)',
|
|
|
|
redirect: to => joinPath(to.path, '/master/-/'),
|
|
|
|
},
|
2018-03-20 10:12:48 -04:00
|
|
|
{
|
2018-03-23 06:45:43 -04:00
|
|
|
path: 'merge_requests/:mrid',
|
2018-03-20 10:12:48 -04:00
|
|
|
component: EmptyRouterComponent,
|
|
|
|
},
|
2018-07-19 09:20:26 -04:00
|
|
|
{
|
|
|
|
path: '',
|
|
|
|
redirect: to => joinPath(to.path, '/edit/master/-/'),
|
|
|
|
},
|
2018-03-20 10:12:48 -04:00
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
if (to.params.namespace && to.params.project) {
|
2018-03-21 08:06:44 -04:00
|
|
|
store
|
|
|
|
.dispatch('getProjectData', {
|
|
|
|
namespace: to.params.namespace,
|
|
|
|
projectId: to.params.project,
|
|
|
|
})
|
|
|
|
.then(() => {
|
2018-08-13 04:12:21 -04:00
|
|
|
const basePath = to.params[0] || '';
|
|
|
|
const projectId = `${to.params.namespace}/${to.params.project}`;
|
2018-07-19 09:20:26 -04:00
|
|
|
const branchId = to.params.branchid;
|
2018-08-13 04:12:21 -04:00
|
|
|
const mergeRequestId = to.params.mrid;
|
2018-05-23 05:36:41 -04:00
|
|
|
|
|
|
|
if (branchId) {
|
2018-08-13 04:12:21 -04:00
|
|
|
store.dispatch('openBranch', {
|
|
|
|
projectId,
|
2018-05-23 05:36:41 -04:00
|
|
|
branchId,
|
2018-08-13 04:12:21 -04:00
|
|
|
basePath,
|
|
|
|
});
|
|
|
|
} else if (mergeRequestId) {
|
|
|
|
store.dispatch('openMergeRequest', {
|
|
|
|
projectId,
|
|
|
|
mergeRequestId,
|
|
|
|
targetProjectId: to.query.target_project,
|
2018-03-21 08:06:44 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
flash(
|
|
|
|
'Error while loading the project data. Please try again.',
|
|
|
|
'alert',
|
|
|
|
document,
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
throw e;
|
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
|
|
|
|
export default router;
|