From cf2d2a5c754e92438572aa43fc6f4dede0dd0c66 Mon Sep 17 00:00:00 2001 From: Prateeksha Singh Date: Wed, 25 Jul 2018 20:02:12 +0530 Subject: [PATCH] [hub][init] add publish items page --- erpnext/hub_node/__init__.py | 14 ++- erpnext/public/js/hub/hub_listing.js | 180 +++++++++++++-------------- erpnext/public/less/hub.less | 40 +++++- 3 files changed, 133 insertions(+), 101 deletions(-) diff --git a/erpnext/hub_node/__init__.py b/erpnext/hub_node/__init__.py index a94f6b1615..138ff1e40e 100644 --- a/erpnext/hub_node/__init__.py +++ b/erpnext/hub_node/__init__.py @@ -31,12 +31,18 @@ def get_list(doctype, start=0, limit=20, fields=["*"], filters="{}", order_by=No return listing - - +#### LOCAL ITEMS @frappe.whitelist() def get_valid_items(): - items = frappe.get_list('Item') - return items + items = frappe.get_list('Item', fields=["*"]) + valid_items = filter(lambda x: x.image and x.description, items) + + def attach_source_type(item): + item.source_type = "local" + return item + + valid_items = map(lambda x: attach_source_type(x), valid_items) + return valid_items @frappe.whitelist() def get_item_favourites(start=0, limit=20, fields=["*"], order_by=None): diff --git a/erpnext/public/js/hub/hub_listing.js b/erpnext/public/js/hub/hub_listing.js index 218960bb17..856d538dd2 100644 --- a/erpnext/public/js/hub/hub_listing.js +++ b/erpnext/public/js/hub/hub_listing.js @@ -26,6 +26,8 @@ erpnext.hub.Marketplace = class Marketplace { const $target = $(e.currentTarget); const route = $target.data().route; frappe.set_route(route); + + e.stopPropagation(); }); } @@ -43,6 +45,12 @@ erpnext.hub.Marketplace = class Marketplace {
  • ${__('Become a seller')}
  • +
  • + ${__('Your Profile')} +
  • +
  • + ${__('Publish Products')} +
  • `); @@ -60,6 +68,9 @@ erpnext.hub.Marketplace = class Marketplace { `
  • ${__('All')}
  • `, + `
  • + ${__('Your Products')} +
  • `, ...categories.map(category => `
  • ${__(category)} @@ -119,6 +130,10 @@ erpnext.hub.Marketplace = class Marketplace { this.subpages.register = new erpnext.hub.Register(this.$body); } + if (route[1] === 'publish' && !this.subpages.publish) { + this.subpages.publish = new erpnext.hub.Publish(this.$body); + } + if (!Object.keys(this.subpages).includes(route[1])) { frappe.show_not_found(); @@ -217,7 +232,7 @@ erpnext.hub.Favourites = class Favourites extends SubPage { render(items) { const html = get_item_card_container_html(items, __('Favourites')); - this.$wrapper.html(html) + this.$wrapper.append(html) } } @@ -241,7 +256,7 @@ erpnext.hub.Category = class Category extends SubPage { render(items) { const html = get_item_card_container_html(items, __(this.category)); - this.$wrapper.html(html) + this.$wrapper.append(html) } } @@ -551,77 +566,42 @@ erpnext.hub.Register = class Register extends SubPage { }); }); } - - make_form() { - const form_html = `
    -
    - Become a Seller -
    - -
    -
    -
    -
    - -
    -
    -
    - -
    -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    - -
    -
    -
    -
    `; - - - - this.$form_container.append(form_html); - - this.$form_container.on('submit', (e) => { - e.preventDefault(); - - const formValues = this.$form_container.find('form').serializeArray(); - - console.log(formValues); - }) - } } -erpnext.hub.PublishItems = class PublishItems extends SubPage { +erpnext.hub.Publish = class Publish extends SubPage { + constructor(parent) { + super(parent); + // this.selected_items = []; + } + refresh() { - this.get_favourites() + this.get_valid_items() .then(r => { this.render(r.message); }); } render(items) { - const html = get_item_card_container_html(items, __(this.category)); - this.$wrapper.html(html); + const html = get_item_card_container_html( + items, + + __('Select Products to Publish'), + + __(`Only products with an image and description can be published. + Please update them if an item in your inventory does not appear.`), + + `
    + +
    ` + ); + + const container = $(html); + container.addClass('static').on('click', '.hub-card', (e) => { + const $target = $(e.currentTarget); + $target.toggleClass('active'); + }); + + this.$wrapper.append(container); } get_valid_items() { @@ -629,17 +609,23 @@ erpnext.hub.PublishItems = class PublishItems extends SubPage { } } -function get_item_card_container_html(items, title) { - const html = (items || []).map(item => get_item_card_html(item)).join(''); +function get_item_card_container_html(items, title, subtitle='', search_html='') { + const items_html = (items || []).map(item => get_item_card_html(item)).join(''); - return ` -
    -
    - ${title} -
    - ${html} + const html = `
    +
    + ${title} + +

    ${subtitle}

    + + ${search_html}
    - `; + + ${items_html} + +
    `; + + return html; } function get_item_card_html(item) { @@ -648,8 +634,8 @@ function get_item_card_html(item) { const img_url = item.image; const company_name = item.company_name; - const route = `marketplace/item/${item.hub_item_code}`; + // Subtitle let subtitle = [comment_when(item.creation)]; const rating = get_rating(item); if (rating > 0) { @@ -660,16 +646,36 @@ function get_item_card_html(item) { let dot_spacer = ''; subtitle = subtitle.join(dot_spacer); + // Decide item link + const isLocal = item.source_type === "local"; + const route = !isLocal + ? `marketplace/item/${item.hub_item_code}` + : `Form/Item/${item.item_name}`; + + const card_route = isLocal ? '' : `data-route='${route}'`; + + const show_local_item_button = isLocal + ? `
    + +
    ` + : ''; + const item_html = `
    -
    +
    -
    ${title}
    -
    ${subtitle}
    +
    +
    ${title}
    +
    ${subtitle}
    +
    +
    -
    +
    + ${show_local_item_button}
    @@ -904,23 +910,7 @@ erpnext.hub.HubListing = class HubListing extends frappe.views.BaseList { } renderHeader() { - return `
    -
    -
    - Riadco Group - Products by Blah blah -
    -
    -
    -
    - - -
    -
    -
    - ${''} -
    -
    `; + return ``; } get_image_html(encoded_name, src, alt_text) { diff --git a/erpnext/public/less/hub.less b/erpnext/public/less/hub.less index 35e1f8de8f..1243743032 100644 --- a/erpnext/public/less/hub.less +++ b/erpnext/public/less/hub.less @@ -21,6 +21,16 @@ body[data-route^="marketplace/"] { font-size: @text-medium; } + .btn-primary { + background-color: #89da28; + border-color: #61ca23; + } + + .btn-primary:hover { + background-color: #61ca23; + border-color: #59b81c; + } + .hub-card { border: 1px solid @border-color; margin-bottom: 25px; @@ -28,15 +38,33 @@ body[data-route^="marketplace/"] { overflow: hidden; cursor: pointer; - &:hover .hub-card-overlay { + &:hover .overlay { display: block; } + + &.active { + .hub-card-header { + background-color: #f4ffe5; + } + + .octicon-check { + display: inline; + } + } } .hub-card-header { padding: 12px 15px; height: 60px; border-bottom: 1px solid @border-color; + + display: flex; + justify-content: space-between; + + .octicon-check { + display: none; + font-size: 20px; + } } .hub-card-body { @@ -44,15 +72,23 @@ body[data-route^="marketplace/"] { height: 200px; } - .hub-card-overlay { + .overlay { display: none; position: absolute; + } + + .hub-card-overlay { top: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.1); } + .button-overlay { + top: 155px; + left: 15px; + } + .hub-card-image { min-width: 100%; width: 100%;