From 468b067ca75f88a28b43fd44f9b13cbd07bf2f71 Mon Sep 17 00:00:00 2001 From: kvgarg Date: Thu, 13 Jun 2019 09:40:39 +0530 Subject: [PATCH] data/: Re-design the contributors webpage Closes https://github.com/coala/community/issues/258 , https://github.com/coala/community/pull/240 , https://github.com/coala/community/pull/231 , https://github.com/coala/community/pull/141 , https://github.com/coala/community/issues/139 , https://github.com/coala/community/pull/141 , https://github.com/coala/community/issues/140 --- community/urls.py | 4 +- data/urls.py | 4 +- data/views.py | 18 +++-- static/css/contributors.css | 64 ++++++++++++++++++ static/js/contributors.js | 64 ++++++++++++++++++ templates/contributors.html | 131 +++++++++++++++++++++++++----------- 6 files changed, 238 insertions(+), 47 deletions(-) create mode 100644 static/css/contributors.css create mode 100644 static/js/contributors.js diff --git a/community/urls.py b/community/urls.py index c03de2e2..546c9ec3 100644 --- a/community/urls.py +++ b/community/urls.py @@ -11,7 +11,7 @@ from gci.feeds import LatestTasksFeed as gci_tasks_rss from twitter.view_twitter import index as twitter_index from log.view_log import index as log_index -from data.views import index as contributors_index +from data.views import ContributorsListView from gamification.views import index as gamification_index from meta_review.views import index as meta_review_index from inactive_issues.inactive_issues_scraper import inactive_issues_json @@ -110,7 +110,7 @@ def get_organization(): distill_file='log/index.html', ), distill_url( - r'contributors/$', contributors_index, + r'contributors/$', ContributorsListView.as_view(), name='community-data', distill_func=get_index, distill_file='contributors/index.html', diff --git a/data/urls.py b/data/urls.py index a3780aa2..6eb2a98a 100644 --- a/data/urls.py +++ b/data/urls.py @@ -1,7 +1,7 @@ from django.conf.urls import url -from . import views +from .views import ContributorsListView urlpatterns = [ - url(r'^$', views.index, name='index'), + url(r'^$', ContributorsListView.as_view(), name='index'), ] diff --git a/data/views.py b/data/views.py index 40436c72..53cd8a3e 100644 --- a/data/views.py +++ b/data/views.py @@ -1,8 +1,16 @@ +from django.views.generic import TemplateView + +from community.views import get_header_and_footer from data.models import Contributor -from django.shortcuts import render -def index(request): - contributors = Contributor.objects.all() - args = {'contributors': contributors} - return render(request, 'contributors.html', args) +class ContributorsListView(TemplateView): + template_name = 'contributors.html' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context = get_header_and_footer(context) + contrib_objects = Contributor.objects.all() + context['contributors'] = contrib_objects.order_by('-num_commits', + 'name') + return context diff --git a/static/css/contributors.css b/static/css/contributors.css new file mode 100644 index 00000000..b7dd1a9b --- /dev/null +++ b/static/css/contributors.css @@ -0,0 +1,64 @@ +.commits, +.reviews, +.issues-opened { + padding: 0px 5px; +} + +.contributions { + margin: 10px; +} + +.contributions p { + margin: 0px; +} + +.contributors-cards { + display: flex; + justify-content: space-evenly; + flex-flow: row wrap; + margin: 50px; +} + +.contributor-card { + background-color: #efefef; + box-shadow: 0px 0px 25px 2px black; + border-radius: 30px; + margin: 0px 15px 20px 15px; + width: 220px; + border: 5px #c0c5d1 solid; +} + +.contributors-section .fa-close { + display: none; +} + +.contributor-details { + text-align: center; +} + +.contributor-image img { + border-radius: 30px 30px 0px 0px; + width: 210px; +} + +.form-fields { + margin-top: 3%; + width: 40%; + min-width: 300px; +} + +.search-results { + width: 100%; + background-color: transparent; + border-radius: 30px; + overflow: auto; + padding: 0px 20px; + max-height: 150px; + display: none; +} + +.side-border { + border-width: 0px 0px 0px 1px; + border-color: darkgray; + border-style: solid; +} diff --git a/static/js/contributors.js b/static/js/contributors.js new file mode 100644 index 00000000..a6164024 --- /dev/null +++ b/static/js/contributors.js @@ -0,0 +1,64 @@ +$(document).ready(function(){ + var search_input = $('#search'); + var close_icon = $('.contributors-section .fa-close'); + var results_body = $('.search-results-tbody'); + var searched_keyword = null; + + function appendChildren(element, username, el_result_value, + hide_all_contributors){ + var result_td = $('').text(el_result_value); + result_td.id = "td-" + username; + if(hide_all_contributors){ + result_td.on('click', function(){ + var row_id = result_td.id; + var login = row_id.replace('td-', ''); + $('.contributor-card').css('display', 'none'); + $('[login=' + login +']').css('display', 'block'); + $('.search-results').css('display', 'none'); + }); + } + element.append(result_td); + } + + search_input.on('keypress keyup', function(){ + searched_keyword = search_input.val(); + if(searched_keyword === ''){ + $('.search-results').css('display', 'none'); + close_icon.css('display', 'none'); + } + else { + $('.search-results').css('display', 'block'); + close_icon.css('display', 'block'); + var search_by_login = $('[login^=' + searched_keyword +']'); + var search_by_name = $('[name^=' + searched_keyword +']'); + var results_tbody_tr = $('.search-results-tbody tr'); + results_tbody_tr.remove(); + if(search_by_login.length + search_by_name.length === 0 ){ + appendChildren(results_body, null, 'No results found!', false); + } + else { + var all_results = search_by_login.add(search_by_name); + for(var contrib in all_results.get()){ + if(all_results[contrib]){ + var login = all_results[contrib].getAttribute('login'); + var name = all_results[contrib].getAttribute('name'); + var result_value = null; + if(name){ + result_value = login + " (" + name + ")"; + } + else { + result_value = login; + } + appendChildren(results_body, login, result_value, true); + } + } + } + } + }); + + close_icon.on('click', function(){ + $('.contributor-card').css('display', 'block'); + close_icon.css('display', 'none'); + search_input.val(null); + }); +}); diff --git a/templates/contributors.html b/templates/contributors.html index 32abe1a6..bfeac9b5 100644 --- a/templates/contributors.html +++ b/templates/contributors.html @@ -1,40 +1,95 @@ - - - - - - - - - Contributors Data - - -

Details of all the contributors

- - - + + + +
+ {% for contributor in contributors %} +
+
+ +
+
+ + {% if contributor.name %} + {{ contributor.name }} + {% else %} + {{ contributor.login }} + {% endif %}{# if contributor.name #} + +
+
+

{{ contributor.num_commits }}

+

Commits

+
+
+

{{ contributor.reviews }}

+

Reviews

+
+
+

{{ contributor.issues_opened }}

+

Issues

+
+
+
+
+ {% endfor %}{# for contributor in contributors #} +
+ +{% endblock %}