feat: single thread discussions
This commit is contained in:
parent
73f4f3fb7b
commit
4e8f42288f
6 changed files with 54 additions and 43 deletions
|
|
@ -1,31 +1,35 @@
|
|||
<form class="discussion-form">
|
||||
|
||||
<div class="form-group">
|
||||
<div class="control-input-wrapper">
|
||||
<div class="control-input">
|
||||
<input type="text" autocomplete="off" class="input-with-feedback form-control topic-title" data-fieldtype="Data"
|
||||
data-fieldname="feedback_comments" placeholder="{{ _('Type title') }}" spellcheck="false"></input>
|
||||
</div>
|
||||
{% if not single_thread %}
|
||||
<div class="form-group">
|
||||
<div class="control-input-wrapper">
|
||||
<div class="control-input">
|
||||
<input type="text" autocomplete="off" class="input-with-feedback form-control topic-title"
|
||||
data-fieldtype="Data" data-fieldname="feedback_comments" placeholder="{{ _('Type title') }}"
|
||||
spellcheck="false"></input>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="form-group">
|
||||
<div class="control-input-wrapper">
|
||||
<div class="control-input">
|
||||
<textarea type="text" autocomplete="off" class="input-with-feedback form-control comment-field"
|
||||
data-fieldtype="Text" data-fieldname="feedback_comments" placeholder="{{ _('Type here. Use markdown to format.') }}"
|
||||
spellcheck="false"></textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="control-input-wrapper">
|
||||
<div class="control-input">
|
||||
<textarea type="text" autocomplete="off" class="input-with-feedback form-control comment-field"
|
||||
data-fieldtype="Text" data-fieldname="feedback_comments"
|
||||
placeholder="{{ _('Type here. Use markdown to format.') }}" spellcheck="false"></textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="comment-footer">
|
||||
<div class="small flex-grow-1">
|
||||
{{ _("Press Cmd+Enter to post your comment") }}
|
||||
</div>
|
||||
|
||||
<a class="dark-links cancel-comment hide"> {{ _("Cancel") }} </a>
|
||||
<div class="button is-default submit-discussion pull-right mb-1">
|
||||
{{ _("Post") }} </div>
|
||||
<div class="comment-footer">
|
||||
<div class="small flex-grow-1">
|
||||
{{ _("Press Cmd+Enter to post your comment") }}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<a class="dark-links cancel-comment hide"> {{ _("Cancel") }} </a>
|
||||
<div class="button is-default submit-discussion pull-right mb-1">
|
||||
{{ _("Post") }}
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
|||
|
|
@ -87,18 +87,23 @@ const setup_socket_io = () => {
|
|||
};
|
||||
|
||||
const publish_message = (data) => {
|
||||
const doctype = decodeURIComponent($(".discussions-parent .thread-card").attr("data-doctype"));
|
||||
const docname = decodeURIComponent($(".discussions-parent .thread-card").attr("data-docname"));
|
||||
const doctype = decodeURIComponent($(".discussions-parent").attr("data-doctype"));
|
||||
const docname = decodeURIComponent($(".discussions-parent").attr("data-docname"));
|
||||
const topic = data.topic_info;
|
||||
|
||||
if ($(`.discussion-on-page[data-topic=${topic.name}]`).length) {
|
||||
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) {
|
||||
|
||||
} else if (doctype == topic.reference_doctype && docname == topic.reference_docname && $(".reply-card").length) {
|
||||
console.log("elif")
|
||||
post_message_cleanup();
|
||||
data.new_topic_template = style_avatar_frame(data.new_topic_template);
|
||||
|
||||
|
|
@ -106,13 +111,13 @@ const publish_message = (data) => {
|
|||
$(`#discussion-group`).prepend(data.new_topic_template);
|
||||
|
||||
if (topic.owner == frappe.session.user) {
|
||||
$(".discussion-on-page").collapse();
|
||||
$(".discussion-on-page") && $(".discussion-on-page").collapse();
|
||||
$(".sidebar-topic").first().click();
|
||||
}
|
||||
|
||||
} else if (topic.owner == frappe.session.user
|
||||
&& doctype == topic.reference_docname && docname == topic.reference_docname) {
|
||||
} else if (topic.owner == frappe.session.user && doctype == topic.reference_doctype && docname == topic.reference_docname) {
|
||||
post_message_cleanup();
|
||||
console.log("in")
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
|
|
@ -198,10 +203,10 @@ const submit_discussion = (e) => {
|
|||
const reply = $(".comment-field:visible").val().trim();
|
||||
|
||||
if (reply) {
|
||||
let doctype = $(e.currentTarget).closest(".thread-card").attr("data-doctype");
|
||||
let doctype = $(e.currentTarget).closest(".discussions-parent").attr("data-doctype");
|
||||
doctype = doctype ? decodeURIComponent(doctype) : doctype;
|
||||
|
||||
let docname = $(e.currentTarget).closest(".thread-card").attr("data-docname");
|
||||
let docname = $(e.currentTarget).closest(".discussions-parent").attr("data-docname");
|
||||
docname = docname ? decodeURIComponent(docname) : docname;
|
||||
|
||||
frappe.call({
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
{% set topics = frappe.get_all("Discussion Topic",
|
||||
{"reference_doctype": doctype, "reference_docname": docname}, ["name", "title", "owner", "creation"]) %}
|
||||
|
||||
{% include "frappe/templates/discussions/topic_modal.html" %}
|
||||
|
||||
<div class="discussions-parent">
|
||||
<div class="discussions-parent" 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 %}
|
||||
|
|
@ -11,20 +13,24 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
|
||||
|
||||
<div class="common-card-style thread-card {% if topics | length or not single_thread %} discussions-card {% endif %} "
|
||||
data-doctype="{{ doctype | urlencode }}" data-docname="{{ docname | urlencode }}">
|
||||
<div class="common-card-style thread-card {% if topics | length and not single_thread %} discussions-card {% endif %} ">
|
||||
{% if topics %}
|
||||
|
||||
{% if not single_thread %}
|
||||
<div class="discussions-sidebar">
|
||||
{% include "frappe/templates/discussions/search.html" %}
|
||||
|
||||
{% for topic in topics %}
|
||||
{% set replies = frappe.get_all("Discussion Reply", {"topic": topic.name})%}
|
||||
{% include "frappe/templates/discussions/sidebar.html" %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="mr-2" id="discussion-group">
|
||||
{% for topic in topics %}
|
||||
{% include "frappe/templates/discussions/reply_section.html" %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% elif not topics and single_thread %}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
{% for topic in topics %}
|
||||
{% set replies = frappe.get_all("Discussion Reply", {"topic": topic.name},
|
||||
["reply", "owner", "creation"], order_by="creation")%}
|
||||
|
||||
{% if replies %}
|
||||
<div class="collapse discussion-on-page" id="t{{ topic.name }}" data-topic="{{ topic.name }}"
|
||||
data-parent="#discussion-group">
|
||||
|
||||
|
|
@ -34,5 +32,3 @@
|
|||
{% endif %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
padding: 1rem;
|
||||
}
|
||||
|
||||
.discussions-parent .form-control {
|
||||
.thread-card .form-control {
|
||||
background-color: #FFFFFF;
|
||||
font-size: inherit;
|
||||
color: inherit;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class DiscussionReply(Document):
|
|||
})
|
||||
|
||||
new_topic_template = frappe.render_template("frappe/templates/discussions/reply_section.html", {
|
||||
"topics": topic_info
|
||||
"topic": topic_info[0]
|
||||
})
|
||||
|
||||
frappe.publish_realtime(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue