1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
import $ from 'jquery';
import Vue from 'vue';
import { visitUrl, joinPaths } from '~/lib/utils/url_utility';
import ShortcutsNetwork from '~/behaviors/shortcuts/shortcuts_network';
import RefSelector from '~/ref/components/ref_selector.vue';
import Network from '../network';
const initRefSwitcher = () => {
const refSwitcherEl = document.getElementById('js-graph-ref-switcher');
const NETWORK_PATH_REGEX = /^(.*?)\/-\/network/g;
if (!refSwitcherEl) return false;
const { projectId, ref, networkPath } = refSwitcherEl.dataset;
const networkRootPath = networkPath.match(NETWORK_PATH_REGEX)?.[0]; // gets the network path without the ref
return new Vue({
el: refSwitcherEl,
render(createElement) {
return createElement(RefSelector, {
props: {
projectId,
value: ref,
},
on: {
input(selectedRef) {
visitUrl(joinPaths(networkRootPath, selectedRef));
},
},
});
},
});
};
initRefSwitcher();
(() => {
if (!$('.network-graph').length) return;
const networkGraph = new Network({
url: $('.network-graph').attr('data-url'),
commit_url: $('.network-graph').attr('data-commit-url'),
ref: $('.network-graph').attr('data-ref'),
commit_id: $('.network-graph').attr('data-commit-id'),
});
// eslint-disable-next-line no-new
new ShortcutsNetwork(networkGraph.branch_graph);
})();
|