debian-mirror-gitlab/app/assets/javascripts/boards/components/project_select.vue

106 lines
2.7 KiB
Vue
Raw Normal View History

2018-03-27 19:54:05 +05:30
<script>
2018-11-08 19:23:39 +05:30
import $ from 'jquery';
import _ from 'underscore';
2018-12-13 13:39:08 +05:30
import Icon from '~/vue_shared/components/icon.vue';
2019-02-13 22:33:31 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2018-11-08 19:23:39 +05:30
import eventHub from '../eventhub';
import Api from '../../api';
2018-05-09 12:01:36 +05:30
2018-11-08 19:23:39 +05:30
export default {
name: 'BoardProjectSelect',
2018-12-13 13:39:08 +05:30
components: {
Icon,
GlLoadingIcon,
},
2018-11-08 19:23:39 +05:30
props: {
groupId: {
type: Number,
required: true,
default: 0,
2018-03-27 19:54:05 +05:30
},
2018-11-08 19:23:39 +05:30
},
data() {
return {
loading: true,
selectedProject: {},
};
},
computed: {
selectedProjectName() {
return this.selectedProject.name || 'Select a project';
2018-03-27 19:54:05 +05:30
},
2018-11-08 19:23:39 +05:30
},
mounted() {
$(this.$refs.projectsDropdown).glDropdown({
filterable: true,
filterRemote: true,
search: {
fields: ['name_with_namespace'],
2018-03-27 19:54:05 +05:30
},
2018-11-08 19:23:39 +05:30
clicked: ({ $el, e }) => {
e.preventDefault();
this.selectedProject = {
id: $el.data('project-id'),
name: $el.data('project-name'),
};
eventHub.$emit('setSelectedProject', this.selectedProject);
},
selectable: true,
data: (term, callback) => {
this.loading = true;
2019-02-13 22:33:31 +05:30
return Api.groupProjects(
this.groupId,
term,
{
with_issues_enabled: true,
with_shared: false,
include_subgroups: true,
},
projects => {
this.loading = false;
callback(projects);
},
);
2018-11-08 19:23:39 +05:30
},
renderRow(project) {
return `
2018-03-27 19:54:05 +05:30
<li>
2018-12-13 13:39:08 +05:30
<a href='#' class='dropdown-menu-link' data-project-id="${
project.id
}" data-project-name="${project.name}">
2018-03-27 19:54:05 +05:30
${_.escape(project.name)}
</a>
</li>
`;
2018-11-08 19:23:39 +05:30
},
text: project => project.name,
});
},
};
2018-03-27 19:54:05 +05:30
</script>
<template>
<div>
2019-02-13 22:33:31 +05:30
<label class="label-bold prepend-top-10"> Project </label>
<div ref="projectsDropdown" class="dropdown">
2018-03-27 19:54:05 +05:30
<button
class="dropdown-menu-toggle wide"
type="button"
data-toggle="dropdown"
aria-expanded="false"
>
2019-02-13 22:33:31 +05:30
{{ selectedProjectName }} <icon name="chevron-down" />
2018-03-27 19:54:05 +05:30
</button>
<div class="dropdown-menu dropdown-menu-selectable dropdown-menu-full-width">
2019-02-13 22:33:31 +05:30
<div class="dropdown-title">Projects</div>
2018-03-27 19:54:05 +05:30
<div class="dropdown-input">
2019-02-13 22:33:31 +05:30
<input class="dropdown-input-field" type="search" placeholder="Search projects" />
<icon name="search" class="dropdown-input-search" data-hidden="true" />
2018-03-27 19:54:05 +05:30
</div>
<div class="dropdown-content"></div>
2019-02-13 22:33:31 +05:30
<div class="dropdown-loading"><gl-loading-icon /></div>
2018-03-27 19:54:05 +05:30
</div>
</div>
</div>
</template>