From dc3402c5461d5941a5b47b6fc7ae2c8d3a42037d Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Wed, 1 Jul 2020 10:31:17 +0530 Subject: [PATCH] feat: Option to add custom timeline contents (#10677) --- frappe/desk/form/load.py | 12 +++++++++ .../public/js/frappe/form/footer/timeline.js | 20 +++++++++++--- .../js/frappe/form/templates/timeline.html | 4 +-- .../frappe/form/templates/timeline_item.html | 13 ++++++--- frappe/public/less/form.less | 27 ++++++++++++++++--- 5 files changed, 62 insertions(+), 14 deletions(-) diff --git a/frappe/desk/form/load.py b/frappe/desk/form/load.py index f24f33df07..cacbd3c633 100644 --- a/frappe/desk/form/load.py +++ b/frappe/desk/form/load.py @@ -100,6 +100,7 @@ def get_docinfo(doc=None, doctype=None, name=None): "shared": frappe.share.get_users(doc.doctype, doc.name), "views": get_view_logs(doc.doctype, doc.name), "energy_point_logs": get_point_logs(doc.doctype, doc.name), + "additional_timeline_content": get_additional_timeline_content(doc.doctype, doc.name), "milestones": get_milestones(doc.doctype, doc.name), "is_document_followed": is_document_followed(doc.doctype, doc.name, frappe.session.user), "tags": get_tags(doc.doctype, doc.name), @@ -277,3 +278,14 @@ def get_document_email(doctype, name): def get_automatic_email_link(): return frappe.db.get_value("Email Account", {"enable_incoming": 1, "enable_automatic_linking": 1}, "email_id") + +def get_additional_timeline_content(doctype, docname): + contents = [] + hooks = frappe.get_hooks().get('additional_timeline_content', {}) + methods_for_all_doctype = hooks.get('*', []) + methods_for_current_doctype = hooks.get(doctype, []) + + for method in methods_for_all_doctype + methods_for_current_doctype: + contents.extend(frappe.get_attr(method)(doctype, docname) or []) + + return contents \ No newline at end of file diff --git a/frappe/public/js/frappe/form/footer/timeline.js b/frappe/public/js/frappe/form/footer/timeline.js index 7821a04c50..84f34d4757 100644 --- a/frappe/public/js/frappe/form/footer/timeline.js +++ b/frappe/public/js/frappe/form/footer/timeline.js @@ -120,9 +120,11 @@ frappe.ui.form.Timeline = class Timeline { display_automatic_link_email() { let docinfo = this.frm.get_docinfo(); - if (docinfo.document_email){ + if (docinfo.document_email) { let link = __("Send an email to {0} to link it here", [`${docinfo.document_email}`]); - $('.timeline-email-import').html(link); + const email_link = $('.timeline-email-import'); + email_link.removeClass('hide'); + email_link.html(link); } } @@ -180,12 +182,15 @@ frappe.ui.form.Timeline = class Timeline { // append energy point logs timeline = timeline.concat(this.get_energy_point_logs()); + // custom contents + timeline = timeline.concat(this.get_additional_timeline_content()); + // append milestones timeline = timeline.concat(this.get_milestones()); // sort timeline - .filter(a => a.content) + .filter(a => a.content || a.template) .sort((b, c) => me.compare_dates(b, c)) .forEach(d => { d.frm = me.frm; @@ -407,7 +412,10 @@ frappe.ui.form.Timeline = class Timeline { c.original_content = c.content; c.content = frappe.utils.toggle_blockquote(c.content); } - if(!frappe.utils.is_html(c.content)) { + + if (c.template) { + c.content_html = frappe.render_template(c.template, c.template_data); + } else if (!frappe.utils.is_html(c.content)) { c.content_html = frappe.markdown(__(c.content)); } else { c.content_html = c.content; @@ -529,6 +537,10 @@ frappe.ui.form.Timeline = class Timeline { return energy_point_logs; } + get_additional_timeline_content() { + return this.frm.get_docinfo().additional_timeline_content || []; + } + get_milestones() { let milestones = this.frm.get_docinfo().milestones; milestones.map(log => { diff --git a/frappe/public/js/frappe/form/templates/timeline.html b/frappe/public/js/frappe/form/templates/timeline.html index 5600f9384f..0a8a631142 100644 --- a/frappe/public/js/frappe/form/templates/timeline.html +++ b/frappe/public/js/frappe/form/templates/timeline.html @@ -17,9 +17,7 @@ {% } %} {% } %} -