summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/monitoring/mixins/monitoring_mixins.js
blob: cbca14ede026530d7062846d4a6eaca9b7092eff (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
66
67
68
69
70
import { bisectDate } from '../utils/date_time_formatters';

const mixins = {
  methods: {
    mouseOverDeployInfo(mouseXPos) {
      if (!this.reducedDeploymentData) return false;

      let dataFound = false;
      this.reducedDeploymentData = this.reducedDeploymentData.map((d) => {
        const deployment = d;
        if (d.xPos >= mouseXPos - 10 && d.xPos <= mouseXPos + 10 && !dataFound) {
          dataFound = d.xPos + 1;

          deployment.showDeploymentFlag = true;
        } else {
          deployment.showDeploymentFlag = false;
        }
        return deployment;
      });

      return dataFound;
    },

    formatDeployments() {
      this.reducedDeploymentData = this.deploymentData.reduce((deploymentDataArray, deployment) => {
        const time = new Date(deployment.created_at);
        const xPos = Math.floor(this.timeSeries[0].timeSeriesScaleX(time));

        time.setSeconds(this.timeSeries[0].values[0].time.getSeconds());

        if (xPos >= 0) {
          deploymentDataArray.push({
            id: deployment.id,
            time,
            sha: deployment.sha,
            commitUrl: `${this.projectPath}/commit/${deployment.sha}`,
            tag: deployment.tag,
            tagUrl: `${this.tagsPath}/${deployment.tag}`,
            ref: deployment.ref.name,
            xPos,
            showDeploymentFlag: false,
          });
        }

        return deploymentDataArray;
      }, []);
    },

    positionFlag() {
      const timeSeries = this.timeSeries[0];
      const hoveredDataIndex = bisectDate(timeSeries.values, this.hoverData.hoveredDate, 1);
      this.currentData = timeSeries.values[hoveredDataIndex];
      this.currentDataIndex = hoveredDataIndex;
      this.currentXCoordinate = Math.floor(timeSeries.timeSeriesScaleX(this.currentData.time));
      if (this.currentXCoordinate > (this.graphWidth - 200)) {
        this.currentFlagPosition = this.currentXCoordinate - 103;
      } else {
        this.currentFlagPosition = this.currentXCoordinate;
      }

      if (this.hoverData.currentDeployXPos) {
        this.showFlag = false;
      } else {
        this.showFlag = true;
      }
    },
  },
};

export default mixins;