Permalink
Browse files

Fixes #202 - (Re-fix) lib.js/getdevicetypes gets wrong list of device…

…s versus showdevicetypes
  • Loading branch information...
shazron committed Nov 28, 2016
1 parent aaf3b2e commit 840bf11465e5c04e57100a351dd31198b4e5e44a
Showing with 14 additions and 13 deletions.
  1. +14 −13 src/lib.js
View
@@ -115,7 +115,7 @@ function findRuntimesGroupByDeviceProperty(list, deviceProperty, availableOnly)
function findAvailableRuntime(list, device_name) {
var all_druntimes = findRuntimesGroupByDeviceProperty(list, 'name', true);
var druntime = all_druntimes[device_name];
var druntime = all_druntimes[ filterDeviceName(device_name) ];
var runtime_found = druntime && druntime.length > 0;
if (!runtime_found) {
@@ -203,7 +203,7 @@ function getDeviceFromDeviceTypeId(devicetypeid) {
// found the runtime, now find the actual device matching devicename
if (deviceGroup.runtime === ret_obj.runtime) {
return deviceGroup.devices.some(function(device) {
if (device.name === ret_obj.name) {
if (filterDeviceName(device.name) === filterDeviceName(ret_obj.name)) {
ret_obj.id = device.id;
return true;
}
@@ -223,6 +223,15 @@ function getDeviceFromDeviceTypeId(devicetypeid) {
return ret_obj;
}
// replace hyphens in iPad Pro name which differ in 'Device Types' and 'Devices'
function filterDeviceName(deviceName) {
// replace hyphens in iPad Pro name which differ in 'Device Types' and 'Devices'
if (deviceName.indexOf('iPad Pro') === 0) {
return deviceName.replace(/\-/g, ' ').trim();
}
return deviceName;
}
var lib = {
init: function() {
@@ -264,11 +273,7 @@ var lib = {
var name_id_map = {};
list.devicetypes.forEach(function(device) {
// replace hyphens in iPad Pro name which differ in 'Device Types' and 'Devices'
if (device.name.indexOf('iPad Pro') === 0) {
device.name = device.name.replace(/\-/g, ' ').trim();
}
name_id_map[ device.name ] = device.id;
name_id_map[ filterDeviceName(device.name) ] = device.id;
});
list = [];
@@ -279,13 +284,9 @@ var lib = {
for (var deviceName in druntimes) {
var runtimes = druntimes[ deviceName ];
var dname = filterDeviceName(deviceName);
// replace hyphens in iPad Pro name which differ in 'Device Types' and 'Devices'
if (deviceName.indexOf('iPad Pro') === 0) {
deviceName = deviceName.replace(/\-/g, ' ').trim();
}
if (!(deviceName in name_id_map)) {
if (!(dname in name_id_map)) {
continue;
}
runtimes.forEach(remove);

0 comments on commit 840bf11

Please sign in to comment.