[FIX] runbot: adapt js for 17.0

This commit is contained in:
Xavier-Do 2024-01-26 14:55:56 +01:00
parent 3b50f172c0
commit 8f34312967
4 changed files with 91 additions and 87 deletions

View File

@ -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"
/>
</div>
</t>
`;
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 {

View File

@ -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);
},
});

View File

@ -1,32 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<templates>
<t t-name="runbot.TrackingValue" owl="1">
<div class="o_TrackingValue o_RunbotTrackingValue d-flex align-items-center flex-wrap mb-1" t-attf-class="{{ className }}" role="group" t-ref="root">
<t t-if="multiline">
<div class="btn-group btn-group-toggle mb-1">
<button class="btn btn-sm btn-outline-primary" t-on-click="copyOldToClipboard">Copy old value to clipboard</button>
<button class="btn btn-sm btn-outline-primary" t-on-click="toggleKept">Toggle context</button>
<button class="btn btn-sm btn-outline-primary" t-on-click="copyNewToClipboard">Copy new value to clipboard</button>
</div>
<div class="o_TrackingValue_fieldName fst-italic text-muted ms-1 " t-esc="'(' + trackingValue.formattedChangedField + ')'"/>
<div class="code_diff">
<table>
<t t-foreach="lines" t-as="line" t-key="line_index">
<tr t-if="display.kept or line.type!=='kept'">
<td class="col_number" t-esc="line.pre_line_counter"/>
<td class="col_number" t-esc="line.post_line_counter"/>
<td class="code" t-att-class="line.type" t-esc="line.line"/>
</tr>
</t>
</table>
</div>
</t>
<t t-else="">
<span class="o_TrackingValue_oldValue me-1 px-1 text-muted fw-bold" t-esc="trackingValue.oldValue.formattedValueOrNone" t-att-class="{ 'fst-italic': !trackingValue.oldValue.formattedValue }"/>
<i class="o_TrackingValue_separator fa fa-long-arrow-right mx-1 text-600" title="Changed" role="img" aria-label="Changed"/>
<span class="o_TrackingValue_newValue me-1 fw-bold text-info" t-esc="trackingValue.newValue.formattedValueOrNone" t-att-class="{ 'fst-italic': !trackingValue.newValue.formattedValue }"/>
<span class="o_TrackingValue_fieldName fst-italic text-muted" t-esc="'(' + trackingValue.formattedChangedField + ')'"/>
</t>
</div>
<templates xml:space="preserve">
<t t-inherit="mail.Message" t-inherit-mode="extension">
<xpath expr="//li[hasclass('o-mail-Message-tracking')]" position="replace">
<li class="o-mail-Message-tracking mb-1" role="group">
<t t-if="isMultiline(trackingValue)">
<div class="btn-group btn-group-toggle mb-1">
<button class="btn btn-sm btn-outline-primary" t-on-click="copyOldToClipboard(trackingValue)">Copy old value to clipboard</button>
<button class="btn btn-sm btn-outline-primary" t-on-click="toggleKept">Toggle context</button>
<button class="btn btn-sm btn-outline-primary" t-on-click="copyNewToClipboard(trackingValue)">Copy new value to clipboard</button>
</div>
<div class="o-mail-Message-trackingField ms-1 fst-italic text-muted">(<t t-esc="trackingValue.changedField"/>)</div>
<div class="code_diff">
<table>
<t t-foreach="lines(trackingValue)" t-as="line" t-key="line_index">
<tr t-if="kept or line.type!=='kept'">
<td class="col_number" t-esc="line.pre_line_counter"/>
<td class="col_number" t-esc="line.post_line_counter"/>
<td class="code" t-att-class="line.type" t-esc="line.line"/>
</tr>
</t>
</table>
</div>
</t>
<t t-else="">
<span class="o-mail-Message-trackingOld me-1 px-1 text-muted fw-bold" t-esc="formatTrackingOrNone(trackingValue.fieldType, trackingValue.oldValue)"/>
<i class="o-mail-Message-trackingSeparator fa fa-long-arrow-right mx-1 text-600"/>
<span class="o-mail-Message-trackingNew me-1 fw-bold text-info" t-esc="formatTrackingOrNone(trackingValue.fieldType, trackingValue.newValue)"/>
<span class="o-mail-Message-trackingField ms-1 fst-italic text-muted">(<t t-esc="trackingValue.changedField"/>)</span>
</t>
</li>
</xpath>
</t>
</templates>

View File

@ -75,7 +75,7 @@
<field name="trigger_id" domain="[('project_id', '=', parent.project_id)]"/>
<field name="config_id"/>
<field name="extra_params"/>
<field name="config_data" widget="jsonb"/>
<field name="config_data" widget="runbotjsonb"/>
</tree>
</field>
</page>
@ -117,7 +117,7 @@
<field name="trigger_id"/>
<field name="config_id"/>
<field name="extra_params"/>
<field name="config_data" widget="jsonb"/>
<field name="config_data" widget="runbotjsonb"/>
</tree>
</field>
</record>