2017-05-15 18:12:43 -04:00
|
|
|
/* eslint-disable class-methods-use-this, no-new */
|
|
|
|
|
2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2020-04-21 11:21:10 -04:00
|
|
|
import { property } from 'lodash';
|
2017-05-15 18:12:43 -04:00
|
|
|
import IssuableBulkUpdateActions from './issuable_bulk_update_actions';
|
2017-10-30 14:59:16 -04:00
|
|
|
import issueStatusSelect from './issue_status_select';
|
2020-09-16 08:10:15 -04:00
|
|
|
import issueableEventHub from './issues_list/eventhub';
|
2021-02-14 13:09:20 -05:00
|
|
|
import LabelsSelect from './labels_select';
|
|
|
|
import MilestoneSelect from './milestone_select';
|
|
|
|
import subscriptionSelect from './subscription_select';
|
2017-05-15 18:12:43 -04:00
|
|
|
|
|
|
|
const HIDDEN_CLASS = 'hidden';
|
|
|
|
const DISABLED_CONTENT_CLASS = 'disabled-content';
|
|
|
|
const SIDEBAR_EXPANDED_CLASS = 'right-sidebar-expanded issuable-bulk-update-sidebar';
|
|
|
|
const SIDEBAR_COLLAPSED_CLASS = 'right-sidebar-collapsed issuable-bulk-update-sidebar';
|
|
|
|
|
|
|
|
export default class IssuableBulkUpdateSidebar {
|
|
|
|
constructor() {
|
2019-11-06 16:06:44 -05:00
|
|
|
this.vueIssuablesListFeature = property(['gon', 'features', 'vueIssuablesList'])(window);
|
|
|
|
|
2017-05-15 18:12:43 -04:00
|
|
|
this.initDomElements();
|
|
|
|
this.bindEvents();
|
|
|
|
this.initDropdowns();
|
|
|
|
this.setupBulkUpdateActions();
|
|
|
|
}
|
|
|
|
|
|
|
|
initDomElements() {
|
2017-12-08 16:19:01 -05:00
|
|
|
this.$page = $('.layout-page');
|
2017-05-15 18:12:43 -04:00
|
|
|
this.$sidebar = $('.right-sidebar');
|
2017-06-21 03:33:39 -04:00
|
|
|
this.$sidebarInnerContainer = this.$sidebar.find('.issuable-sidebar');
|
2017-05-15 18:12:43 -04:00
|
|
|
this.$bulkEditCancelBtn = $('.js-bulk-update-menu-hide');
|
|
|
|
this.$bulkEditSubmitBtn = $('.update-selected-issues');
|
|
|
|
this.$bulkUpdateEnableBtn = $('.js-bulk-update-toggle');
|
|
|
|
this.$otherFilters = $('.issues-other-filters');
|
|
|
|
this.$checkAllContainer = $('.check-all-holder');
|
|
|
|
this.$issueChecks = $('.issue-check');
|
2021-03-25 08:09:19 -04:00
|
|
|
this.$issuesList = $('.issuable-list input[type="checkbox"]');
|
2017-05-15 18:12:43 -04:00
|
|
|
this.$issuableIdsInput = $('#update_issuable_ids');
|
|
|
|
}
|
|
|
|
|
|
|
|
bindEvents() {
|
2020-12-23 19:10:25 -05:00
|
|
|
this.$bulkUpdateEnableBtn.on('click', (e) => this.toggleBulkEdit(e, true));
|
|
|
|
this.$bulkEditCancelBtn.on('click', (e) => this.toggleBulkEdit(e, false));
|
|
|
|
this.$checkAllContainer.on('click', (e) => this.selectAll(e));
|
2017-05-15 18:12:43 -04:00
|
|
|
this.$issuesList.on('change', () => this.updateFormState());
|
|
|
|
this.$bulkEditSubmitBtn.on('click', () => this.prepForSubmit());
|
|
|
|
this.$checkAllContainer.on('click', () => this.updateFormState());
|
2019-11-06 16:06:44 -05:00
|
|
|
|
2021-04-01 14:13:56 -04:00
|
|
|
// The event hub connects this bulk update logic with `issues_list_app.vue`.
|
|
|
|
// We can remove it once we've refactored the issues list page bulk edit sidebar to Vue.
|
|
|
|
// https://gitlab.com/gitlab-org/gitlab/-/issues/325874
|
|
|
|
issueableEventHub.$on('issuables:enableBulkEdit', () => this.toggleBulkEdit(null, true));
|
|
|
|
issueableEventHub.$on('issuables:updateBulkEdit', () => this.updateFormState());
|
2017-05-15 18:12:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
initDropdowns() {
|
|
|
|
new LabelsSelect();
|
|
|
|
new MilestoneSelect();
|
2017-10-30 14:59:16 -04:00
|
|
|
issueStatusSelect();
|
2017-11-20 15:28:29 -05:00
|
|
|
subscriptionSelect();
|
2020-07-06 05:09:20 -04:00
|
|
|
|
2020-07-06 11:08:42 -04:00
|
|
|
if (IS_EE) {
|
|
|
|
import('ee/vue_shared/components/sidebar/health_status_select/health_status_bundle')
|
|
|
|
.then(({ default: HealthStatusSelect }) => {
|
|
|
|
HealthStatusSelect();
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
2020-07-06 05:09:20 -04:00
|
|
|
}
|
2020-07-07 08:09:16 -04:00
|
|
|
|
|
|
|
if (IS_EE) {
|
|
|
|
import('ee/vue_shared/components/sidebar/epics_select/epics_select_bundle')
|
|
|
|
.then(({ default: EpicSelect }) => {
|
|
|
|
EpicSelect();
|
|
|
|
})
|
|
|
|
.catch(() => {});
|
|
|
|
}
|
2021-01-31 16:09:10 -05:00
|
|
|
|
|
|
|
if (IS_EE) {
|
|
|
|
import('ee/vue_shared/components/sidebar/iterations_dropdown_bundle')
|
|
|
|
.then(({ default: iterationsDropdown }) => {
|
|
|
|
iterationsDropdown();
|
|
|
|
})
|
|
|
|
.catch((e) => {
|
|
|
|
throw e;
|
|
|
|
});
|
|
|
|
}
|
2017-05-15 18:12:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
setupBulkUpdateActions() {
|
|
|
|
IssuableBulkUpdateActions.setOriginalDropdownData();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateFormState() {
|
2021-03-25 08:09:19 -04:00
|
|
|
const noCheckedIssues = !$('.issuable-list input[type="checkbox"]:checked').length;
|
2017-05-15 18:12:43 -04:00
|
|
|
|
|
|
|
this.toggleSubmitButtonDisabled(noCheckedIssues);
|
|
|
|
this.updateSelectedIssuableIds();
|
|
|
|
|
|
|
|
IssuableBulkUpdateActions.setOriginalDropdownData();
|
|
|
|
}
|
|
|
|
|
|
|
|
prepForSubmit() {
|
|
|
|
// if submit button is disabled, submission is blocked. This ensures we disable after
|
|
|
|
// form submission is carried out
|
|
|
|
setTimeout(() => this.$bulkEditSubmitBtn.disable());
|
|
|
|
this.updateSelectedIssuableIds();
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleBulkEdit(e, enable) {
|
2021-04-01 14:13:56 -04:00
|
|
|
e?.preventDefault();
|
2017-05-15 18:12:43 -04:00
|
|
|
|
2019-11-06 16:06:44 -05:00
|
|
|
issueableEventHub.$emit('issuables:toggleBulkEdit', enable);
|
|
|
|
|
2017-05-15 18:12:43 -04:00
|
|
|
this.toggleSidebarDisplay(enable);
|
|
|
|
this.toggleBulkEditButtonDisabled(enable);
|
|
|
|
this.toggleOtherFiltersDisabled(enable);
|
|
|
|
this.toggleCheckboxDisplay(enable);
|
2017-07-24 03:47:38 -04:00
|
|
|
}
|
|
|
|
|
2017-05-15 18:12:43 -04:00
|
|
|
updateSelectedIssuableIds() {
|
|
|
|
this.$issuableIdsInput.val(IssuableBulkUpdateSidebar.getCheckedIssueIds());
|
|
|
|
}
|
|
|
|
|
|
|
|
selectAll() {
|
|
|
|
const checkAllButtonState = this.$checkAllContainer.find('input').prop('checked');
|
|
|
|
|
|
|
|
this.$issuesList.prop('checked', checkAllButtonState);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleSidebarDisplay(show) {
|
|
|
|
this.$page.toggleClass(SIDEBAR_EXPANDED_CLASS, show);
|
|
|
|
this.$page.toggleClass(SIDEBAR_COLLAPSED_CLASS, !show);
|
2017-06-21 03:33:39 -04:00
|
|
|
this.$sidebarInnerContainer.toggleClass(HIDDEN_CLASS, !show);
|
2017-05-15 18:12:43 -04:00
|
|
|
this.$sidebar.toggleClass(SIDEBAR_EXPANDED_CLASS, show);
|
|
|
|
this.$sidebar.toggleClass(SIDEBAR_COLLAPSED_CLASS, !show);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleBulkEditButtonDisabled(disable) {
|
|
|
|
if (disable) {
|
|
|
|
this.$bulkUpdateEnableBtn.disable();
|
|
|
|
} else {
|
|
|
|
this.$bulkUpdateEnableBtn.enable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleCheckboxDisplay(show) {
|
2019-11-06 16:06:44 -05:00
|
|
|
this.$checkAllContainer.toggleClass(HIDDEN_CLASS, !show || this.vueIssuablesListFeature);
|
2017-05-15 18:12:43 -04:00
|
|
|
this.$issueChecks.toggleClass(HIDDEN_CLASS, !show);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleOtherFiltersDisabled(disable) {
|
|
|
|
this.$otherFilters.toggleClass(DISABLED_CONTENT_CLASS, disable);
|
|
|
|
}
|
|
|
|
|
|
|
|
toggleSubmitButtonDisabled(disable) {
|
|
|
|
if (disable) {
|
|
|
|
this.$bulkEditSubmitBtn.disable();
|
|
|
|
} else {
|
|
|
|
this.$bulkEditSubmitBtn.enable();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static getCheckedIssueIds() {
|
2021-03-25 08:09:19 -04:00
|
|
|
const $checkedIssues = $('.issuable-list input[type="checkbox"]:checked');
|
2017-05-15 18:12:43 -04:00
|
|
|
|
|
|
|
if ($checkedIssues.length > 0) {
|
2020-12-23 19:10:25 -05:00
|
|
|
return $.map($checkedIssues, (value) => $(value).data('id'));
|
2017-05-15 18:12:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|