diff --git a/modules/system/assets/css/eventlogs/exception-beautifier.css b/modules/system/assets/css/eventlogs/exception-beautifier.css index 3e2c4dff1..dbf0f09f5 100644 --- a/modules/system/assets/css/eventlogs/exception-beautifier.css +++ b/modules/system/assets/css/eventlogs/exception-beautifier.css @@ -2,28 +2,38 @@ width: auto !important; } -.plugin-exception-beautifier .beautifier-name { - display: block; - font-weight: bold; - font-size: 1.2em; -} - .plugin-exception-beautifier .beautifier-message { display: block; padding: 15px 0; font-size: 1.1em; } -.plugin-exception-beautifier .beautifier-stacktrace-title { +.plugin-exception-beautifier .beautifier-toggle-stacktrace { + background: #D0D9DD; + color: #2b3e50; + text-decoration: none; display: block; - margin-top: 15px; - font-weight: bold; + padding: 20px; + -webkit-border-radius: 4px; + -moz-border-radius: 4px; + border-radius: 4px; +} + +.plugin-exception-beautifier .beautifier-toggle-stacktrace.--hidden { + background: #ecf0f1; + color: #2b3e50; +} + +.plugin-exception-beautifier .beautifier-toggle-stacktrace:hover, +.plugin-exception-beautifier .beautifier-toggle-stacktrace.--hidden:hover { + background: #0181b9; + color: white; } .plugin-exception-beautifier .beautifier-stacktrace-line { display: block; - white-space: nowrap; padding: 10px 0; + white-space: nowrap; } .plugin-exception-beautifier .beautifier-stacktrace-line:nth-child(even) { @@ -53,6 +63,7 @@ .plugin-exception-beautifier .beautifier-file { color: #204bff; + white-space: nowrap; } .plugin-exception-beautifier .beautifier-line-number { diff --git a/modules/system/assets/js/eventlogs/exception-beautifier.js b/modules/system/assets/js/eventlogs/exception-beautifier.js index b1f86c51a..505242153 100644 --- a/modules/system/assets/js/eventlogs/exception-beautifier.js +++ b/modules/system/assets/js/eventlogs/exception-beautifier.js @@ -22,7 +22,7 @@ internalLine: /^(#[0-9]+)\s+(\[internal function\]\s*:)(.*)/, defaultLine: /^(#[0-9]+)\s*(.*)/, className: /([a-z0-9]+\\[a-z0-9\\]+(?:\.\.\.)?)/gi, - filePath: /((?:[A-Z]:[/\\]|\/)?[\w/\\]+\.php)(\(([0-9]+)\)|:([0-9]+))?/gi, + filePath: /((?:[A-Z]:)?(?:[\\\/][\w\.-_~@%]+)\.(?:php|js|css|less|yaml|txt|ini))(\(([0-9]+)\)|:([0-9]+)|\s|$)/gi, staticCall: /::([^( ]+)\(([^()]*|(?:[^(]*\(.+\)[^)]*))\)/, functionCall: /->([^(]+)\(([^()]*|(?:[^(]*\(.+\)[^)]*))\)/, closureCall: /\{closure\}\(([^()]*|(?:[^(]*\(.+\)[^)]*))\)/ @@ -31,7 +31,8 @@ ExceptionBeautifier.extensions = [] ExceptionBeautifier.prototype.init = function () { - var self = this + var self = this, + markup ExceptionBeautifier.extensions.forEach(function (extension) { if (typeof extension.onInit === 'function') { @@ -39,13 +40,17 @@ } }) - self.$el.addClass('plugin-exception-beautifier') - self.$el.html(self.parseSource()).find('.beautifier-message-container').addClass('form-control') + markup = self.parseSource(self.$el.text()) + + self.$el + .addClass('plugin-exception-beautifier') + .empty() + .append(markup) } - ExceptionBeautifier.prototype.parseSource = function () { + ExceptionBeautifier.prototype.parseSource = function (raw) { var self = this, - source = self.$el.text(), + source = raw, markup = {lines: []}, start = 0, end @@ -57,10 +62,6 @@ if (source.indexOf('Stack trace:') < 0) { source = '{exception-beautifier-message-container}{exception-beautifier-message}' + self.formatMessage(source) + '{/exception-beautifier-message}{/exception-beautifier-message-container}' } else { - end = source.indexOf(':', start) + 1 - markup.name = source.substring(start, end) - - start = end end = source.indexOf('Stack trace:', start) markup.message = source.substring(start, end) @@ -73,15 +74,16 @@ markup.lines.push(self.parseLine(source.substring(start))) source = '{exception-beautifier-message-container}' + - '{exception-beautifier-name}' + markup.name + '{/exception-beautifier-name}' + '{exception-beautifier-message}' + self.formatMessage(markup.message) + '{/exception-beautifier-message}' + '{/exception-beautifier-message-container}' + - '{exception-beautifier-stacktrace-title}Stack trace:{/exception-beautifier-stacktrace-title}' + '{exception-beautifier-stacktrace#div}' markup.lines.forEach(function (line) { source += '{exception-beautifier-stacktrace-line}' + self.formatStackTraceLine(line) + '{/exception-beautifier-stacktrace-line}' }) + source += '{/exception-beautifier-stacktrace#div}' + ExceptionBeautifier.extensions.forEach(function (extension) { if (typeof extension.onParse === 'function') { extension.onParse(self) @@ -89,7 +91,9 @@ }) } - return self.buildMarkup('{exception-beautifier-container}' + source + '{/exception-beautifier-container}') + markup = $(self.buildMarkup('{exception-beautifier-container}' + source + '{/exception-beautifier-container}')) + + return self.finalizeMarkup(markup, raw) } ExceptionBeautifier.prototype.parseLine = function (str) { @@ -117,13 +121,14 @@ return line } + ExceptionBeautifier.prototype.formatMessage = function (str) { var self = this return self.formatLineCode( str .replace(/^\s+/, '') - .replace(/\r|\n|\r\n/g, '{x-newline}') + .replace(/\r\n|\r|\n/g, '{x-newline}') .replace(/\t| {2}/g, '{x-tabulation}') ) } @@ -190,7 +195,7 @@ str = str.replace(ExceptionBeautifier.REGEX.filePath, function (str, path, line, lineNumber, altLineNumber) { return self.formatFilePath(path, (lineNumber || '') + (altLineNumber || '')) + - '{exception-beautifier-line-number}' + line + '{/exception-beautifier-line-number}' + ($.trim(line).length > 0 ? ('{exception-beautifier-line-number}' + line + '{/exception-beautifier-line-number}') : ' ') }) str = str.replace(ExceptionBeautifier.REGEX.className, function (str, name) { @@ -271,6 +276,71 @@ return markup } + ExceptionBeautifier.prototype.finalizeMarkup = function (markup, source) { + var stacktrace, + tabs + + markup.find('.beautifier-file').each(function () { + $(this).find('.beautifier-class').each(function () { + var $el = $(this) + + $el.replaceWith($el.text()) + }) + }) + + markup.find('.beautifier-file+.beautifier-line-number').each(function () { + var $el = $(this) + + $el.appendTo($el.prev()) + }) + + markup.find('.beautifier-message-container') + .addClass('form-control') + + stacktrace = markup.find('.beautifier-stacktrace') + .addClass('hidden') + + $(' ' + $.oc.lang.get('eventlog.show_stacktrace') + '') + .insertBefore(stacktrace) + .on('click', function (event) { + var $el = $(this) + + event.preventDefault() + event.stopPropagation() + + $('.beautifier-stacktrace', markup).toggleClass('hidden') + $el.toggleClass('--hidden') + + if(!$el.hasClass('--hidden')) { + if(!$el.data('show-text')) { + $el.data('show-text', $('span', $el).html()) + } + + $('i', $el).removeClass('icon-chevron-down').addClass('icon-chevron-up') + $('span', $el).html($el.data('hide-text')) + } else { + $('i', $el).removeClass('icon-chevron-up').addClass('icon-chevron-down') + $('span', $el).html($el.data('show-text')) + } + }) + + tabs = $('
' + + '
' + + '
' + + '
' + + '
') + + tabs.find('#beautifier-tab-formatted').append(markup) + tabs.find('#beautifier-tab-raw').append('
' + source.replace(/\r\n|\r|\n/g, '
').replace(/ {2}/g, '  ') + '
') + + tabs.ocTab({closable: false}) + + return tabs + } + // EXCEPTION BEAUTIFIER PLUGIN DEFINITION // ============================ diff --git a/modules/system/assets/js/eventlogs/exception-beautifier.links.js b/modules/system/assets/js/eventlogs/exception-beautifier.links.js index 53cb7746f..3b1b19020 100644 --- a/modules/system/assets/js/eventlogs/exception-beautifier.links.js +++ b/modules/system/assets/js/eventlogs/exception-beautifier.links.js @@ -22,7 +22,7 @@ exceptionBeautfier.initEditorPopup() }, onParse: function (exceptionBeautfier) { - exceptionBeautfier.$el.on('click', 'a', function () { + exceptionBeautfier.$el.on('click', 'a[data-href]', function () { exceptionBeautfier.openWithEditor($(this).data('href')) }) } @@ -33,7 +33,7 @@ var title = $.oc.lang.get('eventlog.editor.title'), description = $.oc.lang.get('eventlog.editor.description'), openWith = $.oc.lang.get('eventlog.editor.openWith'), - rememberChoice = $.oc.lang.get('eventlog.editor.rememberChoice'), + rememberChoice = $.oc.lang.get('eventlog.editor.remember_choice'), open = $.oc.lang.get('eventlog.editor.open'), cancel = $.oc.lang.get('eventlog.editor.cancel'), popup = $(' \ @@ -120,7 +120,7 @@ } ExceptionBeautifier.prototype.rewritePath = function (path) { - return path + return path.replace(/\\/g, '/') } ExceptionBeautifier.prototype.initCustomSelect = function (select) { diff --git a/modules/system/controllers/eventlogs/config_form.yaml b/modules/system/controllers/eventlogs/config_form.yaml index 88873b5f3..d03227292 100644 --- a/modules/system/controllers/eventlogs/config_form.yaml +++ b/modules/system/controllers/eventlogs/config_form.yaml @@ -16,4 +16,4 @@ defaultRedirect: system/eventlogs # Preview page preview: - title: Event \ No newline at end of file + title: system::lang.event_log.preview_title \ No newline at end of file diff --git a/modules/system/lang/en/client.php b/modules/system/lang/en/client.php index 80b62f5a1..19e21a29d 100644 --- a/modules/system/lang/en/client.php +++ b/modules/system/lang/en/client.php @@ -74,6 +74,12 @@ return [ ], 'eventlog' => [ + 'show_stacktrace' => 'Show the stacktrace', + 'hide_stacktrace' => 'Hide the stacktrace', + 'tabs' => [ + 'formatted' => 'Formatted', + 'raw' => 'Raw', + ], 'editor' => [ 'title' => 'Select the source code editor to use', 'description' => 'Your OS environnement must be configured to listen to one of these URL schemes.', diff --git a/modules/system/lang/en/lang.php b/modules/system/lang/en/lang.php index d31fe3d56..173671fea 100644 --- a/modules/system/lang/en/lang.php +++ b/modules/system/lang/en/lang.php @@ -310,7 +310,8 @@ return [ 'id_label' => 'Event ID', 'created_at' => 'Date & Time', 'message' => 'Message', - 'level' => 'Level' + 'level' => 'Level', + 'preview_title' => 'Event' ], 'request_log' => [ 'hint' => 'This log displays a list of browser requests that may require attention. For example, if a visitor opens a CMS page that cannot be found, a record is created with the status code 404.', diff --git a/modules/system/lang/fr/client.php b/modules/system/lang/fr/client.php index 9f066e2ff..e37ef031d 100644 --- a/modules/system/lang/fr/client.php +++ b/modules/system/lang/fr/client.php @@ -77,13 +77,19 @@ return [ ], 'eventlog' => [ + 'show_stacktrace' => 'Afficher la pile d’exécution', + 'hide_stacktrace' => 'Masquer la pile d’exécution', + 'tabs' => [ + 'formatted' => 'Formaté', + 'raw' => 'Message brut', + ], 'editor' => [ 'title' => 'Sélectionnez l’éditeur de code source à utiliser', 'description' => 'L’environnement de votre système d’exploitation doit être configuré pour ouvrir l’un des schémas d’URL ci-dessous.', 'openWith' => 'Ouvrir avec', - 'rememberChoice' => 'Se souvenir de la sélection pour la durée de la session dans ce navigateur', + 'remember_choice' => 'Se souvenir de la sélection pour la durée de la session dans ce navigateur', 'open' => 'Ouvrir', - 'cancel' => 'Annuler', + 'cancel' => 'Annuler' ], ] ]; diff --git a/modules/system/lang/fr/lang.php b/modules/system/lang/fr/lang.php index 8b5abd553..3c7a1fca7 100644 --- a/modules/system/lang/fr/lang.php +++ b/modules/system/lang/fr/lang.php @@ -311,6 +311,7 @@ return [ 'created_at' => 'Date et heure', 'message' => 'Message', 'level' => 'Niveau', + 'preview_title' => 'Évènement', ], 'request_log' => [ 'hint' => 'Ce journal affiche une liste de requêtes potentiellement suspectes. par exemple, si un visiteur ouvre une page introuvable du CMS, une ligne avec le statut code 404 est alors créée.',