2019-09-30 21:07:59 +05:30
|
|
|
import Vue from 'vue';
|
2021-09-30 23:02:18 +05:30
|
|
|
import createFlash from '~/flash';
|
2019-09-30 21:07:59 +05:30
|
|
|
import axios from '../lib/utils/axios_utils';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { __ } from '../locale';
|
2019-09-30 21:07:59 +05:30
|
|
|
import DivergenceGraph from './components/divergence_graph.vue';
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
export function createGraphVueApp(el, data, maxCommits, defaultBranch) {
|
2019-09-30 21:07:59 +05:30
|
|
|
return new Vue({
|
|
|
|
el,
|
|
|
|
render(h) {
|
|
|
|
return h(DivergenceGraph, {
|
|
|
|
props: {
|
2021-04-29 21:17:54 +05:30
|
|
|
defaultBranch,
|
2019-09-30 21:07:59 +05:30
|
|
|
distance: data.distance ? parseInt(data.distance, 10) : null,
|
|
|
|
aheadCount: parseInt(data.ahead, 10),
|
|
|
|
behindCount: parseInt(data.behind, 10),
|
|
|
|
maxCommits,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
export default (endpoint, defaultBranch) => {
|
2019-09-30 21:07:59 +05:30
|
|
|
const names = [...document.querySelectorAll('.js-branch-item')].map(
|
|
|
|
({ dataset }) => dataset.name,
|
|
|
|
);
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
if (names.length === 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
return axios
|
|
|
|
.get(endpoint, {
|
|
|
|
params: { names },
|
|
|
|
})
|
|
|
|
.then(({ data }) => {
|
|
|
|
const maxCommits = Object.entries(data).reduce((acc, [, val]) => {
|
|
|
|
const max = Math.max(...Object.values(val));
|
|
|
|
return max > acc ? max : acc;
|
|
|
|
}, 100);
|
|
|
|
|
|
|
|
Object.entries(data).forEach(([branchName, val]) => {
|
|
|
|
const el = document.querySelector(
|
|
|
|
`[data-name="${branchName}"] .js-branch-divergence-graph`,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!el) return;
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
createGraphVueApp(el, val, maxCommits, defaultBranch);
|
2019-09-30 21:07:59 +05:30
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() =>
|
2021-09-04 01:27:46 +05:30
|
|
|
createFlash({
|
|
|
|
message: __('Error fetching diverging counts for branches. Please try again.'),
|
|
|
|
}),
|
2019-09-30 21:07:59 +05:30
|
|
|
);
|
|
|
|
};
|