dropdown_job_component.vue 2.85 KB
Newer Older
1
<script>
2
import $ from 'jquery';
3
import _ from 'underscore';
4 5 6
import JobNameComponent from './job_name_component.vue';
import JobComponent from './job_component.vue';
import tooltip from '../../../vue_shared/directives/tooltip';
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
/**
 * Renders the dropdown for the pipeline graph.
 *
 * The following object should be provided as `job`:
 *
 * {
 *   "id": 4256,
 *   "name": "test",
 *   "status": {
 *     "icon": "icon_status_success",
 *     "text": "passed",
 *     "label": "passed",
 *     "group": "success",
 *     "details_path": "/root/ci-mock/builds/4256",
 *     "action": {
 *       "icon": "retry",
 *       "title": "Retry",
 *       "path": "/root/ci-mock/builds/4256/retry",
 *       "method": "post"
 *     }
 *   }
 * }
 */
export default {
  directives: {
    tooltip,
  },
35

36 37 38 39
  components: {
    JobComponent,
    JobNameComponent,
  },
40

41 42 43 44
  props: {
    job: {
      type: Object,
      required: true,
Filipa Lacerda's avatar
Filipa Lacerda committed
45
    },
46
  },
Filipa Lacerda's avatar
Filipa Lacerda committed
47

48 49
  computed: {
    tooltipText() {
50
      return _.escape(`${this.job.name} - ${this.job.status.label}`);
51
    },
52
  },
53

54 55 56
  mounted() {
    this.stopDropdownClickPropagation();
  },
Filipa Lacerda's avatar
Filipa Lacerda committed
57

58 59
  methods: {
    /**
60 61 62
     * When the user right clicks or cmd/ctrl + click in the job name or the action icon
     * the dropdown should not be closed so we stop propagation
     * of the click event inside the dropdown.
63 64 65 66
     *
     * Since this component is rendered multiple times per page we need to guarantee we only
     * target the click event of this component.
     */
67 68 69 70 71 72 73
    stopDropdownClickPropagation() {
      $(
        '.js-grouped-pipeline-dropdown button, .js-grouped-pipeline-dropdown a.mini-pipeline-graph-dropdown-item',
        this.$el,
      ).on('click', e => {
        e.stopPropagation();
      });
74
    },
75 76 77 78

    pipelineActionRequestComplete() {
      this.$emit('pipelineActionRequestComplete');
    },
79 80
  },
};
81 82
</script>
<template>
83
  <div class="ci-job-dropdown-container dropdown dropright">
84
    <button
85
      v-tooltip
86
      :title="tooltipText"
87 88 89
      type="button"
      data-toggle="dropdown"
      data-container="body"
90
      data-boundary="viewport"
91
      data-display="static"
92
      class="dropdown-menu-toggle build-content"
Filipa Lacerda's avatar
Filipa Lacerda committed
93
    >
94 95 96

      <job-name-component
        :name="job.name"
Filipa Lacerda's avatar
Filipa Lacerda committed
97 98
        :status="job.status"
      />
99 100

      <span class="dropdown-counter-badge">
Filipa Lacerda's avatar
Filipa Lacerda committed
101
        {{ job.size }}
102 103 104 105 106 107
      </span>
    </button>

    <ul class="dropdown-menu big-pipeline-graph-dropdown-menu js-grouped-pipeline-dropdown">
      <li class="scrollable-menu">
        <ul>
Filipa Lacerda's avatar
Filipa Lacerda committed
108 109
          <li
            v-for="(item, i) in job.jobs"
Filipa Lacerda's avatar
Filipa Lacerda committed
110 111
            :key="i"
          >
112
            <job-component
113
              :dropdown-length="job.size"
114 115
              :job="item"
              css-class-job-name="mini-pipeline-graph-dropdown-item"
116
              @pipelineActionRequestComplete="pipelineActionRequestComplete"
Filipa Lacerda's avatar
Filipa Lacerda committed
117
            />
118 119 120 121 122 123
          </li>
        </ul>
      </li>
    </ul>
  </div>
</template>