From d29a3b35671fdcad3e83e6c6c6299d17fadfc2f0 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 21 Aug 2018 19:12:10 +0530 Subject: [PATCH 1/4] Highlight links with part route or full route --- erpnext/public/js/hub/marketplace.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/erpnext/public/js/hub/marketplace.js b/erpnext/public/js/hub/marketplace.js index 953efe4c71..a7b7761f26 100644 --- a/erpnext/public/js/hub/marketplace.js +++ b/erpnext/public/js/hub/marketplace.js @@ -149,8 +149,10 @@ erpnext.hub.Marketplace = class Marketplace { update_sidebar() { const route = frappe.get_route(); - const route_str = route.slice(0, 2).join('/'); - const $sidebar_item = this.$sidebar.find(`[data-route="${route_str}"]`); + const route_str = route.join('/'); + const part_route_str = route.slice(0, 2).join('/'); + const $sidebar_item = this.$sidebar.find(`[data-route="${route_str}"], [data-route="${part_route_str}"]`); + const $siblings = this.$sidebar.find('[data-route]'); $siblings.removeClass('active').addClass('text-muted'); From ff189b6853c21cc6160256fae4047150a8d073f2 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 21 Aug 2018 19:14:44 +0530 Subject: [PATCH 2/4] fix: publish items - Pass image data as a json - ignore duplicates while creating Hub Tracked Item --- erpnext/hub_node/api.py | 2 +- .../item_to_hub_item/__init__.py | 29 ++++++++++++------- .../doctype/hub_settings/hub_settings.py | 1 + .../hub_tracked_item/test_hub_tracked_item.js | 23 --------------- erpnext/public/js/hub/pages/publish.js | 2 +- 5 files changed, 21 insertions(+), 36 deletions(-) delete mode 100644 erpnext/hub_node/doctype/hub_tracked_item/test_hub_tracked_item.js diff --git a/erpnext/hub_node/api.py b/erpnext/hub_node/api.py index 0c9af1abc1..a8958ab59e 100644 --- a/erpnext/hub_node/api.py +++ b/erpnext/hub_node/api.py @@ -56,7 +56,7 @@ def publish_selected_items(items_to_publish): 'item_code': item_code, 'hub_category': item.get('hub_category'), 'image_list': item.get('image_list') - }).insert() + }).insert(ignore_if_duplicate=True) try: hub_settings = frappe.get_doc('Hub Settings') diff --git a/erpnext/hub_node/data_migration_mapping/item_to_hub_item/__init__.py b/erpnext/hub_node/data_migration_mapping/item_to_hub_item/__init__.py index 0b6b2bc8a8..eb57f3a98a 100644 --- a/erpnext/hub_node/data_migration_mapping/item_to_hub_item/__init__.py +++ b/erpnext/hub_node/data_migration_mapping/item_to_hub_item/__init__.py @@ -1,19 +1,26 @@ -import frappe, io, base64, urllib, os +import frappe, io, base64, urllib, os, json +from frappe.utils.file_manager import get_file_path def pre_process(doc): - # file_path = doc.image - # file_name = os.path.basename(file_path) + file_path = doc.image + file_name = os.path.basename(file_path) - # if file_path.startswith('http'): - # url = file_path - # file_path = os.path.join('/tmp', file_name) - # urllib.urlretrieve(url, file_path) + if file_path.startswith('http'): + url = file_path + file_path = os.path.join('/tmp', file_name) + urllib.urlretrieve(url, file_path) + else: + file_path = os.path.abspath(get_file_path(file_path)) - # with io.open(file_path, 'rb') as f: - # doc.image = base64.b64encode(f.read()) - - # doc.image_file_name = file_name + try: + with io.open(file_path, 'rb') as f: + doc.image = json.dumps({ + 'file_name': file_name, + 'base64': base64.b64encode(f.read()) + }) + except Exception as e: + frappe.log_error(title='Hub Sync Error') cached_details = frappe.get_doc('Hub Tracked Item', doc.item_code) diff --git a/erpnext/hub_node/doctype/hub_settings/hub_settings.py b/erpnext/hub_node/doctype/hub_settings/hub_settings.py index 8ec3d5621f..0044cefcbd 100644 --- a/erpnext/hub_node/doctype/hub_settings/hub_settings.py +++ b/erpnext/hub_node/doctype/hub_settings/hub_settings.py @@ -81,6 +81,7 @@ class HubSettings(Document): def create_hub_connector(self, message): if frappe.db.exists('Data Migration Connector', 'Hub Connector'): hub_connector = frappe.get_doc('Data Migration Connector', 'Hub Connector') + hub_connector.hostname = self.get_hub_url() hub_connector.username = message['email'] hub_connector.password = message['password'] hub_connector.save() diff --git a/erpnext/hub_node/doctype/hub_tracked_item/test_hub_tracked_item.js b/erpnext/hub_node/doctype/hub_tracked_item/test_hub_tracked_item.js deleted file mode 100644 index 9f7314d399..0000000000 --- a/erpnext/hub_node/doctype/hub_tracked_item/test_hub_tracked_item.js +++ /dev/null @@ -1,23 +0,0 @@ -/* eslint-disable */ -// rename this file from _test_[name] to test_[name] to activate -// and remove above this line - -QUnit.test("test: Hub Tracked Item", function (assert) { - let done = assert.async(); - - // number of asserts - assert.expect(1); - - frappe.run_serially([ - // insert a new Hub Tracked Item - () => frappe.tests.make('Hub Tracked Item', [ - // values to be set - {key: 'value'} - ]), - () => { - assert.equal(cur_frm.doc.key, 'value'); - }, - () => done() - ]); - -}); diff --git a/erpnext/public/js/hub/pages/publish.js b/erpnext/public/js/hub/pages/publish.js index 98b0a61845..ce73d63fd4 100644 --- a/erpnext/public/js/hub/pages/publish.js +++ b/erpnext/public/js/hub/pages/publish.js @@ -187,7 +187,7 @@ erpnext.hub.Publish = class Publish extends SubPage { show_publish_progress() { const items_to_publish = this.items_data_to_publish.length ? this.items_data_to_publish - : JSON.parse(hub.settings.custom_data); + : JSON.parse(hub.settings.custom_data || '[]'); const $publish_progress = $(`

${__(`Syncing ${items_to_publish.length} Products`)}

From e7af44f1a6857ccb4dbe44955d5ef512b00dce3d Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 21 Aug 2018 19:48:06 +0530 Subject: [PATCH 3/4] fix: remove items with invalid image --- erpnext/public/js/hub/components/item_card.js | 4 ++-- erpnext/public/js/hub/pages/publish.js | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/erpnext/public/js/hub/components/item_card.js b/erpnext/public/js/hub/components/item_card.js index 9f5a6ef683..a1b0ae022d 100644 --- a/erpnext/public/js/hub/components/item_card.js +++ b/erpnext/public/js/hub/components/item_card.js @@ -21,7 +21,7 @@ function get_item_card_html(item) { } const item_html = ` -
+
@@ -74,7 +74,7 @@ function get_local_item_card_html(item) {
`; const item_html = ` -
+
diff --git a/erpnext/public/js/hub/pages/publish.js b/erpnext/public/js/hub/pages/publish.js index 5eb317891c..f49365833e 100644 --- a/erpnext/public/js/hub/pages/publish.js +++ b/erpnext/public/js/hub/pages/publish.js @@ -226,7 +226,14 @@ erpnext.hub.Publish = class Publish extends SubPage { items.map(item => { this.fetched_items_dict[item.item_code] = item; - }) + }); + + // remove the items which doesn't have a valid image + setTimeout(() => { + items_container.find('.no-image').each(function() { + $(this).closest('.hub-card-container').remove(); + }); + }, 1000); } get_valid_items() { From e745e85d98ae0bf2b161ff877539eecc9d24cbb4 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 21 Aug 2018 19:48:42 +0530 Subject: [PATCH 4/4] feat: route to message room page after contact seller dialog --- erpnext/public/js/hub/pages/item.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/public/js/hub/pages/item.js b/erpnext/public/js/hub/pages/item.js index 421d7ef29f..9f40971476 100644 --- a/erpnext/public/js/hub/pages/item.js +++ b/erpnext/public/js/hub/pages/item.js @@ -113,7 +113,7 @@ erpnext.hub.Item = class Item extends SubPage { }) .then(() => { d.hide(); - frappe.set_route('marketplace', 'messages'); + frappe.set_route('marketplace', 'buy', this.item.hub_item_code); erpnext.hub.trigger('action:send_message') }); }