Skip to content
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

Merged
merged 28 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d34ab50
Add user search autocomplete
octavioamu Aug 27, 2018
fed7bf1
eslint: fix
thelostone-mc Aug 27, 2018
bcd2c72
fix username send
octavioamu Aug 27, 2018
b00b6e2
clean code
octavioamu Aug 27, 2018
b3cfa17
Merge pull request #2107 from thelostone-mc/crowd
owocki Aug 27, 2018
8bd1eac
Add user search autocomplete
octavioamu Aug 27, 2018
89b1402
fix username send
octavioamu Aug 27, 2018
a033fdc
clean code
octavioamu Aug 27, 2018
44cb032
trim spaces
octavioamu Aug 27, 2018
dc4d9d2
Merge branch 'feature/autocomplete-users' of https://github.com/octav…
octavioamu Aug 27, 2018
b3c5d07
add new line
octavioamu Aug 27, 2018
a2ba97c
fix code stickler-ci
octavioamu Aug 27, 2018
880a572
lint fixes
thelostone-mc Aug 28, 2018
719183e
css: removed comments
thelostone-mc Aug 28, 2018
12d5a97
Add user search autocomplete
octavioamu Aug 27, 2018
a5f5850
fix username send
octavioamu Aug 27, 2018
b9b6b85
clean code
octavioamu Aug 27, 2018
22f0934
Add user search autocomplete
octavioamu Aug 27, 2018
eba0c76
fix username send
octavioamu Aug 27, 2018
76a469c
clean code
octavioamu Aug 27, 2018
c2f42c4
trim spaces
octavioamu Aug 27, 2018
9a7bd48
add new line
octavioamu Aug 27, 2018
c87d78d
fix code stickler-ci
octavioamu Aug 27, 2018
5883a95
satisfy stickler-ci
octavioamu Aug 27, 2018
71f4d2b
404 for not ajax request
octavioamu Aug 28, 2018
30ce720
Merge branch 'feature/autocomplete-users' of https://github.com/octav…
octavioamu Aug 28, 2018
360214b
update packages
octavioamu Aug 28, 2018
c70e19e
removed leading @ for autocomplete
thelostone-mc Aug 29, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
url(r'^api/v0.1/', include(dbrouter.urls)),
url(r'^api/v0.1/', include(ebrouter.urls)),
url(r'^actions/api/v0.1/', include(dbrouter.urls)), # same as active, but not cached in cloudfront
url(r'^api/v0.1/users_search/', dashboard.views.get_users, name='users_search'),

# Health check endpoint
re_path(r'^health/', include('health_check.urls')),
Expand Down
3 changes: 1 addition & 2 deletions app/assets/onepager/js/send.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ $(document).ready(function() {
if ($(this).hasClass('disabled'))
return;
loading_button($(this));

// get form data
var email = $('#email').val();
var github_url = $('#issueURL').val();
var from_name = $('#fromName').val();
var username = $('#username').val();
var username = $('.username-search').select2('data')[0].text;
var amountInEth = parseFloat($('#amount').val());
var comments_priv = $('#comments_priv').val();
var comments_public = $('#comments_public').val();
Expand Down
Binary file added app/assets/v2/images/user-placeholder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions app/assets/v2/js/pages/bounty_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,18 +296,19 @@ var callbacks = {
},
'started_owners_username': function(key, val, result) {
var started = [];

if (result.interested) {
var interested = result.interested;

interested.forEach(function(_interested, position) {
var name = (position == interested.length - 1) ?
_interested.profile.handle : _interested.profile.handle.concat(',');
if(!_interested.pending){

if (!_interested.pending)
started.push(profileHtml(_interested.profile.handle, name));
}
});
if (started.length == 0) {
if (started.length == 0)
started.push('<i class="fas fa-minus"></i>');
}
}
return [ 'started_owners_username', started ];
},
Expand Down
58 changes: 58 additions & 0 deletions app/assets/v2/js/user-search.js
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">

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)

<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;

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)

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)


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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'selected' used outside of binding context. (block-scoped-var)

}
});
28 changes: 28 additions & 0 deletions app/dashboard/templates/onepager/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@
<link rel="stylesheet" href="{% static "v2/css/forms/button.css" %}">
<link rel="stylesheet" href="{% static "cookielaw/css/cookielaw.css" %}">

<!-- TODO: remove this css if bootstrap is used -->
<style>
.d-flex {
display: flex;
}
.align-items-baseline {
align-items: center;
}
.mr-2 {
margin-right: 1rem;
}
.rounded-circle {
border-radius: 50%;
vertical-align: middle;
}

.select2-container .select2-selection--single {
height: 34px;
text-align: left;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
line-height: 32px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
height: 32px;
}
</style>

<script type="text/javascript">
var static_url = "{{ STATIC_URL }}";
var media_url = "{{ MEDIA_URL }}";
Expand Down
7 changes: 5 additions & 2 deletions app/dashboard/templates/onepager/send2.html
Original file line number Diff line number Diff line change
Expand Up @@ -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' %}
Expand Down Expand Up @@ -59,8 +61,9 @@ <h1>{% trans "Send Tip." %}</h1>
</div>
<div id="usd_amount"> &nbsp;</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;"> -->
Copy link
Member

Choose a reason for hiding this comment

The 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%}
Expand Down
24 changes: 23 additions & 1 deletion app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens when this block of code gets executed? Won't the formatUser fail? Secondly, if you are sending it with application/json, I think it is better to send something like {message: 'fail'}

mimetype = 'application/json'
return HttpResponse(data, mimetype)