Merge pull request #11154 from netchampfaris/hub-item-image

[hub] fix company page routing
This commit is contained in:
Faris Ansari 2017-10-27 17:07:10 +05:30 committed by GitHub
commit 638e3f9fa6
2 changed files with 33 additions and 22 deletions

View File

@ -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)

View File

@ -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: {hub_sync_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 {
<h2>${ company_details.company_name }</h2>
</div>
<div class="company">
<span class="">${ company_details.seller_city }</span>
<span class="">${ company_details.country }</span>
</div>
<div class="description">
<span class="small">${ company_details.seller_description }</span>
<span class="small">${ company_details.site_name }</span>
</div>
</div>
@ -835,7 +843,7 @@ erpnext.hub.HubList = class HubList {
</div>
</a>
<div class="company-link">
<a data-company-name="${ item.company_id }" class="">${ item.company_name }</a>
<a data-company-name="${ item.company_name }" class="">${ item.company_name }</a>
</div>
<div>${ item.formatted_price ? item.formatted_price : ''}</div>
</div>