Move parse error icon to `ErrorTable` too
This commit is contained in:
parent
e82ef3ed31
commit
21b3cca592
|
@ -35,6 +35,10 @@ function ErrorTable (config) {
|
||||||
validationErrorCount.className = 'jsoneditor-validation-error-count';
|
validationErrorCount.className = 'jsoneditor-validation-error-count';
|
||||||
validationErrorCount.style.display = 'none';
|
validationErrorCount.style.display = 'none';
|
||||||
this.dom.validationErrorCount = validationErrorCount;
|
this.dom.validationErrorCount = validationErrorCount;
|
||||||
|
|
||||||
|
this.dom.parseErrorIndication = document.createElement('span');
|
||||||
|
this.dom.parseErrorIndication.className = 'jsoneditor-parse-error-icon';
|
||||||
|
this.dom.parseErrorIndication.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorTable.prototype.getErrorTable = function () {
|
ErrorTable.prototype.getErrorTable = function () {
|
||||||
|
@ -45,10 +49,14 @@ ErrorTable.prototype.getErrorCounter = function () {
|
||||||
return this.dom.validationErrorCount;
|
return this.dom.validationErrorCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
ErrorTable.prototype.getErrorIcon = function () {
|
ErrorTable.prototype.getWarningIcon = function () {
|
||||||
return this.dom.validationErrorIcon;
|
return this.dom.validationErrorIcon;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
ErrorTable.prototype.getErrorIcon = function () {
|
||||||
|
return this.dom.parseErrorIndication;
|
||||||
|
};
|
||||||
|
|
||||||
ErrorTable.prototype.toggleTableVisibility = function () {
|
ErrorTable.prototype.toggleTableVisibility = function () {
|
||||||
this.errorTableVisible = !this.errorTableVisible;
|
this.errorTableVisible = !this.errorTableVisible;
|
||||||
this.onToggleVisibility(this.errorTableVisible);
|
this.onToggleVisibility(this.errorTableVisible);
|
||||||
|
@ -148,6 +156,21 @@ ErrorTable.prototype.setErrors = function (errors, errorLocations) {
|
||||||
this.dom.validationErrorCount.style.display = 'none';
|
this.dom.validationErrorCount.style.display = 'none';
|
||||||
this.dom.validationErrorIcon.style.display = 'none';
|
this.dom.validationErrorIcon.style.display = 'none';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update the parse error icon
|
||||||
|
var hasParseErrors = errors.some(function (error) {
|
||||||
|
return error.type === 'error'
|
||||||
|
});
|
||||||
|
if (hasParseErrors) {
|
||||||
|
var line = errors[0].line
|
||||||
|
this.dom.parseErrorIndication.style.display = 'block';
|
||||||
|
this.dom.parseErrorIndication.title = !isNaN(line)
|
||||||
|
? ('parse error on line ' + line)
|
||||||
|
: 'parse error - check that the json is valid';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.dom.parseErrorIndication.style.display = 'none';
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = ErrorTable;
|
module.exports = ErrorTable;
|
||||||
|
|
|
@ -355,12 +355,8 @@ textmode.create = function (container, options) {
|
||||||
statusBar.appendChild(countLabel);
|
statusBar.appendChild(countLabel);
|
||||||
|
|
||||||
statusBar.appendChild(this.errorTable.getErrorCounter());
|
statusBar.appendChild(this.errorTable.getErrorCounter());
|
||||||
|
statusBar.appendChild(this.errorTable.getWarningIcon());
|
||||||
statusBar.appendChild(this.errorTable.getErrorIcon());
|
statusBar.appendChild(this.errorTable.getErrorIcon());
|
||||||
|
|
||||||
this.parseErrorIndication = document.createElement('span');
|
|
||||||
this.parseErrorIndication.className = 'jsoneditor-parse-error-icon';
|
|
||||||
this.parseErrorIndication.style.display = 'none';
|
|
||||||
statusBar.appendChild(this.parseErrorIndication);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setSchema(this.options.schema, this.options.schemaRefs);
|
this.setSchema(this.options.schema, this.options.schemaRefs);
|
||||||
|
@ -796,25 +792,16 @@ textmode.validate = function () {
|
||||||
var json;
|
var json;
|
||||||
try {
|
try {
|
||||||
json = this.get(); // this can fail when there is no valid json
|
json = this.get(); // this can fail when there is no valid json
|
||||||
if (this.parseErrorIndication) {
|
|
||||||
this.parseErrorIndication.style.display = 'none';
|
|
||||||
}
|
|
||||||
doValidate = true;
|
doValidate = true;
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
if (this.getText()) {
|
if (this.getText()) {
|
||||||
if (this.parseErrorIndication) {
|
|
||||||
this.parseErrorIndication.style.display = 'block';
|
|
||||||
}
|
|
||||||
// try to extract the line number from the jsonlint error message
|
// try to extract the line number from the jsonlint error message
|
||||||
var match = /\w*line\s*(\d+)\w*/g.exec(err.message);
|
var match = /\w*line\s*(\d+)\w*/g.exec(err.message);
|
||||||
var line;
|
var line;
|
||||||
if (match) {
|
if (match) {
|
||||||
line = +match[1];
|
line = +match[1];
|
||||||
}
|
}
|
||||||
if (this.parseErrorIndication) {
|
|
||||||
this.parseErrorIndication.title = !isNaN(line) ? ('parse error on line ' + line) : 'parse error - check that the json is valid';
|
|
||||||
}
|
|
||||||
parseErrors.push({
|
parseErrors.push({
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: err.message.replace(/\n/g, '<br>'),
|
message: err.message.replace(/\n/g, '<br>'),
|
||||||
|
@ -845,7 +832,7 @@ textmode.validate = function () {
|
||||||
.then(function (customValidationErrors) {
|
.then(function (customValidationErrors) {
|
||||||
// only apply when there was no other validation started whilst resolving async results
|
// only apply when there was no other validation started whilst resolving async results
|
||||||
if (seq === me.validationSequence) {
|
if (seq === me.validationSequence) {
|
||||||
var errors = schemaErrors.concat(parseErrors || []).concat(customValidationErrors || []);
|
var errors = schemaErrors.concat(parseErrors).concat(customValidationErrors || []);
|
||||||
me._renderErrors(errors);
|
me._renderErrors(errors);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -858,7 +845,7 @@ textmode.validate = function () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this._renderErrors(parseErrors || []);
|
this._renderErrors(parseErrors);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue