From 82f1e0c11a78f9d89f3c06a06e34665744d6cb68 Mon Sep 17 00:00:00 2001 From: Keshav Garg Date: Thu, 1 Aug 2019 16:06:42 +0530 Subject: [PATCH] community/: Add a feedback form Closes https://github.com/coala/community/issues/274 --- community/forms.py | 15 ++++++++++++ community/views.py | 12 ++++++++- static/css/main.css | 35 +++++++++++++++++++++----- static/js/forms.js | 25 +++++++++++++++++++ static/js/main.js | 10 ++++++++ templates/base.html | 60 +++++++++++++++++++++++++++++++++++++++------ 6 files changed, 142 insertions(+), 15 deletions(-) diff --git a/community/forms.py b/community/forms.py index 729abded..133587e8 100644 --- a/community/forms.py +++ b/community/forms.py @@ -293,3 +293,18 @@ class NewcomerPromotion(forms.Form): max_length=50, label='GitHub Username', widget=forms.TextInput(attrs={'autocomplete': 'off', 'hidden': True}) ) + + +class Feedback(forms.Form): + username = forms.CharField( + label='GitHub Username', required=False, + widget=forms.TextInput(attrs={'autocomplete': 'off'}) + ) + feedback = forms.CharField( + max_length=1000, label='Feedback', + widget=forms.Textarea(attrs={'autocomplete': 'off'}) + ) + experience = forms.CharField( + required=False, + widget=forms.TextInput(attrs={'autocomplete': 'off', 'hidden': True}) + ) diff --git a/community/views.py b/community/views.py index 8d456db6..d1db20ad 100644 --- a/community/views.py +++ b/community/views.py @@ -19,7 +19,8 @@ OrganizationMentor, GSOCStudent, AssignIssue, - NewcomerPromotion + NewcomerPromotion, + Feedback ) from data.models import Team from gamification.models import Participant as GamificationParticipant @@ -50,6 +51,14 @@ def initialize_org_context_details(): return org_details +def get_feedback_form_variables(context): + context['feedback_form'] = Feedback() + context['feedback_form_name'] = os.environ.get( + 'FEEDBACK_FORM_NAME', None + ) + return context + + def get_newcomer_promotion_form_variables(context): context['newcomer_promotion_form'] = NewcomerPromotion() context['newcomer_promotion_form_name'] = os.environ.get( @@ -105,6 +114,7 @@ def get_all_community_forms(context): context = get_gsoc_student_form_variables(context) context = get_assign_issue_form_variables(context) context = get_newcomer_promotion_form_variables(context) + context = get_feedback_form_variables(context) return context diff --git a/static/css/main.css b/static/css/main.css index 5c00f1d0..ffe8a28f 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -38,7 +38,8 @@ body { justify-content: center; } -.community-form { +.community-form, +.feedback { position: fixed; width: 70%; min-width: 330px; @@ -52,25 +53,31 @@ body { overflow-x: auto; } -.community-form form { +.community-form form, +.feedback form { padding-bottom: inherit; } -.community-form form label { +.community-form form label, +.feedback form label, +.experience { font-weight: bold; font-size: 1.5rem; color: darkcyan; } -.community-form form p{ +.community-form form p, +.feedback form p { margin: 0; } -.community-form form textarea{ +.community-form form textarea, +.feedback form textarea { margin-top: 10px; } -.community-form form .row{ +.community-form form .row, +.feedback form .row { margin-bottom: 0; } @@ -97,6 +104,17 @@ body { display: none; } +.feedback-icon { + position: fixed; + bottom: 2%; + right: 1%; +} + +.feedback-comment { + width: 80px; + cursor: pointer; +} + .form-popup, .form-submission-popup { width: 100%; @@ -276,6 +294,11 @@ strong { text-align: center; } +.user-feeling-level i { + font-size: 3rem; + cursor: pointer; +} + #user-dropdown li.user-logout { display: none; } diff --git a/static/js/forms.js b/static/js/forms.js index 80d02dc7..f23b8a36 100644 --- a/static/js/forms.js +++ b/static/js/forms.js @@ -7,6 +7,7 @@ $(document).ready(function () { var get_issue_assigned_form_op = $('.get-issue-assigned-form-op'); var participated_in_gsoc_form_op = $('.participated-in-gsoc-form-op'); var mentor_students_form_op = $('.mentor-students-form-op'); + var feedback_form_op = $('.feedback-comment'); var community_google_form = $('.community-google-form'); var newcomer_promotion_form = $('.newcomer-promotion-form'); @@ -14,6 +15,7 @@ $(document).ready(function () { var get_issue_assigned_form = $('.get-issue-assigned-form'); var participated_in_gsoc_form = $('.participated-in-gsoc-form'); var mentor_students_form = $('.mentor-students-form'); + var feedback_form = $('.feedback'); var is_user_authenticated = Cookies.get('authenticated'); var authenticated_username = Cookies.get('username'); @@ -28,6 +30,11 @@ $(document).ready(function () { '?form_submitted=True&form_type=community' ); + $('.feedback-form').attr( + 'action',window.location.pathname + + '?form_submitted=True&form_type=feedback' + ); + $.getJSON("/static/contributors-data.json", function (data) { var contributor_data = data[authenticated_username]; var teams = contributor_data.teams; @@ -87,6 +94,24 @@ $(document).ready(function () { display_form_or_error(mentor_students_form); }); + feedback_form_op.on('click', function () { + feedback_form.css('display', 'block'); + $('.user-feeling-level i').on('click', function () { + var experience = $(this).attr('experience'); + $('input[name="experience"]').val(experience); + $('.user-feeling-level i').css('color', 'black'); + if(experience==='Negative'){ + $(this).css('color', 'red'); + } + else if(experience==='Neutral'){ + $(this).css('color', 'blue'); + } + else { + $(this).css('color', 'darkgreen'); + } + }); + }); + $('.community-form :input').focusin(function () { if (is_user_authenticated===undefined && authenticated_username===undefined) { diff --git a/static/js/main.js b/static/js/main.js index f9b2e2c6..5d609874 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -23,6 +23,10 @@ $(document).ready(function(){ ' the validation checks are passed or not. If not, the email' + ' will contain the validation errors. Correct them, if any'; } + else if(formType==='feedback'){ + message = 'Your valuable feedback has been received. Thanks for' + + ' providing feedback.'; + } $('.important-message').text(message); $('.form-submission-popup').css('display', 'block'); } @@ -123,11 +127,17 @@ $(document).ready(function(){ $('.form-popup').css('display', 'block'); }); + $('.feedback form').attr( + 'action',window.location.pathname + + '?form_submitted=True&form_type=feedback' + ); + $('.close-form').click(function () { $('.form-popup').css('display', 'none'); $('.form-submission-popup').css('display', 'none'); $('.oauth-error').css('display', 'none'); $('.community-form').css('display', 'none'); + $('.feedback').css('display', 'none'); $('.community-form form').css('display', 'none'); }); diff --git a/templates/base.html b/templates/base.html index 05dece2e..db21ca9d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -158,17 +158,61 @@
Enjoy Coding 'n' Learning
-
- {% block main-content %} - {% endblock %} +