Skip to content

Commit

Permalink
Add 4.13 Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-mrq committed May 23, 2024
1 parent 9bdcece commit 28796f6
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 165 deletions.
74 changes: 58 additions & 16 deletions src/IoTHub.Portal.Client/Components/Planning/EditPlanning.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@using IoTHub.Portal.Client.Dialogs.EdgeModels.EdgeModule
@using IoTHub.Portal.Models
@using IoTHub.Portal.Models
@using IoTHub.Portal.Models.v10
@using IoTHub.Portal.Shared.Models.v10
@using IoTHub.Portal.Client.Validators
Expand Down Expand Up @@ -39,7 +38,7 @@
<MudTextField @bind-Value="@planning.Name" For="@(() => planning.Name)" Label="Name" Margin="Margin.Dense" Variant="Variant.Outlined" Required="true" />
</MudItem>
<MudTd DataLabel="Command" Style="text-align: center;">
<MudSelect @bind-Value="@SelectedModel" Label="Device Model" Margin="Margin.Dense" Variant="Variant.Outlined">
<MudSelect @bind-Value="@SelectedModel" Label=" Device Model" Margin="Margin.Dense" Variant="Variant.Outlined" Disabled="@((mode == "New") ? false : true)">
@foreach (string model in CommandDictionary.Keys.ToList())
{
<MudSelectItem Value="@(model)">@model</MudSelectItem>
Expand Down Expand Up @@ -99,7 +98,7 @@
{
if (day != DaysEnumFlag.DaysOfWeek.None)
{
<MudButton id="editPlanningChangeOnDayLayers" Style=@((planning.DayOff & day) != day ? "text-decoration: underline;" : "text-decoration: line-through;") Size="Size.Medium" OnClick="() => ChangeOffDay(day)" Color="@((planning.DayOff & day) != day ? Color.Success : Color.Error)">@day</MudButton>
<MudButton id="editPlanningChangeOnDayLayers" Style=@((planning.DayOff & day) != day ? "" : "text-decoration: line-through;") Size="Size.Medium" OnClick="() => ChangeOffDay(day)" Color="@((planning.DayOff & day) != day ? Color.Success : Color.Error)">@day</MudButton>
}
}
</div>
Expand Down Expand Up @@ -153,7 +152,7 @@
{
if (day != DaysEnumFlag.DaysOfWeek.None)
{
<MudButton id="editPlanningChangeOffDayLayers" Style=@((planning.DayOff & day) == day ? "text-decoration: underline;" : "text-decoration: line-through;") Size="Size.Medium" OnClick="() => ChangeOffDay(day)" Color="@((planning.DayOff & day) == day ? Color.Success : Color.Error)">@day</MudButton>
<MudButton id="editPlanningChangeOffDayLayers" Style=@((planning.DayOff & day) == day ? "text-decoration: underline;" : "") Size="Size.Medium" OnClick="() => ChangeOffDay(day)" Color="@((planning.DayOff & day) == day ? Color.Success : Color.Error)">@day</MudButton>
}
}
</div>
Expand Down Expand Up @@ -285,6 +284,7 @@

public async void Save()
{
if (!areDataValid()) return;
await SavePlanning();
await SaveLayers(Layers);
NavigationManager.NavigateTo($"/planning");
Expand Down Expand Up @@ -332,11 +332,7 @@
foreach (LayerHash layer in saveLayers)
{
await LayerClientService.UpdateLayer(layer.LayerData);

if (layer.Children.Count() != 0)
{
await SaveLayers(layer.Children);
}
await SaveLayers(layer.Children);
}
}
catch (ProblemDetailsException exception)
Expand All @@ -350,20 +346,17 @@
if (item.LayerData.Planning == planning.Id) item.LayerData.Planning = "None";
else item.LayerData.Planning = planning.Id;

if (item.Children.Count() != 0)
foreach (LayerHash child in item.Children)
{
foreach (LayerHash child in item.Children)
{
CheckedChanged(child);
}
CheckedChanged(child);
}
}

private async Task LoadCommands()
{
DeviceModels = (await DeviceModelsClientService.GetDeviceModels(new DeviceModelFilter())).Items.ToList<IDeviceModel>();

foreach(var deviceModel in DeviceModels)
foreach (var deviceModel in DeviceModels)
{
// Load all commands for a particular Device Model
IList<DeviceModelCommandDto> commandList = await LoRaWanDeviceModelsClientService.GetDeviceModelCommands(deviceModel.ModelId);
Expand All @@ -376,4 +369,53 @@
if (isDeviceSelected != null) SelectedModel = deviceModel.Name;
}
}

private bool areDataValid()
{
var errorMessage = "";
if (string.IsNullOrEmpty(planning.Name)) errorMessage += " - Name is empty";
if (string.IsNullOrEmpty(planning.CommandId)) errorMessage += " - Day off command is empty";
if (string.IsNullOrEmpty(planning.Start) || string.IsNullOrEmpty(planning.End)) errorMessage += " - Date of application are empty";

var commandMissing = 0;
var scheduleStartEnd = new List<List<string>>();
foreach (var schedule in scheduleList)
{
if (string.IsNullOrEmpty(schedule.CommandId)) commandMissing += 1;
scheduleStartEnd.Add(new List<string> { schedule.Start, schedule.End });
}

if (commandMissing != 0) errorMessage += commandMissing.ToString() + " - Buisiness day command missing";

errorMessage += CheckSceduleTimeline(scheduleStartEnd);

if (string.IsNullOrEmpty(errorMessage)) return true;

Snackbar.Add($"Some data are missing{errorMessage}", Severity.Error, null);
return false;
}

private string CheckSceduleTimeline(List<List<string>> listSchedule)
{
var connections = new Dictionary<string, string>();

foreach (var pair in listSchedule)
{
if (string.IsNullOrEmpty(pair[0]) | string.IsNullOrEmpty(pair[1])) return " - Business Day is not fully completed";
connections[pair[0]] = pair[1];
}

var start = listSchedule[0][0];
var end = listSchedule[0][1];
while (connections.ContainsKey(end))
{
connections[start] = connections[end];
connections.Remove(end);
end = connections[start];
}

if (connections.Count != 1) return " - Business Day is not fully completed";
return "";
}

}
40 changes: 0 additions & 40 deletions src/IoTHub.Portal.Client/Dialogs/Layer/DeleteLayerDialog.razor

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@using IoTHub.Portal.Models.v10
@using IoTHub.Portal.Shared.Models.v10.Filters
@using IoTHub.Portal.Shared.Models
@using System.Web

@inject ISnackbar Snackbar
@inject IEdgeDeviceClientService EdgeDeviceClientService
Expand All @@ -11,7 +12,11 @@

<MudDialog MaxWidth="800px" MaxHeight="600px">
<DialogContent>
<MudTextField @bind-Value="@Layer.Name" For="@(() => Layer.Name)" />
<MudGrid>
<MudItem xs="12" md="6">
<MudTextField @bind-Value="@LayerName" For="@(() => LayerName)" />
</MudItem>
</MudGrid>
<MudGrid>
<MudItem xs="12" xd="12">
@if (!IsLoading)
Expand All @@ -23,10 +28,10 @@
<MudSelectItem Value="@(model)">@model.Name</MudSelectItem>
}
</MudSelect>
<MudButton Variant="Variant.Filled" Class="mx-1" Color="Color.Primary" OnClick="LoadItems" id="saveButton">Search</MudButton>
<MudButton Variant="Variant.Filled" Class="mx-1" Color="Color.Primary" OnClick="Search" id="saveButton">Search</MudButton>
</div>
}
<MudTable T="DeviceListItem" Items="@Devices" Dense=true Hover=true Loading="@IsLoading" Bordered=true Striped=true RowStyle="cursor: pointer;">
<MudTable T="DeviceListItem" ServerData=@LoadItems Dense=true Hover=true Bordered=true Striped=true @ref="table" Loading="@IsLoading" RowStyle="cursor: pointer;">
<ColGroup>
<col style="width: 10%;" />
<col style="width: 70%;" />
Expand All @@ -47,20 +52,24 @@
</MudItem>
</MudTd>
<MudTd DataLabel="Delete" Style="text-align: center">
<MudTooltip Text="Delete device">
@if ((context.LayerId != null && context.LayerId == Layer.Id) || DeviceList.Contains(context.DeviceID))
{
@if ((context.LayerId != null && context.LayerId == InitLayer.Id) || DeviceList.Contains(context.DeviceID))
{
<MudTooltip Text="Already registered">
<MudIconButton Color="Color.Success" Icon="@Icons.Material.Filled.CheckBox" Size="Size.Medium" @onclick="() => UpdateChecked(context)"></MudIconButton>
}
else if (context.LayerId != null && context.LayerId.Contains('-'))
{
</MudTooltip>
}
else if (context.LayerId != null && context.LayerId.Contains('-'))
{
<MudTooltip Text="Registered on other Layer">
<MudIconButton Color="Color.Error" Icon="@Icons.Material.Filled.IndeterminateCheckBox" Size="Size.Medium" @onclick="() => UpdateChecked(context)"></MudIconButton>
}
else
{
</MudTooltip>
}
else
{
<MudTooltip Text="Add device">
<MudIconButton Color="Color.Default" Icon="@Icons.Material.Filled.CheckBoxOutlineBlank" Size="Size.Medium" @onclick="() => UpdateChecked(context)"></MudIconButton>
}
</MudTooltip>
</MudTooltip>
}
</MudTd>
</RowTemplate>
<NoRecordsContent>
Expand All @@ -69,6 +78,9 @@
<LoadingContent>
<MudText>Loading...</MudText>
</LoadingContent>
<PagerContent>
<MudTablePager PageSizeOptions="new int[] { 5, 10 }" />
</PagerContent>
</MudTable>
</MudItem>
</MudGrid>
Expand All @@ -85,12 +97,19 @@

[CascadingParameter] MudDialogInstance MudDialog { get; set; } = default!;

[Parameter] public LayerDto Layer { get; set; } = default!;
[Parameter] public LayerDto InitLayer { get; set; } = default!;
[Parameter] public HashSet<LayerHash> LayerList { get; set; } = default!;

public string LayerName { get; set; } = default!;

private IEnumerable<DeviceListItem> Devices { get; set; } = new List<DeviceListItem>();
private MudTable<DeviceListItem>? table;

private string? searchID = "";

public IDeviceModel SelectedModel = new DeviceModelDto();
public IEnumerable<IDeviceModel> DeviceModels = new List<IDeviceModel>();
public bool modelIdLoad;

public List<string> DeviceList { get; set; } = new List<string>();
public List<string> DeviceRemoveList { get; set; } = new List<string>();
Expand All @@ -101,47 +120,62 @@

protected override async Task OnInitializedAsync()
{
LayerName = InitLayer.Name;
var filter = new DeviceModelFilter
{
SearchText = "",
PageNumber = 0,
PageSize = 100,
OrderBy = new string[]
{
{
string.Empty
}
}
};

DeviceModels = (await DeviceModelsClientService.GetDeviceModels(filter)).Items.ToList<IDeviceModel>();

await LoadItems();

if (DeviceModels.Count() != 0) SelectedModel = DeviceModels.First();

IsLoading = false;
}

public async Task LoadItems()
private void Search()
{
modelIdLoad = true;
table?.ReloadServerData();
}

private async Task<TableData<DeviceListItem>> LoadItems(TableState state)
{
try
{
string uri = $"api/devices?pageNumber=0&pageSize=10000";

if (!IsLoading) uri = uri + "&modelId=" + SelectedModel.ModelId;
var uri = $"api/devices?pageNumber={state.Page}&pageSize={state.PageSize}&searchText={HttpUtility.UrlEncode(searchID)}";
if (modelIdLoad) uri += $"&modelId={SelectedModel.ModelId}";

var result = await DeviceClientService.GetDevices(uri);

Devices = result.Items;

return new TableData<DeviceListItem>
{
Items = result.Items,
TotalItems = result.TotalItems
};
}
catch (ProblemDetailsException exception)
{
Error?.ProcessProblemDetails(exception);

return new TableData<DeviceListItem>();
}
finally
{
IsLoading = false;
}
}

public void UpdateChecked(DeviceListItem device)
{
if (device.LayerId != null && device.LayerId == Layer.Id)
if (device.LayerId != null && device.LayerId == InitLayer.Id)
{
if (DeviceRemoveList.Contains(device.DeviceID)) DeviceRemoveList.Remove(device.DeviceID);
else DeviceRemoveList.Add(device.DeviceID);
Expand All @@ -157,7 +191,8 @@
{
try
{
await LayerClientService.UpdateLayer(Layer);
InitLayer.Name = LayerName;
await LayerClientService.UpdateLayer(InitLayer);
List<DeviceDetails> devices = new List<DeviceDetails>();
foreach (string deviceRemove in DeviceRemoveList)
{
Expand All @@ -168,7 +203,7 @@
foreach (string device in DeviceList)
{
DeviceDetails updatedDevice = FindDevice(device);
updatedDevice.LayerId = Layer.Id;
updatedDevice.LayerId = InitLayer.Id;
await DeviceClientService.UpdateDevice(updatedDevice);
}
}
Expand All @@ -178,7 +213,7 @@
}
finally
{
MudDialog.Close(DialogResult.Ok(Layer.Name));
MudDialog.Close(DialogResult.Ok(InitLayer.Name));
}
}

Expand All @@ -192,20 +227,14 @@

deviceDetails.DeviceID = device.DeviceID;
deviceDetails.DeviceName = device.DeviceName;
deviceDetails.ModelId = device.DeviceModelId;
deviceDetails.ImageUrl = device.ImageUrl;
deviceDetails.IsConnected = device.IsConnected;
deviceDetails.IsEnabled = device.IsEnabled;
deviceDetails.StatusUpdatedTime = device.StatusUpdatedTime;
deviceDetails.Labels = device.Labels.ToList();
deviceDetails.LayerId = device.LayerId;

var model = DeviceModels.FirstOrDefault(deviceModel => deviceModel.ModelId == device.DeviceModelId);
if (model != null)
{
deviceDetails.ModelId = model.ModelId;
deviceDetails.ModelName = model.Name;
}

return deviceDetails;
}
}
Loading

0 comments on commit 28796f6

Please sign in to comment.