Skip to content

Commit

Permalink
Use channelTypeUID for channel types comparison (eclipse-archived#2949)
Browse files Browse the repository at this point in the history
* Use channelTypeUID for comparing channel types
* Use channelTypeUID in linkChannel

Signed-off-by: Aoun Bukhari <[email protected]>
  • Loading branch information
aounhaider1 authored and kaikreuzer committed Feb 2, 2017
1 parent dcd1ee9 commit 387a731
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ angular.module('PaperUI.controllers.configuration', [ 'PaperUI.constants' ]).con

$scope.linkChannel = function(channelID, event, preSelect) {
var channel = $scope.getChannelById(channelID);
var channelType = $scope.getChannelTypeById(channelID);
var channelType = $scope.getChannelTypeByUID(channel.channelTypeUID);
var params = {
linkedItems : channel.linkedItems.length > 0 ? channel.linkedItems : '',
acceptedItemType : channel.itemType,
Expand Down Expand Up @@ -476,8 +476,8 @@ angular.module('PaperUI.controllers.configuration', [ 'PaperUI.constants' ]).con
})[0];
}

$scope.getChannelTypeById = function(channelId) {
return thingConfigService.getChannelTypeById($scope.thingType, $scope.channelTypes, channelId);
$scope.getChannelTypeByUID = function(channelUID) {
return thingConfigService.getChannelTypeByUID($scope.thingType, $scope.channelTypes, channelUID);
};

$scope.getChannelFromChannelTypes = function(channelUID) {
Expand All @@ -503,7 +503,7 @@ angular.module('PaperUI.controllers.configuration', [ 'PaperUI.constants' ]).con
if (channels) {
for (var i = 0, len = channels.length; i < len; i++) {
var channel = channels[i];
var channelType = $scope.getChannelTypeById(channel.id);
var channelType = $scope.getChannelTypeByUID(channel.channelTypeUID);
if (channelType && channelType.advanced) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,45 +559,42 @@ angular.module('PaperUI.services', [ 'PaperUI.constants' ]).config(function($htt
var self = this;
self.thingType = thingType, self.channelTypes = channelTypes, self.channels = channels;
return $.grep(channels, function(channel, i) {
var channelType = self.getChannelTypeById(self.thingType, self.channelTypes, channel.id);
var channelType = self.getChannelTypeByUID(self.thingType, self.channelTypes, channel.channelTypeUID);
return channelType ? advanced == channelType.advanced : true;
});
},
getChannelTypeById : function(thingType, channelTypes, channelId) {
getChannelTypeByUID : function(thingType, channelTypes, channelUID) {
if (thingType) {
var cid_part = channelId.split('#', 2)
if (cid_part.length == 1) {
if (thingType.channels && thingType.channels.length > 0) {
var c, c_i, c_l;
for (c_i = 0, c_l = thingType.channels.length; c_i < c_l; ++c_i) {
c = thingType.channels[c_i];
if (c.id == channelId) {
if (c.typeUID == channelUID) {
return c;
}
}
} else if (cid_part.length == 2) {
var cg, cg_i, cg_l;
}
if (thingType.channelGroups && thingType.channelGroups.length > 0) {
var c, c_i, c_l;
var cg, cg_i, cg_l;
for (cg_i = 0, cg_l = thingType.channelGroups.length; cg_i < cg_l; ++cg_i) {
cg = thingType.channelGroups[cg_i];
if (cg.id == cid_part[0]) {
for (c_i = 0, c_l = cg.channels.length; c_i < c_l; ++c_i) {
c = cg.channels[c_i];
if (c.id == cid_part[1]) {
if (c.typeUID == channelUID) {
return c;
}
}
}
}
} else {
return;
}
}
if (channelTypes) {
var c = {}, c_i, c_l;
for (c_i = 0, c_l = channelTypes.length; c_i < c_l; ++c_i) {
c = channelTypes[c_i];
var id = c.UID.split(':', 2);
if (id[1] == channelId) {
if (c.UID == channelUID) {
return c;
}
}
Expand Down

0 comments on commit 387a731

Please sign in to comment.