[IMP] im_livechat: improve rating views
This commit improves the tree/kanban rating view for livechat channels: - Open the channel in discuss if the member is a member of it. Open the form view otherwise. part of task-3332872 closes odoo/odoo#125902 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
@@ -22,6 +22,14 @@ class Rating(models.Model):
|
||||
def action_open_rated_object(self):
|
||||
action = super(Rating, self).action_open_rated_object()
|
||||
if self.res_model == 'discuss.channel':
|
||||
if self.env[self.res_model].browse(self.res_id).is_member:
|
||||
ctx = self.env.context.copy()
|
||||
ctx.update({'active_id': self.res_id})
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'mail.action_discuss',
|
||||
'context': ctx,
|
||||
}
|
||||
view_id = self.env.ref('im_livechat.discuss_channel_view_form').id
|
||||
action['views'] = [[view_id, 'form']]
|
||||
return action
|
||||
|
||||
+1
-11
@@ -1,30 +1,20 @@
|
||||
/* @odoo-module */
|
||||
|
||||
import { createLocalId } from "@mail/utils/common/misc";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { ListController } from "@web/views/list/list_controller";
|
||||
|
||||
export class DiscussChannelListController extends ListController {
|
||||
setup() {
|
||||
super.setup(...arguments);
|
||||
this.threadService = useService("mail.thread");
|
||||
this.store = useService("mail.store");
|
||||
}
|
||||
|
||||
async openRecord(record) {
|
||||
if (!record.data.is_member) {
|
||||
return super.openRecord(record);
|
||||
}
|
||||
const channel =
|
||||
this.store.threads[createLocalId(record.resModel, record.resId)] ??
|
||||
(await this.threadService.fetchChannel(record.resId));
|
||||
if (!channel.is_pinned) {
|
||||
this.threadService.pin(channel);
|
||||
}
|
||||
this.threadService.setDiscussThread(channel);
|
||||
this.actionService.doAction("mail.action_discuss", {
|
||||
name: _t("Discuss"),
|
||||
additionalContext: { active_id: record.resId },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,11 +35,45 @@
|
||||
<field name="context">{'search_default_rating_last_7_days': 1}</field>
|
||||
</record>
|
||||
|
||||
<record id="im_livechat.rating_rating_view_kanban" model="ir.ui.view">
|
||||
<field name="name">im_livechat.rating.rating.view.kanban</field>
|
||||
<field name="model">rating.rating</field>
|
||||
<field name="inherit_id" ref="rating.rating_rating_view_kanban"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//kanban" position="attributes">
|
||||
<attribute name="type">object</attribute>
|
||||
<attribute name="action">action_open_rated_object</attribute>
|
||||
</xpath>
|
||||
<xpath expr="//*[@name='action_open_rated_object']" position="attributes">
|
||||
<attribute name="style">pointer-events: none;</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="im_livechat.rating_rating_view_tree" model="ir.ui.view">
|
||||
<field name="name">im_livechat.rating.rating.view.tree</field>
|
||||
<field name="model">rating.rating</field>
|
||||
<field name="inherit_id" ref="rating.rating_rating_view_tree"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//tree" position="attributes">
|
||||
<attribute name="type">object</attribute>
|
||||
<attribute name="action">action_open_rated_object</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="rating_rating_action_livechat_view_kanban" model="ir.actions.act_window.view">
|
||||
<field name="sequence" eval="1"/>
|
||||
<field name="view_mode">kanban</field>
|
||||
<field name="act_window_id" ref="rating_rating_action_livechat"/>
|
||||
<field name="view_id" ref="rating.rating_rating_view_kanban"/>
|
||||
<field name="view_id" ref="im_livechat.rating_rating_view_kanban"/>
|
||||
</record>
|
||||
|
||||
<record id="rating_rating_action_livechat_view_tree" model="ir.actions.act_window.view">
|
||||
<field name="sequence" eval="1"/>
|
||||
<field name="view_mode">tree</field>
|
||||
<field name="act_window_id" ref="rating_rating_action_livechat"/>
|
||||
<field name="view_id" ref="im_livechat.rating_rating_view_tree"/>
|
||||
</record>
|
||||
|
||||
<record id="rating_rating_action_livechat_view_form" model="ir.actions.act_window.view">
|
||||
|
||||
@@ -669,17 +669,6 @@ export const messagingService = {
|
||||
"mail.out_of_focus",
|
||||
],
|
||||
start(env, services) {
|
||||
// compute initial discuss thread if not on public page
|
||||
if (!services["mail.store"].inPublicPage) {
|
||||
const activeId = services.router.current.hash.active_id ?? "mail.box_inbox";
|
||||
let [model, id] =
|
||||
typeof activeId === "number" ? ["discuss.channel", activeId] : activeId.split("_");
|
||||
if (model === "mail.channel") {
|
||||
// legacy format (sent in old emails, shared links, ...)
|
||||
model = "discuss.channel";
|
||||
}
|
||||
services["mail.store"].discuss.threadLocalId = createLocalId(model, id);
|
||||
}
|
||||
const messaging = new Messaging(env, services);
|
||||
messaging.initialize();
|
||||
messaging.isReady.then(() => {
|
||||
|
||||
@@ -1,15 +1,71 @@
|
||||
/* @odoo-module */
|
||||
|
||||
import { Discuss } from "@mail/core/common/discuss";
|
||||
import { useMessaging, useStore } from "@mail/core/common/messaging_hook";
|
||||
|
||||
import { Component } from "@odoo/owl";
|
||||
import { Component, onWillStart, onWillUpdateProps } from "@odoo/owl";
|
||||
|
||||
import { registry } from "@web/core/registry";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { createLocalId } from "@mail/utils/common/misc";
|
||||
|
||||
/**
|
||||
* @typedef {Object} Props
|
||||
* @property {Object} action
|
||||
* @property {Object} action.context
|
||||
* @property {number} [action.context.active_id]
|
||||
* @property {Object} [action.params]
|
||||
* @property {number} [action.params.active_id]
|
||||
* @extends {Component<Props, Env>}
|
||||
*/
|
||||
export class DiscussClientAction extends Component {
|
||||
static components = { Discuss };
|
||||
static props = ["*"];
|
||||
static template = "mail.DiscussClientAction";
|
||||
|
||||
setup() {
|
||||
this.store = useStore();
|
||||
this.messaging = useMessaging();
|
||||
this.threadService = useService("mail.thread");
|
||||
onWillStart(() => this.restoreDiscussThread(this.props));
|
||||
onWillUpdateProps((nextProps) => this.restoreDiscussThread(nextProps));
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore the discuss thread according to the active_id in the action
|
||||
* if necessary: thread is different than the one already displayed and
|
||||
* we are not in a public page. If the thread is not yet known, fetch it.
|
||||
*
|
||||
* @param {Props} props
|
||||
*/
|
||||
async restoreDiscussThread(props) {
|
||||
await this.messaging.isReady;
|
||||
if (this.store.inPublicPage) {
|
||||
return;
|
||||
}
|
||||
const rawActiveId =
|
||||
props.action.context.active_id ??
|
||||
props.action.params?.active_id ??
|
||||
this.store.discuss.threadLocalId?.replace(",", "_") ??
|
||||
"mail.box_inbox";
|
||||
const activeId =
|
||||
typeof rawActiveId === "number" ? `discuss.channel_${rawActiveId}` : rawActiveId;
|
||||
let [model, id] = activeId.split("_");
|
||||
if (model === "mail.channel") {
|
||||
// legacy format (sent in old emails, shared links, ...)
|
||||
model = "discuss.channel";
|
||||
}
|
||||
const activeThreadLocalId = createLocalId(model, id);
|
||||
if (activeThreadLocalId !== this.store.discuss.threadLocalId) {
|
||||
const thread =
|
||||
this.store.threads[createLocalId(model, id)] ??
|
||||
(await this.threadService.fetchChannel(parseInt(id)));
|
||||
if (!thread.is_pinned) {
|
||||
await this.threadService.pin(thread);
|
||||
}
|
||||
this.threadService.setDiscussThread(thread);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
registry.category("actions").add("mail.action_discuss", DiscussClientAction);
|
||||
|
||||
Reference in New Issue
Block a user