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
Jérome Perrin
gitlab-ce
Commits
48c682b5
Commit
48c682b5
authored
Dec 25, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Switch Notes controller to use json
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
923bd2ec
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
61 deletions
+62
-61
app/controllers/projects/notes_controller.rb
app/controllers/projects/notes_controller.rb
+59
-39
app/views/projects/notes/_form.html.haml
app/views/projects/notes/_form.html.haml
+1
-2
app/views/projects/notes/_notes_with_form.html.haml
app/views/projects/notes/_notes_with_form.html.haml
+2
-2
app/views/projects/notes/create.js.haml
app/views/projects/notes/create.js.haml
+0
-18
No files found.
app/controllers/projects/notes_controller.rb
View file @
48c682b5
...
...
@@ -2,71 +2,54 @@ class Projects::NotesController < Projects::ApplicationController
# Authorize
before_filter
:authorize_read_note!
before_filter
:authorize_write_note!
,
only:
[
:create
]
respond_to
:js
before_filter
:authorize_admin_note!
,
only:
[
:update
,
:destroy
]
def
index
@notes
=
Notes
::
LoadContext
.
new
(
project
,
current_user
,
params
).
execute
@target_type
=
params
[
:target_type
].
camelize
@target_id
=
params
[
:target_id
]
if
params
[
:target_type
]
==
"merge_request"
@discussions
=
Note
.
discussions_from_notes
(
@notes
)
end
notes_json
=
{
notes:
[]
}
respond_to
do
|
format
|
format
.
html
{
redirect_to
:back
}
format
.
json
do
render
json:
{
html:
view_to_html_string
(
"projects/notes/_notes"
)
}
end
@notes
.
each
do
|
note
|
notes_json
[
:notes
]
<<
{
id:
note
.
id
,
html:
note_to_html
(
note
)
}
end
render
json:
notes_json
end
def
create
@note
=
Notes
::
CreateContext
.
new
(
project
,
current_user
,
params
).
execute
@target_type
=
params
[
:target_type
].
camelize
@target_id
=
params
[
:target_id
]
respond_to
do
|
format
|
format
.
html
{
redirect_to
:back
}
format
.
js
format
.
json
{
render_note_json
(
@note
)
}
format
.
html
{
redirect_to
:back
}
end
end
def
destroy
@note
=
@project
.
notes
.
find
(
params
[
:id
])
return
access_denied!
unless
can?
(
current_user
,
:admin_note
,
@note
)
@note
.
destroy
@note
.
reset_events_cache
def
update
note
.
update_attributes
(
params
[
:note
])
note
.
reset_events_cache
respond_to
do
|
format
|
format
.
js
{
render
nothing:
true
}
format
.
json
{
render_note_json
(
note
)
}
format
.
html
{
redirect_to
:back
}
end
end
def
update
@note
=
@project
.
notes
.
find
(
params
[
:id
])
return
access_denied!
unless
can?
(
current_user
,
:admin_note
,
@note
)
@note
.
update_attributes
(
params
[
:note
])
@note
.
reset_events_cache
def
destroy
note
.
destroy
note
.
reset_events_cache
respond_to
do
|
format
|
format
.
js
do
render
js:
{
success:
@note
.
valid?
,
id:
@note
.
id
,
note:
view_context
.
markdown
(
@note
.
note
)
}.
to_json
end
format
.
html
do
redirect_to
:back
end
format
.
js
{
render
nothing:
true
}
end
end
def
delete_attachment
@note
=
@project
.
notes
.
find
(
params
[
:id
])
@note
.
remove_attachment!
@note
.
update_attribute
(
:attachment
,
nil
)
note
.
remove_attachment!
note
.
update_attribute
(
:attachment
,
nil
)
respond_to
do
|
format
|
format
.
js
{
render
nothing:
true
}
...
...
@@ -76,4 +59,41 @@ class Projects::NotesController < Projects::ApplicationController
def
preview
render
text:
view_context
.
markdown
(
params
[
:note
])
end
private
def
note
@note
||=
@project
.
notes
.
find
(
params
[
:id
])
end
def
note_to_html
(
note
)
render_to_string
(
"projects/notes/_note"
,
layout:
false
,
formats:
[
:html
],
locals:
{
note:
note
}
)
end
def
note_to_discussion_html
(
note
)
render_to_string
(
"projects/notes/_diff_notes_with_reply"
,
layout:
false
,
formats:
[
:html
],
locals:
{
notes:
[
note
]
}
)
end
def
render_note_json
(
note
)
render
json:
{
id:
note
.
id
,
discussion_id:
note
.
discussion_id
,
html:
note_to_html
(
note
),
discussion_html:
note_to_discussion_html
(
note
)
}
end
def
authorize_admin_note!
return
access_denied!
unless
can?
(
current_user
,
:admin_note
,
note
)
end
end
app/views/projects/notes/_form.html.haml
View file @
48c682b5
=
form_for
[
@project
,
@note
],
remote:
true
,
html:
{
multipart:
true
,
id:
nil
,
class:
"new_note js-new-note-form common-note-form"
},
authenticity_token:
true
do
|
f
|
=
form_for
[
@project
,
@note
],
remote:
true
,
html:
{
:'data-type'
=>
'json'
,
multipart:
true
,
id:
nil
,
class:
"new_note js-new-note-form common-note-form"
},
authenticity_token:
true
do
|
f
|
=
note_target_fields
=
f
.
hidden_field
:commit_id
=
f
.
hidden_field
:line_code
...
...
app/views/projects/notes/_notes_with_form.html.haml
View file @
48c682b5
%ul
#notes-list
.notes
%ul
#notes-list
.notes
.main-notes-list
=
render
"projects/notes/notes"
.js-notes-busy
...
...
@@ -7,4 +7,4 @@
=
render
"projects/notes/form"
:javascript
NoteList
.
init
(
"
#{
@target_id
}
"
,
"
#{
@target_type
}
"
,
"
#{
project_notes_path
(
@project
)
}
"
);
new
Notes
(
"
#{
project_notes_path
(
target_id:
@noteable
.
id
,
target_type:
@noteable
.
class
.
name
.
underscore
)
}
"
,
#{
@notes
.
map
(
&
:id
).
to_json
}
)
app/views/projects/notes/create.js.haml
deleted
100644 → 0
View file @
923bd2ec
-
if
@note
.
valid?
var noteHtml = "
#{
escape_javascript
(
render
@note
)
}
";
-
if
note_for_main_target?
(
@note
)
NoteList.appendNewNote(
#{
@note
.
id
}
, noteHtml);
-
else
:plain
var firstDiscussionNoteHtml = "
#{
escape_javascript
(
render
"projects/notes/diff_notes_with_reply"
,
notes:
[
@note
])
}
";
NoteList.appendNewDiscussionNote("
#{
@note
.
discussion_id
}
",
firstDiscussionNoteHtml,
noteHtml);
-
else
var errorsHtml = "
#{
escape_javascript
(
render
'projects/notes/form_errors'
,
note:
@note
)
}
";
-
if
note_for_main_target?
(
@note
)
NoteList.errorsOnForm(errorsHtml);
-
else
NoteList.errorsOnForm(errorsHtml, "
#{
@note
.
discussion_id
}
");
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