Skip to content

Commit

Permalink
[UPD] Added a new attribute to the view element "color_field", to be …
Browse files Browse the repository at this point in the history
…able to directly specify the color of the bar by reading a char field compatible with widget="color" from view's model, the "colors" attribute take precedence over the new "color_field" attribute
  • Loading branch information
IJOL committed Sep 6, 2024
1 parent 92ca5b0 commit 4f62ab5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions web_timeline/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Web timeline
============

..
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
Expand Down Expand Up @@ -69,6 +69,8 @@ the possible attributes for the tag:
+--------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| colors | No | Allows to set certain specific colors if the expressed condition (JS syntax) is met. |
+--------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| color_field | No | Allows to set a field from the model to specify the color of the bar, colors will take precedence if used |
+--------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| dependency_arrow | No | Set this attribute to a x2many field to draw arrows between the records referenced in the x2many field. |
+--------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Expand Down Expand Up @@ -258,7 +260,7 @@ promote its widespread use.

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-tarteo|
|maintainer-tarteo|

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

Expand Down
2 changes: 2 additions & 0 deletions web_timeline/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ the possible attributes for the tag:
+--------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| colors | No | Allows to set certain specific colors if the expressed condition (JS syntax) is met. |
+--------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| color_field | No | Gets the color for the bar from field named here, if specified colors are set after this color |
+--------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| dependency_arrow | No | Set this attribute to a x2many field to draw arrows between the records referenced in the x2many field. |
+--------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

Expand Down
5 changes: 4 additions & 1 deletion web_timeline/static/src/js/timeline_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
this.date_stop = params.date_stop;
this.date_delay = params.date_delay;
this.colors = params.colors;
this.color_field = params.color_field;
this.fieldNames = params.fieldNames;
this.default_group_by = params.default_group_by;
this.dependency_arrow = params.dependency_arrow;
Expand Down Expand Up @@ -510,7 +511,9 @@ odoo.define("web_timeline.TimelineRenderer", function (require) {
} else {
group = -1;
}

if (this.color_field) {
this.color = evt[this.color_field];
}
for (const color of this.colors) {
if (py.eval(`'${evt[color.field]}' ${color.opt} '${color.value}'`)) {
this.color = color.color;
Expand Down
6 changes: 6 additions & 0 deletions web_timeline/static/src/js/timeline_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ odoo.define("web_timeline.TimelineView", function (require) {
);
fieldNames = _.union(fieldNames, archFieldNames);

if (attrs.color_field) {
fieldNames.push(attrs.color_field);
}
const color_field = attrs.color_field;

const colors = this.parse_colors();
for (const color of colors) {
if (!fieldNames.includes(color.field)) {
Expand Down Expand Up @@ -109,6 +114,7 @@ odoo.define("web_timeline.TimelineView", function (require) {
this.rendererParams.date_stop = date_stop;
this.rendererParams.date_delay = date_delay;
this.rendererParams.colors = colors;
this.rendererParams.color_field = color_field;
this.rendererParams.fieldNames = fieldNames;
this.rendererParams.default_group_by = attrs.default_group_by;
this.rendererParams.min_height = min_height;
Expand Down

0 comments on commit 4f62ab5

Please sign in to comment.