Display issues in perform edits dialog

This commit is contained in:
Antonin Delpeuch 2018-02-22 18:15:05 +00:00
parent 1c51b32458
commit 9513807a83
9 changed files with 256 additions and 158 deletions

View File

@ -6,9 +6,11 @@
Consider requesting feedback at the <a href="https://www.wikidata.org/wiki/Wikidata:Data_Import_Hub">Data Import Hub</a>
for large datasets.
</p>
<div class="perform-edits-warnings-area" bind="warningsArea">
</div>
<div class="wikibase-perform-edits-area">
<p>You are logged in as <span bind="loggedInUsername"></span>.</p>
<p>Edit summary: <input type="text" name="editSummary" bind="editSummary" value="#openrefine" /></p>
<p>Edit summary: <input type="text" name="editSummary" bind="editSummary" class="edit-summary" value="" /></p>
<div class="wikibase-login-buttons">
<button class="button cancel-button" bind="cancelButton">Cancel</button>
<button class="button button-primary" bind="performEditsButton">Perform edits</button>

View File

@ -2,8 +2,13 @@ var PerformEditsDialog = {};
PerformEditsDialog.launch = function(logged_in_username) {
var self = this;
var frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/perform-edits-dialog.html"));
var elmts = this._elmts = DOM.bind(frame);
var elmts = this._elmts;
var frame = this.frame;
console.log(this.missingSchema);
if (this.missingSchema) {
return;
}
this._level = DialogSystem.showDialog(frame);
@ -35,10 +40,42 @@ PerformEditsDialog.launch = function(logged_in_username) {
});
};
PerformEditsDialog._updateWarnings = function(data) {
var warnings = data.warnings;
var mainDiv = this._elmts.warningsArea;
// clear everything
mainDiv.empty();
var table = $('<table></table>').appendTo(mainDiv);
for (var i = 0; i != warnings.length; i++) {
var rendered = WarningsRenderer._renderWarning(warnings[i]);
rendered.appendTo(table);
}
}
PerformEditsDialog.checkAndLaunch = function () {
var self = this;
this.frame = $(DOM.loadHTML("wikidata", "scripts/dialogs/perform-edits-dialog.html"));
this._elmts = DOM.bind(this.frame);
this.missingSchema = false;
ManageAccountDialog.ensureLoggedIn(function(logged_in_username) {
if (logged_in_username) {
$.post(
"command/wikidata/preview-wikibase-schema?" + $.param({ project: theProject.id }),
{ engine: JSON.stringify(ui.browsingEngine.getJSON()) },
function(data) {
if(data['status'] != 'error') {
PerformEditsDialog._updateWarnings(data);
PerformEditsDialog.launch(logged_in_username);
} else {
SchemaAlignmentDialog.launch(
PerformEditsDialog.checkAndLaunch);
}
},
"json"
);
}
});
};

View File

@ -816,77 +816,6 @@ SchemaAlignmentDialog.preview = function(initial) {
* WARNINGS RENDERING *
*************************/
// renders a Wikibase entity into a link
SchemaAlignmentDialog._renderEntity = function(entity) {
if (!entity.id && entity.value) {
entity.id = entity.value.id;
}
var id = entity.id;
var is_new = id == "Q0";
if (is_new) {
id = $.i18n._('wikidata-preview')['new-id'];
}
var fullLabel = id;
if (entity.label) {
fullLabel = entity.label + ' (' + id + ')';
}
if (is_new) {
return '<span class="wb-preview-new-entity">'+fullLabel+'</span>';
} else {
return '<a href="'+entity.iri+'" class="wb-preview-entity" target="_blank">'+fullLabel+'</a>';
}
}
// replaces the issue properties in localization template
SchemaAlignmentDialog._replaceIssueProperties = function(template, properties) {
if (!properties) {
return template;
}
var expanded = template;
for (var key in properties) {
if (properties.hasOwnProperty(key)) {
var rendered = properties[key];
if (key.endsWith('_entity')) {
rendered = SchemaAlignmentDialog._renderEntity(properties[key]);
}
expanded = expanded.replace(new RegExp('{'+key+'}', 'g'), rendered);
}
}
return expanded;
}
SchemaAlignmentDialog._renderWarning = function(warning) {
var localized = $.i18n._('warnings-messages')[warning.type];
var title = warning.type;
var body = "";
if (localized) {
title = SchemaAlignmentDialog._replaceIssueProperties(localized.title, warning.properties);
body = SchemaAlignmentDialog._replaceIssueProperties(localized.body, warning.properties);
}
var tr = $('<tr></tr>').addClass('wb-warning');
var severityTd = $('<td></td>')
.addClass('wb-warning-severity')
.addClass('wb-warning-severity-'+warning.severity)
.appendTo(tr);
var bodyTd = $('<td></td>')
.addClass('wb-warning-body')
.appendTo(tr);
var h1 = $('<h1></h1>')
.html(title)
.appendTo(bodyTd);
var p = $('<p></p>')
.html(body)
.appendTo(bodyTd);
var countTd = $('<td></td>')
.addClass('wb-warning-count')
.appendTo(tr);
var countSpan = $('<span></span>')
.text(warning.count)
.appendTo(countTd);
return tr;
}
SchemaAlignmentDialog._updateWarnings = function(warnings, totalCount) {
var mainDiv = this._elmts.warningsArea;
var countsElem = this._elmts.warningsTabCount;
@ -897,7 +826,7 @@ SchemaAlignmentDialog._updateWarnings = function(warnings, totalCount) {
var table = $('<table></table>').appendTo(mainDiv);
for (var i = 0; i != warnings.length; i++) {
var rendered = SchemaAlignmentDialog._renderWarning(warnings[i]);
var rendered = WarningsRenderer._renderWarning(warnings[i]);
rendered.appendTo(table);
}
@ -908,79 +837,3 @@ SchemaAlignmentDialog._updateWarnings = function(warnings, totalCount) {
}
}
/********************
* LANGUAGE SUGGEST *
********************/
// This list was manually copied from https://www.wikidata.org/w/api.php?action=paraminfo&modules=wbsetlabel on 2017-10-06
// I don't think it is worth making every OpenRefine client perform this query at every startup, because it typically does
// not change very often.
// See https://stackoverflow.com/questions/46507037/how-to-get-all-allowed-languages-for-wikidata/46562061#46562061
WIKIDATA_LANGUAGES = [ "aa", "ab", "ace", "ady", "ady-cyrl", "aeb", "aeb-arab", "aeb-latn", "af", "ak", "aln", "als", "am", "an", "ang", "anp", "ar", "arc", "arn", "arq", "ary", "arz",
"as", "ase", "ast", "atj", "av", "avk", "awa", "ay", "az", "azb", "ba", "ban", "bar", "bat-smg", "bbc", "bbc-latn", "bcc", "bcl", "be", "be-tarask", "be-x-old", "bg", "bgn", "bh", "bho",
"bi", "bjn", "bm", "bn", "bo", "bpy", "bqi", "br", "brh", "bs", "bto", "bug", "bxr", "ca", "cbk-zam", "cdo", "ce", "ceb", "ch", "cho", "chr", "chy", "ckb", "co", "cps", "cr", "crh",
"crh-cyrl", "crh-latn", "cs", "csb", "cu", "cv", "cy", "da", "de", "de-at", "de-ch", "de-formal", "din", "diq", "dsb", "dtp", "dty", "dv", "dz", "ee", "egl", "el", "eml", "en", "en-ca",
"en-gb", "eo", "es", "et", "eu", "ext", "fa", "ff", "fi", "fit", "fiu-vro", "fj", "fo", "fr", "frc", "frp", "frr", "fur", "fy", "ga", "gag", "gan", "gan-hans", "gan-hant", "gd", "gl",
"glk", "gn", "gom", "gom-deva", "gom-latn", "gor", "got", "grc", "gsw", "gu", "gv", "ha", "hak", "haw", "he", "hi", "hif", "hif-latn", "hil", "ho", "hr", "hrx", "hsb", "ht", "hu", "hy",
"hz", "ia", "id", "ie", "ig", "ii", "ik", "ike-cans", "ike-latn", "ilo", "inh", "io", "is", "it", "iu", "ja", "jam", "jbo", "jut", "jv", "ka", "kaa", "kab", "kbd", "kbd-cyrl", "kbp",
"kea", "kg", "khw", "ki", "kiu", "kj", "kk", "kk-arab", "kk-cn", "kk-cyrl", "kk-kz", "kk-latn", "kk-tr", "kl", "km", "kn", "ko", "ko-kp", "koi", "kr", "krc", "kri", "krj", "krl", "ks",
"ks-arab", "ks-deva", "ksh", "ku", "ku-arab", "ku-latn", "kv", "kw", "ky", "la", "lad", "lb", "lbe", "lez", "lfn", "lg", "li", "lij", "liv", "lki", "lmo", "ln", "lo", "loz", "lrc", "lt",
"ltg", "lus", "luz", "lv", "lzh", "lzz", "mai", "map-bms", "mdf", "mg", "mh", "mhr", "mi", "min", "mk", "ml", "mn", "mo", "mr", "mrj", "ms", "mt", "mus", "mwl", "my", "myv", "mzn", "na",
"nah", "nan", "nap", "nb", "nds", "nds-nl", "ne", "new", "ng", "niu", "nl", "nl-informal", "nn", "no", "nod", "nov", "nrm", "nso", "nv", "ny", "nys", "oc", "olo", "om", "or", "os", "ota",
"pa", "pag", "pam", "pap", "pcd", "pdc", "pdt", "pfl", "pi", "pih", "pl", "pms", "pnb", "pnt", "prg", "ps", "pt", "pt-br", "qu", "qug", "rgn", "rif", "rm", "rmy", "rn", "ro", "roa-rup",
"roa-tara", "ru", "rue", "rup", "ruq", "ruq-cyrl", "ruq-latn", "rw", "rwr", "sa", "sah", "sat", "sc", "scn", "sco", "sd", "sdc", "sdh", "se", "sei", "ses", "sg", "sgs", "sh", "shi",
"shi-latn", "shi-tfng", "shn", "si", "simple", "sje", "sk", "skr", "skr-arab", "sl", "sli", "sm", "sma", "smj", "sn", "so", "sq", "sr", "sr-ec", "sr-el", "srn", "srq", "ss", "st", "stq",
"su", "sv", "sw", "szl", "ta", "tay", "tcy", "te", "tet", "tg", "tg-cyrl", "tg-latn", "th", "ti", "tk", "tl", "tly", "tn", "to", "tokipona", "tpi", "tr", "tru", "ts", "tt", "tt-cyrl",
"tt-latn", "tum", "tw", "ty", "tyv", "tzm", "udm", "ug", "ug-arab", "ug-latn", "uk", "ur", "uz", "uz-cyrl", "uz-latn", "ve", "vec", "vep", "vi", "vls", "vmf", "vo", "vot", "vro", "wa",
"war", "wo", "wuu", "xal", "xh", "xmf", "yi", "yo", "yue", "za", "zea", "zh", "zh-classical", "zh-cn", "zh-hans", "zh-hant", "zh-hk", "zh-min-nan", "zh-mo", "zh-my", "zh-sg", "zh-tw",
"zh-yue", "zu" ]
$.suggest("langsuggest", {
_init: function() {
this.api_url = "https://www.wikidata.org/w/api.php";
this._status.SELECT = "Select a language from the list:";
},
request: function(val, cursor) {
var self = this;
var ajax_options = {
url: self.api_url,
data: { action: "languagesearch",
search: val,
format: "json", },
success: function(data) {
self.response(self.convertResults(data));
},
dataType: "jsonp",
};
$.ajax(ajax_options);
},
convertResults: function(data) {
var array = [];
for (var key in data.languagesearch) {
if (data.languagesearch.hasOwnProperty(key) && WIKIDATA_LANGUAGES.indexOf(key) != -1) {
array.push({ id: key, name: key, search_name: data.languagesearch[key] });
}
}
return array;
},
create_item: function(data, response_data) {
var css = this.options.css;
var li = $("<li>").addClass(css.item);
var type = $("<div>").addClass("fbs-item-type").text(data.id);
var native_name = this.get_native_name(data.id);
var full_name = native_name ? native_name : data.search_name;
var label = $("<label>").text(full_name);
li.append($("<div>").addClass(css.item_name).append(type).append(label));
return li;
},
get_native_name: function(lang_code) {
var language = $.uls.data.languages[lang_code];
if (language) {
return language[2];
}
},
});

View File

@ -0,0 +1,78 @@
/********************
* LANGUAGE SUGGEST *
********************/
// This list was manually copied from https://www.wikidata.org/w/api.php?action=paraminfo&modules=wbsetlabel on 2017-10-06
// I don't think it is worth making every OpenRefine client perform this query at every startup, because it typically does
// not change very often.
// See https://stackoverflow.com/questions/46507037/how-to-get-all-allowed-languages-for-wikidata/46562061#46562061
WIKIDATA_LANGUAGES = [ "aa", "ab", "ace", "ady", "ady-cyrl", "aeb", "aeb-arab", "aeb-latn", "af", "ak", "aln", "als", "am", "an", "ang", "anp", "ar", "arc", "arn", "arq", "ary", "arz",
"as", "ase", "ast", "atj", "av", "avk", "awa", "ay", "az", "azb", "ba", "ban", "bar", "bat-smg", "bbc", "bbc-latn", "bcc", "bcl", "be", "be-tarask", "be-x-old", "bg", "bgn", "bh", "bho",
"bi", "bjn", "bm", "bn", "bo", "bpy", "bqi", "br", "brh", "bs", "bto", "bug", "bxr", "ca", "cbk-zam", "cdo", "ce", "ceb", "ch", "cho", "chr", "chy", "ckb", "co", "cps", "cr", "crh",
"crh-cyrl", "crh-latn", "cs", "csb", "cu", "cv", "cy", "da", "de", "de-at", "de-ch", "de-formal", "din", "diq", "dsb", "dtp", "dty", "dv", "dz", "ee", "egl", "el", "eml", "en", "en-ca",
"en-gb", "eo", "es", "et", "eu", "ext", "fa", "ff", "fi", "fit", "fiu-vro", "fj", "fo", "fr", "frc", "frp", "frr", "fur", "fy", "ga", "gag", "gan", "gan-hans", "gan-hant", "gd", "gl",
"glk", "gn", "gom", "gom-deva", "gom-latn", "gor", "got", "grc", "gsw", "gu", "gv", "ha", "hak", "haw", "he", "hi", "hif", "hif-latn", "hil", "ho", "hr", "hrx", "hsb", "ht", "hu", "hy",
"hz", "ia", "id", "ie", "ig", "ii", "ik", "ike-cans", "ike-latn", "ilo", "inh", "io", "is", "it", "iu", "ja", "jam", "jbo", "jut", "jv", "ka", "kaa", "kab", "kbd", "kbd-cyrl", "kbp",
"kea", "kg", "khw", "ki", "kiu", "kj", "kk", "kk-arab", "kk-cn", "kk-cyrl", "kk-kz", "kk-latn", "kk-tr", "kl", "km", "kn", "ko", "ko-kp", "koi", "kr", "krc", "kri", "krj", "krl", "ks",
"ks-arab", "ks-deva", "ksh", "ku", "ku-arab", "ku-latn", "kv", "kw", "ky", "la", "lad", "lb", "lbe", "lez", "lfn", "lg", "li", "lij", "liv", "lki", "lmo", "ln", "lo", "loz", "lrc", "lt",
"ltg", "lus", "luz", "lv", "lzh", "lzz", "mai", "map-bms", "mdf", "mg", "mh", "mhr", "mi", "min", "mk", "ml", "mn", "mo", "mr", "mrj", "ms", "mt", "mus", "mwl", "my", "myv", "mzn", "na",
"nah", "nan", "nap", "nb", "nds", "nds-nl", "ne", "new", "ng", "niu", "nl", "nl-informal", "nn", "no", "nod", "nov", "nrm", "nso", "nv", "ny", "nys", "oc", "olo", "om", "or", "os", "ota",
"pa", "pag", "pam", "pap", "pcd", "pdc", "pdt", "pfl", "pi", "pih", "pl", "pms", "pnb", "pnt", "prg", "ps", "pt", "pt-br", "qu", "qug", "rgn", "rif", "rm", "rmy", "rn", "ro", "roa-rup",
"roa-tara", "ru", "rue", "rup", "ruq", "ruq-cyrl", "ruq-latn", "rw", "rwr", "sa", "sah", "sat", "sc", "scn", "sco", "sd", "sdc", "sdh", "se", "sei", "ses", "sg", "sgs", "sh", "shi",
"shi-latn", "shi-tfng", "shn", "si", "simple", "sje", "sk", "skr", "skr-arab", "sl", "sli", "sm", "sma", "smj", "sn", "so", "sq", "sr", "sr-ec", "sr-el", "srn", "srq", "ss", "st", "stq",
"su", "sv", "sw", "szl", "ta", "tay", "tcy", "te", "tet", "tg", "tg-cyrl", "tg-latn", "th", "ti", "tk", "tl", "tly", "tn", "to", "tokipona", "tpi", "tr", "tru", "ts", "tt", "tt-cyrl",
"tt-latn", "tum", "tw", "ty", "tyv", "tzm", "udm", "ug", "ug-arab", "ug-latn", "uk", "ur", "uz", "uz-cyrl", "uz-latn", "ve", "vec", "vep", "vi", "vls", "vmf", "vo", "vot", "vro", "wa",
"war", "wo", "wuu", "xal", "xh", "xmf", "yi", "yo", "yue", "za", "zea", "zh", "zh-classical", "zh-cn", "zh-hans", "zh-hant", "zh-hk", "zh-min-nan", "zh-mo", "zh-my", "zh-sg", "zh-tw",
"zh-yue", "zu" ]
$.suggest("langsuggest", {
_init: function() {
this.api_url = "https://www.wikidata.org/w/api.php";
this._status.SELECT = "Select a language from the list:";
},
request: function(val, cursor) {
var self = this;
var ajax_options = {
url: self.api_url,
data: { action: "languagesearch",
search: val,
format: "json", },
success: function(data) {
self.response(self.convertResults(data));
},
dataType: "jsonp",
};
$.ajax(ajax_options);
},
convertResults: function(data) {
var array = [];
for (var key in data.languagesearch) {
if (data.languagesearch.hasOwnProperty(key) && WIKIDATA_LANGUAGES.indexOf(key) != -1) {
array.push({ id: key, name: key, search_name: data.languagesearch[key] });
}
}
return array;
},
create_item: function(data, response_data) {
var css = this.options.css;
var li = $("<li>").addClass(css.item);
var type = $("<div>").addClass("fbs-item-type").text(data.id);
var native_name = this.get_native_name(data.id);
var full_name = native_name ? native_name : data.search_name;
var label = $("<label>").text(full_name);
li.append($("<div>").addClass(css.item_name).append(type).append(label));
return li;
},
get_native_name: function(lang_code) {
var language = $.uls.data.languages[lang_code];
if (language) {
return language[2];
}
},
});

View File

@ -0,0 +1,74 @@
var WarningsRenderer = {};
// renders a Wikibase entity into a link
WarningsRenderer._renderEntity = function(entity) {
if (!entity.id && entity.value) {
entity.id = entity.value.id;
}
var id = entity.id;
var is_new = id == "Q0";
if (is_new) {
id = $.i18n._('wikidata-preview')['new-id'];
}
var fullLabel = id;
if (entity.label) {
fullLabel = entity.label + ' (' + id + ')';
}
if (is_new) {
return '<span class="wb-preview-new-entity">'+fullLabel+'</span>';
} else {
return '<a href="'+entity.iri+'" class="wb-preview-entity" target="_blank">'+fullLabel+'</a>';
}
}
// replaces the issue properties in localization template
WarningsRenderer._replaceIssueProperties = function(template, properties) {
if (!properties) {
return template;
}
var expanded = template;
for (var key in properties) {
if (properties.hasOwnProperty(key)) {
var rendered = properties[key];
if (key.endsWith('_entity')) {
rendered = WarningsRenderer._renderEntity(properties[key]);
}
expanded = expanded.replace(new RegExp('{'+key+'}', 'g'), rendered);
}
}
return expanded;
}
WarningsRenderer._renderWarning = function(warning) {
var localized = $.i18n._('warnings-messages')[warning.type];
var title = warning.type;
var body = "";
if (localized) {
title = WarningsRenderer._replaceIssueProperties(localized.title, warning.properties);
body = WarningsRenderer._replaceIssueProperties(localized.body, warning.properties);
}
var tr = $('<tr></tr>').addClass('wb-warning');
var severityTd = $('<td></td>')
.addClass('wb-warning-severity')
.addClass('wb-warning-severity-'+warning.severity)
.appendTo(tr);
var bodyTd = $('<td></td>')
.addClass('wb-warning-body')
.appendTo(tr);
var h1 = $('<h1></h1>')
.html(title)
.appendTo(bodyTd);
var p = $('<p></p>')
.html(body)
.appendTo(bodyTd);
var countTd = $('<td></td>')
.addClass('wb-warning-count')
.appendTo(tr);
var countSpan = $('<span></span>')
.text(warning.count)
.appendTo(countTd);
return tr;
}

View File

@ -0,0 +1,39 @@
/*
Copyright 2010, Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
@import-less url("../theme.less");
.edit-summary {
width: 300px;
}

View File

@ -229,11 +229,12 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/*** Warnings rendering ****/
.schema-alignment-dialog-warnings h1 {
.wb-warning h1 {
font-size: 1.2em;
}
.schema-alignment-dialog-warnings table {
.schema-alignment-dialog-warnings table,
.perform-edits-warnings-area table {
width: 100%;
}
@ -287,7 +288,8 @@ tr.wb-warning:nth-of-type(odd) {
float: clear;
}
div.schema-alignment-dialog-warnings {
div.schema-alignment-dialog-warnings,
div.perform-edits-warnings-area {
min-height: 340px;
max-height: 400px;
overflow-x: hidden;

View File

@ -71,8 +71,19 @@ public class PreviewWikibaseSchemaCommand extends Command {
response.setHeader("Content-Type", "application/json");
String jsonString = request.getParameter("schema");
WikibaseSchema schema = null;
if (jsonString != null) {
JSONObject json = ParsingUtilities.evaluateJsonStringToObject(jsonString);
WikibaseSchema schema = WikibaseSchema.reconstruct(json);
schema = WikibaseSchema.reconstruct(json);
} else {
schema = (WikibaseSchema) project.overlayModels.get("wikibaseSchema");
}
if (schema == null) {
respond(response, "error", "No Wikibase schema provided.");
return;
}
QAWarningStore warningStore = new QAWarningStore();
// Evaluate project

View File

@ -81,6 +81,8 @@ public class ConnectionManager {
savedCredentials.getString("password"));
} catch (LoginFailedException e) {
connection = null;
} catch (JSONException e) {
connection = null;
}
}
}