pipelines_store.js 1.28 KB
Newer Older
1
/* eslint-disable no-underscore-dangle*/
Filipa Lacerda's avatar
Filipa Lacerda committed
2 3 4 5 6
/**
 * Pipelines' Store for commits view.
 *
 * Used to store the Pipelines rendered in the commit view in the pipelines table.
 */
7
require('../../vue_realtime_listener');
Filipa Lacerda's avatar
Filipa Lacerda committed
8

Filipa Lacerda's avatar
Filipa Lacerda committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
class PipelinesStore {
  constructor() {
    this.state = {};
    this.state.pipelines = [];
  }

  storePipelines(pipelines = []) {
    this.state.pipelines = pipelines;

    return pipelines;
  }

  /**
   * Once the data is received we will start the time ago loops.
   *
   * Everytime a request is made like retry or cancel a pipeline, every 10 seconds we
   * update the time to show how long as passed.
   *
   */
28
  static startTimeAgoLoops() {
Filipa Lacerda's avatar
Filipa Lacerda committed
29
    const startTimeLoops = () => {
30
      this.timeLoopInterval = setInterval(() => {
Filipa Lacerda's avatar
Filipa Lacerda committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
        this.$children[0].$children.reduce((acc, component) => {
          const timeAgoComponent = component.$children.filter(el => el.$options._componentTag === 'time-ago')[0];
          acc.push(timeAgoComponent);
          return acc;
        }, []).forEach(e => e.changeTime());
      }, 10000);
    };

    startTimeLoops();

    const removeIntervals = () => clearInterval(this.timeLoopInterval);
    const startIntervals = () => startTimeLoops();

    gl.VueRealtimeListener(removeIntervals, startIntervals);
  }
}

48
module.exports = PipelinesStore;