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

Skip to content

Commit 102db62

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 4c650f3 commit 102db62

File tree

10 files changed

+331
-0
lines changed

10 files changed

+331
-0
lines changed

website_helpdesk_snippet/__init__.py

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
'name': 'Website Helpdesk Snippet',
3+
'version': '1.0',
4+
'author': "sujal asodariya",
5+
'summary': 'Website snippet for displaying Helpdesk Tickets',
6+
'depends': ['website', 'helpdesk'],
7+
'data': [
8+
"data/helpdesk_snippet_tour.xml",
9+
"views/snippets/snippets.xml",
10+
],
11+
'assets': {
12+
'web.assets_frontend': [
13+
'website_helpdesk_snippet/static/src/snippets/s_helpdesk_ticket/000.xml',
14+
"website_helpdesk_snippet/static/src/snippets/s_helpdesk_ticket/000.js",
15+
],
16+
'website.assets_wysiwyg': [
17+
'website_helpdesk_snippet/static/src/snippets/s_helpdesk_ticket/options.js',
18+
],
19+
'web.assets_tests': [
20+
'website_helpdesk_snippet/static/tests/tours/helpdesk_snippet_tour.js',
21+
],
22+
},
23+
'application': False,
24+
'installable': True,
25+
'license': "LGPL-3",
26+
}
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: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
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";
50+
import { renderToElement } from "@web/core/utils/render";
51+
52+
export class GetProductTab extends Interaction {
53+
static selector = ".categories_section";
54+
55+
setup(){
56+
this.orm = this.services.orm;
57+
}
58+
59+
async willStart() {
60+
61+
const helpdeskTeamId = this.el.dataset.helpdeskTeamId;
62+
this.customDomain = [];
63+
if (helpdeskTeamId) {
64+
this.customDomain = [["team_id", "=", parseInt(helpdeskTeamId)]];
65+
}
66+
67+
this.layout = this.el.dataset.layout || "list";
68+
this.result = await this.orm.searchRead(
69+
"helpdesk.ticket",
70+
this.customDomain,
71+
["name", "user_id", "partner_id", "priority"]
72+
);
73+
}
74+
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 });
83+
this.el.replaceChildren(rendered);
84+
}
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+
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<templates xml:space="preserve">
4+
<t t-name="website_helpdesk_snippet.helpdesk_ticket_card">
5+
<section class="categories_section">
6+
<div class="container">
7+
<h3 class="section_heading">Helpdesk Ticket</h3>
8+
<div class="row">
9+
<t t-foreach="result" t-as="ticket" t-key="ticket.id">
10+
<div class="col-md-4 mb-3">
11+
<div class="card p-3 shadow-sm h-100">
12+
<h5 class="card-title" t-esc="ticket.name"/>
13+
<p><strong>Name:</strong> <t t-out="ticket.name or 'NO USER'"/></p>
14+
<p><strong>Assigned to:</strong>
15+
<t t-out E377 ="ticket.user_id and ticket.user_id[1] or 'Not Assigned'"/>
16+
</p>
17+
<p><strong>Customer:</strong>
18+
<t t-out="ticket.partner_id and ticket.partner_id[1] or 'Unknown'"/>
19+
</p>
20+
<p><strong>Priority:</strong>
21+
<t t-out="ticket.priority or 'Normal'"/>
22+
</p>
23+
</div>
24+
</div>
25+
</t>
26+
</div>
27+
</div>
28+
</section>
29+
</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+
62+
</templates>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/** @odoo-module **/
2+
3+
import options from '@web_editor/js/editor/snippets.options';
4+
5+
options.registry.HelpdeskTickets = options.Class.extend({
6+
7+
selectDataAttribute(previewMode, widgetValue, params) {
8+
this.$target[0].setAttribute("data-helpdesk-team-id", widgetValue) || '';
9+
},
10+
11+
selectLayout(previewMode, widgetValue, params) {
12+
13+
this.$target[0].setAttribute("data-layout", widgetValue);
14+
},
15+
//----------------------------------------------------------------------
16+
// Private methods
17+
//----------------------------------------------------------------------
18+
19+
/**
20+
* @override
21+
*/
22+
23+
_computeWidgetState(methodName, params) {
24+
if (methodName === 'selectDataAttribute') {
25+
return this.$target[0].getAttribute("data-helpdesk-team-id") || '';
26+
}
27+
28+
if (methodName === 'selectLayout') {
29+
return this.$target[0].getAttribute("data-layout");
30+
}
31+
return this._super(...arguments);
32+
},
33+
34+
});
35+
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: 38 additions & 0 deletions
< F79D tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<odoo>
2+
<!-- Main Template -->
3+
<template id="s_helpdesk_tickets" name="Helpdesk Ticket">
4+
<section class="categories_section">
5+
<div class="container">
6+
<div class="alert alert-info">
7+
<h4>Your Helpdesk ticket Highlight Tab snippet will be displayed here...
8+
Please save to view the snippet
9+
</h4>
10+
</div>
11+
</div>
12+
</section>
13+
</template>
14+
15+
<!-- Snippet Registration -->
16+
<template id="snippets" inherit_id="website.snippets">
17+
<xpath expr="//snippets[@id='snippet_groups']" position="inside">
18+
<t t-snippet="website_helpdesk_snippet.s_helpdesk_tickets"/>
19+
</xpath>
20+
</template>
21+
22+
<template id="s_dynamic_snippet_helpdesk_options" inherit_id="website.snippet_options">
23+
<xpath expr="." position="inside">
24+
<div data-js="HelpdeskTickets" data-selector=".categories_section">
25+
<we-row>
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" />
28+
</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>
34+
</div>
35+
</xpath>
36+
</template>
37+
38+
</odoo>

0 commit comments

Comments
 (0)
0