From 9ae0096deda2715ca9e0eee94ec3f732f4601ec6 Mon Sep 17 00:00:00 2001 From: tarteo Date: Tue, 17 Jul 2018 15:54:40 +0200 Subject: [PATCH] [IMP] web_timeline: Templates implementation like kanban [IMP] web_timeline: Templates implementation like kanban [ADD] Check if template exists Update README.rst --- web_timeline/README.rst | 13 +++++++-- web_timeline/__manifest__.py | 3 ++- .../static/src/js/timeline_renderer.js | 27 ++++++++++++++++++- web_timeline/static/src/js/timeline_view.js | 11 ++++++++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/web_timeline/README.rst b/web_timeline/README.rst index 66fbd5e2..8ea995a3 100755 --- a/web_timeline/README.rst +++ b/web_timeline/README.rst @@ -19,8 +19,8 @@ the possible attributes for the tag: * date_start (required): it defines the name of the field of type date that contains the start of the event. -* date_end (optional): it defines the name of the field of type date that - contains the end of the event. The date_end can be equal to the attribute +* date_stop (optional): it defines the name of the field of type date that + contains the end of the event. The date_stop can be equal to the attribute date_start to display events has 'point' on the Timeline (instantaneous event) * date_delay (optional): it defines the name of the field of type float/integer that contain the duration in hours of the event, default = 1 @@ -59,6 +59,14 @@ Example: event_open_popup="true" zoomKey="ctrlKey" colors="#ec7063:user_id == false;#2ecb71:kanban_state=='done';"> + + +
+
+ Assigned to: + +
+ @@ -135,6 +143,7 @@ Contributors * Pedro M. Baeza * Leonardo Donelli * Adrien Didenot +* Dennis Sluijk Do not contact contributors directly about support or help with technical issues. diff --git a/web_timeline/__manifest__.py b/web_timeline/__manifest__.py index 1ecd04b7..60e2028a 100644 --- a/web_timeline/__manifest__.py +++ b/web_timeline/__manifest__.py @@ -4,10 +4,11 @@ { 'name': "Web timeline", 'summary': "Interactive visualization chart to show events in time", - "version": "11.0.1.0.1", + "version": "11.0.1.1.1", 'author': 'ACSONE SA/NV, ' 'Tecnativa, ' 'Monk Software, ' + 'Onestein, ' 'Odoo Community Association (OCA)', "category": "web", "license": "AGPL-3", diff --git a/web_timeline/static/src/js/timeline_renderer.js b/web_timeline/static/src/js/timeline_renderer.js index d7688c37..8eb1d98a 100644 --- a/web_timeline/static/src/js/timeline_renderer.js +++ b/web_timeline/static/src/js/timeline_renderer.js @@ -4,6 +4,9 @@ odoo.define('web_timeline.TimelineRenderer', function (require) { var AbstractRenderer = require('web.AbstractRenderer'); var core = require('web.core'); var time = require('web.time'); +var utils = require('web.utils'); +var session = require('web.session'); +var QWeb = require('web.QWeb'); var _t = core._t; @@ -151,6 +154,16 @@ var CalendarRenderer = AbstractRenderer.extend({ onUpdate: self.on_update, onRemove: self.on_remove, }); + if (this.arch.children.length) { + this.qweb = new QWeb(session.debug, {_s: session.origin}, false); + var tmpl = utils.json_node_to_xml( + _.filter(this.arch.children, function(item) { + return item.tag === 'templates'; + })[0] + ); + this.qweb.add_template(tmpl); + } + this.timeline = new vis.Timeline(self.$timeline.empty().get(0)); this.timeline.setOptions(this.options); if (self.mode && self['on_scale_' + self.mode + '_clicked']) { @@ -264,9 +277,21 @@ var CalendarRenderer = AbstractRenderer.extend({ self.color = color.color; } }); + + var content = evt.__name != undefined ? evt.__name : evt.display_name; + if (this.arch.children.length) { + if(this.qweb.has_template('timeline-item')) { + content = this.qweb.render('timeline-item', { + 'record': evt + }); + } else { + console.error(_t('Template "timeline-item" not present in timeline view definition.')); + } + } + var r = { 'start': date_start, - 'content': evt.__name != undefined ? evt.__name : evt.display_name, + 'content': content, 'id': evt.id, 'group': group, 'evt': evt, diff --git a/web_timeline/static/src/js/timeline_view.js b/web_timeline/static/src/js/timeline_view.js index 3d34beab..76f32900 100644 --- a/web_timeline/static/src/js/timeline_view.js +++ b/web_timeline/static/src/js/timeline_view.js @@ -68,6 +68,17 @@ odoo.define('web_timeline.TimelineView', function (require) { fieldNames.push(fieldName); } }); + + var archFieldNames = _.map(_.filter(this.arch.children, function(item) { + return item.tag === 'field'; + }), function(item) { + return item.attrs.name; + }); + fieldNames = _.union( + fieldNames, + archFieldNames + ); + this.parse_colors(); for (var i=0; i