Skip to content

Commit 40943e2

Browse files
committed
Merge pull request #2 from acsone/8.0-web_timeline-prototype-ape
[8.0] Some changes on web_timeline
2 parents 2862c53 + 9398a50 commit 40943e2

File tree

8 files changed

+142
-87
lines changed

8 files changed

+142
-87
lines changed

web_timeline/README.rst

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,75 @@
1+
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
2+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
3+
:alt: License: AGPL-3
4+
5+
===============
16
Timeline Widget
27
===============
38

4-
!Prototype!
59
Define a new widget displaying events in an interactive visualization chart.
10+
611
The widget is based on the external library
712
http://visjs.org/timeline_examples.html
13+
14+
Usage
15+
=====
16+
17+
Exemple:
18+
<?xml version="1.0" encoding="utf-8"?>
19+
<openerp>
20+
<data>
21+
22+
<record id="view_task_timeline" model="ir.ui.view">
23+
<field name="name">project.task.timeline</field>
24+
<field name="model">project.task</field>
25+
<field name="type">timeline</field>
26+
<field eval="2" name="priority"/>
27+
<field name="arch" type="xml">
28+
<timeline date_start="date_start"
29+
date_stop="date_end"
30+
date_delay='1'
31+
string="Tasks"
32+
default_group_by="user_id" event_open_popup="true" colors="#ec7063:user_id == false;#2ecb71:kanban_state=='done';">
33+
</timeline>
34+
</field>
35+
</record>
36+
37+
<record id="project.action_view_task" model="ir.actions.act_window">
38+
<field name="view_mode">kanban,tree,form,calendar,gantt,timeline,graph</field>
39+
</record>
40+
</data>
41+
</openerp>
42+
43+
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
44+
:alt: Try me on Runbot
45+
:target: https://runbot.odoo-community.org/runbot/162/8.0
46+
47+
Bug Tracker
48+
===========
49+
50+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_.
51+
In case of trouble, please check there if your issue has already been reported.
52+
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
53+
`here <https://github.com/OCA/web/issues/new?body=module:%20web_timeline%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
54+
55+
Credits
56+
=======
57+
58+
Contributors
59+
------------
60+
61+
* Laurent Mignon <laurent.mignon@acsone.eu>
62+
* Adrien Peiffer <adrien.peiffer@acsone.eu>
63+
64+
Maintainer
65+
----------
66+
67+
.. image:: https://odoo-community.org/logo.png
68+
:alt: Odoo Community Association
69+
:target: https://odoo-community.org
70+
71+
This module is maintained by the OCA.
72+
73+
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
74+
75+
To contribute to this module, please visit https://odoo-community.org.

web_timeline/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
from . import ir_view
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
from . import models

web_timeline/__openerp__.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
15
{
26
'name': "Web timeline",
37
'summary': """
4-
Interactive visualization chart to visualize events in time
8+
Interactive visualization chart to visualize events in time
59
""",
6-
"version": "0.1",
7-
"author": "ACSONE SA/NV",
8-
"category": "Acsone",
10+
"version": "8.0.1.0.0",
11+
'author': 'ACSONE SA/NV,'
12+
'Odoo Community Association (OCA)',
13+
"category": "Tools",
914
"website": "http://acsone.eu",
10-
'depends': ['web', 'project'],
11-
'qweb': ['static/src/xml/web_timeline.xml'],
15+
'depends': [
16+
'web'
17+
],
18+
'qweb': [
19+
'static/src/xml/web_timeline.xml',
20+
],
1221
'data': [
1322
'views/web_timeline.xml',
14-
'project_view.xml',
1523
],
1624
}

web_timeline/ir_view.py

Lines changed: 0 additions & 40 deletions
This file was deleted.

web_timeline/models/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# -*- coding: utf-8 -*-
2+
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
from . import ir_view

web_timeline/models/ir_view.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2016 ACSONE SA/NV (<http://acsone.eu>)
3+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
4+
5+
from openerp import models
6+
from openerp import api
7+
8+
9+
TIMELINE_VIEW = ('timeline', 'Timeline')
10+
11+
12+
class IrUIView(models.Model):
13+
_inherit = 'ir.ui.view'
14+
15+
@api.model
16+
def _setup_fields(self):
17+
"""Hack due since the field 'type' is not defined with the new api.
18+
"""
19+
cls = type(self)
20+
type_selection = cls._fields['type'].selection
21+
if TIMELINE_VIEW not in type_selection:
22+
tmp = list(type_selection)
23+
tmp.append(TIMELINE_VIEW)
24+
cls._fields['type'].selection = tuple(set(tmp))
25+
super(IrUIView, self)._setup_fields()

web_timeline/project_view.xml

Lines changed: 0 additions & 24 deletions
This file was deleted.

web_timeline/static/src/js/web_timeline.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ openerp.web_timeline = function(instance) {
247247
var self = this;
248248
self.last_domains = domains;
249249
self.last_contexts = contexts;
250-
// self.reload_gantt();
251250
// select the group by
252251
var n_group_bys = [];
253252
if (this.fields_view.arch.attrs.default_group_by) {
@@ -263,14 +262,7 @@ openerp.web_timeline = function(instance) {
263262
}));
264263

265264
fields = _.uniq(fields.concat(_.pluck(this.colors, "field").concat(n_group_bys)));
266-
var group_by = self.fields[_.first(n_group_bys)]
267-
var read_groups = new instance.web.DataSet(this, group_by.relation, group_by.context)
268-
.name_search('', group_by.domain)
269-
.then(function(groups){
270-
self.groups = groups;
271-
});
272-
273-
return $.when(this.has_been_loaded, read_groups).then(function() {
265+
return $.when(this.has_been_loaded).then(function() {
274266
return self.dataset.read_slice(fields, {
275267
domain: domains,
276268
context: contexts
@@ -304,13 +296,30 @@ openerp.web_timeline = function(instance) {
304296
var self = this;
305297
var data = [];
306298
var groups = [];
307-
groups.push({id:-1, content: _t('Undefined')})
308299
_.each(tasks, function(event) {
309-
data.push(self.event_data_transform(event));
310-
});
311-
_.each(self.groups, function(group){
312-
groups.push({id: group[0], content: group[1]});
300+
if (event[self.date_start]){
301+
data.push(self.event_data_transform(event));
302+
}
313303
});
304+
// get the groups
305+
var split_groups = function(tasks, group_bys) {
306+
if (group_bys.length === 0)
307+
return tasks;
308+
var groups = [];
309+
groups.push({id:-1, content: _t('-')})
310+
_.each(tasks, function(task) {
311+
var group_name = task[_.first(group_bys)];
312+
if (group_name) {
313+
var group = _.find(groups, function(group) { return _.isEqual(group.id, group_name[0]); });
314+
if (group === undefined) {
315+
group = {id: group_name[0], content: group_name[1]};
316+
groups.push(group);
317+
}
318+
}
319+
});
320+
return groups;
321+
}
322+
var groups = split_groups(tasks, group_bys);
314323
this.timeline.setGroups(groups);
315324
this.timeline.setItems(data);
316325
this.timeline.setWindow(this.current_window);

0 commit comments

Comments
 (0)