summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/boards/components/project_select.vue
blob: f90fe58256619e453c29bec08b33e158c20901f0 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<script>
import $ from 'jquery';
import { escape } from 'lodash';
import { GlLoadingIcon, GlIcon } from '@gitlab/ui';
import { __ } from '~/locale';
import eventHub from '../eventhub';
import Api from '../../api';
import { featureAccessLevel } from '~/pages/projects/shared/permissions/constants';
import initDeprecatedJQueryDropdown from '~/deprecated_jquery_dropdown';

export default {
  name: 'BoardProjectSelect',
  components: {
    GlIcon,
    GlLoadingIcon,
  },
  props: {
    list: {
      type: Object,
      required: true,
    },
  },
  inject: ['groupId'],
  data() {
    return {
      loading: true,
      selectedProject: {},
    };
  },
  computed: {
    selectedProjectName() {
      return this.selectedProject.name || __('Select a project');
    },
  },
  mounted() {
    initDeprecatedJQueryDropdown($(this.$refs.projectsDropdown), {
      filterable: true,
      filterRemote: true,
      search: {
        fields: ['name_with_namespace'],
      },
      clicked: ({ $el, e }) => {
        e.preventDefault();
        this.selectedProject = {
          id: $el.data('project-id'),
          name: $el.data('project-name'),
          path: $el.data('project-path'),
        };
        eventHub.$emit('setSelectedProject', this.selectedProject);
      },
      selectable: true,
      data: (term, callback) => {
        this.loading = true;
        const additionalAttrs = {};

        if (this.list.type && this.list.type !== 'backlog') {
          additionalAttrs.min_access_level = featureAccessLevel.EVERYONE;
        }

        return Api.groupProjects(
          this.groupId,
          term,
          {
            with_issues_enabled: true,
            with_shared: false,
            include_subgroups: true,
            order_by: 'similarity',
            ...additionalAttrs,
          },
          projects => {
            this.loading = false;
            callback(projects);
          },
        );
      },
      renderRow(project) {
        return `
            <li>
              <a href='#' class='dropdown-menu-link'
                data-project-id="${project.id}"
                data-project-name="${project.name}"
                data-project-name-with-namespace="${project.name_with_namespace}"
                data-project-path="${project.path_with_namespace}"
              >
                ${escape(project.name_with_namespace)}
              </a>
            </li>
          `;
      },
      text: project => project.name_with_namespace,
    });
  },
};
</script>

<template>
  <div>
    <label class="label-bold gl-mt-3">{{ __('Project') }}</label>
    <div ref="projectsDropdown" class="dropdown dropdown-projects">
      <button
        class="dropdown-menu-toggle wide"
        type="button"
        data-toggle="dropdown"
        aria-expanded="false"
      >
        {{ selectedProjectName }} <gl-icon name="chevron-down" class="dropdown-menu-toggle-icon" />
      </button>
      <div class="dropdown-menu dropdown-menu-selectable dropdown-menu-full-width">
        <div class="dropdown-title">{{ __('Projects') }}</div>
        <div class="dropdown-input">
          <input class="dropdown-input-field" type="search" :placeholder="__('Search projects')" />
          <gl-icon name="search" class="dropdown-input-search" data-hidden="true" />
        </div>
        <div class="dropdown-content"></div>
        <div class="dropdown-loading"><gl-loading-icon /></div>
      </div>
    </div>
  </div>
</template>