mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-07 15:12:51 +00:00
Merge branch 'hub-redesign' of https://github.com/frappe/erpnext into hub-redesign
This commit is contained in:
31
erpnext/public/js/hub/event_emitter.js
Normal file
31
erpnext/public/js/hub/event_emitter.js
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/**
|
||||||
|
* Simple EventEmitter which uses jQuery's event system
|
||||||
|
*/
|
||||||
|
class EventEmitter {
|
||||||
|
init() {
|
||||||
|
this.jq = jQuery(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
trigger(evt, data) {
|
||||||
|
!this.jq && this.init();
|
||||||
|
this.jq.trigger(evt, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
once(evt, handler) {
|
||||||
|
!this.jq && this.init();
|
||||||
|
this.jq.one(evt, (e, data) => handler(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
on(evt, handler) {
|
||||||
|
!this.jq && this.init();
|
||||||
|
this.jq.bind(evt, (e, data) => handler(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
off(evt, handler) {
|
||||||
|
!this.jq && this.init();
|
||||||
|
this.jq.unbind(evt, (e, data) => handler(data));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default EventEmitter;
|
||||||
@@ -2,7 +2,7 @@ frappe.provide('hub');
|
|||||||
frappe.provide('erpnext.hub');
|
frappe.provide('erpnext.hub');
|
||||||
|
|
||||||
erpnext.hub.cache = {};
|
erpnext.hub.cache = {};
|
||||||
hub.call = function call_hub_method(method, args={}) {
|
hub.call = function call_hub_method(method, args={}, setup_cache_invalidation = invalidate_after_5_mins) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
// cache
|
// cache
|
||||||
@@ -11,12 +11,9 @@ hub.call = function call_hub_method(method, args={}) {
|
|||||||
resolve(erpnext.hub.cache[key]);
|
resolve(erpnext.hub.cache[key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// cache invalidation after 5 minutes
|
// cache invalidation
|
||||||
const timeout = 5 * 60 * 1000;
|
const clear_cache = () => delete erpnext.hub.cache[key];
|
||||||
|
setup_cache_invalidation(clear_cache);
|
||||||
setTimeout(() => {
|
|
||||||
delete erpnext.hub.cache[key];
|
|
||||||
}, timeout);
|
|
||||||
|
|
||||||
frappe.call({
|
frappe.call({
|
||||||
method: 'erpnext.hub_node.api.call_hub_method',
|
method: 'erpnext.hub_node.api.call_hub_method',
|
||||||
@@ -42,3 +39,12 @@ hub.call = function call_hub_method(method, args={}) {
|
|||||||
.fail(reject)
|
.fail(reject)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function invalidate_after_5_mins(clear_cache) {
|
||||||
|
// cache invalidation after 5 minutes
|
||||||
|
const timeout = 5 * 60 * 1000;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
clear_cache();
|
||||||
|
}, timeout);
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,10 +17,13 @@ import { ProfileDialog } from './components/profile_dialog';
|
|||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
import './hub_call';
|
import './hub_call';
|
||||||
|
import EventEmitter from './event_emitter';
|
||||||
|
|
||||||
frappe.provide('hub');
|
frappe.provide('hub');
|
||||||
frappe.provide('erpnext.hub');
|
frappe.provide('erpnext.hub');
|
||||||
|
|
||||||
|
$.extend(erpnext.hub, EventEmitter.prototype);
|
||||||
|
|
||||||
erpnext.hub.Marketplace = class Marketplace {
|
erpnext.hub.Marketplace = class Marketplace {
|
||||||
constructor({ parent }) {
|
constructor({ parent }) {
|
||||||
this.$parent = $(parent);
|
this.$parent = $(parent);
|
||||||
|
|||||||
@@ -26,9 +26,11 @@ erpnext.hub.Favourites = class Favourites extends SubPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_favourites() {
|
get_favourites() {
|
||||||
return hub.call('get_favourite_items_of_seller', {
|
return hub.call(
|
||||||
hub_seller: hub.settings.company_email
|
'get_favourite_items_of_seller',
|
||||||
});
|
{ hub_seller: hub.settings.company_email },
|
||||||
|
clear_cache => erpnext.hub.on('action:item_favourite', clear_cache)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
render(items) {
|
render(items) {
|
||||||
|
|||||||
@@ -79,9 +79,10 @@ erpnext.hub.Item = class Item extends SubPage {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
$(favourite_button).html('Saved');
|
$(favourite_button).html('Saved');
|
||||||
frappe.show_alert(__('Saved to <b><a href="#marketplace/favourites">Favourites</a></b>'));
|
frappe.show_alert(__('Saved to <b><a href="#marketplace/favourites">Favourites</a></b>'));
|
||||||
|
erpnext.hub.trigger('action:item_favourite');
|
||||||
})
|
})
|
||||||
.catch(e => {
|
.catch(e => {
|
||||||
console.log(e);
|
console.error(e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user