Skip to content

Commit

Permalink
Merge pull request #85 from LangCorrect/various-fixes
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
danielzeljko committed Aug 19, 2023
2 parents 9aab49e + 2ecd8f2 commit a0cca5f
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 35 deletions.
5 changes: 5 additions & 0 deletions langcorrect/corrections/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def make_corrections(request, slug):

overall_feedback = OverallFeedback.available_objects.filter(post=post, user=current_user).first()

is_edit = False

for post_row in all_post_rows:
previous_correction = CorrectedRow.available_objects.filter(
post_row_id=post_row.id, user=current_user
Expand All @@ -125,13 +127,16 @@ def make_corrections(request, slug):
post_row.show_form = True
post_row.is_action_taken = True
post_row.action = "corrected"
is_edit |= True
elif previous_perfect:
post_row.is_action_taken = True
post_row.action = "perfect"
is_edit |= True

context = {}
context["post_rows"] = all_post_rows
context["post"] = post
context["overall_feedback"] = overall_feedback.comment if overall_feedback else ""
context["is_edit"] = is_edit

return render(request, "corrections/make_corrections.html", context)
33 changes: 27 additions & 6 deletions langcorrect/templates/corrections/make_corrections.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,18 @@
</div>
<div class="d-flex justify-content-end">
<div class="d-flex gap-3">
<button id="discard-btn" class="btn btn-outline-danger">{% translate "Discard" %}</button>
<button type="submit" class="btn btn-primary">{% translate "Submit" %}</button>
<button id="modal-btn"
class="btn btn-outline-danger"
data-bs-config='{ "actionLink":"{% url "posts:detail" post.slug %}"}'>
{% translate "Discard" %}
</button>
<button type="submit" class="btn btn-primary">
{% if is_edit %}
{% translate "Update" %}
{% else %}
{% translate "Submit" %}
{% endif %}
</button>
</div>
</div>
</div>
Expand All @@ -92,7 +102,7 @@
{% endblock content %}
{% block modal %}
{{ block.super }}
{% include "modals/discard_corrections.html" %}
{% include "modals/discard_modal.html" %}
{% endblock modal %}
{% block inline_javascript %}
<script>
Expand All @@ -108,10 +118,21 @@

const textareas = document.querySelectorAll("textarea").forEach(textarea => autosize(textarea));

const discardBtn = document.getElementById("discard-btn");
discardBtn.addEventListener("click", function(e) {
const discardModalBtn = document.getElementById("modal-btn");
discardModalBtn.addEventListener("click", function(e) {
e.preventDefault();
const modal = new bootstrap.Modal("#discard-corrections-modal");

const config = JSON.parse(discardModalBtn.getAttribute("data-bs-config"));
const {
actionLink
} = config;

if (actionLink) {
const discardBtn = document.getElementById("action-link");
discardBtn.href = actionLink;
}

const modal = new bootstrap.Modal("#discard-modal");
modal.show();
})
});
Expand Down
15 changes: 5 additions & 10 deletions langcorrect/templates/corrections/partials/correction.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<div class="d-flex justify-content-between border-bottom">
<div class="p-3">
<p class="{% if correction.type == 'perfect' %} text-success {% endif %}">
<i class="fa-solid {% if correction.type == 'perfect' %} fa-check {% else %} fa-xmark text-danger {% endif %}"></i> {{ correction.correction|safe }}
</p>
{% if correction.note %}<p class="mb-0 text-secondary">{{ correction.note|linebreaksbr }}</p>{% endif %}
</div>
<button class="btn">
<i class="fa-solid fa-ellipsis-vertical"></i>
</button>
<div class="p-3 border-bottom">
<p class="{% if correction.type == 'perfect' %} text-success {% endif %} mb-0">
<i class="fa-solid {% if correction.type == 'perfect' %} fa-check {% else %} fa-xmark text-danger {% endif %}"></i> {{ correction.correction|safe }}
</p>
{% if correction.note %}<p class="mt-3 mb-0 text-secondary">{{ correction.note|linebreaksbr }}</p>{% endif %}
</div>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load i18n %}

<div id="discard-corrections-modal" class="modal" tabindex="-1">
<div id="discard-modal" class="modal" tabindex="-1">
<div class="modal-dialog modal-dialog-centered modal-sm">
<div class="modal-content">
<div class="modal-header">
Expand All @@ -15,7 +15,7 @@ <h5 class="modal-title">{% translate "Are you sure?" %}</h5>
<button type="button"
class="btn btn-outline-secondary"
data-bs-dismiss="modal">{% translate "Cancel" %}</button>
<a href="{% url 'posts:detail' post.slug %}" class="btn btn-danger">{% translate "Discard" %}</a>
<a id="action-link" href="" class="btn btn-danger">{% translate "Discard" %}</a>
</div>
</div>
</div>
Expand Down
6 changes: 3 additions & 3 deletions langcorrect/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
</li>
{% endif %}
{% if request.user.is_authenticated %}
<li class="d-none d-md-block">
<li class="d-none d-md-block me-2">
<a href="{% url 'posts:create' %}" class="btn btn-primary">
<i class="fas fa-pen fa-fw"></i>
{% translate "Write" %}
Expand All @@ -84,11 +84,11 @@
{{ unread_count }}
</button>
</li>
<li class="dropdown d-inline-block">
<li class="dropdown d-inline-block mt-2 mt-md-0">
<div class="pointer" data-bs-toggle="dropdown" aria-expanded="false">
<img src="{{ request.user.avatar }}" alt="profile" height="38" />
</div>
<div class="dropdown-menu dropdown-menu-end py-0">
<div class="dropdown-menu dropdown-menu-end py-0 mt-2">
<a class="dropdown-item py-2 bg-transparent"
href="{{ request.user.get_absolute_url }}">
<div class="d-flex align-items-center">
Expand Down
62 changes: 48 additions & 14 deletions langcorrect/templates/posts/post_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@
{{ post.title }}
{% endblock title %}
{% block content %}
<div class="alert alert-warning">
Please be aware that the system for automatically saving drafts of your content is currently
unavailable. If you navigate away from the page before publishing your content, you will lose any
unsaved changes.
We apologize for the inconvenience and appreciate your patience while we work to re-implement the
auto-save feature.
</div>
{% if prompt or post.prompt %}
<p>
<strong>{{ prompt.content }}{{ post.prompt.content }}</strong>
Expand All @@ -23,13 +16,54 @@
{% csrf_token %}
{{ form|crispy }}
<div class="d-flex justify-content-end">
<button type="submit" class="btn btn-primary">
{% if is_edit %}
{% translate "Update" %}
{% else %}
{% translate "Submit" %}
{% endif %}
</button>
<div class="d-flex gap-3">
<button id="modal-btn"
class="btn btn-outline-danger"
data-bs-config='{"actionLink": "{% url "posts:list" %}"}'>
{% if is_edit %}
{% translate "Cancel" %}
{% else %}
{% translate "Discard" %}
{% endif %}
</button>
<button type="submit" class="btn btn-primary">
{% if is_edit %}
{% translate "Update" %}
{% else %}
{% translate "Publish" %}
{% endif %}
</button>
</div>
</div>
</form>
{% endblock content %}
{% block modal %}
{{ block.super }}
{% include "modals/discard_modal.html" %}
{% endblock modal %}
{% block inline_javascript %}
<script>
document.addEventListener("DOMContentLoaded", function() {
const discardModalBtn = document.getElementById("modal-btn");

discardModalBtn.addEventListener("click", function(e) {
e.preventDefault()

const config = JSON.parse(discardModalBtn.getAttribute("data-bs-config"));
const {
actionLink
} = config;

if (actionLink) {
const discardBtn = document.getElementById("action-link");
discardBtn.href = actionLink;
}

const modal = new bootstrap.Modal("#discard-modal");
modal.show();
});

const textareas = document.querySelectorAll("textarea").forEach(textarea => autosize(textarea));
});
</script>
{% endblock inline_javascript %}

0 comments on commit a0cca5f

Please sign in to comment.