fix(timeline): Add attachment logs

This commit is contained in:
Suraj Shetty 2020-09-03 13:58:05 +05:30
parent 230db3a9ee
commit 245c261b08
3 changed files with 29 additions and 11 deletions

View file

@ -37,7 +37,9 @@ class Comment(Document):
'Like': 'like_logs',
'Assigned': 'assignment_logs',
'Assignment Completed': 'assignment_logs',
'Comment': 'comments'
'Comment': 'comments',
'Attachment': 'attachment_logs',
'Attachment Removed': 'attachment_logs',
}
key = key_map.get(self.comment_type)
if not key: return

View file

@ -91,6 +91,7 @@ def get_docinfo(doc=None, doctype=None, name=None):
raise frappe.PermissionError
frappe.response["docinfo"] = {
"attachments": get_attachments(doc.doctype, doc.name),
"attachment_logs": get_comments(doc.doctype, doc.name, 'attachment'),
"communications": _get_communications(doc.doctype, doc.name),
'comments': get_comments(doc.doctype, doc.name),
'total_comments': len(json.loads(doc.get('_comments') or '[]')),
@ -137,9 +138,12 @@ def get_comments(doctype, name, comment_type='Comment'):
if comment_type == 'share':
comment_types = ['Shared', 'Unshared']
if comment_type == 'assignment':
elif comment_type == 'assignment':
comment_types = ['Assignment Completed', 'Assigned']
elif comment_type == 'attachment':
comment_types = ['Attachment', 'Attachment Removed']
comments = frappe.get_all('Comment', fields = ['name', 'creation', 'content', 'owner'], filters=dict(
reference_doctype = doctype,
reference_name = name,

View file

@ -130,6 +130,7 @@ frappe.ui.form.NewTimeline = class {
this.timeline_items.push(...this.get_like_timeline_contents());
this.timeline_items.push(...this.get_custom_timeline_contents());
this.timeline_items.push(...this.get_assignment_timeline_contents());
this.timeline_items.push(...this.get_attachment_timeline_contents());
}
// attachments
// milestones
@ -245,10 +246,10 @@ frappe.ui.form.NewTimeline = class {
get_share_timeline_contents() {
let share_timeline_contents = [];
(this.doc_info.share_logs || []).forEach(share => {
(this.doc_info.share_logs || []).forEach(share_log => {
share_timeline_contents.push({
creation: share.creation,
content: share.content,
creation: share_log.creation,
content: share_log.content,
});
});
return share_timeline_contents;
@ -256,23 +257,34 @@ frappe.ui.form.NewTimeline = class {
get_assignment_timeline_contents() {
let assignment_timeline_contents = [];
(this.doc_info.assignment_logs || []).forEach(assignment => {
(this.doc_info.assignment_logs || []).forEach(assignment_log => {
assignment_timeline_contents.push({
creation: assignment.creation,
content: assignment.content,
creation: assignment_log.creation,
content: assignment_log.content,
});
});
return assignment_timeline_contents;
}
get_attachment_timeline_contents() {
let attachment_timeline_contents = [];
(this.doc_info.attachment_logs || []).forEach(attachment_log => {
attachment_timeline_contents.push({
creation: attachment_log.creation,
content: `${this.get_user_link(attachment_log.owner)} ${attachment_log.content}`,
});
});
return attachment_timeline_contents;
}
get_like_timeline_contents() {
let like_timeline_contents = [];
(this.doc_info.like_logs || []).forEach(like => {
(this.doc_info.like_logs || []).forEach(like_log => {
like_timeline_contents.push({
icon: 'heart',
icon_size: 'sm',
creation: like.creation,
content: __('{0} Liked', [this.get_user_link(like.owner)]),
creation: like_log.creation,
content: __('{0} Liked', [this.get_user_link(like_log.owner)]),
});
});
return like_timeline_contents;