Expose Wikibase schema exporter in UI, for #1776

This commit is contained in:
Antonin Delpeuch 2018-10-28 15:19:48 +01:00
parent e85f7d36e0
commit 7c26021b61
4 changed files with 36 additions and 11 deletions

View File

@ -36,8 +36,10 @@ function init() {
*/
var ExporterRegistry = Packages.com.google.refine.exporters.ExporterRegistry;
var QSExporter = Packages.org.openrefine.wikidata.exporters.QuickStatementsExporter;
var SchemaExporter = Packages.org.openrefine.wikidata.exporters.SchemaExporter;
ExporterRegistry.registerExporter("quickstatements", new QSExporter());
ExporterRegistry.registerExporter("wikibase-schema", new SchemaExporter());
/*
* Commands

View File

@ -5,6 +5,7 @@
"manage-wikidata-account": "Manage Wikidata account",
"perform-edits-on-wikidata": "Upload edits to Wikidata",
"export-to-qs": "Export to QuickStatements",
"export-schema": "Export schema",
"quickstatements-export-name": "QuickStatements"
},
"wikidata-schema": {

View File

@ -19,19 +19,37 @@ $.i18n.setDictionary(dictionary);
ExporterManager.MenuItems.push({});
ExporterManager.MenuItems.push(
{
"id" : "exportQuickStatements",
"label": $.i18n._('wikidata-extension')["quickstatements-export-name"],
"click": function() { WikibaseSchemaExporterMenuBar.checkSchemaAndExport(); }
id:"performWikibaseEdits",
label: $.i18n._('wikidata-extension')["perform-edits-on-wikidata"],
click: function() { PerformEditsDialog.checkAndLaunch(); }
});
ExporterManager.MenuItems.push(
{
id:"exportQuickStatements",
label: $.i18n._('wikidata-extension')["export-to-qs"],
click: function() { WikibaseExporterMenuBar.checkSchemaAndExport("quickstatements"); }
});
ExporterManager.MenuItems.push(
{
id:"exportWikibaseSchema",
label: $.i18n._('wikidata-extension')["export-schema"],
click: function() { WikibaseExporterMenuBar.checkSchemaAndExport("wikibase-schema"); }
}
);
WikibaseExporterMenuBar = {};
WikibaseExporterMenuBar.exportTo = function(format) {
var targetUrl = null;
if (format ==="quickstatements") {
targetUrl = "statements.txt";
} else {
targetUrl = "schema.json";
}
var form = document.createElement("form");
$(form).css("display", "none")
.attr("method", "post")
.attr("action", "command/core/export-rows/statements.txt")
.attr("action", "command/core/export-rows/"+targetUrl)
.attr("target", "gridworks-export");
$('<input />')
.attr("name", "engine")
@ -54,9 +72,9 @@ WikibaseExporterMenuBar.exportTo = function(format) {
document.body.removeChild(form);
};
WikibaseExporterMenuBar.checkSchemaAndExport = function() {
WikibaseExporterMenuBar.checkSchemaAndExport = function(format) {
var onSaved = function(callback) {
WikibaseExporterMenuBar.exportTo("quickstatements");
WikibaseExporterMenuBar.exportTo(format);
};
if (!SchemaAlignmentDialog.isSetUp()) {
SchemaAlignmentDialog.launch(null);
@ -85,6 +103,7 @@ $(function(){
label: $.i18n._('wikidata-extension')["manage-wikidata-account"],
click: function() { ManageAccountDialog.checkAndLaunch(); }
},
{},
{
id:"wikidata/perform-edits",
label: $.i18n._('wikidata-extension')["perform-edits-on-wikidata"],
@ -93,7 +112,12 @@ $(function(){
{
id:"wikidata/export-qs",
label: $.i18n._('wikidata-extension')["export-to-qs"],
click: function() { WikibaseExporterMenuBar.checkSchemaAndExport(); }
click: function() { WikibaseExporterMenuBar.checkSchemaAndExport("quickstatements"); }
},
{
id:"wikidata/export-schema",
label: $.i18n._('wikidata-extension')["export-schema"],
click: function() { WikibaseExporterMenuBar.checkSchemaAndExport("wikibase-schema"); }
},
]

View File

@ -24,6 +24,8 @@
package org.openrefine.wikidata.commands;
import static org.openrefine.wikidata.commands.CommandUtilities.respondError;
import java.io.IOException;
import java.io.StringWriter;
import java.util.List;
@ -36,7 +38,6 @@ import javax.servlet.http.HttpServletResponse;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter;
import org.openrefine.wikidata.qa.EditInspector;
import org.openrefine.wikidata.qa.QAWarning;
@ -45,10 +46,7 @@ import org.openrefine.wikidata.schema.WikibaseSchema;
import org.openrefine.wikidata.updates.ItemUpdate;
import org.openrefine.wikidata.updates.scheduler.WikibaseAPIUpdateScheduler;
import static org.openrefine.wikidata.commands.CommandUtilities.respondError;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.refine.browsing.Engine;
import com.google.refine.commands.Command;
import com.google.refine.model.Project;