Add number of edits in preview and upload dialog

This commit is contained in:
Antonin Delpeuch 2018-04-28 11:25:49 +02:00
parent f9a1a5ba18
commit 97e16d6e8e
5 changed files with 50 additions and 28 deletions

View File

@ -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 <a href=\"https://www.wikidata.org/wiki/Wikidata:Requests_for_permissions/Bot\" target=\"_blank\">bot review</a> 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 <a href=\"https://www.wikidata.org/wiki/Wikidata:Requests_for_permissions/Bot\" target=\"_blank\">bot review</a> first.",
"logged-in-as": "You are logged in as",
"edit-summary-label": "Edit summary:",
"edit-summary-placeholder": "a few words to describe your edits",

View File

@ -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 = $('<table></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"
);
}
});
};

View File

@ -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) {

View File

@ -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 {

View File

@ -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<ItemUpdate> firstEdits = scheduler.schedule(editBatch).stream()
List<ItemUpdate> nonNullEdits = scheduler.schedule(editBatch).stream()
.filter(e -> !e.isNull())
.collect(Collectors.toList());
writer.key("edit_count");
writer.value(nonNullEdits.size());
List<ItemUpdate> firstEdits = nonNullEdits.stream()
.limit(10)
.collect(Collectors.toList());
ObjectMapper mapper = new ObjectMapper();