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

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: Inline setting of characteristic fieldset object 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 this.serviceFieldSet_.setObject({ 64 this.serviceFieldSet_.setObject({
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 12 matching lines...) Expand all
75 serviceHeader.appendChild(serviceHeaderValue); 79 serviceHeader.appendChild(serviceHeaderValue);
76 this.briefContent_.appendChild(serviceHeader); 80 this.briefContent_.appendChild(serviceHeader);
77 81
78 // Create content for display in expanded content container. 82 // Create content for display in expanded content container.
79 var serviceInfoHeader = document.createElement('h4'); 83 var serviceInfoHeader = document.createElement('h4');
80 serviceInfoHeader.textContent = 'Service Info'; 84 serviceInfoHeader.textContent = 'Service Info';
81 85
82 var serviceDiv = document.createElement('div'); 86 var serviceDiv = document.createElement('div');
83 serviceDiv.classList.add('flex'); 87 serviceDiv.classList.add('flex');
84 serviceDiv.appendChild(this.serviceFieldSet_); 88 serviceDiv.appendChild(this.serviceFieldSet_);
85
86 this.infoDiv_.appendChild(serviceInfoHeader); 89 this.infoDiv_.appendChild(serviceInfoHeader);
87 this.infoDiv_.appendChild(serviceDiv); 90 this.infoDiv_.appendChild(serviceDiv);
91
92 var characteristicsListHeader = document.createElement('h4');
93 characteristicsListHeader.textContent = 'Characteristics';
94 this.infoDiv_.appendChild(characteristicsListHeader);
95
96 this.characteristicList_ = new characteristic_list.CharacteristicList();
97 this.characteristicList_.setLoading(true);
98 this.infoDiv_.appendChild(this.characteristicList_);
99
88 this.expandedContent_.appendChild(this.infoDiv_); 100 this.expandedContent_.appendChild(this.infoDiv_);
89 }, 101 },
102
103 /** @override */
104 onExpand: function(expanded) {
105 if (!expanded || this.characteristicsRequested_ ||
106 !this.characteristicList_.isLoading())
107 return;
dpapad 2017/01/17 20:01:01 Use braces when the "if" condition spans multiple
mbrunson 2017/01/17 21:05:49 Done.
108
109 this.dispatchEvent(new CustomEvent('characteristicsrequested', {
110 bubbles: true,
111 detail: {
112 serviceId: this.info.id,
113 }
114 }));
115 this.characteristicsRequested_ = true;
116 },
117
118 /**
119 * Called when the 'characteristicsrequested' event is handled. The incoming
120 * |characteristics| are wrapped in an ArrayDataModel then set as the data
121 * model of the characteristics list and cached in the service info.
122 * @param {!Array<!interfaces.BluetoothDevice.CharacteristicInfo}>}
123 * characteristics
124 */
125 onCharacteristicsReturned: function(characteristics) {
126 this.characteristicList_.setData(new ArrayDataModel(characteristics));
127 this.characteristicList_.setLoading(false);
128
129 this.info.characteristics = this.characteristicList_.dataModel;
130 this.characteristicsRequested_ = false;
131 },
90 }; 132 };
91 133
92 /** 134 /**
93 * A list that displays ServiceListItems. 135 * A list that displays ServiceListItems.
94 * @constructor 136 * @constructor
95 */ 137 */
96 var ServiceList = cr.ui.define('list'); 138 var ServiceList = cr.ui.define('list');
97 139
98 ServiceList.prototype = { 140 ServiceList.prototype = {
99 __proto__: ExpandableList.prototype, 141 __proto__: ExpandableList.prototype,
100 142
101 /** @override */ 143 /** @override */
102 decorate: function() { 144 decorate: function() {
103 ExpandableList.prototype.decorate.call(this); 145 ExpandableList.prototype.decorate.call(this);
104 this.classList.add('service-list'); 146 this.classList.add('service-list');
105 this.setEmptyMessage('No Services Found'); 147 this.setEmptyMessage('No Services Found');
106 }, 148 },
107 149
108 /** @override */ 150 /** @override */
109 createItem: function(data) { 151 createItem: function(data) {
110 return new ServiceListItem(data); 152 return new ServiceListItem(data);
111 }, 153 },
112 }; 154 };
113 155
114 return { 156 return {
115 ServiceList: ServiceList, 157 ServiceList: ServiceList,
116 ServiceListItem: ServiceListItem, 158 ServiceListItem: ServiceListItem,
117 }; 159 };
118 }); 160 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698