[REF] web: linting and small code improvements
Part-of: odoo/odoo#92475
This commit is contained in:
@@ -52,11 +52,11 @@ Object.defineProperty(browser, "location", {
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
Object.defineProperty(browser, 'innerHeight', {
|
||||
Object.defineProperty(browser, "innerHeight", {
|
||||
get: () => window.innerHeight,
|
||||
configurable: true,
|
||||
});
|
||||
Object.defineProperty(browser, 'innerWidth', {
|
||||
Object.defineProperty(browser, "innerWidth", {
|
||||
get: () => window.innerWidth,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
</t>
|
||||
</span>
|
||||
<input type="file" name="ufile" class="o_input_file d-none"
|
||||
t-att="{multiple: props.multi_upload, accept: props.accepted_file_extensions}"
|
||||
t-att-multiple="props.multi_upload" t-att-accept="props.accepted_file_extensions"
|
||||
t-ref="file-input"
|
||||
t-on-change="onFileInputChange"
|
||||
/>
|
||||
|
||||
@@ -4,7 +4,9 @@ import { browser } from "@web/core/browser/browser";
|
||||
|
||||
// rough approximation of a visible element. not perfect (does not take into
|
||||
// account opacity = 0 for example), but good enough for our purpose
|
||||
const isVisible = (e) => e.offsetWidth > 0 || e.offsetHeight > 0;
|
||||
function isVisible(e) {
|
||||
return e.offsetWidth > 0 || e.offsetHeight > 0;
|
||||
}
|
||||
|
||||
export const ACTION_HELPERS = {
|
||||
click(el, _step) {
|
||||
|
||||
@@ -55,7 +55,7 @@ export const MEDIAS_BREAKPOINTS = [
|
||||
*
|
||||
* @returns {MediaQueryList[]}
|
||||
*/
|
||||
export function getMediaQueryLists() {
|
||||
export function getMediaQueryLists() {
|
||||
return MEDIAS_BREAKPOINTS.map(({ minWidth, maxWidth }) => {
|
||||
if (!maxWidth) {
|
||||
return window.matchMedia(`(min-width: ${minWidth}px)`);
|
||||
@@ -72,11 +72,9 @@ const MEDIAS = getMediaQueryLists();
|
||||
|
||||
export const uiService = {
|
||||
getSize() {
|
||||
return MEDIAS.findIndex(media => media.matches);
|
||||
return MEDIAS.findIndex((media) => media.matches);
|
||||
},
|
||||
start(env) {
|
||||
let ui = {};
|
||||
|
||||
// block/unblock code
|
||||
const bus = new EventBus();
|
||||
registry.category("main_components").add("BlockUI", { Component: BlockUI, props: { bus } });
|
||||
@@ -101,18 +99,6 @@ export const uiService = {
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(ui, {
|
||||
bus,
|
||||
block,
|
||||
unblock,
|
||||
});
|
||||
|
||||
Object.defineProperty(ui, "isBlocked", {
|
||||
get() {
|
||||
return blockCount > 0;
|
||||
},
|
||||
});
|
||||
|
||||
// UI active element code
|
||||
let activeElems = [document];
|
||||
|
||||
@@ -132,34 +118,34 @@ export const uiService = {
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(ui, {
|
||||
const ui = {
|
||||
bus,
|
||||
size: this.getSize(),
|
||||
get activeElement() {
|
||||
return activeElems[activeElems.length - 1];
|
||||
},
|
||||
get isBlocked() {
|
||||
return blockCount > 0;
|
||||
},
|
||||
get isSmall() {
|
||||
return ui.size <= SIZES.SM;
|
||||
},
|
||||
block,
|
||||
unblock,
|
||||
activateElement,
|
||||
deactivateElement,
|
||||
getActiveElementOf,
|
||||
});
|
||||
Object.defineProperty(ui, "activeElement", {
|
||||
get() {
|
||||
return activeElems[activeElems.length - 1];
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// listen to media query status changes
|
||||
function updateSize() {
|
||||
const updateSize = () => {
|
||||
ui.size = this.getSize();
|
||||
}
|
||||
browser.addEventListener("resize", debounce(updateSize.bind(this), 100));
|
||||
};
|
||||
browser.addEventListener("resize", debounce(updateSize, 100));
|
||||
|
||||
Object.assign(ui, {
|
||||
size: this.getSize(),
|
||||
});
|
||||
Object.defineProperty(ui, "isSmall", {
|
||||
get() {
|
||||
return ui.size <= SIZES.SM;
|
||||
},
|
||||
});
|
||||
Object.defineProperty(env, "isSmall", {
|
||||
get() {
|
||||
return ui.size <= SIZES.SM;
|
||||
return ui.isSmall;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@ export function computeVariation(value, comparisonValue) {
|
||||
|
||||
/**
|
||||
* Returns value clamped to the inclusive range of min and max.
|
||||
*
|
||||
*
|
||||
* @param {Number} num
|
||||
* @param {Number} min
|
||||
* @param {Number} max
|
||||
* @param {Number} max
|
||||
* @returns {Number}
|
||||
*/
|
||||
export function clamp(num, min, max) {
|
||||
|
||||
@@ -91,9 +91,9 @@ export function intersperse(str, indices, separator = "") {
|
||||
export function sprintf(s, ...values) {
|
||||
if (values.length === 1 && Object.prototype.toString.call(values[0]) === "[object Object]") {
|
||||
const valuesDict = values[0];
|
||||
s = s.replace(/\%\(?([^\)]+)\)s/g, (match, value) => valuesDict[value]);
|
||||
s = s.replace(/%\(?([^)]+)\)s/g, (match, value) => valuesDict[value]);
|
||||
} else if (values.length > 0) {
|
||||
s = s.replace(/\%s/g, () => values.shift());
|
||||
s = s.replace(/%s/g, () => values.shift());
|
||||
}
|
||||
return s;
|
||||
}
|
||||
@@ -108,6 +108,7 @@ export function capitalize(s) {
|
||||
return s ? s[0].toUpperCase() + s.slice(1) : "";
|
||||
}
|
||||
|
||||
/* eslint-disable */
|
||||
// prettier-ignore
|
||||
const diacriticsMap = {
|
||||
'\u0041': 'A','\u24B6': 'A','\uFF21': 'A','\u00C0': 'A','\u00C1': 'A','\u00C2': 'A','\u1EA6': 'A','\u1EA4': 'A','\u1EAA': 'A','\u1EA8': 'A',
|
||||
|
||||
@@ -118,7 +118,7 @@ async function _startServices(env, toStart) {
|
||||
}
|
||||
if (value instanceof Promise) {
|
||||
proms.push(
|
||||
new Promise(async (resolve) => {
|
||||
new Promise((resolve) => {
|
||||
value
|
||||
.then((val) => {
|
||||
services[name] = val || null;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { escape, sprintf } from "@web/core/utils/strings";
|
||||
|
||||
const { Component, onMounted, xml } = owl;
|
||||
|
||||
export const displayNotificationAction = (env, action) => {
|
||||
export function displayNotificationAction(env, action) {
|
||||
const params = action.params || {};
|
||||
const options = {
|
||||
className: params.className || "",
|
||||
@@ -20,7 +20,7 @@ export const displayNotificationAction = (env, action) => {
|
||||
const message = owl.markup(sprintf(escape(params.message), ...links));
|
||||
env.services.notification.add(message, options);
|
||||
return params.next;
|
||||
};
|
||||
}
|
||||
|
||||
registry.category("actions").add("display_notification", displayNotificationAction);
|
||||
|
||||
|
||||
@@ -228,13 +228,13 @@ QUnit.test("data-hotkey added to command palette", async (assert) => {
|
||||
}
|
||||
MyComponent.components = { TestComponent };
|
||||
MyComponent.template = xml`
|
||||
<div>
|
||||
<button title="Aria Stark" data-hotkey="a" t-on-click="onClick" />
|
||||
<input title="Bran Stark" type="text" data-hotkey="b" />
|
||||
<button title="Sansa Stark" data-hotkey="b" style="display: none;" />
|
||||
<TestComponent />
|
||||
</div>
|
||||
`;
|
||||
<div>
|
||||
<button title="Aria Stark" data-hotkey="a" t-on-click="onClick" />
|
||||
<input title="Bran Stark" type="text" data-hotkey="b" />
|
||||
<button title="Sansa Stark" data-hotkey="c" style="display: none;" />
|
||||
<TestComponent />
|
||||
</div>
|
||||
`;
|
||||
await mount(MyComponent, target, { env });
|
||||
|
||||
// Open palette
|
||||
|
||||
@@ -24,7 +24,7 @@ class TestComponent extends Component {}
|
||||
* @param {string} lang
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const patchLang = async (lang) => {
|
||||
async function patchLang(lang) {
|
||||
const { defaultLocale, defaultNumberingSystem } = Settings;
|
||||
registerCleanup(() => {
|
||||
Settings.defaultLocale = defaultLocale;
|
||||
@@ -50,7 +50,7 @@ const patchLang = async (lang) => {
|
||||
});
|
||||
serviceRegistry.add("localization", localizationService);
|
||||
await makeTestEnv();
|
||||
};
|
||||
}
|
||||
|
||||
QUnit.module("Translations");
|
||||
|
||||
|
||||
@@ -153,7 +153,7 @@ QUnit.test("has no effect when component is destroyed", async (assert) => {
|
||||
);
|
||||
});
|
||||
|
||||
const getPositionTest = (position, positionToCheck) => {
|
||||
function getPositionTest(position, positionToCheck) {
|
||||
return async (assert) => {
|
||||
assert.expect(2);
|
||||
positionToCheck = positionToCheck || position;
|
||||
@@ -167,7 +167,8 @@ const getPositionTest = (position, positionToCheck) => {
|
||||
});
|
||||
await mount(TestComp, container);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
QUnit.test("position top", getPositionTest("top"));
|
||||
QUnit.test("position left", getPositionTest("left"));
|
||||
QUnit.test("position bottom", getPositionTest("bottom"));
|
||||
@@ -198,7 +199,8 @@ const CONTAINER_STYLE_MAP = {
|
||||
h125: { height: "125px" }, // height of popper + 1/2 reference
|
||||
w125: { width: "125px" }, // width of popper + 1/2 reference
|
||||
};
|
||||
const getRepositionTest = (from, to, containerStyleChanges) => {
|
||||
|
||||
function getRepositionTest(from, to, containerStyleChanges) {
|
||||
return async (assert) => {
|
||||
assert.expect(4);
|
||||
const TestComp = getTestComponent({
|
||||
@@ -220,7 +222,8 @@ const getRepositionTest = (from, to, containerStyleChanges) => {
|
||||
[d, v = "middle"] = to.split("-");
|
||||
assert.verifySteps([`${d}-${v}`], `has ${to} position`);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
QUnit.test(
|
||||
"reposition from top-start to bottom-start",
|
||||
|
||||
Reference in New Issue
Block a user