Support inverting list facet selection.
Make sure blank and error selections are saved and restored in permanent links. git-svn-id: http://google-refine.googlecode.com/svn/trunk@570 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
17c9b65889
commit
270f147d92
@ -27,6 +27,7 @@ public class ListFacet implements Facet {
|
||||
protected String _name;
|
||||
protected String _expression;
|
||||
protected String _columnName;
|
||||
protected boolean _invert;
|
||||
|
||||
// If true, then facet won't show the blank and error choices
|
||||
protected boolean _omitBlank;
|
||||
@ -60,6 +61,7 @@ public class ListFacet implements Facet {
|
||||
writer.key("name"); writer.value(_name);
|
||||
writer.key("expression"); writer.value(_expression);
|
||||
writer.key("columnName"); writer.value(_columnName);
|
||||
writer.key("invert"); writer.value(_invert);
|
||||
|
||||
if (_errorMessage != null) {
|
||||
writer.key("error"); writer.value(_errorMessage);
|
||||
@ -95,6 +97,7 @@ public class ListFacet implements Facet {
|
||||
_name = o.getString("name");
|
||||
_expression = o.getString("expression");
|
||||
_columnName = o.getString("columnName");
|
||||
_invert = o.has("invert") && o.getBoolean("invert");
|
||||
|
||||
if (_columnName.length() > 0) {
|
||||
Column column = project.columnModel.getColumnByName(_columnName);
|
||||
@ -150,7 +153,8 @@ public class ListFacet implements Facet {
|
||||
_cellIndex,
|
||||
createMatches(),
|
||||
_selectBlank,
|
||||
_selectError);
|
||||
_selectError,
|
||||
_invert);
|
||||
}
|
||||
|
||||
public void computeChoices(Project project, FilteredRows filteredRows) {
|
||||
|
@ -25,6 +25,7 @@ public class ExpressionEqualRowFilter implements RowFilter {
|
||||
final protected Object[] _matches;
|
||||
final protected boolean _selectBlank;
|
||||
final protected boolean _selectError;
|
||||
final protected boolean _invert;
|
||||
|
||||
public ExpressionEqualRowFilter(
|
||||
Evaluable evaluable,
|
||||
@ -32,7 +33,8 @@ public class ExpressionEqualRowFilter implements RowFilter {
|
||||
int cellIndex,
|
||||
Object[] matches,
|
||||
boolean selectBlank,
|
||||
boolean selectError
|
||||
boolean selectError,
|
||||
boolean invert
|
||||
) {
|
||||
_evaluable = evaluable;
|
||||
_columnName = columnName;
|
||||
@ -40,9 +42,14 @@ public class ExpressionEqualRowFilter implements RowFilter {
|
||||
_matches = matches;
|
||||
_selectBlank = selectBlank;
|
||||
_selectError = selectError;
|
||||
_invert = invert;
|
||||
}
|
||||
|
||||
public boolean filterRow(Project project, int rowIndex, Row row) {
|
||||
return _invert != internalFilterRow(project, rowIndex, row);
|
||||
}
|
||||
|
||||
public boolean internalFilterRow(Project project, int rowIndex, Row row) {
|
||||
Cell cell = _cellIndex < 0 ? null : row.getCell(_cellIndex);
|
||||
|
||||
Properties bindings = ExpressionUtils.createBindings(project);
|
||||
|
@ -1,6 +1,9 @@
|
||||
function ListFacet(div, config, options, selection) {
|
||||
this._div = div;
|
||||
this._config = config;
|
||||
if (!("invert" in this._config)) {
|
||||
this._config.invert = false;
|
||||
}
|
||||
|
||||
this._options = options || {};
|
||||
if (!("sort" in this._options)) {
|
||||
@ -8,8 +11,8 @@ function ListFacet(div, config, options, selection) {
|
||||
}
|
||||
|
||||
this._selection = selection || [];
|
||||
this._blankChoice = null;
|
||||
this._errorChoice = null;
|
||||
this._blankChoice = (config.selectBlank) ? { s : true, c : 0 } : null;
|
||||
this._errorChoice = (config.selectError) ? { s : true, c : 0 } : null;
|
||||
|
||||
this._data = null;
|
||||
|
||||
@ -52,7 +55,8 @@ ListFacet.prototype.getJSON = function() {
|
||||
omitError: "omitError" in this._config ? this._config.omitError : false,
|
||||
selection: [],
|
||||
selectBlank: this._blankChoice !== null && this._blankChoice.s,
|
||||
selectError: this._errorChoice !== null && this._errorChoice.s
|
||||
selectError: this._errorChoice !== null && this._errorChoice.s,
|
||||
invert: this._config.invert
|
||||
};
|
||||
for (var i = 0; i < this._selection.length; i++) {
|
||||
var choice = {
|
||||
@ -113,6 +117,7 @@ ListFacet.prototype._initializeUI = function() {
|
||||
'<td width="1%"><a href="javascript:{}" title="Remove this facet" class="facet-title-remove" bind="removeButton"> </a></td>' +
|
||||
'<td>' +
|
||||
'<a href="javascript:{}" class="facet-choice-link" bind="resetButton">reset</a>' +
|
||||
'<a href="javascript:{}" class="facet-choice-link" bind="invertButton">invert</a>' +
|
||||
'<a href="javascript:{}" class="facet-choice-link" bind="changeButton">change</a>' +
|
||||
'<span bind="titleSpan"></span>' +
|
||||
'</td>' +
|
||||
@ -141,6 +146,7 @@ ListFacet.prototype._initializeUI = function() {
|
||||
this._elmts.expressionDiv.text(this._config.expression).hide().click(function() { self._editExpression(); });
|
||||
this._elmts.removeButton.click(function() { self._remove(); });
|
||||
this._elmts.resetButton.click(function() { self._reset(); });
|
||||
this._elmts.invertButton.click(function() { self._invert(); });
|
||||
|
||||
this._elmts.sortByCountLink.click(function() {
|
||||
if (self._options.sort != "count") {
|
||||
@ -179,6 +185,15 @@ ListFacet.prototype._initializeUI = function() {
|
||||
ListFacet.prototype._update = function(resetScroll) {
|
||||
var self = this;
|
||||
|
||||
var invert = this._config.invert;
|
||||
if (invert) {
|
||||
this._elmts.bodyInnerDiv.addClass("facet-mode-inverted");
|
||||
this._elmts.invertButton.addClass("facet-mode-inverted");
|
||||
} else {
|
||||
this._elmts.bodyInnerDiv.removeClass("facet-mode-inverted");
|
||||
this._elmts.invertButton.removeClass("facet-mode-inverted");
|
||||
}
|
||||
|
||||
if (!this._data) {
|
||||
//this._elmts.statusDiv.hide();
|
||||
this._elmts.controlsDiv.hide();
|
||||
@ -215,8 +230,10 @@ ListFacet.prototype._update = function(resetScroll) {
|
||||
this._elmts.choiceCountContainer.text(choices.length + " choices");
|
||||
if (selectionCount > 0) {
|
||||
this._elmts.resetButton.show();
|
||||
this._elmts.invertButton.show();
|
||||
} else {
|
||||
this._elmts.resetButton.hide();
|
||||
this._elmts.invertButton.hide();
|
||||
}
|
||||
|
||||
if (this._options.sort == "name") {
|
||||
@ -244,7 +261,7 @@ ListFacet.prototype._update = function(resetScroll) {
|
||||
html.push(
|
||||
'<a href="javascript:{}" class="facet-choice-link facet-choice-toggle" ' +
|
||||
'style="visibility: ' + (choice.s ? 'visible' : 'hidden') + '">' +
|
||||
(choice.s ? 'exclude' : 'include') +
|
||||
(invert != choice.s ? 'exclude' : 'include') +
|
||||
'</a>'
|
||||
);
|
||||
|
||||
@ -491,6 +508,13 @@ ListFacet.prototype._reset = function() {
|
||||
this._selection = [];
|
||||
this._blankChoice = null;
|
||||
this._errorChoice = null;
|
||||
this._config.invert = false;
|
||||
|
||||
this._updateRest();
|
||||
};
|
||||
|
||||
ListFacet.prototype._invert = function() {
|
||||
this._config.invert = !this._config.invert;
|
||||
|
||||
this._updateRest();
|
||||
};
|
||||
|
@ -98,7 +98,7 @@ a.facet-title-remove:hover {
|
||||
border-bottom: 1px solid #ccc;
|
||||
}
|
||||
.facet-controls .ui-button-text {
|
||||
padding: 0.1em 0.4em 0.2em;
|
||||
padding: 0.1em 0.4em 0.2em;
|
||||
}
|
||||
|
||||
.facet-body {
|
||||
@ -131,6 +131,14 @@ a.facet-title-remove:hover {
|
||||
font-weight: bold;
|
||||
color: #ff6a00;
|
||||
}
|
||||
.facet-mode-inverted .facet-choice-selected .facet-choice-label {
|
||||
text-decoration: line-through;
|
||||
color: black;
|
||||
}
|
||||
.facet-choice-link.facet-mode-inverted {
|
||||
text-decoration: line-through;
|
||||
color: black;
|
||||
}
|
||||
|
||||
a.facet-choice-label {
|
||||
margin-right: 0.25em;
|
||||
|
Loading…
Reference in New Issue
Block a user