mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[MIG] web_timeline: Finish migration to 13.0
This commit is contained in:
committed by
CarlosRoca13
parent
1e21541b8f
commit
63c0353f28
@@ -1,31 +1,31 @@
|
||||
/* global py */
|
||||
/* Odoo web_timeline
|
||||
* Copyright 2015 ACSONE SA/NV
|
||||
* Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
|
||||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
||||
|
||||
odoo.define('web_timeline.TimelineView', function (require) {
|
||||
odoo.define("web_timeline.TimelineView", function(require) {
|
||||
"use strict";
|
||||
|
||||
var core = require('web.core');
|
||||
var utils = require('web.utils');
|
||||
var view_registry = require('web.view_registry');
|
||||
var AbstractView = require('web.AbstractView');
|
||||
var TimelineRenderer = require('web_timeline.TimelineRenderer');
|
||||
var TimelineController = require('web_timeline.TimelineController');
|
||||
var TimelineModel = require('web_timeline.TimelineModel');
|
||||
const core = require("web.core");
|
||||
const utils = require("web.utils");
|
||||
const view_registry = require("web.view_registry");
|
||||
const AbstractView = require("web.AbstractView");
|
||||
const TimelineRenderer = require("web_timeline.TimelineRenderer");
|
||||
const TimelineController = require("web_timeline.TimelineController");
|
||||
const TimelineModel = require("web_timeline.TimelineModel");
|
||||
|
||||
|
||||
var _lt = core._lt;
|
||||
const _lt = core._lt;
|
||||
|
||||
function isNullOrUndef(value) {
|
||||
return _.isUndefined(value) || _.isNull(value);
|
||||
}
|
||||
|
||||
var TimelineView = AbstractView.extend({
|
||||
display_name: _lt('Timeline'),
|
||||
icon: 'fa-clock-o',
|
||||
jsLibs: ['/web_timeline/static/lib/vis-timeline/vis-timeline-graph2d.min.js'],
|
||||
cssLibs: ['/web_timeline/static/lib/vis-timeline/vis-timeline-graph2d.min.css'],
|
||||
display_name: _lt("Timeline"),
|
||||
icon: "fa-tasks",
|
||||
jsLibs: ["/web_timeline/static/lib/vis-timeline/vis-timeline-graph2d.min.js"],
|
||||
cssLibs: ["/web_timeline/static/lib/vis-timeline/vis-timeline-graph2d.min.css"],
|
||||
config: {
|
||||
Model: TimelineModel,
|
||||
Controller: TimelineController,
|
||||
@@ -35,123 +35,112 @@ odoo.define('web_timeline.TimelineView', function (require) {
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
init: function (viewInfo, params) {
|
||||
init: function(viewInfo, params) {
|
||||
this._super.apply(this, arguments);
|
||||
var self = this;
|
||||
this.timeline = false;
|
||||
this.arch = this.rendererParams.arch;
|
||||
var attrs = this.arch.attrs;
|
||||
this.fields = viewInfo.fields;
|
||||
this.modelName = this.controllerParams.modelName;
|
||||
this.action = params.action;
|
||||
|
||||
var fieldNames = this.fields.display_name ? ['display_name'] : [];
|
||||
var mapping = {};
|
||||
var fieldsToGather = [
|
||||
const action = params.action;
|
||||
this.arch = this.rendererParams.arch;
|
||||
const attrs = this.arch.attrs;
|
||||
const date_start = attrs.date_start;
|
||||
const date_stop = attrs.date_stop;
|
||||
const date_delay = attrs.date_delay;
|
||||
const dependency_arrow = attrs.dependency_arrow;
|
||||
|
||||
const fields = viewInfo.fields;
|
||||
let fieldNames = fields.display_name ? ["display_name"] : [];
|
||||
const fieldsToGather = [
|
||||
"date_start",
|
||||
"date_stop",
|
||||
"default_group_by",
|
||||
"progress",
|
||||
"date_delay",
|
||||
attrs.default_group_by,
|
||||
];
|
||||
|
||||
fieldsToGather.push(attrs.default_group_by);
|
||||
|
||||
for (const field of fieldsToGather) {
|
||||
if (attrs[field]) {
|
||||
var fieldName = attrs[field];
|
||||
mapping[field] = fieldName;
|
||||
fieldNames.push(fieldName);
|
||||
fieldNames.push(attrs[field]);
|
||||
}
|
||||
}
|
||||
|
||||
var archFieldNames = _.map(_.filter(this.arch.children, function (item) {
|
||||
return item.tag === 'field';
|
||||
}), function (item) {
|
||||
return item.attrs.name;
|
||||
});
|
||||
fieldNames = _.union(
|
||||
fieldNames,
|
||||
archFieldNames
|
||||
const archFieldNames = _.map(
|
||||
_.filter(this.arch.children, item => item.tag === "field"),
|
||||
item => item.attrs.name
|
||||
);
|
||||
fieldNames = _.union(fieldNames, archFieldNames);
|
||||
|
||||
this.parse_colors();
|
||||
for (const color of this.colors) {
|
||||
const colors = this.parse_colors();
|
||||
for (const color of colors) {
|
||||
fieldNames.push(color.field);
|
||||
}
|
||||
|
||||
if (attrs.dependency_arrow) {
|
||||
fieldNames.push(attrs.dependency_arrow);
|
||||
if (dependency_arrow) {
|
||||
fieldNames.push(dependency_arrow);
|
||||
}
|
||||
|
||||
this.permissions = {};
|
||||
this.grouped_by = false;
|
||||
this.date_start = attrs.date_start;
|
||||
this.date_stop = attrs.date_stop;
|
||||
this.date_delay = attrs.date_delay;
|
||||
this.dependency_arrow = attrs.dependency_arrow;
|
||||
const mode = attrs.mode || attrs.default_window || "fit";
|
||||
const min_height = attrs.min_height || 300;
|
||||
|
||||
this.no_period = this.date_start === this.date_stop;
|
||||
this.zoomKey = attrs.zoomKey || '';
|
||||
this.margin = attrs.margin || '{}';
|
||||
this.mode = attrs.mode || attrs.default_window || 'fit';
|
||||
this.min_height = attrs.min_height || 300;
|
||||
|
||||
this.current_window = {
|
||||
const current_window = {
|
||||
start: new moment(),
|
||||
end: new moment().add(24, 'hours'),
|
||||
end: new moment().add(24, "hours"),
|
||||
};
|
||||
if (!isNullOrUndef(attrs.quick_create_instance)) {
|
||||
self.quick_create_instance = 'instance.' + attrs.quick_create_instance;
|
||||
this.quick_create_instance = "instance." + attrs.quick_create_instance;
|
||||
}
|
||||
this.stack = true;
|
||||
if (!isNullOrUndef(attrs.stack) && !utils.toBoolElse(attrs.stack, true)) {
|
||||
this.stack = false;
|
||||
let open_popup_action = false;
|
||||
if (
|
||||
!isNullOrUndef(attrs.event_open_popup) &&
|
||||
utils.toBoolElse(attrs.event_open_popup, true)
|
||||
) {
|
||||
open_popup_action = attrs.event_open_popup;
|
||||
}
|
||||
this.options = {
|
||||
this.rendererParams.mode = mode;
|
||||
this.rendererParams.model = this.modelName;
|
||||
this.rendererParams.view = this;
|
||||
this.rendererParams.options = this._preapre_vis_timeline_options(attrs);
|
||||
this.rendererParams.current_window = current_window;
|
||||
this.rendererParams.date_start = date_start;
|
||||
this.rendererParams.date_stop = date_stop;
|
||||
this.rendererParams.date_delay = date_delay;
|
||||
this.rendererParams.colors = colors;
|
||||
this.rendererParams.fieldNames = fieldNames;
|
||||
this.rendererParams.min_height = min_height;
|
||||
this.rendererParams.dependency_arrow = dependency_arrow;
|
||||
this.rendererParams.fields = fields;
|
||||
this.loadParams.modelName = this.modelName;
|
||||
this.loadParams.fieldNames = fieldNames;
|
||||
this.controllerParams.open_popup_action = open_popup_action;
|
||||
this.controllerParams.date_start = date_start;
|
||||
this.controllerParams.date_stop = date_stop;
|
||||
this.controllerParams.date_delay = date_delay;
|
||||
this.controllerParams.actionContext = action.context;
|
||||
this.withSearchPanel = false;
|
||||
},
|
||||
|
||||
_preapre_vis_timeline_options: function(attrs) {
|
||||
return {
|
||||
groupOrder: this.group_order,
|
||||
orientation: 'both',
|
||||
orientation: "both",
|
||||
selectable: true,
|
||||
multiselect: true,
|
||||
showCurrentTime: true,
|
||||
stack: this.stack,
|
||||
margin: JSON.parse(this.margin),
|
||||
zoomKey: this.zoomKey,
|
||||
stack: isNullOrUndef(attrs.stack)
|
||||
? true
|
||||
: utils.toBoolElse(attrs.stack, true),
|
||||
margin: attrs.margin ? JSON.parse(attrs.margin) : {item: 2},
|
||||
zoomKey: attrs.zoomKey || "ctrlKey",
|
||||
};
|
||||
if (isNullOrUndef(attrs.event_open_popup) || !utils.toBoolElse(attrs.event_open_popup, true)) {
|
||||
this.open_popup_action = false;
|
||||
} else {
|
||||
this.open_popup_action = attrs.event_open_popup;
|
||||
}
|
||||
this.rendererParams.mode = this.mode;
|
||||
this.rendererParams.model = this.modelName;
|
||||
this.rendererParams.options = this.options;
|
||||
this.rendererParams.permissions = this.permissions;
|
||||
this.rendererParams.current_window = this.current_window;
|
||||
this.rendererParams.timeline = this.timeline;
|
||||
this.rendererParams.date_start = this.date_start;
|
||||
this.rendererParams.date_stop = this.date_stop;
|
||||
this.rendererParams.date_delay = this.date_delay;
|
||||
this.rendererParams.colors = this.colors;
|
||||
this.rendererParams.fieldNames = fieldNames;
|
||||
this.rendererParams.view = this;
|
||||
this.rendererParams.min_height = this.min_height;
|
||||
this.rendererParams.dependency_arrow = this.dependency_arrow;
|
||||
this.loadParams.modelName = this.modelName;
|
||||
this.loadParams.fieldNames = fieldNames;
|
||||
this.controllerParams.open_popup_action = this.open_popup_action;
|
||||
this.controllerParams.date_start = this.date_start;
|
||||
this.controllerParams.date_stop = this.date_stop;
|
||||
this.controllerParams.date_delay = this.date_delay;
|
||||
this.controllerParams.actionContext = this.action.context;
|
||||
this.withSearchPanel = false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Order function for groups.
|
||||
* @param {Object} grp1
|
||||
* @param {Object} grp2
|
||||
* @returns {Integer}
|
||||
*/
|
||||
group_order: function (grp1, grp2) {
|
||||
group_order: function(grp1, grp2) {
|
||||
// Display non grouped elements first
|
||||
if (grp1.id === -1) {
|
||||
return -1;
|
||||
@@ -167,26 +156,31 @@ odoo.define('web_timeline.TimelineView', function (require) {
|
||||
* Parse the colors attribute.
|
||||
*
|
||||
* @private
|
||||
* @returns {Array}
|
||||
*/
|
||||
parse_colors: function () {
|
||||
parse_colors: function() {
|
||||
if (this.arch.attrs.colors) {
|
||||
this.colors = _(this.arch.attrs.colors.split(';')).chain().compact().map(function (color_pair) {
|
||||
var pair = color_pair.split(':'), color = pair[0], expr = pair[1];
|
||||
var temp = py.parse(py.tokenize(expr));
|
||||
return {
|
||||
'color': color,
|
||||
'field': temp.expressions[0].value,
|
||||
'opt': temp.operators[0],
|
||||
'value': temp.expressions[1].value,
|
||||
};
|
||||
}).value();
|
||||
} else {
|
||||
this.colors = [];
|
||||
return _(this.arch.attrs.colors.split(";"))
|
||||
.chain()
|
||||
.compact()
|
||||
.map(color_pair => {
|
||||
const pair = color_pair.split(":");
|
||||
const color = pair[0];
|
||||
const expr = pair[1];
|
||||
const temp = py.parse(py.tokenize(expr));
|
||||
return {
|
||||
color: color,
|
||||
field: temp.expressions[0].value,
|
||||
opt: temp.operators[0],
|
||||
value: temp.expressions[1].value,
|
||||
};
|
||||
})
|
||||
.value();
|
||||
}
|
||||
return [];
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
view_registry.add('timeline', TimelineView);
|
||||
view_registry.add("timeline", TimelineView);
|
||||
return TimelineView;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user