[hub] record views, update favourite api

This commit is contained in:
Prateeksha Singh 2018-08-28 17:24:31 +05:30
parent 9a50044003
commit 1e02f00075
4 changed files with 50 additions and 13 deletions

View File

@ -28,7 +28,7 @@
<div class="row margin-bottom">
<div class="col-md-3">
<div class="hub-item-image">
<img :src="image">
<img v-img-src="image">
</div>
</div>
<div class="col-md-8">

View File

@ -54,6 +54,11 @@ export default {
sections: [],
menu_items: [
{
label: __('Save Item'),
condition: !this.is_own_item,
action: this.add_to_saved_items
},
{
label: __('Report this Product'),
condition: !this.is_own_item,
@ -127,11 +132,29 @@ export default {
}
},
created() {
this.get_profile();
this.get_item_details();
},
mounted() {
// To record a single view per session, (later)
// erpnext.hub.item_view_cache = erpnext.hub.item_view_cache || [];
// if (erpnext.hub.item_view_cache.includes(this.hub_item_name)) {
// return;
// }
this.item_received.then(() => {
setTimeout(() => {
hub.call('add_item_view', {
hub_item_name: this.hub_item_name
})
// .then(() => {
// erpnext.hub.item_view_cache.push(this.hub_item_name);
// });
}, 5000);
});
},
methods: {
get_profile() {
hub.call('get_item_details', { hub_item_name: this.hub_item_name })
get_item_details() {
this.item_received = hub.call('get_item_details', { hub_item_name: this.hub_item_name })
.then(item => {
this.init = false;
this.item = item;
@ -163,6 +186,21 @@ export default {
//
},
add_to_saved_items() {
hub.call('add_item_to_seller_saved_items', {
hub_item_name: this.hub_item_name,
hub_seller: hub.settings.company_email
})
.then(() => {
const saved_items_link = `<b><a href="#marketplace/saved-products">${__('Saved')}</a></b>`
frappe.show_alert(saved_items_link);
erpnext.hub.trigger('action:item_save');
})
.catch(e => {
console.error(e);
});
},
contact_seller() {
const d = new frappe.ui.Dialog({
title: __('Send a message'),

View File

@ -38,11 +38,8 @@ export default {
methods: {
get_items() {
hub.call(
'get_favourite_items_of_seller',
{
hub_seller: hub.settings.company_email
},
'action:item_favourite'
'get_saved_items_of_seller', {},
'action:item_save'
)
.then((items) => {
this.items = items;
@ -65,7 +62,9 @@ export default {
return false;
}
alert = frappe.show_alert(__(`<span>${hub_item_name} removed.
const item_name = this.items.filter(item => item.hub_item_name === hub_item_name);
alert = frappe.show_alert(__(`<span>${item_name} removed.
<a href="#" data-action="undo-remove"><b>Undo</b></a></span>`),
grace_period/1000,
{
@ -83,8 +82,8 @@ export default {
},
remove_item_from_saved_products(hub_item_name) {
erpnext.hub.trigger('action:item_favourite');
hub.call('remove_item_from_seller_favourites', {
erpnext.hub.trigger('action:item_save');
hub.call('remove_item_from_seller_saved_items', {
hub_item_name,
hub_seller: hub.settings.company_email
})

View File

@ -78,7 +78,7 @@ erpnext.hub.Item = class Item extends SubPage {
.then(() => {
$(favourite_button).html('Saved');
frappe.show_alert(__('Saved to <b><a href="#marketplace/favourites">Favourites</a></b>'));
erpnext.hub.trigger('action:item_favourite');
erpnext.hub.trigger('action:item_save');
})
.catch(e => {
console.error(e);