Commit 55dd0d72 authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett

Dont show toggle if only one action is available and do not show report as...

Dont show toggle if only one action is available and do not show report as abuse for current_user's issuables
parent b8deafd0
......@@ -31,6 +31,11 @@ class Issue {
this.initCloseReopenReport();
if (!this.closeReopenReportToggle) {
this.closeButtons = $('a.btn-close');
this.reopenButtons = $('a.btn-reopen');
}
if (Issue.createMrDropdownWrap) {
this.createMergeRequestDropdown = new CreateMergeRequestDropdown(Issue.createMrDropdownWrap);
}
......@@ -52,7 +57,7 @@ class Issue {
Issue.submitNoteForm($button.closest('form'));
}
this.closeReopenReportToggle.setDisable(true);
this.disableCloseReopenButton($button, true);
url = $button.attr('href');
return $.ajax({
......@@ -68,7 +73,7 @@ class Issue {
isClosedBadge.toggleClass('hidden', !isClosed);
isOpenBadge.toggleClass('hidden', isClosed);
this.closeReopenReportToggle.updateButton(isClosed);
this.toggleCloseReopenButton(isClosed);
let numProjectIssues = Number(projectIssuesCounter.text().replace(/[^\d]/, ''));
numProjectIssues = isClosed ? numProjectIssues - 1 : numProjectIssues + 1;
......@@ -87,13 +92,16 @@ class Issue {
new Flash(issueFailMessage);
}
this.closeReopenReportToggle.setDisable(false);
this.disableCloseReopenButton($button, false);
});
});
}
initCloseReopenReport() {
const container = document.querySelector('.js-issuable-close-dropdown');
if (!container) return;
const dropdownTrigger = container.querySelector('.js-issuable-close-toggle');
const dropdownList = container.querySelector('.js-issuable-close-menu');
const button = container.querySelector('.js-issuable-close-button');
......@@ -107,6 +115,23 @@ class Issue {
this.closeReopenReportToggle.initDroplab();
}
disableCloseReopenButton($button, shouldDisable) {
if (this.closeReopenReportToggle) {
this.closeReopenReportToggle.setDisable(shouldDisable);
} else {
$button.prop('disabled', shouldDisable);
}
}
toggleCloseReopenButton(isClosed) {
if (this.closeReopenReportToggle) {
this.closeReopenReportToggle.updateButton(isClosed);
} else {
this.closeButtons.toggleClass('hidden', isClosed);
this.reopenButtons.toggleClass('hidden', !isClosed);
}
}
static submitNoteForm(form) {
var noteText;
noteText = form.find("textarea.js-note-text").val();
......
......@@ -22,10 +22,12 @@ import CloseReopenReportToggle from './close_reopen_report_toggle';
return _this.showAllCommits();
};
})(this));
this.initTabs();
this.initMRBtnListeners();
this.initCommitMessageListeners();
MergeRequest.initCloseReopenReport();
this.initCloseReopenReport();
if ($("a.btn-close").length) {
this.taskList = new gl.TaskList({
dataType: 'merge_request',
......@@ -66,11 +68,15 @@ import CloseReopenReportToggle from './close_reopen_report_toggle';
if (shouldSubmit && $this.data('submitted')) {
return;
}
_this.disableCloseReopenButton($this, true);
if (shouldSubmit) {
if ($this.hasClass('btn-comment-and-close') || $this.hasClass('btn-comment-and-reopen')) {
e.preventDefault();
e.stopImmediatePropagation();
return _this.submitNoteForm($this.closest('form'), $this);
_this.submitNoteForm($this.closest('form'), $this);
}
}
});
......@@ -121,7 +127,7 @@ import CloseReopenReportToggle from './close_reopen_report_toggle';
$el.text(gl.text.addDelimiter(count));
};
MergeRequest.initCloseReopenReport = function () {
MergeRequest.prototype.initCloseReopenReport = function () {
const container = document.querySelector('.js-issuable-close-dropdown');
if (!container) return;
......@@ -130,13 +136,21 @@ import CloseReopenReportToggle from './close_reopen_report_toggle';
const dropdownList = container.querySelector('.js-issuable-close-menu');
const button = container.querySelector('.js-issuable-close-button');
const closeReopenReportToggle = new CloseReopenReportToggle({
this.closeReopenReportToggle = new CloseReopenReportToggle({
dropdownTrigger,
dropdownList,
button,
});
closeReopenReportToggle.initDroplab();
this.closeReopenReportToggle.initDroplab();
};
MergeRequest.prototype.disableCloseReopenButton = function ($button, shouldDisable) {
if (this.closeReopenReportToggle) {
this.closeReopenReportToggle.setDisable(shouldDisable);
} else {
$button.prop('disabled', shouldDisable);
}
};
return MergeRequest;
......
......@@ -83,6 +83,7 @@
flex: 1;
-webkit-flex: 1;
max-width: inherit;
padding: 0;
}
}
......
......@@ -261,8 +261,11 @@ module IssuablesHelper
issuable_url(issuable, params)
end
def close_reopen_issuable_url(issuable)
issuable.closed? ? reopen_issuable_url(issuable) : close_issuable_url(issuable)
def close_reopen_issuable_url(issuable, should_inverse = false)
is_closed = issuable.closed?
is_closed = !is_closed if should_inverse
is_closed ? reopen_issuable_url(issuable) : close_issuable_url(issuable)
end
def issuable_url(issuable, *options)
......
......@@ -31,7 +31,8 @@
%ul
- if can_update_issue
%li= link_to 'Edit', edit_project_issue_path(@project, @issue)
%li= link_to 'Report abuse', new_abuse_report_path(user_id: @issue.author.id, ref_url: issue_url(@issue))
- unless current_user == @issue.author
%li= link_to 'Report abuse', new_abuse_report_path(user_id: @issue.author.id, ref_url: issue_url(@issue))
- if can_update_issue
%li= link_to 'Close issue', issue_path(@issue, issue: { state_event: :close }, format: 'json'), class: "btn-close #{issue_button_visibility(@issue, true)}", title: 'Close issue'
%li= link_to 'Reopen issue', issue_path(@issue, issue: { state_event: :reopen }, format: 'json'), class: "btn-reopen #{issue_button_visibility(@issue, false)}", title: 'Reopen issue'
......
......@@ -26,7 +26,8 @@
%ul
- if can_update_merge_request
%li= link_to 'Edit', edit_namespace_project_merge_request_path(@project.namespace, @project, @merge_request), class: 'issuable-edit'
%li= link_to 'Report abuse', new_abuse_report_path(user_id: @merge_request.author.id, ref_url: merge_request_url(@merge_request))
- unless current_user == @merge_request.author
%li= link_to 'Report abuse', new_abuse_report_path(user_id: @merge_request.author.id, ref_url: merge_request_url(@merge_request))
- if can_update_merge_request
%li{ class: merge_request_button_visibility(@merge_request, true) }
= link_to 'Close', merge_request_path(@merge_request, merge_request: { state_event: :close }), method: :put, title: 'Close merge request'
......
- if can_update
- is_current_user = current_user == issuable.author
- display_issuable_type = issuable.model_name.human.downcase
- button_method = issuable.is_a?(MergeRequest) ? 'put' : ''
- if can_update && is_current_user
= link_to "Close #{display_issuable_type}", close_issuable_url(issuable), { method: button_method, class: "hidden-xs hidden-sm btn btn-close btn-grouped #{'hidden' if issuable.closed?}", title: "Close #{display_issuable_type}" }
= link_to "Reopen #{display_issuable_type}", reopen_issuable_url(issuable), { method: button_method, class: "hidden-xs hidden-sm btn btn-reopen btn-grouped #{'hidden' unless issuable.closed?}", title: "Reopen #{display_issuable_type}" }
- elsif can_update && !is_current_user
= render 'shared/issuable/close_reopen_report_toggle', issuable: issuable
- else
= link_to 'Report abuse', new_abuse_report_path(user_id: issuable.author.id, ref_url: issuable_url(issuable)), class: 'hidden-xs hidden-sm btn btn-grouped btn-close-color', title: 'Report abuse'
......@@ -7,7 +7,7 @@
- button_method = issuable.is_a?(MergeRequest) ? 'put' : ''
.pull-left.btn-group.prepend-left-10.issuable-close-dropdown.droplab-dropdown.js-issuable-close-dropdown
= link_to "#{display_button_action} #{display_issuable_type}", close_reopen_issuable_url(issuable), { method: button_method.to_s, class: "#{button_class} btn-#{button_action}", title: "#{display_button_action} #{display_issuable_type}" }
= link_to "#{display_button_action} #{display_issuable_type}", close_reopen_issuable_url(issuable), { method: button_method, class: "#{button_class} btn-#{button_action}", title: "#{display_button_action} #{display_issuable_type}" }
= button_tag type: 'button', class: "#{toggle_class} btn-#{button_action}-color", data: { 'dropdown-trigger' => '#issuable-close-menu' }, 'aria-label' => 'Toggle dropdown' do
= icon('caret-down', class: 'toggle-icon icon')
......@@ -31,14 +31,14 @@
= display_issuable_type
%p
%li.divider.droplab-item-ignore
%li.divider.droplab-item-ignore
%li.report-item{ data: { text: 'Report abuse', url: new_abuse_report_path(user_id: issuable.author.id, ref_url: issuable_url(issuable)), button_class: "#{button_class} btn-close-color", toggle_class: "#{toggle_class} btn-close-color", method: '' } }
%button.btn.btn-transparent
= icon('check', class: 'icon')
.description
%strong Report abuse
%p
Report
= display_issuable_type.pluralize
that are abusive, inappropriate or spam.
%li.report-item{ data: { text: 'Report abuse', url: new_abuse_report_path(user_id: issuable.author.id, ref_url: issuable_url(issuable)), button_class: "#{button_class} btn-close-color", toggle_class: "#{toggle_class} btn-close-color", method: '' } }
%button.btn.btn-transparent
= icon('check', class: 'icon')
.description
%strong Report abuse
%p
Report
= display_issuable_type.pluralize
that are abusive, inappropriate or spam.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment