From 20a479350f1a3c44e52175a18af42d4a39e2fd74 Mon Sep 17 00:00:00 2001 From: octavioamu Date: Tue, 19 Mar 2019 23:16:36 -0300 Subject: [PATCH 01/29] fetch users --- app/app/urls.py | 3 + app/dashboard/templates/dashboard/users.html | 111 +++++++++++++++++++ app/dashboard/views.py | 25 +++++ 3 files changed, 139 insertions(+) create mode 100644 app/dashboard/templates/dashboard/users.html diff --git a/app/app/urls.py b/app/app/urls.py index c2d33c8a6bd..94caaf84a99 100644 --- a/app/app/urls.py +++ b/app/app/urls.py @@ -516,6 +516,9 @@ re_path(r'^cms/', include(wagtailadmin_urls)), re_path(r'^documents/', include(wagtaildocs_urls)), re_path(r'', include(wagtail_urls)), + + # users + path('users',dashboard.views.users, name='users'), ] if settings.ENABLE_SILK: diff --git a/app/dashboard/templates/dashboard/users.html b/app/dashboard/templates/dashboard/users.html new file mode 100644 index 00000000000..2cfdacbd893 --- /dev/null +++ b/app/dashboard/templates/dashboard/users.html @@ -0,0 +1,111 @@ +{% comment %} + Copyright (C) 2019 Gitcoin Core + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +{% endcomment %} +{% load i18n static %} + + + + + {% include 'shared/head.html' %} + {% include 'shared/cards.html' %} + + + + + + + {% include 'shared/tag_manager_2.html' %} +
+ {% include 'shared/top_nav.html' with class='d-md-flex' %} + {% include 'shared/nav.html' %} +
+
+ + +
+ {% for user in users %} +
+ + {{user.handle}} + {{ user.data.name }} + {% if verification.verified %} + + {% endif %} +
+ {% endfor %} +
+
+ + + + {% include 'shared/analytics.html' %} + {% include 'shared/footer_scripts.html' %} + {% include 'shared/footer.html' %} + {% include 'shared/messages.html' %} + + + + + + diff --git a/app/dashboard/views.py b/app/dashboard/views.py index 4f96a49047e..07121b9616e 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -625,6 +625,31 @@ def onboard(request, flow): return TemplateResponse(request, 'ftux/onboard.html', params) +def users(request): + """Handle displaying the users.""" + + # q = request.GET.get('q') + order_by = request.GET.get('order_by', '-created_on') + + # Only show the latest contract Kudos for the current network. + query_kwargs = { + + } + user_list = Profile.objects.all() + # if q: + # user_list = user_list.keyword(q) + + users = user_list.order_by(order_by).cache() + + params = { + 'active': 'users', + 'title': 'Users', + 'meta_title': "", + 'meta_description': "", + 'users': users, + } + return TemplateResponse(request, 'dashboard/users.html', params) + def dashboard(request): """Handle displaying the dashboard.""" From dd1c62040936462f446d8c02bbe182ccc83fd448 Mon Sep 17 00:00:00 2001 From: octavioamu Date: Wed, 20 Mar 2019 00:51:38 -0300 Subject: [PATCH 02/29] add data --- app/dashboard/templates/dashboard/users.html | 182 +++++++++++++------ 1 file changed, 130 insertions(+), 52 deletions(-) diff --git a/app/dashboard/templates/dashboard/users.html b/app/dashboard/templates/dashboard/users.html index 2cfdacbd893..408a745fff1 100644 --- a/app/dashboard/templates/dashboard/users.html +++ b/app/dashboard/templates/dashboard/users.html @@ -15,7 +15,7 @@ along with this program. If not, see . {% endcomment %} -{% load i18n static %} +{% load i18n static email_obfuscator add_url_schema avatar_tags %} @@ -26,71 +26,148 @@ - + {% include 'shared/tag_manager_2.html' %}
{% include 'shared/top_nav.html' with class='d-md-flex' %} {% include 'shared/nav.html' %}
+
+ +
- - -
- {% for user in users %} -
- - {{user.handle}} - {{ user.data.name }} - {% if verification.verified %} - - {% endif %} + {% endif %} +
+ + + + {% if user.data.blog %} + + + + {% endif %} + {% if user.data.email %} + + + + {% endif %} +
+ {% if user.show_job_status %} +
+ {% if user.resume %} + + {{ user.job_status_verbose }} + + {% else %} + {{ user.job_status_verbose }} + {% endif %} +
+ {% endif %} + + Joined: + + + +
+
+ {% endfor %}
- {% endfor %} @@ -104,7 +181,8 @@ From b0d47a920cc17ff46d0e14de884c14b0feff7b44 Mon Sep 17 00:00:00 2001 From: octavioamu Date: Wed, 20 Mar 2019 01:24:17 -0300 Subject: [PATCH 03/29] add keywords --- app/dashboard/templates/dashboard/users.html | 12 +++++++++++- app/dashboard/views.py | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/dashboard/templates/dashboard/users.html b/app/dashboard/templates/dashboard/users.html index 408a745fff1..c1060cf1673 100644 --- a/app/dashboard/templates/dashboard/users.html +++ b/app/dashboard/templates/dashboard/users.html @@ -77,6 +77,10 @@ + + +
- - + +
-
+
@@ -150,7 +150,7 @@
- Joined: + Joined:
diff --git a/app/dashboard/views.py b/app/dashboard/views.py index 0c231415b68..36caccbfb09 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -672,12 +672,13 @@ def users_fetch(request): # 'keywords': json.dumps([str(key) for key in Keyword.objects.all().values_list('keyword', flat=True)]), # } - + q = request.GET.get('search','') limit = int(request.GET.get('limit', 10)) page = int(request.GET.get('page', 1)) order_by = request.GET.get('order_by', '-created_on') context = {} - user_list = Profile.objects.all().order_by(order_by).cache() + user_list = Profile.objects.all().order_by(order_by).filter(handle__icontains=q).cache() + # all_notifs = Notification.objects.filter(to_user_id=request.user.id).order_by('-id') params = dict() all_pages = Paginator(user_list, limit) From 16950a35613cc2fde24e4c9845a74c30cf53e6e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Octavio=20Amuch=C3=A1stegui?= Date: Thu, 4 Apr 2019 00:39:46 -0300 Subject: [PATCH 10/29] comment not active filters --- app/dashboard/templates/dashboard/users.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/dashboard/templates/dashboard/users.html b/app/dashboard/templates/dashboard/users.html index 874c9a41fc2..636ab325293 100644 --- a/app/dashboard/templates/dashboard/users.html +++ b/app/dashboard/templates/dashboard/users.html @@ -67,7 +67,7 @@ +
-
{% for user in users %} @@ -183,6 +186,13 @@
let bootstrapTooltip = $.fn.tooltip.noConflict() $.fn.runTooltip = bootstrapTooltip; $('[data-toggle="tooltip"]').runTooltip(); + document.keywords = {{keywords | safe}}; + + $(".keywords-filter").select2({ + tags: true, + placeholder: 'Skill', + data: document.keywords + }) diff --git a/app/dashboard/views.py b/app/dashboard/views.py index a7a1662754f..a6ad0c8c0e8 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -736,7 +736,7 @@ def users(request): # q = request.GET.get('q') order_by = request.GET.get('order_by', '-created_on') - + keyword = request.GET.get('keywords', False) # Only show the latest contract Kudos for the current network. query_kwargs = { @@ -753,6 +753,7 @@ def users(request): 'meta_title': "", 'meta_description': "", 'users': users, + 'keywords': json.dumps([str(key) for key in Keyword.objects.all().values_list('keyword', flat=True)]), } return TemplateResponse(request, 'dashboard/users.html', params) From 8c4f877ceb99e058966d4af6cb5118765854a167 Mon Sep 17 00:00:00 2001 From: octavioamu Date: Tue, 2 Apr 2019 16:58:20 -0300 Subject: [PATCH 17/29] change to rest --- app/app/urls.py | 3 +- app/assets/v2/js/users.js | 58 +++++ app/dashboard/templates/dashboard/users.html | 213 ++++++++++--------- app/dashboard/views.py | 52 ++++- 4 files changed, 218 insertions(+), 108 deletions(-) create mode 100644 app/assets/v2/js/users.js diff --git a/app/app/urls.py b/app/app/urls.py index 441bc2f497a..3007dbc2134 100644 --- a/app/app/urls.py +++ b/app/app/urls.py @@ -539,7 +539,8 @@ re_path(r'', include(wagtail_urls)), # users - path('users',dashboard.views.users, name='users'), + path('users',dashboard.views.users_directory, name='users_directory'), + url(r'^api/v0.1/users_fetch/', dashboard.views.users_fetch, name='users_fetch'), ] if settings.ENABLE_SILK: diff --git a/app/assets/v2/js/users.js b/app/assets/v2/js/users.js new file mode 100644 index 00000000000..c76ae719f2b --- /dev/null +++ b/app/assets/v2/js/users.js @@ -0,0 +1,58 @@ +let users = []; +let usersPage = 1; +let usersNumPages = ''; +let usersHasNext = false; + +Vue.mixin({ + methods: { + fetchUsers: function(newPage) { + var vm = this; + + if (newPage) { + vm.usersPage = newPage; + } + + var getNotifications = fetchData (`/api/v0.1/users_fetch/?page=${vm.usersPage}`, 'GET'); + + $.when(getNotifications).then(function(response) { + newNotifications = newData(response.data, vm.notifications); + newNotifications.forEach(function(item) { + vm.notifications.push(item); + }); + + vm.usersNumPages = response.num_pages; + vm.usersHasNext = response.has_next; + vm.numNotifications = response.count; + + vm.checkUnread(); + if (vm.usersHasNext) { + vm.usersPage = ++vm.usersPage; + + } else { + vm.usersPage = 1; + } + }); + } + + } + +}); + +if (document.getElementById('gc-users-directory')) { + var app = new Vue({ + delimiters: [ '[[', ']]' ], + el: '#gc-users-directory', + data: { + users, + usersPage, + usersNumPages, + usersHasNext + }, + mounted() { + this.fetchUsers(); + }, + created() { + // this.sendState(); + } + }); +} diff --git a/app/dashboard/templates/dashboard/users.html b/app/dashboard/templates/dashboard/users.html index c1060cf1673..657d32def29 100644 --- a/app/dashboard/templates/dashboard/users.html +++ b/app/dashboard/templates/dashboard/users.html @@ -58,120 +58,122 @@ {% include 'shared/top_nav.html' with class='d-md-flex' %} {% include 'shared/nav.html' %}
-
- -
-
-
-
- {% for user in users %} -
- -
- -
- {% if user.data.name %} - {{ user.data.name }} - {% else %} - @{{ user.handle }} - {% endif %} -
- - @{{ user.handle }} - - {% if user.keywords %} -
- {% for keyword in user.keywords %} - {{ keyword }} - {% endfor %} -
- {% endif %} - +
+
+
+ {% for user in users %} +
+ + - {% if user.show_job_status %} -
- {% if user.resume %} - - {{ user.job_status_verbose }} - - {% else %} - {{ user.job_status_verbose }} + {% if user.keywords %} +
+ {% for keyword in user.keywords %} + {{ keyword }} + {% endfor %} +
{% endif %} -
- {% endif %} - - Joined: - +
+ + + + {% if user.data.blog %} + + + + {% endif %} + {% if user.data.email %} + + + + {% endif %} +
+ {% if user.show_job_status %} +
+ {% if user.resume %} + + {{ user.job_status_verbose }} + + {% else %} + {{ user.job_status_verbose }} + {% endif %} +
+ {% endif %} + + Joined: + +
+ {% endfor %}
- {% endfor %}
-
+
@@ -194,6 +196,7 @@
data: document.keywords }) + diff --git a/app/dashboard/views.py b/app/dashboard/views.py index a6ad0c8c0e8..6a573e618c8 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -731,8 +731,8 @@ def onboard(request, flow): return TemplateResponse(request, 'ftux/onboard.html', params) -def users(request): - """Handle displaying the users.""" +def users_directory(request): + """Handle displaying users directory page.""" # q = request.GET.get('q') order_by = request.GET.get('order_by', '-created_on') @@ -757,6 +757,54 @@ def users(request): } return TemplateResponse(request, 'dashboard/users.html', params) + +@require_GET +def users_fetch(request): + """Handle displaying users.""" + # order_by = request.GET.get('order_by', '-created_on') + # query_kwargs = { + + # } + # user_list = Profile.objects.all() + # users = user_list.order_by(order_by).cache() + + # params = { + # 'active': 'users', + # 'title': 'Users', + # 'meta_title': "", + # 'meta_description': "", + # 'users': users, + # 'keywords': json.dumps([str(key) for key in Keyword.objects.all().values_list('keyword', flat=True)]), + # } + + + limit = int(request.GET.get('limit', 10)) + page = int(request.GET.get('page', 1)) + order_by = request.GET.get('order_by', '-created_on') + user_list = Profile.objects.all() + users = user_list.order_by(order_by).cache() + # all_notifs = Notification.objects.filter(to_user_id=request.user.id).order_by('-id') + params = dict() + all_pages = Paginator(users, limit) + if page <= 0 or page > all_pages.num_pages: + page = 1 + all_users = [] + # all_users = all_pages.page(page) + for user in all_pages.page(page): + print(user) + profile_json = {} + if user.avatar_baseavatar_related.exists(): + profile_json['avatar_id'] = user.avatar_baseavatar_related.first().pk + profile_json['avatar_url'] = user.avatar_baseavatar_related.first().avatar_url + profile_json = user.to_standard_dict() + all_users.append(profile_json) + params['data'] = json.dumps(all_users) + params['has_next'] = all_pages.page(page).has_next() + params['count'] = all_pages.count + params['num_pages'] = all_pages.num_pages + return JsonResponse(params, status=200, safe=False) + + def dashboard(request): """Handle displaying the dashboard.""" From bf56fd878762d0f29f95b3d6eed2b7a34170ffbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Octavio=20Amuch=C3=A1stegui?= Date: Wed, 3 Apr 2019 12:26:42 -0300 Subject: [PATCH 18/29] backend --- app/assets/v2/js/users.js | 12 +++--- app/dashboard/templates/dashboard/users.html | 6 +++ app/dashboard/views.py | 42 +++++++++++--------- 3 files changed, 36 insertions(+), 24 deletions(-) diff --git a/app/assets/v2/js/users.js b/app/assets/v2/js/users.js index c76ae719f2b..e8e74e0c5d6 100644 --- a/app/assets/v2/js/users.js +++ b/app/assets/v2/js/users.js @@ -15,16 +15,18 @@ Vue.mixin({ var getNotifications = fetchData (`/api/v0.1/users_fetch/?page=${vm.usersPage}`, 'GET'); $.when(getNotifications).then(function(response) { - newNotifications = newData(response.data, vm.notifications); - newNotifications.forEach(function(item) { - vm.notifications.push(item); - }); + console.log(response.data) + vm.users = response.data; + + // newNotifications = newData(response.data, vm.notifications); + // newNotifications.forEach(function(item) { + // vm.notifications.push(item); + // }); vm.usersNumPages = response.num_pages; vm.usersHasNext = response.has_next; vm.numNotifications = response.count; - vm.checkUnread(); if (vm.usersHasNext) { vm.usersPage = ++vm.usersPage; diff --git a/app/dashboard/templates/dashboard/users.html b/app/dashboard/templates/dashboard/users.html index 657d32def29..f68d15b5dc1 100644 --- a/app/dashboard/templates/dashboard/users.html +++ b/app/dashboard/templates/dashboard/users.html @@ -59,6 +59,12 @@ {% include 'shared/nav.html' %}
+ +
    +
  • + [[user]] +
  • +
-
+
-
    -
  • - [[user]] -
  • -
-
-
- {% for user in users %} -
- -
- -
- {% if user.data.name %} - {{ user.data.name }} - {% else %} - @{{ user.handle }} - {% endif %} -
- - @{{ user.handle }} - - {% if user.keywords %} -
- {% for keyword in user.keywords %} - {{ keyword }} - {% endfor %} -
- {% endif %} -
- - - - {% if user.data.blog %} - - - - {% endif %} - {% if user.data.email %} - - - - {% endif %} -
- {% if user.show_job_status %} -
- {% if user.resume %} - - {{ user.job_status_verbose }} - - {% else %} - {{ user.job_status_verbose }} - {% endif %} -
- {% endif %} - - Joined: - - - -
+
+
+
+ +
+
+ [[ user.data.name || user.handle ]] + + + +
+ + @[[ user.handle ]] + +
+ +
+ - {% endfor %} +
+ + + +
+ + Joined: +
+
+
+
From 082942dffd74bc1e7846486e8e25ecfdffd76dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Octavio=20Amuch=C3=A1stegui?= Date: Thu, 4 Apr 2019 00:37:28 -0300 Subject: [PATCH 22/29] add infinite pagination + usersearch --- app/assets/v2/js/users.js | 90 +++++++++++++++++--- app/dashboard/templates/dashboard/users.html | 8 +- app/dashboard/views.py | 5 +- 3 files changed, 85 insertions(+), 18 deletions(-) diff --git a/app/assets/v2/js/users.js b/app/assets/v2/js/users.js index 43eaada0385..b94a147c86c 100644 --- a/app/assets/v2/js/users.js +++ b/app/assets/v2/js/users.js @@ -2,6 +2,7 @@ let users = []; let usersPage = 1; let usersNumPages = ''; let usersHasNext = false; +let numUsers = ''; Vue.mixin({ methods: { @@ -11,21 +12,33 @@ Vue.mixin({ if (newPage) { vm.usersPage = newPage; } + vm.params.page = vm.usersPage - var getNotifications = fetchData (`/api/v0.1/users_fetch/?page=${vm.usersPage}`, 'GET'); + console.log(vm.searchTerm) + if(vm.searchTerm) { + vm.params.search = vm.searchTerm + } else { + delete vm.params['search'] + } + let searchParams = new URLSearchParams(vm.params); + + let apiUrlUsers = `/api/v0.1/users_fetch/?${searchParams.toString()}` + + var getUsers = fetchData (apiUrlUsers, 'GET'); - $.when(getNotifications).then(function(response) { + $.when(getUsers).then(function(response) { console.log(response.data) - vm.users = response.data; - - // newNotifications = newData(response.data, vm.notifications); - // newNotifications.forEach(function(item) { - // vm.notifications.push(item); - // }); + // vm.users = response.data; + // vm.users.push(response.data); + + response.data.forEach(function(item) { + vm.users.push(item); + }); + vm.usersNumPages = response.num_pages; vm.usersHasNext = response.has_next; - vm.numNotifications = response.count; + vm.numUsers = response.count; if (vm.usersHasNext) { vm.usersPage = ++vm.usersPage; @@ -34,8 +47,30 @@ Vue.mixin({ vm.usersPage = 1; } }); - } + }, + searchUsers: function() { + vm = this; + vm.users = []; + // vm.usersPage = 1 + // vm.params.page = 1 + + vm.fetchUsers(1) + }, + bottomVisible: function() { + vm = this; + + const scrollY = window.scrollY + const visible = document.documentElement.clientHeight + const pageHeight = document.documentElement.scrollHeight - 500 + const bottomOfPage = visible + scrollY >= pageHeight + if( bottomOfPage || pageHeight < visible) { + if (vm.usersHasNext) { + vm.fetchUsers(); + vm.usersHasNext = false + } + } + } } }); @@ -49,13 +84,44 @@ if (document.getElementById('gc-users-directory')) { usersPage, usersNumPages, usersHasNext, - media_url + numUsers, + media_url, + searchTerm: null, + bottom: false, + params: {} }, mounted() { this.fetchUsers(); }, - created() { + beforeMount() { + // window.addEventListener('scroll', this.onScroll); + + window.addEventListener('scroll', () => { + this.bottom = this.bottomVisible() + }, false) + // this.onScroll() // this.sendState(); + }, + beforeDestroy () { + window.removeEventListener('scroll', () => { + this.bottom = this.bottomVisible() + }); } }); } + + +// const createQueryParams = params => +// Object.keys(params) +// .map(k => `${k}=${encodeURI(params[k])}`) +// .join('&'); + + +// const data2 = { +// var1: 'value1', +// var2: 'value2' +// }; + +// const searchParams = new URLSearchParams(data); + +// searchParams.toString() \ No newline at end of file diff --git a/app/dashboard/templates/dashboard/users.html b/app/dashboard/templates/dashboard/users.html index 8e7f7a80f58..874c9a41fc2 100644 --- a/app/dashboard/templates/dashboard/users.html +++ b/app/dashboard/templates/dashboard/users.html @@ -107,13 +107,13 @@
- - + +
-
+
@@ -150,7 +150,7 @@
- Joined: + Joined:
diff --git a/app/dashboard/views.py b/app/dashboard/views.py index 72a8a30d6df..5b57c9425db 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -777,12 +777,13 @@ def users_fetch(request): # 'keywords': json.dumps([str(key) for key in Keyword.objects.all().values_list('keyword', flat=True)]), # } - + q = request.GET.get('search','') limit = int(request.GET.get('limit', 10)) page = int(request.GET.get('page', 1)) order_by = request.GET.get('order_by', '-created_on') context = {} - user_list = Profile.objects.all().order_by(order_by).cache() + user_list = Profile.objects.all().order_by(order_by).filter(handle__icontains=q).cache() + # all_notifs = Notification.objects.filter(to_user_id=request.user.id).order_by('-id') params = dict() all_pages = Paginator(user_list, limit) From 752ffc8fbccbab92c57d9281bab73e27c6519426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Octavio=20Amuch=C3=A1stegui?= Date: Thu, 4 Apr 2019 00:39:46 -0300 Subject: [PATCH 23/29] comment not active filters --- app/dashboard/templates/dashboard/users.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/dashboard/templates/dashboard/users.html b/app/dashboard/templates/dashboard/users.html index 874c9a41fc2..636ab325293 100644 --- a/app/dashboard/templates/dashboard/users.html +++ b/app/dashboard/templates/dashboard/users.html @@ -67,7 +67,7 @@