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

121 lines
3.2 KiB
Vue
Raw Normal View History

2018-03-27 19:54:05 +05:30
<script>
2019-09-30 21:07:59 +05:30
import { __ } from '~/locale';
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-15 15:39:39 +05:30
import { GlLoadingIcon } from '@gitlab/ui';
2018-11-08 19:23:39 +05:30
import eventHub from '../eventhub';
import Api from '../../api';
2019-12-04 20:38:33 +05:30
import { featureAccessLevel } from '~/pages/projects/shared/permissions/constants';
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
},
2019-12-04 20:38:33 +05:30
list: {
type: Object,
required: true,
},
2018-11-08 19:23:39 +05:30
},
data() {
return {
loading: true,
selectedProject: {},
};
},
computed: {
selectedProjectName() {
2019-09-30 21:07:59 +05:30
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-12-04 20:38:33 +05:30
const additionalAttrs = {};
if (this.list.type && this.list.type !== 'backlog') {
additionalAttrs.min_access_level = featureAccessLevel.EVERYONE;
}
2019-02-15 15:39:39 +05:30
return Api.groupProjects(
this.groupId,
term,
{
with_issues_enabled: true,
with_shared: false,
include_subgroups: true,
2019-12-04 20:38:33 +05:30
...additionalAttrs,
2019-02-15 15:39:39 +05:30
},
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
2019-10-12 21:52:04 +05:30
}" data-project-name="${project.name}" data-project-name-with-namespace="${
project.name_with_namespace
}">
${_.escape(project.name_with_namespace)}
2018-03-27 19:54:05 +05:30
</a>
</li>
`;
2018-11-08 19:23:39 +05:30
},
2019-10-12 21:52:04 +05:30
text: project => project.name_with_namespace,
2018-11-08 19:23:39 +05:30
});
},
};
2018-03-27 19:54:05 +05:30
</script>
<template>
<div>
2019-09-30 21:07:59 +05:30
<label class="label-bold prepend-top-10">{{ __('Project') }}</label>
2019-03-02 22:35:43 +05:30
<div ref="projectsDropdown" class="dropdown dropdown-projects">
2018-03-27 19:54:05 +05:30
<button
class="dropdown-menu-toggle wide"
type="button"
data-toggle="dropdown"
aria-expanded="false"
>
2019-02-15 15:39:39 +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-09-30 21:07:59 +05:30
<div class="dropdown-title">{{ __('Projects') }}</div>
2018-03-27 19:54:05 +05:30
<div class="dropdown-input">
2019-09-30 21:07:59 +05:30
<input class="dropdown-input-field" type="search" :placeholder="__('Search projects')" />
2019-02-15 15:39:39 +05:30
<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-15 15:39:39 +05:30
<div class="dropdown-loading"><gl-loading-icon /></div>
2018-03-27 19:54:05 +05:30
</div>
</div>
</div>
</template>