diff --git a/src/AzureIoTHub.Portal/Client/Pages/Devices/DeviceListPage.razor b/src/AzureIoTHub.Portal/Client/Pages/Devices/DeviceListPage.razor index 18b7c432f..3cc4abdad 100644 --- a/src/AzureIoTHub.Portal/Client/Pages/Devices/DeviceListPage.razor +++ b/src/AzureIoTHub.Portal/Client/Pages/Devices/DeviceListPage.razor @@ -18,10 +18,25 @@ - - + + + + DeviceID : + + + + + + + + Location : + + + + + - + Status : @@ -34,7 +49,7 @@ All - + Connection state : @@ -48,37 +63,12 @@ - - - - - Location : - - - - - - - - AppEUI : - - - - - - - - AppKey : - - - - - - + + Search Reset @@ -118,7 +108,7 @@ Delete - + @@ -134,9 +124,9 @@ { } - - - + + + @if (context.IsConnected) { @@ -145,20 +135,20 @@ { } - - @context.LastActivityDate - - - - - - - - - - - - + + @context.LastActivityDate + + + + + + + + + + + + } @@ -168,7 +158,7 @@ @code { private DeviceListItem[] result; - private string searchString = ""; + private string searchID = ""; private string searchStatus = ""; private string searchState = ""; private string searchLocation = ""; @@ -205,7 +195,7 @@ /// private void Reset() { - searchString = ""; + searchID = ""; searchStatus = ""; searchState = ""; searchLocation = ""; @@ -234,23 +224,45 @@ } /// - /// Filter the list of devices, based on fields set in the search panel + /// Filters the list of devices, based on fields set in the search panel /// - /// - /// + /// Device represented in the current row + /// Boolean private bool FilterFunc(DeviceListItem item) { - bool flagName = string.IsNullOrWhiteSpace(searchString) || item.DeviceID.Contains(searchString, StringComparison.OrdinalIgnoreCase); - bool flagStatus = string.IsNullOrWhiteSpace(searchStatus) || item.IsEnabled.ToString().Contains(searchStatus, StringComparison.OrdinalIgnoreCase); - bool flagState = string.IsNullOrWhiteSpace(searchState) || item.IsConnected.ToString().Contains(searchState, StringComparison.OrdinalIgnoreCase); - bool flagLocation = string.IsNullOrWhiteSpace(searchLocation) || item.LocationCode.Contains(searchLocation, StringComparison.OrdinalIgnoreCase); - bool flagAppEUI = string.IsNullOrWhiteSpace(searchAppEUI) || item.AppEUI.Contains(searchAppEUI, StringComparison.OrdinalIgnoreCase); - bool flagAppKey = string.IsNullOrWhiteSpace(searchAppKey) || item.AppKey.Contains(searchAppKey, StringComparison.OrdinalIgnoreCase); + bool flagID = checkFlag(item.DeviceID, searchID); + bool flagStatus = checkFlag(item.IsEnabled.ToString(), searchStatus); + bool flagState = checkFlag(item.IsConnected.ToString(), searchState); + bool flagLocation = checkFlag(item.LocationCode, searchLocation); + bool flagAppEUI = checkFlag(item.AppEUI, searchAppEUI); + bool flagAppKey = checkFlag(item.AppKey, searchAppKey); // Current row is shown only if all the flags are true - if (flagName && flagStatus && flagState && flagLocation && flagAppEUI && flagAppKey) + if (flagID && flagStatus && flagState && flagLocation && flagAppEUI && flagAppKey) return true; return false; } + + /// + /// Checks if the specific device value matches the search criteria + /// + /// Device attribute being compared + /// Field value in the search panel + /// True if it matches of field is empty + private bool checkFlag(string deviceValue, string searchString) + { + bool flag; + try + { + flag = string.IsNullOrWhiteSpace(searchString) || deviceValue.Contains(searchString, StringComparison.OrdinalIgnoreCase); + } + + //May happen if the device attribute is set to null + catch (NullReferenceException) + { + flag = false; + } + return flag; + } } diff --git a/src/AzureIoTHub.Portal/Server/Mappers/DeviceTwinMapper.cs b/src/AzureIoTHub.Portal/Server/Mappers/DeviceTwinMapper.cs index 008966e5d..76b01f2b5 100644 --- a/src/AzureIoTHub.Portal/Server/Mappers/DeviceTwinMapper.cs +++ b/src/AzureIoTHub.Portal/Server/Mappers/DeviceTwinMapper.cs @@ -54,6 +54,7 @@ public DeviceListItem CreateDeviceListItem(Twin twin) ImageUrl = this.deviceModelImageManager.ComputeImageUri(Helpers.DeviceHelper.RetrieveTagValue(twin, nameof(DeviceDetails.ModelId))), IsConnected = twin.ConnectionState == DeviceConnectionState.Connected, IsEnabled = twin.Status == DeviceStatus.Enabled, + LocationCode = Helpers.DeviceHelper.RetrieveTagValue(twin, nameof(DeviceDetails.LocationCode)), LastActivityDate = twin.LastActivityTime.GetValueOrDefault(DateTime.MinValue) }; }