Skip to content

Commit

Permalink
Prevent device creation if no model is selected (#94)
Browse files Browse the repository at this point in the history
* fix #88 (#92)

Co-authored-by: ben salim <salim.benahben@cgi.com>

* Migrate to CGI-FR Organization (#93)

* Reset fields if the "Model type" field is cleared

* Prevent device creation if no model is selected

Co-authored-by: salim ben ahben <40862545+Sben65@users.noreply.github.com>
Co-authored-by: ben salim <salim.benahben@cgi.com>
Co-authored-by: Kevin BEAUGRAND <9513635+kbeaugrand@users.noreply.github.com>
  • Loading branch information
4 people authored Jan 24, 2022
1 parent fd84da4 commit e7718da
Showing 6 changed files with 39 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Build & Test](https://github.com/michelin/i4i-iot-hub-portal/actions/workflows/build.yml/badge.svg)](https://github.com/michelin/i4i-iot-hub-portal/actions/workflows/build.yml)
[![Continuous Deployment](https://github.com/michelin/i4i-iot-hub-portal/actions/workflows/publish.yml/badge.svg)](https://github.com/michelin/i4i-iot-hub-portal/actions/workflows/publish.yml)
[![Build & Test](https://github.com/CGI-FR/iot-hub-portal/actions/workflows/build.yml/badge.svg)](https://github.com/CGI-FR/iot-hub-portal/actions/workflows/build.yml)
[![Continuous Deployment](https://github.com/CGI-FR/iot-hub-portal/actions/workflows/publish.yml/badge.svg)](https://github.com/CGI-FR/iot-hub-portal/actions/workflows/publish.yml)

# IoT Hub Portal

@@ -24,7 +24,7 @@ The following should be completed before proceeding with the IoT Hub Portal deve

## Documentation

Our documentation is present at github page: [https://michelin.github.io/i4i-iot-hub-portal/](https://michelin.github.io/i4i-iot-hub-portal/).
Our documentation is present at github page: [https://cgi-fr.github.io/iot-hub-portal/](https://cgi-fr.github.io/iot-hub-portal/).

## Known Issues and Limitations

39 changes: 32 additions & 7 deletions src/AzureIoTHub.Portal/Client/Pages/Devices/CreateDevicePage.razor
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
<MudContainer MaxWidth="MaxWidth.False">
<MudGrid>
<MudItem xs="12">
<EditForm Model="@Device" OnValidSubmit="SaveDevice">
<EditForm Model="@Device" OnValidSubmit="SaveDevice" OnInvalidSubmit="HandleInvalidSubmit">
<DataAnnotationsValidator />
<MudCard>
<MudCardHeader>
@@ -70,7 +70,11 @@
ToStringFunc="@(x => x.Name)"
ResetValueOnEmptyText="true"
Immediate="true" Clearable="true"
CoerceText="true" CoerceValue="false" />
CoerceText="true" CoerceValue="false"/>
@if (Device.ModelName == null && displayValidationErrorMessages)
{
<p class="mud-input-helper-text mud-input-error">The Model Type field is required.</p>
}
</MudItem>
</MudItem>
</MudItem>
@@ -165,6 +169,8 @@

private IEnumerable<DeviceModel> DeviceModelList { get; set; } = new List<DeviceModel>();

private bool displayValidationErrorMessages = false;

protected override async Task OnInitializedAsync()
{
Device.DeviceType = "LoRa Device";
@@ -224,11 +230,30 @@

private void ModelSelected(DeviceModel model)
{
Device.ModelId = model.ModelId;
Device.ModelName = model.Name;
Device.ImageUrl = new Uri(model.ImageUrl);
Device.AppEUI = model.AppEUI ?? "Selected model contains no AppEUI value";
Device.SensorDecoder = model.SensorDecoderURL;
// Reset all the other fields if the Model Type field is cleared
if(model == null)
{
Device.ModelId = null;
Device.ModelName = null;
Device.ImageUrl = null;
Device.AppEUI = null;
Device.SensorDecoder = null;
}
else
{
Device.ModelId = model.ModelId;
Device.ModelName = model.Name;
Device.ImageUrl = new Uri(model.ImageUrl);
Device.AppEUI = model.AppEUI ?? "Selected model contains no AppEUI value";
Device.SensorDecoder = model.SensorDecoderURL;
}
}

private void HandleInvalidSubmit(EditContext context)
{
// Invalid submit manually handled
// Waiting for MudBlazor MudAutocomplete issue #2674 to be fixed
displayValidationErrorMessages = true;
}
}

2 changes: 1 addition & 1 deletion src/AzureIoTHub.Portal/Server/Services/DeviceService.cs
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ public async Task<Twin> GetDeviceTwinWithModule(string deviceId)
/// <returns>AttestationMechanism.</returns>
public async Task<AttestationMechanism> GetDpsAttestionMechanism()
{
return await this.dps.GetEnrollmentGroupAttestationAsync(this.configuration["IoTDPS:DefaultEnrollmentGroupe"]);
return await this.dps.GetEnrollmentGroupAttestationAsync(this.configuration["IoTDPS:DefaultEnrollmentGroup"]);
}

/// <summary>
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@ public class DeviceDetails

public string ModelId { get; set; }

[Required]
public string ModelName { get; set; }

public string SensorDecoder { get; set; }
2 changes: 1 addition & 1 deletion templates/azuredeploy.json
Original file line number Diff line number Diff line change
@@ -145,7 +145,7 @@
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "https://raw.githubusercontent.com/michelin/i4i-iot-hub-portal/main/templates/portalDeploy.json",
"uri": "https://raw.githubusercontent.com/CGI-FR/iot-hub-portal/main/templates/portalDeploy.json",
"contentVersion": "1.0.0.0"
},
"parameters": {
2 changes: 1 addition & 1 deletion templates/portalDeploy.json
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@
"reserved": true,
"siteConfig": {
"numberOfWorkers": 1,
"linuxFxVersion": "DOCKER|ghcr.io/michelin/iothub-portal:latest",
"linuxFxVersion": "DOCKER|ghcr.io/cgi-fr/iothub-portal:latest",
"connectionStrings": [
{
"name": "IoTHub__ConnectionString",

0 comments on commit e7718da

Please sign in to comment.