Created
September 23, 2015 10:33
-
-
Save quadrophobiac/99a0d131b266be62be5f to your computer and use it in GitHub Desktop.
Promise Raising as Uncaught in Comma Chameleon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// line 54-86, feature-prebaked | |
// inclusion of printErrs is because type returns as undefined | |
function displayValidationMessages(validation) { | |
console.log(JSON.stringify(validation,null, 2)); | |
var $messagePanel = $('#message-panel'); | |
$messagePanel.html("<h4>Validation results <img src='" + validation.badges.png +"' /></h4>"); | |
var resultsTemplate = _.template('<p><%= validation.errors.length %> errors, <%= validation.warnings.length %> warnings and <%= validation.info.length %> info messages:</p>') | |
$messagePanel.append(resultsTemplate({'validation': validation})); | |
//TODO the errorText function below is truncated and isn't doing what it should be doing | |
var printErrs = validation.errors[0]; | |
console.log(errorText(type)); | |
console.log(errorGuidance(type, row, col)); | |
var messageTemplate = _.template('<div><h5><%= errorText(type) %></h5><p><%= errorGuidance(type, row, col) %></p></div>'); | |
var messages = _.flatten([ | |
_.map(validation.errors, function(d) { return _.extend({}, d, { msg_type: 'error' }) }), | |
_.map(validation.warnings, function(d) { return _.extend({}, d, { msg_type: 'warning' }) }), | |
_.map(validation.info, function(d) { return _.extend({}, d, { msg_type: 'info' }) }) | |
]); | |
if (messages.length) { | |
var elements = _.map(messages, function(message) { | |
return $(messageTemplate(message)).data(message) | |
.addClass('message') | |
.addClass('validation-' + message.msg_type); | |
}); | |
$messagePanel.append(elements); | |
} else { | |
$messagePanel.append('<p>CSV Valid!</p>'); | |
} | |
clearHighlights(); | |
$messagePanel.on('click', '.message', function() { | |
highlightCell($(this).data()); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this is an example validation arg that is passed to function above | |
{ | |
"url": "http://csvlint.io/validation/56027e4363737614390006e7", | |
"source": null, | |
"state": "invalid", | |
"errors": [ | |
{ | |
"type": "ragged_rows", | |
"category": "structure", | |
"row": 3, | |
"col": null | |
} | |
], | |
"warnings": [], | |
"info": [ | |
{ | |
"type": "assumed_header", | |
"category": "structure", | |
"row": null, | |
"col": null | |
} | |
], | |
"standardisedCSV": "http://csvlint.io/validation/56027e4363737614390006e7.csv", | |
"badges": { | |
"svg": "http://csvlint.io/validation/56027e4363737614390006e7.svg", | |
"png": "http://csvlint.io/validation/56027e4363737614390006e7.png" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment