diff options
| author | rubenwardy <rw@rubenwardy.com> | 2020-07-09 04:10:09 +0100 |
|---|---|---|
| committer | rubenwardy <rw@rubenwardy.com> | 2020-07-09 04:10:09 +0100 |
| commit | 307b8f8ddea30cb44ad02170b40dd3c0d1d3d6c3 (patch) | |
| tree | 50572120643ec9f6f5da9b68c507bd4b61d1d5ff /app/templates | |
| parent | 9d033acffff319e4f38b98a09ff2519f3f36dc88 (diff) | |
| download | cheatdb-307b8f8ddea30cb44ad02170b40dd3c0d1d3d6c3.tar.xz | |
Add reviews
Fixes #173
Diffstat (limited to 'app/templates')
| -rw-r--r-- | app/templates/macros/reviews.html | 117 | ||||
| -rw-r--r-- | app/templates/packages/review_create_edit.html | 45 | ||||
| -rw-r--r-- | app/templates/packages/view.html | 10 | ||||
| -rw-r--r-- | app/templates/threads/view.html | 19 |
4 files changed, 186 insertions, 5 deletions
diff --git a/app/templates/macros/reviews.html b/app/templates/macros/reviews.html new file mode 100644 index 0000000..fc6673e --- /dev/null +++ b/app/templates/macros/reviews.html @@ -0,0 +1,117 @@ +{% macro render_reviews(reviews) -%} +<ul class="comments mt-4 mb-0"> + {% for review in reviews %} + <li class="row my-2 mx-0"> + <div class="col-md-1 p-1"> + <a href="{{ url_for('users.profile', username=review.author.username) }}"> + <img class="img-responsive user-photo img-thumbnail img-thumbnail-1" src="{{ review.author.getProfilePicURL() }}"> + </a> + </div> + <div class="col-md-auto pl-1 pr-3 pt-2 text-center" style=" font-size: 200%;"> + {% if review.recommends %} + <i class="fas fa-thumbs-up" style="color:#6f6;"></i> + {% else %} + <i class="fas fa-thumbs-down" style="color:#f66;"></i> + {% endif %} + </div> + {% if review.thread %} + {% set reply = review.thread.replies[0] %} + <div class="col pr-0"> + <div class="card"> + <div class="card-header"> + <a class="author {{ reply.author.rank.name }}" + href="{{ url_for('users.profile', username=reply.author.username) }}"> + {{ reply.author.display_name }} + </a> + + <a name="reply-{{ reply.id }}" class="text-muted float-right" + href="{{ url_for('threads.view', id=review.thread.id) }}#reply-{{ reply.id }}"> + {{ reply.created_at | datetime }} + </a> + </div> + + <div class="card-body"> + <p> + <strong>{{ review.thread.title }}</strong> + </p> + + {{ reply.comment | markdown }} + + <a class="btn btn-primary" href="{{ url_for('threads.view', id=review.thread.id) }}"> + <i class="fas fa-comments mr-2"></i> + {{ _("%(num)d comments", num=review.thread.replies.count() - 1) }} + </a> + </div> + </div> + </div> + {% endif %} + </li> + {% endfor %} +</ul> +{% endmacro %} + + +{% macro render_review_form(package, current_user) -%} + <div class="card mt-0 mb-4 "> + <div class="card-header"> + {{ _("Review") }} + </div> + <form method="post" action="{{ url_for('packages.review', author=package.author.username, name=package.name) }}" class="card-body"> + <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" /> + <p> + {{ _("Do you recommend this %(type)s?", type=package.type.value | lower) }} + </p> + + <div class="btn-group btn-group-toggle" data-toggle="buttons"> + <label class="btn btn-primary"> + <i class="fas fa-thumbs-up mr-2"></i> + <input type="radio" name="recommends" id="yes" autocomplete="off"> {{ _("Yes") }} + </label> + <label class="btn btn-primary"> + <i class="fas fa-thumbs-down mr-2"></i> + <input type="radio" name="recommends" id="no" autocomplete="off"> {{ _("No") }} + </label> + </div> + + <p class="mt-4 mb-3"> + {{ _("Why or why not? Try to be constructive") }} + </p> + + <div class="form-group"> + <label for="title">{{ _("Title") }}</label> + <input class="form-control" id="title" name="title" required="" type="text"> + </div> + + <textarea class="form-control markdown" required maxlength=500 name="comment"></textarea><br /> + <input class="btn btn-primary" type="submit" value="{{ _('Post Review') }}" /> + </form> + </div> +{% endmacro %} + + +{% macro render_review_preview(package, current_user) -%} + <input type="hidden" name="csrf_token" value="{{ csrf_token() }}" /> + <div class="card mt-0 mb-4 "> + <div class="card-header"> + {{ _("Review") }} + </div> + <div class="card-body"> + <p> + {{ _("Do you recommend this %(type)s?", type=package.type.value | lower) }} + </p> + + {% set review_url = url_for('packages.review', author=package.author.username, name=package.name) %} + + <div class="btn-group"> + <a class="btn btn-primary" href="{{ url_for('user.login', r=review_url) }}"> + <i class="fas fa-thumbs-up mr-2"></i> + {{ _("Yes") }} + </a> + <a class="btn btn-primary" href="{{ url_for('user.login', r=review_url) }}"> + <i class="fas fa-thumbs-down mr-2"></i> + {{ _("No") }} + </a> + </div> + </div> + </div> +{% endmacro %} diff --git a/app/templates/packages/review_create_edit.html b/app/templates/packages/review_create_edit.html new file mode 100644 index 0000000..2f475cd --- /dev/null +++ b/app/templates/packages/review_create_edit.html @@ -0,0 +1,45 @@ +{% extends "base.html" %} + +{% block title %} + {{ _("Review") }} +{% endblock %} + +{% block content %} + +<h1>{{ _("Review") }}</h1> + +{% from "macros/forms.html" import render_field, render_submit_field, render_radio_field %} +<form method="POST" action="" enctype="multipart/form-data"> + {{ form.hidden_tag() }} + <div class="row mt-0 mb-4 comments mx-0"> + <div class="col-md-1 p-1"> + <img class="img-responsive user-photo img-thumbnail img-thumbnail-1" src="{{ current_user.getProfilePicURL() }}"> + </div> + <div class="col"> + <div class="card"> + <div class="card-header {{ current_user.rank.name }}"> + {{ current_user.display_name }} + <a name="reply"></a> + </div> + <div class="card-body"> + <p> + {{ _("Do you recommend this %(type)s?", type=package.type.value | lower) }} + </p> + {{ render_radio_field(form.recommends) }} + + <p class="mt-4 mb-3"> + {{ _("Why or why not? Try to be constructive") }} + </p> + + {{ render_field(form.title) }} + {{ render_field(form.comment, label="", class_="m-0", fieldclass="form-control markdown") }} <br /> + {{ render_submit_field(form.submit) }} + </div> + </div> + </div> + </div> + +</form> + + +{% endblock %} diff --git a/app/templates/packages/view.html b/app/templates/packages/view.html index cd7ba9d..3a8084d 100644 --- a/app/templates/packages/view.html +++ b/app/templates/packages/view.html @@ -459,6 +459,16 @@ <div style="clear: both;"></div> + <h3>Ratings and Reviews</h3> + + {% from "macros/reviews.html" import render_reviews, render_review_form, render_review_preview %} + {% if current_user.is_authenticated %} + {{ render_review_form(package, current_user) }} + {% else %} + {{ render_review_preview(package) }} + {% endif %} + {{ render_reviews(package.reviews) }} + {# {% if current_user.is_authenticated or requests %} <h3>Edit Requests</h3> diff --git a/app/templates/threads/view.html b/app/templates/threads/view.html index 13097fe..b91f866 100644 --- a/app/templates/threads/view.html +++ b/app/templates/threads/view.html @@ -19,12 +19,21 @@ Threads {% endif %} {% endif %} - <h1>{% if thread.private %}🔒 {% endif %}{{ thread.title }}</h1> - - {% if thread.package or current_user.is_authenticated %} - {% if thread.package %} - <p>Package: <a href="{{ thread.package.getDetailsURL() }}">{{ thread.package.title }}</a></p> + <h1> + {% if thread.review %} + {% if thread.review.recommends %} + <i class="fas fa-thumbs-up mr-2" style="color:#6f6;"></i> + {% else %} + <i class="fas fa-thumbs-down mr-2" style="color:#f66;"></i> + {% endif %} {% endif %} + {% if thread.private %}🔒 {% endif %}{{ thread.title }} + </h1> + + {% if thread.package %} + <p> + Package: <a href="{{ thread.package.getDetailsURL() }}">{{ thread.package.title }}</a> + </p> {% endif %} {% if thread.private %} |
