Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
330e9136
Commit
330e9136
authored
Jun 09, 2016
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Uses update URL to update the status of a todo
parent
20d382a8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
41 deletions
+51
-41
app/assets/javascripts/right_sidebar.js.coffee
app/assets/javascripts/right_sidebar.js.coffee
+37
-30
app/controllers/projects/todos_controller.rb
app/controllers/projects/todos_controller.rb
+12
-9
app/views/shared/issuable/_sidebar.html.haml
app/views/shared/issuable/_sidebar.html.haml
+1
-1
config/routes.rb
config/routes.rb
+1
-1
No files found.
app/assets/javascripts/right_sidebar.js.coffee
View file @
330e9136
...
@@ -47,44 +47,51 @@ class @Sidebar
...
@@ -47,44 +47,51 @@ class @Sidebar
.
off
'click'
,
'.js-issuable-todo'
.
off
'click'
,
'.js-issuable-todo'
.
on
'click'
,
'.js-issuable-todo'
,
@
toggleTodo
.
on
'click'
,
'.js-issuable-todo'
,
@
toggleTodo
toggleTodo
:
-
>
toggleTodo
:
(
e
)
=
>
$this
=
$
(
@
)
$this
=
$
(
e
.
currentTarget
)
$todoLoading
=
$
(
'.js-issuable-todo-loading'
)
$todoLoading
=
$
(
'.js-issuable-todo-loading'
)
$btnText
=
$
(
'.js-issuable-todo-text'
,
$this
)
$btnText
=
$
(
'.js-issuable-todo-text'
,
$this
)
ajaxType
=
if
$this
.
attr
(
'data-id'
)
then
'PATCH'
else
'POST'
ajaxUrlExtra
=
if
$this
.
attr
(
'data-id'
)
then
"/
#{
$this
.
attr
(
'data-id'
)
}
"
else
''
$
.
ajax
(
$
.
ajax
(
url
:
$this
.
data
(
'url'
)
url
:
"
#{
$this
.
data
(
'url'
)
}#{
ajaxUrlExtra
}
"
type
:
'POST'
type
:
ajaxType
dataType
:
'json'
dataType
:
'json'
data
:
data
:
todo_id
:
$this
.
attr
(
'data-id'
)
issuable_id
:
$this
.
data
(
'issuable'
)
issuable_id
:
$this
.
data
(
'issuable'
)
issuable_type
:
$this
.
data
(
'issuable-type'
)
issuable_type
:
$this
.
data
(
'issuable-type'
)
beforeSend
:
->
beforeSend
:
=>
$this
.
disable
()
@
beforeTodoSend
(
$this
,
$todoLoading
)
$todoLoading
.
removeClass
'hidden'
).
done
(
data
)
=>
).
done
(
data
)
->
@
todoUpdateDone
(
data
,
$this
,
$btnText
,
$todoLoading
)
$todoPendingCount
=
$
(
'.todos-pending-count'
)
$todoPendingCount
.
text
data
.
count
beforeTodoSend
:
(
$btn
,
$todoLoading
)
->
$btn
.
disable
()
$this
.
enable
()
$todoLoading
.
removeClass
'hidden'
$todoLoading
.
addClass
'hidden'
todoUpdateDone
:
(
data
,
$btn
,
$btnText
,
$todoLoading
)
->
if
data
.
count
is
0
$todoPendingCount
=
$
(
'.todos-pending-count'
)
$todoPendingCount
.
addClass
'hidden'
$todoPendingCount
.
text
data
.
count
else
$todoPendingCount
.
removeClass
'hidden'
$btn
.
enable
()
$todoLoading
.
addClass
'hidden'
if
data
.
todo
?
$this
if
data
.
count
is
0
.
attr
'aria-label'
,
$this
.
data
(
'mark-text'
)
$todoPendingCount
.
addClass
'hidden'
.
attr
'data-id'
,
data
.
todo
.
id
else
$btnText
.
text
$this
.
data
(
'mark-text'
)
$todoPendingCount
.
removeClass
'hidden'
else
$this
if
data
.
todo
?
.
attr
'aria-label'
,
$this
.
data
(
'todo-text'
)
$btn
.
removeAttr
'data-id'
.
attr
'aria-label'
,
$btn
.
data
(
'mark-text'
)
$btnText
.
text
$this
.
data
(
'todo-text'
)
.
attr
'data-id'
,
data
.
todo
.
id
$btnText
.
text
$btn
.
data
(
'mark-text'
)
else
$btn
.
attr
'aria-label'
,
$btn
.
data
(
'todo-text'
)
.
removeAttr
'data-id'
$btnText
.
text
$btn
.
data
(
'todo-text'
)
sidebarDropdownLoading
:
(
e
)
->
sidebarDropdownLoading
:
(
e
)
->
$sidebarCollapsedIcon
=
$
(
@
).
closest
(
'.block'
).
find
(
'.sidebar-collapsed-icon'
)
$sidebarCollapsedIcon
=
$
(
@
).
closest
(
'.block'
).
find
(
'.sidebar-collapsed-icon'
)
...
...
app/controllers/projects/todos_controller.rb
View file @
330e9136
class
Projects::TodosController
<
Projects
::
ApplicationController
class
Projects::TodosController
<
Projects
::
ApplicationController
def
create
def
create
json_data
=
Hash
.
new
TodoService
.
new
.
mark_todo
(
issuable
,
current_user
)
if
params
[
:todo_id
].
nil?
render
json:
{
TodoService
.
new
.
mark_todo
(
issuable
,
current_user
)
todo:
current_user
.
todos
.
find_by
(
state: :pending
,
action:
Todo
::
MARKED
,
target_id:
issuable
.
id
),
count:
current_user
.
todos
.
pending
.
count
,
}
end
json_data
[
:todo
]
=
current_user
.
todos
.
find_by
(
state: :pending
,
action:
Todo
::
MARKED
,
target_id:
issuable
.
id
)
def
update
else
current_user
.
todos
.
find_by_id
(
params
[
:id
]).
update
(
state: :done
)
current_user
.
todos
.
find_by_id
(
params
[
:todo_id
]).
update
(
state: :done
)
end
render
json:
json_data
.
merge
({
count:
current_user
.
todos
.
pending
.
count
})
render
json:
{
count:
current_user
.
todos
.
pending
.
count
,
}
end
end
private
private
def
issuable
def
issuable
@issuable
||=
begin
@issuable
||=
begin
case
params
[
:issuable_type
]
case
params
[
:issuable_type
]
...
...
app/views/shared/issuable/_sidebar.html.haml
View file @
330e9136
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
%a
.gutter-toggle.pull-right.js-sidebar-toggle
{
role:
"button"
,
href:
"#"
,
aria:
{
label:
"Toggle sidebar"
}
}
%a
.gutter-toggle.pull-right.js-sidebar-toggle
{
role:
"button"
,
href:
"#"
,
aria:
{
label:
"Toggle sidebar"
}
}
=
sidebar_gutter_toggle_icon
=
sidebar_gutter_toggle_icon
-
if
current_user
-
if
current_user
%button
.btn.btn-default.issuable-header-btn.pull-right.js-issuable-todo
{
type:
"button"
,
aria:
{
label:
(
todo
.
nil?
?
"Add Todo"
:
"Mark Done"
)
},
data:
{
todo_text:
"Add Todo"
,
mark_text:
"Mark Done"
,
id:
(
todo
.
id
unless
todo
.
nil?
),
issuable:
issuable
.
id
,
issuable_type:
issuable
.
class
.
name
.
underscore
,
url:
namespace_project_todos_path
(
@project
.
namespace
,
@project
,
:json
)
}
}
%button
.btn.btn-default.issuable-header-btn.pull-right.js-issuable-todo
{
type:
"button"
,
aria:
{
label:
(
todo
.
nil?
?
"Add Todo"
:
"Mark Done"
)
},
data:
{
todo_text:
"Add Todo"
,
mark_text:
"Mark Done"
,
id:
(
todo
.
id
unless
todo
.
nil?
),
issuable:
issuable
.
id
,
issuable_type:
issuable
.
class
.
name
.
underscore
,
url:
namespace_project_todos_path
(
@project
.
namespace
,
@project
)
}
}
%span
.js-issuable-todo-text
%span
.js-issuable-todo-text
-
if
todo
.
nil?
-
if
todo
.
nil?
Add Todo
Add Todo
...
...
config/routes.rb
View file @
330e9136
...
@@ -789,7 +789,7 @@ Rails.application.routes.draw do
...
@@ -789,7 +789,7 @@ Rails.application.routes.draw do
end
end
end
end
resources
:todos
,
only:
[
:create
],
constraints:
{
id:
/\d+/
}
resources
:todos
,
only:
[
:create
,
:update
],
constraints:
{
id:
/\d+/
}
resources
:uploads
,
only:
[
:create
]
do
resources
:uploads
,
only:
[
:create
]
do
collection
do
collection
do
...
...
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