-
-
Notifications
You must be signed in to change notification settings - Fork 775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add user search autocomplete #2108
Changes from 13 commits
d34ab50
fed7bf1
bcd2c72
b00b6e2
b3cfa17
8bd1eac
89b1402
a033fdc
44cb032
dc4d9d2
b3c5d07
a2ba97c
880a572
719183e
12d5a97
a5f5850
b9b6b85
22f0934
eba0c76
76a469c
c2f42c4
9a7bd48
c87d78d
5883a95
71f4d2b
30ce720
360214b
c70e19e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
$(function() { | ||
$('.username-search').select2({ | ||
ajax: { | ||
url: '/api/v0.1/users_search/', | ||
dataType: 'json', | ||
delay: 250, | ||
data: function(params) { | ||
|
||
let query = { | ||
term: params.term | ||
}; | ||
|
||
return query; | ||
}, | ||
processResults: function(data) { | ||
return { | ||
results: data | ||
}; | ||
}, | ||
cache: true | ||
}, | ||
placeholder: 'Search by username', | ||
minimumInputLength: 3, | ||
escapeMarkup: function(markup) { | ||
|
||
return markup; | ||
}, | ||
templateResult: formatUser, | ||
templateSelection: formatUserSelection | ||
}); | ||
|
||
function formatUser(user) { | ||
|
||
if (user.loading) { | ||
return user.text; | ||
} | ||
let markup = `<div class="d-flex align-items-baseline"> | ||
<div class="mr-2"> | ||
<img class="rounded-circle" src="${user.avatar_url || static_url + 'v2/images/user-placeholder.png'}" width="40" height="40"/> | ||
</div> | ||
<div class="">${user.text}</div> | ||
</div>`; | ||
|
||
return markup; | ||
} | ||
|
||
function formatUserSelection(user) { | ||
|
||
let selected; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected blank line after variable declarations. (newline-after-var) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Expected blank line after variable declarations. (newline-after-var) |
||
|
||
if (user.id) { | ||
selected = `<img class="rounded-circle" src="${user.avatar_url || static_url + 'v2/images/user-placeholder.png'}" width="20" height="20"/> ${user.text}`; | ||
} else { | ||
selected = user.text; | ||
} | ||
return selected; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 'selected' used outside of binding context. (block-scoped-var) |
||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,8 @@ | |
<script src="/dynamic/js/tokens_dynamic.js"></script> | ||
<script src="{% static "onepager/js/send.js" %}"></script> | ||
<script src="{% static "onepager/js/confetti.js" %}"></script> | ||
<script src="{% static "v2/js/user-search.js" %}"></script> | ||
|
||
{% endblock %} | ||
<!-- Main --> | ||
{% block 'main' %} | ||
|
@@ -59,8 +61,9 @@ <h1>{% trans "Send Tip." %}</h1> | |
</div> | ||
<div id="usd_amount"> </div> | ||
<div> | ||
{% trans "To Github Username" %}: | ||
<input type="text" placeholder="@username" id="username" value="" style="max-width: 400px; margin-left: auto; margin-right: auto;"> | ||
<label for="">{% trans "To Github Username" %}:</label> <br> | ||
<!-- <input type="text" placeholder="@username" id="username" value="" style="max-width: 400px; margin-left: auto; margin-right: auto;"> --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @octavioamu could we remove this if it's not being used ? |
||
<select id="username" class="username-search custom-select" style="max-width: 400px; margin-left: auto; margin-right: auto;"></select> | ||
</div> | ||
<div> | ||
{% trans "From Github Username" %} {% if not request.user.is_authenticated %}(<a href="{% url 'social:begin' 'github' %}?next=/tip">{% trans "Login" %}</a>) {%endif%} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
from django.contrib.admin.views.decorators import staff_member_required | ||
from django.contrib.auth.models import User | ||
from django.core.cache import cache | ||
from django.http import Http404, JsonResponse | ||
from django.http import Http404, HttpResponse, JsonResponse | ||
from django.shortcuts import redirect | ||
from django.template.response import TemplateResponse | ||
from django.templatetags.static import static | ||
|
@@ -1557,3 +1557,25 @@ def change_bounty(request, bounty_id): | |
'result': result | ||
} | ||
return TemplateResponse(request, 'bounty/change.html', params) | ||
|
||
|
||
def get_users(request): | ||
if request.is_ajax(): | ||
q = request.GET.get('term') | ||
profiles = Profile.objects.filter(handle__icontains=q) | ||
results = [] | ||
for user in profiles: | ||
profile_json = {} | ||
profile_json['id'] = user.id | ||
profile_json['text'] = user.handle | ||
profile_json['email'] = user.email | ||
profile_json['avatar_id'] = user.avatar_id | ||
if user.avatar_id: | ||
profile_json['avatar_url'] = user.avatar_url | ||
profile_json['preferred_payout_address'] = user.preferred_payout_address | ||
results.append(profile_json) | ||
data = json.dumps(results) | ||
else: | ||
data = 'fail' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens when this block of code gets executed? Won't the |
||
mimetype = 'application/json' | ||
return HttpResponse(data, mimetype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expected blank line after variable declarations. (newline-after-var)