Mathias Markl 7 years ago
parent
commit
624fac12ad
  1. 2
      muk_web_client_refresh/__manifest__.py
  2. 2
      muk_web_client_refresh/controllers/main.py
  3. 30
      muk_web_client_refresh/data/refresh_actions.xml
  4. 5
      muk_web_client_refresh/doc/changelog.rst
  5. 36
      muk_web_client_refresh/static/src/js/client_refresh.js
  6. 14
      muk_web_client_refresh/views/refresh_action_view.xml

2
muk_web_client_refresh/__manifest__.py

@ -20,7 +20,7 @@
{ {
"name": "MuK Web Refresh", "name": "MuK Web Refresh",
"summary": """Web Client Refresh""", "summary": """Web Client Refresh""",
"version": "11.0.2.0.0",
"version": "11.0.2.1.0",
"category": "Extra Tools", "category": "Extra Tools",
"license": "AGPL-3", "license": "AGPL-3",
"website": "http://www.mukit.at", "website": "http://www.mukit.at",

2
muk_web_client_refresh/controllers/main.py

@ -30,5 +30,5 @@ class RefreshController(http.Controller):
def refresh_delay(self, **kw): def refresh_delay(self, **kw):
params = request.env['ir.config_parameter'].sudo() params = request.env['ir.config_parameter'].sudo()
return { return {
'refresh_delay': int(params.get_param("muk_web_client_refresh.refresh_delay", default=10000))
'refresh_delay': int(params.get_param("muk_web_client_refresh.refresh_delay", default=1000))
} }

30
muk_web_client_refresh/data/refresh_actions.xml

@ -24,7 +24,11 @@
<field name="model_id" ref="base.model_res_partner" /> <field name="model_id" ref="base.model_res_partner" />
<field name="state">code</field> <field name="state">code</field>
<field name="trigger">on_create</field> <field name="trigger">on_create</field>
<field name="code">env["bus.bus"].sendone("refresh", {"model": model._name, "uid": env.user.id, "ids": (record | records).mapped("id")})</field>
<field name="code">env["bus.bus"].sendone("refresh", {
"create": record.exists() and record.create_date == record.write_date,
"model": model._name,
"uid": env.user.id,
"ids": (record | records).mapped("id")})</field>
</record> </record>
<record id="base_automation_refresh_partner_on_write" model="base.automation"> <record id="base_automation_refresh_partner_on_write" model="base.automation">
@ -32,7 +36,11 @@
<field name="model_id" ref="base.model_res_partner" /> <field name="model_id" ref="base.model_res_partner" />
<field name="state">code</field> <field name="state">code</field>
<field name="trigger">on_write</field> <field name="trigger">on_write</field>
<field name="code">env["bus.bus"].sendone("refresh", {"model": model._name, "uid": env.user.id, "ids": (record | records).mapped("id")})</field>
<field name="code">env["bus.bus"].sendone("refresh", {
"create": record.exists() and record.create_date == record.write_date,
"model": model._name,
"uid": env.user.id,
"ids": (record | records).mapped("id")})</field>
</record> </record>
<record id="base_automation_refresh_partner_on_unlink" model="base.automation"> <record id="base_automation_refresh_partner_on_unlink" model="base.automation">
@ -40,7 +48,23 @@
<field name="model_id" ref="base.model_res_partner" /> <field name="model_id" ref="base.model_res_partner" />
<field name="state">code</field> <field name="state">code</field>
<field name="trigger">on_unlink</field> <field name="trigger">on_unlink</field>
<field name="code">env["bus.bus"].sendone("refresh", {"model": model._name, "uid": env.user.id, "ids": (record | records).mapped("id")})</field>
<field name="code">env["bus.bus"].sendone("refresh", {
"create": record.exists() and record.create_date == record.write_date,
"model": model._name,
"uid": env.user.id,
"ids": (record | records).mapped("id")})</field>
</record>
<record id="base_automation_refresh_partner_on_create_or_write" model="base.automation">
<field name="name">Refresh Users on Creation/Update</field>
<field name="model_id" ref="base.model_res_users" />
<field name="state">code</field>
<field name="trigger">on_create_or_write</field>
<field name="code">env["bus.bus"].sendone("refresh", {
"create": record.exists() and record.create_date == record.write_date,
"model": model._name,
"uid": env.user.id,
"ids": (record | records).mapped("id")})</field>
</record> </record>
</odoo> </odoo>

5
muk_web_client_refresh/doc/changelog.rst

@ -1,3 +1,8 @@
`2.1.0`
-------
- Reduced unnecessary refresh calls
`2.0.0` `2.0.0`
------- -------

36
muk_web_client_refresh/static/src/js/client_refresh.js

@ -43,23 +43,27 @@ WebClient.include({
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
}, },
refresh: function(message) { refresh: function(message) {
var self = this;
utils.delay(function() {
var widget = self.action_manager && self.action_manager.inner_widget;
var active_view = widget ? widget.active_view : false;
if (active_view && message.uid && session.uid !== message.uid) {
var controller = self.action_manager.inner_widget.active_view.controller;
if(controller.modelName === message.model && controller.mode === "readonly") {
if(active_view.type === "form" && message.ids.includes(widget.env.currentId)) {
controller.reload();
} else if(active_view.type === "list") {
controller.reload();
} else if(active_view.type === "kanban") {
controller.reload();
}
}
var widget = this.action_manager && this.action_manager.inner_widget;
var active_view = widget ? widget.active_view : false;
if (active_view && message.uid && session.uid !== message.uid) {
var controller = this.action_manager.inner_widget.active_view.controller;
if(controller.modelName === message.model && controller.mode === "readonly") {
if(active_view.type === "form" && message.ids.includes(widget.env.currentId)) {
this.reload(controller);
} else if(active_view.type === "list" &&
(message.create || _.intersection(message.ids, widget.env.ids) >= 1)) {
this.reload(controller);
} else if(active_view.type === "kanban" &&
(message.create || _.intersection(message.ids, widget.env.ids) >= 1)) {
this.reload(controller);
}
} }
}, self.refresh_delay || 1000);
}
},
reload: function(controller) {
utils.delay(function() {
controller.reload();
}, this.refresh_delay || 1000);
}, },
}); });

14
muk_web_client_refresh/views/refresh_action_view.xml

@ -41,7 +41,7 @@
<field name="name">base.automation.tree</field> <field name="name">base.automation.tree</field>
<field name="model">base.automation</field> <field name="model">base.automation</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Automation">
<tree string="Automations">
<field name="sequence" widget="handle"/> <field name="sequence" widget="handle"/>
<field name="name"/> <field name="name"/>
<field name="trigger"/> <field name="trigger"/>
@ -57,13 +57,21 @@
<field name="view_mode">tree,form</field> <field name="view_mode">tree,form</field>
<field name="domain"> <field name="domain">
[ [
['code', '=', 'env["bus.bus"].sendone("refresh", {"model": model._name, "uid": env.user.id, "ids": (record | records).mapped("id")})']
['code', '=', 'env["bus.bus"].sendone("refresh", {
"create": record.exists() and record.create_date == record.write_date,
"model": model._name,
"uid": env.user.id,
"ids": (record | records).mapped("id")})']
] ]
</field> </field>
<field name="context"> <field name="context">
{ {
'default_state': 'code', 'default_state': 'code',
'default_code': 'env["bus.bus"].sendone("refresh", {"model": model._name, "uid": env.user.id, "ids": (record | records).mapped("id")})'
'default_code': 'env["bus.bus"].sendone("refresh", {
"create": record.exists() and record.create_date == record.write_date,
"model": model._name,
"uid": env.user.id,
"ids": (record | records).mapped("id")})'
} }
</field> </field>
<field name="help" type="html"> <field name="help" type="html">

Loading…
Cancel
Save