-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a search bar to the controllers #735
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f43c2f1
WIP for search bar for categories in view controllers
ElDeveloper bd5e60a
Make the searchbar look less awful
ElDeveloper 84d77c5
Improve the order of the searchbar
ElDeveloper 40a450f
ENH: Add searchbar to attribute view controller
ElDeveloper b773d6e
break long line
ElDeveloper 9a966af
TST: Add tests for searchbar functionality
ElDeveloper 70c698a
STY: Small cleanup
ElDeveloper 700c29b
Make searchbar available for continuous values and remove new line
ElDeveloper 6bd2fbc
BUG: Fix "results not found" position
ElDeveloper d8afd55
ENH: Hide searchbar while controller is disabled
ElDeveloper 050cd3c
BUG: Fix issue with "No results found" message
ElDeveloper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,8 +174,31 @@ define([ | |
this.$select = $('<select>'); | ||
this.$header.append(this.$select); | ||
|
||
this.$searchBar = $("<input type='search' " + | ||
"placeholder='Search for a value ...'>" | ||
).css({ | ||
'width': '100%' | ||
}); | ||
this.$header.append(this.$searchBar); | ||
|
||
// there's a few attributes we can only set on "ready" so list them up here | ||
$(function() { | ||
scope.$searchBar.tooltip({ | ||
content: 'No results found!', | ||
disabled: true, | ||
// place the element with a slight offset at the bottom of the input | ||
// so that it doesn't overlap with the "continuous values" elements | ||
position: {my: 'center top+40', at: 'center bottom', | ||
of: scope.$searchBar}, | ||
// prevent the tooltip from disappearing when there's no matches | ||
close: function(event, ui) { | ||
if (scope.bodyGrid.getDataLength() === 0 && | ||
scope.$searchBar.val() !== '') { | ||
scope.$searchBar.tooltip('open'); | ||
} | ||
} | ||
}); | ||
|
||
var placeholder = 'Select a ' + scope.title + ' Category'; | ||
|
||
// setup the slick grid | ||
|
@@ -308,7 +331,7 @@ define([ | |
* displayed by the body grid. | ||
*/ | ||
EmperorAttributeABC.prototype.getSlickGridDataset = function() { | ||
return this.bodyGrid.getData(); | ||
return this.bodyGrid.getData().getItems(); | ||
}; | ||
|
||
/** | ||
|
@@ -326,9 +349,9 @@ define([ | |
} | ||
|
||
// Re-render | ||
this.bodyGrid.setData(data); | ||
this.bodyGrid.invalidate(); | ||
this.bodyGrid.render(); | ||
this.bodyGrid.getData().beginUpdate(); | ||
this.bodyGrid.getData().setItems(data); | ||
this.bodyGrid.getData().endUpdate(); | ||
}; | ||
|
||
/** | ||
|
@@ -340,7 +363,7 @@ define([ | |
* | ||
*/ | ||
EmperorAttributeABC.prototype._buildGrid = function(options) { | ||
var columns = [{id: 'field1', name: '', field: 'category'}]; | ||
var columns = [{id: 'field1', name: '', field: 'category'}], scope = this; | ||
|
||
// autoEdit enables one-click editor trigger on the entire grid, instead | ||
// of requiring users to click twice on a widget. | ||
|
@@ -353,12 +376,52 @@ define([ | |
columns.unshift(options.slickGridColumn); | ||
} | ||
|
||
var dataView = new Slick.Data.DataView(), searchString = ''; | ||
|
||
/** | ||
* @type {Slick.Grid} | ||
* Container that lists the metadata categories described under the | ||
* metadata column and the attribute that can be modified. | ||
*/ | ||
this.bodyGrid = new Slick.Grid(this.$gridDiv, [], columns, gridOptions); | ||
this.bodyGrid = new Slick.Grid(this.$gridDiv, dataView, columns, | ||
gridOptions); | ||
|
||
this.$searchBar.on('input', function(e) { | ||
dataView.refresh(); | ||
|
||
// show a message when no results are found | ||
if (scope.bodyGrid.getDataLength() === 0 && | ||
scope.$searchBar.val() !== '') { | ||
scope.$searchBar.tooltip('option', 'disabled', false); | ||
scope.$searchBar.tooltip('open'); | ||
} | ||
else { | ||
scope.$searchBar.tooltip('option', 'disabled', true); | ||
scope.$searchBar.tooltip('close'); | ||
} | ||
|
||
}); | ||
|
||
function substringFilter(item, args) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need a newline above it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
var val = scope.$searchBar.val(); | ||
if (!searchString && val && | ||
item.category.toLowerCase().indexOf(val.toLowerCase()) === -1) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
dataView.onRowCountChanged.subscribe(function(e, args) { | ||
scope.bodyGrid.updateRowCount(); | ||
scope.bodyGrid.render(); | ||
}); | ||
|
||
dataView.onRowsChanged.subscribe(function(e, args) { | ||
scope.bodyGrid.invalidateRows(args.rows); | ||
scope.bodyGrid.render(); | ||
}); | ||
|
||
dataView.setFilter(substringFilter); | ||
|
||
// hide the header row of the grid | ||
// http://stackoverflow.com/a/29827664/379593 | ||
|
@@ -402,7 +465,7 @@ define([ | |
json.category = this.getMetadataField(); | ||
|
||
// Convert SlickGrid list of objects to single object | ||
var gridData = this.bodyGrid.getData(); | ||
var gridData = this.getSlickGridDataset(); | ||
var jsonData = {}; | ||
for (var i = 0; i < gridData.length; i++) { | ||
jsonData[gridData[i].category] = gridData[i].value; | ||
|
@@ -488,6 +551,8 @@ define([ | |
|
||
this.$select.prop('disabled', !trulse).trigger('chosen:updated'); | ||
this.bodyGrid.setOptions({editable: trulse}); | ||
this.$searchBar.prop('disabled', !trulse); | ||
this.$searchBar.prop('hidden', !trulse); | ||
}; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this library need an entry in https://github.com/biocore/emperor/blob/new-api/LICENSE.md ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not, the module is part of the slickgrid library, which is already in use. 👍