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
3cdac0b9
Commit
3cdac0b9
authored
Mar 20, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Api.js to handle api calls to gitlab
parent
a163135c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
42 deletions
+70
-42
app/assets/javascripts/api.js.coffee
app/assets/javascripts/api.js.coffee
+53
-0
app/assets/javascripts/users_select.js.coffee
app/assets/javascripts/users_select.js.coffee
+8
-23
app/assets/javascripts/wall.js.coffee
app/assets/javascripts/wall.js.coffee
+9
-19
No files found.
app/assets/javascripts/api.js.coffee
0 → 100644
View file @
3cdac0b9
@
Api
=
users_path
:
"/api/:version/users.json"
user_path
:
"/api/:version/users/:id.json"
notes_path
:
"/api/:version/projects/:id/notes.json"
# Get 20 (depends on api) recent notes
# and sort the ascending from oldest to newest
notes
:
(
project_id
,
callback
)
->
url
=
Api
.
buildUrl
(
Api
.
notes_path
)
url
=
url
.
replace
(
':id'
,
project_id
)
$
.
ajax
(
url
:
url
,
data
:
private_token
:
gon
.
api_token
gfm
:
true
recent
:
true
dataType
:
"json"
).
done
(
notes
)
->
notes
.
sort
(
a
,
b
)
->
return
a
.
id
-
b
.
id
callback
(
notes
)
user
:
(
user_id
,
callback
)
->
url
=
Api
.
buildUrl
(
Api
.
user_path
)
url
=
url
.
replace
(
':id'
,
user_id
)
$
.
ajax
(
url
:
url
data
:
private_token
:
gon
.
api_token
dataType
:
"json"
).
done
(
user
)
->
callback
(
user
)
# Return users list. Filtered by query
# Only active users retrieved
users
:
(
query
,
callback
)
->
url
=
Api
.
buildUrl
(
Api
.
users_path
)
$
.
ajax
(
url
:
url
data
:
private_token
:
gon
.
api_token
search
:
query
per_page
:
20
active
:
true
dataType
:
"json"
).
done
(
users
)
->
callback
(
users
)
buildUrl
:
(
url
)
->
return
url
.
replace
(
':version'
,
gon
.
api_version
)
app/assets/javascripts/users_select.js.coffee
View file @
3cdac0b9
...
...
@@ -18,34 +18,19 @@ $ ->
placeholder
:
"Search for a user"
multiple
:
$
(
'.ajax-users-select'
).
hasClass
(
'multiselect'
)
minimumInputLength
:
0
ajax
:
# instead of writing the function to execute the request we use Select2's convenient helper
url
:
"/api/"
+
gon
.
api_version
+
"/users.json"
dataType
:
"json"
data
:
(
term
,
page
)
->
search
:
term
# search term
per_page
:
10
active
:
true
private_token
:
gon
.
api_token
results
:
(
data
,
page
)
->
# parse the results into the format expected by Select2.
# since we are using custom formatting functions we do not need to alter remote JSON data
results
:
data
query
:
(
query
)
->
Api
.
users
query
.
term
,
(
users
)
->
data
=
{
results
:
users
}
query
.
callback
(
data
)
initSelection
:
(
element
,
callback
)
->
id
=
$
(
element
).
val
()
if
id
isnt
""
$
.
ajax
(
"/api/"
+
gon
.
api_version
+
"/users/"
+
id
+
".json"
,
dataType
:
"json"
data
:
private_token
:
gon
.
api_token
).
done
(
data
)
->
callback
data
Api
.
user
(
id
,
callback
)
formatResult
:
userFormatResult
# omitted for brevity, see the source of this page
formatSelection
:
userFormatSelection
# omitted for brevity, see the source of this page
dropdownCssClass
:
"ajax-users-dropdown"
# apply css that makes the dropdown taller
formatResult
:
userFormatResult
formatSelection
:
userFormatSelection
dropdownCssClass
:
"ajax-users-dropdown"
escapeMarkup
:
(
m
)
->
# we do not want to escape markup since we are displaying html in results
m
app/assets/javascripts/wall.js.coffee
View file @
3cdac0b9
@
Wall
=
note_ids
:
[]
notes_path
:
null
notes_params
:
null
project_id
:
null
init
:
(
project_id
)
->
Wall
.
project_id
=
project_id
Wall
.
notes_path
=
"/api/"
+
gon
.
api_version
+
"/projects/"
+
project_id
+
"/notes.json"
Wall
.
getContent
()
Wall
.
initRefresh
()
Wall
.
initForm
()
...
...
@@ -15,22 +12,15 @@
# Gets an initial set of notes.
#
getContent
:
->
$
.
ajax
url
:
Wall
.
notes_path
,
data
:
private_token
:
gon
.
api_token
gfm
:
true
recent
:
true
dataType
:
"json"
success
:
(
notes
)
->
notes
.
sort
(
a
,
b
)
->
return
a
.
id
-
b
.
id
$
.
each
notes
,
(
i
,
note
)
->
if
$
.
inArray
(
note
.
id
,
Wall
.
note_ids
)
==
-
1
Wall
.
note_ids
.
push
(
note
.
id
)
Wall
.
renderNote
(
note
)
Wall
.
scrollDown
()
$
(
"abbr.timeago"
).
timeago
()
Api
.
notes
Wall
.
project_id
,
(
notes
)
->
$
.
each
notes
,
(
i
,
note
)
->
# render note if it not present in loaded list
# or skip if rendered
if
$
.
inArray
(
note
.
id
,
Wall
.
note_ids
)
==
-
1
Wall
.
note_ids
.
push
(
note
.
id
)
Wall
.
renderNote
(
note
)
Wall
.
scrollDown
()
$
(
"abbr.timeago"
).
timeago
()
initRefresh
:
->
setInterval
(
"Wall.refresh()"
,
10000
)
...
...
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