8000 feat: support list view for "show titles instead of name" (backport #18060) by mergify[bot] · Pull Request #18681 · frappe/frappe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: support list view for "show titles instead of name" (backport #18060) #18681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions frappe/public/js/frappe/list/base_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ frappe.views.BaseList = class BaseList {
.then((doc) => (this.list_view_settings = doc.message || {}));
}

setup_fields() {
this.set_fields();
async setup_fields() {
await this.set_fields();
this.build_fields();
}

set_fields() {
async set_fields() {
let fields = [].concat(frappe.model.std_fields_list, this.meta.title_field);

fields.forEach((f) => this._add_field(f));
Expand Down
54 changes: 49 additions & 5 deletions frappe/public/js/frappe/list/list_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,18 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
);
}

set_fields() {
get_fields() {
return super
.get_fields()
.concat(
Object.entries(this.link_field_title_fields || {}).map(
(entry) => entry.join(".") + " as " + entry.join("_")
)
);
}

async set_fields() {
this.link_field_title_fields = {};
let fields = [].concat(
frappe.model.std_fields_list,
this.get_fields_in_list_view(),
Expand All @@ -183,7 +194,34 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
"color"
);

fields.forEach((f) => this._add_field(f));
await Promise.all(
fields.map((f) => {
return new Promise((resolve) => {
const df =
typeof f === "string" ? frappe.meta.get_docfield(this.doctype, f) : f;
if (
df &&
df.fieldtype == "Link" &&
frappe.boot.link_title_doctypes.includes(df.options)
) {
frappe.model.with_doctype(df.options, () => {
const meta = frappe.get_meta(df.options);
if (meta.show_title_field_in_link) {
this.link_field_title_fields[
typeof f === "string" ? f : f.fieldname
] = meta.title_field;
}

this._add_field(f);
resolve();
});
} else {
this._add_field(f);
resolve();
}
});
})
);

this.fields.forEach((f) => {
const df = frappe.meta.get_docfield(f[1], f[0]);
Expand Down Expand Up @@ -691,8 +729,11 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
const df = col.df || {};
const label = df.label;
const fieldname = df.fieldname;
const link_title_fieldname = this.link_field_title_fields[fieldname];
const value = doc[fieldname] || "";

const value_display = link_title_fieldname
? doc[fieldname + "_" + link_title_fieldname] || value
: value;
const format = () => {
if (df.fieldtype === "Code") {
return value;
Expand All @@ -716,9 +757,12 @@ frappe.views.ListView = class ListView extends frappe.views.BaseList {
(df.fetch_from && ["Text", "Small Text"].includes(df.fieldtype));

if (strip_html_required) {
_value = strip_html(value);
_value = strip_html(value_display);
} else {
_value = typeof value === "string" ? frappe.utils.escape_html(value) : value;
_value =
typeof value_display === "string"
? frappe.utils.escape_html(value_display)
: value_display;
}

if (df.fieldtype === "Rating") {
Expand Down
0