summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pipelines/mixins/graph_pipeline_bundle_mixin.js
blob: 5c34f4e4f7e7a3ed24c3b6e86a38f8f307d4d2ba (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import createFlash from '~/flash';
import { __ } from '~/locale';

export default {
  methods: {
    getExpandedPipelines(pipeline) {
      this.mediator.service
        .getPipeline(this.mediator.getExpandedParameters())
        .then((response) => {
          this.mediator.store.toggleLoading(pipeline);
          this.mediator.store.storePipeline(response.data);
          this.mediator.poll.enable({ data: this.mediator.getExpandedParameters() });
        })
        .catch(() => {
          this.mediator.store.toggleLoading(pipeline);
          createFlash({
            message: __('An error occurred while fetching the pipeline.'),
          });
        });
    },
    /**
     * Called when a linked pipeline is clicked.
     *
     * If the pipeline is collapsed we will start polling it & we will reset the other pipelines.
     * If the pipeline is expanded we will close it.
     *
     * @param {String} method Method to fetch the pipeline
     * @param {String} storeKey Store property that will be updates
     * @param {String} resetStoreKey Store key for the visible pipeline that will need to be reset
     * @param {Object} pipeline The clicked pipeline
     */
    clickPipeline(pipeline, openMethod, closeMethod) {
      if (!pipeline.isExpanded) {
        this.mediator.store[openMethod](pipeline);
        this.mediator.store.toggleLoading(pipeline);
        this.mediator.poll.stop();

        this.getExpandedPipelines(pipeline);
      } else {
        this.mediator.store[closeMethod](pipeline);
        this.mediator.poll.stop();

        this.mediator.poll.enable({ data: this.mediator.getExpandedParameters() });
      }
    },
    resetDownstreamPipelines(parentPipeline, pipeline) {
      this.mediator.store.resetTriggeredPipelines(parentPipeline, pipeline);
    },
    clickUpstreamPipeline(pipeline) {
      this.clickPipeline(pipeline, 'openPipeline', 'closePipeline');
    },
    clickDownstreamPipeline(pipeline) {
      this.clickPipeline(pipeline, 'openPipeline', 'closePipeline');
    },
    requestRefreshPipelineGraph() {
      // When an action is clicked
      // (whether in the dropdown or in the main nodes, we refresh the big graph)
      this.mediator.refreshPipeline().catch(() =>
        createFlash({
          message: __('An error occurred while making the request.'),
        }),
      );
    },
  },
};