Skip to content

Commit

Permalink
Update to v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kid1194 committed Nov 17, 2022
1 parent 2edff64 commit 90999de
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 63 deletions.
93 changes: 53 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,9 @@
# Frappe Better List View

A small plugin for Frappe that modifies the list view to allow:
1. Setting the number of rows displayed per page
2. Fetching a list of fields without displaying their values

```
frappe.listview_settings['DocType'] = {
// Only 50 rows will be displayed per page
page_length: 50,
// No columns will be created for these fields
get_fields: ['is_approved', 'is_paid'],
// The fields listed above can be used inside the following functions
get_indicator: function(doc) {
if (doc.is_paid) {
return [__('Paid'), 'blue', 'is_paid,=,Yes|is_approved,=,Yes'];
}
if (doc.is_approved) {
return [__('Approved'), 'green', 'is_paid,=,No|is_approved,=,Yes'];
}
return [__('Pending'), 'gray', 'is_paid,=,No|is_approved,=,No'];
},
formatters: {
name: function(value, field, doc) {
let html = value;
if (doc.is_approved) {
html += ' <span class="fa fa-check"></span>';
}
return html;
},
},
};
```
A small **Frappe** list view plugin that allows the following modifications:
1. Setting additional fields to fetch without displaying their values
1. Setting additional filters in the data query
3. Setting the number of rows to display per page

---

Expand All @@ -41,6 +14,7 @@ frappe.listview_settings['DocType'] = {
- [Update](#update)
- [Uninstall](#uninstall)
- [Available Options](#available-options)
- [Example](#example)
- [Issues](#issues)
- [License](#license)

Expand Down Expand Up @@ -86,7 +60,7 @@ bench build --app frappe_better_list_view
bench --site [sitename] install-app frappe_better_list_view
```

5. Check the usage section below
5. Check the [Available Options](#available-options) and [Example](#example)

#### Update
1. Go to app directory
Expand Down Expand Up @@ -153,17 +127,56 @@ bench restart
---

### Available Options
1. `page_length`

The number of rows to display per page
- Type: `Integer`
- Example: `50`
⚠️ *Important* ⚠️

*All the following options must be placed inside the* `query` *object. Check the* [Example](#example) *below.*

| Option | Description |
| :--- | :--- |
| `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` |

2. `get_fields`
---

### Example

The list of fields to fetch without displaying their values
- Type: `Array`
- Example: `['currency', 'exchange_rate']`
```
frappe.listview_settings['DocType'] = {
// The query modification
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 fields listed above can be used inside the following functions
get_indicator: function(doc) {
if (doc.is_paid) {
return [__('Paid'), 'blue', 'is_paid,=,Yes|is_approved,=,Yes'];
}
if (doc.is_approved) {
return [__('Approved'), 'green', 'is_paid,=,No|is_approved,=,Yes'];
}
return [__('Pending'), 'gray', 'is_paid,=,No|is_approved,=,No'];
},
formatters: {
name: function(value, field, doc) {
let html = value;
if (doc.is_approved) {
html += ' <span class="fa fa-check"></span>';
}
return html;
},
},
};
```

---

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.0.0"
__version__ = "1.1.0"
2 changes: 1 addition & 1 deletion frappe_better_list_view/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
app_name = "frappe_better_list_view"
app_title = "Frappe Better List View"
app_publisher = "Ameen Ahmed (Level Up)"
app_description = "Frappe list view that allows setting the number of rows per page and fetching a list of fields without displaying their values."
app_description = "Frappe list view plugin that allows modification."
app_icon = "octicon octicon-list-unordered"
app_color = "blue"
app_email = "kid1194@gmail.com"
Expand Down
60 changes: 41 additions & 19 deletions frappe_better_list_view/public/js/better_list_view.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,50 @@
frappe.provide("frappe.views");

frappe.views.ListView = class ListView extends frappe.views.ListView {
setup_defaults() {
var me = this,
ret = super.setup_defaults();
ret.then(function() {
if (cint(me.settings.page_length))
me.page_length = cint(me.settings.page_length);
});
return ret;
}
get_args() {
var args = super.get_args();
if (
Array.isArray(this.settings.get_fields)
&& this.settings.get_fields.length
) {
for (var i = 0, l = this.settings.get_fields.length; i < l; i++) {
args.fields.push(
frappe.model.get_full_column_name(
this.settings.get_fields[i],
if ($.isPlainObject(this.settings.query)) {
if (Array.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],
this.doctype
)
);
);
if (args.fields.indexOf(field) < 0) {
args.fields.push(field);
}
}
}
if (
$.isPlainObject(this.settings.query.filters)
|| Array.isArray(this.settings.query.filters)
) {
var get_query_filter = function(doctype, cond, column) {
var sign = '=',
value = cond;
if (Array.isArray(cond)) {
var len = cond.length;
if (len < 2) return null;
var i = 0;
if (len > 2) column = cond[i++];
sign = cond[i++];
value = cond[i++];
}
return [doctype, column, sign, value];
};
for (var key in this.settings.query.filters) {
var cond = get_query_filter(
this.doctype,
this.settings.query.filters[key],
key
);
if (cond && args.filters.indexOf(cond) < 0) {
args.filters.push(cond);
}
}
}
if (cint(this.settings.query.page_length)) {
args.page_length = cint(this.settings.query.page_length);
}
}
return args;
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "frappe_better_list_view"
authors = [
{name = "Ameen Ahmed (Level Up)", email = "kid1194@gmail.com"}
]
description = "Frappe list view that allows setting the number of rows per page and fetching a list of fields without displaying their values."
description = "Frappe list view plugin that allows modification."
keywords = ["frappe", "list view", "better list view"]
classifiers = [
"Development Status :: 5 - Production/Stable",
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
setup(
name='frappe_better_list_view',
version=version,
description='Frappe list view that allows setting the number of rows per page and fetching a list of fields without displaying their values.',
description='Frappe list view plugin that allows modification.',
author='Ameen Ahmed (Level Up)',
author_email='kid1194@gmail.com',
packages=find_packages(),
Expand Down

0 comments on commit 90999de

Please sign in to comment.