From 1d1696080e8366a8f5f9e8b8ef34407ec253a65f Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Thu, 26 Jul 2018 08:36:33 +0530 Subject: [PATCH] [hub][publish] add search, fix multiple append --- erpnext/hub_node/__init__.py | 9 +++++++-- erpnext/public/js/hub/hub_listing.js | 29 ++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/erpnext/hub_node/__init__.py b/erpnext/hub_node/__init__.py index 138ff1e40e..993737e147 100644 --- a/erpnext/hub_node/__init__.py +++ b/erpnext/hub_node/__init__.py @@ -33,8 +33,13 @@ def get_list(doctype, start=0, limit=20, fields=["*"], filters="{}", order_by=No #### 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 3107c674be..33df23e0c5 100644 --- a/erpnext/public/js/hub/hub_listing.js +++ b/erpnext/public/js/hub/hub_listing.js @@ -186,6 +186,7 @@ erpnext.hub.Home = class Home extends SubPage { } 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 @@ erpnext.hub.Favourites = class Favourites extends SubPage { } 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 @@ erpnext.hub.Category = class Category extends SubPage { } 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 @@ erpnext.hub.Register = class Register extends SubPage { } refresh() { + this.$register_container.empty(); + this.$form_container.empty(); this.render(); } @@ -615,15 +620,30 @@ erpnext.hub.Publish = class Publish extends SubPage { 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 @@ erpnext.hub.Publish = class Publish extends SubPage { } 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 + } + ); } }