Merge pull request #15709 from gavindsouza/sort-options-listviews

This commit is contained in:
Suraj Shetty 2022-01-25 13:16:19 +05:30 committed by GitHub
commit fc08dffefa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -113,41 +113,43 @@ frappe.ui.SortSelector = class SortSelector {
if(!this.args.options) {
// default options
var _options = [
{'fieldname': 'modified'}
{'fieldname': 'modified'},
{'fieldname': 'name'},
{'fieldname': 'creation'},
{'fieldname': 'idx'},
]
// title field
if(meta.title_field) {
_options.push({'fieldname': meta.title_field});
if (meta.title_field) {
_options.splice(1, 0, {'fieldname': meta.title_field});
}
// bold or mandatory
// sort field - set via DocType schema or Customize Form
if (meta_sort_field) {
_options.splice(1, 0, { 'fieldname': meta_sort_field });
}
// bold, mandatory and fields that are available in list view
meta.fields.forEach(function(df) {
if(df.mandatory || df.bold) {
if (
(df.mandatory || df.bold || df.in_list_view)
&& frappe.model.is_value_type(df.fieldtype)
&& frappe.perm.has_perm(me.doctype, df.permlevel, "read")
) {
_options.push({fieldname: df.fieldname, label: df.label});
}
});
// meta sort field
if(meta_sort_field) _options.push({ 'fieldname': meta_sort_field });
// more default options
_options.push(
{'fieldname': 'name'},
{'fieldname': 'creation'},
{'fieldname': 'idx'}
)
// de-duplicate
this.args.options = _options.uniqBy(function(obj) {
return obj.fieldname;
// add missing labels
_options.forEach(option => {
if (!option.label) {
option.label = me.get_label(option.fieldname);
}
});
// add missing labels
this.args.options.forEach(function(o) {
if(!o.label) {
o.label = me.get_label(o.fieldname);
}
// de-duplicate
this.args.options = _options.uniqBy(obj => {
return obj.fieldname;
});
}