mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 08:24:47 +00:00
[hub] sync in progress
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
# For license information, please see license.txt
|
# For license information, please see license.txt
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe, requests, json
|
import frappe, requests, json, time
|
||||||
from frappe.utils import now, nowdate, cint
|
from frappe.utils import now, nowdate, cint
|
||||||
from frappe.utils.nestedset import get_root_of
|
from frappe.utils.nestedset import get_root_of
|
||||||
from frappe.contacts.doctype.contact.contact import get_default_contact
|
from frappe.contacts.doctype.contact.contact import get_default_contact
|
||||||
@@ -35,7 +35,8 @@ def get_list(doctype, start=0, limit=20, fields=["*"], filters="{}", order_by=No
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_valid_items(search_value=''):
|
def get_valid_items(search_value=''):
|
||||||
items = frappe.get_list(
|
items = frappe.get_list(
|
||||||
'Item', fields=["*"],
|
'Item',
|
||||||
|
fields=["*"],
|
||||||
filters={
|
filters={
|
||||||
'item_name': ['like', '%' + search_value + '%'],
|
'item_name': ['like', '%' + search_value + '%'],
|
||||||
'publish_in_hub': 0
|
'publish_in_hub': 0
|
||||||
@@ -53,12 +54,14 @@ def get_valid_items(search_value=''):
|
|||||||
return valid_items
|
return valid_items
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def publish_selected_items(items_to_publish, items_to_unpublish):
|
def publish_selected_items(items_to_publish):
|
||||||
for item_code in json.loads(items_to_publish):
|
# for item_code in json.loads(items_to_publish):
|
||||||
frappe.db.set_value('Item', item_code, 'publish_in_hub', 1)
|
# frappe.db.set_value('Item', item_code, 'publish_in_hub', 1)
|
||||||
|
|
||||||
hub_settings = frappe.get_doc('Hub Settings')
|
time.sleep(3)
|
||||||
hub_settings.sync()
|
|
||||||
|
# hub_settings = frappe.get_doc('Hub Settings')
|
||||||
|
# hub_settings.sync()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -1,53 +1,23 @@
|
|||||||
frappe.ui.form.on("Hub Settings", {
|
frappe.ui.form.on("Hub Settings", {
|
||||||
refresh: function(frm) {
|
refresh: function(frm) {
|
||||||
|
frm.disable_save();
|
||||||
frm.add_custom_button(__('Logs'),
|
frm.add_custom_button(__('Logs'),
|
||||||
() => frappe.set_route('List', 'Data Migration Run', {
|
() => frappe.set_route('List', 'Data Migration Run', {
|
||||||
data_migration_plan: 'Hub Sync'
|
data_migration_plan: 'Hub Sync'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
frm.trigger("enabled");
|
|
||||||
|
|
||||||
if (frm.doc.enabled) {
|
if (frm.doc.enabled) {
|
||||||
frm.add_custom_button(__('Sync'),
|
frm.add_custom_button(__('Sync'),
|
||||||
() => frm.call('sync'));
|
() => frm.call('sync'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onload: function(frm) {
|
onload: function(frm) { },
|
||||||
let token = frappe.urllib.get_arg("access_token");
|
|
||||||
if(token) {
|
|
||||||
let email = frm.get_field("user");
|
|
||||||
console.log('token', frappe.urllib.get_arg("access_token"));
|
|
||||||
|
|
||||||
get_user_details(frm, token, email);
|
|
||||||
let row = frappe.model.add_child(frm.doc, "Hub Users", "users");
|
|
||||||
row.user = frappe.session.user;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!frm.doc.country) {
|
|
||||||
frm.set_value("country", frappe.defaults.get_default("Country"));
|
|
||||||
}
|
|
||||||
if(!frm.doc.company) {
|
|
||||||
frm.set_value("company", frappe.defaults.get_default("Company"));
|
|
||||||
}
|
|
||||||
if(!frm.doc.user) {
|
|
||||||
frm.set_value("user", frappe.session.user);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onload_post_render: function(frm) {
|
onload_post_render: function(frm) {
|
||||||
if(frm.get_field("unregister_from_hub").$input)
|
if(frm.get_field("unregister_from_hub").$input)
|
||||||
frm.get_field("unregister_from_hub").$input.addClass("btn-danger");
|
frm.get_field("unregister_from_hub").$input.addClass("btn-danger");
|
||||||
},
|
},
|
||||||
on_update: function(frm) {
|
on_update: function(frm) {
|
||||||
},
|
},
|
||||||
enabled: function(frm) {
|
|
||||||
if(!frm.doc.enabled) {
|
|
||||||
frm.trigger("set_enable_hub_primary_button");
|
|
||||||
} else {
|
|
||||||
frm.page.set_primary_action(__("Save Settings"), () => {
|
|
||||||
frm.save();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
hub_user_email: function(frm) {
|
hub_user_email: function(frm) {
|
||||||
if(frm.doc.hub_user_email){
|
if(frm.doc.hub_user_email){
|
||||||
@@ -55,39 +25,6 @@ frappe.ui.form.on("Hub Settings", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
set_enable_hub_primary_button: (frm) => {
|
|
||||||
frm.page.set_primary_action(__("Enable Hub"), () => {
|
|
||||||
if(frappe.session.user === "Administrator") {
|
|
||||||
frappe.msgprint(__("Please login as another user."))
|
|
||||||
} else {
|
|
||||||
// frappe.verify_password(() => {
|
|
||||||
|
|
||||||
// } );
|
|
||||||
|
|
||||||
frm.trigger("call_pre_reg");
|
|
||||||
// frm.trigger("call_register");
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
call_pre_reg: (frm) => {
|
|
||||||
this.frm.call({
|
|
||||||
doc: this.frm.doc,
|
|
||||||
method: "pre_reg",
|
|
||||||
args: {},
|
|
||||||
freeze: true,
|
|
||||||
callback: function(r) {
|
|
||||||
console.log(r.message);
|
|
||||||
authorize(frm, r.message.client_id, r.message.redirect_uri);
|
|
||||||
},
|
|
||||||
onerror: function() {
|
|
||||||
frappe.msgprint(__("Wrong Password"));
|
|
||||||
frm.set_value("enabled", 0);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
call_register: (frm) => {
|
call_register: (frm) => {
|
||||||
this.frm.call({
|
this.frm.call({
|
||||||
doc: this.frm.doc,
|
doc: this.frm.doc,
|
||||||
@@ -111,67 +48,3 @@ frappe.ui.form.on("Hub Settings", {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// let hub_url = 'https://hubmarket.org'
|
|
||||||
let hub_url = 'http://159.89.175.122'
|
|
||||||
// let hub_url = 'http://erpnext.hub:8000'
|
|
||||||
|
|
||||||
function authorize(frm, client_id, redirect_uri) {
|
|
||||||
|
|
||||||
// queryStringData is details of OAuth Client (Implicit Grant) on Custom App
|
|
||||||
var queryStringData = {
|
|
||||||
response_type : "token",
|
|
||||||
client_id : client_id,
|
|
||||||
redirect_uri : redirect_uri
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current raw route and build url
|
|
||||||
const route = "/desk#" + frappe.get_raw_route_str();
|
|
||||||
localStorage.removeItem("route"); // Clear previously set route if any
|
|
||||||
localStorage.setItem("route", route);
|
|
||||||
|
|
||||||
// Go authorize!
|
|
||||||
let api_route = "/api/method/frappe.integrations.oauth2.authorize?";
|
|
||||||
let url = hub_url + api_route + $.param(queryStringData);
|
|
||||||
window.location.replace(url, 'test');
|
|
||||||
}
|
|
||||||
|
|
||||||
function get_user_details(frm, token, email) {
|
|
||||||
console.log('user_details');
|
|
||||||
var route = localStorage.getItem("route");
|
|
||||||
if (token && route) {
|
|
||||||
// Clean up access token from route
|
|
||||||
frappe.set_route(frappe.get_route().join("/"))
|
|
||||||
|
|
||||||
// query protected resource e.g. Hub Items with token
|
|
||||||
var call = {
|
|
||||||
"async": true,
|
|
||||||
"crossDomain": true,
|
|
||||||
"url": hub_url + "/api/resource/User",
|
|
||||||
"method": "GET",
|
|
||||||
"data": {
|
|
||||||
// "email": email,
|
|
||||||
"fields": '["name", "first_name", "language"]',
|
|
||||||
"limit_page_length": 1
|
|
||||||
},
|
|
||||||
"headers": {
|
|
||||||
"authorization": "Bearer " + token,
|
|
||||||
"content-type": "application/x-www-form-urlencoded"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$.ajax(call).done(function (response) {
|
|
||||||
// display openid profile
|
|
||||||
console.log('response', response);
|
|
||||||
|
|
||||||
let data = response.data[0];
|
|
||||||
frm.set_value("enabled", 1);
|
|
||||||
frm.set_value("hub_username", data.first_name);
|
|
||||||
frm.set_value("hub_user_status", "Starter");
|
|
||||||
frm.set_value("language", data.language);
|
|
||||||
frm.save();
|
|
||||||
|
|
||||||
// clear route from localStorage
|
|
||||||
localStorage.removeItem("route");
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -44,6 +44,38 @@
|
|||||||
"translatable": 0,
|
"translatable": 0,
|
||||||
"unique": 0
|
"unique": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"allow_bulk_edit": 0,
|
||||||
|
"allow_in_quick_entry": 0,
|
||||||
|
"allow_on_submit": 0,
|
||||||
|
"bold": 0,
|
||||||
|
"collapsible": 0,
|
||||||
|
"columns": 0,
|
||||||
|
"fieldname": "sync_in_progress",
|
||||||
|
"fieldtype": "Check",
|
||||||
|
"hidden": 0,
|
||||||
|
"ignore_user_permissions": 0,
|
||||||
|
"ignore_xss_filter": 0,
|
||||||
|
"in_filter": 0,
|
||||||
|
"in_global_search": 0,
|
||||||
|
"in_list_view": 0,
|
||||||
|
"in_standard_filter": 0,
|
||||||
|
"label": "Sync in Progress",
|
||||||
|
"length": 0,
|
||||||
|
"no_copy": 0,
|
||||||
|
"permlevel": 0,
|
||||||
|
"precision": "",
|
||||||
|
"print_hide": 0,
|
||||||
|
"print_hide_if_no_value": 0,
|
||||||
|
"read_only": 0,
|
||||||
|
"remember_last_selected_value": 0,
|
||||||
|
"report_hide": 0,
|
||||||
|
"reqd": 0,
|
||||||
|
"search_index": 0,
|
||||||
|
"set_only_once": 0,
|
||||||
|
"translatable": 0,
|
||||||
|
"unique": 0
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"allow_bulk_edit": 0,
|
"allow_bulk_edit": 0,
|
||||||
"allow_in_quick_entry": 0,
|
"allow_in_quick_entry": 0,
|
||||||
@@ -611,7 +643,7 @@
|
|||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"istable": 0,
|
"istable": 0,
|
||||||
"max_attachments": 0,
|
"max_attachments": 0,
|
||||||
"modified": "2018-07-24 18:53:09.442523",
|
"modified": "2018-07-26 15:56:36.104768",
|
||||||
"modified_by": "cave@aperture.com",
|
"modified_by": "cave@aperture.com",
|
||||||
"module": "Hub Node",
|
"module": "Hub Node",
|
||||||
"name": "Hub Settings",
|
"name": "Hub Settings",
|
||||||
|
|||||||
@@ -138,11 +138,14 @@ erpnext.hub.Marketplace = class Marketplace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (route[1] === 'profile' && !this.subpages.profile) {
|
if (route[1] === 'profile' && !this.subpages.profile) {
|
||||||
this.subpages.profile = new erpnext.hub.Profile(this.$body, this.hub_settings);
|
this.subpages.profile = new erpnext.hub.Profile(this.$body, {data: this.hub_settings});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (route[1] === 'publish' && !this.subpages.publish) {
|
if (route[1] === 'publish' && !this.subpages.publish) {
|
||||||
this.subpages.publish = new erpnext.hub.Publish(this.$body);
|
this.subpages.publish = new erpnext.hub.Publish(
|
||||||
|
this.$body,
|
||||||
|
{sync_in_progress: this.hub_settings.sync_in_progress}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Object.keys(this.subpages).includes(route[1])) {
|
if (!Object.keys(this.subpages).includes(route[1])) {
|
||||||
@@ -157,9 +160,9 @@ erpnext.hub.Marketplace = class Marketplace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class SubPage {
|
class SubPage {
|
||||||
constructor(parent) {
|
constructor(parent, options) {
|
||||||
this.$parent = $(parent);
|
this.$parent = $(parent);
|
||||||
this.make_wrapper();
|
this.make_wrapper(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
make_wrapper() {
|
make_wrapper() {
|
||||||
@@ -621,8 +624,14 @@ erpnext.hub.Profile = class Profile extends SubPage {
|
|||||||
render() {}
|
render() {}
|
||||||
}
|
}
|
||||||
erpnext.hub.Publish = class Publish extends SubPage {
|
erpnext.hub.Publish = class Publish extends SubPage {
|
||||||
make_wrapper() {
|
make_wrapper(options) {
|
||||||
super.make_wrapper();
|
super.make_wrapper();
|
||||||
|
this.sync_in_progress = options.sync_in_progress;
|
||||||
|
|
||||||
|
this.load_publish_page();
|
||||||
|
}
|
||||||
|
|
||||||
|
load_publish_page() {
|
||||||
const title_html = `<b>${__('Select Products to Publish')}</b>`;
|
const title_html = `<b>${__('Select Products to Publish')}</b>`;
|
||||||
const info = `<p class="text-muted">${__("Status decided by the 'Publish in Hub' field in Item.")}</p>`;
|
const info = `<p class="text-muted">${__("Status decided by the 'Publish in Hub' field in Item.")}</p>`;
|
||||||
const subtitle_html = `
|
const subtitle_html = `
|
||||||
@@ -660,17 +669,10 @@ erpnext.hub.Publish = class Publish extends SubPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setup_events() {
|
setup_events() {
|
||||||
// this.$wrapper.find('.select-all').on('click', () => {
|
|
||||||
// this.$wrapper.find('.hub-card').addClass('active');
|
|
||||||
// });
|
|
||||||
|
|
||||||
// this.$wrapper.find('.deselect-all').on('click', () => {
|
|
||||||
// this.$wrapper.find('.hub-card').removeClass('active');
|
|
||||||
// });
|
|
||||||
|
|
||||||
this.$wrapper.find('.publish-items').on('click', () => {
|
this.$wrapper.find('.publish-items').on('click', () => {
|
||||||
this.publish_selected_items()
|
this.publish_selected_items()
|
||||||
.then(r => {
|
.then(r => {
|
||||||
|
this.load_publishing_state();
|
||||||
frappe.msgprint('check');
|
frappe.msgprint('check');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -687,6 +689,11 @@ erpnext.hub.Publish = class Publish extends SubPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_items_and_render() {
|
get_items_and_render() {
|
||||||
|
if(this.sync_in_progress) {
|
||||||
|
this.load_publishing_state();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.$wrapper.find('.hub-card-container').empty();
|
this.$wrapper.find('.hub-card-container').empty();
|
||||||
this.get_valid_items()
|
this.get_valid_items()
|
||||||
.then(r => {
|
.then(r => {
|
||||||
@@ -703,6 +710,18 @@ erpnext.hub.Publish = class Publish extends SubPage {
|
|||||||
items_container.addClass('static').on('click', '.hub-card', (e) => {
|
items_container.addClass('static').on('click', '.hub-card', (e) => {
|
||||||
const $target = $(e.currentTarget);
|
const $target = $(e.currentTarget);
|
||||||
$target.toggleClass('active');
|
$target.toggleClass('active');
|
||||||
|
|
||||||
|
// Get total items
|
||||||
|
const total_items = this.$wrapper.find('.hub-card.active').length;
|
||||||
|
const more_than_one = total_items > 1;
|
||||||
|
this.$wrapper.find('.publish-items')
|
||||||
|
.html(__('Publish ' + total_items + ' item' + (more_than_one ? 's' : '')));
|
||||||
|
|
||||||
|
// if($target.hasClass('active')) {
|
||||||
|
// $target.addClass('active');
|
||||||
|
// } else {
|
||||||
|
// $target.removeClass('active');
|
||||||
|
// }
|
||||||
});
|
});
|
||||||
|
|
||||||
this.$wrapper.append(items_container);
|
this.$wrapper.append(items_container);
|
||||||
@@ -717,24 +736,22 @@ erpnext.hub.Publish = class Publish extends SubPage {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
load_publishing_state() {
|
||||||
|
this.$wrapper.html(`<div>
|
||||||
|
<b>Publishing</b>
|
||||||
|
</div>`);
|
||||||
|
}
|
||||||
|
|
||||||
publish_selected_items() {
|
publish_selected_items() {
|
||||||
const items_to_publish = [];
|
const items_to_publish = [];
|
||||||
const items_to_unpublish = [];
|
this.$wrapper.find('.hub-card.active').map(function () {
|
||||||
this.$wrapper.find('.hub-card').map(function () {
|
items_to_publish.push($(this).attr("data-id"));
|
||||||
const active = $(this).hasClass('active');
|
|
||||||
|
|
||||||
if(active) {
|
|
||||||
items_to_publish.push($(this).attr("data-id"));
|
|
||||||
} else {
|
|
||||||
items_to_unpublish.push($(this).attr("data-id"));
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return frappe.call(
|
return frappe.call(
|
||||||
'erpnext.hub_node.publish_selected_items',
|
'erpnext.hub_node.publish_selected_items',
|
||||||
{
|
{
|
||||||
items_to_publish: items_to_publish,
|
items_to_publish: items_to_publish
|
||||||
items_to_unpublish: items_to_unpublish
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user