|
|
@ -76,42 +76,58 @@ function Renderer (appAPI) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Renderer.prototype.error = function (message, container, options) { |
|
|
|
/** |
|
|
|
|
|
|
|
* format msg like error or warning, |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {String or DOMElement} message |
|
|
|
|
|
|
|
* @param {DOMElement} container |
|
|
|
|
|
|
|
* @param {Object} options {useSpan, noAnnotations, click:(Function), type:(warning, error), errFile, errLine, errCol} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
Renderer.prototype.error = function (message, container, opt) { |
|
|
|
if (container === undefined) return |
|
|
|
if (container === undefined) return |
|
|
|
var self = this |
|
|
|
opt = opt || {} |
|
|
|
var opt = options || {} |
|
|
|
|
|
|
|
|
|
|
|
var text |
|
|
|
|
|
|
|
if (typeof message === 'string') { |
|
|
|
|
|
|
|
text = message |
|
|
|
|
|
|
|
message = yo`<span>${message}</span>` |
|
|
|
|
|
|
|
} else if (message.innerText) { |
|
|
|
|
|
|
|
text = message.innerText |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!opt.type) { |
|
|
|
if (!opt.type) { |
|
|
|
opt.type = utils.errortype(message) |
|
|
|
opt.type = utils.errortype(text) |
|
|
|
} |
|
|
|
} |
|
|
|
var $pre |
|
|
|
|
|
|
|
if (opt.isHTML) { |
|
|
|
var errLocation = text.match(/^([^:]*):([0-9]*):(([0-9]*):)? /) |
|
|
|
$pre = $(opt.useSpan ? '<span />' : '<pre />').html(message) |
|
|
|
if (errLocation) { |
|
|
|
} else { |
|
|
|
errLocation = parseRegExError(errLocation) |
|
|
|
$pre = $(opt.useSpan ? '<span />' : '<pre />').text(message) |
|
|
|
opt.errFile = errLocation.errFile |
|
|
|
|
|
|
|
opt.errLine = errLocation.errLine |
|
|
|
|
|
|
|
opt.errCol = errLocation.errCol |
|
|
|
} |
|
|
|
} |
|
|
|
var $error = $('<div class="sol ' + opt.type + '"><div class="close"><i class="fa fa-close"></i></div></div>').prepend($pre) |
|
|
|
|
|
|
|
container.append($error) |
|
|
|
if (!opt.noAnnotations && errLocation) { |
|
|
|
var err = message.match(/^([^:]*):([0-9]*):(([0-9]*):)? /) |
|
|
|
this.appAPI.error(errLocation.errFile, { |
|
|
|
if (err) { |
|
|
|
row: errLocation.errLine, |
|
|
|
var errFile = err[1] |
|
|
|
column: errLocation.errCol, |
|
|
|
var errLine = parseInt(err[2], 10) - 1 |
|
|
|
text: text, |
|
|
|
var errCol = err[4] ? parseInt(err[4], 10) : 0 |
|
|
|
|
|
|
|
if (!opt.noAnnotations) { |
|
|
|
|
|
|
|
self.appAPI.error(errFile, { |
|
|
|
|
|
|
|
row: errLine, |
|
|
|
|
|
|
|
column: errCol, |
|
|
|
|
|
|
|
text: message, |
|
|
|
|
|
|
|
type: opt.type |
|
|
|
type: opt.type |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
$error.click(function (ev) { |
|
|
|
|
|
|
|
options && options.click ? options.click(errFile, errLine, errCol) : self.appAPI.errorClick(errFile, errLine, errCol) |
|
|
|
var $pre = $(opt.useSpan ? '<span />' : '<pre />').html(message) |
|
|
|
}) |
|
|
|
|
|
|
|
} else if (options && options.click) { |
|
|
|
var $error = $(yo`<div class="sol ${opt.type}"><div class="close"><i class="fa fa-close"></i></div></div>`).prepend($pre) |
|
|
|
$error.click(function (ev) { |
|
|
|
container.append($error) |
|
|
|
options.click(message) |
|
|
|
|
|
|
|
}) |
|
|
|
$error.click((ev) => { |
|
|
|
|
|
|
|
if (opt.errFile && opt.errLine) { |
|
|
|
|
|
|
|
this.appAPI.errorClick(opt.errFile, opt.errLine, opt.errCol) |
|
|
|
|
|
|
|
} else if (opt.click) { |
|
|
|
|
|
|
|
opt.click(message) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
$error.find('.close').click(function (ev) { |
|
|
|
$error.find('.close').click(function (ev) { |
|
|
|
ev.preventDefault() |
|
|
|
ev.preventDefault() |
|
|
@ -120,4 +136,12 @@ Renderer.prototype.error = function (message, container, options) { |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function parseRegExError (err) { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
errFile: err[1], |
|
|
|
|
|
|
|
errLine: parseInt(err[2], 10) - 1, |
|
|
|
|
|
|
|
errCol: err[4] ? parseInt(err[4], 10) : 0 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = Renderer |
|
|
|
module.exports = Renderer |
|
|
|