Skip to content

Commit

Permalink
Update to v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kid1194 committed Nov 20, 2022
1 parent 90999de commit a5af7be
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,46 @@ bench restart
| `fields` | The additional list of fields to fetch without displaying their values.<br/><br/>Type: `Array`<br/>Example: `['is_approved', 'is_paid']` |
| `filters` | The additional filter conditions to customize the data fetched.<br/><br/>Type: `Object` or `Array`<br/>Example: `{is_approved: 1, is_paid: 0}` or `[['is_approved', '=', 1], ['is_paid', '=', 0]]` |
| `page_length` | The number of rows to display per page.<br/><br/>Type: `Integer`<br/>Example: `50` |
| `parser` | The function that modifies row values on time. Must call `resolve()` after modification is done.<br/><br/>Type: `Function`<br/>Parameter: `row, resolve`<br/>Example: Check both ways listed in the [example](#example) code below |

---

### Example

```
frappe.listview_settings['DocType'] = {
// The query modification
// The list view modifications
query: {
// No columns will be created for these fields
fields: ['is_approved', 'is_paid'],
// Additional filters (array or object) to customize query
filters: {
is_approved: 1,
is_paid: 1,
},
// Only 50 rows will be displayed per page
page_length: 50,
// The function that modifies row values using one of the following ways
parser: function(row, resolve) {
// 1. Simply change row values directly
row.actual_qty = 10;
resolve();
// 2. Query db and modify row value
frappe.db.get_value('DocType', row.name, 'actual_qty')
.then(function(ret) {
if (ret && $.isPlainObjecr(ret)) ret = ret.message || ret;
row.actual_qty = ret;
resolve();
});
},
},
// The fields listed above can be used inside the following functions
get_indicator: function(doc) {
if (doc.is_paid) {
Expand Down
2 changes: 1 addition & 1 deletion frappe_better_list_view/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# Licence: Please refer to LICENSE file


__version__ = "1.1.0"
__version__ = "1.2.0"
37 changes: 34 additions & 3 deletions frappe_better_list_view/public/js/better_list_view.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ frappe.views.ListView = class ListView extends frappe.views.ListView {
get_args() {
var args = super.get_args();
if ($.isPlainObject(this.settings.query)) {
if (Array.isArray(this.settings.query.fields)) {
if ($.isArray(this.settings.query.fields)) {
for (var i in this.settings.query.fields) {
var field = frappe.model.get_full_column_name(
this.settings.query.fields[i],
Expand All @@ -25,12 +25,12 @@ frappe.views.ListView = class ListView extends frappe.views.ListView {
}
if (
$.isPlainObject(this.settings.query.filters)
|| Array.isArray(this.settings.query.filters)
|| $.isArray(this.settings.query.filters)
) {
var get_query_filter = function(doctype, cond, column) {
var sign = '=',
value = cond;
if (Array.isArray(cond)) {
if ($.isArray(cond)) {
var len = cond.length;
if (len < 2) return null;
var i = 0;
Expand All @@ -57,4 +57,35 @@ frappe.views.ListView = class ListView extends frappe.views.ListView {
}
return args;
}
render_list() {
if (
!this._inside_parser
&& this.settings.query.parser
&& typeof this.settings.query.parser === 'function'
) {
var me = this,
tasks = [];
$.each(this.data, function(i, row) {
tasks.push(new Promise(function(resolve, reject) {
try {
me.settings.query.parser(row, resolve);
} catch(e) {
reject(e);
}
}));
});
if (tasks.length) {
var render = function() {
me._inside_parser = true;
me.render_list();
me._inside_parser = false;
};
Promise.all(tasks)
.catch(render)
.finally(render);
return;
}
}
super.render_list();
}
};

0 comments on commit a5af7be

Please sign in to comment.