8000 [ADD] webiste_helpdesk_snippet: Dynamic snippet added · odoo/tutorials@eba241d · GitHub
[go: up one dir, main page]

Skip to content

Commit eba241d

Browse files
committed
[ADD] webiste_helpdesk_snippet: Dynamic snippet added
show a all dynamic data of ticket is shown into list and card view form and filter out that ticket based on the team wise.
1 parent e10c7ea commit eba241d

File tree

9 files changed

+221
-44
lines changed

9 files changed

+221
-44
lines changed

website_helpdesk_snippet/__manifest__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'summary': 'Website snippet for displaying Helpdesk Tickets',
66
'depends': ['website', 'helpdesk'],
77
'data': [
8+
"data/helpdesk_snippet_tour.xml",
89
"views/snippets/snippets.xml",
910
],
1011
'assets': {
@@ -14,9 +15,12 @@
1415
],
1516
'website.assets_wysiwyg': [
1617
'website_helpdesk_snippet/static/src/snippets/s_helpdesk_ticket/options.js',
17-
],
18+
],
19+
'web.assets_tests': [
20+
'website_helpdesk_snippet/static/tests/tours/helpdesk_snippet_tour.js',
21+
],
1822
},
1923
'application': False,
2024
'installable': True,
21-
'license':"LGPL-3",
25+
'license': "LGPL-3",
2226
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<odoo>
3+
<record id="helpdesk_snippet_tour" model="web_tour.tour">
4+
<field name="name">website_helpdesk_snippet.helpdesk_snippet_tour</field>
5+
<field name="sequence">10</field>
6+
<field name="rainbow_man_message">Congrats, your tour completed successfully!</field>
7+
</record>
8+
</odoo>
Lines changed: 85 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,95 @@
11

2-
/** @odoo-module */
2+
// /** @odoo-module */
3+
// import { renderToElement } from "@web/core/utils/render";
4+
// import publicWidget from "@web/legacy/js/public/public_widget";
5+
// // import { rpc } from "@web/core/network/rpc";
6+
7+
// publicWidget.registry.get_product_tab = publicWidget.Widget.extend({
8+
// selector: '.categories_section',
9+
// disabledInEditableMode: false,
10+
11+
// init() {
12+
// this._super(...arguments);
13+
// this.orm = this.bindService("orm");
14+
// this.customDomain = [];
15+
// this.result = [];
16+
// },
17+
18+
// async willStart() {
19+
// const helpdeskTeamId = this.el.dataset.helpdeskTeamId;
20+
// if (helpdeskTeamId) {
21+
// this.customDomain = [["team_id", "=", parseInt(helpdeskTeamId)]];
22+
// }
23+
24+
// this.layout = this.el.dataset.layout || "list";
25+
26+
// this.result = await this.orm.searchRead(
27+
// "helpdesk.ticket",
28+
// this.customDomain,
29+
// ["name", "user_id", "partner_id", "priority"]
30+
// );
31+
// },
32+
33+
// start() {
34+
// if (this.result && this.result.length) {
35+
// const templateName =
36+
// this.layout === "list"
37+
// ? "website_helpdesk_snippet.helpdesk_ticket_list"
38+
// : "website_helpdesk_snippet.helpdesk_ticket_card";
39+
40+
// const rendered = renderToElement(templateName, { result: this.result });
41+
// this.el.replaceChildren(rendered);
42+
// }
43+
// },
44+
// });
45+
46+
/** @odoo-module **/
47+
48+
import { Interaction } from "@web/public/interaction";
49+
import { registry } from "@web/core/registry";
350
import { renderToElement } from "@web/core/utils/render";
4-
import publicWidget from "@web/legacy/js/public/public_widget";
5-
// import { rpc } from "@web/core/network/rpc";
651

7-
publicWidget.registry.get_product_tab = publicWidget.Widget.extend({
8-
selector: '.categories_section',
9-
disabledInEditableMode: false,
52+
export class GetProductTab extends Interaction {
53+
static selector = ".categories_section";
1054

11-
init(){
12-
this._super(...arguments);
13-
this.orm = this.bindService('orm');
55+
setup(){
56+
this.orm = this.services.orm;
57+
}
58+
59+
async willStart() {
60+
61+
const helpdeskTeamId = this.el.dataset.helpdeskTeamId;
1462
this.customDomain = [];
15-
},
16-
17-
async willStart(){
18-
if(this.el.dataset.helpdeskTeamId) {
19-
const helpdesk_id = parseInt(this.el.dataset.helpdeskTeamId);
20-
this.customDomain = [['team_id', '=', helpdesk_id]];
63+
if (helpdeskTeamId) {
64+
this.customDomain = [["team_id", "=", parseInt(helpdeskTeamId)]];
2165
}
22-
23-
const result = await this.orm.searchRead(
24-
'helpdesk.ticket',
66+
67+
this.layout = this.el.dataset.layout || "list";
68+
this.result = await this.orm.searchRead(
69+
"helpdesk.ticket",
2570
this.customDomain,
26-
['name', 'user_id','partner_id','priority'],
27-
)
71+
["name", "user_id", "partner_id", "priority"]
72+
);
73+
}
2874

29-
if (result && result.length) {
30-
const rendered = await renderToElement('website_helpdesk_snippet.category_data', {
31-
result,
32-
});
75+
start() {
76+
if (this.result && this.result.length) {
77+
const templateName =
78+
this.layout === "list"
79+
? "website_helpdesk_snippet.helpdesk_ticket_list"
80+
: "website_helpdesk_snippet.helpdesk_ticket_card";
81+
82+
const rendered = renderToElement(templateName, { result: this.result });
3383
this.el.replaceChildren(rendered);
3484
}
35-
},
36-
});
85+
}
86+
}
87+
88+
registry
89+
.category("public.interactions")
90+
.add("website_helpdesk.get_product_tab", GetProductTab);
91+
92+
registry
93+
.category("public.interactions.edit")
94+
.add("website_helpdesk.get_product_tab", { Interaction: GetProductTab} );
95+

website_helpdesk_snippet/static/src/snippets/s_helpdesk_ticket/000.xml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22

33
<templates xml:space="preserve">
4-
<t t-name="website_helpdesk_snippet.category_data">
4+
<t t-name="website_helpdesk_snippet.helpdesk_ticket_card">
55
<section class="categories_section">
66
<div class="container">
77
<h3 class="section_heading">Helpdesk Ticket</h3>
@@ -27,4 +27,36 @@
2727
</div>
2828
</section>
2929
</t>
30+
31+
<t t-name="website_helpdesk_snippet.helpdesk_ticket_list">
32+
<div class="container">
33+
<div class="table-responsive">
34+
<table class="table table-hover">
35+
<thead>
36+
<tr>
37+
<th>Ticket Name</th>
38+
<th>Assigned To</th>
39+
<th>Customer</th>
40+
<th>Priority</th>
41+
</tr>
42+
</thead>
43+
<tbody>
44+
<t t-foreach="result" t-as="ticket" t-key="ticket.id">
45+
<tr t-att-data-ticket-priority="ticket.priority" t-att-data-ticket-id="ticket.id">
46+
<td><t t-esc="ticket.name"/></td>
47+
<td>
48+
<t t-out="ticket.user_id and ticket.user_id[1] or 'Not Assigned'"/>
49+
</td>
50+
<td>
51+
<t t-out="ticket.partner_id and ticket.partner_id[1] or 'Unknown'"/>
52+
</td>
53+
<td><t t-esc="ticket.priority or 'Normal'"/></td>
54+
</tr>
55+
</t>
56+
</tbody>
57+
</table>
58+
</div>
59+
</div>
60+
</t>
61+
3062
</templates>

website_helpdesk_snippet/static/src/snippets/s_helpdesk_ticket/options.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import options from '@web_editor/js/editor/snippets.options';
44

55
options.registry.HelpdeskTickets = options.Class.extend({
66

7-
setHelpdeskTeamId(previewMode, widgetValue, params) {
8-
const teamId = widgetValue
9-
this.$target.attr('data-helpdesk-team-id', teamId? teamId : 'all');
7+
selectDataAttribute(previewMode, widgetValue, params) {
8+
this.$target[0].setAttribute("data-helpdesk-team-id", widgetValue) || '';
9+
},
10+
11+
selectLayout(previewMode, widgetValue, params) {
1012

13+
this.$target[0].setAttribute("data-layout", widgetValue);
1114
},
1215
//----------------------------------------------------------------------
1316
// Private methods
@@ -16,10 +19,15 @@ options.registry.HelpdeskTickets = options.Class.extend({
1619
/**
1720
* @override
1821
*/
22+
1923
_computeWidgetState(methodName, params) {
20-
if (methodName === 'setHelpdeskTeamId') {
21-
return this.$target[0].dataset.helpdeskTeamId || 'all';
24+
if (methodName === 'selectDataAttribute') {
25+
return this.$target[0].getAttribute("data-helpdesk-team-id") || '';
2226
}
27+
28+
if (methodName === 'selectLayout') {
29+
return this.$target[0].getAttribute("data-layout");
30+
}
2331
return this._super(...arguments);
2432
},
2533

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import {
2+
changeOption,
3+
insertSnippet,
4+
clickOnSnippet,
5+
clickOnEditAndWaitEditMode,
6+
clickOnSave,
7+
registerWebsitePreviewTour,
8+
} from '@website/js/tours/tour_utils';
9+
10+
function helpdeskSnippetTourSteps() {
11+
return [
12+
...clickOnEditAndWaitEditMode(),
13+
{
14+
content: "Click on the Helpdesk snippet to insert it.",
15+
trigger: "[data-snippet='s_helpdesk_tickets']",
16+
run: "drag_and_drop :iframe #wrap .oe_drop_zone",
17+
},
18+
...clickOnSnippet({ id: "categories_section", name: "Helpdesk Ticket" }),
19+
{
20+
content: "Click to open the layout selection.",
21+
trigger: '[data-option-name="view_template"] we-toggler',
22+
run: 'click',
23+
},
24+
{
25+
content: "Select the card layout.",
26+
trigger: '[data-select-layout="card"]',
27+
run: 'click',
28+
},
29+
{
30+
content: "check that list to card layout is selected",
31+
trigger: ":iframe .categories_section[data-layout='card']",
32+
},
33+
{
34+
content: "Open the Helpdesk Team filter.",
35+
trigger: '[data-name="helpdesk_team_opt"] we-toggler',
36+
run: 'click',
37+
},
38+
{
39+
content: "Choose a Helpdesk Team to filter the tickets.",
40+
trigger: '[data-select-data-attribute="2"]',
41+
run: 'click',
42+
},
43+
{
44+
content: "check that my team id-2 filter apply",
45+
trigger: ':iframe .categories_section[data-helpdesk-team-id="2"]',
46+
},
47+
...clickOnSave(),
48+
];
49+
}
50+
51+
registerWebsitePreviewTour(
52+
"website_helpdesk_snippet.helpdesk_snippet_tour", // same name as your js tour name
53+
{
54+
url: "/", // staring point of my url
55+
},
56+
helpdeskSnippetTourSteps
57+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_helpdesk_snippet_tour
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import odoo.tests
2+
from odoo.tests import HttpCase
3+
4+
@odoo.tests.common.tagged('post_install', '-at_install')
5+
class MyCustomTest(HttpCase):
6+
def test_my_tour(self):
7+
8+
self.start_tour("/", "website_helpdesk_snippet.helpdesk_snippet_tour", login="admin")
9+
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<odoo>
22
<!-- Main Template -->
3-
<template id="s_category_template_highlight" name="Helpdesk Ticket">
3+
<template id="s_helpdesk_tickets" name="Helpdesk Ticket">
44
<section class="categories_section">
55
<div class="container">
66
<div class="alert alert-info">
@@ -15,25 +15,24 @@
1515
<!-- Snippet Registration -->
1616
<template id="snippets" inherit_id="website.snippets">
1717
<xpath expr="//snippets[@id='snippet_groups']" position="inside">
18-
<t t-snippet="website_helpdesk_snippet.s_category_template_highlight"/>
18+
<t t-snippet="website_helpdesk_snippet.s_helpdesk_tickets"/>
1919
</xpath>
2020
</template>
2121

2222
<template id="s_dynamic_snippet_helpdesk_options" inherit_id="website.snippet_options">
2323
<xpath expr="." position="inside">
2424
<div data-js="HelpdeskTickets" data-selector=".categories_section">
2525
<we-row>
26-
<we-many2one string="Helpdesk Team" data-model="helpdesk.team" data-name="helpdesk_team_opt" data-no-preview="true" data-set-helpdesk-team-id="" />
27-
<we-button data-icon="fa-times" data-set-helpdesk-team-id="all" data-no-preview="true" />
26+
<we-many2one string="Helpdesk Team" data-model="helpdesk.team" data-name="helpdesk_team_opt" data-no-preview="true" data-select-data-attribute=""/>
27+
<we-button data-icon="fa-times" data-select-data-attribute="" data-no-preview="true" />
2828
</we-row>
29+
30+
<we-select string="Layout" data-option-name="view_template" data-no-preview="true" data-select-layout="">
31+
<we-button title="Card" data-select-layout="card" data-attribute-name="layout" data-name="card_opt">Card</we-button>
32+
<we-button title="List" data-select-layout="list" data-attribute-name="layout" data-name="list_opt">List</we-button>
33+
</we-select>
2934
</div>
3035
</xpath>
3136
</template>
3237

33-
<!-- <template id="website_helpdesk" inherit_id="website.snippets" name="Snippet Helpdesk">
34-
<xpath expr="//t[@id='installed_snippets_hook']" position="replace">
35-
<t t-snippet="website_helpdesk_snippet.category_template_highlight"/>
36-
</xpath>
37-
</template> -->
38-
3938
</odoo>

0 commit comments

Comments
 (0)
0