OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 * Requests the database from the backend. | 6 * Requests the database from the backend. |
7 */ | 7 */ |
8 function requestNetworkActionPredictorDb() { | 8 function requestAutocompleteActionPredictorDb() { |
9 console.debug('Requesting NAP DB'); | 9 console.debug('Requesting NAP DB'); |
10 chrome.send('requestNetworkActionPredictorDb', []) | 10 chrome.send('requestAutocompleteActionPredictorDb', []) |
11 } | 11 } |
12 | 12 |
13 | 13 |
14 /** | 14 /** |
15 * Callback from backend with the database contents. Sets up some globals and | 15 * Callback from backend with the database contents. Sets up some globals and |
16 * calls to create the UI. | 16 * calls to create the UI. |
17 * @param {Dictionary} database Information about NetworkActionPredictor | 17 * @param {Dictionary} database Information about AutocompleteActionPredictor |
18 * including the database as a flattened list, a boolean indicating if the | 18 * including the database as a flattened list, a boolean indicating if the |
19 * system is enabled and the current hit weight. | 19 * system is enabled and the current hit weight. |
20 */ | 20 */ |
21 function updateDatabaseTable(database) { | 21 function updateDatabaseTable(database) { |
22 console.debug('Updating Table NAP DB'); | 22 console.debug('Updating Table NAP DB'); |
23 | 23 |
24 var filter = $('filter'); | 24 var filter = $('filter'); |
25 filter.disabled = false; | 25 filter.disabled = false; |
26 filter.onchange = function() { | 26 filter.onchange = function() { |
27 updateDatabaseView(database); | 27 updateDatabaseView(database); |
28 }; | 28 }; |
29 | 29 |
30 updateDatabaseView(database); | 30 updateDatabaseView(database); |
31 } | 31 } |
32 | 32 |
33 /** | 33 /** |
34 * Updates the table from the database. | 34 * Updates the table from the database. |
35 * @param {Dictionary} database Information about NetworkActionPredictor | 35 * @param {Dictionary} database Information about AutocompleteActionPredictor |
36 * including the database as a flattened list, a boolean indicating if the | 36 * including the database as a flattened list, a boolean indicating if the |
37 * system is enabled and the current hit weight. | 37 * system is enabled and the current hit weight. |
38 */ | 38 */ |
39 function updateDatabaseView(database) { | 39 function updateDatabaseView(database) { |
40 var databaseSection = $('databaseTableBody'); | 40 var databaseSection = $('databaseTableBody'); |
41 var showEnabled = database.enabled && database.db; | 41 var autocompletePredictorEnabled = database.autocompletePredictorEnabled && |
42 database.db; | |
42 | 43 |
43 $('enabledMode').hidden = !showEnabled; | 44 $('autocompletePredictorEnabledMode').hidden = !autocompletePredictorEnabled; |
44 $('disabledMode').hidden = showEnabled; | 45 $('autocompletePredictorDisabledMode').hidden = autocompletePredictorEnabled; |
45 | 46 |
46 if (!showEnabled) | 47 if (!autocompletePredictorEnabled) |
47 return; | 48 return; |
48 | 49 |
49 var filter = $('filter'); | 50 var filter = $('filter'); |
50 | 51 |
51 // Clear any previous list. | 52 // Clear any previous list. |
52 databaseSection.textContent = ''; | 53 databaseSection.textContent = ''; |
53 | 54 |
54 for (var i = 0; i < database.db.length; ++i) { | 55 for (var i = 0; i < database.db.length; ++i) { |
55 var entry = database.db[i]; | 56 var entry = database.db[i]; |
56 | 57 |
57 if (!filter.checked || entry.confidence > 0) { | 58 if (!filter.checked || entry.confidence > 0) { |
58 var row = document.createElement('tr'); | 59 var row = document.createElement('tr'); |
59 | 60 |
dominich
2012/03/13 14:55:21
you'll have to merge in a change here.
| |
60 row.appendChild(document.createElement('td')).textContent = | 61 row.appendChild(document.createElement('td')).textContent = |
61 entry.user_text; | 62 entry.user_text; |
62 row.appendChild(document.createElement('td')).textContent = entry.url; | 63 row.appendChild(document.createElement('td')).textContent = entry.url; |
63 row.appendChild(document.createElement('td')).textContent = | 64 row.appendChild(document.createElement('td')).textContent = |
64 entry.hit_count; | 65 entry.hit_count; |
65 row.appendChild(document.createElement('td')).textContent = | 66 row.appendChild(document.createElement('td')).textContent = |
66 entry.miss_count; | 67 entry.miss_count; |
67 row.appendChild(document.createElement('td')).textContent = | 68 row.appendChild(document.createElement('td')).textContent = |
68 entry.confidence; | 69 entry.confidence; |
69 | 70 |
70 databaseSection.appendChild(row); | 71 databaseSection.appendChild(row); |
71 } | 72 } |
72 } | 73 } |
73 $('countBanner').textContent = 'Entries: ' + databaseSection.children.length; | 74 $('countBanner').textContent = 'Entries: ' + databaseSection.children.length; |
74 $('countBanner').textContent += ' Hit Weight: ' + database.hit_weight; | 75 $('countBanner').textContent += ' Hit Weight: ' + database.hit_weight; |
75 } | 76 } |
76 | 77 |
77 document.addEventListener('DOMContentLoaded', requestNetworkActionPredictorDb); | 78 document.addEventListener('DOMContentLoaded', |
79 requestAutocompleteActionPredictorDb); | |
OLD | NEW |