Skip to content

Commit

Permalink
Improvements in the module
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteMeAsap committed May 3, 2024
1 parent abeeef6 commit 427068d
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ publicWidget.registry.dynamic_project_list = DynamicSnippetCarousel.extend({
* @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;
},
// _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('filterByCategoryIds') && this.$el.get(0).dataset[keys[i]]){
// ids.push(JSON.parse(this.$el.get(0).dataset[keys[i]]))
// }
// }
// return ids;
// },

/**
* Gets the category search domain
Expand All @@ -30,41 +30,38 @@ publicWidget.registry.dynamic_project_list = DynamicSnippetCarousel.extend({
* @returns Search domain
*/
_getCategorySearchDomain: function() {

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

if (filterByCategoryIds.length === 0) {
return searchDomain;
let filterByCategoryIds = JSON.parse(this.$el.get(0).dataset.filterByCategoryIds || '[]');
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;
},
// _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[0][0].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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ options.registry.dynamic_project_list = dynamicSnippetCarouselOptions.extend({
*/
init: function () {
this._super.apply(this, arguments);
this.projectCategories = {};
// 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);
},
// 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 @@ -42,68 +42,68 @@ options.registry.dynamic_project_list = dynamicSnippetCarouselOptions.extend({
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'],
});
},
// 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);
},
// _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;
},
// _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);
},
// 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();
},
// _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);
},
// async _computeWidgetState(methodName, params) {
// if (methodName === 'setTags') {
// return JSON.stringify(this.tagIDs.map(id => this.allTagsByID[id]));
// }
// return this._super(...arguments);
// },

});

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

0 comments on commit 427068d

Please sign in to comment.