From 657ea5a657390094d4260cc5b3de3f3453dadb96 Mon Sep 17 00:00:00 2001 From: Arnaud Pineux Date: Wed, 7 Aug 2019 15:35:33 +0200 Subject: [PATCH] [IMP] Allow to specify a field in timeline to define element's color --- web_timeline/README.rst | 2 ++ web_timeline/readme/CONFIGURE.rst | 2 ++ .../static/src/js/timeline_renderer.js | 18 +++++++++++------- web_timeline/static/src/js/timeline_view.js | 1 + 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/web_timeline/README.rst b/web_timeline/README.rst index 16db743db..d28816ec1 100755 --- a/web_timeline/README.rst +++ b/web_timeline/README.rst @@ -66,6 +66,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 (on the current model) that contains the HTML color (e.g. #FFFFFF). This option has priority over 'colors'. | ++--------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | dependency_arrow | No | Set this attribute to a x2many field to draw arrows between the records referenced in the x2many field. | +--------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ diff --git a/web_timeline/readme/CONFIGURE.rst b/web_timeline/readme/CONFIGURE.rst index 09bf110b9..f7c74b449 100644 --- a/web_timeline/readme/CONFIGURE.rst +++ b/web_timeline/readme/CONFIGURE.rst @@ -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 | Allows to set a field (on the current model) that contains the HTML color (e.g. #FFFFFF). This option has priority over 'colors'. | ++--------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | dependency_arrow | No | Set this attribute to a x2many field to draw arrows between the records referenced in the x2many field. | +--------------------+-----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ diff --git a/web_timeline/static/src/js/timeline_renderer.js b/web_timeline/static/src/js/timeline_renderer.js index 4a0038ce6..349aa4950 100644 --- a/web_timeline/static/src/js/timeline_renderer.js +++ b/web_timeline/static/src/js/timeline_renderer.js @@ -421,11 +421,16 @@ odoo.define('web_timeline.TimelineRenderer', function (require) { } else { group = -1; } - _.each(self.colors, function (color) { - if (eval("'" + evt[color.field] + "' " + color.opt + " '" + color.value + "'")) { - self.color = color.color; - } - }); + var color = null; + if (self.arch.attrs.color_field !== undefined) { + color = evt[self.arch.attrs.color_field]; + } else { + _.each(self.colors, function (col) { + if (eval("'" + evt[col.field] + "' " + col.opt + " '" + col.value + "'")) { + color = col.color; + } + }); + } var content = _.isUndefined(evt.__name) ? evt.display_name : evt.__name; if (this.arch.children.length) { @@ -438,13 +443,12 @@ odoo.define('web_timeline.TimelineRenderer', function (require) { 'id': evt.id, 'group': group, 'evt': evt, - 'style': 'background-color: ' + self.color + ';' + 'style': 'background-color: ' + color + ';' }; // Check if the event is instantaneous, if so, display it with a point on the timeline (no 'end') if (date_stop && !moment(date_start).isSame(date_stop)) { r.end = date_stop; } - self.color = null; return r; }, diff --git a/web_timeline/static/src/js/timeline_view.js b/web_timeline/static/src/js/timeline_view.js index 9c9c36245..44ab7884d 100644 --- a/web_timeline/static/src/js/timeline_view.js +++ b/web_timeline/static/src/js/timeline_view.js @@ -61,6 +61,7 @@ odoo.define('web_timeline.TimelineView', function (require) { "default_group_by", "progress", "date_delay", + "color_field", ]; fieldsToGather.push(attrs.default_group_by);