OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 |
| 6 var logPainter = (function () { |
| 7 "use strict"; |
| 8 |
| 9 var logPainter = {}; |
| 10 |
| 11 // Creates a filter function for filtering the logs. |
| 12 function genFilterFun(text) { |
| 13 if (text.trim().length === 0) { |
| 14 return function () { |
| 15 return true; |
| 16 }; |
| 17 } |
| 18 |
| 19 var split = text.split(","); |
| 20 var trimmed = split.map(function (x) { |
| 21 return x.trim().toLowerCase(); |
| 22 }); |
| 23 |
| 24 return function (x) { |
| 25 return trimmed.indexOf(x.key.trim().toLowerCase()) !== -1; |
| 26 }; |
| 27 } |
| 28 |
| 29 logPainter.paintNew = function (playerInfo, div, properties) { |
| 30 // Make sure that we don't have anything else inside. |
| 31 removeChildren(div); |
| 32 var table = makeTable("Timestamp", "Key", "Value"); |
| 33 var filterFun = genFilterFun(properties.filterText); |
| 34 |
| 35 var logEntries = playerInfo.allEvents; |
| 36 logEntries = logEntries.filter(filterFun); |
| 37 |
| 38 playerInfo.lastRendered = playerInfo.allEvents.length; |
| 39 |
| 40 logEntries.forEach(function (entry) { |
| 41 appendRow(table, genLogRow(entry)); |
| 42 }); |
| 43 |
| 44 div.appendChild(table); |
| 45 }; |
| 46 |
| 47 logPainter.paintExist = function (playerInfo, div, properties) { |
| 48 // Find the existing table |
| 49 var table = div.querySelector("table"); |
| 50 var filterFun = genFilterFun(properties.filterText); |
| 51 |
| 52 // Cut off all the events that we've already rendered |
| 53 var logEntries = playerInfo.allEvents.slice(playerInfo.lastRendered); |
| 54 logEntries = logEntries.filter(filterFun); |
| 55 |
| 56 // Set the last rendered property so we |
| 57 // slice at the right place next time |
| 58 playerInfo.lastRendered = playerInfo.allEvents.length; |
| 59 |
| 60 logEntries.forEach(function (entry) { |
| 61 appendRow(table, genLogRow(entry)); |
| 62 }); |
| 63 }; |
| 64 |
| 65 logPainter.invalidate = function (playerInfo) { |
| 66 playerInfo.lastRendered = 0; |
| 67 }; |
| 68 |
| 69 return logPainter; |
| 70 }()); |
OLD | NEW |