Skip to content

Commit

Permalink
Improvements in the module
Browse files Browse the repository at this point in the history
Snippet Updates
  • Loading branch information
ByteMeAsap committed Jun 26, 2024
1 parent abeeef6 commit f83e1f4
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,21 @@ import publicWidget from "web.public.widget";

publicWidget.registry.dynamic_project_list = DynamicSnippetCarousel.extend({
selector: '.s_dynamic_project_list',

/**
* Parses the project category information from the data attributes
*
* @private
* @returns Parsed JSON object
*/
_parseCategoryData: function() {
const keys = Object.keys(this.$el.get(0).dataset)
const ids = []
for (let i = 0; i < keys.length; i++) {
if (keys[i].startsWith('projectCategory_') && this.$el.get(0).dataset[keys[i]]){
ids.push(parseInt(this.$el.get(0).dataset[keys[i]]))
}
}
return ids;
},

/**
* Gets the category search domain
*
* @private
* @returns Search domain
*/
_getCategorySearchDomain: function() {

const searchDomain = [];
const filterByCategoryIds = JSON.parse(this.$el.get(0).dataset.filterByCategoryIds || '[]');

if (filterByCategoryIds.length === 0) {
return searchDomain;
if (filterByCategoryIds.length) {
searchDomain.push(['category_id', 'in', filterByCategoryIds.map(projectCategory => projectCategory.id)]);
}
searchDomain.push(['category_id', 'in', filterByCategoryIds]);
return searchDomain;
},

/**
* @override
* @private
*/
_renderContent: function () {
const result = this._super.apply(this, arguments);

const projectCategory = this._parseCategoryData();
const $title = this.$el.find('h3');
const $subTitle = this.$el.find('h4');
const $templateArea = this.$el.find('.dynamic_snippet_template');

this.trigger_up('widgets_stop_request', {
$target: $templateArea,
});
$title.text(projectCategory.name || "");
$subTitle.text(projectCategory.description || "");
this.trigger_up('widgets_start_request', {
$target: $templateArea,
editableMode: this.editableMode,
});

return result;
},

/**
* Method to be overridden in child components in order to provide a search
* domain if needed.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/** @odoo-module **/
import dynamicSnippetCarouselOptions from "website.s_dynamic_snippet_carousel_options";
import options from "web_editor.snippets.options";
import utils from "web.utils";

options.registry.dynamic_project_list = dynamicSnippetCarouselOptions.extend({
/**
Expand All @@ -10,29 +9,8 @@ options.registry.dynamic_project_list = dynamicSnippetCarouselOptions.extend({
*/
init: function () {
this._super.apply(this, arguments);
this.projectCategories = {};
this.modelNameFilter = "project.project";
},

/**
* @override
*/
async willStart() {
const _super = this._super.bind(this);
this.tagIDs = JSON.parse(this.$target[0].dataset.filterByTagIds || '[]');
const tags = await this._rpc({
model: 'project.project.category',
method: 'search_read',
domain: [['website_published', '=', true]],
fields: ['id', 'display_name'],
});

this.allTagsByID = {};
for (const tag of tags) {
this.allTagsByID[tag.id] = tag;
}
return _super(...arguments);
},
/**
*
* @override
Expand All @@ -41,70 +19,6 @@ options.registry.dynamic_project_list = dynamicSnippetCarouselOptions.extend({
this._super.apply(this, arguments);
this.$target[0].dataset.snippet = 'dynamic_project_list';
},

async _fetchProjectCategories() {
this.tagIDs = JSON.parse(this.$target[0].dataset.filterByTagIds || '[]');
const tags = await this._rpc({
model: 'project.project.category',
method: 'search_read',
domain: [['website_published', '=', true]],
fields: ['id', 'display_name'],
});

this.allTagsByID = {};
for (const tag of tags) {
this.allTagsByID[tag.id] = tag;
}
return this._rpc({
model: 'project.project.category',
method: 'search_read',
domain: [['website_published', '=', true]],
fields: ['id', 'display_name'],
});
},

/**
*
* @override
* @private
*/
_renderCustomXML: async function (uiFragment) {
// The parent _renderCustomXML function renders a filter and a template selector.
await this._super.apply(this, arguments);
},


_markupDictionary(obj) {
Object.keys(obj).forEach(
key => {obj[key] = typeof obj[key] === "string" ? utils.Markup(obj[key]) : obj[key]});
return obj;
},


setTags(previewMode, widgetValue, params) {
this.tagIDs = JSON.parse(widgetValue).map(tag => tag.id);
this.selectDataAttribute(previewMode, JSON.stringify(this.tagIDs), params);
},

/**
* @override
* @private
*/
_setOptionsDefaultValues: async function () {
this._super.apply(this, arguments);

this.options.wysiwyg.odooEditor.observerUnactive();
this._setOptionValue('projectCategory', '');
this.options.wysiwyg.odooEditor.observerActive();
},

async _computeWidgetState(methodName, params) {
if (methodName === 'setTags') {
return JSON.stringify(this.tagIDs.map(id => this.allTagsByID[id]));
}
return this._super(...arguments);
},

});

export default {
Expand Down
12 changes: 6 additions & 6 deletions website_snippet_project/views/snippets/options.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<odoo>
<template id="s_dynamic_project_list_options_template" inherit_id="website.s_dynamic_snippet_options_template">
<xpath expr="//we-select[@data-name='filter_opt']" position="after">
<t t-set="project_category_domain" t-translation="off">[["website_published", "=", true]]</t>
<we-many2many t-if="snippet_name == 'dynamic_project_list'"
string="Project categories"
data-name="project_categ_opt"
data-model="project.project"
data-m2o-field="category_id"
data-domain='[["website_published", "=", true]]'
data-limit="10"
data-set-tags=""
data-model="project.project.category"
t-att-data-domain="project_category_domain"
data-attribute-name="filterByCategoryIds"
data-no-preview="true"/>
data-fakem2m="true"
data-select-data-attribute=""
/>
</xpath>
</template>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
<odoo>

<template id="s_dynamic_project_list_template" inherit_id="website.s_dynamic_snippet_template">
<div class="dynamic_snippet_template" position="before">
<t t-if="snippet_name == 's_dynamic_project_list'">
<h3 class="text-center">Name</h3>
<h4 class="text-center">Subtitle</h4>
</t>
</div>
</template>

<template id="s_dynamic_project_list_snippet" name="Projects">
<t t-call="website_snippet_project.s_dynamic_project_list_template">
<t t-call="website.s_dynamic_snippet_template">
<t t-set="snippet_name" t-value="'s_dynamic_project_list'"/>
</t>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<template id="dynamic_filter_template_project_project_view_detail" name="Classic Card - Detailed">
<t t-foreach="records" t-as="data" data-number-of-elements="3" data-thumb="/website_snippet_project/static/src/img/snippets_options/project_view_detail.svg">
<t t-set="record" t-value="data['_record']" data-arrow-position="bottom"/>
<div class="o_carousel_project_card card h-100 w-100">
<img class="card-img-top o_img_project_square o_img_project_cover h-auto" loading="lazy" t-att-src="data['image_512']" t-att-alt="record.display_name"/>
<div class="o_carousel_project_card card h-100 w-100 text-center">
<img class="card-img-top o_img_project_square o_img_project_cover" loading="lazy" t-att-src="data['image_512']" t-att-alt="record.display_name"/>
<div class="o_carousel_project_card_body card-body d-flex flex-column justify-content-between">
<div class="card-title h5" t-field="record.display_name"/>
<div class="card-text flex-grow-1 text-muted h6" t-field="record.description"/>
<div class="d-flex justify-content-between flex-wrap flex-md-column flex-lg-row align-items-center align-self-end w-100 mt-2 pt-3 border-top">
<div class="d-flex justify-content-between flex-wrap flex-md-column align-items-center align-self-end w-100 mt-2 pt-3 border-top">
<a class="btn btn-primary" t-attf-href="/projects/#{data['slug']}">
Discover
</a>
Expand Down Expand Up @@ -59,7 +59,7 @@
<t t-foreach="records" t-as="data" data-thumb="/website_snippet_project/static/src/img/snippets_options/project_image_with_name.svg">
<t t-set="record" t-value="data['_record']"/>
<div class="card h-100 border-0 w-100 rounded-0 bg-transparent o_dynamic_project_hovered" t-att-data-url="record.website_url">
<img class="card-img-top h-auto o_img_project_square o_img_project_cover rounded" loading="lazy" t-att-src="data['image_512']" t-att-alt="record.display_name"/>
<img class="card-img-top o_img_project_square o_img_project_cover rounded" loading="lazy" t-att-src="data['image_512']" t-att-alt="record.display_name"/>
<div class="h6 text-center mt-2 p-2" t-field="record.display_name"/>
</div>
</t>
Expand Down

0 comments on commit f83e1f4

Please sign in to comment.