From 958c0a2c45d7b7e7c2fbb49feb59ff5c00fd2005 Mon Sep 17 00:00:00 2001 From: Jacob Schatz Date: Wed, 14 Feb 2018 15:39:59 -0500 Subject: Refactor pipelines show for webpack bundle tag removal --- .../pages/projects/pipelines/show/index.js | 71 +++++++++++++++++++++- app/views/projects/pipelines/show.html.haml | 1 - 2 files changed, 70 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/pages/projects/pipelines/show/index.js b/app/assets/javascripts/pages/projects/pipelines/show/index.js index fbe9824c34b..c02c8631bb2 100644 --- a/app/assets/javascripts/pages/projects/pipelines/show/index.js +++ b/app/assets/javascripts/pages/projects/pipelines/show/index.js @@ -1,3 +1,72 @@ + +import Vue from 'vue'; +import Flash from '../../../../flash'; +import PipelinesMediator from '../../../../pipelines/pipeline_details_mediatior'; +import pipelineGraph from '../../../../pipelines/components/graph/graph_component.vue'; +import pipelineHeader from '../../../../pipelines/components/header_component.vue'; +import eventHub from '../../../../pipelines/event_hub'; import initPipelines from '../init_pipelines'; -document.addEventListener('DOMContentLoaded', initPipelines); +document.addEventListener('DOMContentLoaded', () => { + const dataset = document.querySelector('.js-pipeline-details-vue').dataset; + + const mediator = new PipelinesMediator({ endpoint: dataset.endpoint }); + + mediator.fetchPipeline(); + initPipelines(); + + // eslint-disable-next-line + new Vue({ + el: '#js-pipeline-graph-vue', + components: { + pipelineGraph, + }, + data() { + return { + mediator, + }; + }, + render(createElement) { + return createElement('pipeline-graph', { + props: { + isLoading: this.mediator.state.isLoading, + pipeline: this.mediator.store.state.pipeline, + }, + }); + }, + }); + + // eslint-disable-next-line + new Vue({ + el: '#js-pipeline-header-vue', + components: { + pipelineHeader, + }, + data() { + return { + mediator, + }; + }, + created() { + eventHub.$on('headerPostAction', this.postAction); + }, + beforeDestroy() { + eventHub.$off('headerPostAction', this.postAction); + }, + methods: { + postAction(action) { + this.mediator.service.postAction(action.path) + .then(() => this.mediator.refreshPipeline()) + .catch(() => new Flash('An error occurred while making the request.')); + }, + }, + render(createElement) { + return createElement('pipeline-header', { + props: { + isLoading: this.mediator.state.isLoading, + pipeline: this.mediator.store.state.pipeline, + }, + }); + }, + }); +}); diff --git a/app/views/projects/pipelines/show.html.haml b/app/views/projects/pipelines/show.html.haml index 2174154b207..ffb0ae95f9b 100644 --- a/app/views/projects/pipelines/show.html.haml +++ b/app/views/projects/pipelines/show.html.haml @@ -13,4 +13,3 @@ - content_for :page_specific_javascripts do = webpack_bundle_tag('common_vue') - = webpack_bundle_tag('pipelines_details') -- cgit v1.2.1