fix: format energy point log for history and form separately
This commit is contained in:
parent
e8cd9dc4c6
commit
950ce155f7
3 changed files with 50 additions and 18 deletions
|
|
@ -522,7 +522,7 @@ frappe.ui.form.Timeline = class Timeline {
|
|||
let energy_point_logs = this.frm.get_docinfo().energy_point_logs;
|
||||
energy_point_logs.map(log => {
|
||||
log.comment_type = 'Energy Points';
|
||||
log.content = frappe.energy_points.format_log(log);
|
||||
log.content = frappe.energy_points.format_form_log(log);
|
||||
return log;
|
||||
});
|
||||
return energy_point_logs;
|
||||
|
|
|
|||
|
|
@ -9,23 +9,55 @@ Object.assign(frappe.energy_points, {
|
|||
${points > 0 ? '+': ''}${points}
|
||||
</span>`;
|
||||
},
|
||||
log_message(log) {
|
||||
const doc_link = frappe.utils.get_form_link(log.reference_doctype, log.reference_name, true);
|
||||
const owner_name = frappe.user.full_name(log.owner).bold();
|
||||
const user = frappe.user.full_name(log.user).bold();
|
||||
if (log.type === 'Appreciation') {
|
||||
return __('{0} appreciated {1} on {2}', [owner_name, user, doc_link]);
|
||||
}
|
||||
if (log.type === 'Criticism') {
|
||||
return __('{0} criticized {1} on {2}', [owner_name, user, doc_link]);
|
||||
}
|
||||
return __('for {0} via automatic rule {1} on {2}', [user, log.rule.bold(), doc_link]);
|
||||
},
|
||||
format_log(log, with_timestamp=false) {
|
||||
let formatted_log = `<span>
|
||||
${this.get_points(log.points)} ${this.log_message(log)}
|
||||
${ with_timestamp ? '<span> - </span>' + frappe.datetime.comment_when(log.creation):''}
|
||||
format_form_log(log) {
|
||||
const separator = `<span> - </span>`;
|
||||
const formatted_log = `<span>
|
||||
${this.get_points(log.points)}
|
||||
<a href="#Form/Energy Point Log/${log.name}">${this.get_form_log_message(log)}</a>
|
||||
${log.reason ? separator + log.reason: ''}
|
||||
</span>`;
|
||||
return formatted_log;
|
||||
},
|
||||
format_history_log(log) {
|
||||
// redundant code to honor readability and to avoid confusion
|
||||
const separator = `<span> - </span>`;
|
||||
const formatted_log = `<span>
|
||||
${this.get_points(log.points)}
|
||||
<a href="#Form/Energy Point Log/${log.name}">${this.get_history_log_message(log)}</a>
|
||||
${log.reason ? separator + log.reason: ''}
|
||||
${separator + frappe.datetime.comment_when(log.creation)}
|
||||
</span>`;
|
||||
return formatted_log;
|
||||
},
|
||||
get_history_log_message(log) {
|
||||
const doc_link = frappe.utils.get_form_link(log.reference_doctype, log.reference_name, true);
|
||||
const owner_name = frappe.user.full_name(log.owner).bold();
|
||||
if (log.type === 'Appreciation') {
|
||||
return __('{0} appreciated on {1}', [owner_name, doc_link]);
|
||||
}
|
||||
if (log.type === 'Criticism') {
|
||||
return __('{0} criticized on {1}', [owner_name, doc_link]);
|
||||
}
|
||||
if (log.type === 'Revert') {
|
||||
return __('{0} reverted {1}', [owner_name,
|
||||
frappe.utils.get_form_link('Energy Point Log', log.revert_for, true)]);
|
||||
}
|
||||
return __('via automatic rule {0} on {1}', [log.rule.bold(), doc_link]);
|
||||
},
|
||||
get_form_log_message(log) {
|
||||
// redundant code to honor readability and to avoid confusion
|
||||
const owner_name = frappe.user.full_name(log.owner).bold();
|
||||
const user = frappe.user.full_name(log.user).bold();
|
||||
if (log.type === 'Appreciation') {
|
||||
return __('{0} appreciated {1}', [owner_name, user]);
|
||||
}
|
||||
if (log.type === 'Criticism') {
|
||||
return __('{0} criticized {1}', [owner_name, user]);
|
||||
}
|
||||
if (log.type === 'Revert') {
|
||||
return __('{0} reverted {1}', [user,
|
||||
frappe.utils.get_form_link('Energy Point Log', log.revert_for, true)]);
|
||||
}
|
||||
return __('gained by {0} via automatic rule {1}', [user, log.rule.bold()]);
|
||||
},
|
||||
});
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
<div>
|
||||
<ul class="log-list">
|
||||
<li class="history-log" v-for="log in history_logs" :key="log.name">
|
||||
<span v-html="frappe.energy_points.format_log(log, true)"></span>
|
||||
<span v-html="frappe.energy_points.format_history_log(log, true)"></span>
|
||||
</li>
|
||||
<li v-if="!history_logs.length" class="history-log">
|
||||
{{__('No logs found')}}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue