8000 dynamic snippet by assk-odoo · Pull Request #752 · odoo/tutorials · GitHub
[go: up one dir, main page]

Skip to content
8000

dynamic snippet #752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
26 changes: 26 additions & 0 deletions website_helpdesk_snippet/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
'name': 'Website Helpdesk Snippet',
'version': '1.0',
'author': "sujal asodariya",
'summary': 'Website snippet for displaying Helpdesk Tickets',
'depends': ['website', 'helpdesk'],
'data': [
"data/helpdesk_snippet_tour.xml",
"views/snippets/snippets.xml",
],
'assets': {
'web.assets_frontend': [
'website_helpdesk_snippet/static/src/snippets/s_helpdesk_ticket/000.xml',
"website_helpdesk_snippet/static/src/snippets/s_helpdesk_ticket/000.js",
],
'website.assets_wysiwyg': [
'website_helpdesk_snippet/static/src/snippets/s_helpdesk_ticket/options.js',
],
'web.assets_tests': [
'website_helpdesk_snippet/static/tests/tours/helpdesk_snippet_tour.js',
],
},
'application': False,
'installable': True,
'license': "LGPL-3",
}
8 changes: 8 additions & 0 deletions website_helpdesk_snippet/data/helpdesk_snippet_tour.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="helpdesk_snippet_tour" model="web_tour.tour">
<field name="name">website_helpdesk_snippet.helpdesk_snippet_tour</field>
<field name="sequence">10</field>
<field name="rainbow_man_message">Congrats, your tour completed successfully!</field>
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@

// /** @odoo-module */
// import { renderToElement } from "@web/core/utils/render";
// import publicWidget from "@web/legacy/js/public/public_widget";
// // import { rpc } from "@web/core/network/rpc";

// publicWidget.registry.get_product_tab = publicWidget.Widget.extend({
// selector: '.categories_section',
// disabledInEditableMode: false,

// init() {
// this._super(...arguments);
// this.orm = this.bindService("orm");
// this.customDomain = [];
// this.result = [];
// },

// async willStart() {
// const helpdeskTeamId = this.el.dataset.helpdeskTeamId;
// if (helpdeskTeamId) {
// this.customDomain = [["team_id", "=", parseInt(helpdeskTeamId)]];
// }

// this.layout = this.el.dataset.layout || "list";

// this.result = await this.orm.searchRead(
// "helpdesk.ticket",
// this.customDomain,
// ["name", "user_id", "partner_id", "priority"]
// );
// },

// start() {
// if (this.result && this.result.length) {
// const templateName =
// this.layout === "list"
// ? "website_helpdesk_snippet.helpdesk_ticket_list"
// : "website_helpdesk_snippet.helpdesk_ticket_card";

// const rendered = renderToElement(templateName, { result: this.result });
// this.el.replaceChildren(rendered);
// }
// },
// });

/** @odoo-module **/

import { Interaction } from "@web/public/interaction";
import { registry } from "@web/core/registry";
import { renderToElement } from "@web/core/utils/render";

export class GetProductTab extends Interaction {
static selector = ".categories_section";

setup(){
this.orm = this.services.orm;
}

async willStart() {

const helpdeskTeamId = this.el.dataset.helpdeskTeamId;
this.customDomain = [];
if (helpdeskTeamId) {
this.customDomain = [["team_id", "=", parseInt(helpdeskTeamId)]];
}

this.layout = this.el.dataset.layout || "list";
this.result = await this.orm.searchRead(
"helpdesk.ticket",
this.customDomain,
["name", "user_id", "partner_id", "priority"]
);
}

start() {
if (this.result && this.result.length) {
const templateName =
this.layout === "list"
? "website_helpdesk_snippet.helpdesk_ticket_list"
: "website_helpdesk_snippet.helpdesk_ticket_card";

const rendered = renderToElement(templateName, { result: this.result });
this.el.replaceChildren(rendered);
}
}
}

registry
.category("public.interactions")
.add("website_helpdesk.get_product_tab", GetProductTab);

registry
.category("public.interactions.edit")
.add("website_helpdesk.get_product_tab", { Interaction: GetProductTab} );

Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8" ?>

<templates xml:space="preserve">
<t t-name="website_helpdesk_snippet.helpdesk_ticket_card">
<section class="categories_section">
<div class="container">
<h3 class="section_heading">Helpdesk Ticket</h3>
<div class="row">
<t t-foreach="result" t-as="ticket" t-key="ticket.id">
<div class="col-md-4 mb-3">
<div class="card p-3 shadow-sm h-100">
<h5 class="card-title" t-esc="ticket.name"/>
<p><strong>Name:</strong> <t t-out="ticket.name or 'NO USER'"/></p>
<p><strong>Assigned to:</strong>
<t t-out="ticket.user_id and ticket.user_id[1] or 'Not Assigned'"/>
</p>
<p><strong>Customer:</strong>
<t t-out="ticket.partner_id and ticket.partner_id[1] or 'Unknown'"/>
</p>
<p><strong>Priority:</strong>
<t t-out="ticket.priority or 'Normal'"/>
</p>
</div>
</div>
</t>
</div>
</div>
</section>
</t>

<t t-name="website_helpdesk_snippet.helpdesk_ticket_list">
<div class="container">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Ticket Name</th>
<th>Assigned To</th>
<th>Customer</th>
<th>Priority</th>
</tr>
</thead>
<tbody>
<t t-foreach="result" t-as="ticket" t-key="ticket.id">
<tr t-att-data-ticket-priority="ticket.priority" t-att-data-ticket-id="ticket.id">
<td><t t-esc="ticket.name"/></td>
<td>
<t t-out="ticket.user_id and ticket.user_id[1] or 'Not Assigned'"/>
</td>
<td>
<t t-out="ticket.partner_id and ticket.partner_id[1] or 'Unknown'"/>
</td>
<td><t t-esc="ticket.priority or 'Normal'"/></td>
</tr>
</t>
</tbody>
</table>
</div>
</div>
</t>

</templates>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/** @odoo-module **/

import options from '@web_editor/js/editor/snippets.options';

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

selectDataAttribute(previewMode, widgetValue, params) {
this.$target[0].setAttribute("data-helpdesk-team-id", widgetValue) || '';
},

selectLayout(previewMode, widgetValue, params) {

this.$target[0].setAttribute("data-layout", widgetValue);
},
//----------------------------------------------------------------------
// Private methods
//----------------------------------------------------------------------

/**
* @override
*/

_computeWidgetState(methodName, params) {
if (methodName === 'selectDataAttribute') {
return this.$target[0].getAttribute("data-helpdesk-team-id") || '';
}

if (methodName === 'selectLayout') {
return this.$target[0].getAttribute("data-layout");
}
return this._super(...arguments);
},

});

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {
changeOption,
insertSnippet,
clickOnSnippet,
clickOnEditAndWaitEditMode,
clickOnSave,
registerWebsitePreviewTour,
} from '@website/js/tours/tour_utils';

function helpdeskSnippetTourSteps() {
return [
...clickOnEditAndWaitEditMode(),
{
content: "Click on the Helpdesk snippet to insert it.",
trigger: "[data-snippet='s_helpdesk_tickets']",
run: "drag_and_drop :iframe #wrap .oe_drop_zone",
},
...clickOnSnippet({ id: "categories_section", name: "Helpdesk Ticket" }),
{
content: "Click to open the layout selection.",
trigger: '[data-option-name="view_template"] we-toggler',
run: 'click',
},
{
content: "Select the card layout.",
trigger: '[data-select-layout="card"]',
run: 'click',
},
{
content: "check that list to card layout is selected",
trigger: ":iframe .categories_section[data-layout='card']",
},
{
content: "Open the Helpdesk Team filter.",
trigger: '[data-name="helpdesk_team_opt"] we-toggler',
run: 'click',
},
{
content: "Choose a Helpdesk Team to filter the tickets.",
trigger: '[data-select-data-attribute="2"]',
run: 'click',
},
{
content: "check that my team id-2 filter apply",
trigger: ':iframe .categories_section[data-helpdesk-team-id="2"]',
},
...clickOnSave(),
];
}

registerWebsitePreviewTour(
"website_helpdesk_snippet.helpdesk_snippet_tour", // same name as your js tour name
{
url: "/", // staring point of my url
},
helpdeskSnippetTourSteps
);
1 change: 1 addition & 0 deletions website_helpdesk_snippet/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_helpdesk_snippet_tour
9 changes: 9 additions & 0 deletions website_helpdesk_snippet/tests/test_helpdesk_snippet_tour.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import odoo.tests
from odoo.tests import HttpCase

@odoo.tests.common.tagged('post_install', '-at_install')
class MyCustomTest(HttpCase):
def test_my_tour(self):

self.start_tour("/", "website_helpdesk_snippet.helpdesk_snippet_tour", login="admin")

38 changes: 38 additions & 0 deletions website_helpdesk_snippet/views/snippets/snippets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<odoo>
<!-- Main Template -->
<template id="s_helpdesk_tickets" name="Helpdesk Ticket">
<section class="categories_section">
<div class="container">
<div class="alert alert-info">
<h4>Your Helpdesk ticket Highlight Tab snippet will be displayed here...
Please save to view the snippet
</h4>
</div>
</div>
</section>
</template>

<!-- Snippet Registration -->
<template id="snippets" inherit_id="website.snippets">
<xpath expr="//snippets[@id='snippet_groups']" position="inside">
<t t-snippet="website_helpdesk_snippet.s_helpdesk_tickets"/>
</xpath>
</template>

<template id="s_dynamic_snippet_helpdesk_options" inherit_id="website.snippet_options">
<xpath expr="." position="inside">
<div data-js="HelpdeskTickets" data-selector=".categories_section">
<we-row>
<we-many2one string="Helpdesk Team" data-model="helpdesk.team" data-name="helpdesk_team_opt" data-no-preview="true" data-select-data-attribute=""/>
<we-button data-icon="fa-times" data-select-data-attribute="" data-no-preview="true" />
</we-row>

<we-select string="Layout" data-option-name="view_template" data-no-preview="true" data-select-layout="">
<we-button title="Card" data-select-layout="card" data-attribute-name="layout" data-name="card_opt">Card</we-button>
<we-button title="List" data-select-layout="list" data-attribute-name="layout" data-name="list_opt">List</we-button>
</we-select>
</div>
</xpath>
</template>

</odoo>
0