summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/environments/components/environment_actions.js.es6
blob: 4cdcd555e89d994f4f034a462c054f90d6247121 (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
/*= require vue */
/* global Vue */

(() => {
  window.gl = window.gl || {};
  window.gl.environmentsList = window.gl.environmentsList || {};

  window.gl.environmentsList.ActionsComponent = Vue.component('actions-component', {
    props: {
      actions: {
        type: Array,
        required: false,
        default: () => [],
      },
    },

    /**
     * Appends the svg icon that were render in the index page.
     * In order to reuse the svg instead of copy and paste in this template
     * we need to render it outside this component using =custom_icon partial.
     *
     * TODO: Remove this when webpack is merged.
     *
     */
    mounted() {
      const playIcon = document.querySelector('.play-icon-svg.hidden svg');

      const dropdownContainer = this.$el.querySelector('.dropdown-play-icon-container');
      const actionContainers = this.$el.querySelectorAll('.action-play-icon-container');
      // Phantomjs does not have support to iterate a nodelist.
      const actionsArray = [].slice.call(actionContainers);

      if (playIcon && actionsArray && dropdownContainer) {
        dropdownContainer.appendChild(playIcon.cloneNode(true));

        actionsArray.forEach((element) => {
          element.appendChild(playIcon.cloneNode(true));
        });
      }
    },

    template: `
      <div class="inline">
        <div class="dropdown">
          <a class="dropdown-new btn btn-default" data-toggle="dropdown">
            <span class="dropdown-play-icon-container">
              <!-- svg goes here -->
            </span>
            <i class="fa fa-caret-down"></i>
          </a>

          <ul class="dropdown-menu dropdown-menu-align-right">
            <li v-for="action in actions">
              <a :href="action.play_url" data-method="post" rel="nofollow" class="js-manual-action-link">
              <span class="action-play-icon-container">
                <!-- svg goes here -->
              </span>
              <span v-html="action.name"></span>
              </a>
            </li>
          </ul>
        </div>
      </div>
    `,
  });
})();