Permalink
Browse files

[IMP] base: srch applied on descr + better order

[FIX] base: Fix QUnit breadcrumb test fail

Allows users to not only search on settings name but on their description too.
Improves search results relevance :
Instead of the actual fixed order, top results should be about the module
selected in the left panel

Task : #1893252
closes : #28094
  • Loading branch information...
qmo-odoo committed Oct 19, 2018
1 parent 42c6db1 commit 8e04f05d3376d3f451f81ab0c9e947fd24b9288b
Showing with 40 additions and 3 deletions.
  1. +40 −3 odoo/addons/base/static/src/js/res_config_settings.js
@@ -9,6 +9,7 @@ var FormController = require('web.FormController');
var FormRenderer = require('web.FormRenderer');
var view_registry = require('web.view_registry');
var QWeb = core.qweb;
var BaseSettingRenderer = FormRenderer.extend({
@@ -21,15 +22,17 @@ var BaseSettingRenderer = FormRenderer.extend({
this._super.apply(this, arguments);
this.activeView = false;
this.activeTab = false;
this.initial_order;
},
start: function () {
this._super.apply(this, arguments);
if (config.device.isMobile) {
core.bus.on("DOM_updated", this, function () {
this._moveToTab(this.currentIndex || this._currentAppIndex());
});
}
},
/**
@@ -199,6 +202,19 @@ var BaseSettingRenderer = FormRenderer.extend({
* @param {int} index
*/
_moveToTab: function (index) {
//Used to reorder the settings after a search and a tab switch
//Thought it would be better for the UX if the order stayed the same as the one on the left panel
if(!this.initial_order && this.$el.find('.settings')[0]){
//Converts an HtmlCollection into an array
this.initial_order = Array.prototype.slice.call(this.$el.find('.settings')[0].children);
}
else{
var current_order = this.$el.find('.settings');
current_order.empty()
current_order.append(this.initial_order)
}
this.currentIndex = !index || index === -1 ? 0 : (index === this.modules.length ? index - 1 : index);
if (this.currentIndex !== -1) {
if (this.activeView) {
@@ -219,6 +235,7 @@ var BaseSettingRenderer = FormRenderer.extend({
tab.addClass("selected");
}
}
},
_onSettingTabClick: function (event) {
@@ -236,7 +253,7 @@ var BaseSettingRenderer = FormRenderer.extend({
_onKeyUpSearch: function (event) {
this.searchText = this.searchInput.val();
this.activeTab.removeClass('selected');
// this.activeTab.removeClass('selected');
if (config.device.isMobile) {
this.$('.settings_tab').addClass('o_hidden');
this.$('.settings').addClass('d-block');
@@ -249,6 +266,9 @@ var BaseSettingRenderer = FormRenderer.extend({
* @private
*/
_resetSearch: function () {
this.searchInput.val("");
_.each(this.modules, function (module) {
module.settingView.addClass('o_hidden');
@@ -299,13 +319,23 @@ var BaseSettingRenderer = FormRenderer.extend({
_searchSetting: function () {
var self = this;
this.count = 0;
var settings = $(this.$el.find('.settings')[0].children)
//Results for active module should be at the top
var active_key = self.$el.find('.selected')[0].attributes['data-key'].value
var selectedModule = self.$el.find('.app_settings_block[data-key="' + active_key + '"]');
var toInsertBefore = $(settings[1]);
selectedModule.insertBefore(toInsertBefore)
_.each(this.modules, function (module) {
self.inVisibleCount = 0;
module.settingView.find('.o_setting_box').addClass('o_hidden');
module.settingView.find('h2').addClass('o_hidden');
module.settingView.find('.settingSearchHeader').addClass('o_hidden');
module.settingView.find('.o_settings_container').removeClass('mt16');
var resultSetting = module.settingView.find("label:containsTextLike('" + self.searchText + "')");
var resultSetting = module.settingView.find("label:containsTextLike('" + self.searchText + "'), .text-muted:containsTextLike('"+ self.searchText +"')");
if (resultSetting.length > 0) {
resultSetting.each(function () {
var settingBox = $(this).closest('.o_setting_box');
@@ -320,10 +350,17 @@ var BaseSettingRenderer = FormRenderer.extend({
module.settingView.find('.settingSearchHeader').removeClass('o_hidden');
module.settingView.removeClass('o_hidden');
}
} else {
++self.count;
}
});
this.count === _.size(this.modules) ? this.$('.notFound').removeClass('o_hidden') : this.$('.notFound').addClass('o_hidden');
if (this.searchText.length === 0) {
this._resetSearch();

0 comments on commit 8e04f05

Please sign in to comment.