From 79972713682347883eed84a2fbc533669c90a7b2 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Wed, 11 Oct 2017 15:46:21 +0530 Subject: [PATCH] [hub] fix company page routing --- erpnext/hub_node/__init__.py | 5 +++- erpnext/hub_node/page/hub/hub.js | 50 ++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/erpnext/hub_node/__init__.py b/erpnext/hub_node/__init__.py index 686fe8d202..3216f0d753 100644 --- a/erpnext/hub_node/__init__.py +++ b/erpnext/hub_node/__init__.py @@ -15,13 +15,16 @@ def enable_hub(): return hub_settings @frappe.whitelist() -def get_items(start=0, limit=20, category=None, order_by=None, text=None): +def get_items(start=0, limit=20, category=None, order_by=None, company=None, text=None): connection = get_connection() filters = { 'hub_category': category, } if text: filters.update({'item_name': ('like', '%' + text + '%')}) + if company: + filters.update({'company_name': company}) + response = connection.get_list('Hub Item', limit_start=start, limit_page_length=limit, filters=filters) diff --git a/erpnext/hub_node/page/hub/hub.js b/erpnext/hub_node/page/hub/hub.js index 143f55444f..b065f0a197 100644 --- a/erpnext/hub_node/page/hub/hub.js +++ b/erpnext/hub_node/page/hub/hub.js @@ -215,7 +215,7 @@ erpnext.hub.Hub = class Hub { .on('click', '.company-link a', function(e) { e.preventDefault(); const company_name = $(this).attr('data-company-name'); - me.get_company_details(company_name); + frappe.set_route('hub', 'Company', company_name); }) .on('click', '.breadcrumb li', function(e) { e.preventDefault(); @@ -475,26 +475,34 @@ erpnext.hub.Hub = class Hub { } get_company_details(company_id) { - // get from cache if exists - let company_details = this.company_cache[company_id]; - if(this.company_cache[company_id]) { - this.go_to_company_page(company_details); - return; - } - frappe.call({ - method: 'erpnext.hub_node.get_company_details', - args: {company_id: company_id} - }).then((r) => { - if (r.message) { - const company_details = r.message.company_details; - this.company_cache[company_id] = company_details; - this.go_to_company_page(company_details) + this.company_cache = this.company_cache || {}; + + return new Promise(resolve => { + // get from cache if exists + let company_details = this.company_cache[company_id]; + if(company_details) { + resolve(company_details); + return; } - }); + frappe.call({ + method: 'erpnext.hub_node.get_company_details', + args: {hub_sync_id: company_id} + }).then((r) => { + if (r.message) { + const company_details = r.message; + this.company_cache[company_id] = company_details; + resolve(company_details) + } + }); + }) } - go_to_company_page(company_details) { - frappe.set_route('hub', 'Company', company_details.company_name); + go_to_company_page(company_id) { + this.get_company_details(company_id) + .then(this.show_company_page.bind(this)); + } + + show_company_page(company_details) { this.$hub_main_section.empty(); let $company_page = @@ -573,10 +581,10 @@ erpnext.hub.Hub = class Hub {

${ company_details.company_name }

- ${ company_details.seller_city } + ${ company_details.country }
- ${ company_details.seller_description } + ${ company_details.site_name }
@@ -835,7 +843,7 @@ erpnext.hub.HubList = class HubList {
${ item.formatted_price ? item.formatted_price : ''}