2018-05-09 12:01:36 +05:30
|
|
|
import Vue from 'vue';
|
2020-03-13 15:44:24 +05:30
|
|
|
import IdeRouter from '~/ide/ide_router_extension';
|
2019-07-31 22:56:46 +05:30
|
|
|
import { joinPaths } from '~/lib/utils/url_utility';
|
2018-05-09 12:01:36 +05:30
|
|
|
import flash from '~/flash';
|
2019-07-31 22:56:46 +05:30
|
|
|
import { __ } from '~/locale';
|
2020-06-23 00:09:42 +05:30
|
|
|
import { syncRouterAndStore } from './sync_router_and_store';
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
Vue.use(IdeRouter);
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
/**
|
|
|
|
* 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');
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
// eslint-disable-next-line import/prefer-default-export
|
|
|
|
export const createRouter = store => {
|
|
|
|
const router = new IdeRouter({
|
|
|
|
mode: 'history',
|
|
|
|
base: joinPaths(gon.relative_url_root || '', '/-/ide/'),
|
|
|
|
routes: [
|
|
|
|
{
|
|
|
|
path: '/project/:namespace+/:project',
|
|
|
|
component: EmptyRouterComponent,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
path: ':targetmode(edit|tree|blob)/:branchid+/-/*',
|
|
|
|
component: EmptyRouterComponent,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ':targetmode(edit|tree|blob)/:branchid+/',
|
|
|
|
redirect: to => joinPaths(to.path, '/-/'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ':targetmode(edit|tree|blob)',
|
|
|
|
redirect: to => joinPaths(to.path, '/master/-/'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'merge_requests/:mrid',
|
|
|
|
component: EmptyRouterComponent,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '',
|
|
|
|
redirect: to => joinPaths(to.path, '/edit/master/-/'),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
if (to.params.namespace && to.params.project) {
|
|
|
|
store
|
|
|
|
.dispatch('getProjectData', {
|
|
|
|
namespace: to.params.namespace,
|
|
|
|
projectId: to.params.project,
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
const basePath = to.params.pathMatch || '';
|
|
|
|
const projectId = `${to.params.namespace}/${to.params.project}`;
|
|
|
|
const branchId = to.params.branchid;
|
|
|
|
const mergeRequestId = to.params.mrid;
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
if (branchId) {
|
|
|
|
store.dispatch('openBranch', {
|
|
|
|
projectId,
|
|
|
|
branchId,
|
|
|
|
basePath,
|
|
|
|
});
|
|
|
|
} else if (mergeRequestId) {
|
|
|
|
store.dispatch('openMergeRequest', {
|
|
|
|
projectId,
|
|
|
|
mergeRequestId,
|
|
|
|
targetProjectId: to.query.target_project,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(e => {
|
|
|
|
flash(
|
|
|
|
__('Error while loading the project data. Please try again.'),
|
|
|
|
'alert',
|
|
|
|
document,
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
}
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
next();
|
|
|
|
});
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
syncRouterAndStore(router, store);
|
|
|
|
|
|
|
|
return router;
|
|
|
|
};
|