summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-11-15 21:11:13 -0200
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2016-11-15 21:39:38 -0200
commit96670914f8ebb63d9db2ca95b1a9b31213460d3d (patch)
tree04bdc5a754ec765002513e1d68a4160bfb40c281
parent2544e7b7892ccb5abc259c56c08db95c2344cc5f (diff)
downloadgitlab-ce-96670914f8ebb63d9db2ca95b1a9b31213460d3d.tar.gz
Avoid code duplication for label subscription status on label partial
-rw-r--r--app/assets/javascripts/project_label_subscription.js.es68
-rw-r--r--app/helpers/labels_helper.rb8
-rw-r--r--app/views/shared/_label.html.haml8
3 files changed, 9 insertions, 15 deletions
diff --git a/app/assets/javascripts/project_label_subscription.js.es6 b/app/assets/javascripts/project_label_subscription.js.es6
index fd5146e2f12..03a115cb35b 100644
--- a/app/assets/javascripts/project_label_subscription.js.es6
+++ b/app/assets/javascripts/project_label_subscription.js.es6
@@ -14,7 +14,7 @@
const $btn = $(event.currentTarget);
const $span = $btn.find('span');
const url = $btn.attr('data-url');
- const status = $btn.attr('data-status');
+ const oldStatus = $btn.attr('data-status');
$btn.addClass('disabled');
$span.toggleClass('hidden');
@@ -25,10 +25,10 @@
}).done(() => {
let newStatus, newAction;
- if (status === 'subscribed') {
- [newStatus, newAction] = ['unsubscribed', 'Subscribe'];
- } else {
+ if (oldStatus === 'unsubscribed') {
[newStatus, newAction] = ['subscribed', 'Unsubscribe'];
+ } else {
+ [newStatus, newAction] = ['unsubscribed', 'Subscribe'];
}
$span.toggleClass('hidden');
diff --git a/app/helpers/labels_helper.rb b/app/helpers/labels_helper.rb
index 7495414f525..4f180456b16 100644
--- a/app/helpers/labels_helper.rb
+++ b/app/helpers/labels_helper.rb
@@ -140,7 +140,7 @@ module LabelsHelper
end
end
- def group_label_subscription_status(label, project)
+ def label_subscription_status(label, project)
return 'project-level' if label.subscribed?(current_user, project)
return 'group-level' if label.subscribed?(current_user)
@@ -148,16 +148,12 @@ module LabelsHelper
end
def group_label_unsubscribe_path(label, project)
- case group_label_subscription_status(label, project)
+ case label_subscription_status(label, project)
when 'project-level' then toggle_subscription_namespace_project_label_path(@project.namespace, @project, label)
when 'group-level' then toggle_subscription_group_label_path(label.group, label)
end
end
- def label_subscription_status(label, project)
- label.subscribed?(current_user, project) ? 'subscribed' : 'unsubscribed'
- end
-
def label_subscription_toggle_button_text(label, project)
label.subscribed?(current_user, project) ? 'Unsubscribe' : 'Subscribe'
end
diff --git a/app/views/shared/_label.html.haml b/app/views/shared/_label.html.haml
index e2495b00f52..db324d8868e 100644
--- a/app/views/shared/_label.html.haml
+++ b/app/views/shared/_label.html.haml
@@ -1,6 +1,7 @@
- label_css_id = dom_id(label)
- open_issues_count = label.open_issues_count(current_user)
- open_merge_requests_count = label.open_merge_requests_count(current_user)
+- status = label_subscription_status(label, @project).inquiry if current_user
- subject = local_assigns[:subject]
%li{id: label_css_id, data: { id: label.id } }
@@ -21,10 +22,9 @@
- if current_user && defined?(@project)
%li.label-subscription
- if label.is_a?(ProjectLabel)
- %a.js-subscribe-button.label-subscribe-button{ role: 'button', href: '#', data: { status: label_subscription_status(label, @project), url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label) } }
+ %a.js-subscribe-button.label-subscribe-button{ role: 'button', href: '#', data: { status: status, url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label) } }
%span= label_subscription_toggle_button_text(label, @project)
- else
- - status = group_label_subscription_status(label, @project).inquiry
%a.js-unsubscribe-button.label-subscribe-button{ role: 'button', href: '#', class: ('hidden' if status.unsubscribed?), data: { url: group_label_unsubscribe_path(label, @project) } }
%span Unsubscribe
%a.js-subscribe-button.label-subscribe-button{ role: 'button', href: '#', class: ('hidden' unless status.unsubscribed?), data: { url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label) } }
@@ -47,12 +47,10 @@
- if current_user && defined?(@project)
.label-subscription.inline
- if label.is_a?(ProjectLabel)
- %button.js-subscribe-button.label-subscribe-button.btn.btn-default.btn-action{ type: 'button', title: label_subscription_toggle_button_text(label, @project), data: { toggle: 'tooltip', status: label_subscription_status(label, @project), url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label) } }
+ %button.js-subscribe-button.label-subscribe-button.btn.btn-default.btn-action{ type: 'button', title: label_subscription_toggle_button_text(label, @project), data: { toggle: 'tooltip', status: status, url: toggle_subscription_namespace_project_label_path(@project.namespace, @project, label) } }
%span= label_subscription_toggle_button_text(label, @project)
= icon('spinner spin', class: 'label-subscribe-button-loading')
- else
- - status = group_label_subscription_status(label, @project).inquiry
-
%button.js-unsubscribe-button.label-subscribe-button.btn.btn-default.btn-action{ type: 'button', class: ('hidden' if status.unsubscribed?), title: 'Unsubscribe', data: { toggle: 'tooltip', url: group_label_unsubscribe_path(label, @project) } }
%span Unsubscribe
= icon('spinner spin', class: 'label-subscribe-button-loading')