initial filter implementation

This commit is contained in:
Martin Cech
2019-07-06 11:51:10 +02:00
parent 0f796740dc
commit a13953dabc
3 changed files with 50 additions and 4 deletions
@@ -275,6 +275,24 @@ var FolderListView = Backbone.View.extend({
this.renderSortIcon();
},
/**
* In case the search_term is not empty perform the search and render
* the result. Render all visible folder items otherwise.
* @param {string} search_term string to search for
*/
searchFolder: function(search_term) {
const trimmed_term = $.trim(search_term);
if (trimmed_term !== "") {
let result_collection = null;
result_collection = this.collection.search(search_term);
this.options.result_models = result_collection.models;
this.collection.reset(result_collection);
} else {
this.options.result_models = null;
this.paginate();
}
},
/**
* User clicked the checkbox in the table heading
* @param {context} event
@@ -463,7 +481,7 @@ var FolderListView = Backbone.View.extend({
<a title="Return to this folder" href="#/folders/<%- path_item[0] %>">
<%- path_item[1] %>
</a>
</li>
</li>
<% } else { %>
<li class="breadcrumb-item active">
<span title="You are in this folder">
@@ -501,7 +519,7 @@ var FolderListView = Backbone.View.extend({
<a class="sort-folder-state" title="Click to reverse order" href="#">State</a>
<span title="Sorted alphabetically" class="sort-icon-state fa"></span>
</th>
<th style="width:160px;"></th>
<th style="width:160px;"></th>
</thead>
<tbody id="folder_list_body">
<tr id="first_folder_item">
@@ -25,7 +25,8 @@ var FolderToolbarView = Backbone.View.extend({
"click .toolbtn-show-locinfo": "showLocInfo",
"keydown .page_size": "changePageSize",
"blur .page_size": "changePageSize",
"click .toolbtn-collection-import": "showCollectionSelect"
"click .toolbtn-collection-import": "showCollectionSelect",
"keyup .folder-search-input": "searchFolder"
},
defaults: {
@@ -1416,6 +1417,17 @@ var FolderToolbarView = Backbone.View.extend({
return hdca.save(options);
},
/**
* Take the contents of the search field and send it to the list view
* to query the collection of folder items.
*/
searchFolder: function(event) {
const Galaxy = getGalaxyInstance();
var search_term = $(".folder-search-input").val();
this.options.search_term = search_term;
Galaxy.libraries.folderListView.searchFolder(search_term);
},
templateToolBar: function() {
return _.template(
`<div class="library_style_container">
@@ -1425,6 +1437,7 @@ var FolderToolbarView = Backbone.View.extend({
</a>
<div>
<form class="form-inline">
<input type="text" id="folder-filter" class="form-control folder-search-input mr-1" placeholder="Search" size="15">
<button style="display:none;" title="Create new folder"
class="btn btn-secondary toolbtn-create-folder add-library-items add-library-items-folder mr-1"
type="button">
@@ -81,7 +81,22 @@ var Folder = Backbone.Collection.extend({
sortFolder: function(sort_key, sort_order) {
this.comparator = mod_util.generateFolderComparator(sort_key, sort_order);
this.sort();
}
},
/**
* Search the collection and return only the models that have
* the search term in their names.
* [the term to search]
* @type {string}
*/
search: function(search_term) {
if (search_term == "") return this;
const lowercase_term = search_term.toLowerCase();
return this.filter(data => {
const lowercase_name = data.get("name").toLowerCase();
return lowercase_name.indexOf(lowercase_term) !== -1;
});
},
});
var FolderContainer = Backbone.Model.extend({