2021-04-17 20:07:23 +05:30
|
|
|
import { GlButton } from '@gitlab/ui';
|
2019-09-04 21:01:54 +05:30
|
|
|
import Vue from 'vue';
|
2022-05-07 20:08:51 +05:30
|
|
|
import Vuex from 'vuex';
|
2021-04-29 21:17:54 +05:30
|
|
|
import { parseBoolean } from '~/lib/utils/common_utils';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { escapeFileUrl, visitUrl } from '~/lib/utils/url_utility';
|
2021-04-29 21:17:54 +05:30
|
|
|
import { __ } from '~/locale';
|
2021-03-11 19:13:27 +05:30
|
|
|
import initWebIdeLink from '~/pages/projects/shared/web_ide_link';
|
2021-06-08 01:23:25 +05:30
|
|
|
import PerformancePlugin from '~/performance/vue_performance_plugin';
|
2022-05-07 20:08:51 +05:30
|
|
|
import createStore from '~/code_navigation/store';
|
2023-03-04 22:38:38 +05:30
|
|
|
import RefSelector from '~/ref/components/ref_selector.vue';
|
2019-09-04 21:01:54 +05:30
|
|
|
import App from './components/app.vue';
|
|
|
|
import Breadcrumbs from './components/breadcrumbs.vue';
|
2021-03-11 19:13:27 +05:30
|
|
|
import DirectoryDownloadLinks from './components/directory_download_links.vue';
|
2023-03-17 16:20:25 +05:30
|
|
|
import ForkInfo from './components/fork_info.vue';
|
2019-09-30 21:07:59 +05:30
|
|
|
import LastCommit from './components/last_commit.vue';
|
2022-03-02 08:16:31 +05:30
|
|
|
import BlobControls from './components/blob_controls.vue';
|
2019-09-04 21:01:54 +05:30
|
|
|
import apolloProvider from './graphql';
|
2021-04-29 21:17:54 +05:30
|
|
|
import commitsQuery from './queries/commits.query.graphql';
|
|
|
|
import projectPathQuery from './queries/project_path.query.graphql';
|
|
|
|
import projectShortPathQuery from './queries/project_short_path.query.graphql';
|
|
|
|
import refsQuery from './queries/ref.query.graphql';
|
2021-03-11 19:13:27 +05:30
|
|
|
import createRouter from './router';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { updateFormAction } from './utils/dom';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { setTitle } from './utils/title';
|
2023-03-04 22:38:38 +05:30
|
|
|
import { generateRefDestinationPath } from './utils/ref_switcher_utils';
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2022-05-07 20:08:51 +05:30
|
|
|
Vue.use(Vuex);
|
2021-06-08 01:23:25 +05:30
|
|
|
Vue.use(PerformancePlugin, {
|
|
|
|
components: ['SimpleViewer', 'BlobContent'],
|
|
|
|
});
|
|
|
|
|
2019-09-04 21:01:54 +05:30
|
|
|
export default function setupVueRepositoryList() {
|
|
|
|
const el = document.getElementById('js-tree-list');
|
2019-12-26 22:10:19 +05:30
|
|
|
const { dataset } = el;
|
2020-11-24 15:15:51 +05:30
|
|
|
const { projectPath, projectShortPath, ref, escapedRef, fullName } = dataset;
|
2020-05-05 14:28:15 +05:30
|
|
|
const router = createRouter(projectPath, escapedRef);
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
apolloProvider.clients.defaultClient.cache.writeQuery({
|
|
|
|
query: commitsQuery,
|
|
|
|
data: {
|
|
|
|
commits: [],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
apolloProvider.clients.defaultClient.cache.writeQuery({
|
|
|
|
query: projectPathQuery,
|
2019-09-04 21:01:54 +05:30
|
|
|
data: {
|
|
|
|
projectPath,
|
2021-04-29 21:17:54 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
apolloProvider.clients.defaultClient.cache.writeQuery({
|
|
|
|
query: projectShortPathQuery,
|
|
|
|
data: {
|
2019-09-04 21:01:54 +05:30
|
|
|
projectShortPath,
|
2021-04-29 21:17:54 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
apolloProvider.clients.defaultClient.cache.writeQuery({
|
|
|
|
query: refsQuery,
|
|
|
|
data: {
|
2019-09-04 21:01:54 +05:30
|
|
|
ref,
|
2020-05-05 14:28:15 +05:30
|
|
|
escapedRef,
|
2019-09-04 21:01:54 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-03-17 16:20:25 +05:30
|
|
|
const initForkInfo = () => {
|
|
|
|
const forkEl = document.getElementById('js-fork-info');
|
|
|
|
if (!forkEl) {
|
|
|
|
return null;
|
|
|
|
}
|
2023-04-23 21:23:45 +05:30
|
|
|
const { sourceName, sourcePath, aheadComparePath, behindComparePath } = forkEl.dataset;
|
2023-03-17 16:20:25 +05:30
|
|
|
return new Vue({
|
|
|
|
el: forkEl,
|
|
|
|
apolloProvider,
|
|
|
|
render(h) {
|
|
|
|
return h(ForkInfo, {
|
|
|
|
props: {
|
|
|
|
projectPath,
|
2023-04-23 21:23:45 +05:30
|
|
|
selectedBranch: ref,
|
2023-03-17 16:20:25 +05:30
|
|
|
sourceName,
|
|
|
|
sourcePath,
|
2023-04-23 21:23:45 +05:30
|
|
|
aheadComparePath,
|
|
|
|
behindComparePath,
|
2023-03-17 16:20:25 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
const initLastCommitApp = () =>
|
|
|
|
new Vue({
|
|
|
|
el: document.getElementById('js-last-commit'),
|
|
|
|
router,
|
|
|
|
apolloProvider,
|
|
|
|
render(h) {
|
|
|
|
return h(LastCommit, {
|
|
|
|
props: {
|
|
|
|
currentPath: this.$route.params.path,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
const initBlobControlsApp = () =>
|
|
|
|
new Vue({
|
|
|
|
el: document.getElementById('js-blob-controls'),
|
|
|
|
router,
|
|
|
|
apolloProvider,
|
|
|
|
render(h) {
|
|
|
|
return h(BlobControls, {
|
|
|
|
props: {
|
|
|
|
projectPath,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
const initRefSwitcher = () => {
|
|
|
|
const refSwitcherEl = document.getElementById('js-tree-ref-switcher');
|
|
|
|
|
|
|
|
if (!refSwitcherEl) return false;
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
const { projectId, projectRootPath } = refSwitcherEl.dataset;
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
return new Vue({
|
|
|
|
el: refSwitcherEl,
|
|
|
|
render(createElement) {
|
|
|
|
return createElement(RefSelector, {
|
|
|
|
props: {
|
|
|
|
projectId,
|
2023-04-23 21:23:45 +05:30
|
|
|
value: ref,
|
2023-03-04 22:38:38 +05:30
|
|
|
},
|
|
|
|
on: {
|
|
|
|
input(selectedRef) {
|
2023-04-03 14:13:38 +05:30
|
|
|
visitUrl(generateRefDestinationPath(projectRootPath, ref, selectedRef));
|
2023-03-04 22:38:38 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
initLastCommitApp();
|
2022-08-13 15:12:31 +05:30
|
|
|
initBlobControlsApp();
|
2023-03-17 16:20:25 +05:30
|
|
|
initForkInfo();
|
2023-03-04 22:38:38 +05:30
|
|
|
initRefSwitcher();
|
2022-03-02 08:16:31 +05:30
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
router.afterEach(({ params: { path } }) => {
|
|
|
|
setTitle(path, ref, fullName);
|
2019-09-04 21:01:54 +05:30
|
|
|
});
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
const breadcrumbEl = document.getElementById('js-repo-breadcrumb');
|
|
|
|
|
|
|
|
if (breadcrumbEl) {
|
|
|
|
const {
|
|
|
|
canCollaborate,
|
|
|
|
canEditTree,
|
2021-04-29 21:17:54 +05:30
|
|
|
canPushCode,
|
|
|
|
selectedBranch,
|
2019-09-30 21:07:59 +05:30
|
|
|
newBranchPath,
|
|
|
|
newTagPath,
|
|
|
|
newBlobPath,
|
|
|
|
forkNewBlobPath,
|
|
|
|
forkNewDirectoryPath,
|
|
|
|
forkUploadBlobPath,
|
2020-01-01 13:55:28 +05:30
|
|
|
uploadPath,
|
|
|
|
newDirPath,
|
2019-09-30 21:07:59 +05:30
|
|
|
} = breadcrumbEl.dataset;
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
router.afterEach(({ params: { path } }) => {
|
2020-03-13 15:44:24 +05:30
|
|
|
updateFormAction('.js-create-dir-form', newDirPath, path);
|
2020-01-01 13:55:28 +05:30
|
|
|
});
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
|
|
|
el: breadcrumbEl,
|
|
|
|
router,
|
|
|
|
apolloProvider,
|
|
|
|
render(h) {
|
|
|
|
return h(Breadcrumbs, {
|
|
|
|
props: {
|
2020-03-13 15:44:24 +05:30
|
|
|
currentPath: this.$route.params.path,
|
2019-09-30 21:07:59 +05:30
|
|
|
canCollaborate: parseBoolean(canCollaborate),
|
|
|
|
canEditTree: parseBoolean(canEditTree),
|
2021-04-29 21:17:54 +05:30
|
|
|
canPushCode: parseBoolean(canPushCode),
|
|
|
|
originalBranch: ref,
|
|
|
|
selectedBranch,
|
2019-09-30 21:07:59 +05:30
|
|
|
newBranchPath,
|
|
|
|
newTagPath,
|
|
|
|
newBlobPath,
|
|
|
|
forkNewBlobPath,
|
|
|
|
forkNewDirectoryPath,
|
|
|
|
forkUploadBlobPath,
|
2021-04-29 21:17:54 +05:30
|
|
|
uploadPath,
|
2021-11-18 22:05:49 +05:30
|
|
|
newDirPath,
|
2019-09-30 21:07:59 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
const treeHistoryLinkEl = document.getElementById('js-tree-history-link');
|
|
|
|
const { historyLink } = treeHistoryLinkEl.dataset;
|
2022-07-16 23:28:13 +05:30
|
|
|
let { isProjectOverview } = treeHistoryLinkEl.dataset;
|
|
|
|
|
|
|
|
const isProjectOverviewAfterEach = router.afterEach(() => {
|
|
|
|
isProjectOverview = false;
|
|
|
|
isProjectOverviewAfterEach();
|
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
|
|
|
el: treeHistoryLinkEl,
|
|
|
|
router,
|
|
|
|
render(h) {
|
2022-07-16 23:28:13 +05:30
|
|
|
if (parseBoolean(isProjectOverview) && !this.$route.params.path) return null;
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
return h(
|
|
|
|
GlButton,
|
|
|
|
{
|
|
|
|
attrs: {
|
|
|
|
href: `${historyLink}/${
|
|
|
|
this.$route.params.path ? escapeFileUrl(this.$route.params.path) : ''
|
|
|
|
}`,
|
2021-09-04 01:27:46 +05:30
|
|
|
// Ideally passing this class to `props` should work
|
|
|
|
// But it doesn't work here. :(
|
2022-03-02 08:16:31 +05:30
|
|
|
class: 'btn btn-default btn-md gl-button',
|
2021-04-17 20:07:23 +05:30
|
|
|
},
|
2019-12-26 22:10:19 +05:30
|
|
|
},
|
2021-04-17 20:07:23 +05:30
|
|
|
[__('History')],
|
|
|
|
);
|
2019-12-26 22:10:19 +05:30
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
initWebIdeLink({ el: document.getElementById('js-tree-web-ide-link'), router });
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
const directoryDownloadLinks = document.getElementById('js-directory-downloads');
|
|
|
|
|
|
|
|
if (directoryDownloadLinks) {
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
|
|
|
el: directoryDownloadLinks,
|
|
|
|
router,
|
|
|
|
render(h) {
|
2020-03-13 15:44:24 +05:30
|
|
|
const currentPath = this.$route.params.path || '/';
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
if (currentPath !== '/') {
|
|
|
|
return h(DirectoryDownloadLinks, {
|
|
|
|
props: {
|
|
|
|
currentPath: currentPath.replace(/^\//, ''),
|
|
|
|
links: JSON.parse(directoryDownloadLinks.dataset.links),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
2019-09-04 21:01:54 +05:30
|
|
|
el,
|
2022-05-07 20:08:51 +05:30
|
|
|
store: createStore(),
|
2019-09-04 21:01:54 +05:30
|
|
|
router,
|
|
|
|
apolloProvider,
|
|
|
|
render(h) {
|
|
|
|
return h(App);
|
|
|
|
},
|
|
|
|
});
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2022-01-26 12:08:38 +05:30
|
|
|
return { router, data: dataset, apolloProvider, projectPath };
|
2019-09-04 21:01:54 +05:30
|
|
|
}
|