diff --git a/erpnext/hub_node/__init__.py b/erpnext/hub_node/__init__.py index 93129d9f43..dc6c789a78 100644 --- a/erpnext/hub_node/__init__.py +++ b/erpnext/hub_node/__init__.py @@ -15,25 +15,15 @@ def enable_hub(): return hub_settings @frappe.whitelist() -def get_items(start=0, limit=20, fields=["*"], category=None, order_by=None, company=None, text=None): +def get_items(doctype, start=0, limit=20, fields=["*"], filters="{}", order_by=None): connection = get_client_connection() + filters = json.loads(filters) - filters = {} - - if category: - filters.update({ 'hub_category': category }) - if text: - filters.update({'item_name': ('like', '%' + text + '%')}) - if company: - filters.update({'company_name': company}) - - response = connection.get_list('Hub Item', + response = connection.get_list(doctype, limit_start=start, limit_page_length=limit, filters=filters, fields=fields) return response -# - @frappe.whitelist() def get_hub_item_meta(): connection = get_client_connection() diff --git a/erpnext/public/js/hub/hub_factory.js b/erpnext/public/js/hub/hub_factory.js index a341c22839..c43dfa5437 100644 --- a/erpnext/public/js/hub/hub_factory.js +++ b/erpnext/public/js/hub/hub_factory.js @@ -21,7 +21,15 @@ frappe.views.HubFactory = frappe.views.Factory.extend({ console.log("pages?"); if (page === 'Item' && !route[2]) { frappe.require(assets['List'], () => { - erpnext.hub.pages[page_name] = new erpnext.hub.HubPage({ + erpnext.hub.pages[page_name] = new erpnext.hub.ItemListing({ + doctype: 'Hub Settings', + parent: this.make_page(true, page_name) + }); + window.hub_page = erpnext.hub.pages[page_name]; + }); + } if (page === 'Company' && !route[2]) { + frappe.require(assets['List'], () => { + erpnext.hub.pages[page_name] = new erpnext.hub.CompanyListing({ doctype: 'Hub Settings', parent: this.make_page(true, page_name) }); diff --git a/erpnext/public/js/hub/hub_page.js b/erpnext/public/js/hub/hub_page.js index 9b6c4f4f47..20fcf4daee 100644 --- a/erpnext/public/js/hub/hub_page.js +++ b/erpnext/public/js/hub/hub_page.js @@ -1,6 +1,6 @@ frappe.provide('erpnext.hub'); -erpnext.hub.HubPage = class HubPage extends frappe.views.BaseList { +erpnext.hub.ItemListing = class ItemListing extends frappe.views.BaseList { setup_defaults() { super.setup_defaults(); this.page_title = __('Hub'); @@ -23,16 +23,12 @@ erpnext.hub.HubPage = class HubPage extends frappe.views.BaseList { } setup_fields() { - this.fields = ['name', 'hub_item_code', 'image', 'item_name', 'item_code']; + this.fields = ['name', 'hub_item_code', 'image', 'item_name', 'item_code', 'company_name']; } - set_breadcrumbs() { + set_breadcrumbs() { } - } - - setup_side_bar() { - - } + setup_side_bar() { } setup_filter_area() { this.custom_filter_configs = [ @@ -53,29 +49,41 @@ erpnext.hub.HubPage = class HubPage extends frappe.views.BaseList { this.filter_area = new FilterArea(this); } - setup_sort_selector() { + setup_sort_selector() { } - } - - setup_view() { + setup_view() { } + get_filters_for_args() { + let filters = {}; + this.filter_area.get().forEach(f => { + let field = f[1] !== 'name' ? f[1] : 'item_name'; + filters[field] = [f[2], f[3]]; + }); + if(this.current_category) { + filters['hub_category'] = this.current_category; + } + return filters; } get_args() { + console.log('filters', this.get_filters_for_args()); return { + doctype: 'Hub Item' start: this.start, limit: this.page_length, - category: this.category || '', order_by: this.order_by, - company: this.company || '', - text: this.search_text || '', - fields: this.fields + fields: this.fields, + filters: this.get_filters_for_args() + + // category: this.category || '', + // company: this.company || '', + // text: this.search_text || '', }; } update_data(r) { const data = r.message; - console.log('update data', data); + // console.log('update data', data); if (this.start === 0) { this.data = data; @@ -103,7 +111,7 @@ erpnext.hub.HubPage = class HubPage extends frappe.views.BaseList { render_image_view() { let data = this.data; - console.log('this.data render', this.data); + // console.log('this.data render', this.data); if (this.start === 0) { this.$result.html('
'); data = this.data.slice(this.start); @@ -117,6 +125,8 @@ erpnext.hub.HubPage = class HubPage extends frappe.views.BaseList { item._name = encodeURI(item.name); const encoded_name = item._name; const title = strip_html(item['item_name' || 'item_code']); + console.log(item); + const company_name = item['company_name']; const route = `#Hub/Item/${item.hub_item_code}`; @@ -137,9 +147,14 @@ erpnext.hub.HubPage = class HubPage extends frappe.views.BaseList {
${ title }
+

${ company_name }

`; } +}; + +erpnext.hub.CompanyListing = class CompanyListing extends frappe.views.BaseList { + }; \ No newline at end of file