Introduction
Welcome to this comprehensive guide on the Customization of Empress Desk in Empress. As a developer, you recognize the importance of tailoring software to meet specific business needs. Customizing the Empress Desk allows you to adapt the Empress system to better align it with your organization’s operational requirements. This guide will provide in-depth information on two key features: Formatter for Link Fields and Making Charts.
Formatter for Link Fields
The Formatter for Link Fields is a powerful feature that modifies the display of linked fields in your documents. It allows developers to customize the way linked fields are shown, enhancing user experience and data readability.
Here’s a typical code snippet for this feature:
def formatter_for_link_fields(doctype, txt, searchfield, start, page_len, filters):
return frappe.db.sql("""select name, owner from `tabToDo`
where {key} LIKE %(txt)s
{mcond}
order by
if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
if(locate(%(_txt)s, owner), locate(%(_txt)s, owner), 99999),
name, owner
limit %(start)s, %(page_len)s""".format(**{
'key': searchfield,
'mcond': get_match_cond(doctype)
}), {
'txt': "%%%s%%" % frappe.db.escape(txt),
'_txt': txt.replace("%", ""),
'start': start,
'page_len': page_len
})
In the above code, frappe.db.sql()
executes the SQL command. The SQL command retrieves data from the ToDo
table where the key matches the search field. The get_match_cond(doctype)
function returns the match condition for the doctype. The limit clause sets the number of records to return.
As a developer, you may need to modify this code to suit your needs. This could involve replacing the ToDo
table with a different table, or adjusting the fields to be returned by the SQL command.
Making Charts
The Making Charts feature allows developers to create dynamic and interactive charts. This offers a concise and intuitive way of displaying data, which is crucial for business analysis and decision making.
Here’s a typical code snippet for this feature:
frappe.chart = new Chart({
parent: "#chart",
title: "My Awesome Chart",
data: {
labels: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
datasets: [{
color: "light-blue",
values: [18, 40, 30, 35, 8, 52, 17, -10]
}]
},
});
In the code above, frappe.chart
creates a new chart object. The parent
attribute specifies the location of the chart, title
sets the chart’s title, and data
includes the data to be displayed on the chart. The datasets
attribute holds the color and values for the chart.
As with the Formatter for Link Fields, you can modify this code to suit your needs. For instance, you may need to change the chart’s parent
, title
, and data
attributes to match your desired output.
Summary
The Customization of Empress Desk feature is a powerful tool for developers, allowing for tailored business solutions. Whether you’re tweaking the display of linked fields with the Formatter for Link Fields feature or creating dynamic visual representations with the Making Charts feature, these customizations enhance the user experience and provide valuable insights. By gaining an in-depth understanding of these features, you can effectively leverage Empress to meet your organization’s unique needs.