autocomplete: add flags to show/hide active users, and also display this information
in autocomplete data. ref #3374
This commit is contained in:
parent
5f898873c6
commit
0276305290
3 changed files with 31 additions and 12 deletions
|
|
@ -274,4 +274,11 @@ class HomeController(BaseController):
|
||||||
@XHRRequired()
|
@XHRRequired()
|
||||||
@jsonify
|
@jsonify
|
||||||
def user_group_autocomplete_data(self):
|
def user_group_autocomplete_data(self):
|
||||||
return {'suggestions': []}
|
query = request.GET.get('query')
|
||||||
|
|
||||||
|
repo_model = RepoModel()
|
||||||
|
_user_groups = repo_model.get_user_groups(name_contains=query)
|
||||||
|
_user_groups = _user_groups
|
||||||
|
|
||||||
|
return {'suggestions': _user_groups}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -140,10 +140,12 @@ class RepoModel(BaseModel):
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_users(self, name_contains=None, limit=20):
|
def get_users(self, name_contains=None, limit=20, only_active=True):
|
||||||
# TODO: mikhail: move this method to the UserModel.
|
# TODO: mikhail: move this method to the UserModel.
|
||||||
query = self.sa.query(User)
|
query = self.sa.query(User)
|
||||||
query = query.filter(User.active == true())
|
if only_active:
|
||||||
|
query = query.filter(User.active == true())
|
||||||
|
|
||||||
if name_contains:
|
if name_contains:
|
||||||
ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
|
ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
|
||||||
query = query.filter(
|
query = query.filter(
|
||||||
|
|
@ -165,16 +167,19 @@ class RepoModel(BaseModel):
|
||||||
'icon_link': h.gravatar_url(user.email, 14),
|
'icon_link': h.gravatar_url(user.email, 14),
|
||||||
'value_display': h.person(user.email),
|
'value_display': h.person(user.email),
|
||||||
'value': user.username,
|
'value': user.username,
|
||||||
'value_type': 'user'
|
'value_type': 'user',
|
||||||
|
'active': user.active,
|
||||||
}
|
}
|
||||||
for user in users
|
for user in users
|
||||||
]
|
]
|
||||||
return _users
|
return _users
|
||||||
|
|
||||||
def get_user_groups(self, name_contains=None, limit=20):
|
def get_user_groups(self, name_contains=None, limit=20, only_active=True):
|
||||||
# TODO: mikhail: move this method to the UserGroupModel.
|
# TODO: mikhail: move this method to the UserGroupModel.
|
||||||
query = self.sa.query(UserGroup)
|
query = self.sa.query(UserGroup)
|
||||||
query = query.filter(UserGroup.users_group_active == true())
|
if only_active:
|
||||||
|
query = query.filter(UserGroup.users_group_active == true())
|
||||||
|
|
||||||
if name_contains:
|
if name_contains:
|
||||||
ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
|
ilike_expression = u'%{}%'.format(safe_unicode(name_contains))
|
||||||
query = query.filter(
|
query = query.filter(
|
||||||
|
|
@ -196,7 +201,8 @@ class RepoModel(BaseModel):
|
||||||
'value_display': 'Group: %s (%d members)' % (
|
'value_display': 'Group: %s (%d members)' % (
|
||||||
group.users_group_name, len(group.members),),
|
group.users_group_name, len(group.members),),
|
||||||
'value': group.users_group_name,
|
'value': group.users_group_name,
|
||||||
'value_type': 'user_group'
|
'value_type': 'user_group',
|
||||||
|
'active': group.users_group_active,
|
||||||
}
|
}
|
||||||
for group in user_groups
|
for group in user_groups
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -19,19 +19,25 @@
|
||||||
/**
|
/**
|
||||||
* autocomplete formatter that uses gravatar
|
* autocomplete formatter that uses gravatar
|
||||||
* */
|
* */
|
||||||
var autocompleteFormatResult = function(data, value, org_formatter) {
|
var autocompleteFormatResult = function (data, value, org_formatter) {
|
||||||
var value_display = data.value_display;
|
var activeUser = data.active || true;
|
||||||
|
var valueDisplay = data.value_display;
|
||||||
|
|
||||||
|
if (!activeUser) {
|
||||||
|
valueDisplay = '<strong>(disabled)</strong> ' + valueDisplay;
|
||||||
|
}
|
||||||
|
|
||||||
var escapeRegExChars = function (value) {
|
var escapeRegExChars = function (value) {
|
||||||
return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
||||||
};
|
};
|
||||||
var pattern = '(' + escapeRegExChars(value) + ')';
|
var pattern = '(' + escapeRegExChars(value) + ')';
|
||||||
value_display = value_display.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>');
|
valueDisplay = valueDisplay.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>');
|
||||||
var tmpl = '<div class="ac-container-wrap"><img class="gravatar" src="{0}"/>{1}</div>';
|
var tmpl = '<div class="ac-container-wrap"><img class="gravatar" src="{0}"/>{1}</div>';
|
||||||
if (data.icon_link === "") {
|
if (data.icon_link === "") {
|
||||||
tmpl = '<div class="ac-container-wrap">{0}</div>';
|
tmpl = '<div class="ac-container-wrap">{0}</div>';
|
||||||
return tmpl.format(value_display);
|
return tmpl.format(valueDisplay);
|
||||||
}
|
}
|
||||||
return tmpl.format(data.icon_link, value_display);
|
return tmpl.format(data.icon_link, valueDisplay);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue