Browse Source

publish muk_web_searchpanel - 12.0

pull/115/head
MuK IT GmbH 5 years ago
parent
commit
f4c4b7e786
  1. 2
      muk_web_searchpanel/__manifest__.py
  2. 7
      muk_web_searchpanel/doc/changelog.rst
  3. 106
      muk_web_searchpanel/static/src/js/kanban_searchpanel.js
  4. 14
      muk_web_searchpanel/static/src/scss/kanban_view.scss

2
muk_web_searchpanel/__manifest__.py

@ -20,7 +20,7 @@
{ {
'name': 'MuK Search Panel', 'name': 'MuK Search Panel',
'summary': 'Kanban Search Panel', 'summary': 'Kanban Search Panel',
'version': '12.0.1.0.3',
'version': '12.0.1.1.0',
'category': 'Extra Tools', 'category': 'Extra Tools',
'license': 'AGPL-3', 'license': 'AGPL-3',
'author': 'MuK IT', 'author': 'MuK IT',

7
muk_web_searchpanel/doc/changelog.rst

@ -1,3 +1,10 @@
`1.1.0`
-------
- Lazy Loading on long requests
`1.0.0`
------- -------
- Init version - Init version

106
muk_web_searchpanel/static/src/js/kanban_searchpanel.js

@ -60,16 +60,41 @@ var SearchPanel = Widget.extend({
this.fields = params.fields; this.fields = params.fields;
this.model = params.model; this.model = params.model;
this.searchDomain = params.searchDomain; this.searchDomain = params.searchDomain;
this.loadProm = $.Deferred();
this.loadPromLazy = true;
}, },
willStart: function () { willStart: function () {
var self = this; var self = this;
var loadProm = this._fetchCategories().then(function () {
return self._fetchFilters();
var loading = $.Deferred();
var loadPromTimer = setTimeout(function () {
if(loading.state() !== 'resolved') {
loading.resolve();
}
}, this.loadPromMaxTime || 250);
this._fetchCategories().then(function () {
self._fetchFilters().then(function () {
if(loading.state() !== 'resolved') {
clearTimeout(loadPromTimer);
self.loadPromLazy = false;
loading.resolve();
}
self.loadProm.resolve();
});
}); });
return $.when(loadProm, this._super.apply(this, arguments));
return $.when(loading, this._super.apply(this, arguments));
}, },
start: function () { start: function () {
this._render();
var self = this;
if(this.loadProm.state() !== 'resolved') {
this.$el.html($("<div/>", {
'class': "o_search_panel_loading",
'html': "<i class='fa fa-spinner fa-pulse' />"
}));
}
this.loadProm.then(function() {
self._render();
});
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
}, },
@ -93,15 +118,18 @@ var SearchPanel = Widget.extend({
* @returns {$.Promise} * @returns {$.Promise}
*/ */
update: function (params) { update: function (params) {
var currentSearchDomainStr = JSON.stringify(this.searchDomain);
var newSearchDomainStr = JSON.stringify(params.searchDomain);
var def;
if (this.needReload || (currentSearchDomainStr !== newSearchDomainStr)) {
this.needReload = false;
this.searchDomain = params.searchDomain;
def = this._fetchFilters();
if(this.loadProm.state() === 'resolved') {
var newSearchDomainStr = JSON.stringify(params.searchDomain);
var currentSearchDomainStr = JSON.stringify(this.searchDomain);
if (this.needReload || (currentSearchDomainStr !== newSearchDomainStr)) {
this.needReload = false;
this.searchDomain = params.searchDomain;
this._fetchFilters().then(this._render.bind(this));
} else {
this._render();
}
} }
return $.when(def).then(this._render.bind(this));
return $.when();
}, },
//-------------------------------------------------------------------------- //--------------------------------------------------------------------------
@ -138,26 +166,30 @@ var SearchPanel = Widget.extend({
var value = category.values[valueId]; var value = category.values[valueId];
return value.parentId === false; return value.parentId === false;
}); });
// set active value
var validValues = _.pluck(category.values, 'id').concat([false]);
// set active value from context
var value = this.defaultCategoryValues[category.fieldName];
// if not set in context, or set to an unknown value, set active value
// from localStorage
if (!_.contains(validValues, value)) {
var storageKey = this._getLocalStorageKey(category);
value = this.call('local_storage', 'getItem', storageKey);
}
// if not set in localStorage either, select 'All'
category.activeValueId = _.contains(validValues, value) ? value : false;
// unfold ancestor values of active value to make it is visible
if (category.activeValueId) {
var parentValueIds = this._getAncestorValueIds(category, category.activeValueId);
parentValueIds.forEach(function (parentValue) {
category.values[parentValue].folded = false;
});
category.activeValueId = false;
if(!this.loadPromLazy) {
// set active value
var validValues = _.pluck(category.values, 'id').concat([false]);
// set active value from context
var value = this.defaultCategoryValues[category.fieldName];
// if not set in context, or set to an unknown value, set active value
// from localStorage
if (!_.contains(validValues, value)) {
var storageKey = this._getLocalStorageKey(category);
value = this.call('local_storage', 'getItem', storageKey);
}
// if not set in localStorage either, select 'All'
category.activeValueId = _.contains(validValues, value) ? value : false;
// unfold ancestor values of active value to make it is visible
if (category.activeValueId) {
var parentValueIds = this._getAncestorValueIds(category, category.activeValueId);
parentValueIds.forEach(function (parentValue) {
category.values[parentValue].folded = false;
});
}
} }
}, },
/** /**
@ -246,6 +278,8 @@ var SearchPanel = Widget.extend({
filter_domain: filterDomain, filter_domain: filterDomain,
search_domain: self.searchDomain, search_domain: self.searchDomain,
}, },
}, {
shadow: true,
}).then(function (result) { }).then(function (result) {
category.parentField = result.parent_field; category.parentField = result.parent_field;
return result.values; return result.values;
@ -287,6 +321,8 @@ var SearchPanel = Widget.extend({
group_by: filter.groupBy || false, group_by: filter.groupBy || false,
search_domain: self.searchDomain, search_domain: self.searchDomain,
}, },
}, {
shadow: true,
}).then(function (values) { }).then(function (values) {
self._createFilterTree(filterId, values); self._createFilterTree(filterId, values);
}); });
@ -305,6 +341,11 @@ var SearchPanel = Widget.extend({
var category = self.categories[categoryId]; var category = self.categories[categoryId];
if (category.activeValueId) { if (category.activeValueId) {
domain.push([category.fieldName, '=', category.activeValueId]); domain.push([category.fieldName, '=', category.activeValueId]);
} else if(self.loadPromLazy && self.loadProm.state() !== 'resolved') {
var value = self.defaultCategoryValues[category.fieldName];
if (value) {
domain.push([category.fieldName, '=', value]);
}
} }
return domain; return domain;
} }
@ -447,7 +488,6 @@ var SearchPanel = Widget.extend({
*/ */
_notifyDomainUpdated: function () { _notifyDomainUpdated: function () {
this.needReload = true; this.needReload = true;
console.log(this)
this.trigger_up('search_panel_domain_updated', { this.trigger_up('search_panel_domain_updated', {
domain: this.getDomain(), domain: this.getDomain(),
}); });

14
muk_web_searchpanel/static/src/scss/kanban_view.scss

@ -37,6 +37,20 @@
padding: $o-searchpanel-p-small $o-searchpanel-p-small $o-searchpanel-p*2 $o-searchpanel-p; padding: $o-searchpanel-p-small $o-searchpanel-p-small $o-searchpanel-p*2 $o-searchpanel-p;
border-right: 1px solid $gray-300; border-right: 1px solid $gray-300;
background-color: white; background-color: white;
position: relative;
.o_search_panel_loading {
position: absolute;
margin-top: -30px;
margin-left: -30px;
margin-bottom: 0;
margin-right: 0;
font-size: 60px;
height: 60px;
width: 60px;
left: 50%;
top: 50%;
}
.o_search_panel_category .o_search_panel_section_icon { .o_search_panel_category .o_search_panel_section_icon {
color: $o-searchpanel-category-default-color; color: $o-searchpanel-category-default-color;

Loading…
Cancel
Save