Made recon process cause the client page to create facets when the recon process is done.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@203 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-03-05 01:13:59 +00:00
parent 32c0bf08c9
commit 1d6db8fa6e
5 changed files with 111 additions and 29 deletions

View File

@ -98,10 +98,10 @@ public class ReconOperation extends EngineDependentOperation {
}
public class ReconProcess extends LongRunningProcess implements Runnable {
final protected Project _project;
final protected JSONObject _engineConfig;
protected List<ReconEntry> _entries;
protected int _cellIndex;
final protected Project _project;
final protected JSONObject _engineConfig;
protected List<ReconEntry> _entries;
protected int _cellIndex;
public ReconProcess(
Project project,
@ -113,6 +113,46 @@ public class ReconOperation extends EngineDependentOperation {
_engineConfig = engineConfig;
}
public void write(JSONWriter writer, Properties options)
throws JSONException {
writer.object();
writer.key("id"); writer.value(hashCode());
writer.key("description"); writer.value(_description);
writer.key("immediate"); writer.value(false);
writer.key("status"); writer.value(_thread == null ? "pending" : (_thread.isAlive() ? "running" : "done"));
writer.key("progress"); writer.value(_progress);
writer.key("onDone");
writer.array();
writer.object();
writer.key("action"); writer.value("createFacet");
writer.key("facetType"); writer.value("list");
writer.key("facetConfig");
writer.object();
writer.key("name"); writer.value(_columnName + ": judgment");
writer.key("columnName"); writer.value(_columnName);
writer.key("expression"); writer.value("cell.recon.judgment");
writer.endObject();
writer.key("facetOptions");
writer.object();
writer.key("scroll"); writer.value(false);
writer.endObject();
writer.endObject();
writer.object();
writer.key("action"); writer.value("createFacet");
writer.key("facetType"); writer.value("range");
writer.key("facetConfig");
writer.object();
writer.key("name"); writer.value(_columnName + ": best candidate's score");
writer.key("columnName"); writer.value(_columnName);
writer.key("expression"); writer.value("cell.recon.best.score");
writer.key("mode"); writer.value("range");
writer.endObject();
writer.endObject();
writer.endArray();
writer.endObject();
}
protected Runnable getRunnable() {
return this;
}

View File

@ -6,7 +6,7 @@ import org.json.JSONException;
import org.json.JSONWriter;
abstract public class LongRunningProcess extends Process {
final protected String _description;
final protected String _description;
protected ProcessManager _manager;
protected Thread _thread;
protected int _progress; // out of 100
@ -27,6 +27,7 @@ abstract public class LongRunningProcess extends Process {
throws JSONException {
writer.object();
writer.key("id"); writer.value(hashCode());
writer.key("description"); writer.value(_description);
writer.key("immediate"); writer.value(false);
writer.key("status"); writer.value(_thread == null ? "pending" : (_thread.isAlive() ? "running" : "done"));

View File

@ -47,6 +47,7 @@ abstract public class QuickHistoryEntryProcess extends Process {
throws JSONException {
writer.object();
writer.key("id"); writer.value(hashCode());
writer.key("description"); writer.value(_historyEntry != null ? _historyEntry.description : _briefDescription);
writer.key("immediate"); writer.value(true);
writer.key("status"); writer.value(_done ? "done" : "pending");

View File

@ -27,27 +27,31 @@ ProcessWidget.prototype.update = function(updateOptions, onDone) {
Ajax.chainGetJSON(
"/command/get-processes?" + $.param({ project: theProject.id }), null,
function(data) {
self._data = data;
self._render();
self._render(data);
}
);
};
ProcessWidget.prototype._cancelAll = function() {
var self = this;
$.post(
"/command/cancel-processes?" + $.param({ project: theProject.id }),
null,
function(o) {},
function(o) {
self._data = null;
self._runOnDones();
},
"json"
);
};
ProcessWidget.prototype._render = function() {
ProcessWidget.prototype._render = function(newData) {
var self = this;
var newProcessMap = {};
this._div.empty();
if (this._data.processes.length == 0) {
if (newData.processes.length == 0) {
this._div.hide();
} else {
this._div.show();
@ -64,6 +68,7 @@ ProcessWidget.prototype._render = function() {
.text("cancel all")
.click(function() {
self._cancelAll();
$(this).text("canceling all processes...").unbind();
})
.appendTo(headDiv);
@ -79,33 +84,68 @@ ProcessWidget.prototype._render = function() {
}
};
var processes = this._data.processes;
var processes = newData.processes;
for (var i = 0; i < processes.length; i++) {
renderProcess(processes[i]);
var process = processes[i];
renderProcess(process);
if ("onDone" in process) {
newProcessMap[process.id] = process;
}
}
}
if ((this._data) && this._data.processes.length > 0) {
var oldProcesses = this._data.processes;
for (var i = 0; i < oldProcesses.length; i++) {
var process = oldProcesses[i];
if ("onDone" in process && !(process.id in newProcessMap)) {
this._perform(process.onDone);
}
}
}
this._data = newData;
if (this._data.processes.length > 0 && this._timerID == null) {
this._timerID = window.setTimeout(function() {
self._timerID = null;
self.update();
}, 500);
} else {
var updateOptions = this._updateOptions;
var onDones = this._onDones;
this._updateOptions = {};
this._onDones = [];
Gridworks.update(updateOptions, function() {
for (var i = 0; i < onDones.length; i++) {
try {
onDones[i]();
} catch (e) {
Gridworks.reportException(e);
}
}
});
this._runOnDones();
}
};
ProcessWidget.prototype._perform = function(jobs) {
for (var i = 0; i < jobs.length; i++) {
var job = jobs[i];
if (job.action == "createFacet") {
try {
ui.browsingEngine.addFacet(
job.facetType,
job.facetConfig,
job.facetOptions
);
} catch (e) {
//
}
}
}
};
ProcessWidget.prototype._runOnDones = function() {
var updateOptions = this._updateOptions;
var onDones = this._onDones;
this._updateOptions = {};
this._onDones = [];
Gridworks.update(updateOptions, function() {
for (var i = 0; i < onDones.length; i++) {
try {
onDones[i]();
} catch (e) {
Gridworks.reportException(e);
}
}
});
};

View File

@ -311,7 +311,7 @@ DataTableColumnHeaderUI.prototype._createMenuForColumnHeader = function(elmt) {
ui.browsingEngine.addFacet(
"range",
{
"name" : self._column.headerLabel + ": best candidate's relevance score",
"name" : self._column.headerLabel + ": best candidate's score",
"columnName" : self._column.headerLabel,
"expression" : "cell.recon.best.score",
"mode" : "range"