Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: chrome/browser/resources/bluetooth_internals/device_table.js

Issue 2488093003: bluetooth: Componentize device list fixes (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 * Javascript for DeviceTable UI, served from 6 * Javascript for DeviceTable UI, served from chrome://bluetooth-internals/.
7 * chrome://bluetooth-internals/.
8 */ 7 */
9 8
10 cr.define('device_table', function() { 9 cr.define('device_table', function() {
11 var REMOVED_CSS = 'removed'; 10 var REMOVED_CLASS_NAME = 'removed';
Dan Beam 2016/11/10 03:22:59 why do you need this constant now? can you just i
mbrunson 2016/11/10 04:06:03 Ah, yes. Since it's only used in one place now, I
12 11
13 /** 12 /**
14 * A table that lists the devices and responds to changes in the given 13 * A table that lists the devices and responds to changes in the given
15 * DeviceCollection. 14 * DeviceCollection.
16 * @constructor 15 * @constructor
17 * @extends {HTMLTableElement} 16 * @extends {HTMLTableElement}
18 */ 17 */
19 var DeviceTable = cr.ui.define(function() { 18 var DeviceTable = cr.ui.define(function() {
20 // @type {Array<device_collection.Device>} 19 // @type {?Array<device_collection.Device>}
Dan Beam 2016/11/10 03:22:59 // comments aren't jsdoc you need /** These type
mbrunson 2016/11/10 04:06:03 Ah ok. Done.
20 // @private
21 this.devices_ = null; 21 this.devices_ = null;
22 22
23 return document.importNode($('table-template').content.children[0], 23 return document.importNode($('table-template').content.children[0],
24 true /* deep */); 24 true /* deep */);
25 }); 25 });
26 26
27 DeviceTable.prototype = { 27 DeviceTable.prototype = {
28 __proto__: HTMLTableElement.prototype, 28 __proto__: HTMLTableElement.prototype,
29 29
30 /** 30 /**
31 * Decorates an element as a UI element class. Caches references to the 31 * Decorates an element as a UI element class. Caches references to the
32 * table body and headers. 32 * table body and headers.
33 */ 33 */
34 decorate: function() { 34 decorate: function() {
35 // @private
35 this.body_ = this.tBodies[0]; 36 this.body_ = this.tBodies[0];
37 // @private
36 this.headers_ = this.tHead.rows[0].cells; 38 this.headers_ = this.tHead.rows[0].cells;
37 }, 39 },
38 40
39 /** 41 /**
40 * Sets the tables device collection. 42 * Sets the tables device collection.
41 * @param {!device_collection.DeviceCollection} deviceCollection 43 * @param {!device_collection.DeviceCollection} deviceCollection
42 */ 44 */
43 setDevices: function(deviceCollection) { 45 setDevices: function(deviceCollection) {
44 assert(!this.devices_, 'Devices can only be set once.'); 46 assert(!this.devices_, 'Devices can only be set once.');
45 47
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 /** 112 /**
111 * Updates the row at |index| with the info from |device|. 113 * Updates the row at |index| with the info from |device|.
112 * @private 114 * @private
113 * @param {!device_collection.Device} device 115 * @param {!device_collection.Device} device
114 * @param {number} index 116 * @param {number} index
115 */ 117 */
116 updateRow_: function(device, index) { 118 updateRow_: function(device, index) {
117 assert(this.body_.rows[index], 'Row ' + index + ' is not in the table.'); 119 assert(this.body_.rows[index], 'Row ' + index + ' is not in the table.');
118 var row = this.body_.rows[index]; 120 var row = this.body_.rows[index];
119 121
120 if (device.removed) { 122 row.classList.toggle(REMOVED_CLASS_NAME, device.removed);
121 row.classList.add(REMOVED_CSS);
122 } else {
123 row.classList.remove(REMOVED_CSS);
124 }
125 123
126 // Update the properties based on the header field path. 124 // Update the properties based on the header field path.
127 for (var i = 0; i < this.headers_.length; i++) { 125 for (var i = 0; i < this.headers_.length; i++) {
128 var header = this.headers_[i]; 126 var header = this.headers_[i];
129 var propName = header.dataset.field; 127 var propName = header.dataset.field;
130 128
131 var parts = propName.split('.'); 129 var parts = propName.split('.');
132 var obj = device.info; 130 var obj = device.info;
133 while (obj != null && parts.length > 0) { 131 while (obj != null && parts.length > 0) {
134 var part = parts.shift(); 132 var part = parts.shift();
135 obj = obj[part]; 133 obj = obj[part];
136 } 134 }
137 135
138 var cell = row.cells[i]; 136 var cell = row.cells[i];
139 cell.textContent = obj || 'Unknown'; 137 cell.textContent = obj || 'Unknown';
140 cell.dataset.label = header.textContent; 138 cell.dataset.label = header.textContent;
141 } 139 }
142 }, 140 },
143 }; 141 };
144 142
145 return { 143 return {
146 DeviceTable: DeviceTable, 144 DeviceTable: DeviceTable,
147 }; 145 };
148 }); 146 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698