Merge pull request #3126 from jackwilsdon/toggle-search-filtering
Add option for disabling filters on search results
This commit is contained in:
3 files changed
+28
-7
No files matched your search
@@ -99,6 +99,7 @@ date of first contribution):
|
||||
* [Daniel Joyce](https://github.com/DanielJoyce)
|
||||
* [Andy Qua](https://github.com/AndyQ)
|
||||
* [Fabio Santos](https://github.com/Fabi0San)
|
||||
* [Jack Wilsdon](https://github.com/jackwilsdon)
|
||||
|
||||
OctoPrint started off as a fork of [Cura](https://github.com/daid/Cura) by
|
||||
[Daid Braam](https://github.com/daid). Parts of its communication layer and
|
||||
|
||||
@@ -21,6 +21,7 @@ function ItemListHelper(listType, supportedSorting, supportedFilters, defaultSor
|
||||
self.currentSorting = ko.observable(self.defaultSorting);
|
||||
self.currentFilters = ko.observableArray(self.defaultFilters);
|
||||
self.selectedItem = ko.observable(undefined);
|
||||
self.filterSearch = ko.observable(true);
|
||||
|
||||
self.storageIds = {
|
||||
"currentSorting": self.listType + "." + "currentSorting",
|
||||
@@ -223,6 +224,19 @@ function ItemListHelper(listType, supportedSorting, supportedFilters, defaultSor
|
||||
|
||||
//~~ filtering
|
||||
|
||||
self.setFilterSearch = function(enabled) {
|
||||
if (self.filterSearch() === enabled)
|
||||
return;
|
||||
|
||||
self.filterSearch(enabled);
|
||||
self.changePage(0);
|
||||
self._updateItems();
|
||||
};
|
||||
|
||||
self.toggleFilterSearch = function() {
|
||||
self.setFilterSearch(!self.filterSearch());
|
||||
};
|
||||
|
||||
self.toggleFilter = function(filter) {
|
||||
if (!_.contains(_.keys(self.supportedFilters), filter))
|
||||
return;
|
||||
@@ -283,15 +297,19 @@ function ItemListHelper(listType, supportedSorting, supportedFilters, defaultSor
|
||||
// work on all items
|
||||
var result = self.allItems;
|
||||
|
||||
// filter if necessary
|
||||
var filters = self.currentFilters();
|
||||
_.each(filters, function(filter) {
|
||||
if (typeof filter !== 'undefined' && typeof supportedFilters[filter] !== 'undefined')
|
||||
result = _.filter(result, supportedFilters[filter]);
|
||||
});
|
||||
var hasSearch = typeof self.searchFunction !== 'undefined' && self.searchFunction;
|
||||
|
||||
// filter if we're not searching or have search filtering enabled
|
||||
if (!hasSearch || self.filterSearch()) {
|
||||
var filters = self.currentFilters();
|
||||
_.each(filters, function (filter) {
|
||||
if (typeof filter !== 'undefined' && typeof supportedFilters[filter] !== 'undefined')
|
||||
result = _.filter(result, supportedFilters[filter]);
|
||||
});
|
||||
}
|
||||
|
||||
// search if necessary
|
||||
if (typeof self.searchFunction !== 'undefined' && self.searchFunction) {
|
||||
if (hasSearch) {
|
||||
result = _.filter(result, self.searchFunction);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
<span class="fa fa-wrench"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><a href="#" data-bind="click: function() { $root.listHelper.toggleFilterSearch(); }"><i class="fa fa-check" data-bind="style: {visibility: listHelper.filterSearch() ? 'visible' : 'hidden'}"></i> {{ _('Apply filters to search results') }}</a></li>
|
||||
<li class="divider"></li>
|
||||
<li><a href="#" data-bind="click: function() { $root.listHelper.changeSorting('name'); }"><i class="fa fa-check" data-bind="style: {visibility: listHelper.currentSorting() == 'name' ? 'visible' : 'hidden'}"></i> {{ _('Sort by name') }} ({{ _('ascending') }})</a></li>
|
||||
<li><a href="#" data-bind="click: function() { $root.listHelper.changeSorting('upload'); }"><i class="fa fa-check" data-bind="style: {visibility: listHelper.currentSorting() == 'upload' ? 'visible' : 'hidden'}"></i> {{ _('Sort by upload date') }} ({{ _('descending') }})</a></li>
|
||||
<li><a href="#" data-bind="click: function() { $root.listHelper.changeSorting('size'); }"><i class="fa fa-check" data-bind="style: {visibility: listHelper.currentSorting() == 'size' ? 'visible' : 'hidden'}"></i> {{ _('Sort by file size') }} ({{ _('descending') }})</a></li>
|
||||
|
||||
Reference in new issue
Block a user