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

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

Issue 2622393002: bluetooth: Add characteristic list to DeviceDetailsPage in internals page. (Closed)
Patch Set: Fix comments, simplify onExpand Created 3 years, 11 months 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 ServiceList and ServiceListItem, served from 6 * Javascript for ServiceList and ServiceListItem, served from
7 * chrome://bluetooth-internals/. 7 * chrome://bluetooth-internals/.
8 */ 8 */
9 9
10 cr.define('service_list', function() { 10 cr.define('service_list', function() {
11 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel;
11 /** @const */ var ExpandableList = expandable_list.ExpandableList; 12 /** @const */ var ExpandableList = expandable_list.ExpandableList;
12 /** @const */ var ExpandableListItem = expandable_list.ExpandableListItem; 13 /** @const */ var ExpandableListItem = expandable_list.ExpandableListItem;
13 14
14 /** 15 /**
15 * Property names that will be displayed in the ObjectFieldSet which contains 16 * Property names that will be displayed in the ObjectFieldSet which contains
16 * the ServiceInfo object. 17 * the ServiceInfo object.
17 */ 18 */
18 var PROPERTY_NAMES = { 19 var PROPERTY_NAMES = {
19 id: 'ID', 20 id: 'ID',
20 'uuid.uuid': 'UUID', 21 'uuid.uuid': 'UUID',
(...skipping 22 matching lines...) Expand all
43 __proto__: ExpandableListItem.prototype, 44 __proto__: ExpandableListItem.prototype,
44 45
45 /** 46 /**
46 * Decorates the element as a service list item. Creates layout and caches 47 * Decorates the element as a service list item. Creates layout and caches
47 * references to the created header and fieldset. 48 * references to the created header and fieldset.
48 * @override 49 * @override
49 */ 50 */
50 decorate: function() { 51 decorate: function() {
51 this.classList.add('service-list-item'); 52 this.classList.add('service-list-item');
52 53
54 /** @private {boolean} */
55 this.characteristicsRequested_ = false;
56
53 /** @private {!HTMLElement} */ 57 /** @private {!HTMLElement} */
54 this.infoDiv_ = document.createElement('div'); 58 this.infoDiv_ = document.createElement('div');
55 this.infoDiv_.classList.add('info-container'); 59 this.infoDiv_.classList.add('info-container');
56 60
57 /** @private {!object_fieldset.ObjectFieldSet} */ 61 /** @private {!object_fieldset.ObjectFieldSet} */
58 this.serviceFieldSet_ = object_fieldset.ObjectFieldSet(); 62 this.serviceFieldSet_ = object_fieldset.ObjectFieldSet();
59 this.serviceFieldSet_.setPropertyDisplayNames(PROPERTY_NAMES); 63 this.serviceFieldSet_.setPropertyDisplayNames(PROPERTY_NAMES);
60 var serviceViewObj = { 64 var serviceViewObj = {
61 id: this.info.id, 65 id: this.info.id,
62 'uuid.uuid': this.info.uuid.uuid, 66 'uuid.uuid': this.info.uuid.uuid,
(...skipping 13 matching lines...) Expand all
76 serviceHeader.appendChild(serviceHeaderValue); 80 serviceHeader.appendChild(serviceHeaderValue);
77 this.briefContent_.appendChild(serviceHeader); 81 this.briefContent_.appendChild(serviceHeader);
78 82
79 // Create content for display in expanded content container. 83 // Create content for display in expanded content container.
80 var serviceInfoHeader = document.createElement('h4'); 84 var serviceInfoHeader = document.createElement('h4');
81 serviceInfoHeader.textContent = 'Service Info'; 85 serviceInfoHeader.textContent = 'Service Info';
82 86
83 var serviceDiv = document.createElement('div'); 87 var serviceDiv = document.createElement('div');
84 serviceDiv.classList.add('flex'); 88 serviceDiv.classList.add('flex');
85 serviceDiv.appendChild(this.serviceFieldSet_); 89 serviceDiv.appendChild(this.serviceFieldSet_);
86
87 this.infoDiv_.appendChild(serviceInfoHeader); 90 this.infoDiv_.appendChild(serviceInfoHeader);
88 this.infoDiv_.appendChild(serviceDiv); 91 this.infoDiv_.appendChild(serviceDiv);
92
93 var characteristicsListHeader = document.createElement('h4');
94 characteristicsListHeader.textContent = 'Characteristics';
95 this.infoDiv_.appendChild(characteristicsListHeader);
96
97 this.characteristicList_ = new characteristic_list.CharacteristicList();
98 this.characteristicList_.setLoading(true);
99 this.infoDiv_.appendChild(this.characteristicList_);
100
89 this.expandedContent_.appendChild(this.infoDiv_); 101 this.expandedContent_.appendChild(this.infoDiv_);
90 }, 102 },
103
104 /** @override */
105 onExpand: function(expanded) {
106 if (!expanded || this.characteristicsRequested_ ||
107 !this.characteristicList_.isLoading())
108 return;
109
110 this.dispatchEvent(new CustomEvent('characteristicsrequested', {
111 bubbles: true,
112 detail: {
113 serviceId: this.info.id,
114 }
115 }));
116 this.characteristicsRequested_ = true;
117 },
118
119 /**
120 * Called when the 'characteristicsrequested' event is handled. The incoming
121 * |characteristics| are wrapped in an ArrayDataModel then set as the data
122 * model of the characteristics list and cached in the service info.
123 * @param {!Array<!interfaces.BluetoothDevice.CharacteristicInfo}>}
124 * characteristics
125 */
126 onCharacteristicsRequested: function(characteristics) {
scheib 2017/01/13 05:24:40 Current name implies this is called when they are
mbrunson 2017/01/13 21:21:13 Done.
127 this.characteristicList_.setData(new ArrayDataModel(characteristics));
128 this.characteristicList_.setLoading(false);
129
130 this.info.characteristics = this.characteristicList_.dataModel;
131 this.characteristicsRequested_ = false;
132 },
91 }; 133 };
92 134
93 /** 135 /**
94 * A list that displays ServiceListItems. 136 * A list that displays ServiceListItems.
95 * @constructor 137 * @constructor
96 */ 138 */
97 var ServiceList = cr.ui.define('list'); 139 var ServiceList = cr.ui.define('list');
98 140
99 ServiceList.prototype = { 141 ServiceList.prototype = {
100 __proto__: ExpandableList.prototype, 142 __proto__: ExpandableList.prototype,
101 143
102 /** @override */ 144 /** @override */
103 decorate: function() { 145 decorate: function() {
104 ExpandableList.prototype.decorate.call(this); 146 ExpandableList.prototype.decorate.call(this);
105 this.classList.add('service-list'); 147 this.classList.add('service-list');
106 this.setEmptyMessage('No Services Found'); 148 this.setEmptyMessage('No Services Found');
107 }, 149 },
108 150
109 /** @override */ 151 /** @override */
110 createItem: function(data) { 152 createItem: function(data) {
111 return new ServiceListItem(data); 153 return new ServiceListItem(data);
112 }, 154 },
113 }; 155 };
114 156
115 return { 157 return {
116 ServiceList: ServiceList, 158 ServiceList: ServiceList,
117 ServiceListItem: ServiceListItem, 159 ServiceListItem: ServiceListItem,
118 }; 160 };
119 }); 161 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698