2018-03-27 19:54:05 +05:30
|
|
|
<script>
|
2018-11-08 19:23:39 +05:30
|
|
|
import $ from 'jquery';
|
2020-04-08 14:13:33 +05:30
|
|
|
import { escape } from 'lodash';
|
2020-11-24 15:15:51 +05:30
|
|
|
import { GlLoadingIcon, GlIcon } from '@gitlab/ui';
|
2020-01-01 13:55:28 +05:30
|
|
|
import { __ } from '~/locale';
|
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';
|
2020-11-24 15:15:51 +05:30
|
|
|
import initDeprecatedJQueryDropdown from '~/deprecated_jquery_dropdown';
|
2021-02-22 17:27:13 +05:30
|
|
|
import { ListType } from '../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: {
|
2020-11-24 15:15:51 +05:30
|
|
|
GlIcon,
|
2018-12-13 13:39:08 +05:30
|
|
|
GlLoadingIcon,
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
props: {
|
2019-12-04 20:38:33 +05:30
|
|
|
list: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-11-08 19:23:39 +05:30
|
|
|
},
|
2021-01-03 14:25:43 +05:30
|
|
|
inject: ['groupId'],
|
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() {
|
2020-11-24 15:15:51 +05:30
|
|
|
initDeprecatedJQueryDropdown($(this.$refs.projectsDropdown), {
|
2018-11-08 19:23:39 +05:30
|
|
|
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'),
|
2021-01-29 00:20:46 +05:30
|
|
|
path: $el.data('project-path'),
|
2018-11-08 19:23:39 +05:30
|
|
|
};
|
|
|
|
eventHub.$emit('setSelectedProject', this.selectedProject);
|
|
|
|
},
|
|
|
|
selectable: true,
|
|
|
|
data: (term, callback) => {
|
|
|
|
this.loading = true;
|
2019-12-04 20:38:33 +05:30
|
|
|
const additionalAttrs = {};
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
if ((this.list.type || this.list.listType) !== ListType.backlog) {
|
2019-12-04 20:38:33 +05:30
|
|
|
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,
|
2020-10-24 23:57:45 +05:30
|
|
|
order_by: 'similarity',
|
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>
|
2021-01-29 00:20:46 +05:30
|
|
|
<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}"
|
|
|
|
>
|
2020-04-08 14:13:33 +05:30
|
|
|
${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>
|
2020-10-24 23:57:45 +05:30
|
|
|
<label class="label-bold gl-mt-3">{{ __('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"
|
|
|
|
>
|
2020-11-24 15:15:51 +05:30
|
|
|
{{ selectedProjectName }} <gl-icon name="chevron-down" class="dropdown-menu-toggle-icon" />
|
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')" />
|
2020-11-24 15:15:51 +05:30
|
|
|
<gl-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>
|