diff --git a/awx/ui/client/src/job-results/parse-stdout.service.js b/awx/ui/client/src/job-results/parse-stdout.service.js index 12620d3197..8799a152ac 100644 --- a/awx/ui/client/src/job-results/parse-stdout.service.js +++ b/awx/ui/client/src/job-results/parse-stdout.service.js @@ -4,12 +4,15 @@ * All Rights Reserved *************************************************/ -export default [function(){ +export default ['$log', function($log){ var val = { + // parses stdout string from api and formats various codes to the + // correct dom structure prettify: function(line){ + // TODO: remove once Chris's fixes to the [K lines comes in if (line.indexOf("[K") > -1) { - console.log(line); + $log.error(line); } line = line.replace(/u001b/g, ''); @@ -30,45 +33,60 @@ export default [function(){ line = line.replace(/\[0m/g, ''); return line; }, + // adds anchor tags and tooltips to host status lines getAnchorTags: function(event, line){ if(event.event.indexOf("runner_") === -1){ return line; } else{ - var str = ``, - str2 = ''; - return str.concat(line).concat(str2); + return `${line}`; } }, - getCollapseClasses: function(event, line, lineNum) { + // this adds classes based on event data to the + // .JobResultsStdOut-aLineOfStdOut element + getLineClasses: function(event, line, lineNum) { var string = ""; if (event.event_name === "playbook_on_play_start") { + // play header classes string += " header_play"; string += " header_play_" + event.event_data.play_uuid; if (line) { string += " actual_header"; } } else if (event.event_name === "playbook_on_task_start") { + // task header classes string += " header_task"; string += " header_task_" + event.event_data.task_uuid; - if (event.event_data.play_uuid) { - string += " play_" + event.event_data.play_uuid; - } if (line) { string += " actual_header"; } - } else { + + // task headers also get classed by their parent play + // if applicable if (event.event_data.play_uuid) { string += " play_" + event.event_data.play_uuid; } + } else { + // host status or debug line + + // these get classed by their parent play if applicable + if (event.event_data.play_uuid) { + string += " play_" + event.event_data.play_uuid; + } + // as well as their parent task if applicable if (event.event_data.task_uuid) { string += " task_" + event.event_data.task_uuid; } } + + // TODO: adding this line_num_XX class is hacky because the + // line number is availabe in children of this dom element string += " line_num_" + lineNum; + return string; }, + // used to add expand/collapse icon next to line numbers of headers getCollapseIcon: function(event, line) { var clickClass, expanderizerSpecifier; @@ -81,19 +99,26 @@ export default [function(){ line !== "") { if (event.event_name === "playbook_on_play_start" && line.indexOf("PLAY") > -1) { + // play header specific attrs expanderizerSpecifier = "play"; clickClass = "play_" + event.event_data.play_uuid; } else if (line.indexOf("TASK") > -1 || line.indexOf("RUNNING HANDLER") > -1) { + // task header specific attrs expanderizerSpecifier = "task"; clickClass = "task_" + event.event_data.task_uuid; } else { + // header lines that don't have PLAY, TASK, + // or RUNNING HANDLER in them don't get + // expand icon. + // This provides cowsay support. return emptySpan; } - return ` + + var expandDom = ` `; + console.log(expandDom); + return expandDom; } else { + // non-header lines don't get an expander return emptySpan; } }, + // public function that provides the parsed stdout line, given a + // job_event parseStdout: function(event){ - return _ + // this utilizes the start/end lines and stdout blob + // to create an array in the format: + // [ + // [lineNum: lineText], + // [lineNum: lineText], + // ] + var lineArr = _ .zip(_.range(event.start_line + 1, event.end_line + 1), - event.stdout.replace("\t", " ").split("\r\n").slice(0, -1)) + event.stdout.replace("\t", " ").split("\r\n").slice(0, -1)); + + // this takes each `[lineNum: lineText]` element and calls the + // relevant helper functions in this service to build the + // parsed line of standard out + lineArr = lineArr .map(lineArr => { return ` -