From 5511e06f06255957195217352c5241e10a2ae16f Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Mon, 3 Sep 2018 02:25:41 +0530 Subject: [PATCH] [hub][api] Update save and view api to be user specific --- .../public/js/hub/components/detail_view.js | 138 ------------------ erpnext/public/js/hub/components/item_card.js | 80 ---------- erpnext/public/js/hub/pages/Item.vue | 4 +- erpnext/public/js/hub/pages/Profile.vue | 2 +- erpnext/public/js/hub/pages/SavedItems.vue | 6 +- 5 files changed, 6 insertions(+), 224 deletions(-) delete mode 100644 erpnext/public/js/hub/components/detail_view.js delete mode 100644 erpnext/public/js/hub/components/item_card.js diff --git a/erpnext/public/js/hub/components/detail_view.js b/erpnext/public/js/hub/components/detail_view.js deleted file mode 100644 index d80720c1da..0000000000 --- a/erpnext/public/js/hub/components/detail_view.js +++ /dev/null @@ -1,138 +0,0 @@ -import { get_rating_html } from './reviews'; - -function get_detail_view_html(item, allow_edit) { - const title = item.item_name || item.name; - const seller = item.company; - - const who = __('Posted By {0}', [seller]); - const when = comment_when(item.creation); - - const city = item.city ? item.city + ', ' : ''; - const country = item.country ? item.country : ''; - const where = `${city}${country}`; - - const dot_spacer = ''; - - const description = item.description || ''; - - let stats = __('No views yet'); - if(item.view_count) { - const views_message = __(`${item.view_count} Views`); - - const rating_html = get_rating_html(item.average_rating); - const rating_count = item.no_of_ratings > 0 ? `${item.no_of_ratings} reviews` : __('No reviews yet'); - - stats = `${views_message}${dot_spacer}${rating_html} (${rating_count})`; - } - - let favourite_button = '' - if (hub.settings.registered) { - favourite_button = !item.favourited - ? `` - : ``; - } - - const contact_seller_button = item.hub_seller !== hub.settings.company_email - ? `` - : ''; - - let menu_items = ''; - - if(allow_edit) { - menu_items = ` -
  • ${__('Edit Details')}
  • -
  • ${__('Unpublish')}
  • `; - } else { - menu_items = ` -
  • ${__('Report this item')}
  • - `; - } - - const html = ` -
    -
    -
    - -
    -
    -
    -
    -
    - -
    -
    -
    -
    -

    ${title}

    -
    -

    ${where}${dot_spacer}${when}

    -

    ${stats}

    -
    -
    - -
    - ${favourite_button} - ${contact_seller_button} -
    -
    -
    - -
    -
    -
    -
    - Item Description -
    -

    - ${description ? description : __('No details')} -

    -
    -
    - -
    - Seller Information -
    -
    - -
    -
    - -
    -
    - -
    - -
    -
    - `; - - return html; -} - -export { - get_detail_view_html, - get_profile_html -} diff --git a/erpnext/public/js/hub/components/item_card.js b/erpnext/public/js/hub/components/item_card.js deleted file mode 100644 index 41ab33aaf9..0000000000 --- a/erpnext/public/js/hub/components/item_card.js +++ /dev/null @@ -1,80 +0,0 @@ -function get_buying_item_message_card_html(item) { - const item_name = item.item_name || item.name; - const title = strip_html(item_name); - - const message = item.recent_message - const sender = message.sender === frappe.session.user ? 'You' : message.sender - const content = strip_html(message.content) - - // route - item.route = `marketplace/buying/${item.name}` - - const item_html = ` -
    -
    -
    - -
    -
    ${item_name}
    -
    - ${sender}: - ${content} -
    -
    -
    -
    - ${comment_when(message.creation, true)} -
    -
    -
    - `; - - return item_html; -} - -function get_selling_item_message_card_html(item) { - const item_name = item.item_name || item.name; - const title = strip_html(item_name); - - // route - if (!item.route) { - item.route = `marketplace/item/${item.name}` - } - - let received_messages = ''; - item.received_messages.forEach(message => { - const sender = message.sender === frappe.session.user ? 'You' : message.sender - const content = strip_html(message.content) - - received_messages += ` -
    - ${comment_when(message.creation, true)} -
    - ${sender}: - ${content} -
    -
    - ` - }); - - const item_html = ` -
    -
    - -
    ${item_name}
    -
    - ${received_messages} -
    -
    -
    - `; - - return item_html; -} - -export { - get_item_card_html, - get_local_item_card_html, - get_buying_item_message_card_html, - get_selling_item_message_card_html -} diff --git a/erpnext/public/js/hub/pages/Item.vue b/erpnext/public/js/hub/pages/Item.vue index 3305b1da4c..5d07bcd620 100644 --- a/erpnext/public/js/hub/pages/Item.vue +++ b/erpnext/public/js/hub/pages/Item.vue @@ -190,9 +190,9 @@ export default { }, add_to_saved_items() { - hub.call('add_item_to_seller_saved_items', { + hub.call('add_item_to_user_saved_items', { hub_item_name: this.hub_item_name, - hub_seller: hub.settings.company_email + hub_user: frappe.session.user }) .then(() => { const saved_items_link = `${__('Saved')}` diff --git a/erpnext/public/js/hub/pages/Profile.vue b/erpnext/public/js/hub/pages/Profile.vue index a0bc6cba78..91ed946761 100644 --- a/erpnext/public/js/hub/pages/Profile.vue +++ b/erpnext/public/js/hub/pages/Profile.vue @@ -52,7 +52,7 @@ export default { get_profile() { hub.call( 'get_hub_seller_profile', - { hub_seller: hub.settings.company_email } + { hub_seller: hub.settings.hub_seller_name } ).then(profile => { this.init = false; diff --git a/erpnext/public/js/hub/pages/SavedItems.vue b/erpnext/public/js/hub/pages/SavedItems.vue index e5d21cdd3c..c29675acd3 100644 --- a/erpnext/public/js/hub/pages/SavedItems.vue +++ b/erpnext/public/js/hub/pages/SavedItems.vue @@ -38,7 +38,7 @@ export default { methods: { get_items() { hub.call( - 'get_saved_items_of_seller', {}, + 'get_saved_items_of_user', {}, 'action:item_save' ) .then((items) => { @@ -83,9 +83,9 @@ export default { remove_item_from_saved_items(hub_item_name) { erpnext.hub.trigger('action:item_save'); - hub.call('remove_item_from_seller_saved_items', { + hub.call('remove_item_from_user_saved_items', { hub_item_name, - hub_seller: hub.settings.company_email + hub_user: frappe.session.user }) .then(() => { this.get_items();