diff mbox

[Branch,~linaro-validation/lava-scheduler/trunk] Rev 254: Fix bug #1213949. Reviewed by terceiro.

Message ID 20130827090128.28328.90242.launchpad@ackee.canonical.com
State Accepted
Headers show

Commit Message

Stevan Radakovic Aug. 27, 2013, 9:01 a.m. UTC
Merge authors:
  Stevan Radaković (stevanr)
Related merge proposals:
  https://code.launchpad.net/~stevanr/lava-scheduler/fix-1213949/+merge/182096
  proposed by: Stevan Radaković (stevanr)
  review: Approve - Milosz Wasilewski (mwasilew)
  review: Approve - Antonio Terceiro (terceiro)
------------------------------------------------------------
revno: 254 [merge]
committer: Stevan Radakovic <stevan.radakovic@linaro.org>
branch nick: trunk
timestamp: Tue 2013-08-27 11:00:32 +0200
message:
  Fix bug #1213949. Reviewed by terceiro.
modified:
  lava_scheduler_app/templates/lava_scheduler_app/job_log_file.html
  lava_scheduler_app/templatetags/linenumbers.py


--
lp:lava-scheduler
https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk

You are subscribed to branch lp:lava-scheduler.
To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-scheduler/trunk/+edit-subscription
diff mbox

Patch

=== modified file 'lava_scheduler_app/templates/lava_scheduler_app/job_log_file.html'
--- lava_scheduler_app/templates/lava_scheduler_app/job_log_file.html	2013-07-30 10:15:36 +0000
+++ lava_scheduler_app/templates/lava_scheduler_app/job_log_file.html	2013-08-26 13:08:40 +0000
@@ -42,11 +42,9 @@ 
           var atBottom = w.attr('innerHeight') + w.scrollTop() >= s.attr('scrollHeight')
                       && w.attr('innerHeight') > progressNode.attr('offsetHeight');
           if (last_pre.attr('class') == cls) {
-              last_pre.append(document.createTextNode(d[2]));
+              append_to_section(last_pre, d);
           } else {
-              var newNode = $("<pre></pre>");
-              newNode.addClass('log_' + d[0]);
-              newNode.text(d[2]);
+              var newNode = create_new_section_node(d);
               newNode.insertBefore(progressNode);
           }
           if (atBottom) {
@@ -62,6 +60,114 @@ 
     }
   });
 }
+
+append_to_section = function (element, data) {
+
+    current_table = $("#logfile_content table:last");
+    data_arr = data[2].replace(/\r\n/, "\n").split("\n");
+    line_number = get_current_section_number()[1];
+
+    if (data_arr[data_arr.length-1] == "") {
+        data_arr.pop();
+    }
+
+    for (var i in data_arr) {
+        line_number++;
+        name = "L_" + section_number + "_" + line_number;
+        display = section_number + "." + line_number;
+
+        link_node = $("<a>", {
+            href: "#" + name,
+            html: display
+        });
+
+        section_line = $("<div>", {
+            class: "line",
+        }).append($("<a>", {
+            name: name,
+        })).append(link_node);
+
+        $(current_table).find("td:first").append(section_line);
+
+        line_node = $("<div>", {
+            id: name,
+            class: "line"
+        }).html("&nbsp;" + data_arr[i]);
+        element.append(line_node);
+    }
+}
+
+create_new_section_node = function(data) {
+
+    section_number++;
+    data_arr = data[2].split("\n");
+    if (data_arr[data_arr.length-1] == "") {
+        data_arr.pop();
+    }
+
+    section_node = $("<td>");
+    for (var i in data_arr) {
+        name = "L_" + section_number + "_" + i;
+        if (i == 0) {
+            display = "Section " + section_number;
+        } else {
+            display = section_number + "." + i;
+        }
+
+        link_node = $("<a>", {
+            href: "#" + name,
+            html: display
+        });
+
+        section_node.append($("<div>", {
+            class: "line",
+        }).append($("<a>", {
+            name: name,
+        })).append(link_node));
+    }
+
+    text_element = $("<pre>", {
+                  class: "log_" + data[0],
+              });
+    for (var i in data_arr) {
+        var id = "L_" + section_number + "_" + i;
+        text_element.append($("<div>", {
+            id: id,
+            class: "line"
+
+        }).html("&nbsp;" + data_arr[i]));
+    }
+
+    var text_node = $("<td>", {
+                      class: "code",
+                  }).append($("<div>",{
+                      class: "container",
+                  }).append(text_element));
+
+    var node = $("<table>")
+                .append($("<tr>")
+                .append(section_node)
+                .append(text_node)
+               );
+
+    return node;
+}
+
+get_current_section_number = function() {
+
+    last_div = $("#logfile_content div:last");
+
+    if ($(last_div).attr("id")) {
+        div_id_arr = $(last_div).attr("id").split('_');
+        return [div_id_arr[1], div_id_arr[2]];
+    }
+
+    return [-1, -1];
+}
+
+var section_line_number = get_current_section_number();
+var section_number = section_line_number[0];
+
 $(document).ready(function () {
   pollTimer = setTimeout(poll, 1000);
 });

=== modified file 'lava_scheduler_app/templatetags/linenumbers.py'
--- lava_scheduler_app/templatetags/linenumbers.py	2013-07-30 10:15:36 +0000
+++ lava_scheduler_app/templatetags/linenumbers.py	2013-08-26 13:08:40 +0000
@@ -18,7 +18,10 @@ 
         ret = "<table><tr><td>"
         for i in range(0, len(text.splitlines())):
             name = "L_%s_%s" % (prefix, i)
-            display = "Section %s.%s" % (prefix, i)
+            if (i == 0):
+                display = "Section %s" % (prefix)
+            else:
+                display = "%s.%s" % (prefix, i)
             ret += "<div class=\"line\"><a name=\"%s\"></a> \
                 <a href=\"#%s\">%s</a></div>" % (name, name, display)