From 8f34312967d317b436345efbfa8f90b8f67a8cae Mon Sep 17 00:00:00 2001 From: Xavier-Do Date: Fri, 26 Jan 2024 14:55:56 +0100 Subject: [PATCH] [FIX] runbot: adapt js for 17.0 --- runbot/static/src/js/fields/fields.js | 38 +++++----- runbot/static/src/js/fields/tracking_value.js | 76 +++++++++---------- .../static/src/js/fields/tracking_value.xml | 60 ++++++++------- runbot/views/bundle_views.xml | 4 +- 4 files changed, 91 insertions(+), 87 deletions(-) diff --git a/runbot/static/src/js/fields/fields.js b/runbot/static/src/js/fields/fields.js index 10c49eca..e6e16a02 100644 --- a/runbot/static/src/js/fields/fields.js +++ b/runbot/static/src/js/fields/fields.js @@ -6,10 +6,11 @@ import { Many2OneField } from "@web/views/fields/many2one/many2one_field"; import { _lt } from "@web/core/l10n/translation"; import { registry } from "@web/core/registry"; -import { useDynamicPlaceholder } from "@web/views/fields/dynamicplaceholder_hook"; +import { useDynamicPlaceholder } from "@web/views/fields/dynamic_placeholder_hook"; import { useInputField } from "@web/views/fields/input_field_hook"; -import { onMounted, onWillUnmount, useEffect, useRef, xml, Component } from "@odoo/owl"; +import { useRef, xml, Component } from "@odoo/owl"; +import { useAutoresize } from "@web/core/utils/autoresize"; function stringify(obj) { @@ -30,39 +31,34 @@ export class JsonField extends TextField { t-att-id="props.id" t-att-placeholder="props.placeholder" t-att-rows="rowCount" - t-on-input="onInput" t-ref="textarea" /> `; setup() { - if (this.props.dynamicPlaceholder) { - this.dynamicPlaceholder = useDynamicPlaceholder(); - } this.divRef = useRef("div"); this.textareaRef = useRef("textarea"); + //if (this.props.dynamicPlaceholder) { + // this.dynamicPlaceholder = useDynamicPlaceholder(this.textareaRef); + //} useInputField({ getValue: () => this.value, refName: "textarea", parse: JSON.parse, }); - - useEffect(() => { - if (!this.props.readonly) { - this.resize(); - } - }); - onMounted(this.onMounted); - onWillUnmount(this.onWillUnmount); + useAutoresize(this.textareaRef, { minimumHeight: 50 }); } get value() { - return stringify(this.props.value || ""); + return stringify(this.props.record.data[this.props.name] || ""); } } -registry.category("fields").add("jsonb", JsonField); +registry.category("fields").add("runbotjsonb", { + supportedTypes: ["jsonb"], + component: JsonField, +}); export class FrontendUrl extends Component { static template = xml` @@ -84,7 +80,10 @@ export class FrontendUrl extends Component { } } -registry.category("fields").add("frontend_url", FrontendUrl); +registry.category("fields").add("frontend_url", { + supportedTypes: ["many2one"], + component: FrontendUrl, +}); export class FieldCharFrontendUrl extends Component { @@ -108,7 +107,10 @@ export class FieldCharFrontendUrl extends Component { } } -registry.category("fields").add("char_frontend_url", FieldCharFrontendUrl); +registry.category("fields").add("char_frontend_url", { + supportedTypes: ["char"], + component: FieldCharFrontendUrl, +}); //export class GithubTeamWidget extends CharField { diff --git a/runbot/static/src/js/fields/tracking_value.js b/runbot/static/src/js/fields/tracking_value.js index 0cfcc11b..47312046 100644 --- a/runbot/static/src/js/fields/tracking_value.js +++ b/runbot/static/src/js/fields/tracking_value.js @@ -1,31 +1,42 @@ /** @odoo-module **/ +import { patch } from "@web/core/utils/patch"; +import { Message } from "@mail/core/common/message"; - -import { useState} from "@odoo/owl"; -import { registerMessagingComponent, getMessagingComponent, unregisterMessagingComponent } from '@mail/utils/messaging_component'; - -const MailTrackingValue = getMessagingComponent('TrackingValue'); -export class TrackingValue extends MailTrackingValue { - static template = 'runbot.TrackingValue' - +patch(Message.prototype, { setup() { - this.display = useState({kept: false}); - super.setup() - this.oldValue = this.props.value.oldValue.formattedValueOrNone; - this.newValue = this.props.value.newValue.formattedValueOrNone; - this.multiline = ( - (this.oldValue && this.oldValue.includes('\n')) - && - (this.newValue && this.newValue.includes('\n')) - ) - if (this.multiline) { - var diff = this.makeDiff(this.oldValue, this.newValue); - this.lines = this.prepareForRendering(diff); - } - } + super.setup(...arguments); + this.kept = false; + }, + isMultiline(trackingValue) { + console.log(trackingValue) + const oldValue = trackingValue.oldValue.value; + const newValue = trackingValue.newValue.value; + return ((oldValue && oldValue.includes('\n')) && (newValue && newValue.includes('\n'))) + }, + formatTracking(trackingType, trackingValue) { + console.log('aaa') + return super.formatTracking(trackingType, trackingValue) + }, toggleKept() { - this.display.kept = !this.display.kept; - } + this.kept = !this.kept; + }, + copyOldToClipboard(trackingValue) { + return function () { + navigator.clipboard.writeText(trackingValue.oldValue.value); + }; + }, + copyNewToClipboard(trackingValue) { + return function () { + navigator.clipboard.writeText(trackingValue.newValue.value); + }; + }, + lines(trackingValue) { + const oldValue = trackingValue.oldValue.value; + const newValue = trackingValue.newValue.value; + const diff = this.makeDiff(oldValue, newValue); + const lines = this.prepareForRendering(diff); + return lines; + }, makeDiff(text1, text2) { var dmp = new diff_match_patch(); var a = dmp.diff_linesToChars_(text1, text2); @@ -36,7 +47,7 @@ export class TrackingValue extends MailTrackingValue { dmp.diff_charsToLines_(diffs, lineArray); dmp.diff_cleanupSemantic(diffs); return diffs; - } + }, prepareForRendering(diffs) { var lines = []; var pre_line_counter = 0 @@ -66,16 +77,5 @@ export class TrackingValue extends MailTrackingValue { } } return lines; - }; - - copyOldToClipboard() { - navigator.clipboard.writeText(this.oldValue); - } - - copyNewToClipboard() { - navigator.clipboard.writeText(this.newValue); - } -} - -unregisterMessagingComponent({name:'TrackingValue'}); -registerMessagingComponent(TrackingValue); + }, +}); \ No newline at end of file diff --git a/runbot/static/src/js/fields/tracking_value.xml b/runbot/static/src/js/fields/tracking_value.xml index 02c225e2..a3829af8 100644 --- a/runbot/static/src/js/fields/tracking_value.xml +++ b/runbot/static/src/js/fields/tracking_value.xml @@ -1,32 +1,34 @@ - - -
- -
- - - -
-
-
- - - - - -
- - -
-
- - - - - - - -
+ + + +
  • + +
    + + + +
    +
    ()
    +
    + + + + + +
    + + +
    +
    +
    + + + + + () + +
  • +
    diff --git a/runbot/views/bundle_views.xml b/runbot/views/bundle_views.xml index 42fff982..3335b808 100644 --- a/runbot/views/bundle_views.xml +++ b/runbot/views/bundle_views.xml @@ -75,7 +75,7 @@ - + @@ -117,7 +117,7 @@ - +