[IMP] web: graph: restorable order, stacked & cumulative options
For the Knowledge module, we would like to allow the user to fully customize a graph view and let the user insert the graph they see in an article. When loading the graph view from an article, the system can not currently restore the following settings: - For the bar chart and the line chart: The system will not able to restore the "sorting order" and the "stack option" set by the user. - For the line chart: The system will not be able to restore the "cumulative option" set by the user. This commit will ensure that these options can be specified from the context of the view. The context configuration will have a higher precedence than the configuration stored in the metadata of the model. When the user will open an article containing a graph view, the graph view will automatically load the options that have been set by the user when inserting the view. The user can thus create their own dashboards by customizing the graphs and inserting them in an article. task-3056268 closes odoo/odoo#112600 X-original-commit: 458bf22c7e275b7893505bb39c16073a9f63b9ca Related: odoo/enterprise#37046 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -31,11 +31,19 @@ export class GraphController extends Component {
|
||||
getContext() {
|
||||
// expand context object? change keys?
|
||||
const { measure, groupBy, mode } = this.model.metaData;
|
||||
return {
|
||||
const context = {
|
||||
graph_measure: measure,
|
||||
graph_mode: mode,
|
||||
graph_groupbys: groupBy.map((gb) => gb.spec),
|
||||
};
|
||||
if (mode !== "pie") {
|
||||
context.graph_order = this.model.metaData.order;
|
||||
context.graph_stacked = this.model.metaData.stacked;
|
||||
if (mode === "line") {
|
||||
context.graph_cumulated = this.model.metaData.cumulated;
|
||||
}
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -163,6 +163,13 @@ export class GraphModel extends Model {
|
||||
metaData.measure = context.graph_measure || metaData.measure;
|
||||
metaData.mode = context.graph_mode || metaData.mode;
|
||||
metaData.groupBy = groupBy.length ? groupBy : this.initialGroupBy;
|
||||
if (metaData.mode !== "pie") {
|
||||
metaData.order = "graph_order" in context ? context.graph_order : metaData.order;
|
||||
metaData.stacked = "graph_stacked" in context ? context.graph_stacked : metaData.stacked;
|
||||
if (metaData.mode === "line") {
|
||||
metaData.cumulated = "graph_cumulated" in context ? context.graph_cumulated : metaData.cumulated;
|
||||
}
|
||||
}
|
||||
|
||||
this._normalize(metaData);
|
||||
|
||||
|
||||
@@ -2479,24 +2479,34 @@ QUnit.module("Views", (hooks) => {
|
||||
graph_mode: "bar",
|
||||
graph_measure: "__count",
|
||||
graph_groupbys: ["product_id"],
|
||||
graph_order: null,
|
||||
graph_stacked: true,
|
||||
group_by: [],
|
||||
},
|
||||
{
|
||||
graph_mode: "bar",
|
||||
graph_measure: "foo",
|
||||
graph_groupbys: ["product_id"],
|
||||
graph_order: null,
|
||||
graph_stacked: true,
|
||||
group_by: [],
|
||||
},
|
||||
{
|
||||
graph_mode: "line",
|
||||
graph_measure: "foo",
|
||||
graph_cumulated: false,
|
||||
graph_groupbys: ["product_id"],
|
||||
graph_order: null,
|
||||
graph_stacked: true,
|
||||
group_by: [],
|
||||
},
|
||||
{
|
||||
graph_mode: "line",
|
||||
graph_measure: "foo",
|
||||
graph_cumulated: false,
|
||||
graph_groupbys: ["product_id", "color_id"],
|
||||
graph_order: null,
|
||||
graph_stacked: true,
|
||||
group_by: ["product_id", "color_id"],
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user