2022-03-31 08:08:17 -04:00
|
|
|
/* eslint-disable func-names, prefer-rest-params, consistent-return, no-shadow, no-self-compare, no-unused-expressions, yoda, prefer-spread, camelcase, no-param-reassign */
|
2016-12-14 00:26:26 -05:00
|
|
|
/* global Issuable */
|
2017-05-09 09:43:08 -04:00
|
|
|
/* global emitSidebarEvent */
|
2018-03-09 15:18:59 -05:00
|
|
|
|
|
|
|
import $ from 'jquery';
|
2020-04-21 14:09:31 -04:00
|
|
|
import { escape, template, uniqBy } from 'lodash';
|
2020-05-04 14:10:20 -04:00
|
|
|
import {
|
|
|
|
AJAX_USERS_SELECT_OPTIONS_MAP,
|
|
|
|
AJAX_USERS_SELECT_PARAMS_MAP,
|
|
|
|
} from 'ee_else_ce/users_select/constants';
|
2021-02-01 10:08:56 -05:00
|
|
|
import initDeprecatedJQueryDropdown from '~/deprecated_jquery_dropdown';
|
2021-02-17 04:09:36 -05:00
|
|
|
import { isUserBusy } from '~/set_status_modal/utils';
|
2021-02-01 10:08:56 -05:00
|
|
|
import { fixTitle, dispose } from '~/tooltips';
|
2022-03-31 08:08:17 -04:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import { parseBoolean, spriteIcon } from '~/lib/utils/common_utils';
|
|
|
|
import { loadCSSFile } from '~/lib/utils/css_utils';
|
|
|
|
import { s__, __, sprintf } from '~/locale';
|
2021-02-01 10:08:56 -05:00
|
|
|
import { getAjaxUsersSelectOptions, getAjaxUsersSelectParams } from './utils';
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2017-05-09 09:43:08 -04:00
|
|
|
// TODO: remove eventHub hack after code splitting refactor
|
|
|
|
window.emitSidebarEvent = window.emitSidebarEvent || $.noop;
|
2016-12-14 00:26:26 -05:00
|
|
|
|
2017-10-24 09:48:41 -04:00
|
|
|
function UsersSelect(currentUser, els, options = {}) {
|
2020-09-29 05:09:49 -04:00
|
|
|
const elsClassName = els?.toString().match('.(.+$)')[1];
|
2019-11-22 13:06:00 -05:00
|
|
|
const $els = $(els || '.js-user-search');
|
2017-05-12 04:15:28 -04:00
|
|
|
this.users = this.users.bind(this);
|
|
|
|
this.user = this.user.bind(this);
|
2020-06-18 11:08:45 -04:00
|
|
|
this.usersPath = '/-/autocomplete/users.json';
|
|
|
|
this.userPath = '/-/autocomplete/users/:id.json';
|
2017-05-12 04:15:28 -04:00
|
|
|
if (currentUser != null) {
|
|
|
|
if (typeof currentUser === 'object') {
|
|
|
|
this.currentUser = currentUser;
|
|
|
|
} else {
|
|
|
|
this.currentUser = JSON.parse(currentUser);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-28 14:08:20 -04:00
|
|
|
const { handleClick } = options;
|
2019-12-18 01:08:03 -05:00
|
|
|
const userSelect = this;
|
|
|
|
|
|
|
|
$els.each((i, dropdown) => {
|
|
|
|
const userSelect = this;
|
|
|
|
const options = {};
|
|
|
|
const $dropdown = $(dropdown);
|
|
|
|
options.projectId = $dropdown.data('projectId');
|
|
|
|
options.groupId = $dropdown.data('groupId');
|
|
|
|
options.showCurrentUser = $dropdown.data('currentUser');
|
|
|
|
options.todoFilter = $dropdown.data('todoFilter');
|
|
|
|
options.todoStateFilter = $dropdown.data('todoStateFilter');
|
|
|
|
options.iid = $dropdown.data('iid');
|
|
|
|
options.issuableType = $dropdown.data('issuableType');
|
2020-12-16 16:09:57 -05:00
|
|
|
options.targetBranch = $dropdown.data('targetBranch');
|
2022-09-23 14:12:59 -04:00
|
|
|
options.showSuggested = $dropdown.data('showSuggested');
|
2019-12-18 01:08:03 -05:00
|
|
|
const showNullUser = $dropdown.data('nullUser');
|
|
|
|
const defaultNullUser = $dropdown.data('nullUserDefault');
|
|
|
|
const showMenuAbove = $dropdown.data('showMenuAbove');
|
|
|
|
const showAnyUser = $dropdown.data('anyUser');
|
|
|
|
const firstUser = $dropdown.data('firstUser');
|
|
|
|
options.authorId = $dropdown.data('authorId');
|
|
|
|
const defaultLabel = $dropdown.data('defaultLabel');
|
|
|
|
const issueURL = $dropdown.data('issueUpdate');
|
|
|
|
const $selectbox = $dropdown.closest('.selectbox');
|
2020-09-14 08:09:34 -04:00
|
|
|
const $assignToMeLink = $selectbox.next('.assign-to-me-link');
|
2019-12-18 01:08:03 -05:00
|
|
|
let $block = $selectbox.closest('.block');
|
|
|
|
const abilityName = $dropdown.data('abilityName');
|
|
|
|
let $value = $block.find('.value');
|
|
|
|
const $collapsedSidebar = $block.find('.sidebar-collapsed-user');
|
2020-12-02 10:09:37 -05:00
|
|
|
const $loading = $block.find('.block-loading').addClass('gl-display-none');
|
2019-12-18 01:08:03 -05:00
|
|
|
const selectedIdDefault = defaultNullUser && showNullUser ? 0 : null;
|
|
|
|
let selectedId = $dropdown.data('selected');
|
|
|
|
let assignTo;
|
|
|
|
let assigneeTemplate;
|
|
|
|
let collapsedAssigneeTemplate;
|
|
|
|
|
|
|
|
if (selectedId === undefined) {
|
|
|
|
selectedId = selectedIdDefault;
|
|
|
|
}
|
2017-10-24 09:48:41 -04:00
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
const assignYourself = function () {
|
2019-12-18 01:08:03 -05:00
|
|
|
const unassignedSelected = $dropdown
|
|
|
|
.closest('.selectbox')
|
|
|
|
.find(`input[name='${$dropdown.data('fieldName')}'][value=0]`);
|
|
|
|
|
|
|
|
if (unassignedSelected) {
|
|
|
|
unassignedSelected.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save current selected user to the DOM
|
|
|
|
const currentUserInfo = $dropdown.data('currentUserInfo') || {};
|
|
|
|
const currentUser = userSelect.currentUser || {};
|
|
|
|
const fieldName = $dropdown.data('fieldName');
|
|
|
|
const userName = currentUserInfo.name;
|
|
|
|
const userId = currentUserInfo.id || currentUser.id;
|
|
|
|
|
2020-04-21 11:21:10 -04:00
|
|
|
const inputHtmlString = template(`
|
2019-12-18 01:08:03 -05:00
|
|
|
<input type="hidden" name="<%- fieldName %>"
|
|
|
|
data-meta="<%- userName %>"
|
|
|
|
value="<%- userId %>" />
|
|
|
|
`)({ fieldName, userName, userId });
|
|
|
|
|
|
|
|
if ($selectbox) {
|
|
|
|
$dropdown.parent().before(inputHtmlString);
|
|
|
|
} else {
|
|
|
|
$dropdown.after(inputHtmlString);
|
|
|
|
}
|
|
|
|
};
|
2017-05-12 04:15:28 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
if ($block[0]) {
|
|
|
|
$block[0].addEventListener('assignYourself', assignYourself);
|
|
|
|
}
|
2017-05-12 04:15:28 -04:00
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
const getSelectedUserInputs = function () {
|
2019-12-18 01:08:03 -05:00
|
|
|
return $selectbox.find(`input[name="${$dropdown.data('fieldName')}"]`);
|
|
|
|
};
|
2017-05-12 04:15:28 -04:00
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
const getSelected = function () {
|
2019-12-18 01:08:03 -05:00
|
|
|
return getSelectedUserInputs()
|
|
|
|
.map((index, input) => parseInt(input.value, 10))
|
|
|
|
.get();
|
|
|
|
};
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
const checkMaxSelect = function () {
|
2019-12-18 01:08:03 -05:00
|
|
|
const maxSelect = $dropdown.data('maxSelect');
|
|
|
|
if (maxSelect) {
|
|
|
|
const selected = getSelected();
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
if (selected.length > maxSelect) {
|
|
|
|
const firstSelectedId = selected[0];
|
|
|
|
const firstSelected = $dropdown
|
|
|
|
.closest('.selectbox')
|
|
|
|
.find(`input[name='${$dropdown.data('fieldName')}'][value=${firstSelectedId}]`);
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
firstSelected.remove();
|
2020-09-29 05:09:49 -04:00
|
|
|
|
|
|
|
if ($dropdown.hasClass(elsClassName)) {
|
|
|
|
emitSidebarEvent('sidebar.removeReviewer', {
|
|
|
|
id: firstSelectedId,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
emitSidebarEvent('sidebar.removeAssignee', {
|
|
|
|
id: firstSelectedId,
|
|
|
|
});
|
|
|
|
}
|
2019-12-18 01:08:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-10-10 03:13:34 -04:00
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
const getMultiSelectDropdownTitle = function (selectedUser, isSelected) {
|
2020-12-23 16:10:24 -05:00
|
|
|
const selectedUsers = getSelected().filter((u) => u !== 0);
|
2019-12-18 01:08:03 -05:00
|
|
|
|
|
|
|
const firstUser = getSelectedUserInputs()
|
|
|
|
.map((index, input) => ({
|
|
|
|
name: input.dataset.meta,
|
|
|
|
value: parseInt(input.value, 10),
|
|
|
|
}))
|
2020-12-23 16:10:24 -05:00
|
|
|
.filter((u) => u.id !== 0)
|
2019-12-18 01:08:03 -05:00
|
|
|
.get(0);
|
|
|
|
|
|
|
|
if (selectedUsers.length === 0) {
|
|
|
|
return s__('UsersSelect|Unassigned');
|
|
|
|
} else if (selectedUsers.length === 1) {
|
|
|
|
return firstUser.name;
|
|
|
|
} else if (isSelected) {
|
2020-12-23 16:10:24 -05:00
|
|
|
const otherSelected = selectedUsers.filter((s) => s !== selectedUser.id);
|
2019-12-18 01:08:03 -05:00
|
|
|
return sprintf(s__('UsersSelect|%{name} + %{length} more'), {
|
|
|
|
name: selectedUser.name,
|
|
|
|
length: otherSelected.length,
|
2018-10-10 03:13:34 -04:00
|
|
|
});
|
2019-12-18 01:08:03 -05:00
|
|
|
}
|
2020-04-29 20:09:37 -04:00
|
|
|
return sprintf(s__('UsersSelect|%{name} + %{length} more'), {
|
|
|
|
name: firstUser.name,
|
|
|
|
length: selectedUsers.length - 1,
|
|
|
|
});
|
2019-12-18 01:08:03 -05:00
|
|
|
};
|
2018-10-10 03:13:34 -04:00
|
|
|
|
2022-06-28 14:08:20 -04:00
|
|
|
$assignToMeLink.on('click', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
$(e.currentTarget).hide();
|
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
if ($dropdown.data('multiSelect')) {
|
|
|
|
assignYourself();
|
|
|
|
checkMaxSelect();
|
|
|
|
|
|
|
|
const currentUserInfo = $dropdown.data('currentUserInfo');
|
|
|
|
$dropdown
|
|
|
|
.find('.dropdown-toggle-text')
|
|
|
|
.text(getMultiSelectDropdownTitle(currentUserInfo))
|
|
|
|
.removeClass('is-default');
|
|
|
|
} else {
|
|
|
|
const $input = $(`input[name="${$dropdown.data('fieldName')}"]`);
|
|
|
|
$input.val(gon.current_user_id);
|
|
|
|
selectedId = $input.val();
|
|
|
|
$dropdown
|
|
|
|
.find('.dropdown-toggle-text')
|
|
|
|
.text(gon.current_user_fullname)
|
|
|
|
.removeClass('is-default');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
$block.on('click', '.js-assign-yourself', (e) => {
|
2019-12-18 01:08:03 -05:00
|
|
|
e.preventDefault();
|
|
|
|
return assignTo(userSelect.currentUser.id);
|
|
|
|
});
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
assignTo = function (selected) {
|
2019-12-18 01:08:03 -05:00
|
|
|
const data = {};
|
|
|
|
data[abilityName] = {};
|
|
|
|
data[abilityName].assignee_id = selected != null ? selected : null;
|
2020-12-02 10:09:37 -05:00
|
|
|
$loading.removeClass('gl-display-none');
|
2019-12-18 01:08:03 -05:00
|
|
|
$dropdown.trigger('loading.gl.dropdown');
|
|
|
|
|
|
|
|
return axios.put(issueURL, data).then(({ data }) => {
|
|
|
|
let user = {};
|
2022-03-16 08:07:24 -04:00
|
|
|
let tooltipTitle;
|
2019-12-18 01:08:03 -05:00
|
|
|
$dropdown.trigger('loaded.gl.dropdown');
|
2020-12-02 10:09:37 -05:00
|
|
|
$loading.addClass('gl-display-none');
|
2019-12-18 01:08:03 -05:00
|
|
|
if (data.assignee) {
|
|
|
|
user = {
|
|
|
|
name: data.assignee.name,
|
|
|
|
username: data.assignee.username,
|
|
|
|
avatar: data.assignee.avatar_url,
|
|
|
|
};
|
2020-04-21 14:09:31 -04:00
|
|
|
tooltipTitle = escape(user.name);
|
2019-12-18 01:08:03 -05:00
|
|
|
} else {
|
|
|
|
user = {
|
|
|
|
name: s__('UsersSelect|Unassigned'),
|
|
|
|
username: '',
|
|
|
|
avatar: '',
|
|
|
|
};
|
|
|
|
tooltipTitle = s__('UsersSelect|Assignee');
|
|
|
|
}
|
|
|
|
$value.html(assigneeTemplate(user));
|
2020-10-28 08:08:40 -04:00
|
|
|
$collapsedSidebar.attr('title', tooltipTitle);
|
|
|
|
fixTitle($collapsedSidebar);
|
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
return $collapsedSidebar.html(collapsedAssigneeTemplate(user));
|
|
|
|
});
|
|
|
|
};
|
2020-04-21 11:21:10 -04:00
|
|
|
collapsedAssigneeTemplate = template(
|
2020-08-27 11:10:21 -04:00
|
|
|
`<% if( avatar ) { %> <a class="author-link" href="/<%- username %>"> <img width="24" class="avatar avatar-inline s24" alt="" src="<%- avatar %>"> </a> <% } else { %> ${spriteIcon(
|
|
|
|
'user',
|
|
|
|
)} <% } %>`,
|
2019-12-18 01:08:03 -05:00
|
|
|
);
|
2020-04-21 11:21:10 -04:00
|
|
|
assigneeTemplate = template(
|
2022-06-27 23:09:38 -04:00
|
|
|
`<% if (username) { %> <a class="author-link gl-font-weight-bold" href="/<%- username %>"> <% if( avatar ) { %> <img width="32" class="avatar avatar-inline s32" alt="" src="<%- avatar %>"> <% } %> <span class="author"><%- name %></span> <span class="username"> @<%- username %> </span> </a> <% } else { %> <span class="no-value assign-yourself">
|
2019-12-18 01:08:03 -05:00
|
|
|
${sprintf(s__('UsersSelect|No assignee - %{openingTag} assign yourself %{closingTag}'), {
|
|
|
|
openingTag: '<a href="#" class="js-assign-yourself">',
|
|
|
|
closingTag: '</a>',
|
|
|
|
})}</span> <% } %>`,
|
|
|
|
);
|
2020-08-24 14:10:19 -04:00
|
|
|
return initDeprecatedJQueryDropdown($dropdown, {
|
2019-12-18 01:08:03 -05:00
|
|
|
showMenuAbove,
|
|
|
|
data(term, callback) {
|
2020-12-23 16:10:24 -05:00
|
|
|
return userSelect.users(term, options, (users) => {
|
2019-12-18 01:08:03 -05:00
|
|
|
// GitLabDropdownFilter returns this.instance
|
|
|
|
// GitLabDropdownRemote returns this.options.instance
|
2020-08-24 14:10:19 -04:00
|
|
|
const deprecatedJQueryDropdown = this.instance || this.options.instance;
|
|
|
|
deprecatedJQueryDropdown.options.processData(term, users, callback);
|
2019-12-18 01:08:03 -05:00
|
|
|
});
|
|
|
|
},
|
2021-04-14 11:09:04 -04:00
|
|
|
processData(term, dataArg, callback) {
|
|
|
|
// Sometimes the `dataArg` can contain special dropdown items like
|
|
|
|
// dividers which we don't want to consider here.
|
|
|
|
const data = dataArg.filter((x) => !x.type);
|
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
let users = data;
|
|
|
|
|
|
|
|
// Only show assigned user list when there is no search term
|
|
|
|
if ($dropdown.hasClass('js-multiselect') && term.length === 0) {
|
|
|
|
const selectedInputs = getSelectedUserInputs();
|
|
|
|
|
|
|
|
// Potential duplicate entries when dealing with issue board
|
|
|
|
// because issue board is also managed by vue
|
2020-12-23 16:10:24 -05:00
|
|
|
const selectedUsers = uniqBy(selectedInputs, (a) => a.value)
|
|
|
|
.filter((input) => {
|
2019-12-18 01:08:03 -05:00
|
|
|
const userId = parseInt(input.value, 10);
|
2020-12-23 16:10:24 -05:00
|
|
|
const inUsersArray = users.find((u) => u.id === userId);
|
2019-12-18 01:08:03 -05:00
|
|
|
|
|
|
|
return !inUsersArray && userId !== 0;
|
|
|
|
})
|
2020-12-23 16:10:24 -05:00
|
|
|
.map((input) => {
|
2019-12-18 01:08:03 -05:00
|
|
|
const userId = parseInt(input.value, 10);
|
|
|
|
const { avatarUrl, avatar_url, name, username, canMerge } = input.dataset;
|
|
|
|
return {
|
2020-06-23 02:08:52 -04:00
|
|
|
avatar_url: avatarUrl || avatar_url || gon.default_avatar_url,
|
2019-12-18 01:08:03 -05:00
|
|
|
id: userId,
|
|
|
|
name,
|
|
|
|
username,
|
|
|
|
can_merge: parseBoolean(canMerge),
|
2018-02-02 08:17:23 -05:00
|
|
|
};
|
2019-09-24 05:06:04 -04:00
|
|
|
});
|
2017-05-26 17:27:30 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
users = data.concat(selectedUsers);
|
|
|
|
}
|
2017-05-26 17:27:30 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
let anyUser;
|
|
|
|
let index;
|
|
|
|
let len;
|
|
|
|
let name;
|
|
|
|
let obj;
|
|
|
|
let showDivider;
|
|
|
|
if (term.length === 0) {
|
|
|
|
showDivider = 0;
|
|
|
|
if (firstUser) {
|
|
|
|
// Move current user to the front of the list
|
|
|
|
for (index = 0, len = users.length; index < len; index += 1) {
|
|
|
|
obj = users[index];
|
|
|
|
if (obj.username === firstUser) {
|
|
|
|
users.splice(index, 1);
|
|
|
|
users.unshift(obj);
|
|
|
|
break;
|
2017-05-04 16:55:36 -04:00
|
|
|
}
|
2019-12-18 01:08:03 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (showNullUser) {
|
|
|
|
showDivider += 1;
|
|
|
|
users.unshift({
|
|
|
|
beforeDivider: true,
|
|
|
|
name: s__('UsersSelect|Unassigned'),
|
|
|
|
id: 0,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (showAnyUser) {
|
|
|
|
showDivider += 1;
|
|
|
|
name = showAnyUser;
|
|
|
|
if (name === true) {
|
|
|
|
name = s__('UsersSelect|Any User');
|
|
|
|
}
|
|
|
|
anyUser = {
|
|
|
|
beforeDivider: true,
|
|
|
|
name,
|
|
|
|
id: null,
|
|
|
|
};
|
|
|
|
users.unshift(anyUser);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (showDivider) {
|
|
|
|
users.splice(showDivider, 0, { type: 'divider' });
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($dropdown.hasClass('js-multiselect')) {
|
2020-12-23 16:10:24 -05:00
|
|
|
const selected = getSelected().filter((i) => i !== 0);
|
2019-12-18 01:08:03 -05:00
|
|
|
|
2022-09-23 14:12:59 -04:00
|
|
|
if ($dropdown.data('showSuggested')) {
|
|
|
|
const suggested = this.suggestedUsers(users);
|
|
|
|
if (suggested.length) {
|
|
|
|
users = users.filter(
|
|
|
|
(u) => !u.suggested || (u.suggested && selected.indexOf(u.id) !== -1),
|
|
|
|
);
|
|
|
|
users.splice(showDivider + 1, 0, ...suggested);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
if (selected.length > 0) {
|
|
|
|
if ($dropdown.data('dropdownHeader')) {
|
2018-10-10 03:13:34 -04:00
|
|
|
showDivider += 1;
|
2019-12-18 01:08:03 -05:00
|
|
|
users.splice(showDivider, 0, {
|
|
|
|
type: 'header',
|
|
|
|
content: $dropdown.data('dropdownHeader'),
|
2018-10-10 03:13:34 -04:00
|
|
|
});
|
|
|
|
}
|
2016-10-05 07:20:59 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
const selectedUsers = users
|
2020-12-23 16:10:24 -05:00
|
|
|
.filter((u) => selected.indexOf(u.id) !== -1)
|
2019-12-18 01:08:03 -05:00
|
|
|
.sort((a, b) => a.name > b.name);
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
users = users.filter((u) => selected.indexOf(u.id) === -1);
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
selectedUsers.forEach((selectedUser) => {
|
2019-12-18 01:08:03 -05:00
|
|
|
showDivider += 1;
|
|
|
|
users.splice(showDivider, 0, selectedUser);
|
|
|
|
});
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
users.splice(showDivider + 1, 0, { type: 'divider' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-04 15:21:06 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
callback(users);
|
|
|
|
if (showMenuAbove) {
|
2020-08-24 14:10:19 -04:00
|
|
|
$dropdown.data('deprecatedJQueryDropdown').positionMenuAbove();
|
2019-12-18 01:08:03 -05:00
|
|
|
}
|
|
|
|
},
|
2022-09-23 14:12:59 -04:00
|
|
|
suggestedUsers(users) {
|
|
|
|
const selected = getSelected().filter((i) => i !== 0);
|
|
|
|
const suggestedUsers = users
|
|
|
|
.filter((u) => u.suggested && selected.indexOf(u.id) === -1)
|
|
|
|
.sort((a, b) => a.name > b.name);
|
|
|
|
|
|
|
|
if (!suggestedUsers.length) return [];
|
|
|
|
|
|
|
|
const items = [
|
|
|
|
{ type: 'header', content: $dropdown.data('suggestedReviewersHeader') },
|
|
|
|
...suggestedUsers,
|
|
|
|
{ type: 'header', content: $dropdown.data('allMembersHeader') },
|
|
|
|
];
|
|
|
|
return items;
|
|
|
|
},
|
2019-12-18 01:08:03 -05:00
|
|
|
filterable: true,
|
|
|
|
filterRemote: true,
|
|
|
|
search: {
|
|
|
|
fields: ['name', 'username'],
|
|
|
|
},
|
|
|
|
selectable: true,
|
|
|
|
fieldName: $dropdown.data('fieldName'),
|
2020-08-24 14:10:19 -04:00
|
|
|
toggleLabel(selected, el, deprecatedJQueryDropdown) {
|
|
|
|
const inputValue = deprecatedJQueryDropdown.filterInput.val();
|
2019-12-18 01:08:03 -05:00
|
|
|
|
|
|
|
if (this.multiSelect && inputValue === '') {
|
|
|
|
// Remove non-users from the fullData array
|
2020-08-24 14:10:19 -04:00
|
|
|
const users = deprecatedJQueryDropdown.filteredFullData();
|
|
|
|
const callback = deprecatedJQueryDropdown.parseData.bind(deprecatedJQueryDropdown);
|
2019-12-18 01:08:03 -05:00
|
|
|
|
|
|
|
// Update the data model
|
|
|
|
this.processData(inputValue, users, callback);
|
|
|
|
}
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
if (this.multiSelect) {
|
|
|
|
return getMultiSelectDropdownTitle(selected, $(el).hasClass('is-active'));
|
|
|
|
}
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
if (selected && 'id' in selected && $(el).hasClass('is-active')) {
|
|
|
|
$dropdown.find('.dropdown-toggle-text').removeClass('is-default');
|
|
|
|
if (selected.text) {
|
|
|
|
return selected.text;
|
|
|
|
}
|
2020-04-29 20:09:37 -04:00
|
|
|
return selected.name;
|
2019-12-18 01:08:03 -05:00
|
|
|
}
|
2020-04-29 20:09:37 -04:00
|
|
|
$dropdown.find('.dropdown-toggle-text').addClass('is-default');
|
|
|
|
return defaultLabel;
|
2019-12-18 01:08:03 -05:00
|
|
|
},
|
|
|
|
defaultLabel,
|
|
|
|
hidden() {
|
|
|
|
if ($dropdown.hasClass('js-multiselect')) {
|
2020-09-29 05:09:49 -04:00
|
|
|
if ($dropdown.hasClass(elsClassName)) {
|
|
|
|
emitSidebarEvent('sidebar.saveReviewers');
|
|
|
|
} else {
|
|
|
|
emitSidebarEvent('sidebar.saveAssignees');
|
|
|
|
}
|
2019-12-18 01:08:03 -05:00
|
|
|
}
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
if (!$dropdown.data('alwaysShowSelectbox')) {
|
|
|
|
$selectbox.hide();
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
// Recalculate where .value is because vue might have changed it
|
|
|
|
$block = $selectbox.closest('.block');
|
|
|
|
$value = $block.find('.value');
|
|
|
|
// display:block overrides the hide-collapse rule
|
|
|
|
$value.css('display', '');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
multiSelect: $dropdown.hasClass('js-multiselect'),
|
|
|
|
inputMeta: $dropdown.data('inputMeta'),
|
|
|
|
clicked(options) {
|
|
|
|
const { $el, e, isMarking } = options;
|
|
|
|
const user = options.selectedObj;
|
|
|
|
|
2020-10-28 08:08:40 -04:00
|
|
|
dispose($el);
|
2019-12-18 01:08:03 -05:00
|
|
|
|
|
|
|
if ($dropdown.hasClass('js-multiselect')) {
|
|
|
|
const isActive = $el.hasClass('is-active');
|
|
|
|
const previouslySelected = $dropdown
|
|
|
|
.closest('.selectbox')
|
|
|
|
.find(`input[name='${$dropdown.data('fieldName')}'][value!=0]`);
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
// Enables support for limiting the number of users selected
|
|
|
|
// Automatically removes the first on the list if more users are selected
|
|
|
|
checkMaxSelect();
|
|
|
|
|
|
|
|
if (user.beforeDivider && user.name.toLowerCase() === 'unassigned') {
|
|
|
|
// Unassigned selected
|
|
|
|
previouslySelected.each((index, element) => {
|
|
|
|
element.remove();
|
|
|
|
});
|
2020-09-29 05:09:49 -04:00
|
|
|
if ($dropdown.hasClass(elsClassName)) {
|
|
|
|
emitSidebarEvent('sidebar.removeAllReviewers');
|
|
|
|
} else {
|
|
|
|
emitSidebarEvent('sidebar.removeAllAssignees');
|
|
|
|
}
|
2019-12-18 01:08:03 -05:00
|
|
|
} else if (isActive) {
|
|
|
|
// user selected
|
2020-09-29 05:09:49 -04:00
|
|
|
if ($dropdown.hasClass(elsClassName)) {
|
|
|
|
emitSidebarEvent('sidebar.addReviewer', user);
|
|
|
|
} else {
|
|
|
|
emitSidebarEvent('sidebar.addAssignee', user);
|
|
|
|
}
|
2019-12-18 01:08:03 -05:00
|
|
|
|
|
|
|
// Remove unassigned selection (if it was previously selected)
|
|
|
|
const unassignedSelected = $dropdown
|
|
|
|
.closest('.selectbox')
|
|
|
|
.find(`input[name='${$dropdown.data('fieldName')}'][value=0]`);
|
|
|
|
|
|
|
|
if (unassignedSelected) {
|
|
|
|
unassignedSelected.remove();
|
2018-10-10 03:13:34 -04:00
|
|
|
}
|
2019-12-18 01:08:03 -05:00
|
|
|
} else {
|
|
|
|
if (previouslySelected.length === 0) {
|
|
|
|
// Select unassigned because there is no more selected users
|
|
|
|
this.addInput($dropdown.data('fieldName'), 0, {});
|
2017-05-12 04:15:28 -04:00
|
|
|
}
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
// User unselected
|
2020-09-29 05:09:49 -04:00
|
|
|
if ($dropdown.hasClass(elsClassName)) {
|
|
|
|
emitSidebarEvent('sidebar.removeReviewer', user);
|
|
|
|
} else {
|
|
|
|
emitSidebarEvent('sidebar.removeAssignee', user);
|
|
|
|
}
|
2019-12-18 01:08:03 -05:00
|
|
|
}
|
2017-05-12 04:15:28 -04:00
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
if (getSelected().find((u) => u === gon.current_user_id)) {
|
2020-09-14 08:09:34 -04:00
|
|
|
$assignToMeLink.hide();
|
2019-12-18 01:08:03 -05:00
|
|
|
} else {
|
2020-09-14 08:09:34 -04:00
|
|
|
$assignToMeLink.show();
|
2019-12-18 01:08:03 -05:00
|
|
|
}
|
|
|
|
}
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
const page = $('body').attr('data-page');
|
|
|
|
const isIssueIndex = page === 'projects:issues:index';
|
|
|
|
const isMRIndex = page === page && page === 'projects:merge_requests:index';
|
|
|
|
if (
|
|
|
|
$dropdown.hasClass('js-filter-bulk-update') ||
|
|
|
|
$dropdown.hasClass('js-issuable-form-dropdown')
|
|
|
|
) {
|
|
|
|
e.preventDefault();
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
const isSelecting = user.id !== selectedId;
|
|
|
|
selectedId = isSelecting ? user.id : selectedIdDefault;
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
if (selectedId === gon.current_user_id) {
|
|
|
|
$('.assign-to-me-link').hide();
|
|
|
|
} else {
|
|
|
|
$('.assign-to-me-link').show();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2021-03-28 20:09:36 -04:00
|
|
|
if (handleClick) {
|
2019-12-18 01:08:03 -05:00
|
|
|
e.preventDefault();
|
|
|
|
handleClick(user, isMarking);
|
|
|
|
} else if ($dropdown.hasClass('js-filter-submit') && (isIssueIndex || isMRIndex)) {
|
|
|
|
return Issuable.filterResults($dropdown.closest('form'));
|
|
|
|
} else if ($dropdown.hasClass('js-filter-submit')) {
|
|
|
|
return $dropdown.closest('form').submit();
|
|
|
|
} else if (!$dropdown.hasClass('js-multiselect')) {
|
|
|
|
const selected = $dropdown
|
|
|
|
.closest('.selectbox')
|
|
|
|
.find(`input[name='${$dropdown.data('fieldName')}']`)
|
|
|
|
.val();
|
|
|
|
return assignTo(selected);
|
|
|
|
}
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
// Automatically close dropdown after assignee is selected
|
|
|
|
// since CE has no multiple assignees
|
|
|
|
// EE does not have a max-select
|
|
|
|
if ($dropdown.data('maxSelect') && getSelected().length === $dropdown.data('maxSelect')) {
|
|
|
|
// Close the dropdown
|
|
|
|
$dropdown.dropdown('toggle');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
id(user) {
|
|
|
|
return user.id;
|
|
|
|
},
|
|
|
|
opened(e) {
|
|
|
|
const $el = $(e.currentTarget);
|
|
|
|
const selected = getSelected();
|
|
|
|
$el.find('.is-active').removeClass('is-active');
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
function highlightSelected(id) {
|
|
|
|
$el.find(`li[data-user-id="${id}"] .dropdown-menu-user-link`).addClass('is-active');
|
|
|
|
}
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
if (selected.length > 0) {
|
2020-12-23 16:10:24 -05:00
|
|
|
getSelected().forEach((selectedId) => highlightSelected(selectedId));
|
2019-12-18 01:08:03 -05:00
|
|
|
} else {
|
|
|
|
highlightSelected(selectedId);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
updateLabel: $dropdown.data('dropdownTitle'),
|
|
|
|
renderRow(user) {
|
|
|
|
const username = user.username ? `@${user.username}` : '';
|
|
|
|
const avatar = user.avatar_url ? user.avatar_url : gon.default_avatar_url;
|
2017-05-04 14:36:18 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
let selected = false;
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
if (this.multiSelect) {
|
2020-12-23 16:10:24 -05:00
|
|
|
selected = getSelected().find((u) => user.id === u);
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
const { fieldName } = this;
|
|
|
|
const field = $dropdown
|
|
|
|
.closest('.selectbox')
|
|
|
|
.find(`input[name='${fieldName}'][value='${user.id}']`);
|
2017-05-17 11:26:52 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
if (field.length) {
|
|
|
|
selected = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
selected = user.id === selectedId;
|
|
|
|
}
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2019-12-18 01:08:03 -05:00
|
|
|
let img = '';
|
|
|
|
if (user.beforeDivider != null) {
|
2020-04-21 14:09:31 -04:00
|
|
|
`<li><a href='#' class='${selected === true ? 'is-active' : ''}'>${escape(
|
2019-12-18 01:08:03 -05:00
|
|
|
user.name,
|
|
|
|
)}</a></li>`;
|
|
|
|
} else {
|
|
|
|
// 0 margin, because it's now handled by a wrapper
|
2022-06-27 23:09:38 -04:00
|
|
|
img = `<img src='${avatar}' class='avatar avatar-inline gl-m-0!' width='32' />`;
|
2019-12-18 01:08:03 -05:00
|
|
|
}
|
2017-05-04 08:11:15 -04:00
|
|
|
|
2020-12-16 16:09:57 -05:00
|
|
|
return userSelect.renderRow(
|
|
|
|
options.issuableType,
|
|
|
|
user,
|
|
|
|
selected,
|
|
|
|
username,
|
|
|
|
img,
|
|
|
|
elsClassName,
|
|
|
|
);
|
2019-12-18 01:08:03 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2020-09-15 11:10:08 -04:00
|
|
|
|
|
|
|
if ($('.ajax-users-select').length) {
|
|
|
|
import(/* webpackChunkName: 'select2' */ 'select2/select2')
|
|
|
|
.then(() => {
|
2020-11-18 04:09:02 -05:00
|
|
|
// eslint-disable-next-line promise/no-nesting
|
|
|
|
loadCSSFile(gon.select2_css_path)
|
|
|
|
.then(() => {
|
|
|
|
$('.ajax-users-select').each((i, select) => {
|
|
|
|
const options = getAjaxUsersSelectOptions($(select), AJAX_USERS_SELECT_OPTIONS_MAP);
|
|
|
|
options.skipLdap = $(select).hasClass('skip_ldap');
|
|
|
|
const showNullUser = $(select).data('nullUser');
|
|
|
|
const showAnyUser = $(select).data('anyUser');
|
|
|
|
const showEmailUser = $(select).data('emailUser');
|
|
|
|
const firstUser = $(select).data('firstUser');
|
|
|
|
return $(select).select2({
|
|
|
|
placeholder: __('Search for a user'),
|
|
|
|
multiple: $(select).hasClass('multiselect'),
|
|
|
|
minimumInputLength: 0,
|
|
|
|
query(query) {
|
2020-12-23 16:10:24 -05:00
|
|
|
return userSelect.users(query.term, options, (users) => {
|
2020-11-18 04:09:02 -05:00
|
|
|
let name;
|
|
|
|
const data = {
|
|
|
|
results: users,
|
|
|
|
};
|
|
|
|
if (query.term.length === 0) {
|
|
|
|
if (firstUser) {
|
|
|
|
// Move current user to the front of the list
|
|
|
|
const ref = data.results;
|
|
|
|
|
|
|
|
for (let index = 0, len = ref.length; index < len; index += 1) {
|
|
|
|
const obj = ref[index];
|
|
|
|
if (obj.username === firstUser) {
|
|
|
|
data.results.splice(index, 1);
|
|
|
|
data.results.unshift(obj);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (showNullUser) {
|
|
|
|
const nullUser = {
|
|
|
|
name: s__('UsersSelect|Unassigned'),
|
|
|
|
id: 0,
|
|
|
|
};
|
|
|
|
data.results.unshift(nullUser);
|
|
|
|
}
|
|
|
|
if (showAnyUser) {
|
|
|
|
name = showAnyUser;
|
|
|
|
if (name === true) {
|
|
|
|
name = s__('UsersSelect|Any User');
|
|
|
|
}
|
|
|
|
const anyUser = {
|
|
|
|
name,
|
|
|
|
id: null,
|
|
|
|
};
|
|
|
|
data.results.unshift(anyUser);
|
2020-09-15 11:10:08 -04:00
|
|
|
}
|
2018-10-10 03:13:34 -04:00
|
|
|
}
|
2020-11-18 04:09:02 -05:00
|
|
|
if (
|
|
|
|
showEmailUser &&
|
|
|
|
data.results.length === 0 &&
|
|
|
|
query.term.match(/^[^@]+@[^@]+$/)
|
|
|
|
) {
|
|
|
|
const trimmed = query.term.trim();
|
|
|
|
const emailUser = {
|
|
|
|
name: sprintf(__('Invite "%{trimmed}" by email'), { trimmed }),
|
|
|
|
username: trimmed,
|
|
|
|
id: trimmed,
|
|
|
|
invite: true,
|
|
|
|
};
|
|
|
|
data.results.unshift(emailUser);
|
2020-09-15 11:10:08 -04:00
|
|
|
}
|
2020-11-18 04:09:02 -05:00
|
|
|
return query.callback(data);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
initSelection() {
|
|
|
|
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
|
|
|
|
return userSelect.initSelection.apply(userSelect, args);
|
|
|
|
},
|
|
|
|
formatResult() {
|
|
|
|
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
|
|
|
|
return userSelect.formatResult.apply(userSelect, args);
|
|
|
|
},
|
|
|
|
formatSelection() {
|
|
|
|
const args = 1 <= arguments.length ? [].slice.call(arguments, 0) : [];
|
|
|
|
return userSelect.formatSelection.apply(userSelect, args);
|
|
|
|
},
|
|
|
|
dropdownCssClass: 'ajax-users-dropdown',
|
|
|
|
// we do not want to escape markup since we are displaying html in results
|
|
|
|
escapeMarkup(m) {
|
|
|
|
return m;
|
|
|
|
},
|
2020-09-15 11:10:08 -04:00
|
|
|
});
|
2020-11-18 04:09:02 -05:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
2020-09-15 11:10:08 -04:00
|
|
|
})
|
|
|
|
.catch(() => {});
|
|
|
|
}
|
2017-05-12 04:15:28 -04:00
|
|
|
}
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
UsersSelect.prototype.initSelection = function (element, callback) {
|
2019-11-22 13:06:00 -05:00
|
|
|
const id = $(element).val();
|
2018-10-10 03:13:34 -04:00
|
|
|
if (id === '0') {
|
2019-11-22 13:06:00 -05:00
|
|
|
const nullUser = {
|
2019-05-07 08:00:52 -04:00
|
|
|
name: s__('UsersSelect|Unassigned'),
|
2016-07-24 16:45:11 -04:00
|
|
|
};
|
2017-05-12 04:15:28 -04:00
|
|
|
return callback(nullUser);
|
2018-10-10 03:13:34 -04:00
|
|
|
} else if (id !== '') {
|
2017-05-12 04:15:28 -04:00
|
|
|
return this.user(id, callback);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
UsersSelect.prototype.formatResult = function (user) {
|
2019-11-22 13:06:00 -05:00
|
|
|
let avatar = gon.default_avatar_url;
|
2017-05-12 04:15:28 -04:00
|
|
|
if (user.avatar_url) {
|
|
|
|
avatar = user.avatar_url;
|
|
|
|
}
|
2018-11-06 01:57:21 -05:00
|
|
|
return `
|
|
|
|
<div class='user-result'>
|
|
|
|
<div class='user-image'>
|
|
|
|
<img class='avatar avatar-inline s32' src='${avatar}'>
|
|
|
|
</div>
|
|
|
|
<div class='user-info'>
|
|
|
|
<div class='user-name dropdown-menu-user-full-name'>
|
2020-04-21 14:09:31 -04:00
|
|
|
${escape(user.name)}
|
2018-11-06 01:57:21 -05:00
|
|
|
</div>
|
|
|
|
<div class='user-username dropdown-menu-user-username text-secondary'>
|
2020-04-21 14:09:31 -04:00
|
|
|
${!user.invite ? `@${escape(user.username)}` : ''}
|
2018-11-06 01:57:21 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`;
|
2017-05-12 04:15:28 -04:00
|
|
|
};
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
UsersSelect.prototype.formatSelection = function (user) {
|
2020-04-21 14:09:31 -04:00
|
|
|
return escape(user.name);
|
2017-05-12 04:15:28 -04:00
|
|
|
};
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
UsersSelect.prototype.user = function (user_id, callback) {
|
2017-05-12 04:15:28 -04:00
|
|
|
if (!/^\d+$/.test(user_id)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-22 13:06:00 -05:00
|
|
|
let url = this.buildUrl(this.userPath);
|
2017-05-12 04:15:28 -04:00
|
|
|
url = url.replace(':id', user_id);
|
2018-10-10 03:13:34 -04:00
|
|
|
return axios.get(url).then(({ data }) => {
|
|
|
|
callback(data);
|
|
|
|
});
|
2017-05-12 04:15:28 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// Return users list. Filtered by query
|
|
|
|
// Only active users retrieved
|
2020-12-23 07:10:26 -05:00
|
|
|
UsersSelect.prototype.users = function (query, options, callback) {
|
2018-02-02 08:17:23 -05:00
|
|
|
const url = this.buildUrl(this.usersPath);
|
|
|
|
const params = {
|
|
|
|
search: query,
|
|
|
|
active: true,
|
2020-05-04 14:10:20 -04:00
|
|
|
...getAjaxUsersSelectParams(options, AJAX_USERS_SELECT_PARAMS_MAP),
|
2018-02-02 08:17:23 -05:00
|
|
|
};
|
2019-07-25 22:30:50 -04:00
|
|
|
|
2020-12-16 16:09:57 -05:00
|
|
|
const isMergeRequest = options.issuableType === 'merge_request';
|
2020-12-23 07:10:26 -05:00
|
|
|
const isEditMergeRequest = !options.issuableType && options.iid && options.targetBranch;
|
|
|
|
const isNewMergeRequest = !options.issuableType && !options.iid && options.targetBranch;
|
2020-12-16 16:09:57 -05:00
|
|
|
|
|
|
|
if (isMergeRequest || isEditMergeRequest || isNewMergeRequest) {
|
2019-07-25 22:30:50 -04:00
|
|
|
params.merge_request_iid = options.iid || null;
|
2020-12-16 16:09:57 -05:00
|
|
|
params.approval_rules = true;
|
|
|
|
}
|
|
|
|
|
2022-09-23 14:12:59 -04:00
|
|
|
if (isMergeRequest && options.showSuggested) {
|
|
|
|
params.show_suggested = true;
|
|
|
|
}
|
|
|
|
|
2020-12-16 16:09:57 -05:00
|
|
|
if (isNewMergeRequest) {
|
|
|
|
params.target_branch = options.targetBranch || null;
|
2019-07-25 22:30:50 -04:00
|
|
|
}
|
|
|
|
|
2018-10-10 03:13:34 -04:00
|
|
|
return axios.get(url, { params }).then(({ data }) => {
|
|
|
|
callback(data);
|
|
|
|
});
|
2017-05-12 04:15:28 -04:00
|
|
|
};
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
UsersSelect.prototype.buildUrl = function (url) {
|
2017-05-12 04:15:28 -04:00
|
|
|
if (gon.relative_url_root != null) {
|
|
|
|
url = gon.relative_url_root.replace(/\/$/, '') + url;
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
};
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
UsersSelect.prototype.renderRow = function (
|
2020-12-16 16:09:57 -05:00
|
|
|
issuableType,
|
|
|
|
user,
|
|
|
|
selected,
|
|
|
|
username,
|
|
|
|
img,
|
|
|
|
elsClassName,
|
|
|
|
) {
|
2019-07-25 22:30:50 -04:00
|
|
|
const tooltip = issuableType === 'merge_request' && !user.can_merge ? __('Cannot merge') : '';
|
|
|
|
const tooltipClass = tooltip ? `has-tooltip` : '';
|
|
|
|
const selectedClass = selected === true ? 'is-active' : '';
|
|
|
|
const linkClasses = `${selectedClass} ${tooltipClass}`;
|
|
|
|
const tooltipAttributes = tooltip
|
|
|
|
? `data-container="body" data-placement="left" data-title="${tooltip}"`
|
|
|
|
: '';
|
|
|
|
|
2021-02-17 04:09:36 -05:00
|
|
|
const name =
|
|
|
|
user?.availability && isUserBusy(user.availability)
|
|
|
|
? sprintf(__('%{name} (Busy)'), { name: user.name })
|
|
|
|
: user.name;
|
2019-07-25 22:30:50 -04:00
|
|
|
return `
|
|
|
|
<li data-user-id=${user.id}>
|
2022-06-27 23:09:38 -04:00
|
|
|
<a href="#" class="dropdown-menu-user-link gl-display-flex! gl-align-items-center ${linkClasses}" ${tooltipAttributes}>
|
2019-07-25 22:30:50 -04:00
|
|
|
${this.renderRowAvatar(issuableType, user, img)}
|
2022-06-27 23:09:38 -04:00
|
|
|
<span class="gl-display-flex gl-flex-direction-column gl-overflow-hidden">
|
2020-12-16 16:09:57 -05:00
|
|
|
<strong class="dropdown-menu-user-full-name gl-font-weight-bold">
|
2021-02-17 04:09:36 -05:00
|
|
|
${escape(name)}
|
2019-07-25 22:30:50 -04:00
|
|
|
</strong>
|
2020-12-16 16:09:57 -05:00
|
|
|
${
|
|
|
|
username
|
2022-03-16 08:07:24 -04:00
|
|
|
? `<span class="dropdown-menu-user-username gl-text-gray-400">${escape(
|
|
|
|
username,
|
|
|
|
)}</span>`
|
2020-12-16 16:09:57 -05:00
|
|
|
: ''
|
|
|
|
}
|
|
|
|
${this.renderApprovalRules(elsClassName, user.applicable_approval_rules)}
|
2019-07-25 22:30:50 -04:00
|
|
|
</span>
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
`;
|
|
|
|
};
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
UsersSelect.prototype.renderRowAvatar = function (issuableType, user, img) {
|
2019-07-25 22:30:50 -04:00
|
|
|
if (user.beforeDivider) {
|
|
|
|
return img;
|
|
|
|
}
|
|
|
|
|
|
|
|
const mergeIcon =
|
|
|
|
issuableType === 'merge_request' && !user.can_merge
|
2020-12-02 04:09:50 -05:00
|
|
|
? spriteIcon('warning-solid', 's12 merge-icon')
|
2019-07-25 22:30:50 -04:00
|
|
|
: '';
|
|
|
|
|
2022-06-27 23:09:38 -04:00
|
|
|
return `<span class="gl-relative gl-mr-3">
|
2019-07-25 22:30:50 -04:00
|
|
|
${img}
|
|
|
|
${mergeIcon}
|
|
|
|
</span>`;
|
|
|
|
};
|
|
|
|
|
2020-12-23 07:10:26 -05:00
|
|
|
UsersSelect.prototype.renderApprovalRules = function (elsClassName, approvalRules = []) {
|
2020-12-17 07:09:57 -05:00
|
|
|
const count = approvalRules.length;
|
|
|
|
|
2021-02-05 19:09:54 -05:00
|
|
|
if (!elsClassName?.includes('reviewer') || !count) {
|
2020-12-16 16:09:57 -05:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
const [rule] = approvalRules;
|
|
|
|
const countText = sprintf(__('(+%{count} rules)'), { count });
|
2022-06-27 23:09:38 -04:00
|
|
|
const renderApprovalRulesCount = count > 1 ? `<span class="gl-ml-2">${countText}</span>` : '';
|
2021-09-30 14:11:31 -04:00
|
|
|
const ruleName = rule.rule_type === 'code_owner' ? __('Code Owner') : escape(rule.name);
|
2020-12-16 16:09:57 -05:00
|
|
|
|
2020-12-17 07:09:57 -05:00
|
|
|
return `<div class="gl-display-flex gl-font-sm">
|
|
|
|
<span class="gl-text-truncate" title="${ruleName}">${ruleName}</span>
|
|
|
|
${renderApprovalRulesCount}
|
|
|
|
</div>`;
|
2020-12-16 16:09:57 -05:00
|
|
|
};
|
|
|
|
|
2017-05-12 04:15:28 -04:00
|
|
|
export default UsersSelect;
|