contentdb/app/templates/macros/reviews.html

194 lines
6.7 KiB
HTML

{% macro render_review_vote(review, current_user, next_url) %}
{% set (positive, negative, is_positive) = review.get_totals(current_user) %}
<form class="review-helpful-vote" method="post" action="{{ review.get_vote_url(next_url) }}">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<div class="btn-group">
<button class="btn {% if is_positive == true %}btn-primary{% else %}btn-secondary{% endif %}" name="is_positive" value="yes">
{{ _("Helpful") }}
{% if positive > 0 %}
<span class="badge bg-light text-dark ms-1">{{ positive }}</span>
{% endif %}
</button>
<button class="btn {% if is_positive == false %}btn-primary{% else %}btn-secondary{% endif %}" name="is_positive" value="no">
{{ _("Unhelpful") }}
{% if negative > 0 %}
<span class="badge bg-light text-dark ms-1">{{ negative }}</span>
{% endif %}
</button>
</div>
</form>
{% endmacro %}
{% macro render_reviews(reviews, current_user, show_package_link=False) -%}
<ul class="comments mt-4 mb-0">
{% for review in reviews %}
{% set review_anchor = "review-" + (review.id | string) %}
<li class="row my-2 mx-0">
<a id="{{ review_anchor }}"></a>
<div class="col-md-1 p-1">
<a href="{{ url_for('users.profile', username=review.author.username) }}">
<img class="img-fluid user-photo img-thumbnail img-thumbnail-1"
src="{{ review.author.get_profile_pic_url() }}" loading="lazy">
</a>
</div>
<div class="col-md-auto ps-1 pe-3 pt-2 text-center" style=" font-size: 200%;">
{% if review.rating > 3 %}
<i class="fas fa-thumbs-up" style="color:#6f6;"></i>
{% elif review.rating < 3 %}
<i class="fas fa-thumbs-down" style="color:#f66;"></i>
{% else %}
<i class="fas fa-minus" style="color:#999"></i>
{% endif %}
</div>
{% if review.thread %}
{% set reply = review.thread.first_reply %}
<div class="col pr-0">
<div class="card">
<div class="card-header">
<a class="author {{ review.author.rank.name }}"
href="{{ url_for('users.profile', username=review.author.username) }}">
{{ review.author.display_name }}
</a>
<a name="reply-{{ reply.id }}" class="text-muted float-end"
href="{{ url_for('threads.view', id=review.thread.id) }}#reply-{{ reply.id }}">
{{ review.created_at | datetime }}
</a>
</div>
<div class="card-body markdown">
{% if current_user == review.author %}
<a class="btn btn-primary btn-sm ms-1 float-end"
href="{{ review.package.get_url('packages.review') }}">
<i class="fas fa-pen"></i>
</a>
{% endif %}
<p>
<strong>{{ review.thread.title }}</strong>
</p>
{{ reply.comment | markdown }}
<div class="btn-toolbar mt-2 mb-0">
{% if show_package_link %}
<a class="btn btn-primary me-1" href="{{ review.package.get_url('packages.view') }}">
{{ _("%(title)s by %(author)s",
title="<b>" | safe + review.package.title + "</b>" | safe,
author=review.package.author.display_name) }}
</a>
{% endif %}
<a class="btn {% if review.thread.replies_count > 1 %} btn-primary {% else %} btn-secondary {% endif %} me-1"
href="{{ url_for('threads.view', id=review.thread.id) }}">
<i class="fas fa-comments me-2"></i>
{{ _("%(num)d comments", num=review.thread.replies_count - 1) }}
</a>
{{ render_review_vote(review, current_user, url_set_anchor(review_anchor)) }}
</div>
</div>
</div>
</div>
{% endif %}
</li>
{% else %}
<li>
<i>{{ _("No reviews, yet.") }}</i>
</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="{{ package.get_url('packages.review') }}" class="card-body">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<p>
{{ _("Do you recommend this %(type)s?", type=package.type.text | lower) }}
</p>
<div class="btn-group" role="group">
<input type="radio" class="btn-check" name="rating" id="rating-5" value="5" autocomplete="off">
<label class="btn btn-primary" for="rating-5">
<i class="fas fa-thumbs-up me-2"></i>
{{ _("Yes") }}
</label>
<input type="radio" class="btn-check" name="rating" id="rating-3" value="3" autocomplete="off">
<label class="btn btn-primary" for="rating-3">
<i class="fas fa-minus me-2"></i>
{{ _("Neutral") }}
</label>
<input type="radio" class="btn-check" name="rating" id="rating-1" value="1" autocomplete="off">
<label class="btn btn-primary" for="rating-1">
<i class="fas fa-thumbs-down me-2"></i>
{{ _("No") }}
</label>
</div>
<p class="mt-4 mb-3">
{{ _("Why or why not? Try to be constructive") }}
</p>
<div class="form-group mb-3">
<label for="title" class="form-label">{{ _("Title") }}</label>
<span class="ms-1 text-danger">
<small>
<i class="fas fa-asterisk"></i>
</small>
</span>
<span class="ms-3 text-muted">
{{ _("Required") }}
</span>
<input class="form-control" id="title" name="title" required="" type="text">
</div>
<textarea class="form-control markdown" required maxlength=2000 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>
<form method="post" action="{{ package.get_url('packages.review') }}" class="card-body">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<p>
{{ _("Do you recommend this %(type)s?", type=package.type.text | lower) }}
</p>
<div class="btn-toolbar" role="toolbar">
<div class="btn-group me-2">
<button class="btn btn-primary" name="rating" value="5">
<i class="fas fa-thumbs-up me-1"></i>
{{ _("Yes") }}
</button>
<button class="btn btn-primary" name="rating" value="3">
<i class="fas fa-minus me-1"></i>
{{ _("Neutral") }}
</button>
<button class="btn btn-primary" name="rating" value="1">
<i class="fas fa-thumbs-down me-1"></i>
{{ _("No") }}
</button>
</div>
<div class="btn-group">
<a class="btn btn-secondary" href="{{ package.issueTracker or url_for('threads.new', pid=package.id) }}" rel="ugc">
<i class="fas fa-bug me-1"></i>
{{ _("Report an Issue") }}
</a>
</div>
</div>
</form>
</div>
{% endmacro %}