BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
d533c0e7
Commit
d533c0e7
authored
Nov 15, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid code duplication for label subscription status on label partial
parent
e2865c23
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
9 additions
and
15 deletions
+9
-15
project_label_subscription.js.es6
app/assets/javascripts/project_label_subscription.js.es6
+4
-4
labels_helper.rb
app/helpers/labels_helper.rb
+2
-6
_label.html.haml
app/views/shared/_label.html.haml
+3
-5
No files found.
app/assets/javascripts/project_label_subscription.js.es6
View file @
d533c0e7
...
...
@@ -14,7 +14,7 @@
const $btn = $(event.currentTarget);
const $span = $btn.find('span');
const url = $btn.attr('data-url');
const
s
tatus = $btn.attr('data-status');
const
oldS
tatus = $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');
...
...
app/helpers/labels_helper.rb
View file @
d533c0e7
...
...
@@ -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
...
...
app/views/shared/_label.html.haml
View file @
d533c0e7
-
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'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment