Using o-spreadsheet features and functions is done using the same import module as if it was installed from npm. Additionaly, by adding the library as dev dependency in package.json[1], IDEs can now leverage Typescript types for autocomplete and type checking. The "alpha" release tag is always the lastest master version. [1] enable web tooling `addons/web/tooling/enable.sh` ;) closes odoo/odoo#115972 Related: odoo/enterprise#38471 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
/** @odoo-module */
|
|
|
|
import { Spreadsheet } from "@odoo/o-spreadsheet";
|
|
import { registerCleanup } from "@web/../tests/helpers/cleanup";
|
|
import { getFixture } from "@web/../tests/helpers/utils";
|
|
import { loadJS, templates } from "@web/core/assets";
|
|
|
|
import { App } from "@odoo/owl";
|
|
|
|
/** @typedef {import("@spreadsheet/o_spreadsheet/o_spreadsheet").Model} Model */
|
|
|
|
/**
|
|
* Mount o-spreadsheet component with the given spreadsheet model
|
|
* @param {Model} model
|
|
* @returns {Promise<HTMLElement>}
|
|
*/
|
|
export async function mountSpreadsheet(model) {
|
|
await loadJS("/web/static/lib/Chart/Chart.js");
|
|
const app = new App(Spreadsheet, {
|
|
props: { model },
|
|
templates: templates,
|
|
env: model.config.custom.env,
|
|
test: true,
|
|
});
|
|
registerCleanup(() => app.destroy());
|
|
const fixture = getFixture();
|
|
await app.mount(fixture);
|
|
return fixture;
|
|
}
|
|
|
|
export async function doMenuAction(registry, path, env) {
|
|
await getMenuItem(registry, path, env).action(env);
|
|
}
|
|
|
|
function getMenuItem(registry, _path, env) {
|
|
const path = [..._path];
|
|
let items = registry.getMenuItems();
|
|
while (items.length && path.length) {
|
|
const id = path.shift();
|
|
const item = items.find((item) => item.id === id);
|
|
if (!item) {
|
|
throw new Error(`Menu item ${id} not found`);
|
|
}
|
|
if (path.length === 0) {
|
|
return item;
|
|
}
|
|
items = item.children(env);
|
|
}
|
|
throw new Error(`Menu item not found`);
|
|
}
|