2018-03-20 10:12:48 -04:00
|
|
|
import Vue from 'vue';
|
2020-02-12 10:09:37 -05:00
|
|
|
import IdeRouter from '~/ide/ide_router_extension';
|
2019-04-24 13:30:46 -04:00
|
|
|
import { joinPaths } from '~/lib/utils/url_utility';
|
2020-11-18 13:09:08 -05: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 13:09:20 -05:00
|
|
|
import { performanceMarkAndMeasure } from '~/performance/utils';
|
2020-06-04 20:08:38 -04:00
|
|
|
import { syncRouterAndStore } from './sync_router_and_store';
|
2018-03-20 10:12:48 -04:00
|
|
|
|
2020-02-12 10:09:37 -05:00
|
|
|
Vue.use(IdeRouter);
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Routes below /-/ide/:
|
|
|
|
|
2021-06-14 20:10:11 -04:00
|
|
|
/project/h5bp/html5-boilerplate/blob/main
|
|
|
|
/project/h5bp/html5-boilerplate/blob/main/app/js/test.js
|
2018-03-20 10:12:48 -04: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-14 20:10:11 -04:00
|
|
|
export const createRouter = (store, defaultBranch) => {
|
2020-06-04 20:08:38 -04: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-23 19:10:25 -05:00
|
|
|
redirect: (to) => joinPaths(to.path, '/-/'),
|
2020-06-04 20:08:38 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: ':targetmode(edit|tree|blob)',
|
2021-06-14 20:10:11 -04:00
|
|
|
redirect: (to) => joinPaths(to.path, `/${defaultBranch}/-/`),
|
2020-06-04 20:08:38 -04:00
|
|
|
},
|
|
|
|
{
|
|
|
|
path: 'merge_requests/:mrid',
|
|
|
|
component: EmptyRouterComponent,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
path: '',
|
2021-06-14 20:10:11 -04:00
|
|
|
redirect: (to) => joinPaths(to.path, `/edit/${defaultBranch}/-/`),
|
2020-06-04 20:08:38 -04:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
|
2020-06-04 20:08:38 -04:00
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
if (to.params.namespace && to.params.project) {
|
2021-12-15 16:11:32 -05: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 05:36:41 -04:00
|
|
|
|
2021-12-15 16:11:32 -05: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-04 20:08:38 -04:00
|
|
|
});
|
2021-12-15 16:11:32 -05:00
|
|
|
}
|
2020-06-04 20:08:38 -04:00
|
|
|
}
|
2018-03-20 10:12:48 -04:00
|
|
|
|
2020-06-04 20:08:38 -04:00
|
|
|
next();
|
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
|
2020-06-04 20:08:38 -04:00
|
|
|
syncRouterAndStore(router, store);
|
|
|
|
|
|
|
|
return router;
|
|
|
|
};
|