From 6b86fc222d1ee09fd0fbe6bd0a7bb70b9a4b5b8b Mon Sep 17 00:00:00 2001 From: Hocine Hacherouf Date: Tue, 2 Aug 2022 16:54:43 +0200 Subject: [PATCH] Disable the edition of existing tags names #1002 --- .../Client/Models/DeviceTagModel.cs | 25 +++++++++++++++++ .../Pages/Settings/DeviceTagsPage.razor | 27 +++++++++++-------- 2 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 src/AzureIoTHub.Portal/Client/Models/DeviceTagModel.cs diff --git a/src/AzureIoTHub.Portal/Client/Models/DeviceTagModel.cs b/src/AzureIoTHub.Portal/Client/Models/DeviceTagModel.cs new file mode 100644 index 000000000..b18f7ba2e --- /dev/null +++ b/src/AzureIoTHub.Portal/Client/Models/DeviceTagModel.cs @@ -0,0 +1,25 @@ +// Copyright (c) CGI France. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace AzureIoTHub.Portal.Client.Models +{ + using Portal.Models.v10; + + public class DeviceTagModel : DeviceTag + { + public DeviceTagModel() + { + IsNewTag = true; + } + + public DeviceTagModel(DeviceTag deviceTag) + { + Name = deviceTag.Name; + Label = deviceTag.Label; + Required = deviceTag.Required; + Searchable = deviceTag.Searchable; + } + + public bool IsNewTag { get; set; } + } +} diff --git a/src/AzureIoTHub.Portal/Client/Pages/Settings/DeviceTagsPage.razor b/src/AzureIoTHub.Portal/Client/Pages/Settings/DeviceTagsPage.razor index 4209f113c..fc70ad08d 100644 --- a/src/AzureIoTHub.Portal/Client/Pages/Settings/DeviceTagsPage.razor +++ b/src/AzureIoTHub.Portal/Client/Pages/Settings/DeviceTagsPage.razor @@ -1,5 +1,4 @@ @page "/settings/device-tag" -@using AzureIoTHub.Portal.Models.v10 @attribute [Authorize] @inject ISnackbar Snackbar @@ -7,7 +6,7 @@ - + Tags @@ -37,6 +36,7 @@ @@ -66,7 +66,7 @@ - Add a new Tag + Add a new Tag @@ -83,7 +83,7 @@ [CascadingParameter] public Error Error { get; set; } - List Tags { get; set; } = new(); + List Tags { get; } = new(); private MudForm FormName { get; set; } private MudForm FormLabel { get; set; } @@ -100,7 +100,10 @@ { isProcessing = true; Tags.Clear(); - Tags.AddRange(await DeviceTagSettingsClientService.GetDeviceTags()); + + var result = await DeviceTagSettingsClientService.GetDeviceTags(); + + Tags.AddRange(result.Select(tag => new DeviceTagModel(tag)).ToList()); } catch (ProblemDetailsException exception) { @@ -118,16 +121,16 @@ if (Tags.Count == 0 || (last.Name is not null && last.Label is not null)) { - Tags.Add(new DeviceTag()); + Tags.Add(new DeviceTagModel()); } } - private void DeleteTag(DeviceTag item) + private void DeleteTag(DeviceTagModel deviceTagModel) { try { - DeviceTagSettingsClientService.DeleteDeviceTagByName(item.Name); - Tags.Remove(item); + DeviceTagSettingsClientService.DeleteDeviceTagByName(deviceTagModel.Name); + Tags.Remove(deviceTagModel); } catch (ProblemDetailsException exception) { @@ -135,7 +138,7 @@ } } - private async Task Save(DeviceTag deviceTag) + private async Task Save(DeviceTagModel deviceTagModel) { try { @@ -166,7 +169,9 @@ } else { - await DeviceTagSettingsClientService.CreateOrUpdateDeviceTag(deviceTag); + await DeviceTagSettingsClientService.CreateOrUpdateDeviceTag(deviceTagModel); + + deviceTagModel.IsNewTag = false; } Snackbar.Add($"Settings have been successfully updated!", Severity.Success);