Facets can now be removed.

Minor polishing on history widget.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@15 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-02-01 00:19:41 +00:00
parent 8b22eb594f
commit 86f8c630ad
5 changed files with 87 additions and 23 deletions

View File

@ -30,6 +30,22 @@ BrowsingEngine.prototype.addFacet = function(type, config) {
this.update(); this.update();
}; };
BrowsingEngine.prototype.removeFacet = function(facet) {
var update = facet.hasSelection();
for (var i = this._facets.length - 1;i >= 0; i--) {
if (this._facets[i].facet === facet) {
this._facets[i].elmt.remove();
this._facets.splice(i, 1);
break;
}
}
if (update) {
this.update();
ui.dataTableView.update(true);
}
};
BrowsingEngine.prototype.update = function() { BrowsingEngine.prototype.update = function() {
var self = this; var self = this;

View File

@ -1,11 +1,5 @@
function HistoryWidget(div) { function HistoryWidget(div) {
this._div = div; this._div = div;
this._div.mouseover(function() {
this.style.height = "300px";
}).mouseout(function() {
this.style.height = "100px";
});
this.update(); this.update();
} }
@ -22,29 +16,50 @@ HistoryWidget.prototype.update = function(onDone) {
HistoryWidget.prototype._render = function() { HistoryWidget.prototype._render = function() {
var self = this; var self = this;
var container = this._div.empty();
this._div.empty();
$('<h3>History</h3>').appendTo(this._div); $('<h3>History</h3>').appendTo(this._div);
var bodyDiv = $('<div></div>').addClass("history-panel-body").appendTo(this._div);
bodyDiv.mouseover(function() {
this.style.height = "300px";
}).mouseout(function() {
this.style.height = "50px";
});
var lastPast = null;
var renderEntry = function(container, entry, lastDoneID, title) { var renderEntry = function(container, entry, lastDoneID, title) {
var a = $('<a href="javascript:{}"></a>').appendTo(container); var a = $('<a href="javascript:{}"></a>').appendTo(container);
a.addClass("history-entry").html(entry.description).attr("title", title).click(function(evt) { a.addClass("history-entry").html(entry.description).attr("title", title).click(function(evt) {
return self._onClickHistoryEntry(evt, entry, lastDoneID); return self._onClickHistoryEntry(evt, entry, lastDoneID);
}); });
return a;
}; };
var divPast = $('<div></div>').addClass("history-past").appendTo(this._div); var divPast = $('<div></div>').addClass("history-past").appendTo(bodyDiv);
if (this._data.past.length == 0) {
$('<div></div>').addClass("history-panel-message").text("No change to undo").appendTo(divPast);
} else {
for (var i = 0; i < this._data.past.length; i++) { for (var i = 0; i < this._data.past.length; i++) {
var entry = this._data.past[i]; var entry = this._data.past[i];
renderEntry(divPast, entry, i == 0 ? 0 : this._data.past[i - 1].id, "Undo upto and including this change"); lastPast = renderEntry(divPast, entry, i == 0 ? 0 : this._data.past[i - 1].id, "Undo upto and including this change");
}
} }
var divFuture = $('<div></div>').addClass("history-future").appendTo(this._div); var divFuture = $('<div></div>').addClass("history-future").appendTo(bodyDiv);
if (this._data.future.length == 0) {
$('<div></div>').addClass("history-panel-message").text("No change to redo").appendTo(divFuture);
} else {
for (var i = 0; i < this._data.future.length; i++) { for (var i = 0; i < this._data.future.length; i++) {
var entry = this._data.future[i]; var entry = this._data.future[i];
renderEntry(divFuture, entry, entry.id, "Redo upto and including this change"); renderEntry(divFuture, entry, entry.id, "Redo upto and including this change");
} }
}
if (lastPast != null) {
bodyDiv[0].scrollTop = lastPast[0].offsetTop;
}
}; };
HistoryWidget.prototype._onClickHistoryEntry = function(evt, entry, lastDoneID) { HistoryWidget.prototype._onClickHistoryEntry = function(evt, entry, lastDoneID) {

View File

@ -19,6 +19,10 @@ ListFacet.prototype.getJSON = function() {
return o; return o;
}; };
ListFacet.prototype.hasSelection = function() {
return this._selection.length > 0;
};
ListFacet.prototype.updateState = function(data) { ListFacet.prototype.updateState = function(data) {
this._data = data; this._data = data;
@ -48,6 +52,10 @@ ListFacet.prototype.render = function() {
var headerDiv = $('<div></div>').addClass("facet-title").appendTo(container); var headerDiv = $('<div></div>').addClass("facet-title").appendTo(container);
$('<span></span>').text(this._config.name).appendTo(headerDiv); $('<span></span>').text(this._config.name).appendTo(headerDiv);
var removeButton = $('<a href="javascript:{}"></a>').addClass("facet-choice-link").text("remove").click(function() {
self._remove();
}).prependTo(headerDiv);
var bodyDiv = $('<div></div>').addClass("facet-body").appendTo(container); var bodyDiv = $('<div></div>').addClass("facet-body").appendTo(container);
if (this._data == null) { if (this._data == null) {
bodyDiv.html("Loading..."); bodyDiv.html("Loading...");
@ -57,7 +65,9 @@ ListFacet.prototype.render = function() {
var reset = function() { var reset = function() {
self._reset(); self._reset();
}; };
$('<a href="javascript:{}"></a>').addClass("facet-choice-link").text("reset").click(reset).prependTo(headerDiv); removeButton.after(
$('<a href="javascript:{}"></a>').addClass("facet-choice-link").text("reset").click(reset)
);
} }
var renderChoice = function(choice) { var renderChoice = function(choice) {
@ -136,6 +146,15 @@ ListFacet.prototype._reset = function() {
this._updateRest(); this._updateRest();
}; };
ListFacet.prototype._remove = function() {
ui.browsingEngine.removeFacet(this);
this._div = null;
this._config = null;
this._selection = null;
this._data = null;
};
ListFacet.prototype._updateRest = function() { ListFacet.prototype._updateRest = function() {
ui.browsingEngine.update(); ui.browsingEngine.update();
ui.dataTableView.update(true); ui.dataTableView.update(true);

View File

@ -48,6 +48,7 @@ a.facet-choice-label:hover {
} }
a.facet-choice-link { a.facet-choice-link {
margin-left: 1em;
font-size: 80%; font-size: 80%;
float: right; float: right;
text-decoration: none; text-decoration: none;

View File

@ -3,18 +3,26 @@
top: -1px; top: -1px;
right: 20px; right: 20px;
width: 200px; width: 200px;
padding: 2px;
background: #fffee0; background: #fffee0;
border: 1px solid #ccc; border: 1px solid #ccc;
height: 100px;
overflow: auto;
} }
.history-panel h3 { .history-panel h3 {
margin: 0; margin: 0;
padding: 3px; padding: 3px;
background: #fee; background: #888;
color: #eee;
font-size: 100%; font-size: 100%;
} }
.history-panel-body {
padding: 2px;
height: 50px;
overflow: auto;
}
.history-panel-message {
text-align: center;
color: #aaa;
}
.history-past { .history-past {
padding-bottom: 3px; padding-bottom: 3px;
border-bottom: 2px solid #aaa; border-bottom: 2px solid #aaa;
@ -33,3 +41,8 @@ a.history-entry:hover {
background: #eee; background: #eee;
color: #a88; color: #a88;
} }
.history-future a.history-entry {
color: #888;
font-style: italic;
}