| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * This view displays network related log data and is specific fo ChromeOS. | 6 * This view displays network related log data and is specific fo ChromeOS. |
| 7 * We get log data from chrome by filtering system logs for network related | 7 * We get log data from chrome by filtering system logs for network related |
| 8 * keywords. Logs are not fetched until we actually need them. | 8 * keywords. Logs are not fetched until we actually need them. |
| 9 * | 9 * |
| 10 * @constructor | 10 * @constructor |
| 11 */ | 11 */ |
| 12 function LogsView() { | 12 function LogsView() { |
| 13 const mainBoxId = 'logsTabContent'; | 13 const mainBoxId = 'logs-view-tab-content'; |
| 14 const tableId = 'logTable'; | 14 const tableId = 'logs-view-log-table'; |
| 15 const globalShowButtonId = 'logsGlobalShowBtn'; | 15 const globalShowButtonId = 'logsGlobalShowBtn'; |
| 16 const globalHideButtonId = 'logsGlobalHideBtn'; | 16 const globalHideButtonId = 'logsGlobalHideBtn'; |
| 17 const refreshLogsButtonId = 'logsRefreshBtn'; | 17 const refreshLogsButtonId = 'logsRefreshBtn'; |
| 18 | 18 |
| 19 var tableDiv = $(tableId); | 19 var tableDiv = $(tableId); |
| 20 this.rows = []; | 20 this.rows = []; |
| 21 this.PopulateTable(tableDiv, this.logFilterList); | 21 this.PopulateTable(tableDiv, this.logFilterList); |
| 22 $(globalShowButtonId).addEventListener('click', | 22 $(globalShowButtonId).addEventListener('click', |
| 23 this.onGlobalChangeVisibleClick_.bind(this, true)); | 23 this.onGlobalChangeVisibleClick_.bind(this, true)); |
| 24 $(globalHideButtonId).addEventListener('click', | 24 $(globalHideButtonId).addEventListener('click', |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 LogsView.prototype.CreateTableRow = function(logKey) { | 60 LogsView.prototype.CreateTableRow = function(logKey) { |
| 61 var row = document.createElement('tr'); | 61 var row = document.createElement('tr'); |
| 62 | 62 |
| 63 var cells = []; | 63 var cells = []; |
| 64 for (var i = 0; i < 3; i++) { | 64 for (var i = 0; i < 3; i++) { |
| 65 var rowCell = document.createElement('td'); | 65 var rowCell = document.createElement('td'); |
| 66 cells.push(rowCell); | 66 cells.push(rowCell); |
| 67 row.appendChild(rowCell); | 67 row.appendChild(rowCell); |
| 68 } | 68 } |
| 69 // Log key cell. | 69 // Log key cell. |
| 70 cells[0].className = 'logCellText'; | 70 cells[0].className = 'logs-view-log-cell-text'; |
| 71 cells[0].textContent = logKey; | 71 cells[0].textContent = logKey; |
| 72 // Cell log is displayed in. Log content is in div element that is initially | 72 // Cell log is displayed in. Log content is in div element that is initially |
| 73 // hidden and empty. | 73 // hidden and empty. |
| 74 cells[2].className = 'logCellText'; | 74 cells[2].className = 'logs-view-log-cell-text'; |
| 75 var logDiv = document.createElement('div'); | 75 var logDiv = document.createElement('div'); |
| 76 logDiv.textContent = ''; | 76 logDiv.textContent = ''; |
| 77 logDiv.className = 'logCellLog'; | 77 logDiv.className = 'logs-view-log-cell-log'; |
| 78 logDiv.id = 'logsView.logCell.' + this.rows.length; | 78 logDiv.id = 'logsView.logCell.' + this.rows.length; |
| 79 cells[2].appendChild(logDiv); | 79 cells[2].appendChild(logDiv); |
| 80 | 80 |
| 81 // Button that we use to show or hide div element with log content. Logs are | 81 // Button that we use to show or hide div element with log content. Logs are |
| 82 // not visible initially, so we initialize button accordingly. | 82 // not visible initially, so we initialize button accordingly. |
| 83 var expandButton = document.createElement('button'); | 83 var expandButton = document.createElement('button'); |
| 84 expandButton.textContent = 'Show...'; | 84 expandButton.textContent = 'Show...'; |
| 85 expandButton.className = 'logButton'; | 85 expandButton.className = 'logs-view-log-button'; |
| 86 expandButton.addEventListener('click', | 86 expandButton.addEventListener('click', |
| 87 this.onButtonClicked_.bind(this, row)); | 87 this.onButtonClicked_.bind(this, row)); |
| 88 | 88 |
| 89 // Cell that contains show/hide button. | 89 // Cell that contains show/hide button. |
| 90 cells[1].appendChild(expandButton); | 90 cells[1].appendChild(expandButton); |
| 91 cells[1].className = 'logTableButtonColumn'; | 91 cells[1].className = 'logs-view-log-table-button-column'; |
| 92 | 92 |
| 93 // Initially, log is not visible. | 93 // Initially, log is not visible. |
| 94 row.className = 'logRowCollapsed'; | 94 row.className = 'logs-view-log-row-collapsed'; |
| 95 | 95 |
| 96 // We will need those to process row buttons' onclick events. | 96 // We will need those to process row buttons' onclick events. |
| 97 row.logKey = logKey; | 97 row.logKey = logKey; |
| 98 row.expandButton = expandButton; | 98 row.expandButton = expandButton; |
| 99 row.logDiv = logDiv; | 99 row.logDiv = logDiv; |
| 100 row.logVisible = false; | 100 row.logVisible = false; |
| 101 this.rows.push(row); | 101 this.rows.push(row); |
| 102 | 102 |
| 103 return row; | 103 return row; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * Initializes |tableDiv| to represent data from |logList| which should be of | 107 * Initializes |tableDiv| to represent data from |logList| which should be of |
| 108 * type LogsView.logFilterList. | 108 * type LogsView.logFilterList. |
| 109 */ | 109 */ |
| 110 LogsView.prototype.PopulateTable = function(tableDiv, logList) { | 110 LogsView.prototype.PopulateTable = function(tableDiv, logList) { |
| 111 for (var i = 0; i < logList.length; i++) { | 111 for (var i = 0; i < logList.length; i++) { |
| 112 var logSource = this.CreateTableRow(logList[i].key); | 112 var logSource = this.CreateTableRow(logList[i].key); |
| 113 tableDiv.appendChild(logSource); | 113 tableDiv.appendChild(logSource); |
| 114 } | 114 } |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 /** | 117 /** |
| 118 * Processes clicks on buttons that show or hide log contents in log row. | 118 * Processes clicks on buttons that show or hide log contents in log row. |
| 119 * Row containing the clicked button is given to the method since it contains | 119 * Row containing the clicked button is given to the method since it contains |
| 120 * all data we need to process the click (unlike button object itself). | 120 * all data we need to process the click (unlike button object itself). |
| 121 */ | 121 */ |
| 122 LogsView.prototype.onButtonClicked_ = function(containingRow) { | 122 LogsView.prototype.onButtonClicked_ = function(containingRow) { |
| 123 if (!containingRow.logVisible) { | 123 if (!containingRow.logVisible) { |
| 124 containingRow.className = 'logRowExpanded'; | 124 containingRow.className = 'logs-view-log-row-expanded'; |
| 125 containingRow.expandButton.textContent = 'Hide...'; | 125 containingRow.expandButton.textContent = 'Hide...'; |
| 126 var logDiv = containingRow.logDiv; | 126 var logDiv = containingRow.logDiv; |
| 127 if (logDiv.textContent == '') { | 127 if (logDiv.textContent == '') { |
| 128 logDiv.textContent = 'Getting logs...'; | 128 logDiv.textContent = 'Getting logs...'; |
| 129 // Callback will be executed by g_browser. | 129 // Callback will be executed by g_browser. |
| 130 g_browser.getSystemLog(containingRow.logKey, | 130 g_browser.getSystemLog(containingRow.logKey, |
| 131 containingRow.logDiv.id); | 131 containingRow.logDiv.id); |
| 132 } | 132 } |
| 133 } else { | 133 } else { |
| 134 containingRow.className = 'logRowCollapsed'; | 134 containingRow.className = 'logs-view-log-row-collapsed'; |
| 135 containingRow.expandButton.textContent = 'Show...'; | 135 containingRow.expandButton.textContent = 'Show...'; |
| 136 } | 136 } |
| 137 containingRow.logVisible = !containingRow.logVisible; | 137 containingRow.logVisible = !containingRow.logVisible; |
| 138 }; | 138 }; |
| 139 | 139 |
| 140 /** | 140 /** |
| 141 * Processes click on one of the buttons that are used to show or hide all logs | 141 * Processes click on one of the buttons that are used to show or hide all logs |
| 142 * we care about. | 142 * we care about. |
| 143 */ | 143 */ |
| 144 LogsView.prototype.onGlobalChangeVisibleClick_ = function(isShowAll) { | 144 LogsView.prototype.onGlobalChangeVisibleClick_ = function(isShowAll) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 172 g_browser.getSystemLog(visibleLogRows[row].logKey, | 172 g_browser.getSystemLog(visibleLogRows[row].logKey, |
| 173 visibleLogRows[row].logDiv.id); | 173 visibleLogRows[row].logDiv.id); |
| 174 } | 174 } |
| 175 | 175 |
| 176 // In hidden rows we just clear potential log text, so we know we have to get | 176 // In hidden rows we just clear potential log text, so we know we have to get |
| 177 // new contents when we show the row next time. | 177 // new contents when we show the row next time. |
| 178 for (row in hiddenLogRows) { | 178 for (row in hiddenLogRows) { |
| 179 hiddenLogRows[row].logDiv.textContent = ''; | 179 hiddenLogRows[row].logDiv.textContent = ''; |
| 180 } | 180 } |
| 181 }; | 181 }; |
| OLD | NEW |