[REF] *: adapt modules to action and view contexts
This commit handles the adaptation of any component using the search model's 'action' and/or 'view' key, now replaced by the environment keys 'actionContext' and 'viewContext'. Affected modules are: - base_import - board - crm - google_spreadsheet - project X-original-commit: 40f1ae87e1436192a70a8a7432eb72d379cfa6dc Part-of: odoo/odoo#77463
This commit is contained in:
@@ -36,10 +36,10 @@ ImportRecords.template = "base_import.ImportRecords";
|
||||
const importRecordsItem = {
|
||||
Component: ImportRecords,
|
||||
groupNumber: 4,
|
||||
isDisplayed: ({ isSmall, searchModel }) =>
|
||||
isDisplayed: ({ config, isSmall }) =>
|
||||
!isSmall &&
|
||||
searchModel.action.type === "ir.actions.act_window" &&
|
||||
["kanban", "list"].includes(searchModel.view.type)
|
||||
config.actionType === "ir.actions.act_window" &&
|
||||
["kanban", "list"].includes(config.viewType)
|
||||
// TODO: add arch info to searchModel?
|
||||
// !!JSON.parse(env.view.arch.attrs.import || "1") &&
|
||||
// !!JSON.parse(env.view.arch.attrs.create || "1"),
|
||||
|
||||
@@ -24,7 +24,7 @@ export class AddToBoard extends Component {
|
||||
setup() {
|
||||
this.notification = useService("notification");
|
||||
this.rpc = useService("rpc");
|
||||
this.state = useState({ name: this.env.searchModel.displayName });
|
||||
this.state = useState({ name: this.env.config.displayName });
|
||||
|
||||
useAutofocus();
|
||||
}
|
||||
@@ -34,39 +34,19 @@ export class AddToBoard extends Component {
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
async addToBoard() {
|
||||
const {
|
||||
action,
|
||||
displayName,
|
||||
domain,
|
||||
context,
|
||||
groupBy,
|
||||
orderedBy,
|
||||
view,
|
||||
} = this.env.searchModel;
|
||||
|
||||
// Retrieves view context
|
||||
const fns = this.env.__getContext__.callbacks;
|
||||
const viewContext = Object.assign({}, ...fns.map((fn) => fn()));
|
||||
|
||||
const { context, domain } = this.env.searchModel.getIrFilterValues();
|
||||
const contextToSave = {
|
||||
...context,
|
||||
group_by: groupBy,
|
||||
orderedBy,
|
||||
orderedBy: this.env.searchModel.orderBy,
|
||||
dashboard_merge_domains_contexts: false,
|
||||
...viewContext,
|
||||
};
|
||||
|
||||
const detailedComparison = this.env.searchModel.getFullComparison();
|
||||
if (detailedComparison) {
|
||||
contextToSave.comparison = detailedComparison;
|
||||
}
|
||||
|
||||
const result = await this.rpc("/board/add_to_dashboard", {
|
||||
action_id: action.id,
|
||||
action_id: this.env.config.actionId,
|
||||
context_to_save: contextToSave,
|
||||
domain,
|
||||
name: this.state.name,
|
||||
view_mode: view.type,
|
||||
view_mode: this.env.config.viewType,
|
||||
});
|
||||
|
||||
if (result) {
|
||||
@@ -77,12 +57,11 @@ export class AddToBoard extends Component {
|
||||
type: "warning",
|
||||
}
|
||||
);
|
||||
this.state.name = displayName;
|
||||
this.state.name = this.env.config.displayName;
|
||||
} else {
|
||||
this.notification.add(
|
||||
this.env._t("Could not add filter to dashboard"),
|
||||
{ type: "danger" }
|
||||
);
|
||||
this.notification.add(this.env._t("Could not add filter to dashboard"), {
|
||||
type: "danger",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +85,7 @@ AddToBoard.template = "board.AddToBoard";
|
||||
const addToBoardItem = {
|
||||
Component: AddToBoard,
|
||||
groupNumber: 4,
|
||||
isDisplayed: ({ searchModel }) => searchModel.action.type === "ir.actions.act_window",
|
||||
isDisplayed: ({ config }) => config.actionType === "ir.actions.act_window",
|
||||
};
|
||||
|
||||
favoriteMenuRegistry.add("add-to-board", addToBoardItem, { sequence: 10 });
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,24 +1,23 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { _lt } from "@web/core/l10n/translation";
|
||||
import AbstractView from "web.AbstractView";
|
||||
import AbstractModel from "web.AbstractModel";
|
||||
import { controlPanel as cpHelpers } from "web.test_utils";
|
||||
import { createWebClient, doAction } from "@web/../tests/webclient/helpers";
|
||||
import { dialogService } from "@web/core/dialog/dialog_service";
|
||||
import { legacyExtraNextTick, patchWithCleanup } from "@web/../tests/helpers/utils";
|
||||
import legacyViewRegistry from "web.view_registry";
|
||||
import { makeView } from "@web/../tests/views/helpers";
|
||||
import { mock } from "web.test_utils";
|
||||
import { registry } from "@web/core/registry";
|
||||
import {
|
||||
setupControlPanelServiceRegistry,
|
||||
switchView,
|
||||
toggleFilterMenu,
|
||||
toggleGroupByMenu,
|
||||
toggleMenuItem,
|
||||
toggleMenuItemOption,
|
||||
toggleMenuItemOption
|
||||
} from "@web/../tests/search/helpers";
|
||||
import { makeView } from "@web/../tests/views/helpers";
|
||||
import { createWebClient, doAction } from "@web/../tests/webclient/helpers";
|
||||
import { dialogService } from "@web/core/dialog/dialog_service";
|
||||
import { _lt } from "@web/core/l10n/translation";
|
||||
import { registry } from "@web/core/registry";
|
||||
import AbstractModel from "web.AbstractModel";
|
||||
import AbstractView from "web.AbstractView";
|
||||
import { controlPanel as cpHelpers, mock } from "web.test_utils";
|
||||
import legacyViewRegistry from "web.view_registry";
|
||||
|
||||
const patchDate = mock.patchDate;
|
||||
|
||||
@@ -88,7 +87,7 @@ QUnit.module("Views", (hooks) => {
|
||||
|
||||
const forecastGraph = await makeView({
|
||||
resModel: "foo",
|
||||
type: "forecast_graph",
|
||||
type: "graph",
|
||||
serverData,
|
||||
searchViewId: false,
|
||||
context: {
|
||||
@@ -133,7 +132,7 @@ QUnit.module("Views", (hooks) => {
|
||||
|
||||
await makeView({
|
||||
resModel: "foo",
|
||||
type: "forecast_graph",
|
||||
type: "graph",
|
||||
serverData,
|
||||
searchViewId: false,
|
||||
context: {
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ AddToGoogleSpreadsheet.template = "google_spreadsheet.AddToGoogleSpreadsheet";
|
||||
const addToGoogleSpreadsheetItem = {
|
||||
Component: AddToGoogleSpreadsheet,
|
||||
groupNumber: 4,
|
||||
isDisplayed: ({ searchModel }) => searchModel.action.type === "ir.actions.act_window",
|
||||
isDisplayed: ({ config }) => config.actionType === "ir.actions.act_window",
|
||||
};
|
||||
|
||||
favoriteMenuRegistry.add("add-to-google-spreadsheet", addToGoogleSpreadsheetItem, { sequence: 20 });
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { GraphView } from "@web/views/graph/graph_view";
|
||||
import { ProjectControlPanel } from "@project/project_control_panel/project_control_panel";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { GraphView } from "@web/views/graph/graph_view";
|
||||
|
||||
const viewRegistry = registry.category("views");
|
||||
|
||||
class ProjectGraphView extends GraphView {}
|
||||
ProjectGraphView.components = { ...GraphView.components, ControlPanel: ProjectControlPanel };
|
||||
ProjectGraphView.ControlPanel = ProjectControlPanel;
|
||||
|
||||
viewRegistry.add("project_graph", ProjectGraphView);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { PivotView } from "@web/views/pivot/pivot_view";
|
||||
import { ProjectControlPanel } from "@project/project_control_panel/project_control_panel";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { PivotView } from "@web/views/pivot/pivot_view";
|
||||
|
||||
const viewRegistry = registry.category("views");
|
||||
|
||||
class ProjectPivotView extends PivotView {}
|
||||
ProjectPivotView.components = { ...PivotView.components, ControlPanel: ProjectControlPanel };
|
||||
ProjectPivotView.ControlPanel = ProjectControlPanel;
|
||||
|
||||
viewRegistry.add("project_pivot", ProjectPivotView);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { _lt } from "@web/core/l10n/translation";
|
||||
import { GraphView } from "@web/views/graph/graph_view";
|
||||
import { GraphArchParser } from "@web/views/graph/graph_arch_parser";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { GraphArchParser } from "@web/views/graph/graph_arch_parser";
|
||||
import { GraphView } from "@web/views/graph/graph_view";
|
||||
|
||||
const viewRegistry = registry.category("views");
|
||||
|
||||
@@ -29,6 +29,6 @@ class ProjectRatingArchParser extends GraphArchParser {
|
||||
// Would it be not better achiedved by using a proper arch directly?
|
||||
|
||||
class ProjectRatingGraphView extends GraphView {}
|
||||
ProjectRatingGraphView.archParser = ProjectRatingArchParser;
|
||||
ProjectRatingGraphView.ArchParser = ProjectRatingArchParser;
|
||||
|
||||
viewRegistry.add("project_rating_graph", ProjectRatingGraphView);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { _lt } from "@web/core/l10n/translation";
|
||||
import { PivotView } from "@web/views/pivot/pivot_view";
|
||||
import { PivotArchParser } from "@web/views/pivot/pivot_arch_parser";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { PivotArchParser } from "@web/views/pivot/pivot_arch_parser";
|
||||
import { PivotView } from "@web/views/pivot/pivot_view";
|
||||
|
||||
const viewRegistry = registry.category("views");
|
||||
|
||||
@@ -29,6 +29,6 @@ class ProjectRatingArchParser extends PivotArchParser {
|
||||
// Would it be not better achiedved by using a proper arch directly?
|
||||
|
||||
class ProjectRatingPivotView extends PivotView {}
|
||||
ProjectRatingPivotView.archParser = ProjectRatingArchParser;
|
||||
ProjectRatingPivotView.ArchParser = ProjectRatingArchParser;
|
||||
|
||||
viewRegistry.add("project_rating_pivot", ProjectRatingPivotView);
|
||||
|
||||
@@ -9,7 +9,7 @@ export class ProjectControlPanel extends ControlPanel {
|
||||
this.orm = useService("orm");
|
||||
this.user = useService("user");
|
||||
const { active_id, show_project_update } = this.env.searchModel.globalContext;
|
||||
this.showProjectUpdate = this.env.searchModel.view.type === "form" || show_project_update;
|
||||
this.showProjectUpdate = this.env.config.viewType === "form" || show_project_update;
|
||||
this.projectId = this.showProjectUpdate ? active_id : false;
|
||||
}
|
||||
|
||||
@@ -48,4 +48,5 @@ export class ProjectControlPanel extends ControlPanel {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
ProjectControlPanel.template = "project.ProjectControlPanel";
|
||||
|
||||
Reference in New Issue
Block a user