Skip to content

Commit

Permalink
[IMP] mail: better activity info translatability by providing context
Browse files Browse the repository at this point in the history
  • Loading branch information
oomsveta committed Mar 28, 2023
1 parent 54ffd01 commit 4986048
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
58 changes: 56 additions & 2 deletions addons/mail/static/src/web/activity/activity.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* @odoo-module */

import { Component, useState, onMounted, onWillUpdateProps } from "@odoo/owl";
import { Component, markup, onMounted, onWillUpdateProps, useState } from "@odoo/owl";
import { useService } from "@web/core/utils/hooks";
import { sprintf } from "@web/core/utils/strings";
import { escape, sprintf } from "@web/core/utils/strings";
import { usePopover } from "@web/core/popover/popover_hook";
import { FileUploader } from "@web/views/fields/file_handler";
import { browser } from "@web/core/browser/browser";
Expand Down Expand Up @@ -51,6 +51,60 @@ export class Activity extends Component {
this.attachmentUploader = useAttachmentUploader(this.thread);
}

/**
* @returns {string}
*/
get activityInfo() {
return markup(
sprintf(
_t(
`<span class="fw-bolder %(classes)s }}">%(delay)s:</span> %(activity name)s <span class="o-mail-Activity-user">for %(responsible employee)s</span>`
),
{
classes: this.delayClass,
delay: this.delayString,
"activity name": `<span class="fw-bolder">${escape(this.displayName)}</span>`,
"responsible employee": escape(this.props.data.user_id[1]),
}
)
);
}

/**
* @returns {string}
*/
get delayClass() {
if (this.state.delay === 0) {
return "text-warning";
}
if (this.state.delay < 0) {
return "text-danger";
}
return "text-success";
}

/**
* @returns {string}
*/
get delayString() {
switch (this.state.delay) {
case 1:
return _t("Tomorrow");
case 0:
return _t("Today");
case -1:
return _t("Yesterday");
}
if (this.state.delay > 0) {
return sprintf(_t("Due in %(number of days)s days"), {
"number of days": this.state.delay,
});
}
return sprintf(_t("%(number of days)s days overdue"), {
"number of days": -this.state.delay,
});
}

get displayName() {
if (this.props.data.summary) {
return sprintf(_t("“%s”"), this.props.data.summary);
Expand Down
8 changes: 1 addition & 7 deletions addons/mail/static/src/web/activity/activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@
</div>
<div class="flex-grow px-3">
<div class="o-mail-Activity-info">
<span class="fw-bolder text-success" t-if="state.delay === 1">Tomorrow:</span>
<span class="fw-bolder text-success" t-elif="state.delay gt 0">Due in <t t-esc="state.delay"/> days:</span>
<span class="fw-bolder text-danger" t-elif="state.delay === -1">Yesterday:</span>
<span class="fw-bolder text-danger" t-elif="state.delay lt 0"><t t-esc="-state.delay"/> days overdue:</span>
<span class="fw-bolder text-warning" t-else="">Today:</span>
<span class="fw-bolder px-2"><t t-esc="displayName"/></span>
<span class="o-mail-Activity-user px-1">for <t t-esc="activity.user_id[1]"/></span>
<t t-out="activityInfo"/>
<i class="fa fa-info-circle btn-link btn-primary cursor-pointer ms-1" role="img" title="Info" aria-label="Info" t-on-click="toggleDetails"></i>
</div>
<div t-if="state.showDetails">
Expand Down

0 comments on commit 4986048

Please sign in to comment.