fix: single thread without refresh
This commit is contained in:
parent
4e8f42288f
commit
e7ad5f2c29
5 changed files with 38 additions and 28 deletions
|
|
@ -90,20 +90,16 @@ const publish_message = (data) => {
|
|||
const doctype = decodeURIComponent($(".discussions-parent").attr("data-doctype"));
|
||||
const docname = decodeURIComponent($(".discussions-parent").attr("data-docname"));
|
||||
const topic = data.topic_info;
|
||||
const single_thread = $(".is-single-thread").length;
|
||||
const first_topic = !$(".reply-card").length;
|
||||
const document_match_found = doctype == topic.reference_doctype && docname == topic.reference_docname;
|
||||
|
||||
console.log(topic, doctype, topic.reference_doctype, docname, topic.reference_docname, doctype == topic.reference_doctype, docname == topic.reference_docname)
|
||||
console.log(topic.owner, frappe.session.user, topic.owner == frappe.session.user)
|
||||
|
||||
console.log(topic.owner == frappe.session.user && doctype == topic.reference_doctype && docname == topic.reference_docname)
|
||||
console.log(topic.title)
|
||||
if ($(`.discussion-on-page[data-topic=${topic.name}]`).length) {
|
||||
console.log("if")
|
||||
post_message_cleanup();
|
||||
$('<div class="card-divider-dark mb-8"></div>' + data.template)
|
||||
.insertBefore(`.discussion-on-page[data-topic=${topic.name}] .discussion-form`);
|
||||
|
||||
} else if (doctype == topic.reference_doctype && docname == topic.reference_docname && $(".reply-card").length) {
|
||||
console.log("elif")
|
||||
} else if (!first_topic && !single_thread && document_match_found) {
|
||||
post_message_cleanup();
|
||||
data.new_topic_template = style_avatar_frame(data.new_topic_template);
|
||||
|
||||
|
|
@ -115,9 +111,14 @@ const publish_message = (data) => {
|
|||
$(".sidebar-topic").first().click();
|
||||
}
|
||||
|
||||
} else if (topic.owner == frappe.session.user && doctype == topic.reference_doctype && docname == topic.reference_docname) {
|
||||
} else if (single_thread && document_match_found) {
|
||||
post_message_cleanup();
|
||||
data.template = style_avatar_frame(data.template);
|
||||
$(data.template).insertBefore(`.discussion-form`);
|
||||
$(".discussion-on-page").attr("data-topic", topic.name);
|
||||
|
||||
} else if (topic.owner == frappe.session.user && document_match_found) {
|
||||
post_message_cleanup();
|
||||
console.log("in")
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,21 +2,22 @@
|
|||
{"reference_doctype": doctype, "reference_docname": docname}, ["name", "title", "owner", "creation"]) %}
|
||||
|
||||
|
||||
<div class="discussions-parent" data-doctype="{{ doctype | urlencode }}" data-docname="{{ docname | urlencode }}">
|
||||
<div class="discussions-parent {% if single_thread %} is-single-thread {% endif %}"
|
||||
data-doctype="{{ doctype | urlencode }}" data-docname="{{ docname | urlencode }}">
|
||||
|
||||
{% include "frappe/templates/discussions/topic_modal.html" %}
|
||||
|
||||
<div class="discussions-header">
|
||||
<span class="course-home-headings">{{ _(title) }}</span>
|
||||
{% if topics %}
|
||||
{% if topics and not single_thread %}
|
||||
{% include "frappe/templates/discussions/button.html" %}
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="common-card-style thread-card {% if topics | length and not single_thread %} discussions-card {% endif %} ">
|
||||
{% if topics %}
|
||||
{% if topics and not single_thread %}
|
||||
|
||||
|
||||
{% if not single_thread %}
|
||||
<div class="discussions-sidebar">
|
||||
{% include "frappe/templates/discussions/search.html" %}
|
||||
|
||||
|
|
@ -25,7 +26,6 @@
|
|||
{% include "frappe/templates/discussions/sidebar.html" %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="mr-2" id="discussion-group">
|
||||
{% for topic in topics %}
|
||||
|
|
@ -33,10 +33,9 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% elif not topics and single_thread %}
|
||||
<div class="discussion-on-page">
|
||||
{% include "frappe/templates/discussions/comment_box.html" %}
|
||||
</div>
|
||||
{% elif single_thread %}
|
||||
{% set topic = topics[0] if topics | length else None %}
|
||||
{% include "frappe/templates/discussions/reply_section.html" %}
|
||||
|
||||
{% else %}
|
||||
<div class="no-discussions" id="no-discussions">
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@
|
|||
<div class="reply-card">
|
||||
{% set member = frappe.db.get_value("User", reply.owner, ["name", "full_name", "username"], as_dict=True) %}
|
||||
<div class="d-flex align-items-center small mb-2">
|
||||
{% if loop.index == 1 %}
|
||||
{% if loop.index == 1 or single_thread %}
|
||||
{{ avatar(reply.owner) }}
|
||||
{% endif %}
|
||||
<a class="button-links {% if loop.index == 1 %} ml-2 {% endif %}" {% if get_profile_url %} href="{{ get_profile_url(member.username) }}" {% endif %}>
|
||||
<a class="button-links {% if loop.index == 1 or single_thread %} ml-2 {% endif %}" {% if get_profile_url %} href="{{ get_profile_url(member.username) }}" {% endif %}>
|
||||
{{ member.full_name }}
|
||||
</a>
|
||||
<div class="ml-3 frappe-timestamp" data-timestamp="{{ reply.creation }}"> {{ frappe.utils.pretty_date(reply.creation) }} </div>
|
||||
|
|
|
|||
|
|
@ -1,14 +1,23 @@
|
|||
{% if topic %}
|
||||
|
||||
{% set replies = frappe.get_all("Discussion Reply", {"topic": topic.name},
|
||||
["reply", "owner", "creation"], order_by="creation")%}
|
||||
|
||||
<div class="collapse discussion-on-page" id="t{{ topic.name }}" data-topic="{{ topic.name }}"
|
||||
data-parent="#discussion-group">
|
||||
{% endif %}
|
||||
|
||||
<div class="collapse discussion-on-page" data-parent="#discussion-group"
|
||||
{% if topic %} id="t{{ topic.name }}" data-topic="{{ topic.name }}" {% endif %}>
|
||||
|
||||
{% if not single_thread %}
|
||||
<div class="button is-default back">
|
||||
{{ _("Back") }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if topic %}
|
||||
<div class="course-home-headings p-0">{{ topic.title }}</div>
|
||||
{% endif %}
|
||||
|
||||
{% for reply in replies %}
|
||||
{% include "frappe/templates/discussions/reply_card.html" %}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ class DiscussionReply(Document):
|
|||
def after_insert(self):
|
||||
|
||||
replies = frappe.db.count("Discussion Reply", {"topic": self.topic})
|
||||
topic_info = frappe.get_all("Discussion Topic",
|
||||
{"name": self.topic},
|
||||
["reference_doctype", "reference_docname", "name", "title", "owner", "creation"])
|
||||
|
||||
template = frappe.render_template("frappe/templates/discussions/reply_card.html", {
|
||||
"reply": self,
|
||||
"topic": {
|
||||
|
|
@ -15,13 +19,10 @@ class DiscussionReply(Document):
|
|||
},
|
||||
"loop": {
|
||||
"index": replies
|
||||
}
|
||||
},
|
||||
"single_thread": True if not topic_info[0].title else False
|
||||
})
|
||||
|
||||
topic_info = frappe.get_all("Discussion Topic",
|
||||
{"name": self.topic},
|
||||
["reference_doctype", "reference_docname", "name", "title", "owner", "creation"])
|
||||
|
||||
sidebar = frappe.render_template("frappe/templates/discussions/sidebar.html", {
|
||||
"topic": topic_info[0]
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue