2018-03-20 14:12:48 +00:00
|
|
|
import Vue from 'vue';
|
2020-02-12 15:09:37 +00:00
|
|
|
import IdeRouter from '~/ide/ide_router_extension';
|
2019-04-24 17:30:46 +00:00
|
|
|
import { joinPaths } from '~/lib/utils/url_utility';
|
2020-11-18 18:09:08 +00:00
|
|
|
import {
|
|
|
|
WEBIDE_MARK_FETCH_PROJECT_DATA_START,
|
|
|
|
WEBIDE_MARK_FETCH_PROJECT_DATA_FINISH,
|
|
|
|
WEBIDE_MEASURE_FETCH_PROJECT_DATA,
|
|
|
|
} from '~/performance/constants';
|
2021-02-14 18:09:20 +00:00
|
|
|
import { performanceMarkAndMeasure } from '~/performance/utils';
|
2020-06-05 00:08:38 +00:00
|
|
|
import { syncRouterAndStore } from './sync_router_and_store';
|
2018-03-20 14:12:48 +00:00
|
|
|
|
2020-02-12 15:09:37 +00:00
|
|
|
Vue.use(IdeRouter);
|
2018-03-20 14:12:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Routes below /-/ide/:
|
|
|
|
|
2021-06-15 00:10:11 +00:00
|
|
|
/project/h5bp/html5-boilerplate/blob/main
|
|
|
|
/project/h5bp/html5-boilerplate/blob/main/app/js/test.js
|
2018-03-20 14:12:48 +00:00
|
|
|
|
|
|
|
/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');
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2021-06-15 00:10:11 +00:00
|
|
|
export const createRouter = (store, defaultBranch) => {
|
2020-06-05 00:08:38 +00:00
|
|
|
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+/',
|
2020-12-24 00:10:25 +00:00
|
|
|
redirect: (to) => joinPaths(to.path, '/-/'),
|
2020-06-05 00:08:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ':targetmode(edit|tree|blob)',
|
2021-06-15 00:10:11 +00:00
|
|
|
redirect: (to) => joinPaths(to.path, `/${defaultBranch}/-/`),
|
2020-06-05 00:08:38 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'merge_requests/:mrid',
|
|
|
|
component: EmptyRouterComponent,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '',
|
2021-06-15 00:10:11 +00:00
|
|
|
redirect: (to) => joinPaths(to.path, `/edit/${defaultBranch}/-/`),
|
2020-06-05 00:08:38 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2018-03-20 14:12:48 +00:00
|
|
|
|
2020-06-05 00:08:38 +00:00
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
if (to.params.namespace && to.params.project) {
|
2021-12-15 21:11:32 +00:00
|
|
|
const basePath = to.params.pathMatch || '';
|
|
|
|
const projectId = `${to.params.namespace}/${to.params.project}`;
|
|
|
|
const branchId = to.params.branchid;
|
|
|
|
const mergeRequestId = to.params.mrid;
|
2018-05-23 09:36:41 +00:00
|
|
|
|
2021-12-15 21:11:32 +00:00
|
|
|
performanceMarkAndMeasure({ mark: WEBIDE_MARK_FETCH_PROJECT_DATA_START });
|
|
|
|
if (branchId) {
|
|
|
|
performanceMarkAndMeasure({
|
|
|
|
mark: WEBIDE_MARK_FETCH_PROJECT_DATA_FINISH,
|
|
|
|
measures: [
|
|
|
|
{
|
|
|
|
name: WEBIDE_MEASURE_FETCH_PROJECT_DATA,
|
|
|
|
start: WEBIDE_MARK_FETCH_PROJECT_DATA_START,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
store.dispatch('openBranch', {
|
|
|
|
projectId,
|
|
|
|
branchId,
|
|
|
|
basePath,
|
|
|
|
});
|
|
|
|
} else if (mergeRequestId) {
|
|
|
|
store.dispatch('openMergeRequest', {
|
|
|
|
projectId,
|
|
|
|
mergeRequestId,
|
|
|
|
targetProjectId: to.query.target_project,
|
2020-06-05 00:08:38 +00:00
|
|
|
});
|
2021-12-15 21:11:32 +00:00
|
|
|
}
|
2020-06-05 00:08:38 +00:00
|
|
|
}
|
2018-03-20 14:12:48 +00:00
|
|
|
|
2020-06-05 00:08:38 +00:00
|
|
|
next();
|
|
|
|
});
|
2018-03-20 14:12:48 +00:00
|
|
|
|
2020-06-05 00:08:38 +00:00
|
|
|
syncRouterAndStore(router, store);
|
|
|
|
|
|
|
|
return router;
|
|
|
|
};
|