summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pipelines.js
blob: 4252b6158877ec6d2b67503a8ebd2c24ab595a21 (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
/* eslint-disable no-new, guard-for-in, no-restricted-syntax, no-continue, no-param-reassign, max-len */

require('./lib/utils/bootstrap_linked_tabs');

((global) => {
  class Pipelines {
    constructor(options = {}) {
      if (options.initTabs && options.tabsOptions) {
        new global.LinkedTabs(options.tabsOptions);
      }

      if (options.pipelineStatusUrl) {
        gl.utils.setCiStatusFavicon(options.pipelineStatusUrl);
      }

      this.addMarginToBuildColumns();
    }

    addMarginToBuildColumns() {
      this.pipelineGraph = document.querySelector('.js-pipeline-graph');

      const secondChildBuildNodes = this.pipelineGraph.querySelectorAll('.build:nth-child(2)');

      for (const buildNodeIndex in secondChildBuildNodes) {
        const buildNode = secondChildBuildNodes[buildNodeIndex];
        const firstChildBuildNode = buildNode.previousElementSibling;
        if (!firstChildBuildNode || !firstChildBuildNode.matches('.build')) continue;
        const multiBuildColumn = buildNode.closest('.stage-column');
        const previousColumn = multiBuildColumn.previousElementSibling;
        if (!previousColumn || !previousColumn.matches('.stage-column')) continue;
        multiBuildColumn.classList.add('left-margin');
        firstChildBuildNode.classList.add('left-connector');
        const columnBuilds = previousColumn.querySelectorAll('.build');
        if (columnBuilds.length === 1) previousColumn.classList.add('no-margin');
      }

      this.pipelineGraph.classList.remove('hidden');
    }
  }

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