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

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

Issue 2640073004: bluetooth: Add descriptor list to DeviceDetailsPage on internals page. (Closed)
Patch Set: Add comment to differentiate descriptor return value 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
(Empty)
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
3 // found in the LICENSE file.
4
5 /**
6 * Javascript for DescriptorList and DescriptorListItem, served from
7 * chrome://bluetooth-internals/.
8 */
9
10 cr.define('descriptor_list', function() {
11 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel;
12 /** @const */ var ExpandableList = expandable_list.ExpandableList;
13 /** @const */ var ExpandableListItem = expandable_list.ExpandableListItem;
14 /** @const */ var Snackbar = snackbar.Snackbar;
15 /** @const */ var SnackbarType = snackbar.SnackbarType;
16
17 /** Property names for the DescriptorInfo fieldset */
18 var INFO_PROPERTY_NAMES = {
19 id: 'ID',
20 'uuid.uuid': 'UUID',
21 };
22
23 /**
24 * A list item that displays the properties of a DescriptorInfo object.
25 * A fieldset is created within the element for the primitive
26 * properties, 'id' and 'uuid' within the DescriptorInfo object.
27 * @constructor
28 * @param {!interfaces.BluetoothDevice.DescriptorInfo} descriptorInfo
29 */
30 function DescriptorListItem(descriptorInfo) {
31 var listItem = new ExpandableListItem();
32 listItem.__proto__ = DescriptorListItem.prototype;
33
34 listItem.info = descriptorInfo;
35 listItem.decorate();
36
37 return listItem;
38 }
39
40 DescriptorListItem.prototype = {
41 __proto__: ExpandableListItem.prototype,
42
43 /**
44 * Decorates the element as a descriptor list item. Creates and caches
45 * a fieldset for displaying property values.
46 * @override
47 */
48 decorate: function() {
49 this.classList.add('descriptor-list-item');
50
51 /** @private {!object_fieldset.ObjectFieldSet} */
52 this.descriptorFieldSet_ = object_fieldset.ObjectFieldSet();
53 this.descriptorFieldSet_.setPropertyDisplayNames(INFO_PROPERTY_NAMES);
54 this.descriptorFieldSet_.setObject({
55 id: this.info.id,
56 'uuid.uuid': this.info.uuid.uuid,
57 });
58
59 // Create content for display in brief content container.
60 var descriptorHeaderText = document.createElement('div');
61 descriptorHeaderText.textContent = 'Descriptor:';
62
63 var descriptorHeaderValue = document.createElement('div');
64 descriptorHeaderValue.textContent = this.info.uuid.uuid;
65
66 var descriptorHeader = document.createElement('div');
67 descriptorHeader.appendChild(descriptorHeaderText);
68 descriptorHeader.appendChild(descriptorHeaderValue);
69 this.briefContent_.appendChild(descriptorHeader);
70
71 // Create content for display in expanded content container.
72 var descriptorInfoHeader = document.createElement('h4');
73 descriptorInfoHeader.textContent = 'Descriptor Info';
74
75 var descriptorDiv = document.createElement('div');
76 descriptorDiv.classList.add('flex');
77 descriptorDiv.appendChild(this.descriptorFieldSet_);
78
79 var infoDiv = document.createElement('div');
80 infoDiv.classList.add('info-container');
81 infoDiv.appendChild(descriptorInfoHeader);
82 infoDiv.appendChild(descriptorDiv);
83
84 this.expandedContent_.appendChild(infoDiv);
85 },
86 };
87
88 /**
89 * A list that displays DescriptorListItems.
90 * @constructor
91 */
92 var DescriptorList = cr.ui.define('list');
93
94 DescriptorList.prototype = {
95 __proto__: ExpandableList.prototype,
96
97 /** @override */
98 decorate: function() {
99 ExpandableList.prototype.decorate.call(this);
100
101 /** @private {boolean} */
102 this.descriptorsRequested_ = false;
103
104 this.classList.add('descriptor-list');
105 this.setEmptyMessage('No Descriptors Found');
106 },
107
108 /** @override */
109 createItem: function(data) {
110 return new DescriptorListItem(data);
111 },
112
113 /**
114 * Loads the descriptor list with an array of DescriptorInfo from
115 * the device with |deviceAddress|, service with |serviceId|, and
116 * characteristic with |characteristicId|. If no active connection to the
117 * device exists, one is created.
118 * @param {string} deviceAddress
119 * @param {string} serviceId
120 * @param {string} characteristicId
121 */
122 load: function(deviceAddress, serviceId, characteristicId) {
123 if (this.descriptorsRequested_ || !this.isLoading())
Dan Beam 2017/01/24 06:07:29 it's kinda confusing to call load() and return if
mbrunson 2017/01/24 21:29:46 Done.
124 return;
125
126 this.descriptorsRequested_ = true;
127
128 device_broker.connectToDevice(deviceAddress).then(function(device) {
129 return device.getDescriptors(serviceId, characteristicId);
130 }.bind(this)).then(function(response) {
131 this.setData(new ArrayDataModel(response.descriptors || []));
132 this.setLoading(false);
133 this.descriptorsRequested_ = false;
134 }.bind(this)).catch(function(error) {
135 this.descriptorsRequested_ = false;
136 Snackbar.show(
137 deviceAddress + ': ' + error.message, SnackbarType.ERROR, 'Retry',
138 function() {
139 this.load(deviceAddress, serviceId, characteristicId);
140 }.bind(this));
141 }.bind(this));
142 },
143 };
144
145 return {
146 DescriptorList: DescriptorList,
147 DescriptorListItem: DescriptorListItem,
148 };
149 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698