From 97e16d6e8e20fc7582c4c9ebf8f6a1aac33f6b46 Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Sat, 28 Apr 2018 11:25:49 +0200 Subject: [PATCH] Add number of edits in preview and upload dialog --- .../wikidata/module/langs/translation-en.json | 2 +- .../scripts/dialogs/perform-edits-dialog.js | 56 +++++++++++-------- .../dialogs/schema-alignment-dialog.js | 9 ++- .../dialogs/schema-alignment-dialog.css | 3 +- .../PreviewWikibaseSchemaCommand.java | 8 ++- 5 files changed, 50 insertions(+), 28 deletions(-) diff --git a/extensions/wikidata/module/langs/translation-en.json b/extensions/wikidata/module/langs/translation-en.json index 3fb67051a..9806d62b4 100644 --- a/extensions/wikidata/module/langs/translation-en.json +++ b/extensions/wikidata/module/langs/translation-en.json @@ -71,7 +71,7 @@ }, "perform-wikidata-edits": { "dialog-header": "Upload edits to Wikidata", - "review-your-edits": "Please check your edits carefully before pushing them to Wikidata. Large edit batches should be submitted for bot review first.", + "review-your-edits": "You are about to upload {nb_edits} edits to Wikidata. Please check them carefully. Large edit batches should be submitted for bot review first.", "logged-in-as": "You are logged in as", "edit-summary-label": "Edit summary:", "edit-summary-placeholder": "a few words to describe your edits", diff --git a/extensions/wikidata/module/scripts/dialogs/perform-edits-dialog.js b/extensions/wikidata/module/scripts/dialogs/perform-edits-dialog.js index 4b1aa03fe..64bc16a5f 100644 --- a/extensions/wikidata/module/scripts/dialogs/perform-edits-dialog.js +++ b/extensions/wikidata/module/scripts/dialogs/perform-edits-dialog.js @@ -12,7 +12,6 @@ PerformEditsDialog.launch = function(logged_in_username, max_severity) { this._level = DialogSystem.showDialog(frame); this._elmts.dialogHeader.text($.i18n._('perform-wikidata-edits')["dialog-header"]); - this._elmts.reviewYourEdits.html($.i18n._('perform-wikidata-edits')["review-your-edits"]); this._elmts.loggedInAs.text($.i18n._('perform-wikidata-edits')["logged-in-as"]); this._elmts.editSummaryLabel.text($.i18n._('perform-wikidata-edits')["edit-summary-label"]); this._elmts.editSummary.attr('placeholder', $.i18n._('perform-wikidata-edits')["edit-summary-placeholder"]); @@ -56,12 +55,19 @@ PerformEditsDialog.launch = function(logged_in_username, max_severity) { } }; +PerformEditsDialog.updateEditCount = function(edit_count) { + this._elmts.reviewYourEdits.html( + $.i18n._('perform-wikidata-edits')["review-your-edits"] + .replace('{nb_edits}', edit_count)); +} + PerformEditsDialog._updateWarnings = function(data) { var warnings = data.warnings; var mainDiv = this._elmts.warningsArea; // clear everything mainDiv.empty(); + PerformEditsDialog.updateEditCount(data.edit_count); var table = $('
').appendTo(mainDiv); for (var i = 0; i != warnings.length; i++) { @@ -76,28 +82,34 @@ PerformEditsDialog.checkAndLaunch = function () { this._elmts = DOM.bind(this.frame); this.missingSchema = false; + var onSaved = function() { + ManageAccountDialog.ensureLoggedIn(function(logged_in_username) { + if (logged_in_username) { + var discardWaiter = DialogSystem.showBusy($.i18n._('perform-wikidata-edits')["analyzing-edits"]); + $.post( + "command/wikidata/preview-wikibase-schema?" + $.param({ project: theProject.id }), + { engine: JSON.stringify(ui.browsingEngine.getJSON()) }, + function(data) { + discardWaiter(); + if(data['code'] != 'error') { + PerformEditsDialog._updateWarnings(data); + PerformEditsDialog.launch(logged_in_username, data['max_severity']); + } else { + SchemaAlignmentDialog.launch( + PerformEditsDialog.checkAndLaunch); + } + }, + "json" + ); + } + }); + }; + + if (SchemaAlignmentDialog.isSetUp() && SchemaAlignmentDialog._hasUnsavedChanges) { - SchemaAlignmentDialog._save(); + SchemaAlignmentDialog._save(onSaved); + } else { + onSaved(); } - ManageAccountDialog.ensureLoggedIn(function(logged_in_username) { - if (logged_in_username) { - var discardWaiter = DialogSystem.showBusy($.i18n._('perform-wikidata-edits')["analyzing-edits"]); - $.post( - "command/wikidata/preview-wikibase-schema?" + $.param({ project: theProject.id }), - { engine: JSON.stringify(ui.browsingEngine.getJSON()) }, - function(data) { - discardWaiter(); - if(data['code'] != 'error') { - PerformEditsDialog._updateWarnings(data); - PerformEditsDialog.launch(logged_in_username, data['max_severity']); - } else { - SchemaAlignmentDialog.launch( - PerformEditsDialog.checkAndLaunch); - } - }, - "json" - ); - } - }); }; diff --git a/extensions/wikidata/module/scripts/dialogs/schema-alignment-dialog.js b/extensions/wikidata/module/scripts/dialogs/schema-alignment-dialog.js index bf5f895bb..7a33ced1d 100644 --- a/extensions/wikidata/module/scripts/dialogs/schema-alignment-dialog.js +++ b/extensions/wikidata/module/scripts/dialogs/schema-alignment-dialog.js @@ -148,7 +148,7 @@ SchemaAlignmentDialog.setUpTabs = function() { */ var previewTab = $(DOM.loadHTML("wikidata", "scripts/preview-tab.html")).appendTo(this._previewPanel); var previewElmts = this._previewElmts = DOM.bind(previewTab); - previewElmts.previewExplanation.text($.i18n._('wikidata-schema')["preview-explanation"]); + SchemaAlignmentDialog.updateNbEdits(0); previewElmts.invalidSchemaWarningPreview.text($.i18n._('wikidata-schema')["invalid-schema-warning-preview"]); this._previewPanes = $(".schema-alignment-dialog-preview"); @@ -1110,11 +1110,17 @@ SchemaAlignmentDialog._hasChanged = function() { .removeClass('disabled'); } +SchemaAlignmentDialog.updateNbEdits = function(nb_edits) { + this._previewElmts.previewExplanation.text( + $.i18n._('wikidata-schema')["preview-explanation"].replace('{nb_edits}',nb_edits)); +} + SchemaAlignmentDialog.preview = function() { var self = this; $('.invalid-schema-warning').hide(); this._previewPanes.empty(); + this.updateNbEdits(0); this.issueSpinner.show(); this.previewSpinner.show(); var schema = this.getJSON(); @@ -1127,6 +1133,7 @@ SchemaAlignmentDialog.preview = function() { if ("edits_preview" in data) { var previewContainer = self._previewPanes[0]; EditRenderer.renderEdits(data.edits_preview, previewContainer); + self.updateNbEdits(data["edit_count"]); } if (data.warnings) { diff --git a/extensions/wikidata/module/styles/dialogs/schema-alignment-dialog.css b/extensions/wikidata/module/styles/dialogs/schema-alignment-dialog.css index 74bd4e65f..03561fede 100644 --- a/extensions/wikidata/module/styles/dialogs/schema-alignment-dialog.css +++ b/extensions/wikidata/module/styles/dialogs/schema-alignment-dialog.css @@ -486,7 +486,8 @@ div.perform-edits-warnings-area { min-height: 340px; max-height: 400px; overflow-x: hidden; - overflow-y: scroll; + overflow-y: auto; + border: 1px solid #bbb; } .wb-issue-preformat { diff --git a/extensions/wikidata/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommand.java b/extensions/wikidata/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommand.java index 53766d3d6..28ed72400 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommand.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommand.java @@ -94,8 +94,6 @@ public class PreviewWikibaseSchemaCommand extends Command { writer.object(); { - StringWriter stringWriter = new StringWriter(); - // Inspect the edits and generate warnings EditInspector inspector = new EditInspector(warningStore); inspector.inspect(editBatch); @@ -117,8 +115,12 @@ public class PreviewWikibaseSchemaCommand extends Command { // Dump the first 10 edits, scheduled with the default scheduler WikibaseAPIUpdateScheduler scheduler = new WikibaseAPIUpdateScheduler(); - List firstEdits = scheduler.schedule(editBatch).stream() + List nonNullEdits = scheduler.schedule(editBatch).stream() .filter(e -> !e.isNull()) + .collect(Collectors.toList()); + writer.key("edit_count"); + writer.value(nonNullEdits.size()); + List firstEdits = nonNullEdits.stream() .limit(10) .collect(Collectors.toList()); ObjectMapper mapper = new ObjectMapper();