first commit -push
This commit is contained in:
128
RobotNet.WebApp/Robots/Components/OpenACS/ACSLog.razor
Normal file
128
RobotNet.WebApp/Robots/Components/OpenACS/ACSLog.razor
Normal file
@@ -0,0 +1,128 @@
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
@using RobotNet.MapShares.Models
|
||||
|
||||
@inject IConfiguration Configuration
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
|
||||
<div class="data-preview">
|
||||
<div class="d-flex" style="height: fit-content;">
|
||||
<MudTextField Class="mt-1 ms-2 d-flex justify-content-center" T="string" Value="FilterLog" Adornment="Adornment.End" ValueChanged="OnSearch" AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
IconSize="Size.Medium" Variant="Variant.Text" Margin="Margin.Dense" AdornmentColor="Color.Secondary" Label="Search" />
|
||||
<MudSpacer />
|
||||
<div class="m-1 d-flex flex-row">
|
||||
<MudDatePicker Class="mx-4" Label="Date" Date="DateLog" DateChanged="OnDateChanged" MaxDate="DateTime.Today" Variant="Variant.Text" Color="Color.Primary"
|
||||
ShowToolbar="false" Margin="Margin.Dense" AdornmentColor="Color.Primary" />
|
||||
<MudTooltip Text="Refresh">
|
||||
<MudFab Class="mx-4 mt-2" StartIcon="@Icons.Material.Filled.Refresh" Color="Color.Primary" Size="Size.Small" OnClick="@(async() => await LoadLogs(false))" />
|
||||
</MudTooltip>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
<div class="log-container" @ref="LogContainerRef">
|
||||
@foreach (var log in SearchLogs)
|
||||
{
|
||||
<div class="log">
|
||||
<span class="log-head">
|
||||
@log.Time <span class="log-level">@log.Level</span>
|
||||
</span>
|
||||
<span class="@log.ColorClass">@log.Message</span>
|
||||
@if (log.HasException)
|
||||
{
|
||||
<br />
|
||||
<pre class="log-exception">
|
||||
@log.Exception
|
||||
</pre>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudOverlay @bind-Visible="IsLoading" DarkBackground="true" Absolute="true">
|
||||
<MudText Typo="Typo.h1" Color="@Color.Error" Style="font-weight: bold;">Loadding...</MudText>
|
||||
</MudOverlay>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private DateTime DateLog = DateTime.Today;
|
||||
private bool IsLoading;
|
||||
private readonly List<string> ShowLogs = new();
|
||||
private readonly List<LoggerModel> SearchLogs = new();
|
||||
private string? FilterLog { get; set; }
|
||||
private ElementReference LogContainerRef { get; set; }
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
await LoadLogs(true);
|
||||
}
|
||||
|
||||
private async Task LoadLogs(bool firstRender)
|
||||
{
|
||||
try
|
||||
{
|
||||
if(!firstRender)
|
||||
{
|
||||
IsLoading = true;
|
||||
ShowLogs.Clear();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
var Http = HttpClientFactory.CreateClient("RobotManagerAPI");
|
||||
var logs = await Http.GetFromJsonAsync<IEnumerable<string>>($"api/RobotManagerLogger/open-acs?date={DateLog}");
|
||||
ShowLogs.AddRange(logs ?? []);
|
||||
|
||||
IsLoading = false;
|
||||
StateHasChanged();
|
||||
|
||||
await ReloadLogs();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ReloadLogs()
|
||||
{
|
||||
IsLoading = true;
|
||||
SearchLogs.Clear();
|
||||
StateHasChanged();
|
||||
|
||||
foreach (var line in ShowLogs.Where(log => string.IsNullOrEmpty(FilterLog) || log.Contains(FilterLog)).TakeLast(2000))
|
||||
{
|
||||
try
|
||||
{
|
||||
var log = System.Text.Json.JsonSerializer.Deserialize<LoggerModel>(line);
|
||||
if (log is not null) SearchLogs.Add(log);
|
||||
}
|
||||
catch (System.Text.Json.JsonException)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
IsLoading = false;
|
||||
StateHasChanged();
|
||||
await JSRuntime.InvokeVoidAsync("ScrollToBottom", LogContainerRef);
|
||||
}
|
||||
|
||||
private async Task OnSearch(string text)
|
||||
{
|
||||
FilterLog = text;
|
||||
await ReloadLogs();
|
||||
}
|
||||
|
||||
private async Task OnDateChanged(DateTime? date)
|
||||
{
|
||||
if (date is not null && date.HasValue)
|
||||
{
|
||||
DateLog = date.Value;
|
||||
await LoadLogs(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
57
RobotNet.WebApp/Robots/Components/OpenACS/ACSLog.razor.css
Normal file
57
RobotNet.WebApp/Robots/Components/OpenACS/ACSLog.razor.css
Normal file
@@ -0,0 +1,57 @@
|
||||
.data-preview {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
flex-direction: column;
|
||||
border: 1px solid silver;
|
||||
border-radius: 5px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.data-preview .content {
|
||||
display: flex;
|
||||
font-size: 13px;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
flex-grow: 1;
|
||||
padding: 5px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.data-preview .content.log-container {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
padding: 10px;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.log {
|
||||
word-wrap: break-word;
|
||||
line-height: 18px;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
.log-logger {
|
||||
color: rgba(0, 0, 0, 0.3);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.log-level {
|
||||
display: inline-block;
|
||||
width: 46px;
|
||||
}
|
||||
|
||||
.log-head {
|
||||
border-radius: 3px;
|
||||
padding: 2px 5px;
|
||||
}
|
||||
|
||||
.log-exception {
|
||||
line-height: 16px;
|
||||
margin-left: 30px;
|
||||
color: crimson;
|
||||
}
|
||||
111
RobotNet.WebApp/Robots/Components/OpenACS/DashboardConfig.razor
Normal file
111
RobotNet.WebApp/Robots/Components/OpenACS/DashboardConfig.razor
Normal file
@@ -0,0 +1,111 @@
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
|
||||
<MudCard Class="w-100 me-2 position-relative mt-2" Elevation="0" Outlined Style="height: 350px">
|
||||
<MudCardHeader>
|
||||
<MudText Typo="Typo.h5">Dashboard Mission Names</MudText>
|
||||
</MudCardHeader>
|
||||
<MudCardContent>
|
||||
<div class="d-flex flex-column">
|
||||
<div class="d-flex flex-row">
|
||||
<MudTextField Label="Mission Name" Variant="Variant.Outlined" @bind-Value="MissionName" ShrinkLabel />
|
||||
<MudButton Class="mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Info" OnClick="Add">Add</MudButton>
|
||||
</div>
|
||||
<div class="d-flex flex-wrap overflow-x-hidden overflow-y-auto mt-2" style="border: 1px solid silver; height: 115px; border-radius: 5px">
|
||||
@foreach(var missionName in MissionNames)
|
||||
{
|
||||
<div class="m-1" style="height: fit-content">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Tertiary" Style="text-transform:none" OnClick="@(() => MissionNames.Remove(missionName))">
|
||||
@missionName
|
||||
</MudButton>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div class="d-flex flex-row-reverse mt-4">
|
||||
<div>
|
||||
<MudButton Class="d-flex flex-grow-1 mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Info" OnClick="Update">Update</MudButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</MudCardContent>
|
||||
|
||||
<MudOverlay Visible="OverlayIsVisible" DarkBackground="true" Absolute="true">
|
||||
<MudProgressCircular Color="Color.Secondary" Indeterminate="true" />
|
||||
</MudOverlay>
|
||||
</MudCard>
|
||||
|
||||
@code {
|
||||
private List<string> MissionNames = [];
|
||||
private bool OverlayIsVisible;
|
||||
|
||||
private string MissionName = "";
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
await LoadMisison();
|
||||
}
|
||||
|
||||
private async Task LoadMisison()
|
||||
{
|
||||
try
|
||||
{
|
||||
OverlayIsVisible = true;
|
||||
StateHasChanged();
|
||||
|
||||
using var client = HttpClientFactory.CreateClient("ScriptManagerAPI");
|
||||
var mission = await client.GetFromJsonAsync<MessageResult<string[]>>("api/DashboardConfig");
|
||||
if (mission is null || mission.Data is null || !mission.IsSuccess) MissionNames = [];
|
||||
else MissionNames = [.. mission.Data];
|
||||
|
||||
OverlayIsVisible = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Update()
|
||||
{
|
||||
try
|
||||
{
|
||||
OverlayIsVisible = true;
|
||||
StateHasChanged();
|
||||
|
||||
using var Http = HttpClientFactory.CreateClient("ScriptManagerAPI");
|
||||
|
||||
var result = await (await Http.PostAsJsonAsync($"api/DashboardConfig", MissionNames)).Content.ReadFromJsonAsync<MessageResult>();
|
||||
if (result is null) { Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Warning); return; }
|
||||
else if (!result.IsSuccess) { Snackbar.Add(result.Message ?? "Cập nhật không thành công", Severity.Warning); return; }
|
||||
|
||||
OverlayIsVisible = false;
|
||||
Snackbar.Add("Cập nhật thành công", Severity.Success);
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
}
|
||||
}
|
||||
|
||||
private void Add()
|
||||
{
|
||||
if (string.IsNullOrEmpty(MissionName))
|
||||
{
|
||||
Snackbar.Add("Vui lòng nhập mission name", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
if (MissionNames.Contains(MissionName))
|
||||
{
|
||||
Snackbar.Add("Mission name đã tồn tại", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
MissionNames.Add(MissionName);
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
128
RobotNet.WebApp/Robots/Components/OpenACS/PublishSetting.razor
Normal file
128
RobotNet.WebApp/Robots/Components/OpenACS/PublishSetting.razor
Normal file
@@ -0,0 +1,128 @@
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
@using RobotNet.RobotShares.OpenACS
|
||||
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudCard Class="w-100 me-2 position-relative" Elevation="0" Outlined Style="height: 350px">
|
||||
<MudCardHeader>
|
||||
<MudText Typo="Typo.h5">Publish Setting</MudText>
|
||||
</MudCardHeader>
|
||||
<MudCardContent>
|
||||
<div class="d-flex flex-column">
|
||||
<MudSwitch @bind-Value="NewSettingDto.IsPublishEnabled" Color="Color.Primary" Label="Enable" @bind-Value:after="EnableChanged" />
|
||||
<MudAutocomplete T="string" Variant="Variant.Outlined" Label="Url" ShrinkLabel Disabled="@NewSettingDto.IsPublishEnabled" Modal SearchFunc="UrlSearch"
|
||||
CoerceText="false" CoerceValue="true" MaxItems="NewSettingDto.PublishUrlsUsed.Length" ShowProgressIndicator="true" @bind-Value="NewSettingDto.PublishUrl">
|
||||
</MudAutocomplete>
|
||||
<MudNumericField T="int" Label="Interval(ms)" @bind-Value="NewSettingDto.PublishInterval" Disabled="@NewSettingDto.IsPublishEnabled" Variant="Variant.Outlined" Min="500" />
|
||||
<div class="d-flex flex-row-reverse mt-4">
|
||||
<div>
|
||||
<MudButton Class="d-flex flex-grow-1 mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Info" Disabled="@NewSettingDto.IsPublishEnabled" OnClick="Update">Update</MudButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</MudCardContent>
|
||||
|
||||
<MudOverlay Visible="OverlayIsVisible" DarkBackground="true" Absolute="true">
|
||||
<MudProgressCircular Color="Color.Secondary" Indeterminate="true" />
|
||||
</MudOverlay>
|
||||
</MudCard>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public OpenACSPublishSettingDto SettingDto { get; set; } = new(false, "", [], 2000);
|
||||
|
||||
private OpenACSPublishSettingDto NewSettingDto { get; set; } = new(false, "", [], 2000);
|
||||
private bool OverlayIsVisible;
|
||||
|
||||
|
||||
public void UpdateSettings(OpenACSPublishSettingDto settings)
|
||||
{
|
||||
SettingDto = settings;
|
||||
NewSettingDto = new()
|
||||
{
|
||||
IsPublishEnabled = SettingDto.IsPublishEnabled,
|
||||
PublishInterval = SettingDto.PublishInterval,
|
||||
PublishUrl = SettingDto.PublishUrl,
|
||||
PublishUrlsUsed = SettingDto.PublishUrlsUsed,
|
||||
};
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<string>> UrlSearch(string value, CancellationToken token)
|
||||
{
|
||||
await Task.Delay(5, token);
|
||||
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return SettingDto.PublishUrlsUsed;
|
||||
}
|
||||
|
||||
return SettingDto.PublishUrlsUsed.Where(x => x.Contains(value, StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
|
||||
private async Task Update()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (NewSettingDto.PublishUrl == SettingDto.PublishUrl && NewSettingDto.PublishInterval == SettingDto.PublishInterval)
|
||||
{
|
||||
Snackbar.Add("Không có thay đổi nào để cập nhật", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
OverlayIsVisible = true;
|
||||
StateHasChanged();
|
||||
|
||||
using var Http = HttpClientFactory.CreateClient("RobotManagerAPI");
|
||||
|
||||
var result = await (await Http.PostAsJsonAsync($"api/OpenACSSettings/publish", new OpenACSPublishSettingModel(NewSettingDto.PublishUrl, NewSettingDto.PublishInterval))).Content.ReadFromJsonAsync<MessageResult<OpenACSPublishSettingDto>>();
|
||||
if (result is null) { Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Warning); return; }
|
||||
else if (!result.IsSuccess) { Snackbar.Add(result.Message ?? "Cập nhật không thành công", Severity.Warning); return; }
|
||||
else if (result.Data == null)
|
||||
{
|
||||
Snackbar.Add("Lỗi dữ liệu trả về", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
SettingDto = result.Data;
|
||||
NewSettingDto = new()
|
||||
{
|
||||
IsPublishEnabled = SettingDto.IsPublishEnabled,
|
||||
PublishInterval = SettingDto.PublishInterval,
|
||||
PublishUrl = SettingDto.PublishUrl,
|
||||
PublishUrlsUsed = SettingDto.PublishUrlsUsed,
|
||||
};
|
||||
|
||||
OverlayIsVisible = false;
|
||||
Snackbar.Add("Cập nhật thành công", Severity.Success);
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task EnableChanged()
|
||||
{
|
||||
try
|
||||
{
|
||||
OverlayIsVisible = true;
|
||||
StateHasChanged();
|
||||
|
||||
using var Http = HttpClientFactory.CreateClient("RobotManagerAPI");
|
||||
var result = await Http.GetFromJsonAsync<MessageResult>($"api/OpenACSSettings/publish?enable={NewSettingDto.IsPublishEnabled}");
|
||||
if (result is null) { Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error); return; }
|
||||
else if (!result.IsSuccess) { Snackbar.Add(result.Message ?? "Cập nhật không thành công", Severity.Warning); return; }
|
||||
|
||||
SettingDto.IsPublishEnabled = NewSettingDto.IsPublishEnabled;
|
||||
|
||||
OverlayIsVisible = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
@using RobotNet.RobotShares.OpenACS
|
||||
|
||||
@inject IHttpClientFactory HttpFactory
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<div class="view-paper">
|
||||
<div class="d-flex" style="height: fit-content;">
|
||||
<MudSelect Class="mt-1 ms-2 d-flex justify-content-center" T="RobotACSLockedDto" Adornment="Adornment.End" @bind-Value="RobotSeleced"
|
||||
IconSize="Size.Medium" Variant="Variant.Text" Margin="Margin.Dense" AdornmentColor="Color.Secondary" Label="Robot">
|
||||
@foreach(var robot in RobotACSLockedDto)
|
||||
{
|
||||
<MudSelectItem Value="robot">@robot.RobotId</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudSpacer />
|
||||
<div class="m-1 d-flex flex-row">
|
||||
<MudTooltip Text="Refresh">
|
||||
<MudFab Class="mx-4 mt-2" StartIcon="@Icons.Material.Filled.Refresh" Color="Color.Primary" Size="Size.Small" OnClick="@(async () => await LoadRobots())" />
|
||||
</MudTooltip>
|
||||
</div>
|
||||
</div>
|
||||
<div class="content">
|
||||
@if(RobotSeleced is not null)
|
||||
{
|
||||
foreach(var zone in RobotSeleced.ZoneIds)
|
||||
{
|
||||
<div class="zone">
|
||||
<span>@zone</span>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private RobotACSLockedDto[] RobotACSLockedDto = [];
|
||||
private RobotACSLockedDto? RobotSeleced = null;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
await LoadRobots();
|
||||
}
|
||||
|
||||
private async Task LoadRobots()
|
||||
{
|
||||
RobotACSLockedDto = [];
|
||||
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
|
||||
var robots = await Http.GetFromJsonAsync<RobotACSLockedDto[]>("api/TrafficACSRequest");
|
||||
if (robots is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (robots.Length > 0)
|
||||
{
|
||||
RobotACSLockedDto = [..robots.OrderByDescending(robot => robot.RobotId)];
|
||||
RobotSeleced = RobotACSLockedDto.First();
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
.view-paper {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: 1px solid silver;
|
||||
border-radius: 5px;
|
||||
position: relative;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.view-paper .content {
|
||||
display: flex;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
flex-grow: 1;
|
||||
padding: 5px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.view-paper .content .zone {
|
||||
margin: 5px;
|
||||
border: 1px solid silver;
|
||||
padding: 5px;
|
||||
height: fit-content;
|
||||
width: fit-content;
|
||||
font-size: 13px;
|
||||
border-radius: 5px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
104
RobotNet.WebApp/Robots/Components/OpenACS/TrafficRequest.razor
Normal file
104
RobotNet.WebApp/Robots/Components/OpenACS/TrafficRequest.razor
Normal file
@@ -0,0 +1,104 @@
|
||||
@using RobotNet.RobotShares.OpenACS
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
|
||||
<MudCard Class="w-100 me-2 position-relative mt-2" Elevation="0" Outlined Style="height: 370px">
|
||||
<MudCardHeader>
|
||||
<MudText Typo="Typo.h5">Traffic Request</MudText>
|
||||
</MudCardHeader>
|
||||
<MudCardContent>
|
||||
<div class="d-flex flex-column">
|
||||
<MudAutocomplete T="string" Variant="Variant.Outlined" Label="Robot Id" ShrinkLabel Modal SearchFunc="UrlSearch"
|
||||
CoerceText="false" CoerceValue="true" MaxItems="Robots.Length" ShowProgressIndicator="true" @bind-Value="RobotId">
|
||||
</MudAutocomplete>
|
||||
<MudTextField Label="Zone Id" Variant="Variant.Outlined" @bind-Value="ZoneId" ShrinkLabel />
|
||||
<MudSelect T="TrafficRequestType" Label="Type" @bind-Value="@Type" Variant="Variant.Outlined">
|
||||
@foreach (TrafficRequestType item in Enum.GetValues(typeof(TrafficRequestType)))
|
||||
{
|
||||
<MudSelectItem Value="@item" />
|
||||
}
|
||||
</MudSelect>
|
||||
<div class="d-flex flex-row-reverse mt-4">
|
||||
<div>
|
||||
<MudButton Class="d-flex flex-grow-1 mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Info" OnClick="Request">Request</MudButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</MudCardContent>
|
||||
|
||||
<MudOverlay Visible="OverlayIsVisible" DarkBackground="true" Absolute="true">
|
||||
<MudProgressCircular Color="Color.Secondary" Indeterminate="true" />
|
||||
</MudOverlay>
|
||||
</MudCard>
|
||||
|
||||
@code {
|
||||
private bool OverlayIsVisible;
|
||||
|
||||
private RobotDto[] Robots = [];
|
||||
private string RobotId = string.Empty;
|
||||
private string ZoneId = string.Empty;
|
||||
private TrafficRequestType Type = TrafficRequestType.OUT;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
await LoadRobots();
|
||||
}
|
||||
|
||||
private async Task LoadRobots()
|
||||
{
|
||||
OverlayIsVisible = true;
|
||||
StateHasChanged();
|
||||
|
||||
using var Http = HttpClientFactory.CreateClient("RobotManagerAPI");
|
||||
var robots = await Http.GetFromJsonAsync<MessageResult<IEnumerable<RobotDto>>>("api/Robots");
|
||||
if (robots is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!robots.IsSuccess) Snackbar.Add($"Có lỗi xảy ra: {robots.Message}", Severity.Error);
|
||||
else if (robots.Data is not null && robots.Data.Any())
|
||||
{
|
||||
Robots = [..robots.Data];
|
||||
}
|
||||
OverlayIsVisible = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
|
||||
private async Task<IEnumerable<string>> UrlSearch(string value, CancellationToken token)
|
||||
{
|
||||
await Task.Delay(5, token);
|
||||
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return Robots.Select(n => n.Name);
|
||||
}
|
||||
|
||||
return Robots.Where(x => x.Name.Contains(value, StringComparison.InvariantCultureIgnoreCase)).Select(n => n.Name);
|
||||
}
|
||||
|
||||
private async Task Request()
|
||||
{
|
||||
if(string.IsNullOrEmpty(RobotId))
|
||||
{
|
||||
Snackbar.Add($"Trường thông tin Robot Id không được để trống", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(ZoneId))
|
||||
{
|
||||
Snackbar.Add($"Trường thông tin Zone Id không được để trống", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
OverlayIsVisible = true;
|
||||
StateHasChanged();
|
||||
using var Http = HttpClientFactory.CreateClient("RobotManagerAPI");
|
||||
var request = await (await Http.PostAsJsonAsync("api/TrafficACSRequest", new TrafficACSRequestModel() { RobotId = RobotId, ZoneId = ZoneId, Type = Type})).Content.ReadFromJsonAsync<MessageResult<bool>>();
|
||||
if (request is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Warning);
|
||||
else if (!request.IsSuccess) Snackbar.Add($"Có lỗi xảy ra: {request.Message}", Severity.Warning);
|
||||
else if (!request.Data) Snackbar.Add("ACS trả về không thành công thành công", Severity.Warning);
|
||||
else if (request.Data) Snackbar.Add($"{(string.IsNullOrEmpty(request.Message) ? "Yêu cầu thành công" : request.Message)}", Severity.Success);
|
||||
|
||||
OverlayIsVisible = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
124
RobotNet.WebApp/Robots/Components/OpenACS/TrafficSetting.razor
Normal file
124
RobotNet.WebApp/Robots/Components/OpenACS/TrafficSetting.razor
Normal file
@@ -0,0 +1,124 @@
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
@using RobotNet.RobotShares.OpenACS
|
||||
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<MudCard Class="w-100 me-2 position-relative mt-2" Elevation="0" Outlined Style="height: 280px">
|
||||
<MudCardHeader>
|
||||
<MudText Typo="Typo.h5">Traffic Setting</MudText>
|
||||
</MudCardHeader>
|
||||
<MudCardContent>
|
||||
<div class="d-flex flex-column">
|
||||
<MudSwitch @bind-Value="NewSettingDto.IsTrafficEnabled" Color="Color.Primary" Label="Enable" @bind-Value:after="EnableChanged" />
|
||||
<MudAutocomplete T="string" Variant="Variant.Outlined" Label="Url" ShrinkLabel Disabled="@NewSettingDto.IsTrafficEnabled" Modal SearchFunc="UrlSearch"
|
||||
CoerceText="false" CoerceValue="true" MaxItems="NewSettingDto.PublishUrlsUsed.Length" ShowProgressIndicator="true" @bind-Value="NewSettingDto.TrafficUrl">
|
||||
</MudAutocomplete>
|
||||
<div class="d-flex flex-row-reverse mt-4">
|
||||
<div>
|
||||
<MudButton Class="d-flex flex-grow-1 mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Info" Disabled="@NewSettingDto.IsTrafficEnabled" OnClick="Update">Update</MudButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</MudCardContent>
|
||||
|
||||
<MudOverlay Visible="OverlayIsVisible" DarkBackground="true" Absolute="true">
|
||||
<MudProgressCircular Color="Color.Secondary" Indeterminate="true" />
|
||||
</MudOverlay>
|
||||
</MudCard>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public OpenACSTrafficSettingDto SettingDto { get; set; } = new(false, "", []);
|
||||
|
||||
private OpenACSTrafficSettingDto NewSettingDto { get; set; } = new(false, "", []);
|
||||
private bool OverlayIsVisible;
|
||||
|
||||
public void UpdateSettings(OpenACSTrafficSettingDto settings)
|
||||
{
|
||||
SettingDto = settings;
|
||||
NewSettingDto = new()
|
||||
{
|
||||
IsTrafficEnabled = SettingDto.IsTrafficEnabled,
|
||||
TrafficUrl = SettingDto.TrafficUrl,
|
||||
PublishUrlsUsed = SettingDto.PublishUrlsUsed,
|
||||
};
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<string>> UrlSearch(string value, CancellationToken token)
|
||||
{
|
||||
await Task.Delay(5, token);
|
||||
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return SettingDto.PublishUrlsUsed;
|
||||
}
|
||||
|
||||
return SettingDto.PublishUrlsUsed.Where(x => x.Contains(value, StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
|
||||
private async Task Update()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (NewSettingDto.TrafficUrl == SettingDto.TrafficUrl)
|
||||
{
|
||||
Snackbar.Add("Không có thay đổi nào để cập nhật", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
OverlayIsVisible = true;
|
||||
StateHasChanged();
|
||||
|
||||
using var Http = HttpClientFactory.CreateClient("RobotManagerAPI");
|
||||
|
||||
var result = await (await Http.PostAsJsonAsync($"api/OpenACSSettings/traffic", new OpenACSTrafficSettingModel(NewSettingDto.TrafficUrl))).Content.ReadFromJsonAsync<MessageResult<OpenACSTrafficSettingDto>>();
|
||||
if (result is null) { Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Warning); return; }
|
||||
else if (!result.IsSuccess) { Snackbar.Add(result.Message ?? "Cập nhật không thành công", Severity.Warning); return; }
|
||||
else if (result.Data == null)
|
||||
{
|
||||
Snackbar.Add("Lỗi dữ liệu trả về", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
SettingDto = result.Data;
|
||||
NewSettingDto = new()
|
||||
{
|
||||
IsTrafficEnabled = SettingDto.IsTrafficEnabled,
|
||||
TrafficUrl = SettingDto.TrafficUrl,
|
||||
PublishUrlsUsed = SettingDto.PublishUrlsUsed,
|
||||
};
|
||||
|
||||
OverlayIsVisible = false;
|
||||
Snackbar.Add("Cập nhật thành công", Severity.Success);
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task EnableChanged()
|
||||
{
|
||||
try
|
||||
{
|
||||
OverlayIsVisible = true;
|
||||
StateHasChanged();
|
||||
|
||||
using var Http = HttpClientFactory.CreateClient("RobotManagerAPI");
|
||||
var result = await Http.GetFromJsonAsync<MessageResult>($"api/OpenACSSettings/traffic?enable={NewSettingDto.IsTrafficEnabled}");
|
||||
if (result is null) { Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Warning); return; }
|
||||
else if (!result.IsSuccess) { Snackbar.Add(result.Message ?? "Cập nhật không thành công", Severity.Warning); return; }
|
||||
|
||||
SettingDto.IsTrafficEnabled = NewSettingDto.IsTrafficEnabled;
|
||||
|
||||
OverlayIsVisible = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user