summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pipeline.js.es6
blob: 68a34dda2af0f1e70585d229180c7c95d6f01d37 (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
((global) => {

  class Pipelines {
    constructor() {
      $(document).off('click', '.toggle-pipeline-btn').on('click', '.toggle-pipeline-btn', this.toggleGraph);
      $(document).off('ready.addMarginToBuildColumns').on('ready.addMarginToBuildColumns', this.addMarginToBuildColumns);
    }

    toggleGraph() {
      const $pipelineBtn = $(this).closest('.toggle-pipeline-btn');
      const $pipelineGraph = $(this).closest('.row-content-block').next('.pipeline-graph');
      const $btnText = $(this).find('.toggle-btn-text');

      $($pipelineBtn).add($pipelineGraph).toggleClass('graph-collapsed');

      const graphCollapsed = $pipelineGraph.hasClass('graph-collapsed');

      graphCollapsed ? $btnText.text('Expand') : $btnText.text('Hide')
    }

    addMarginToBuildColumns() {
      const $secondChildBuildNode = $('.build:nth-child(2)');
      if ($secondChildBuildNode.length) {
        const $firstChildBuildNode = $secondChildBuildNode.prev('.build');
        const $multiBuildColumn = $secondChildBuildNode.closest('.stage-column');
        const $previousColumn = $multiBuildColumn.prev('.stage-column');
        $multiBuildColumn.addClass('left-margin');
        $firstChildBuildNode.addClass('left-connector');
        $previousColumn.each(function() {
          $this = $(this);
          if ($('.build', $this).length === 1) $this.addClass('no-margin');
        });
      }
      $('.pipeline-graph').removeClass('hidden');
    }
  }

  global.Pipelines = Pipelines;

})(window.gl || (window.gl = {}));