diff --git a/AUTHORS.md b/AUTHORS.md index ae9b33cf7..40e2c08ff 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -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 diff --git a/src/octoprint/static/js/app/helpers.js b/src/octoprint/static/js/app/helpers.js index 455644b26..172ab3eab 100644 --- a/src/octoprint/static/js/app/helpers.js +++ b/src/octoprint/static/js/app/helpers.js @@ -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); } diff --git a/src/octoprint/templates/sidebar/files_header.jinja2 b/src/octoprint/templates/sidebar/files_header.jinja2 index 7240959fc..8852615eb 100644 --- a/src/octoprint/templates/sidebar/files_header.jinja2 +++ b/src/octoprint/templates/sidebar/files_header.jinja2 @@ -3,6 +3,8 @@