diff --git a/frappe/desk/form/load.py b/frappe/desk/form/load.py index 75c049a9ca..565306f07b 100644 --- a/frappe/desk/form/load.py +++ b/frappe/desk/form/load.py @@ -123,7 +123,6 @@ def get_docinfo(doc=None, doctype=None, name=None): "permissions": get_doc_permissions(doc), "shared": get_docshares(doc), "views": get_view_logs(doc), - # "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), @@ -246,19 +245,6 @@ def get_comments(doctype: str, name: str, comment_type: str | list[str] = "Comme return comments -def get_point_logs(doctype, docname): - from frappe.social.doctype.energy_point_settings.energy_point_settings import is_energy_point_enabled - - if not is_energy_point_enabled(): - return [] - - return frappe.get_all( - "Energy Point Log", - filters={"reference_doctype": doctype, "reference_name": docname, "type": ["!=", "Review"]}, - fields=["*"], - ) - - def _get_communications(doctype, name, start=0, limit=20): communications = get_communication_data(doctype, name, start, limit) for c in communications: diff --git a/frappe/desk/leaderboard.py b/frappe/desk/leaderboard.py deleted file mode 100644 index 4800a7d945..0000000000 --- a/frappe/desk/leaderboard.py +++ /dev/null @@ -1,50 +0,0 @@ -import frappe -from frappe.utils import get_fullname - - -def get_leaderboards(): - return { - "User": { - "fields": ["points"], - "method": "frappe.desk.leaderboard.get_energy_point_leaderboard", - "company_disabled": 1, - "icon": "users", - } - } - - -@frappe.whitelist() -def get_energy_point_leaderboard(date_range, company=None, field=None, limit=None): - users = frappe.get_list( - "User", - filters={ - "name": ["not in", ["Administrator", "Guest"]], - "enabled": 1, - "user_type": ["!=", "Website User"], - }, - pluck="name", - ) - - filters = [["type", "!=", "Review"], ["user", "in", users]] - if date_range: - date_range = frappe.parse_json(date_range) - filters.append(["creation", "between", [date_range[0], date_range[1]]]) - energy_point_users = frappe.get_all( - "Energy Point Log", - fields=["user as name", "sum(points) as value"], - filters=filters, - group_by="user", - order_by="value desc", - ) - - energy_point_users_list = list(map(lambda x: x["name"], energy_point_users)) - for user in users: - if user not in energy_point_users_list: - energy_point_users.append({"name": user, "value": 0}) - - for user in energy_point_users: - user_id = user["name"] - user["name"] = get_fullname(user["name"]) - user["formatted_name"] = f'{get_fullname(user_id)}' - - return energy_point_users diff --git a/frappe/hooks.py b/frappe/hooks.py index d6310a5ddf..d87d1a0c72 100644 --- a/frappe/hooks.py +++ b/frappe/hooks.py @@ -81,8 +81,6 @@ email_append_to = ["Event", "ToDo", "Communication"] calendars = ["Event"] -leaderboards = "frappe.desk.leaderboard.get_leaderboards" - # login on_session_creation = [ diff --git a/frappe/public/js/desk.bundle.js b/frappe/public/js/desk.bundle.js index 1287dbabb1..cd7653fba3 100644 --- a/frappe/public/js/desk.bundle.js +++ b/frappe/public/js/desk.bundle.js @@ -101,7 +101,6 @@ import "./frappe/ui/workspace_sidebar_loading_skeleton.html"; import "./frappe/desk.js"; import "./frappe/query_string.js"; -import "./frappe/utils/energy_point_utils.js"; import "./frappe/utils/dashboard_utils.js"; import "./frappe/ui/chart.js"; import "./frappe/ui/datatable.js"; diff --git a/frappe/public/js/frappe/form/footer/base_timeline.js b/frappe/public/js/frappe/form/footer/base_timeline.js index beacdda462..b28c2c7706 100644 --- a/frappe/public/js/frappe/form/footer/base_timeline.js +++ b/frappe/public/js/frappe/form/footer/base_timeline.js @@ -148,4 +148,5 @@ class BaseTimeline { } } +frappe.ui.BaseTimeline = BaseTimeline; export default BaseTimeline; diff --git a/frappe/public/js/frappe/form/footer/form_timeline.js b/frappe/public/js/frappe/form/footer/form_timeline.js index c79c17619f..bd88b6eabc 100644 --- a/frappe/public/js/frappe/form/footer/form_timeline.js +++ b/frappe/public/js/frappe/form/footer/form_timeline.js @@ -161,7 +161,6 @@ class FormTimeline extends BaseTimeline { this.timeline_items.push(...this.get_comment_timeline_contents()); if (!this.only_communication) { this.timeline_items.push(...this.get_view_timeline_contents()); - this.timeline_items.push(...this.get_energy_point_timeline_contents()); this.timeline_items.push(...this.get_version_timeline_contents()); this.timeline_items.push(...this.get_share_timeline_contents()); this.timeline_items.push(...this.get_workflow_timeline_contents()); @@ -494,36 +493,30 @@ class FormTimeline extends BaseTimeline { get_custom_timeline_contents() { let custom_timeline_contents = []; (this.doc_info.additional_timeline_content || []).forEach((custom_item) => { - custom_timeline_contents.push({ - icon: custom_item.icon, - icon_size: "sm", - is_card: custom_item.is_card, - creation: custom_item.creation, - content: - custom_item.content || - frappe.render_template(custom_item.template, custom_item.template_data), - }); + if (custom_item.timeline_badge) { + custom_timeline_contents.push({ + timeline_badge: custom_item.timeline_badge, + creation: custom_item.creation, + content: frappe.utils.eval(custom_item.method, { + custom_item: custom_item, + }), + }); + } else { + custom_timeline_contents.push({ + icon: custom_item.icon, + timeline_badge: custom_item.timeline_badge, + icon_size: "sm", + is_card: custom_item.is_card, + creation: custom_item.creation, + content: + custom_item.content || + frappe.render_template(custom_item.template, custom_item.template_data), + }); + } }); return custom_timeline_contents; } - get_energy_point_timeline_contents() { - let energy_point_timeline_contents = []; - (this.doc_info.energy_point_logs || []).forEach((log) => { - let timeline_badge = ` -
- ${log.points} -
`; - - energy_point_timeline_contents.push({ - timeline_badge: timeline_badge, - creation: log.creation, - content: frappe.energy_points.format_form_log(log), - }); - }); - return energy_point_timeline_contents; - } - setup_reply(communication_box, communication_doc) { let actions = communication_box.find(".custom-actions"); let reply = $(`${frappe.utils.icon("reply", "md")}`).click( diff --git a/frappe/public/js/frappe/form/sidebar/review.js b/frappe/public/js/frappe/form/sidebar/review.js deleted file mode 100644 index 10b11bf4d3..0000000000 --- a/frappe/public/js/frappe/form/sidebar/review.js +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors -// MIT License. See license.txt - -frappe.ui.form.Review = class Review { - constructor({ parent, frm }) { - this.parent = parent; - this.frm = frm; - this.points = frappe.boot.points; - this.reviews = this.parent.find(".reviews"); - this.setup_add_review_button(); - this.update_reviewers(); - } - update_points() { - return frappe - .xcall("frappe.social.doctype.energy_point_log.energy_point_log.get_energy_points", { - user: frappe.session.user, - }) - .then((data) => { - frappe.boot.points = data; - this.points = data; - }); - } - setup_add_review_button() { - const review_button = this.reviews.find(".add-review-btn"); - - if (!this.points.review_points) { - review_button.click(false); - review_button.popover({ - trigger: "hover", - content: () => { - return `
- ${__("You do not have enough review points")} -
`; - }, - html: true, - }); - } else { - review_button.click(() => this.show_review_dialog()); - } - } - - show_review_dialog() { - const user_options = this.frm.get_involved_users(); - const review_dialog = new frappe.ui.Dialog({ - title: __("Add Review"), - fields: [ - { - fieldname: "to_user", - fieldtype: "Autocomplete", - label: __("To User"), - reqd: 1, - options: user_options, - ignore_validation: 1, - description: __("Only users involved in the document are listed"), - }, - { - fieldname: "review_type", - fieldtype: "Select", - label: __("Action"), - options: [ - { - label: __("Appreciate"), - value: "Appreciation", - }, - { - label: __("Criticize"), - value: "Criticism", - }, - ], - default: "Appreciation", - }, - { - fieldname: "points", - fieldtype: "Int", - label: __("Points"), - reqd: 1, - description: __("Currently you have {0} review points", [ - this.points.review_points, - ]), - }, - { - fieldtype: "Small Text", - fieldname: "reason", - reqd: 1, - label: __("Reason"), - }, - ], - primary_action: (values) => { - review_dialog.disable_primary_action(); - if (values.points > this.points.review_points) { - return frappe.msgprint(__("You do not have enough points")); - } - frappe - .xcall("frappe.social.doctype.energy_point_log.energy_point_log.review", { - doc: { - doctype: this.frm.doc.doctype, - name: this.frm.doc.name, - }, - to_user: values.to_user, - points: values.points, - review_type: values.review_type, - reason: values.reason, - }) - .then((review) => { - review_dialog.hide(); - review_dialog.clear(); - this.frm.get_docinfo().energy_point_logs.unshift(review); - this.frm.timeline.refresh(); - this.update_reviewers(); - this.update_points(); - }) - .finally(() => { - review_dialog.enable_primary_action(); - }); - }, - primary_action_label: __("Submit"), - }); - review_dialog.show(); - } - update_reviewers() { - const review_logs = this.frm - .get_docinfo() - .energy_point_logs.filter((log) => ["Appreciation", "Criticism"].includes(log.type)); - - this.reviews.find(".review").remove(); - review_logs.forEach((log) => { - let review_pill = $(` -
- ${frappe.avatar(log.owner)} - - ${log.points > 0 ? "+" : ""}${log.points} - -
- `); - this.reviews.append(review_pill); - this.setup_detail_popover(review_pill, log); - }); - } - setup_detail_popover(el, data) { - let subject = ""; - let fullname = frappe.user.full_name(data.user); - let timestamp = `${frappe.datetime.comment_when( - data.creation - )}`; - let message_parts = [Math.abs(data.points), fullname, timestamp]; - if (data.type === "Appreciation") { - if (data.points == 1) { - subject = __("{0} appreciation point for {1}", message_parts); - } else { - subject = __("{0} appreciation points for {1}", message_parts); - } - } else { - if (data.points == -1) { - subject = __("{0} criticism point for {1}", message_parts); - } else { - subject = __("{0} criticism points for {1}", message_parts); - } - } - - el.popover({ - animation: true, - trigger: "hover", - delay: 500, - placement: "top", - template: ` - ' - `, - content: () => { - return ` -
-
-
${data.reason}
-
- -
- ${frappe.utils.icon("review")} - ${subject} - -

- - ${frappe.user.full_name(data.owner)} - ${timestamp} -

-
-
- `; - }, - html: true, - container: "body", - }); - - return el; - } -}; diff --git a/frappe/public/js/frappe/utils/energy_point_utils.js b/frappe/public/js/frappe/utils/energy_point_utils.js deleted file mode 100644 index edf232b677..0000000000 --- a/frappe/public/js/frappe/utils/energy_point_utils.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors -// MIT License. See license.txt - -frappe.provide("frappe.energy_points"); - -Object.assign(frappe.energy_points, { - get_points(points) { - return ` - ${points > 0 ? "+" : ""}${points} - `; - }, - format_form_log(log) { - const separator = ` - `; - return ` - - ${this.get_form_log_message(log)} - ${log.reason ? separator + log.reason : ""} - `; - }, - format_history_log(log) { - // redundant code to honor readability and to avoid confusion - const separator = ` - `; - const route = frappe.utils.get_form_link(log.reference_doctype, log.reference_name); - return `
- - ${this.get_points(log.points)} - - ${this.get_history_log_message(log)} - ${log.reason ? separator + log.reason : ""} - ${separator + frappe.datetime.comment_when(log.creation)} -
`; - }, - get_history_log_message(log) { - const owner_name = frappe.user.full_name(log.owner).bold(); - const ref_doc = log.reference_name; - - if (log.type === "Appreciation") { - return __("{0} appreciated on {1}", [owner_name, ref_doc]); - } - if (log.type === "Criticism") { - return __("{0} criticized on {1}", [owner_name, ref_doc]); - } - if (log.type === "Revert") { - return __("{0} reverted {1}", [owner_name, log.revert_of]); - } - return __("via automatic rule {0} on {1}", [log.rule.bold(), ref_doc]); - }, - 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}", [owner_name, log.revert_of]); - } - return __("gained by {0} via automatic rule {1}", [user, log.rule.bold()]); - }, -}); diff --git a/frappe/public/js/user_profile_controller.bundle.js b/frappe/public/js/user_profile_controller.bundle.js deleted file mode 100644 index 1bf0b517d7..0000000000 --- a/frappe/public/js/user_profile_controller.bundle.js +++ /dev/null @@ -1 +0,0 @@ -import "../../desk/page/user_profile/user_profile_controller";