summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jobs/job_details_bundle.js
blob: 15cd79b1c505877453eb927d4ccf3bbc5f422406 (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
71
72
73
74
75
76
import _ from 'underscore';
import { mapState, mapActions } from 'vuex';
import Vue from 'vue';
import Job from '../job';
import JobApp from './components/job_app.vue';
import Sidebar from './components/sidebar.vue';
import createStore from './store';

export default () => {
  const { dataset } = document.getElementById('js-job-details-vue');



  const store = createStore();
  store.dispatch('setJobEndpoint', dataset.endpoint);

  store.dispatch('fetchJob');

  // Header
  // eslint-disable-next-line no-new
  new Vue({
    el: '#js-build-header-vue',
    components: {
      JobApp,
    },
    store,
    computed: {
      ...mapState(['job', 'isLoading']),
    },
    render(createElement) {
      return createElement('job-app', {
        props: {
          isLoading: this.isLoading,
          job: this.job,
          runnerSettingsUrl: dataset.runnerSettingsUrl,
        },
      });
    },
  });

  // Sidebar information block
  const detailsBlockElement = document.getElementById('js-details-block-vue');
  const detailsBlockDataset = detailsBlockElement.dataset;
  // eslint-disable-next-line
  new Vue({
    el: detailsBlockElement,
    components: {
      Sidebar,
    },
    computed: {
      ...mapState(['job']),
    },
    watch: {
      job(newVal, oldVal) {
        if (_.isEmpty(oldVal) && !_.isEmpty(newVal.pipeline)) {
          this.fetchStages();
        }
      },
    },
    methods: {
      ...mapActions(['fetchStages']),
    },
    store,
    render(createElement) {
      return createElement('sidebar', {
        props: {
          runnerHelpUrl: dataset.runnerHelpUrl,
          terminalPath: detailsBlockDataset.terminalPath,
        },
      });
    },
  });

  // eslint-disable-next-line no-new
  new Job();
};