Skip to content

Commit

Permalink
[FIX] web_timeline: Allow groupby m2m fields
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosRoca13 committed Aug 2, 2022
1 parent d2dcca1 commit acc94d7
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 40 deletions.
23 changes: 16 additions & 7 deletions web_timeline/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Web timeline
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github
:target: https://github.com/OCA/web/tree/14.0/web_timeline
:target: https://github.com/OCA/web/tree/15.0/web_timeline
:alt: OCA/web
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_timeline
:target: https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_timeline
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/162/14.0
:target: https://runbot.odoo-community.org/runbot/162/15.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -152,14 +152,20 @@ Known issues / Roadmap
* Implement a more efficient way of refreshing timeline after a record update;
* Make `attrs` attribute work;
* Make action attributes work (create, edit, delete) like in form and tree views.
* When grouping by m2m and more than one record is set, the timeline item appears only
on one group. Allow showing in both groups.
* When grouping by m2m and dragging for changing the time or the group, the changes on
the group will not be set, because it could make disappear the records not related
with the changes that we want to make. When the item is showed in all groups change
the value according the group of the dragged item.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_timeline%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/web/issues/new?body=module:%20web_timeline%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand All @@ -180,14 +186,17 @@ Contributors

* Laurent Mignon <[email protected]>
* Adrien Peiffer <[email protected]>
* Pedro M. Baeza <[email protected]>
* Leonardo Donelli <[email protected]>
* Adrien Didenot <[email protected]>
* Dennis Sluijk <[email protected]>
* Thong Nguyen Van <[email protected]>
* Alexandre Díaz <[email protected]>
* Murtaza Mithaiwala <[email protected]>
* Ammar Officewala <[email protected]>
* `Tecnativa <https://www.tecnativa.com>`_:

* Pedro M. Baeza
* Alexandre Díaz
* César A. Sánchez

Maintainers
~~~~~~~~~~~
Expand All @@ -210,6 +219,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-tarteo|

This module is part of the `OCA/web <https://github.com/OCA/web/tree/14.0/web_timeline>`_ project on GitHub.
This module is part of the `OCA/web <https://github.com/OCA/web/tree/15.0/web_timeline>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
6 changes: 4 additions & 2 deletions web_timeline/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"license": "AGPL-3",
"website": "https://github.com/OCA/web",
"depends": ["web"],
"qweb": ["static/src/xml/web_timeline.xml"],
"data": [],
"maintainers": ["tarteo"],
"application": False,
Expand All @@ -29,6 +28,9 @@
"web_timeline/static/src/js/timeline_controller.js",
"web_timeline/static/src/js/timeline_model.js",
"web_timeline/static/src/js/timeline_canvas.js",
]
],
"web.assets_qweb": [
"web_timeline/static/src/xml/web_timeline.xml",
],
},
}
6 changes: 6 additions & 0 deletions web_timeline/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
* Implement a more efficient way of refreshing timeline after a record update;
* Make `attrs` attribute work;
* Make action attributes work (create, edit, delete) like in form and tree views.
* When grouping by m2m and more than one record is set, the timeline item appears only
on one group. Allow showing in both groups.
* When grouping by m2m and dragging for changing the time or the group, the changes on
the group will not be set, because it could make disappear the records not related
with the changes that we want to make. When the item is showed in all groups change
the value according the group of the dragged item.
22 changes: 16 additions & 6 deletions web_timeline/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Web timeline</title>
<style type="text/css">

Expand Down Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Web timeline</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/14.0/web_timeline"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-14-0/web-14-0-web_timeline"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/web/tree/15.0/web_timeline"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_timeline"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/162/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>Define a new view displaying events in an interactive visualization chart.</p>
<p>The widget is based on the external library
<a class="reference external" href="https://visjs.github.io/vis-timeline/examples/timeline">https://visjs.github.io/vis-timeline/examples/timeline</a></p>
Expand Down Expand Up @@ -526,14 +526,20 @@ <h1><a class="toc-backref" href="#id3">Known issues / Roadmap</a></h1>
<li>Implement a more efficient way of refreshing timeline after a record update;</li>
<li>Make <cite>attrs</cite> attribute work;</li>
<li>Make action attributes work (create, edit, delete) like in form and tree views.</li>
<li>When grouping by m2m and more than one record is set, the timeline item appears only
on one group. Allow showing in both groups.</li>
<li>When grouping by m2m and dragging for changing the time or the group, the changes on
the group will not be set, because it could make disappear the records not related
with the changes that we want to make. When the item is showed in all groups change
the value according the group of the dragged item.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/web/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_timeline%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/web/issues/new?body=module:%20web_timeline%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -553,14 +559,18 @@ <h2><a class="toc-backref" href="#id7">Contributors</a></h2>
<ul class="simple">
<li>Laurent Mignon &lt;<a class="reference external" href="mailto:laurent.mignon&#64;acsone.eu">laurent.mignon&#64;acsone.eu</a>&gt;</li>
<li>Adrien Peiffer &lt;<a class="reference external" href="mailto:adrien.peiffer&#64;acsone.eu">adrien.peiffer&#64;acsone.eu</a>&gt;</li>
<li>Pedro M. Baeza &lt;<a class="reference external" href="mailto:pedro.baeza&#64;tecnativa.com">pedro.baeza&#64;tecnativa.com</a>&gt;</li>
<li>Leonardo Donelli &lt;<a class="reference external" href="mailto:donelli&#64;webmonks.it">donelli&#64;webmonks.it</a>&gt;</li>
<li>Adrien Didenot &lt;<a class="reference external" href="mailto:adrien.didenot&#64;horanet.com">adrien.didenot&#64;horanet.com</a>&gt;</li>
<li>Dennis Sluijk &lt;<a class="reference external" href="mailto:d.sluijk&#64;onestein.nl">d.sluijk&#64;onestein.nl</a>&gt;</li>
<li>Thong Nguyen Van &lt;<a class="reference external" href="mailto:thongnv&#64;trobz.com">thongnv&#64;trobz.com</a>&gt;</li>
<li>Alexandre Díaz &lt;<a class="reference external" href="mailto:alexandre.diaz&#64;tecnativa.com">alexandre.diaz&#64;tecnativa.com</a>&gt;</li>
<li>Murtaza Mithaiwala &lt;<a class="reference external" href="mailto:mmithaiwala&#64;opensourceintegrators.com">mmithaiwala&#64;opensourceintegrators.com</a>&gt;</li>
<li>Ammar Officewala &lt;<a class="reference external" href="mailto:aofficewala&#64;opensourceintegrators.com">aofficewala&#64;opensourceintegrators.com</a>&gt;</li>
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
<li>Pedro M. Baeza</li>
<li>Alexandre Díaz</li>
<li>César A. Sánchez</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -572,7 +582,7 @@ <h2><a class="toc-backref" href="#id8">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external" href="https://github.com/tarteo"><img alt="tarteo" src="https://github.com/tarteo.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/14.0/web_timeline">OCA/web</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/web/tree/15.0/web_timeline">OCA/web</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
33 changes: 21 additions & 12 deletions web_timeline/static/src/js/timeline_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,29 @@ odoo.define("web_timeline.TimelineController", function (require) {
);
data[this.date_delay] = diff_seconds / 3600;
}
if (
this.renderer.last_group_bys &&
this.renderer.last_group_bys instanceof Array
) {
data[this.renderer.last_group_bys[0]] = group;
}
const grouped_field = this.renderer.last_group_bys[0];
this._rpc({
model: this.modelName,
method: "fields_get",
args: [grouped_field],
context: this.getSession().user_context,
}).then(async (fields_processed) => {
if (
this.renderer.last_group_bys &&
this.renderer.last_group_bys instanceof Array &&
fields_processed[grouped_field].type !== "many2many"
) {
data[this.renderer.last_group_bys[0]] = group;
}

this.moveQueue.push({
id: event.data.item.id,
data: data,
event: event,
});
this.moveQueue.push({
id: event.data.item.id,
data: data,
event: event,
});

this.debouncedInternalMove();
this.debouncedInternalMove();
});
},

/**
Expand Down
72 changes: 59 additions & 13 deletions web_timeline/static/src/js/timeline_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,15 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
data.push(this.event_data_transform(evt));
}
}
const groups = this.split_groups(events, group_bys);
this.timeline.setGroups(groups);
this.timeline.setItems(data);
const mode = !this.mode || this.mode === "fit";
const adjust = _.isUndefined(adjust_window) || adjust_window;
if (mode && adjust) {
this.timeline.fit();
}
this.split_groups(events, group_bys).then((groups) => {
this.timeline.setGroups(groups);
this.timeline.setItems(data);
const mode = !this.mode || this.mode === "fit";
const adjust = _.isUndefined(adjust_window) || adjust_window;
if (mode && adjust) {
this.timeline.fit();
}
});
},

/**
Expand All @@ -371,24 +372,54 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
* @private
* @returns {Array}
*/
split_groups: function (events, group_bys) {
split_groups: async function (events, group_bys) {
if (group_bys.length === 0) {
return events;
}
const groups = [];
groups.push({id: -1, content: _t("<b>UNASSIGNED</b>")});
for (const evt of events) {
const group_name = evt[_.first(group_bys)];
const grouped_field = _.first(group_bys);
const group_name = evt[grouped_field];
if (group_name) {
if (group_name instanceof Array) {
const group = _.find(
groups,
(existing_group) => existing_group.id === group_name[0]
);
if (_.isUndefined(group)) {
groups.push({
id: group_name[0],
content: group_name[1],
// Check if group is m2m in this case add id -> value of all
// found entries.
await this._rpc({
model: this.modelName,
method: "fields_get",
args: [grouped_field],
context: this.getSession().user_context,
}).then(async (fields) => {
if (fields[grouped_field].type === "many2many") {
const list_values =
await this.get_m2m_grouping_datas(
fields[grouped_field].relation,
group_name
);
for (const vals of list_values) {
let is_inside = false;
for (const gr of groups) {
if (vals.id === gr.id) {
is_inside = true;
break;
}
}
if (!is_inside) {
groups.push(vals);
}
}
} else {
groups.push({
id: group_name[0],
content: group_name[1],
});
}
});
}
}
Expand All @@ -397,6 +428,21 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
return groups;
},

get_m2m_grouping_datas: async function (model, group_name) {
const groups = [];
for (const gr of group_name) {
await this._rpc({
model: model,
method: "name_get",
args: [gr],
context: this.getSession().user_context,
}).then((name) => {
groups.push({id: name[0][0], content: name[0][1]});
});
}
return groups;
},

/**
* Get dates from given event
*
Expand Down
1 change: 1 addition & 0 deletions web_timeline/static/src/js/timeline_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ odoo.define("web_timeline.TimelineView", function (require) {
Controller: TimelineController,
Renderer: TimelineRenderer,
}),
viewType: "timeline",

/**
* @override
Expand Down

0 comments on commit acc94d7

Please sign in to comment.