Permalink
Browse files

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

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 bc930e2 commit dfff2cb6164912e203b12957b22253800a64ca83
@@ -21,8 +21,8 @@ var BaseSettingRenderer = FormRenderer.extend({
this._super.apply(this, arguments);
this.activeView = false;
this.activeTab = false;
this.initialTabElements = undefined;
},
start: function () {
this._super.apply(this, arguments);
if (config.device.isMobile) {
@@ -31,7 +31,6 @@ var BaseSettingRenderer = FormRenderer.extend({
});
}
},
/**
* @override
*/
@@ -199,6 +198,17 @@ 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
var settingsNode = this.$('.settings')[0];
if(!this.initialTabElements && settingsNode){
//Converts an HtmlCollection into an array
this.initialTabElements = Array.prototype.slice.call(settingsNode.children);
} else {
this.$('.settings')
.empty()
.append(this.initialTabElements)
}
this.currentIndex = !index || index === -1 ? 0 : (index === this.modules.length ? index - 1 : index);
if (this.currentIndex !== -1) {
if (this.activeView) {
@@ -236,7 +246,6 @@ var BaseSettingRenderer = FormRenderer.extend({
_onKeyUpSearch: function (event) {
this.searchText = this.searchInput.val();
this.activeTab.removeClass('selected');
if (config.device.isMobile) {
this.$('.settings_tab').addClass('o_hidden');
this.$('.settings').addClass('d-block');
@@ -299,13 +308,19 @@ 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(".o_form_label:containsTextLike('" + self.searchText + "'), .text-muted:containsTextLike('"+ self.searchText +"')");
if (resultSetting.length > 0) {
resultSetting.each(function () {
var settingBox = $(this).closest('.o_setting_box');
@@ -178,5 +178,97 @@ QUnit.module('base_settings_tests', {
form.destroy();
});
QUnit.test('Settings from the selected module are at the top results of a search', function (assert) {
assert.expect(3);
var form = createView({
View: BaseSettingsView,
model: 'project',
data: this.data,
arch: '<form string="Settings" class="oe_form_configuration o_base_settings">' +
'<div class="o_panel">' +
'<div class="setting_search">' +
'<input type="text" class="searchInput" placeholder="Search..."/>' +
'</div> ' +
'</div> ' +
'<header>' +
'<button string="Save" type="object" name="execute" class="oe_highlight" />' +
'<button string="Cancel" type="object" name="cancel" class="oe_link" />' +
'</header>' +
'<div class="o_setting_container">' +
'<div class="settings_tab">'+
'<div class="tab" data-key="crm">'+
'<span>CRM</span>'+
'</div>'+
'<div class="tab" data-key="sale">'+
'<span>Sales</span>'+
'</div>'+
'</div>'+
'<div class="settings">' +
'<div class="notFound o_hidden">No Record Found</div>' +
'<div class="app_settings_block" string="CRM" data-key="crm">' +
'<div class="row mt16 o_settings_container">'+
'<div class="col-12 col-lg-6 o_setting_box">'+
'<div class="o_setting_left_pane">' +
'<field name="bar"/>'+
'</div>'+
'<div class="o_setting_right_pane">'+
'<label class="o_form_label" for="bar"/>'+
'<div class="text-muted">'+
'this is bar'+
'</div>'+
'</div>' +
'</div>'+
'<div class="col-12 col-lg-6 o_setting_box">'+
'<div class="o_setting_left_pane">' +
'<field name="foo"/>'+
'</div>'+
'<div class="o_setting_right_pane">'+
'<label class="o_form_label" for="foo"/>'+
'<div class="text-muted">'+
'this is foo'+
'</div>'+
'</div>' +
'</div>'+
'</div>' +
'</div>' +
'<div class="app_settings_block" string="Sale" data-key="sale">' +
'<div class="row mt16 o_settings_container">'+
'<div class="col-12 col-lg-6 o_setting_box">'+
'<div class="o_setting_left_pane">' +
'<field name="bar"/>'+
'</div>'+
'<div class="o_setting_right_pane">'+
'<label for="bar"/>'+
'<div class="text-muted">'+
'this is bar'+
'</div>'+
'</div>' +
'</div>'+
'<div class="col-12 col-lg-6 o_setting_box">'+
'<div class="o_setting_left_pane">' +
'<field name="foo"/>'+
'</div>'+
'<div class="o_setting_right_pane">'+
'<label for="foo"/>'+
'<div class="text-muted">'+
'this is foo'+
'</div>'+
'</div>' +
'</div>'+
'</div>' +
'</div>' +
'</div>' +
'</div>' +
'</form>',
});
form.$('.tab,[data-key="sale"]').click()
assert.strictEqual(form.$('.tab.selected').attr('data-key'),"sale","sale setting selected");
form.$('.searchInput').val('t').trigger('keyup');
assert.strictEqual($('.highlighter').html(),"t","t word highlighted");
assert.strictEqual($(form.$('.settings')[0].children[1]).attr('data-key'),"sale","Results from Sales are at the top");
form.destroy();
});
});
});

0 comments on commit dfff2cb

Please sign in to comment.