Add importer UI for Wikibase schema

This commit is contained in:
Antonin Delpeuch 2018-11-01 15:01:08 +00:00
parent 7c26021b61
commit 825c4ad213
6 changed files with 91 additions and 0 deletions

View File

@ -64,6 +64,7 @@ function init() {
"scripts/dialogs/schema-alignment-dialog.js", "scripts/dialogs/schema-alignment-dialog.js",
"scripts/dialogs/manage-account-dialog.js", "scripts/dialogs/manage-account-dialog.js",
"scripts/dialogs/perform-edits-dialog.js", "scripts/dialogs/perform-edits-dialog.js",
"scripts/dialogs/import-schema-dialog.js",
"scripts/jquery.uls.data.js", "scripts/jquery.uls.data.js",
]); ]);
@ -73,6 +74,7 @@ function init() {
[ [
"styles/dialogs/schema-alignment-dialog.css", "styles/dialogs/schema-alignment-dialog.css",
"styles/dialogs/manage-account-dialog.less", "styles/dialogs/manage-account-dialog.less",
"styles/dialogs/import-schema-dialog.less",
"styles/dialogs/perform-edits.less", "styles/dialogs/perform-edits.less",
]); ]);

View File

@ -2,6 +2,7 @@
"wikidata-extension": { "wikidata-extension": {
"menu-label": "Wikidata", "menu-label": "Wikidata",
"edit-wikidata-schema": "Edit Wikidata schema", "edit-wikidata-schema": "Edit Wikidata schema",
"import-wikidata-schema": "Import Wikidata schema",
"manage-wikidata-account": "Manage Wikidata account", "manage-wikidata-account": "Manage Wikidata account",
"perform-edits-on-wikidata": "Upload edits to Wikidata", "perform-edits-on-wikidata": "Upload edits to Wikidata",
"export-to-qs": "Export to QuickStatements", "export-to-qs": "Export to QuickStatements",
@ -80,6 +81,13 @@
"cancel": "Cancel", "cancel": "Cancel",
"analyzing-edits": "Analyzing your edits..." "analyzing-edits": "Analyzing your edits..."
}, },
"import-wikibase-schema": {
"dialog-header": "Import Wikidata schema",
"file-label": "From JSON file: ",
"schema-label": "Or from JSON text:",
"invalid-schema": "Invalid Wikibase schema.",
"import": "Import"
},
"warnings-messages": { "warnings-messages": {
"new-item-created": { "new-item-created": {
"title": "This edit batch will create new Wikidata items.", "title": "This edit batch will create new Wikidata items.",

View File

@ -0,0 +1,13 @@
<div class="dialog-frame" style="width: 800px;">
<div class="dialog-header" bind="dialogHeader"></div>
<div class="dialog-body" bind="dialogBody">
<label for="schema-file" bind="fileLabel"></label><input type="file" name="schema-file" /><br />
<label for="schema" bind="schemaLabel"></label><br />
<textarea name="schema" class="wikibase-schema-textarea" bind="schemaTextarea"></textarea><br />
<div class="wikibase-invalid-schema" bind="invalidSchema"></div>
<div class="wikibase-login-buttons">
<button class="button cancel-button" bind="cancelButton"></button>
<button class="button button-primary" bind="importButton"></button>
</div>
</div>
</div>

View File

@ -0,0 +1,53 @@
var ImportSchemaDialog = {};
ImportSchemaDialog.launch = function() {
var self = this;
var frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/import-schema-dialog.html"));
var elmts = this._elmts = DOM.bind(frame);
this._elmts.dialogHeader.text($.i18n._('import-wikibase-schema')["dialog-header"]);
this._elmts.fileLabel.html($.i18n._('import-wikibase-schema')["file-label"]);
this._elmts.schemaLabel.text($.i18n._('import-wikibase-schema')["schema-label"]);
this._elmts.cancelButton.text($.i18n._('core-project')["cancel"]);
this._elmts.importButton.text($.i18n._('import-wikibase-schema')["import"]);
this._level = DialogSystem.showDialog(frame);
var dismiss = function() {
DialogSystem.dismissUntil(self._level - 1);
};
frame.find('.cancel-button').click(function() {
dismiss();
});
elmts.importButton.click(function() {
var schema = null;
try {
schema = JSON.parse(elmts.schemaTextarea.val());
} catch(e) {
elmts.invalidSchema.text($.i18n._('import-wikibase-schema')["invalid-schema"]);
return;
}
Refine.postProcess(
"wikidata",
"save-wikibase-schema",
{},
{ schema: JSON.stringify(schema) },
{},
{
onDone: function() {
theProject.overlayModels.wikibaseSchema = schema;
SchemaAlignmentDialog._discardChanges();
dismiss();
},
onError: function(e) {
elmts.invalidSchema.text($.i18n._('import-wikibase-schema')["invalid-schema"]);
},
}
);
});
};

View File

@ -98,6 +98,11 @@ $(function(){
label: $.i18n._('wikidata-extension')["edit-wikidata-schema"], label: $.i18n._('wikidata-extension')["edit-wikidata-schema"],
click: function() { SchemaAlignmentDialog.launch(false); } click: function() { SchemaAlignmentDialog.launch(false); }
}, },
{
id: "wikidata/import-schema",
label: $.i18n._('wikidata-extension')["import-wikidata-schema"],
click: function() { ImportSchemaDialog.launch(); }
},
{ {
id:"wikidata/manage-account", id:"wikidata/manage-account",
label: $.i18n._('wikidata-extension')["manage-wikidata-account"], label: $.i18n._('wikidata-extension')["manage-wikidata-account"],

View File

@ -0,0 +1,10 @@
@import-less url("../theme.less");
.wikibase-invalid-schema {
color: red;
}
.wikibase-schema-textarea {
width: 100%;
height: 100px;