Skip to content

Commit

Permalink
[IMP] change the option to initialize the timeline window on display.
Browse files Browse the repository at this point in the history
Change the attribute 'default_window' to 'mode' like the Odoo calendar view (to be iso functional)
  • Loading branch information
Creamaster authored and CarlosRoca13 committed Aug 2, 2022
1 parent 275a11e commit 70b9c53
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
4 changes: 2 additions & 2 deletions web_timeline/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ the possible attributes for the tag:
additional key is down. Available values are '' (does not apply), 'altKey',
'ctrlKey', or 'metaKey'. Set this option if you want to be able to use the
scroll to navigate vertically on views with a lot of events.
* default_window (optional): Specifies the initial visible window. Aviable values are:
'day' to display the next 24 hours, 'week', 'month' and 'fit'.
* mode (optional): Specifies the initial visible window. Available values are:
'day' to display the current day, 'week', 'month' and 'fit'.
Default value is 'fit' to adjust the visible window such that it fits all items
* event_open_popup (optional): when set to true, it allows to edit the events
in a popup. If not (default value), the record is edited changing to form
Expand Down
2 changes: 1 addition & 1 deletion web_timeline/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
'name': "Web timeline",
'summary': "Interactive visualization chart to show events in time",
"version": "10.0.1.1.0",
"version": "10.0.1.2.0",
'author': 'ACSONE SA/NV, '
'Tecnativa, '
'Monk Software, '
Expand Down
32 changes: 13 additions & 19 deletions web_timeline/static/src/js/web_timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,6 @@ odoo.define('web_timeline.TimelineView', function (require) {
}
},

// set_default_options: function(options) {
// this._super(options);
// _.defaults(this.options, {
// confirm_on_delete: true
// });
// },

parse_colors: function () {
if (this.fields_view.arch.attrs.colors) {
this.colors = _(this.fields_view.arch.attrs.colors.split(';')).chain().compact().map(function (color_pair) {
Expand Down Expand Up @@ -101,7 +94,6 @@ odoo.define('web_timeline.TimelineView', function (require) {
this.$el.addClass(attrs['class']);

this.info_fields = [];
this.mode = attrs.mode;

if (!attrs.date_start) {
throw new Error(_t("Timeline view has not defined 'date_start' attribute."));
Expand All @@ -111,7 +103,7 @@ odoo.define('web_timeline.TimelineView', function (require) {
this.date_delay = attrs.date_delay;
this.no_period = this.date_start == this.date_stop;
this.zoomKey = attrs.zoomKey || '';
this.default_window = attrs.default_window || 'fit';
this.mode = attrs.mode || attrs.default_window || 'fit';

if (!isNullOrUndef(attrs.quick_create_instance)) {
self.quick_create_instance = 'instance.' + attrs.quick_create_instance;
Expand Down Expand Up @@ -172,25 +164,27 @@ odoo.define('web_timeline.TimelineView', function (require) {
onRemove: self.on_remove,
zoomKey: this.zoomKey
};
if (this.default_window) {
var start = new moment();
var end;
switch (this.default_window) {
if (this.mode) {
var start = false, end = false;
switch (this.mode) {
case 'day':
end = new moment().add(1, 'days');
start = new moment().startOf('day');
end = new moment().endOf('day');
break;
case 'week':
end = new moment().add(1, 'weeks');
start = new moment().startOf('week');
end = new moment().endOf('week');
break;
case 'month':
end = new moment().add(1, 'months');
start = new moment().startOf('month');
end = new moment().endOf('month');
break;
}
if (end) {
if (end && start) {
options['start'] = start;
options['end'] = end;
}else{
this.default_window = 'fit';
this.mode = 'fit';
}
}
self.timeline = new vis.Timeline(self.$timeline.empty().get(0));
Expand Down Expand Up @@ -355,7 +349,7 @@ odoo.define('web_timeline.TimelineView', function (require) {
var groups = split_groups(events, group_bys);
this.timeline.setGroups(groups);
this.timeline.setItems(data);
if (!this.default_window || this.default_window == 'fit'){
if (!this.mode || this.mode == 'fit'){
this.timeline.fit();
}
},
Expand Down

0 comments on commit 70b9c53

Please sign in to comment.