[hub][publish] add search, fix multiple append
diff --git a/erpnext/hub_node/__init__.py b/erpnext/hub_node/__init__.py
index 138ff1e..993737e 100644
--- a/erpnext/hub_node/__init__.py
+++ b/erpnext/hub_node/__init__.py
@@ -33,8 +33,13 @@
#### LOCAL ITEMS
@frappe.whitelist()
-def get_valid_items():
- items = frappe.get_list('Item', fields=["*"])
+def get_valid_items(search_value=''):
+ items = frappe.get_list('Item', fields=["*"], filters={
+ 'item_name': ['like', '%' + search_value + '%']
+ })
+
+ print([d.item_name for d in items])
+
valid_items = filter(lambda x: x.image and x.description, items)
def attach_source_type(item):
diff --git a/erpnext/public/js/hub/hub_listing.js b/erpnext/public/js/hub/hub_listing.js
index 3107c67..33df23e 100644
--- a/erpnext/public/js/hub/hub_listing.js
+++ b/erpnext/public/js/hub/hub_listing.js
@@ -186,6 +186,7 @@
}
get_items_and_render() {
+ this.$wrapper.find('.hub-card-container').empty();
this.get_items()
.then(r => {
erpnext.hub.hub_item_cache = r.message;
@@ -238,6 +239,7 @@
}
render(items) {
+ this.$wrapper.find('.hub-card-container').empty();
const html = get_item_card_container_html(items, __('Favourites'));
this.$wrapper.append(html)
}
@@ -253,6 +255,7 @@
}
get_items_for_category(category) {
+ this.$wrapper.find('.hub-card-container').empty();
return frappe.call('erpnext.hub_node.get_list', {
doctype: 'Hub Item',
filters: {
@@ -490,6 +493,8 @@
}
refresh() {
+ this.$register_container.empty();
+ this.$form_container.empty();
this.render();
}
@@ -615,15 +620,30 @@
this.$wrapper.find('.deselect-all').on('click', () => {
this.$wrapper.find('.hub-card').removeClass('active');
});
+
+ const $search_input = this.$wrapper.find('.hub-search-container input');
+ this.search_value = '';
+
+ $search_input.on('keydown', frappe.utils.debounce((e) => {
+ if (e.which === frappe.ui.keyCode.ENTER) {
+ this.search_value = $search_input.val();
+ this.get_items_and_render();
+ }
+ }, 300));
}
- refresh() {
+ get_items_and_render() {
+ this.$wrapper.find('.hub-card-container').empty();
this.get_valid_items()
.then(r => {
this.render(r.message);
});
}
+ refresh() {
+ this.get_items_and_render();
+ }
+
render(items) {
const items_container = $(get_item_card_container_html(items));
items_container.addClass('static').on('click', '.hub-card', (e) => {
@@ -635,7 +655,12 @@
}
get_valid_items() {
- return frappe.call('erpnext.hub_node.get_valid_items');
+ return frappe.call(
+ 'erpnext.hub_node.get_valid_items',
+ {
+ search_value: this.search_value
+ }
+ );
}
}