From baa4e0db8c03afb97590985f8b77db219d181d14 Mon Sep 17 00:00:00 2001 From: David Huynh Date: Tue, 24 Aug 2010 06:06:07 +0000 Subject: [PATCH] Added command to browse to the data load page on the Gridworks QA dashboard. Save the data load job name and fill it in the next time the Load into Freebase dialog is opened. git-svn-id: http://google-refine.googlecode.com/svn/trunk@1220 7d457c2a-affb-35e4-300a-418c747d4874 --- .../commands/freebase/UploadDataCommand.java | 10 ++++-- .../dialogs/freebase-loading-dialog.js | 14 ++++++-- .../modules/core/scripts/project/menu-bar.js | 34 +++++++++++++++++++ 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/main/src/com/google/gridworks/commands/freebase/UploadDataCommand.java b/main/src/com/google/gridworks/commands/freebase/UploadDataCommand.java index 22958f33b..a90440468 100644 --- a/main/src/com/google/gridworks/commands/freebase/UploadDataCommand.java +++ b/main/src/com/google/gridworks/commands/freebase/UploadDataCommand.java @@ -17,11 +17,13 @@ import com.google.gridworks.browsing.Engine; import com.google.gridworks.commands.Command; import com.google.gridworks.exporters.ProtographTransposeExporter.TripleLoaderExporter; import com.google.gridworks.model.Project; +import com.google.gridworks.preference.PreferenceStore; import com.google.gridworks.util.FreebaseUtils; import com.google.gridworks.util.ParsingUtilities; public class UploadDataCommand extends Command { - final static public String s_dataLoadJobIDPref = "core/freebaseDataLoadJobID"; + final static public String s_dataLoadJobIDPref = "freebase.load.jobID"; + final static public String s_dataLoadJobNamePref = "freebase.load.jobName"; @Override public void doPost(HttpServletRequest request, HttpServletResponse response) @@ -31,6 +33,8 @@ public class UploadDataCommand extends Command { try { Project project = getProject(request); Engine engine = getEngine(request, project); + PreferenceStore preferenceStore = project.getMetadata().getPreferenceStore(); + TripleLoaderExporter exporter = new TripleLoaderExporter(); StringWriter triples = new StringWriter(10 * 1024 * 1024); exporter.export(project, new Properties(), engine, triples); @@ -40,8 +44,10 @@ public class UploadDataCommand extends Command { String graph = request.getParameter("graph"); String mdo_id = null; + preferenceStore.put(s_dataLoadJobNamePref, source_name); + try { - Integer jobID = (Integer) project.getMetadata().getPreferenceStore().get(s_dataLoadJobIDPref); + Integer jobID = (Integer) preferenceStore.get(s_dataLoadJobIDPref); if (jobID != null) { URL url = new URL("http://gridworks-loads.freebaseapps.com/job_id_to_mdo?job=" + jobID); String s = ParsingUtilities.inputStreamToString(url.openConnection().getInputStream()); diff --git a/main/webapp/modules/core/scripts/dialogs/freebase-loading-dialog.js b/main/webapp/modules/core/scripts/dialogs/freebase-loading-dialog.js index 199ccb40a..3f9275370 100644 --- a/main/webapp/modules/core/scripts/dialogs/freebase-loading-dialog.js +++ b/main/webapp/modules/core/scripts/dialogs/freebase-loading-dialog.js @@ -9,7 +9,7 @@ FreebaseLoadingDialog.prototype._createDialog = function() { this._elmts = DOM.bind(dialog); this._elmts.cancelButton.click(function() { self._dismiss(); }); this._elmts.selector.buttonset(); - + var provider = "www.freebase.com"; var authorization = this._elmts.authorization; var loadButton = this._elmts.loadButton; @@ -126,6 +126,16 @@ FreebaseLoadingDialog.prototype._createDialog = function() { make_topic(val, "/dataworld/information_source"); }); + $.getJSON( + "/command/core/get-preference?" + $.param({ project: theProject.id, name: "freebase.load.jobName" }), + null, + function(data) { + if (data.value != null) { + self._elmts.source_name[0].value = data.value; + } + } + ); + if (typeof cont == "function") cont(); } else { body.html( @@ -159,7 +169,7 @@ FreebaseLoadingDialog.prototype._load = function() { var freebase = self._elmts.freebase.attr("checked"); var get_peacock_url = function(url) { - return "http://gridworks-loads.freebaseapps.com/job/" + url.split("/").slice(-1)[0]; + return "http://gridworks-loads.freebaseapps.com/load/" + url.split("/").slice(-1)[0]; }; var doLoad = function() { diff --git a/main/webapp/modules/core/scripts/project/menu-bar.js b/main/webapp/modules/core/scripts/project/menu-bar.js index 97ee4dee1..d86ef87c6 100644 --- a/main/webapp/modules/core/scripts/project/menu-bar.js +++ b/main/webapp/modules/core/scripts/project/menu-bar.js @@ -101,6 +101,11 @@ MenuBar.MenuItems = [ label: "Load into Freebase ...", click: function() { MenuBar.handlers.loadIntoFreebase(); } }, + { + "id" : "core/browse-load", + label: "Browse to Data Load ...", + click: function() { MenuBar.handlers.browseToDataLoad(); } + }, { "id" : "core/import-qa-data", label: "Import QA Data", @@ -326,6 +331,35 @@ MenuBar.handlers.loadIntoFreebase = function() { new FreebaseLoadingDialog(); }; +MenuBar.handlers.browseToDataLoad = function() { + // The form has to be created as part of the click handler. If you create it + // inside the getJSON success handler, it won't work. + + var form = document.createElement("form"); + $(form) + .css("display", "none") + .attr("method", "GET") + .attr("target", "dataload"); + + document.body.appendChild(form); + var w = window.open("about:blank", "dataload"); + + $.getJSON( + "/command/core/get-preference?" + $.param({ project: theProject.id, name: "freebase.load.jobID" }), + null, + function(data) { + if (data.value == null) { + alert("You have not tried to load the data in this project into Freebase yet."); + } else { + $(form).attr("action", "http://gridworks-loads.freebaseapps.com/load/" + data.value); + form.submit(); + w.focus(); + } + document.body.removeChild(form); + } + ); +}; + MenuBar.handlers.importQAData = function() { Gridworks.postCoreProcess( "import-qa-data",