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
iv
gitlab-ce
Commits
f0f88390
Commit
f0f88390
authored
Feb 13, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
project_user selectbox with ajax autocomplete
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
1d48904a
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
98 additions
and
13 deletions
+98
-13
app/assets/javascripts/api.js.coffee
app/assets/javascripts/api.js.coffee
+18
-0
app/assets/javascripts/project_users_select.js.coffee
app/assets/javascripts/project_users_select.js.coffee
+43
-0
app/assets/stylesheets/generic/selects.scss
app/assets/stylesheets/generic/selects.scss
+4
-2
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+0
-9
app/helpers/selects_helper.rb
app/helpers/selects_helper.rb
+19
-0
app/views/projects/issues/_issues.html.haml
app/views/projects/issues/_issues.html.haml
+1
-1
lib/api/projects.rb
lib/api/projects.rb
+13
-1
No files found.
app/assets/javascripts/api.js.coffee
View file @
f0f88390
...
...
@@ -3,6 +3,7 @@
user_path
:
"/api/:version/users/:id.json"
notes_path
:
"/api/:version/projects/:id/notes.json"
namespaces_path
:
"/api/:version/namespaces.json"
project_users_path
:
"/api/:version/projects/:id/users.json"
# Get 20 (depends on api) recent notes
# and sort the ascending from oldest to newest
...
...
@@ -50,6 +51,23 @@
).
done
(
users
)
->
callback
(
users
)
# Return project users list. Filtered by query
# Only active users retrieved
projectUsers
:
(
project_id
,
query
,
callback
)
->
url
=
Api
.
buildUrl
(
Api
.
project_users_path
)
url
=
url
.
replace
(
':id'
,
project_id
)
$
.
ajax
(
url
:
url
data
:
private_token
:
gon
.
api_token
search
:
query
per_page
:
20
active
:
true
dataType
:
"json"
).
done
(
users
)
->
callback
(
users
)
# Return namespaces list. Filtered by query
namespaces
:
(
query
,
callback
)
->
url
=
Api
.
buildUrl
(
Api
.
namespaces_path
)
...
...
app/assets/javascripts/project_users_select.js.coffee
0 → 100644
View file @
f0f88390
$
->
projectUserFormatResult
=
(
user
)
->
if
user
.
avatar_url
avatar
=
user
.
avatar_url
else
if
gon
.
gravatar_enabled
avatar
=
gon
.
gravatar_url
avatar
=
avatar
.
replace
(
'%{hash}'
,
md5
(
user
.
email
))
avatar
=
avatar
.
replace
(
'%{size}'
,
'24'
)
else
avatar
=
gon
.
relative_url_root
+
"/assets/no_avatar.png"
"<div class='user-result'>
<div class='user-image'><img class='avatar s24' src='
#{
avatar
}
'></div>
<div class='user-name'>
#{
user
.
name
}
</div>
<div class='user-username'>
#{
user
.
username
}
</div>
</div>"
projectUserFormatSelection
=
(
user
)
->
user
.
name
$
(
'.ajax-project-users-select'
).
each
(
i
,
select
)
->
project_id
=
$
(
'body'
).
data
(
'project-id'
)
$
(
select
).
select2
placeholder
:
"Search for a user"
multiple
:
$
(
select
).
hasClass
(
'multiselect'
)
minimumInputLength
:
0
query
:
(
query
)
->
Api
.
projectUsers
project_id
,
query
.
term
,
(
users
)
->
data
=
{
results
:
users
}
query
.
callback
(
data
)
initSelection
:
(
element
,
callback
)
->
id
=
$
(
element
).
val
()
if
id
isnt
""
Api
.
user
(
id
,
callback
)
formatResult
:
projectUserFormatResult
formatSelection
:
projectUserFormatSelection
dropdownCssClass
:
"ajax-project-users-dropdown"
dropdownAutoWidth
:
true
escapeMarkup
:
(
m
)
->
# we do not want to escape markup since we are displaying html in results
m
app/assets/stylesheets/generic/selects.scss
View file @
f0f88390
...
...
@@ -79,6 +79,8 @@ select {
margin-right
:
10px
;
}
.ajax-users-dropdown
.select2-search
{
.ajax-users-dropdown
,
.ajax-project-users-dropdown
{
.select2-search
{
padding-top
:
4px
;
}
}
app/helpers/application_helper.rb
View file @
f0f88390
...
...
@@ -162,15 +162,6 @@ module ApplicationHelper
alias_method
:url_to_image
,
:image_url
def
users_select_tag
(
id
,
opts
=
{})
css_class
=
"ajax-users-select "
css_class
<<
"multiselect "
if
opts
[
:multiple
]
css_class
<<
(
opts
[
:class
]
||
''
)
value
=
opts
[
:selected
]
||
''
hidden_field_tag
(
id
,
value
,
class:
css_class
)
end
def
body_data_page
path
=
controller
.
controller_path
.
split
(
'/'
)
namespace
=
path
.
first
if
path
.
second
...
...
app/helpers/selects_helper.rb
0 → 100644
View file @
f0f88390
module
SelectsHelper
def
users_select_tag
(
id
,
opts
=
{})
css_class
=
"ajax-users-select "
css_class
<<
"multiselect "
if
opts
[
:multiple
]
css_class
<<
(
opts
[
:class
]
||
''
)
value
=
opts
[
:selected
]
||
''
hidden_field_tag
(
id
,
value
,
class:
css_class
)
end
def
project_users_select_tag
(
id
,
opts
=
{})
css_class
=
"ajax-project-users-select "
css_class
<<
"multiselect "
if
opts
[
:multiple
]
css_class
<<
(
opts
[
:class
]
||
''
)
value
=
opts
[
:selected
]
||
''
hidden_field_tag
(
id
,
value
,
class:
css_class
)
end
end
app/views/projects/issues/_issues.html.haml
View file @
f0f88390
...
...
@@ -6,7 +6,7 @@
=
form_tag
bulk_update_project_issues_path
(
@project
),
method: :post
do
%span
Update selected issues with
=
select_tag
(
'update[status]'
,
options_for_select
([
'open'
,
'closed'
]),
prompt:
"Status"
)
=
select_tag
(
'update[assignee_id]'
,
bulk_update_assignee_options
,
prompt:
"Assignee"
)
=
project_users_select_tag
(
'update[assignee_id]'
)
=
select_tag
(
'update[milestone_id]'
,
bulk_update_milestone_options
,
prompt:
"Milestone"
)
=
hidden_field_tag
'update[issues_ids]'
,
[]
=
hidden_field_tag
:status
,
params
[
:status
]
...
...
lib/api/projects.rb
View file @
f0f88390
...
...
@@ -308,6 +308,18 @@ module API
projects
=
Project
.
where
(
"(id in (?) OR visibility_level in (?)) AND (name LIKE (?))"
,
ids
,
visibility_levels
,
"%
#{
params
[
:query
]
}
%"
)
present
paginate
(
projects
),
with:
Entities
::
Project
end
# Get a users list
#
# Example Request:
# GET /users
get
':id/users'
do
@users
=
User
.
where
(
id:
user_project
.
team
.
users
.
map
(
&
:id
))
@users
=
@users
.
search
(
params
[
:search
])
if
params
[
:search
].
present?
@users
=
paginate
@users
present
@users
,
with:
Entities
::
User
end
end
end
end
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