pipelines.js.es6 1.41 KB
Newer Older
Luke Bennett's avatar
Luke Bennett committed
1 2 3 4 5
((global) => {

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

Luke Bennett's avatar
Luke Bennett committed
9 10 11 12
    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');
13
      const graphCollapsed = $pipelineGraph.hasClass('graph-collapsed');
14

Luke Bennett's avatar
Luke Bennett committed
15
      $($pipelineBtn).add($pipelineGraph).toggleClass('graph-collapsed');
16

17

18
      graphCollapsed ? $btnText.text('Hide') : $btnText.text('Expand')
Luke Bennett's avatar
Luke Bennett committed
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
    }

    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');
        });
      }
34
      $('.pipeline-graph').removeClass('hidden');
35
    }
36
  }
37

Luke Bennett's avatar
Luke Bennett committed
38 39 40
  global.Pipelines = Pipelines;

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