mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-20 19:31:59 +02:00
Initial commit: Core packages
This commit is contained in:
commit
12c29a983b
9512 changed files with 8379910 additions and 0 deletions
|
|
@ -0,0 +1,104 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import { Dropdown } from "@web/core/dropdown/dropdown";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { useAutofocus, useService } from "@web/core/utils/hooks";
|
||||
import { sprintf } from "@web/core/utils/strings";
|
||||
|
||||
const { Component, useState } = owl;
|
||||
const favoriteMenuRegistry = registry.category("favoriteMenu");
|
||||
|
||||
/**
|
||||
* 'Add to board' menu
|
||||
*
|
||||
* Component consisiting of a toggle button, a text input and an 'Add' button.
|
||||
* The first button is simply used to toggle the component and will determine
|
||||
* whether the other elements should be rendered.
|
||||
* The input will be given the name (or title) of the view that will be added.
|
||||
* Finally, the last button will send the name as well as some of the action
|
||||
* properties to the server to add the current view (and its context) to the
|
||||
* user's dashboard.
|
||||
* This component is only available in actions of type 'ir.actions.act_window'.
|
||||
* @extends Component
|
||||
*/
|
||||
export class AddToBoard extends Component {
|
||||
setup() {
|
||||
this.notification = useService("notification");
|
||||
this.rpc = useService("rpc");
|
||||
this.state = useState({ name: this.env.config.getDisplayName() });
|
||||
|
||||
useAutofocus();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Protected
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
async addToBoard() {
|
||||
const { domain, globalContext } = this.env.searchModel;
|
||||
const { context, groupBys, orderBy } = this.env.searchModel.getPreFavoriteValues();
|
||||
const comparison = this.env.searchModel.comparison;
|
||||
const contextToSave = {
|
||||
...Object.fromEntries(
|
||||
Object.entries(globalContext).filter(
|
||||
(entry) => !entry[0].startsWith("search_default_")
|
||||
)
|
||||
),
|
||||
...context,
|
||||
orderedBy: orderBy,
|
||||
group_by: groupBys,
|
||||
dashboard_merge_domains_contexts: false,
|
||||
};
|
||||
if (comparison) {
|
||||
contextToSave.comparison = comparison;
|
||||
}
|
||||
|
||||
const result = await this.rpc("/board/add_to_dashboard", {
|
||||
action_id: this.env.config.actionId || false,
|
||||
context_to_save: contextToSave,
|
||||
domain,
|
||||
name: this.state.name,
|
||||
view_mode: this.env.config.viewType,
|
||||
});
|
||||
|
||||
if (result) {
|
||||
this.notification.add(
|
||||
this.env._t("Please refresh your browser for the changes to take effect."),
|
||||
{
|
||||
title: sprintf(this.env._t(`"%s" added to dashboard`), this.state.name),
|
||||
type: "warning",
|
||||
}
|
||||
);
|
||||
this.state.name = this.env.config.getDisplayName();
|
||||
} else {
|
||||
this.notification.add(this.env._t("Could not add filter to dashboard"), {
|
||||
type: "danger",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Handlers
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @param {KeyboardEvent} ev
|
||||
*/
|
||||
onInputKeydown(ev) {
|
||||
if (ev.key === "Enter") {
|
||||
ev.preventDefault();
|
||||
this.addToBoard();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AddToBoard.template = "board.AddToBoard";
|
||||
AddToBoard.components = { Dropdown };
|
||||
|
||||
export const addToBoardItem = {
|
||||
Component: AddToBoard,
|
||||
groupNumber: 4,
|
||||
isDisplayed: ({ config }) => config.actionType === "ir.actions.act_window" && config.actionId,
|
||||
};
|
||||
|
||||
favoriteMenuRegistry.add("add-to-board", addToBoardItem, { sequence: 10 });
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="board.AddToBoard" owl="1">
|
||||
<Dropdown class="'o_add_to_board'">
|
||||
<t t-set-slot="toggler">Add to my dashboard</t>
|
||||
<div class="px-3 py-2">
|
||||
<input type="text" class="o_input" t-ref="autofocus" t-model.trim="state.name" t-on-keydown="onInputKeydown" />
|
||||
</div>
|
||||
<div class="px-3 py-2">
|
||||
<button type="button" class="btn btn-primary" t-on-click="addToBoard">Add</button>
|
||||
</div>
|
||||
</Dropdown>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
|
|
@ -0,0 +1,160 @@
|
|||
odoo.define("board.AddToBoardMenu", function (require) {
|
||||
"use strict";
|
||||
|
||||
const Context = require("web.Context");
|
||||
const Domain = require("web.Domain");
|
||||
const { Dropdown } = require("@web/core/dropdown/dropdown");
|
||||
const FavoriteMenu = require("web.FavoriteMenu");
|
||||
const { sprintf } = require("web.utils");
|
||||
const { useAutofocus } = require("@web/core/utils/hooks");
|
||||
|
||||
const { Component, useState } = owl;
|
||||
|
||||
/**
|
||||
* 'Add to board' menu
|
||||
*
|
||||
* Component consisiting of a toggle button, a text input and an 'Add' button.
|
||||
* The first button is simply used to toggle the component and will determine
|
||||
* whether the other elements should be rendered.
|
||||
* The input will be given the name (or title) of the view that will be added.
|
||||
* Finally, the last button will send the name as well as some of the action
|
||||
* properties to the server to add the current view (and its context) to the
|
||||
* user's dashboard.
|
||||
* This component is only available in actions of type 'ir.actions.act_window'.
|
||||
*/
|
||||
class AddToBoardMenu extends Component {
|
||||
setup() {
|
||||
this.interactive = true;
|
||||
this.state = useState({
|
||||
name: this.env.action.name || "",
|
||||
open: false,
|
||||
});
|
||||
|
||||
useAutofocus();
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Private
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* This is the main function for actually saving the dashboard. This method
|
||||
* is supposed to call the route /board/add_to_dashboard with proper
|
||||
* information.
|
||||
* @private
|
||||
*/
|
||||
async addToBoard() {
|
||||
const searchQuery = this.env.searchModel.get("query");
|
||||
const context = new Context(this.env.action.context);
|
||||
context.add(searchQuery.context);
|
||||
context.add({
|
||||
group_by: searchQuery.groupBy,
|
||||
orderedBy: searchQuery.orderedBy,
|
||||
});
|
||||
if (
|
||||
searchQuery.timeRanges &&
|
||||
Object.prototype.hasOwnProperty.call(searchQuery.timeRanges, "fieldName")
|
||||
) {
|
||||
context.add({
|
||||
comparison: searchQuery.timeRanges,
|
||||
});
|
||||
}
|
||||
let controllerQueryParams;
|
||||
this.env.searchModel.trigger("get-controller-query-params", (params) => {
|
||||
controllerQueryParams = params || {};
|
||||
});
|
||||
controllerQueryParams.context = controllerQueryParams.context || {};
|
||||
const queryContext = controllerQueryParams.context;
|
||||
delete controllerQueryParams.context;
|
||||
context.add(Object.assign(controllerQueryParams, queryContext));
|
||||
|
||||
const domainArray = new Domain(this.env.action.domain || []);
|
||||
const domain = Domain.prototype.normalizeArray(
|
||||
domainArray.toArray().concat(searchQuery.domain)
|
||||
);
|
||||
|
||||
const evalutatedContext = context.eval();
|
||||
for (const key in evalutatedContext) {
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(evalutatedContext, key) &&
|
||||
/^search_default_/.test(key)
|
||||
) {
|
||||
delete evalutatedContext[key];
|
||||
}
|
||||
}
|
||||
evalutatedContext.dashboard_merge_domains_contexts = false;
|
||||
|
||||
Object.assign(this.state, {
|
||||
name: $(".o_input").val() || "",
|
||||
open: false,
|
||||
});
|
||||
|
||||
const result = await this.env.services.rpc({
|
||||
route: "/board/add_to_dashboard",
|
||||
params: {
|
||||
action_id: this.env.action.id || false,
|
||||
context_to_save: evalutatedContext,
|
||||
domain: domain,
|
||||
view_mode: this.env.view.type,
|
||||
name: this.state.name,
|
||||
},
|
||||
});
|
||||
if (result) {
|
||||
this.env.services.notification.notify({
|
||||
title: sprintf(this.env._t("'%s' added to dashboard"), this.state.name),
|
||||
message: this.env._t(
|
||||
"Please refresh your browser for the changes to take effect."
|
||||
),
|
||||
type: "warning",
|
||||
});
|
||||
} else {
|
||||
this.env.services.notification.notify({
|
||||
message: this.env._t("Could not add filter to dashboard"),
|
||||
type: "danger",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Handlers
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {KeyboardEvent} ev
|
||||
*/
|
||||
onInputKeydown(ev) {
|
||||
switch (ev.key) {
|
||||
case "Enter":
|
||||
ev.preventDefault();
|
||||
this.addToBoard();
|
||||
break;
|
||||
case "Escape":
|
||||
// Gives the focus back to the component.
|
||||
ev.preventDefault();
|
||||
ev.target.blur();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Static
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* @param {Object} env
|
||||
* @returns {boolean}
|
||||
*/
|
||||
static shouldBeDisplayed(env) {
|
||||
return env.action.type === "ir.actions.act_window";
|
||||
}
|
||||
}
|
||||
|
||||
AddToBoardMenu.props = {};
|
||||
AddToBoardMenu.template = "board.AddToBoard";
|
||||
AddToBoardMenu.components = { Dropdown };
|
||||
|
||||
FavoriteMenu.registry.add("add-to-board-menu", AddToBoardMenu, 10);
|
||||
|
||||
return AddToBoardMenu;
|
||||
});
|
||||
91
odoo-bringout-oca-ocb-board/board/static/src/board_action.js
Normal file
91
odoo-bringout-oca-ocb-board/board/static/src/board_action.js
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { View } from "@web/views/view";
|
||||
import { makeContext } from "@web/core/context";
|
||||
|
||||
const { Component, onWillStart } = owl;
|
||||
|
||||
export class BoardAction extends Component {
|
||||
setup() {
|
||||
const rpc = useService("rpc");
|
||||
const userService = useService("user");
|
||||
this.actionService = useService("action");
|
||||
const action = this.props.action;
|
||||
this.formViewId = false;
|
||||
this.isValid = true;
|
||||
onWillStart(async () => {
|
||||
let result = BoardAction.cache[action.actionId];
|
||||
if (!result) {
|
||||
result = await rpc("/web/action/load", { action_id: action.actionId });
|
||||
BoardAction.cache[action.actionId] = result;
|
||||
}
|
||||
if (!result) {
|
||||
// action does not exist
|
||||
this.isValid = false;
|
||||
return;
|
||||
}
|
||||
const viewMode = action.viewMode || result.views[0][1];
|
||||
const formView = result.views.find((v) => v[1] === "form");
|
||||
if (formView) {
|
||||
this.formViewId = formView[0];
|
||||
}
|
||||
this.viewProps = {
|
||||
resModel: result.res_model,
|
||||
type: viewMode,
|
||||
display: { controlPanel: false },
|
||||
selectRecord: (resId) => this.selectRecord(result.res_model, resId),
|
||||
};
|
||||
const view = result.views.find((v) => v[1] === viewMode);
|
||||
if (view) {
|
||||
this.viewProps.viewId = view[0];
|
||||
}
|
||||
const searchView = result.views.find((v) => v[1] === "search");
|
||||
this.viewProps.views = [
|
||||
[this.viewProps.viewId || false, viewMode],
|
||||
[(searchView && searchView[0]) || false, "search"],
|
||||
];
|
||||
|
||||
if (action.context) {
|
||||
this.viewProps.context = makeContext([
|
||||
action.context,
|
||||
{ lang: userService.context.lang },
|
||||
]);
|
||||
if ("group_by" in this.viewProps.context) {
|
||||
const groupBy = this.viewProps.context.group_by;
|
||||
this.viewProps.groupBy = typeof groupBy === "string" ? [groupBy] : groupBy;
|
||||
}
|
||||
if ("comparison" in this.viewProps.context) {
|
||||
const comparison = this.viewProps.context.comparison;
|
||||
if (
|
||||
comparison !== null &&
|
||||
typeof comparison === "object" &&
|
||||
"domains" in comparison &&
|
||||
"fieldName" in comparison
|
||||
) {
|
||||
// Some comparison object with the wrong form might have been stored in db.
|
||||
// This is why we make the checks on the keys domains and fieldName
|
||||
this.viewProps.comparison = comparison;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (action.domain) {
|
||||
this.viewProps.domain = action.domain;
|
||||
}
|
||||
if (viewMode === "list") {
|
||||
this.viewProps.allowSelectors = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
selectRecord(resModel, resId) {
|
||||
this.actionService.doAction({
|
||||
type: "ir.actions.act_window",
|
||||
res_model: resModel,
|
||||
views: [[this.formViewId, "form"]],
|
||||
res_id: resId,
|
||||
});
|
||||
}
|
||||
}
|
||||
BoardAction.template = "board.BoardAction";
|
||||
BoardAction.components = { View };
|
||||
BoardAction.cache = {};
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="board.BoardAction" owl="1">
|
||||
<t t-if="isValid">
|
||||
<View t-props="viewProps"/>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<div class="text-center text-warning m-1">Invalid action</div>
|
||||
</t>
|
||||
</t>
|
||||
</templates>
|
||||
135
odoo-bringout-oca-ocb-board/board/static/src/board_controller.js
Normal file
135
odoo-bringout-oca-ocb-board/board/static/src/board_controller.js
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import { browser } from "@web/core/browser/browser";
|
||||
import { ConfirmationDialog } from "@web/core/confirmation_dialog/confirmation_dialog";
|
||||
import { Dropdown } from "@web/core/dropdown/dropdown";
|
||||
import { DropdownItem } from "@web/core/dropdown/dropdown_item";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { renderToString } from "@web/core/utils/render";
|
||||
import { useSortable } from "@web/core/utils/sortable";
|
||||
import { standardViewProps } from "@web/views/standard_view_props";
|
||||
import { BoardAction } from "./board_action";
|
||||
|
||||
const { blockDom, Component, useState, useRef } = owl;
|
||||
|
||||
export class BoardController extends Component {
|
||||
setup() {
|
||||
this.board = useState(this.props.board);
|
||||
this.rpc = useService("rpc");
|
||||
this.dialogService = useService("dialog");
|
||||
if (this.env.isSmall) {
|
||||
this.selectLayout("1", false);
|
||||
} else {
|
||||
const mainRef = useRef("main");
|
||||
useSortable({
|
||||
ref: mainRef,
|
||||
elements: ".o-dashboard-action",
|
||||
handle: ".o-dashboard-action-header",
|
||||
cursor: "move",
|
||||
groups: ".o-dashboard-column",
|
||||
connectGroups: true,
|
||||
onDrop: ({ element, previous, parent }) => {
|
||||
const fromColIdx = parseInt(element.parentElement.dataset.idx, 10);
|
||||
const fromActionIdx = parseInt(element.dataset.idx, 10);
|
||||
const toColIdx = parseInt(parent.dataset.idx, 10);
|
||||
const toActionIdx = previous ? parseInt(previous.dataset.idx, 10) + 1 : 0;
|
||||
if (fromColIdx !== toColIdx) {
|
||||
// to reduce visual flickering
|
||||
element.classList.add("d-none");
|
||||
}
|
||||
this.moveAction(fromColIdx, fromActionIdx, toColIdx, toActionIdx);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
moveAction(fromColIdx, fromActionIdx, toColIdx, toActionIdx) {
|
||||
const action = this.board.columns[fromColIdx].actions[fromActionIdx];
|
||||
if (fromColIdx !== toColIdx) {
|
||||
// action moving from a column to another
|
||||
this.board.columns[fromColIdx].actions.splice(fromActionIdx, 1);
|
||||
this.board.columns[toColIdx].actions.splice(toActionIdx, 0, action);
|
||||
} else {
|
||||
// move inside a column
|
||||
if (fromActionIdx === toActionIdx) {
|
||||
return;
|
||||
}
|
||||
const actions = this.board.columns[fromColIdx].actions;
|
||||
if (fromActionIdx < toActionIdx) {
|
||||
actions.splice(toActionIdx + 1, 0, action);
|
||||
actions.splice(fromActionIdx, 1);
|
||||
} else {
|
||||
actions.splice(fromActionIdx, 1);
|
||||
actions.splice(toActionIdx, 0, action);
|
||||
}
|
||||
}
|
||||
this.saveBoard();
|
||||
}
|
||||
|
||||
selectLayout(layout, save = true) {
|
||||
const currentColNbr = this.board.colNumber;
|
||||
const nextColNbr = layout.split("-").length;
|
||||
if (nextColNbr < currentColNbr) {
|
||||
// need to move all actions in last cols in the last visible col
|
||||
const cols = this.board.columns;
|
||||
const lastVisibleCol = cols[nextColNbr - 1];
|
||||
for (let i = nextColNbr; i < currentColNbr; i++) {
|
||||
lastVisibleCol.actions.push(...cols[i].actions);
|
||||
cols[i].actions = [];
|
||||
}
|
||||
}
|
||||
this.board.layout = layout;
|
||||
this.board.colNumber = nextColNbr;
|
||||
if (save) {
|
||||
this.saveBoard();
|
||||
}
|
||||
if (document.querySelector("canvas")) {
|
||||
// horrible hack to force charts to be recreated so they pick up the
|
||||
// proper size. also, no idea why raf is needed :(
|
||||
browser.requestAnimationFrame(() => this.render(true));
|
||||
}
|
||||
}
|
||||
|
||||
closeAction(column, action) {
|
||||
this.dialogService.add(ConfirmationDialog, {
|
||||
body: this.env._t("Are you sure that you want to remove this item?"),
|
||||
confirm: () => {
|
||||
const index = column.actions.indexOf(action);
|
||||
column.actions.splice(index, 1);
|
||||
this.saveBoard();
|
||||
},
|
||||
cancel: () => {},
|
||||
});
|
||||
}
|
||||
|
||||
toggleAction(action, save = true) {
|
||||
action.isFolded = !action.isFolded;
|
||||
if (save) {
|
||||
this.saveBoard();
|
||||
}
|
||||
}
|
||||
|
||||
saveBoard() {
|
||||
const templateFn = renderToString.app.getTemplate("board.arch");
|
||||
const bdom = templateFn(this.board, {});
|
||||
const root = document.createElement("rendertostring");
|
||||
blockDom.mount(bdom, root);
|
||||
const result = xmlSerializer.serializeToString(root);
|
||||
const arch = result.slice(result.indexOf("<", 1), result.indexOf("</rendertostring>"));
|
||||
|
||||
this.rpc("/web/view/edit_custom", {
|
||||
custom_id: this.board.customViewId,
|
||||
arch,
|
||||
});
|
||||
this.env.bus.trigger("CLEAR-CACHES");
|
||||
}
|
||||
}
|
||||
|
||||
BoardController.template = "board.BoardView";
|
||||
BoardController.components = { BoardAction, Dropdown, DropdownItem };
|
||||
BoardController.props = {
|
||||
...standardViewProps,
|
||||
board: Object,
|
||||
};
|
||||
|
||||
const xmlSerializer = new XMLSerializer();
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
.o_dashboard {
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.o-dashboard-layout {
|
||||
display: grid;
|
||||
}
|
||||
.o-dashboard-layout-1 {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
.o-dashboard-layout-1-1 {
|
||||
grid-template-columns: 1fr 1fr;
|
||||
}
|
||||
.o-dashboard-layout-1-1-1 {
|
||||
grid-template-columns: 1fr 1fr 1fr;
|
||||
}
|
||||
.o-dashboard-layout-2-1 {
|
||||
grid-template-columns: 2fr 1fr;
|
||||
}
|
||||
.o-dashboard-layout-1-2 {
|
||||
grid-template-columns: 1fr 2fr;
|
||||
}
|
||||
|
||||
.o-dashboard-column {
|
||||
overflow-x: scroll;
|
||||
}
|
||||
|
||||
.o-dashboard-action {
|
||||
align-self: start;
|
||||
|
||||
> .o_view_controller {
|
||||
padding: 0 12px 12px 12px;
|
||||
.o_graph_renderer canvas {
|
||||
height: 300px;
|
||||
}
|
||||
}
|
||||
|
||||
.o_column_quick_create, .o_control_panel {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.o-dashboard-action > h3 > span > i {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="board.BoardView" owl="1">
|
||||
<div class="o_dashboard d-flex flex-column">
|
||||
<t t-if="board.isEmpty">
|
||||
<t t-call="board.NoContent"/>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<t t-call="board.Content"/>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="board.Content" owl="1">
|
||||
<div t-if="!env.isSmall" class="o-dashboard-header d-flex justify-content-end">
|
||||
<Dropdown togglerClass="'btn btn-secondary m-2 p-2'">
|
||||
<t t-set-slot="toggler">
|
||||
<img t-attf-src="/board/static/img/layout_{{board.layout}}.png" width="16" height="16" alt=""/>
|
||||
Change Layout
|
||||
</t>
|
||||
<t t-foreach="'1 1-1 1-1-1 1-2 2-1'.split(' ')" t-as="layout" t-key="layout">
|
||||
<DropdownItem onSelected="() => this.selectLayout(layout)">
|
||||
<img t-attf-src="/board/static/img/layout_{{layout}}.png" alt=""/>
|
||||
<i t-if="layout == board.layout" class="fa fa-check fa-lg text-success" aria-label='Layout' role="img" title="Layout"/>
|
||||
</DropdownItem>
|
||||
</t>
|
||||
</Dropdown>
|
||||
</div>
|
||||
<div class="o-dashboard-layout flex-grow-1" t-attf-class="o-dashboard-layout-{{board.layout}}" t-ref="main">
|
||||
<t t-foreach="board.columns" t-as="column" t-key="column_index">
|
||||
<div t-if="column_index lt board.colNumber" class="o-dashboard-column h-100" t-att-data-idx="column_index">
|
||||
<t t-foreach="column.actions" t-as="action" t-key="action.id">
|
||||
<div class="o-dashboard-action mx-3 my-1 bg-view border" t-att-data-idx="action_index">
|
||||
<h3 t-attf-class="o-dashboard-action-header {{action.title ? '' : 'oe_header_empty'}} p-2 m-2">
|
||||
<span> <t t-esc="action.title"/> </span>
|
||||
<span t-if="!env.isSmall" class="btn float-end p-1 text-muted" t-on-click="() => this.closeAction(column, action)"><i class="fa fa-close"/></span>
|
||||
<span class="btn float-end p-1 text-muted" t-if="!action.isFolded" t-on-click="() => this.toggleAction(action, !env.isSmall)"><i class="fa fa-window-minimize"/></span>
|
||||
<span class="btn float-end p-1 text-muted" t-if="action.isFolded" t-on-click="() => this.toggleAction(action, !env.isSmall)"><i class="fa fa-window-maximize"/></span>
|
||||
</h3>
|
||||
<BoardAction t-if="!action.isFolded" action="action" />
|
||||
</div>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="board.NoContent" owl="1">
|
||||
<div class="o_view_nocontent">
|
||||
<div class="o_nocontent_help">
|
||||
<p class="o_view_nocontent_neutral_face">
|
||||
Your personal dashboard is empty
|
||||
</p>
|
||||
<p>
|
||||
To add your first report into this dashboard, go to any
|
||||
menu, switch to list or graph view, and click <i>"Add to
|
||||
Dashboard"</i> in the extended search options.
|
||||
</p>
|
||||
<p>
|
||||
You can filter and group data before inserting into the
|
||||
dashboard using the search options.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="board.arch" owl="1">
|
||||
<form t-att-string="title">
|
||||
<board t-att-style="layout">
|
||||
<column t-foreach="columns" t-as="column" t-key="column_index">
|
||||
<t t-foreach="column.actions" t-as="action" t-key="action_index">
|
||||
<action
|
||||
t-att-name="action.actionId"
|
||||
t-att-string="action.title"
|
||||
t-att-view_mode="action.viewMode"
|
||||
t-att-context="action.context"
|
||||
t-att-domain="action.domain"
|
||||
t-att-fold="action.isFolded ? 1 : 0"/>
|
||||
</t>
|
||||
</column>
|
||||
</board>
|
||||
</form>
|
||||
</t>
|
||||
|
||||
|
||||
</templates>
|
||||
82
odoo-bringout-oca-ocb-board/board/static/src/board_view.js
Normal file
82
odoo-bringout-oca-ocb-board/board/static/src/board_view.js
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import { _lt } from "@web/core/l10n/translation";
|
||||
import { registry } from "@web/core/registry";
|
||||
import { BoardController } from "./board_controller";
|
||||
import { XMLParser } from "@web/core/utils/xml";
|
||||
import { Domain } from "@web/core/domain";
|
||||
|
||||
export class BoardArchParser extends XMLParser {
|
||||
parse(arch, customViewId) {
|
||||
let nextId = 1;
|
||||
const archInfo = {
|
||||
title: null,
|
||||
layout: null,
|
||||
colNumber: 0,
|
||||
isEmpty: true,
|
||||
columns: [{ actions: [] }, { actions: [] }, { actions: [] }],
|
||||
customViewId,
|
||||
};
|
||||
let currentIndex = -1;
|
||||
|
||||
this.visitXML(arch, (node) => {
|
||||
switch (node.tagName) {
|
||||
case "form":
|
||||
archInfo.title = node.getAttribute("string");
|
||||
break;
|
||||
case "board":
|
||||
archInfo.layout = node.getAttribute("style");
|
||||
archInfo.colNumber = archInfo.layout.split("-").length;
|
||||
break;
|
||||
case "column":
|
||||
currentIndex++;
|
||||
break;
|
||||
case "action": {
|
||||
archInfo.isEmpty = false;
|
||||
const isFolded = Boolean(
|
||||
node.hasAttribute("fold") ? parseInt(node.getAttribute("fold"), 10) : 0
|
||||
);
|
||||
let action = {
|
||||
id: nextId++,
|
||||
title: node.getAttribute("string"),
|
||||
actionId: parseInt(node.getAttribute("name"), 10),
|
||||
viewMode: node.getAttribute("view_mode"),
|
||||
context: node.getAttribute("context"),
|
||||
isFolded,
|
||||
};
|
||||
if (node.hasAttribute("domain")) {
|
||||
let domain = node.getAttribute("domain");
|
||||
// Since bfadb8e491fe2acda63a79f9577eaaec8a1c8d9c some databases might have
|
||||
// double-encoded domains in the db, so we need to unescape them before use.
|
||||
// TODO: remove unescape in saas-16.3
|
||||
domain = _.unescape(domain);
|
||||
action.domain = new Domain(domain).toList();
|
||||
// so it can be serialized when reexporting board xml
|
||||
action.domain.toString = () => node.getAttribute("domain");
|
||||
}
|
||||
archInfo.columns[currentIndex].actions.push(action);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
return archInfo;
|
||||
}
|
||||
}
|
||||
|
||||
export const boardView = {
|
||||
type: "form",
|
||||
display_name: _lt("Board"),
|
||||
Controller: BoardController,
|
||||
|
||||
props: (genericProps, view) => {
|
||||
const { arch, info } = genericProps;
|
||||
const board = new BoardArchParser().parse(arch, info.customViewId);
|
||||
return {
|
||||
...genericProps,
|
||||
className: "o_dashboard",
|
||||
board,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
registry.category("views").add("board", boardView);
|
||||
Loading…
Add table
Add a link
Reference in a new issue