2017-05-26 10:56:54 +00:00
|
|
|
import Vue from 'vue';
|
2018-02-16 12:07:04 +00:00
|
|
|
import Flash from '~/flash';
|
|
|
|
import Translate from '~/vue_shared/translate';
|
|
|
|
import { __ } from '~/locale';
|
2020-01-08 12:07:59 +00:00
|
|
|
import { setUrlFragment, redirectTo } from '~/lib/utils/url_utility';
|
2019-10-10 09:06:08 +00:00
|
|
|
import pipelineGraph from './components/graph/graph_component.vue';
|
2020-05-21 18:08:27 +00:00
|
|
|
import Dag from './components/dag/dag.vue';
|
2019-10-10 09:06:08 +00:00
|
|
|
import GraphBundleMixin from './mixins/graph_pipeline_bundle_mixin';
|
2018-02-16 12:07:04 +00:00
|
|
|
import PipelinesMediator from './pipeline_details_mediator';
|
2017-06-02 13:24:42 +00:00
|
|
|
import pipelineHeader from './components/header_component.vue';
|
|
|
|
import eventHub from './event_hub';
|
2019-11-05 15:06:17 +00:00
|
|
|
import TestReports from './components/test_reports/test_reports.vue';
|
|
|
|
import testReportsStore from './stores/test_reports';
|
2020-02-10 09:08:56 +00:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2017-05-26 10:56:54 +00:00
|
|
|
|
2018-02-16 12:07:04 +00:00
|
|
|
Vue.use(Translate);
|
|
|
|
|
2020-05-19 18:08:11 +00:00
|
|
|
const createPipelinesDetailApp = mediator => {
|
2019-11-05 15:06:17 +00:00
|
|
|
// eslint-disable-next-line no-new
|
2018-02-27 22:28:17 +00:00
|
|
|
new Vue({
|
|
|
|
el: '#js-pipeline-graph-vue',
|
|
|
|
components: {
|
|
|
|
pipelineGraph,
|
|
|
|
},
|
2019-10-10 09:06:08 +00:00
|
|
|
mixins: [GraphBundleMixin],
|
2018-02-27 22:28:17 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
mediator,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
return createElement('pipeline-graph', {
|
|
|
|
props: {
|
|
|
|
isLoading: this.mediator.state.isLoading,
|
|
|
|
pipeline: this.mediator.store.state.pipeline,
|
2019-04-25 12:37:15 +00:00
|
|
|
mediator: this.mediator,
|
2018-05-15 15:55:07 +00:00
|
|
|
},
|
|
|
|
on: {
|
|
|
|
refreshPipelineGraph: this.requestRefreshPipelineGraph,
|
2020-04-08 09:09:43 +00:00
|
|
|
onResetTriggered: (parentPipeline, pipeline) =>
|
|
|
|
this.resetTriggeredPipelines(parentPipeline, pipeline),
|
|
|
|
onClickTriggeredBy: pipeline => this.clickTriggeredByPipeline(pipeline),
|
|
|
|
onClickTriggered: pipeline => this.clickTriggeredPipeline(pipeline),
|
2018-02-27 22:28:17 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2020-05-19 18:08:11 +00:00
|
|
|
};
|
2017-05-26 10:56:54 +00:00
|
|
|
|
2020-05-19 18:08:11 +00:00
|
|
|
const createPipelineHeaderApp = mediator => {
|
2019-11-05 15:06:17 +00:00
|
|
|
// eslint-disable-next-line no-new
|
2018-02-27 22:28:17 +00:00
|
|
|
new Vue({
|
|
|
|
el: '#js-pipeline-header-vue',
|
|
|
|
components: {
|
|
|
|
pipelineHeader,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
mediator,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
eventHub.$on('headerPostAction', this.postAction);
|
2020-01-08 12:07:59 +00:00
|
|
|
eventHub.$on('headerDeleteAction', this.deleteAction);
|
2018-02-27 22:28:17 +00:00
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
eventHub.$off('headerPostAction', this.postAction);
|
2020-01-08 12:07:59 +00:00
|
|
|
eventHub.$off('headerDeleteAction', this.deleteAction);
|
2018-02-27 22:28:17 +00:00
|
|
|
},
|
|
|
|
methods: {
|
2020-01-29 21:09:22 +00:00
|
|
|
postAction(path) {
|
2018-04-20 14:43:58 +00:00
|
|
|
this.mediator.service
|
2020-01-29 21:09:22 +00:00
|
|
|
.postAction(path)
|
2018-02-27 22:28:17 +00:00
|
|
|
.then(() => this.mediator.refreshPipeline())
|
|
|
|
.catch(() => Flash(__('An error occurred while making the request.')));
|
2017-06-02 13:24:42 +00:00
|
|
|
},
|
2020-01-29 21:09:22 +00:00
|
|
|
deleteAction(path) {
|
2020-01-08 12:07:59 +00:00
|
|
|
this.mediator.stopPipelinePoll();
|
|
|
|
this.mediator.service
|
2020-01-29 21:09:22 +00:00
|
|
|
.deleteAction(path)
|
2020-01-08 12:07:59 +00:00
|
|
|
.then(({ request }) => redirectTo(setUrlFragment(request.responseURL, 'delete_success')))
|
|
|
|
.catch(() => Flash(__('An error occurred while deleting the pipeline.')));
|
|
|
|
},
|
2018-02-27 22:28:17 +00:00
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
return createElement('pipeline-header', {
|
|
|
|
props: {
|
|
|
|
isLoading: this.mediator.state.isLoading,
|
|
|
|
pipeline: this.mediator.store.state.pipeline,
|
2017-06-02 13:24:42 +00:00
|
|
|
},
|
2018-02-27 22:28:17 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2020-05-19 18:08:11 +00:00
|
|
|
};
|
2019-11-05 15:06:17 +00:00
|
|
|
|
2020-05-19 18:08:11 +00:00
|
|
|
const createPipelinesTabs = dataset => {
|
2020-02-24 18:09:05 +00:00
|
|
|
const tabsElement = document.querySelector('.pipelines-tabs');
|
2019-11-05 15:06:17 +00:00
|
|
|
const testReportsEnabled =
|
|
|
|
window.gon && window.gon.features && window.gon.features.junitPipelineView;
|
|
|
|
|
2020-02-24 18:09:05 +00:00
|
|
|
if (tabsElement && testReportsEnabled) {
|
2020-02-13 09:08:52 +00:00
|
|
|
const fetchReportsAction = 'fetchReports';
|
2019-11-05 15:06:17 +00:00
|
|
|
testReportsStore.dispatch('setEndpoint', dataset.testReportEndpoint);
|
2020-02-13 09:08:52 +00:00
|
|
|
|
|
|
|
const isTestTabActive = Boolean(
|
|
|
|
document.querySelector('.pipelines-tabs > li > a.test-tab.active'),
|
|
|
|
);
|
|
|
|
|
|
|
|
if (isTestTabActive) {
|
|
|
|
testReportsStore.dispatch(fetchReportsAction);
|
|
|
|
} else {
|
|
|
|
const tabClickHandler = e => {
|
|
|
|
if (e.target.className === 'test-tab') {
|
|
|
|
testReportsStore.dispatch(fetchReportsAction);
|
2020-02-24 18:09:05 +00:00
|
|
|
tabsElement.removeEventListener('click', tabClickHandler);
|
2020-02-13 09:08:52 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-24 18:09:05 +00:00
|
|
|
tabsElement.addEventListener('click', tabClickHandler);
|
2020-02-13 09:08:52 +00:00
|
|
|
}
|
2020-05-19 18:08:11 +00:00
|
|
|
}
|
|
|
|
};
|
2019-11-05 15:06:17 +00:00
|
|
|
|
2020-05-19 18:08:11 +00:00
|
|
|
const createTestDetails = detailsEndpoint => {
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
|
|
|
el: '#js-pipeline-tests-detail',
|
|
|
|
components: {
|
|
|
|
TestReports,
|
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
return createElement('test-reports');
|
|
|
|
},
|
|
|
|
});
|
2020-02-10 09:08:56 +00:00
|
|
|
|
2020-05-19 18:08:11 +00:00
|
|
|
axios
|
|
|
|
.get(detailsEndpoint)
|
|
|
|
.then(({ data }) => {
|
|
|
|
if (!data.total_count) {
|
|
|
|
return;
|
|
|
|
}
|
2020-02-27 18:09:21 +00:00
|
|
|
|
2020-05-19 18:08:11 +00:00
|
|
|
document.querySelector('.js-test-report-badge-counter').innerHTML = data.total_count;
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
|
|
|
};
|
|
|
|
|
2020-05-21 18:08:27 +00:00
|
|
|
const createDagApp = () => {
|
|
|
|
const el = document.querySelector('#js-pipeline-dag-vue');
|
|
|
|
const graphUrl = el.dataset?.pipelineDataPath;
|
|
|
|
// eslint-disable-next-line no-new
|
|
|
|
new Vue({
|
|
|
|
el,
|
|
|
|
components: {
|
|
|
|
Dag,
|
|
|
|
},
|
|
|
|
render(createElement) {
|
|
|
|
return createElement('dag', {
|
|
|
|
props: {
|
|
|
|
graphUrl,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2020-05-19 18:08:11 +00:00
|
|
|
export default () => {
|
|
|
|
const { dataset } = document.querySelector('.js-pipeline-details-vue');
|
|
|
|
const mediator = new PipelinesMediator({ endpoint: dataset.endpoint });
|
|
|
|
mediator.fetchPipeline();
|
|
|
|
|
|
|
|
createPipelinesDetailApp(mediator);
|
|
|
|
createPipelineHeaderApp(mediator);
|
|
|
|
createPipelinesTabs(dataset);
|
|
|
|
createTestDetails(dataset.testReportsCountEndpoint);
|
2020-05-21 18:08:27 +00:00
|
|
|
createDagApp();
|
2018-02-27 22:17:19 +00:00
|
|
|
};
|