first commit -push
This commit is contained in:
7
RobotNet.WebApp/Pages/Authentication.razor
Normal file
7
RobotNet.WebApp/Pages/Authentication.razor
Normal file
@@ -0,0 +1,7 @@
|
||||
@page "/authentication/{action}"
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
<RemoteAuthenticatorView Action="@Action" />
|
||||
|
||||
@code{
|
||||
[Parameter] public string? Action { get; set; }
|
||||
}
|
||||
105
RobotNet.WebApp/Pages/Dashboard.razor
Normal file
105
RobotNet.WebApp/Pages/Dashboard.razor
Normal file
@@ -0,0 +1,105 @@
|
||||
@page "/"
|
||||
@attribute [Authorize]
|
||||
|
||||
@using RobotNet.Script.Shares.Dashboard
|
||||
@using RobotNet.WebApp.Clients
|
||||
@using RobotNet.WebApp.Dashboard.Components
|
||||
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject NavigationManager Nav
|
||||
@inject DashboardHubClient DashboardHub
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>Dashboard</PageTitle>
|
||||
|
||||
<div class="d-flex w-100 h-100 flex-column overflow-hidden p-2">
|
||||
<div class="dashboard-title">
|
||||
<span>AMR MONITORING</span>
|
||||
<div class="button-group">
|
||||
<span class="me-4" style="font-size: 20px;">@timeUpdate</span>
|
||||
<div>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Refresh" Variant="Variant.Filled" OnClick="GetDashboardData" Color="Color.Info" />
|
||||
</div>
|
||||
<div>
|
||||
<MudIconButton Class="mx-4" Icon="@Icons.Material.Filled.ZoomOutMap" OnClick="ToogleFullScreen" Variant="Variant.Filled" Color="Color.Info" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="dashboard-content">
|
||||
<div class="daily-data">
|
||||
<DailyData @ref="DailyDataRef" />
|
||||
</div>
|
||||
<div class="charts">
|
||||
<div class="performance-chart">
|
||||
<div class="daily-performance-chart">
|
||||
<PerformancePieChart @ref="TodayPerformancePieChartRef" ChartName="Today's AMR Performance" />
|
||||
</div>
|
||||
<div class="weeky-performance-chart">
|
||||
<PerformancePieChart @ref="WeekyPerformancePieChartRef" ChartName="Weekly AMR Performance" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="weely-overall-chart">
|
||||
<div class="mission-bar-chart">
|
||||
<MissionsPerformanceBarChart @ref="MissionsPerformanceBarChartRef" />
|
||||
</div>
|
||||
<div class="takt-time-chart">
|
||||
<TaktTimeLineChart @ref="TaktTimeLineChartRef" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private bool isFullScreen = false;
|
||||
|
||||
private DailyData DailyDataRef = default!;
|
||||
private PerformancePieChart TodayPerformancePieChartRef = default!;
|
||||
private PerformancePieChart WeekyPerformancePieChartRef = default!;
|
||||
private MissionsPerformanceBarChart MissionsPerformanceBarChartRef = default!;
|
||||
private TaktTimeLineChart TaktTimeLineChartRef = default!;
|
||||
|
||||
private string timeUpdate = "";
|
||||
|
||||
private async Task ToogleFullScreen()
|
||||
{
|
||||
await JSRuntime.InvokeVoidAsync("setFullscreen", isFullScreen ? false : true);
|
||||
isFullScreen = isFullScreen ? false : true;
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
DashboardHub.DashboardDataUpdated += (async (value) => await DashboardHub_DashboardDataUpdated(value));
|
||||
await DashboardHub.StartAsync();
|
||||
await GetDashboardData();
|
||||
}
|
||||
|
||||
private async Task GetDashboardData()
|
||||
{
|
||||
var dashboardData = await DashboardHub.GetDashboardData();
|
||||
if (dashboardData.IsSuccess && dashboardData.Data is not null)
|
||||
{
|
||||
timeUpdate = dashboardData.Data.TimeUpdate;
|
||||
DailyDataRef.UpdateData(dashboardData.Data.DailyMission);
|
||||
await TodayPerformancePieChartRef.UpdateData(dashboardData.Data.TodayPerformance);
|
||||
await WeekyPerformancePieChartRef.UpdateData(dashboardData.Data.ThisWeekPerformance);
|
||||
await MissionsPerformanceBarChartRef.UpdateData(dashboardData.Data.TotalMissionPerformance);
|
||||
await TaktTimeLineChartRef.UpdateData(dashboardData.Data.TaktTimeMissions);
|
||||
}
|
||||
else Snackbar.Add($"{(string.IsNullOrEmpty(dashboardData.Message) ? "Có lỗi xảy ra khi lấy dữ liệu dashboard" : dashboardData.Message)}");
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task DashboardHub_DashboardDataUpdated(DashboardDto data)
|
||||
{
|
||||
timeUpdate = data.TimeUpdate;
|
||||
DailyDataRef.UpdateData(data.DailyMission);
|
||||
await TodayPerformancePieChartRef.UpdateData(data.TodayPerformance);
|
||||
await WeekyPerformancePieChartRef.UpdateData(data.ThisWeekPerformance);
|
||||
await MissionsPerformanceBarChartRef.UpdateData(data.TotalMissionPerformance);
|
||||
await TaktTimeLineChartRef.UpdateData(data.TaktTimeMissions);
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
115
RobotNet.WebApp/Pages/Dashboard.razor.css
Normal file
115
RobotNet.WebApp/Pages/Dashboard.razor.css
Normal file
@@ -0,0 +1,115 @@
|
||||
.dashboard-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
width: 100%;
|
||||
margin-bottom: 20px;
|
||||
height: 54px;
|
||||
background: linear-gradient(to right, rgb(5, 39, 103) 0%, #3a0647 70%);
|
||||
border-radius: 15px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
||||
padding: 0 1.5rem;
|
||||
transition: all 0.3s ease;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||||
}
|
||||
.dashboard-title:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
|
||||
}
|
||||
|
||||
.dashboard-title::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 2px;
|
||||
background: linear-gradient(to right, rgb(5, 39, 103) 0%, #3a0647 70%);
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.dashboard-title span {
|
||||
font-family: var(--dashboard-text-font-family);
|
||||
color: var(--dashboard-text-white-color);
|
||||
font-size: 40px;
|
||||
align-items: center;
|
||||
display: flex;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.dashboard-title .button-group {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin-right: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
|
||||
.dashboard-content {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
flex-grow: 1;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.dashboard-content .daily-data {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
height: 18%;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.dashboard-content .charts {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
flex-grow: 1;
|
||||
height: 82%;
|
||||
flex-direction: row;
|
||||
position: relative;
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
.dashboard-content .charts .performance-chart {
|
||||
display: flex;
|
||||
width: 36.9%;
|
||||
height: 100%;
|
||||
flex-direction: column;
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
.dashboard-content .charts .performance-chart .daily-performance-chart {
|
||||
width: 100%;
|
||||
height: 48.5%;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.dashboard-content .charts .performance-chart .weeky-performance-chart {
|
||||
width: 100%;
|
||||
height: 48.5%;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
|
||||
|
||||
.dashboard-content .charts .weely-overall-chart {
|
||||
display: flex;
|
||||
flex-grow: 1;
|
||||
width: 62%;
|
||||
height: 100%;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.dashboard-content .charts .weely-overall-chart .mission-bar-chart {
|
||||
width: 100%;
|
||||
height: 48.5%;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.dashboard-content .charts .weely-overall-chart .takt-time-chart {
|
||||
width: 100%;
|
||||
height: 48.5%;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
192
RobotNet.WebApp/Pages/Logs.razor
Normal file
192
RobotNet.WebApp/Pages/Logs.razor
Normal file
@@ -0,0 +1,192 @@
|
||||
@page "/logs"
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
@using RobotNet.MapShares.Models
|
||||
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
@inject IConfiguration Configuration
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>Logs</PageTitle>
|
||||
|
||||
<div class="w-100 h-100 d-flex flex-column">
|
||||
<div class="d-flex flex-row align-items-center justify-content-between" style="border-bottom: 1px solid silver">
|
||||
<MudTextField Class="mt-1 ms-2" T="string" Value="FilterLog" Adornment="Adornment.End" ValueChanged="OnSearch" AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
IconSize="Size.Medium" Variant="Variant.Outlined" Margin="Margin.Dense" AdornmentColor="Color.Secondary" Label="Search"></MudTextField>
|
||||
<MudSpacer />
|
||||
<div class="m-1 d-flex flex-row">
|
||||
<MudSelect T="LogConfiguration" Label="Proccess" AnchorOrigin="Origin.BottomLeft" @bind-Value="LogProccessSelected" @bind-Value:after="LoadLogs" Variant="Variant.Outlined" Margin="Margin.Dense" Style="width: 200px">
|
||||
@foreach (var proccess in LogsProccess)
|
||||
{
|
||||
<MudSelectItem Value="@proccess">@proccess.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudDatePicker Class="mx-4" Label="Date" Date="DateLog" DateChanged="OnDateChanged" MaxDate="DateTime.Today" Variant="Variant.Outlined" Color="Color.Primary"
|
||||
ShowToolbar="false" Margin="Margin.Dense" AdornmentColor="Color.Primary" />
|
||||
|
||||
<MudTooltip Text="Export">
|
||||
<MudFab Class="mt-2" Color="Color.Info" StartIcon="@Icons.Material.Filled.ImportExport" Size="Size.Small" OnClick="ExportLogs" />
|
||||
</MudTooltip>
|
||||
<MudTooltip Text="Refresh">
|
||||
<MudFab Class="mx-4 mt-2" StartIcon="@Icons.Material.Filled.Refresh" Color="Color.Primary" Size="Size.Small" OnClick="LoadLogs" />
|
||||
</MudTooltip>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex-grow-1 mt-2 ms-2" style="background-color: rgba(0, 0, 0, 0);">
|
||||
<MudOverlay Visible="IsLoading" DarkBackground="true" Absolute="true">
|
||||
<MudProgressCircular Color="Color.Info" Indeterminate="true" />
|
||||
</MudOverlay>
|
||||
<div class="h-100 w-100 position-relative">
|
||||
<div class="log-container" @ref="LogContainerRef">
|
||||
@if (ShowRawLog)
|
||||
{
|
||||
<div class="d-flex justify-content-center my-3">
|
||||
<div><MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="@(() => ShowRawLog = false)">Normal</MudButton></div>
|
||||
</div>
|
||||
<big style="font-size: 14px;">
|
||||
@foreach (var log in ShowLogs)
|
||||
{
|
||||
@log <br />
|
||||
}
|
||||
</big>
|
||||
}
|
||||
else
|
||||
{
|
||||
@if (SearchLogs.Count < ShowLogs.Count)
|
||||
{
|
||||
<div class="d-flex justify-content-center my-3">
|
||||
<div><MudButton Variant="Variant.Outlined" Size="Size.Small" OnClick="@(() => ShowRawLog = true)">Raw log</MudButton></div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@foreach (var log in SearchLogs)
|
||||
{
|
||||
<div class="log">
|
||||
<span class="log-head @log.BackgroundClass">
|
||||
@log.Time <span class="log-level">@log.Level</span>
|
||||
</span>
|
||||
<span>@log.Message</span>
|
||||
@if (log.HasException)
|
||||
{
|
||||
<br />
|
||||
<pre class="log-exception">
|
||||
@log.Exception
|
||||
</pre>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@code {
|
||||
private DateTime DateLog = DateTime.Today;
|
||||
private bool IsLoading;
|
||||
private readonly List<string> ShowLogs = new();
|
||||
private readonly List<LoggerModel> SearchLogs = new();
|
||||
private ElementReference LogContainerRef { get; set; }
|
||||
private bool ShowRawLog { get; set; }
|
||||
private string? FilterLog { get; set; }
|
||||
|
||||
private List<LogConfiguration> LogsProccess = [];
|
||||
private LogConfiguration LogProccessSelected = new();
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
LogsProccess = Configuration.GetSection("Logs").Get<List<LogConfiguration>>() ?? [];
|
||||
LogProccessSelected = LogsProccess.FirstOrDefault() ?? new LogConfiguration();
|
||||
await LoadLogs();
|
||||
}
|
||||
|
||||
private async Task LoadLogs()
|
||||
{
|
||||
try
|
||||
{
|
||||
IsLoading = true;
|
||||
ShowLogs.Clear();
|
||||
StateHasChanged();
|
||||
|
||||
using var Http = new HttpClient();
|
||||
var logs = await Http.GetFromJsonAsync<IEnumerable<string>>($"{LogProccessSelected.Url}?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();
|
||||
}
|
||||
}
|
||||
|
||||
public class LogConfiguration
|
||||
{
|
||||
public string Name { get; set; } = "";
|
||||
public string Url { get; set; } = "";
|
||||
}
|
||||
|
||||
private async Task ExportLogs()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var Http = new HttpClient();
|
||||
var fileContent = await Http.GetFromJsonAsync<IEnumerable<string>>($"{LogProccessSelected.Url}?date={DateLog}");
|
||||
var formattedContent = string.Join("\n", fileContent ?? []);
|
||||
var fileName = $"{LogProccessSelected.Name}_{DateLog.ToShortDateString()}.txt";
|
||||
await JSRuntime.InvokeVoidAsync("downloadFile", fileName, formattedContent, "text/plain");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Lỗi khi tải file: {ex.Message}", Severity.Warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
38
RobotNet.WebApp/Pages/Logs.razor.css
Normal file
38
RobotNet.WebApp/Pages/Logs.razor.css
Normal file
@@ -0,0 +1,38 @@
|
||||
.log-container {
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
position: absolute;
|
||||
top: 0px;
|
||||
left: 0px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.log {
|
||||
word-wrap: break-word;
|
||||
line-height: 18px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
303
RobotNet.WebApp/Pages/Missions.razor
Normal file
303
RobotNet.WebApp/Pages/Missions.razor
Normal file
@@ -0,0 +1,303 @@
|
||||
@page "/missions"
|
||||
@attribute [Authorize]
|
||||
|
||||
@using RobotNet.Script.Shares
|
||||
@using RobotNet.Shares
|
||||
@using RobotNet.Clients
|
||||
@using RobotNet.WebApp.Scripts.Models
|
||||
|
||||
@inject IHttpClientFactory httpFactory
|
||||
@inject IDialogService DialogService
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>Runner Missions</PageTitle>
|
||||
|
||||
<div @ref="divRef" class="w-100 h-100">
|
||||
<MudTable @ref="table" ServerData="ServerReload" Style="margin: 10px;" Items="runnerMissions" Height="@TableHeight" Dense FixedHeader Virtualize Hover Elevation="6">
|
||||
<ToolBarContent>
|
||||
<div @ref="toolbarRef" class="w-100 d-flex flex-row">
|
||||
<h3>Danh sách Missions</h3>
|
||||
<MudSpacer />
|
||||
<MudIconButton Class="me-2" Icon="@Icons.Material.Filled.Refresh" Color="Color.Primary" Size="Size.Small" OnClick="ReloadTable" />
|
||||
<MudTextField T="string" ValueChanged="@(s => OnSearch(s))" DebounceInterval="1000" Value="@searchString" Margin="Margin.Dense"
|
||||
Placeholder="Search" Adornment="Adornment.Start" AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
IconSize="Size.Medium" Class="mt-0" Variant="Variant.Outlined" />
|
||||
</div>
|
||||
</ToolBarContent>
|
||||
<ColGroup>
|
||||
<col style="width:60px;" />
|
||||
<col style="width:100px;" />
|
||||
<col style="width:150px;" />
|
||||
<col style="width:120px;" />
|
||||
<col />
|
||||
<col style="width:100px;" />
|
||||
<col />
|
||||
<col style="width:100px;" />
|
||||
</ColGroup>
|
||||
<HeaderContent>
|
||||
<MudTh>STT</MudTh>
|
||||
<MudTh>Tên</MudTh>
|
||||
<MudTh>Id</MudTh>
|
||||
<MudTh>Create at</MudTh>
|
||||
<MudTh>Parameters</MudTh>
|
||||
<MudTh>Status</MudTh>
|
||||
<MudTh>Log</MudTh>
|
||||
<MudTh></MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>@context.Index</MudTd>
|
||||
<MudTd DataLabel="Tên">@context.MissionName</MudTd>
|
||||
<MudTd DataLabel="Id">@context.Id.ToString()[..13]</MudTd>
|
||||
<MudTd DataLabel="Create at">@context.CreatedAt.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")</MudTd>
|
||||
<MudTd DataLabel="Parameters">
|
||||
@if (context.Parameters?.Any() == true)
|
||||
{
|
||||
<span title="@context.Parameters">
|
||||
@ShortenLog(context.Parameters, 30)
|
||||
</span>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Info" Color="Color.Primary" Size="Size.Small"
|
||||
OnClick="@(() => ShowParametersDialog(context))" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<span>{}</span>
|
||||
}
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Status">
|
||||
@if (context.Status == MissionStatus.Running)
|
||||
{
|
||||
<MudChip T="string" Color="Color.Success" Variant="Variant.Filled">@context.Status</MudChip>
|
||||
}
|
||||
else if (context.Status == MissionStatus.Completed)
|
||||
{
|
||||
<MudChip T="string" Color="Color.Primary" Variant="Variant.Filled">@context.Status</MudChip>
|
||||
}
|
||||
else if (context.Status == MissionStatus.Error)
|
||||
{
|
||||
<MudChip T="string" Color="Color.Error" Variant="Variant.Filled">@context.Status</MudChip>
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudChip T="string" Color="Color.Warning" Variant="Variant.Filled">@context.Status</MudChip>
|
||||
}
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Log">
|
||||
@if (!string.IsNullOrEmpty(context.Log))
|
||||
{
|
||||
<span title="@context.Log">
|
||||
@ShortenLog(context.Log, 30)
|
||||
</span>
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Visibility" Color="Color.Primary" Size="Size.Small"
|
||||
OnClick="@(() => ShowLogDialog(context.Log))" />
|
||||
}
|
||||
</MudTd>
|
||||
<MudTd DataLabel="" Class="text-center">
|
||||
@if (context.Status == MissionStatus.Running)
|
||||
{
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Stop" Color="Color.Error" Size="Size.Small" OnClick="@(() => PauseMission(context))" />
|
||||
}
|
||||
else if (context.Status == MissionStatus.Paused)
|
||||
{
|
||||
<MudIconButton Icon="@Icons.Material.Filled.PlayArrow" Color="Color.Primary" Size="Size.Small" OnClick="@(() => ResumeMission(context))" />
|
||||
}
|
||||
|
||||
@if (context.Status == MissionStatus.Running || context.Status == MissionStatus.Paused)
|
||||
{
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" Color="Color.Error" Size="Size.Small" OnClick="@(() => CancelMission(context))" />
|
||||
}
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
<NoRecordsContent>
|
||||
<MudText>No matching records found</MudText>
|
||||
</NoRecordsContent>
|
||||
<LoadingContent>
|
||||
<MudText>Loading...</MudText>
|
||||
</LoadingContent>
|
||||
<PagerContent>
|
||||
<MudTablePager />
|
||||
</PagerContent>
|
||||
</MudTable>
|
||||
</div>
|
||||
|
||||
<MudDialog @bind-Visible="_logDialogOpen" Style="min-width: 900px;">
|
||||
<DialogContent>
|
||||
<MudText Typo="Typo.h6">Mission Log</MudText>
|
||||
<MudPaper Class="pa-2" Style="overflow-x:auto;">
|
||||
<pre style="white-space:pre-wrap; word-break:break-all;">@_selectedLog</pre>
|
||||
</MudPaper>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="() => _logDialogOpen = false" Color="Color.Primary">Close</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
<MudDialog @bind-Visible="_parametersDialogOpen" Style="min-width: 600px;">
|
||||
<DialogContent>
|
||||
<MudText Typo="Typo.h6">Parameters of mission "@_missionName"</MudText>
|
||||
<MudPaper Class="pa-2" Style="overflow-x:auto;">
|
||||
<table class="mud-table mud-table-dense" style="width:100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="text-align:left;">Key</th>
|
||||
<th style="text-align:left;">Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var kv in _selectedParameters)
|
||||
{
|
||||
<tr>
|
||||
<td style="vertical-align:top;">@kv.Key</td>
|
||||
<td style="vertical-align:top;">@kv.Value</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
</MudPaper>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="() => _parametersDialogOpen = false" Color="Color.Primary">Close</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
private string TableHeight = "0px";
|
||||
private ElementReference divRef;
|
||||
private ElementReference toolbarRef;
|
||||
private MudTable<InstanceMissionModel> table = default!;
|
||||
private List<InstanceMissionModel> runnerMissions = [];
|
||||
private string searchString = "";
|
||||
|
||||
private string _missionName = "";
|
||||
private bool _parametersDialogOpen = false;
|
||||
private IDictionary<string, string> _selectedParameters = new Dictionary<string, string>();
|
||||
|
||||
private bool _logDialogOpen = false;
|
||||
private string _selectedLog = string.Empty;
|
||||
|
||||
private HttpClient http = default!;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (firstRender)
|
||||
{
|
||||
var rect = await divRef.MudGetBoundingClientRectAsync();
|
||||
var toolbarRect = await toolbarRef.MudGetBoundingClientRectAsync();
|
||||
TableHeight = $"{rect.Height - 70 - Math.Max(toolbarRect.Height, 64)}px";
|
||||
StateHasChanged();
|
||||
|
||||
await table.ReloadServerData();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<TableData<InstanceMissionModel>> ServerReload(TableState state, CancellationToken token)
|
||||
{
|
||||
if (http == null)
|
||||
{
|
||||
http = httpFactory.CreateClient("ScriptManagerAPI");
|
||||
}
|
||||
|
||||
var url = $"api/ScriptMissions/Runner?txtSearch={Uri.EscapeDataString(searchString)}&page={state.Page + 1}&size={state.PageSize}";
|
||||
var response = await http.GetFromJsonAsync<SearchResult<InstanceMissionDto>>(url) ?? new();
|
||||
|
||||
return new TableData<InstanceMissionModel>()
|
||||
{
|
||||
TotalItems = response.Total,
|
||||
Items = [.. response.Items.Select((item, index) => new InstanceMissionModel(index + 1 + state.Page * state.PageSize, item))]
|
||||
};
|
||||
}
|
||||
|
||||
private void ShowParametersDialog(InstanceMissionModel mission)
|
||||
{
|
||||
try
|
||||
{
|
||||
_selectedParameters = System.Text.Json.JsonSerializer.Deserialize<IDictionary<string, string>>(mission.Parameters)
|
||||
?? throw new Exception($"Can not convert parameters data from \"{mission.Parameters}\"");
|
||||
_missionName = mission.MissionName;
|
||||
_parametersDialogOpen = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Snackbar.Add($"Failed to parse parameters: {ex.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private string ShortenLog(string? log, int maxLength)
|
||||
{
|
||||
if (string.IsNullOrEmpty(log)) return string.Empty;
|
||||
return log.Length > maxLength ? log.Substring(0, maxLength) + "..." : log;
|
||||
}
|
||||
|
||||
private void ShowLogDialog(string log)
|
||||
{
|
||||
_selectedLog = log;
|
||||
_logDialogOpen = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task OnSearch(string text)
|
||||
{
|
||||
searchString = text;
|
||||
await table.ReloadServerData();
|
||||
}
|
||||
|
||||
private async Task CancelMission(InstanceMissionModel model)
|
||||
{
|
||||
var response = await http.DeleteFromJsonAsync<MessageResult>($"api/ScriptMissions/Runner/{model.Id}");
|
||||
if (response == null)
|
||||
{
|
||||
Snackbar.Add("Failed to cancel mission: server response error", Severity.Error);
|
||||
}
|
||||
else if (response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Mission canceled successfully", Severity.Success);
|
||||
await table.ReloadServerData();
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add($"Failed to cancel mission: {response.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task PauseMission(InstanceMissionModel model)
|
||||
{
|
||||
var response = await http.PutFromJsonAsync<MessageResult>($"api/ScriptMissions/Runner/{model.Id}/pause", new object());
|
||||
if (response == null)
|
||||
{
|
||||
Snackbar.Add("Failed to pause mission: server response error", Severity.Error);
|
||||
}
|
||||
else if (response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Mission paused successfully", Severity.Success);
|
||||
await table.ReloadServerData();
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add($"Failed to pause mission: {response.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ResumeMission(InstanceMissionModel model)
|
||||
{
|
||||
var response = await http.PutFromJsonAsync<MessageResult>($"api/ScriptMissions/Runner/{model.Id}/resume", new object());
|
||||
if (response == null)
|
||||
{
|
||||
Snackbar.Add("Failed to resume mission: server response error", Severity.Error);
|
||||
}
|
||||
else if (response.IsSuccess)
|
||||
{
|
||||
Snackbar.Add("Mission resumed successfully", Severity.Success);
|
||||
await table.ReloadServerData();
|
||||
}
|
||||
else
|
||||
{
|
||||
Snackbar.Add($"Failed to resume mission: {response.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ReloadTable()
|
||||
{
|
||||
await table.ReloadServerData();
|
||||
}
|
||||
}
|
||||
196
RobotNet.WebApp/Pages/NavigationMapEditor.razor
Normal file
196
RobotNet.WebApp/Pages/NavigationMapEditor.razor
Normal file
@@ -0,0 +1,196 @@
|
||||
@page "/navigation-maps/editor/{Id:guid}"
|
||||
@attribute [Authorize]
|
||||
|
||||
@using RobotNet.MapShares.Dtos
|
||||
@using RobotNet.MapShares.Enums
|
||||
@using RobotNet.Shares
|
||||
@using RobotNet.WebApp.Maps.Components.Editor
|
||||
@using RobotNet.WebApp.Maps.Components.Toolbar
|
||||
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
@inject IJSRuntime JSRuntime
|
||||
|
||||
<PageTitle>Map Designer</PageTitle>
|
||||
|
||||
<div class="d-flex flex-column w-100 h-100 position-relative" @onkeyup:preventDefault @onkeypress:preventDefault @onkeydown:preventDefault>
|
||||
<EditorToolbar @ref="@EditorToolbarRef" MapIsActive="@MapIsActive" ShowName="@ShowName" ShowGrid="@ShowGrid" ShowMapSlam="@ShowMapSlam" EditorState="@EditorState"
|
||||
MultiSelectedEdge="@MultiselectedEdge" MultiSelectedNode="@MultiselectedNode" NodesUndoable="@NodesUndoable" ZoneSelected="@ZoneSelected"
|
||||
EditorZoneTypeChanged="((zonetype) => ZoneType = zonetype)"
|
||||
ControlStateClick="ControlStateClick"
|
||||
EditorStateChanged="EditorStateChanged"
|
||||
EditorExtensionChanged="EditorExtensionChanged"
|
||||
AlignStateClick="AlignStateClick" />
|
||||
|
||||
<div class="w-100 flex-grow-1">
|
||||
<MapContainer @ref="MapContainerRef" ShowGrid="@ShowGrid" ShowName="@ShowName" ShowMapSlam="ShowMapSlam" EditorState="@EditorState" MapIsActive="@MapIsActive" ZoneType="@ZoneType"
|
||||
MultiselectedEdgeChanged="((value) => MultiselectedEdge = value)"
|
||||
MultiselectedNodeChanged="((value) => MultiselectedNode = value)"
|
||||
ZoneselectedChanged="((value) => ZoneSelected = value)"
|
||||
NodesUndoableChanged="((value) => NodesUndoable = value)" KeyPress="EditorStateChanged" MapIsChecking="MapIsChecking" />
|
||||
</div>
|
||||
|
||||
<div class="d-flex w-100 h-100 position-absolute" style="visibility: @(OverlayIsShow ? "visiable" :"hidden")">
|
||||
<div class="d-flex w-100 h-100 position-absolute" style="background-color: #f2f2f2; opacity: 0.5; z-index: 999" />
|
||||
<div class="d-flex w-100 h-100 align-items-center justify-content-center position-absolute" style="z-index: 1000">
|
||||
<div class="d-flex" style="width: fit-content; height: fit-content;">
|
||||
<span style="font-size: 4rem; color: red; font-weight: bold">@OverlayIsStr</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
private EditorToolbar EditorToolbarRef = null!;
|
||||
private MapContainer MapContainerRef = null!;
|
||||
|
||||
private bool ShowGrid = true;
|
||||
private bool ShowName = true;
|
||||
private bool ShowMapSlam = true;
|
||||
private bool MapIsActive;
|
||||
private bool MultiselectedEdge = false;
|
||||
private bool MultiselectedNode = false;
|
||||
private bool ZoneSelected = false;
|
||||
private bool NodesUndoable = false;
|
||||
private EditorState EditorState = EditorState.View;
|
||||
private ZoneType ZoneType = ZoneType.Operating;
|
||||
|
||||
private bool OverlayIsShow = false;
|
||||
private string OverlayIsStr = "Loading...";
|
||||
private HttpClient Http = default!;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
Http = HttpClientFactory.CreateClient("MapManagerAPI");
|
||||
await LoadMap();
|
||||
}
|
||||
|
||||
private async Task LoadMap()
|
||||
{
|
||||
try
|
||||
{
|
||||
OverlayIsShow = true;
|
||||
StateHasChanged();
|
||||
|
||||
var mapDataResult = await Http.GetFromJsonAsync<MessageResult<MapDataDto>>($"api/MapsData/{Id}");
|
||||
if (mapDataResult is not null && mapDataResult.Data is not null)
|
||||
{
|
||||
MapIsActive = mapDataResult.Data.Active;
|
||||
await MapContainerRef.LoadMap(mapDataResult.Data);
|
||||
OverlayIsShow = false;
|
||||
}
|
||||
else OverlayIsStr = "Map Not Existed";
|
||||
StateHasChanged();
|
||||
}
|
||||
catch
|
||||
{
|
||||
OverlayIsStr = "Map Not Existed";
|
||||
StateHasChanged();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void EditorExtensionChanged((ControlState state, bool value) extension)
|
||||
{
|
||||
switch (extension.state)
|
||||
{
|
||||
case ControlState.ShowName:
|
||||
ShowName = extension.value;
|
||||
break;
|
||||
case ControlState.ShowGrid:
|
||||
ShowGrid = extension.value;
|
||||
break;
|
||||
case ControlState.ShowMapSlam:
|
||||
ShowMapSlam = extension.value;
|
||||
break;
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task ControlStateClick(ControlState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case ControlState.Undo:
|
||||
MapContainerRef.UndoEditorBackup();
|
||||
break;
|
||||
case ControlState.FitScreen:
|
||||
await MapContainerRef.ScaleFitContentAsync();
|
||||
break;
|
||||
case ControlState.Save:
|
||||
await MapContainerRef.SaveChanged();
|
||||
break;
|
||||
case ControlState.ZoomIn:
|
||||
await MapContainerRef.ScaleZoom(0.5);
|
||||
break;
|
||||
case ControlState.ZoomOut:
|
||||
await MapContainerRef.ScaleZoom(-0.5);
|
||||
break;
|
||||
case ControlState.Delete:
|
||||
if (EditorState == EditorState.NavigationEdit || EditorState == EditorState.Scaner) await MapContainerRef.DeleteEdge();
|
||||
else if (EditorState == EditorState.SettingZone) await MapContainerRef.DeleteZone();
|
||||
break;
|
||||
case ControlState.CheckMap:
|
||||
await MapContainerRef.CheckMap();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task EditorStateChanged(EditorState state)
|
||||
{
|
||||
if (EditorState != state)
|
||||
{
|
||||
EditorState = state;
|
||||
await MapContainerRef.EditStateChange();
|
||||
EditorToolbarRef.SetEditorState(state);
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task AlignStateClick(AlignState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case AlignState.HorizontalLeft:
|
||||
MapContainerRef.HorizontalLeft();
|
||||
break;
|
||||
case AlignState.HorizontalRight:
|
||||
MapContainerRef.HorizontalRight();
|
||||
break;
|
||||
case AlignState.VerticalTop:
|
||||
MapContainerRef.VerticalTop();
|
||||
break;
|
||||
case AlignState.VerticalBottom:
|
||||
MapContainerRef.VerticalBottom();
|
||||
break;
|
||||
case AlignState.HorizontalCenter:
|
||||
MapContainerRef.HorizontalCenter();
|
||||
break;
|
||||
case AlignState.VerticalCenter:
|
||||
MapContainerRef.VerticalCenter();
|
||||
break;
|
||||
case AlignState.MergeNode:
|
||||
await MapContainerRef.MergeNode();
|
||||
break;
|
||||
case AlignState.SplitNode:
|
||||
await MapContainerRef.SplitNode();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void MapIsChecking(bool state)
|
||||
{
|
||||
if (state)
|
||||
{
|
||||
OverlayIsShow = true;
|
||||
OverlayIsStr = "Map Checking ...";
|
||||
}
|
||||
else OverlayIsShow = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
103
RobotNet.WebApp/Pages/NavigationMapElement.razor
Normal file
103
RobotNet.WebApp/Pages/NavigationMapElement.razor
Normal file
@@ -0,0 +1,103 @@
|
||||
@page "/navigation-maps/elements/{Id:guid}"
|
||||
@attribute [Authorize]
|
||||
|
||||
@using RobotNet.MapShares.Dtos
|
||||
@using RobotNet.Shares
|
||||
@using RobotNet.WebApp.Maps.Components.Element
|
||||
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>Map Element</PageTitle>
|
||||
|
||||
<div class="d-flex w-100 h-100 flex-row position-relative p-2">
|
||||
<div class="d-flex h-100 flex-column" style="width: 40%;">
|
||||
<div class="d-flex flex-row" style="height: 70%;">
|
||||
<div class="d-flex h-100 w-50">
|
||||
<ElementModelTable MapInfo="@MapInfo" ElementModels="ElementModels" ElementModelSelectChanged="ElementModelSelectChanged" />
|
||||
</div>
|
||||
<MudDivider Vertical="true" FlexItem="true" Style="border: 0.5px solid gray" />
|
||||
<div class="d-flex h-100 w-50">
|
||||
<ElementDefaultProperty @ref="@ElementDefaultPropertyRef" />
|
||||
</div>
|
||||
</div>
|
||||
<MudDivider Vertical="true" FlexItem="true" Style="border: 0.5px solid gray" />
|
||||
<div class="d-flex flex-grow-1" >
|
||||
<ElementImage @ref="@ElementImageRef" />
|
||||
</div>
|
||||
</div>
|
||||
<MudDivider Vertical="true" FlexItem="true" Style="border: 0.5px solid gray" />
|
||||
<div class="d-flex h-100 flex-column" style="width: 60%">
|
||||
<div class="d-flex w-100" style="height: 70%;">
|
||||
<MapElement @ref="MapElementRef" ElementSelectChanged="ElementSelectChanged" />
|
||||
</div>
|
||||
<MudDivider Vertical="true" FlexItem="true" Style="border: 0.5px solid gray" />
|
||||
<div class="d-flex flex-grow-1">
|
||||
<ElementPropertyTable @ref="@ElementPropertyRef" ElementPropertyChagned="((value) => MapElementRef.UpdateProperty(value))" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudOverlay @bind-Visible="IsLoading" DarkBackground="true" Absolute="true">
|
||||
<MudText Typo="Typo.h1" Color="@Color.Error" Style="font-weight: bold;">Is Loadding ...</MudText>
|
||||
</MudOverlay>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public List<ElementModelDto> ElementModels { get; set; } = [];
|
||||
public List<ElementDto> Elements { get; set; } = [];
|
||||
|
||||
private bool IsLoading { get; set; }
|
||||
private MapInfoDto MapInfo = new();
|
||||
|
||||
private ElementDefaultProperty ElementDefaultPropertyRef = default!;
|
||||
private ElementImage ElementImageRef = default!;
|
||||
private MapElement MapElementRef = default!;
|
||||
private ElementPropertyTable ElementPropertyRef = default!;
|
||||
private HttpClient Http = default!;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
Http = HttpClientFactory.CreateClient("MapManagerAPI");
|
||||
var reponse = await Http.GetFromJsonAsync<MessageResult<MapInfoDto>>($"api/MapsManager/{Id}");
|
||||
if (reponse is not null && reponse.Data is not null) MapInfo = reponse.Data;
|
||||
await LoadElementModels();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task LoadElementModels()
|
||||
{
|
||||
IsLoading = true;
|
||||
ElementModels.Clear();
|
||||
StateHasChanged();
|
||||
|
||||
var elModels = await Http.GetFromJsonAsync<MessageResult<IEnumerable<ElementModelDto>>>($"api/ElementModels/map/{Id}");
|
||||
if (elModels is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!elModels.IsSuccess) Snackbar.Add($"Có lỗi xảy ra: {elModels.Message}", Severity.Error);
|
||||
else if (elModels.Data is null || !elModels.Data.Any())
|
||||
{
|
||||
Snackbar.Add("Không có mô hình phần tử nào được tìm thấy", Severity.Warning);
|
||||
}
|
||||
else
|
||||
{
|
||||
ElementModels.AddRange(elModels.Data.OrderBy(el => el.Name));
|
||||
}
|
||||
IsLoading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task ElementModelSelectChanged(ElementModelDto? model)
|
||||
{
|
||||
ElementDefaultPropertyRef.SetElementModel(model);
|
||||
ElementImageRef.SetElementModel(model);
|
||||
await MapElementRef.SetData(model);
|
||||
}
|
||||
|
||||
private void ElementSelectChanged(ElementDto? model) => ElementPropertyRef.SetProperties(model);
|
||||
}
|
||||
116
RobotNet.WebApp/Pages/NavigationMapSetting.razor
Normal file
116
RobotNet.WebApp/Pages/NavigationMapSetting.razor
Normal file
@@ -0,0 +1,116 @@
|
||||
@page "/navigation-maps/settings/{Id:guid}"
|
||||
@attribute [Authorize]
|
||||
|
||||
@using RobotNet.MapShares.Dtos
|
||||
@using RobotNet.Shares
|
||||
@using RobotNet.WebApp.Maps.Components.Setting
|
||||
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
@inject NavigationManager Nav
|
||||
|
||||
<PageTitle>Map Setting</PageTitle>
|
||||
|
||||
<div class="d-flex flex-column w-100 h-100">
|
||||
<div class="d-flex h-100 w-100">
|
||||
<MudTabs Class="w-100 h-100" Elevation="2" ApplyEffectsToContainer="true" PanelClass="overflow-x-auto w-100 h-100" Color="@Color.Primary" ActivePanelIndexChanged="ActivePanelChanged">
|
||||
<ChildContent>
|
||||
<MudTabPanel Text="Default Settings">
|
||||
<div class="pa-6">
|
||||
<MapSettingDefault @ref=MapConfigDefaultRef Id="@Id" />
|
||||
</div>
|
||||
</MudTabPanel>
|
||||
<MudTabPanel Text="Default Action">
|
||||
<MapSettingAction @ref=MapConfigActionRef Id="@Id" />
|
||||
</MudTabPanel>
|
||||
</ChildContent>
|
||||
<Header>
|
||||
<MudText Class="d-flex flex-nowrap align-items-center me-5 text-truncate" Typo="Typo.h6">@MapName</MudText>
|
||||
<MudDivider Class="me-2" Vertical="true" FlexItem="true"/>
|
||||
@if (PanelSelected == 1)
|
||||
{
|
||||
<MudTooltip RootClass="d-flex align-items-center" Text="Delete" Placement="Placement.Bottom" Color="Color.Info" Arrow="true">
|
||||
<MudIconButton Class="mx-2" Icon="@Icons.Material.Filled.Delete" Variant="Variant.Filled" Color="Color.Secondary" OnClick="DeleteAction"></MudIconButton>
|
||||
</MudTooltip>
|
||||
<MudTooltip RootClass="d-flex align-items-center" Text="Create" Placement="Placement.Bottom" Color="Color.Info" Arrow="true">
|
||||
<MudIconButton Class="mx-2" Icon="@Icons.Material.Filled.Add" Variant="Variant.Filled" Color="Color.Info" OnClick="CreateAction"></MudIconButton>
|
||||
</MudTooltip>
|
||||
}
|
||||
<MudTooltip RootClass="d-flex align-items-center" Text="Save" Placement="Placement.Bottom" Color="Color.Info" Arrow="true">
|
||||
<MudIconButton Class="mx-2" Icon="@Icons.Material.Filled.Save" Variant="Variant.Filled" Color="Color.Info" OnClick="OnSave"></MudIconButton>
|
||||
</MudTooltip>
|
||||
<MudTooltip RootClass="d-flex align-items-center" Text="Reset" Placement="Placement.Bottom" Color="Color.Info" Arrow="true">
|
||||
<MudIconButton Class="mx-2" Icon="@Icons.Material.Filled.Refresh" Variant="Variant.Filled" Color="Color.Info" OnClick="OnReset"></MudIconButton>
|
||||
</MudTooltip>
|
||||
<MudTooltip RootClass="d-flex align-items-center" Text="Exit" Placement="Placement.Bottom" Color="Color.Info" Arrow="true">
|
||||
<MudIconButton Class="mx-2" Icon="@Icons.Material.Filled.KeyboardReturn" Variant="Variant.Filled" Color="Color.Info" OnClick="@(() => Nav.NavigateTo($"/navigation-maps"))"></MudIconButton>
|
||||
</MudTooltip>
|
||||
</Header>
|
||||
</MudTabs>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@code {
|
||||
[Parameter, EditorRequired]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
private MapSettingDefault MapConfigDefaultRef = null!;
|
||||
private MapSettingAction MapConfigActionRef = null!;
|
||||
private int PanelSelected = 0;
|
||||
|
||||
private string MapName = "";
|
||||
private HttpClient Http = default!;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
Http = HttpClientFactory.CreateClient("MapManagerAPI");
|
||||
var reponse = await Http.GetFromJsonAsync<MessageResult<MapInfoDto>>($"api/MapsManager/{Id}");
|
||||
if (reponse is not null && reponse.Data is not null) MapName = reponse.Data.Name;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task OnSave()
|
||||
{
|
||||
switch (PanelSelected)
|
||||
{
|
||||
case 0:
|
||||
await MapConfigDefaultRef.Save();
|
||||
break;
|
||||
case 1:
|
||||
await MapConfigActionRef.Save();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnReset()
|
||||
{
|
||||
switch (PanelSelected)
|
||||
{
|
||||
case 0:
|
||||
MapConfigDefaultRef.Reset();
|
||||
break;
|
||||
case 1:
|
||||
MapConfigActionRef.Reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void ActivePanelChanged(int value)
|
||||
{
|
||||
PanelSelected = value;
|
||||
}
|
||||
|
||||
private void CreateAction()
|
||||
{
|
||||
MapConfigActionRef.ShowCreateAction();
|
||||
}
|
||||
|
||||
private async Task DeleteAction()
|
||||
{
|
||||
await MapConfigActionRef.DeleteAction();
|
||||
}
|
||||
}
|
||||
585
RobotNet.WebApp/Pages/NavigationMapsManager.razor
Normal file
585
RobotNet.WebApp/Pages/NavigationMapsManager.razor
Normal file
@@ -0,0 +1,585 @@
|
||||
@page "/navigation-maps"
|
||||
@attribute [Authorize]
|
||||
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
@using RobotNet.MapShares
|
||||
@using RobotNet.MapShares.Dtos
|
||||
@using System.Net.Http.Headers
|
||||
@using RobotNet.Shares
|
||||
@using RobotNet.WebApp.Maps.Components
|
||||
|
||||
@inject NavigationManager NavManager
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService Dialog
|
||||
|
||||
<PageTitle>Map Manager</PageTitle>
|
||||
|
||||
<style>
|
||||
.selected {
|
||||
background-color: #3399ff !important;
|
||||
}
|
||||
|
||||
.selected > td {
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.selected > td .mud-input {
|
||||
color: white !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="d-flex flex-row w-100 h-100 p-2 overflow-hidden">
|
||||
<div class="d-flex h-100 flex-column flex-grow-1 pe-2">
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<MudTextField Value="txtSearch" T="string" Label="Search" Variant="Variant.Outlined" Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
AdornmentColor="Color.Secondary" ValueChanged="TextSearchChanged" Style="max-width: 550px" />
|
||||
<MudButton StartIcon="@Icons.Material.Filled.FileUpload" HtmlTag="label" Variant="Variant.Filled" Color="Color.Primary" Size="Size.Large" for="WorkspaceAreaMapImport">
|
||||
IMPORT
|
||||
</MudButton>
|
||||
<MudButton Class="ms-3" StartIcon="@Icons.Material.Filled.Add" Variant="Variant.Filled" Color="Color.Primary" Size="Size.Large" OnClick="OpenCreateMap">
|
||||
NEW
|
||||
</MudButton>
|
||||
<InputFile id="WorkspaceAreaMapImport" OnChange="OnMapImportChanged" accept=".map" hidden />
|
||||
</div>
|
||||
<div class="d-flex" style="height: 92%">
|
||||
<MudTable Class="w-100" @ref="Table" Items="@MapsShow" T="MapInfoDto" Dense=true Hover=true ReadOnly=true FixedHeader=true RowClass="cursor-pointer" Striped="true"
|
||||
ServerData="ReloadData" Loading=@IsLoading Outlined="true" RowClassFunc="@SelectedRowClassFunc" OnRowClick="RowClickEvent" Height="95%">
|
||||
<HeaderContent>
|
||||
<MudTh>Nr</MudTh>
|
||||
<MudTh>Name</MudTh>
|
||||
<MudTh>Width (m)</MudTh>
|
||||
<MudTh>Height (m)</MudTh>
|
||||
<MudTh>Resolution (m/px)</MudTh>
|
||||
<MudTh>OriginX</MudTh>
|
||||
<MudTh>OriginY</MudTh>
|
||||
<MudTh></MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="Nr">
|
||||
@(Table?.CurrentPage * Table?.RowsPerPage + MapsShow.IndexOf(context) + 1)
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Name">
|
||||
@context.Name
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Width">
|
||||
@context.Width
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Height">
|
||||
@context.Height
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Resolution">
|
||||
@context.Resolution
|
||||
</MudTd>
|
||||
<MudTd DataLabel="OriginX">
|
||||
@context.OriginX
|
||||
</MudTd>
|
||||
<MudTd DataLabel="OriginY">
|
||||
@context.OriginY
|
||||
</MudTd>
|
||||
<MudTd>
|
||||
<div class="d-flex flex-row-reverse">
|
||||
<MudMenu Icon="@Icons.Material.Filled.MoreVert" AnchorOrigin="Origin.BottomCenter">
|
||||
<MudMenuItem OnClick="(() => OpenUpdateMap(context))" Icon="@Icons.Material.Filled.Edit" IconColor="Color.Info">Edit</MudMenuItem>
|
||||
<MudMenuItem OnClick="(() => DeleteMap(context.Id))" Icon="@Icons.Material.Filled.Delete" IconColor="Color.Error">Delete</MudMenuItem>
|
||||
</MudMenu>
|
||||
<MudButton Class="my-2" IconColor="Color.Success" StartIcon="@(context.Active ? @Icons.Material.Outlined.Check : "")" Color="@(context.Active ? Color.Success : Color.Default)" Variant="Variant.Outlined" Size="Size.Small" OnClick="@(async() => await MapActiveToggle(context.Id, !context.Active))">Active</MudButton>
|
||||
</div>
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
<PagerContent>
|
||||
<div class="d-flex w-100 flex-row-reverse">
|
||||
<MudTablePager Style="width: 100%;" PageSizeOptions="new[] {25 , 100, 200}" />
|
||||
</div>
|
||||
</PagerContent>
|
||||
</MudTable>
|
||||
</div>
|
||||
</div>
|
||||
<div class="map-preview">
|
||||
<NavigationMapPreview @ref="@NavigationMapPreviewRef" MapImageChangedCallBack="MapImageChangedCallBack" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudDialog @bind-Visible="IsCreateMapVisible">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
Create New Map
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudContainer Class="d-flex flex-column" Style="max-height: 700px; overflow-y: auto">
|
||||
<MudTextField Class="my-2"
|
||||
@bind-Value="MapCreateModel.Name" T="string"
|
||||
Label="Map's name" Required="true"
|
||||
RequiredError="Map name is required!" Counter="18" Variant="Variant.Outlined"
|
||||
Validation="@(new Func<string, IEnumerable<string>>(MapEditorHelper.NameValidation))" />
|
||||
<div class="d-flex flex-row my-2">
|
||||
<MudNumericField Class="me-2" @bind-Value="MapCreateModel.OriginX" Label="Origin X" Step="0.1" Variant="Variant.Outlined" />
|
||||
<MudNumericField Class="ms-2" @bind-Value="MapCreateModel.OriginY" Label="Origin Y" Step="0.1" Variant="Variant.Outlined" />
|
||||
</div>
|
||||
<MudNumericField Class="my-2" @bind-Value="MapCreateModel.Resolution" Label="Resolution" Step="0.1" Variant="Variant.Outlined" Min="0" />
|
||||
<div class="d-flex flex-column">
|
||||
<div class="d-flex flex-row my-2">
|
||||
<InputFile id="fileMapImageCreate" OnChange="MapCreateImageChanged" accept=".png" hidden />
|
||||
<MudButton HtmlTag="label"
|
||||
Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.CloudUpload"
|
||||
for="fileMapImageCreate">
|
||||
Map Image
|
||||
</MudButton>
|
||||
</div>
|
||||
<div class="d-flex mb-2">
|
||||
<div class="map-create-item">
|
||||
<img alt="Map Image" src="@ProjectionImageFilePreview" style="image-rendering: pixelated;" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</MudContainer>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@(() => IsCreateMapVisible = false)" Variant="Variant.Filled">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="CreateNewMap" Variant="Variant.Filled">Create</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
<MudDialog @bind-Visible="IsUpdateMapVisible">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
Update Map
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudContainer Class="d-flex flex-column" Style="max-height: 700px;">
|
||||
<MudTextField Class="my-2"
|
||||
@bind-Value="MapUpdateModel.Name" T="string"
|
||||
Label="Map's name" Required="true"
|
||||
RequiredError="Map name is required!" Counter="127" Variant="Variant.Outlined"
|
||||
Validation="@(new Func<string, IEnumerable<string>>(MapEditorHelper.NameValidation))" />
|
||||
<div class="d-flex flex-row my-2">
|
||||
<MudNumericField Class="me-2" @bind-Value="MapUpdateModel.OriginX" Label="Origin X" Step="0.1" Variant="Variant.Outlined" />
|
||||
<MudNumericField Class="ms-2" @bind-Value="MapUpdateModel.OriginY" Label="Origin Y" Step="0.1" Variant="Variant.Outlined" />
|
||||
</div>
|
||||
<MudNumericField Class="my-2" @bind-Value="MapUpdateModel.Resolution" Label="Resolution" Step="0.1" Variant="Variant.Outlined" Min="0" />
|
||||
</MudContainer>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@(() => IsUpdateMapVisible = false)" Variant="Variant.Filled">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="UpdateMap" Variant="Variant.Filled">Update</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
<MudDialog @bind-Visible="IsImportMapVisible">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
Import New Map
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudContainer Class="d-flex flex-column" Style="max-height: 700px; overflow-y: auto">
|
||||
<MudTextField Class="my-2"
|
||||
@bind-Value="MapImport.Name" T="string"
|
||||
Label="Map's name" Required="true"
|
||||
RequiredError="Map name is required!" Counter="127" Variant="Variant.Outlined"
|
||||
Validation="@(new Func<string, IEnumerable<string>>(MapEditorHelper.NameValidation))" />
|
||||
<div class="d-flex flex-row my-2">
|
||||
<MudNumericField Class="me-2" @bind-Value="MapImport.Info.OriginX" Label="Origin X" Step="0.1" Variant="Variant.Outlined" ReadOnly />
|
||||
<MudNumericField Class="ms-2" @bind-Value="MapImport.Info.OriginY" Label="Origin Y" Step="0.1" Variant="Variant.Outlined" ReadOnly />
|
||||
</div>
|
||||
<MudNumericField Class="my-2" @bind-Value="MapImport.Info.Resolution" Label="Resolution" Step="0.1" Variant="Variant.Outlined" Min="0" />
|
||||
<div class="d-flex mb-2">
|
||||
<div class="map-create-item">
|
||||
<img alt="Map Image" src="@ProjectionImportImageFilePreview" style="image-rendering: pixelated;" />
|
||||
</div>
|
||||
</div>
|
||||
</MudContainer>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@(() => IsImportMapVisible = false)" Variant="Variant.Filled">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="ImportNewMap" Variant="Variant.Filled">Create</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
private string txtSearch = "";
|
||||
private bool IsLoading = false;
|
||||
|
||||
private List<MapInfoDto> Maps = [];
|
||||
private List<MapInfoDto> MapsShow = [];
|
||||
private MudTable<MapInfoDto>? Table;
|
||||
|
||||
private int selectedRowNumber = -1;
|
||||
private MapInfoDto MapSelected = new();
|
||||
|
||||
private bool IsCreateMapVisible { get; set; }
|
||||
private readonly MapCreateModel MapCreateModel = new();
|
||||
private IBrowserFile? MapCreateImage { get; set; }
|
||||
private string? ProjectionImageFilePreview { get; set; }
|
||||
|
||||
private bool IsUpdateMapVisible { get; set; }
|
||||
private readonly MapUpdateModel MapUpdateModel = new();
|
||||
|
||||
private NavigationMapPreview NavigationMapPreviewRef = default!;
|
||||
|
||||
private MapExportDto MapImport = default!;
|
||||
private bool IsImportMapVisible { get; set; }
|
||||
private string? ProjectionImportImageFilePreview { get; set; }
|
||||
private HttpClient Http = default!;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
Http = HttpClientFactory.CreateClient("MapManagerAPI");
|
||||
await LoadMaps();
|
||||
}
|
||||
|
||||
private async Task LoadMaps()
|
||||
{
|
||||
try
|
||||
{
|
||||
IsLoading = true;
|
||||
Maps.Clear();
|
||||
StateHasChanged();
|
||||
|
||||
var maps = await Http.GetFromJsonAsync<IEnumerable<MapInfoDto>>($"api/MapsManager?txtSearch={txtSearch}");
|
||||
Maps.AddRange(maps ?? []);
|
||||
|
||||
Table?.ReloadServerData();
|
||||
IsLoading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void TextSearchChanged(string text)
|
||||
{
|
||||
txtSearch = text;
|
||||
Table?.ReloadServerData();
|
||||
}
|
||||
|
||||
private bool FilterFunc(MapInfoDto map)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(txtSearch))
|
||||
return true;
|
||||
if (map.Name is not null && map.Name.Contains(txtSearch, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
if ($"{map.Name}".Contains(txtSearch))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private Task<TableData<MapInfoDto>> ReloadData(TableState state, CancellationToken _)
|
||||
{
|
||||
MapsShow.Clear();
|
||||
var tasks = new List<MapInfoDto>();
|
||||
Maps.ForEach(task =>
|
||||
{
|
||||
if (FilterFunc(task)) tasks.Add(task);
|
||||
});
|
||||
MapsShow = tasks.Skip(state.Page * state.PageSize).Take(state.PageSize).ToList();
|
||||
return Task.FromResult(new TableData<MapInfoDto>() { TotalItems = tasks.Count, Items = MapsShow });
|
||||
}
|
||||
|
||||
private void RowClickEvent(TableRowClickEventArgs<MapInfoDto> tableRowClickEventArgs) { }
|
||||
|
||||
private string SelectedRowClassFunc(MapInfoDto element, int rowNumber)
|
||||
{
|
||||
if (selectedRowNumber == rowNumber && Table?.SelectedItem != null && !Table.SelectedItem.Equals(element))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
else if (selectedRowNumber == rowNumber && Table?.SelectedItem != null && Table.SelectedItem.Equals(element))
|
||||
{
|
||||
return "selected";
|
||||
}
|
||||
else if (Table?.SelectedItem != null && Table.SelectedItem.Equals(element))
|
||||
{
|
||||
selectedRowNumber = rowNumber;
|
||||
MapSelected = element;
|
||||
NavigationMapPreviewRef.SetMapPreview(MapSelected);
|
||||
return "selected";
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenCreateMap()
|
||||
{
|
||||
MapCreateModel.Name = string.Empty;
|
||||
MapCreateModel.OriginX = 0;
|
||||
MapCreateModel.OriginY = 0;
|
||||
MapCreateModel.Resolution = 0.1;
|
||||
ProjectionImageFilePreview = "/images/Image-not-found.png";
|
||||
MapCreateImage = null;
|
||||
IsCreateMapVisible = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task MapCreateImageChanged(InputFileChangeEventArgs e)
|
||||
{
|
||||
MapCreateImage = e.File;
|
||||
if (MapCreateImage is not null)
|
||||
{
|
||||
var buffers = new byte[MapCreateImage.Size];
|
||||
var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
||||
await using var fs = new FileStream(path, FileMode.Create);
|
||||
await MapCreateImage.OpenReadStream(MapCreateImage.Size).CopyToAsync(fs);
|
||||
fs.Position = 0;
|
||||
await fs.ReadAsync(buffers);
|
||||
fs.Close();
|
||||
File.Delete(path);
|
||||
|
||||
ProjectionImageFilePreview = $"data:{MapCreateImage.ContentType};base64,{Convert.ToBase64String(buffers)}";
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CreateNewMap()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (MapCreateImage is null || string.IsNullOrEmpty(ProjectionImageFilePreview))
|
||||
{
|
||||
Snackbar.Add("Ảnh map chưa được chọn.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(MapCreateModel.Name))
|
||||
{
|
||||
Snackbar.Add("Map's name không được để trống.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var nameInvalid = MapEditorHelper.NameChecking(MapCreateModel.Name);
|
||||
if (!nameInvalid.IsSuccess)
|
||||
{
|
||||
Snackbar.Add(nameInvalid.returnStr, Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
using var content = new MultipartFormDataContent
|
||||
{
|
||||
{ new StringContent(MapCreateModel.Name ?? String.Empty), nameof(MapCreateModel.Name) },
|
||||
{ new StringContent(MapCreateModel.OriginX.ToString()), nameof(MapCreateModel.OriginX) },
|
||||
{ new StringContent(MapCreateModel.OriginY.ToString()), nameof(MapCreateModel.OriginY) },
|
||||
{ new StringContent(MapCreateModel.Resolution.ToString()), nameof(MapCreateModel.Resolution) },
|
||||
};
|
||||
|
||||
var fileContent = new StreamContent(MapCreateImage.OpenReadStream(maxAllowedSize: 20480000));
|
||||
fileContent.Headers.ContentType = new MediaTypeHeaderValue(MapCreateImage.ContentType);
|
||||
content.Add(fileContent, "Image", MapCreateImage.Name);
|
||||
|
||||
var response = await (await Http.PostAsync("api/MapsManager", content)).Content.ReadFromJsonAsync<MessageResult<MapInfoDto>>();
|
||||
if (response is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!response.IsSuccess) Snackbar.Add(response.Message ?? "Lỗi chưa xác định.", Severity.Error);
|
||||
else if (response.Data is null) Snackbar.Add("Hệ thống không thể tạo bản đồ này", Severity.Error);
|
||||
else
|
||||
{
|
||||
Maps.Add(response.Data);
|
||||
Table?.ReloadServerData();
|
||||
Snackbar.Add($"Tạo map {MapCreateModel.Name} thành công.", Severity.Success);
|
||||
}
|
||||
|
||||
IsCreateMapVisible = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenUpdateMap(MapInfoDto map)
|
||||
{
|
||||
MapUpdateModel.Id = map.Id;
|
||||
MapUpdateModel.Name = map.Name;
|
||||
MapUpdateModel.OriginX = map.OriginX;
|
||||
MapUpdateModel.OriginY = map.OriginY;
|
||||
MapUpdateModel.Resolution = map.Resolution;
|
||||
IsUpdateMapVisible = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task UpdateMap()
|
||||
{
|
||||
var nameErrors = MapEditorHelper.NameChecking(MapUpdateModel.Name);
|
||||
if (!nameErrors.IsSuccess)
|
||||
{
|
||||
Snackbar.Add(nameErrors.returnStr, Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var result = await (await Http.PutAsJsonAsync($"api/MapsManager/{MapUpdateModel.Id}", MapUpdateModel)).Content.ReadFromJsonAsync<MessageResult<MapInfoDto>>();
|
||||
if (result == null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!result.IsSuccess) Snackbar.Add(result.Message, Severity.Error);
|
||||
else if (result.Data is null)
|
||||
{
|
||||
Snackbar.Add("Dữ liệu không hợp lệ", Severity.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var map = Maps.FirstOrDefault(map => map.Id == MapUpdateModel.Id);
|
||||
if (map is not null)
|
||||
{
|
||||
map.Name = result.Data.Name;
|
||||
map.OriginX = result.Data.OriginX;
|
||||
map.OriginY = result.Data.OriginY;
|
||||
map.Resolution = result.Data.Resolution;
|
||||
map.Width = result.Data.Width;
|
||||
map.Height = result.Data.Height;
|
||||
map.Active = result.Data.Active;
|
||||
Snackbar.Add("Cập nhật thành công", Severity.Success);
|
||||
}
|
||||
else Snackbar.Add("Map không tồn tại", Severity.Error);
|
||||
}
|
||||
|
||||
IsUpdateMapVisible = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task DeleteMap(Guid mapId)
|
||||
{
|
||||
var parameters = new DialogParameters<ConfirmDialog>
|
||||
{
|
||||
{ x => x.Content, "Bạn có chắc chắn muốn xóa map đi không?" },
|
||||
{ x => x.ConfirmText, "Delete" },
|
||||
{ x => x.Color, Color.Secondary }
|
||||
};
|
||||
var ConfirmDelete = await Dialog.ShowAsync<ConfirmDialog>("Xoá Map", parameters);
|
||||
var result = await ConfirmDelete.Result;
|
||||
if (result is not null && result.Data is not null && bool.TryParse(result.Data.ToString(), out bool data) && data)
|
||||
{
|
||||
var response = await Http.DeleteFromJsonAsync<MessageResult>($"api/MapsManager/{mapId}");
|
||||
if (response is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!response.IsSuccess) Snackbar.Add(response.Message ?? "Lỗi chưa xác định.", Severity.Error);
|
||||
else
|
||||
{
|
||||
var map = Maps.FirstOrDefault(m => m.Id == mapId);
|
||||
if (map is not null)
|
||||
{
|
||||
if (map.Id == MapSelected.Id)
|
||||
{
|
||||
NavigationMapPreviewRef.SetMapPreview(null);
|
||||
Table?.SetSelectedItem(null);
|
||||
selectedRowNumber = -1;
|
||||
}
|
||||
Maps.Remove(map);
|
||||
Table?.ReloadServerData();
|
||||
Snackbar.Add($"Xóa map thành công.", Severity.Success);
|
||||
}
|
||||
else Snackbar.Add($"Map không tồn tại.", Severity.Warning);
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task MapActiveToggle(Guid mapId, bool value)
|
||||
{
|
||||
var result = await (await Http.PutAsJsonAsync($"api/MapsManager/active", new MapActiveModel() { Id = mapId, Active = value })).Content.ReadFromJsonAsync<MessageResult>();
|
||||
if (result is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!result.IsSuccess) Snackbar.Add(result.Message ?? "Lỗi chưa xác định.", Severity.Error);
|
||||
else
|
||||
{
|
||||
var map = Maps.FirstOrDefault(map => map.Id == mapId);
|
||||
if (map is not null)
|
||||
{
|
||||
map.Active = value;
|
||||
Snackbar.Add("Cập nhật thành công", Severity.Success);
|
||||
}
|
||||
else Snackbar.Add($"Map không tồn tại.", Severity.Warning);
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task MapImageChangedCallBack(Guid mapId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var mapupdate = await Http.GetFromJsonAsync<MessageResult<MapInfoDto>>($"api/MapsManager/{mapId}");
|
||||
if (mapupdate is not null && mapupdate.Data is not null)
|
||||
{
|
||||
var map = Maps.FirstOrDefault(m => m.Id == mapupdate.Data.Id);
|
||||
if (map is not null)
|
||||
{
|
||||
map.Name = mapupdate.Data.Name;
|
||||
map.Width = mapupdate.Data.Width;
|
||||
map.Height = mapupdate.Data.Height;
|
||||
}
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OnMapImportChanged(InputFileChangeEventArgs e)
|
||||
{
|
||||
if (e.File is not null)
|
||||
{
|
||||
using var content = new MultipartFormDataContent();
|
||||
var fileContent = new StreamContent(e.File.OpenReadStream(maxAllowedSize: 10240000));
|
||||
if (!string.IsNullOrEmpty(e.File.ContentType)) fileContent.Headers.ContentType = new MediaTypeHeaderValue(e.File.ContentType);
|
||||
content.Add(fileContent, "importmap", e.File.Name);
|
||||
var response = await (await Http.PostAsync("api/MapExport/decrypt", content)).Content.ReadFromJsonAsync<MessageResult<MapExportDto>>();
|
||||
if (response is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!response.IsSuccess) Snackbar.Add($"Có lỗi xảy ra: {response.Message}", Severity.Error);
|
||||
else
|
||||
{
|
||||
if (response.Data is not null)
|
||||
{
|
||||
MapImport = response.Data;
|
||||
ProjectionImportImageFilePreview = $"data:image/png;base64,{Convert.ToBase64String(response.Data.Data.ImageData)}";
|
||||
IsImportMapVisible = true;
|
||||
}
|
||||
else Snackbar.Add("Dữ liệu không hợp lệ", Severity.Warning);
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ImportNewMap()
|
||||
{
|
||||
if (string.IsNullOrEmpty(MapImport.Name))
|
||||
{
|
||||
Snackbar.Add("Map's name không được để trống.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var nameInvalid = MapEditorHelper.NameChecking(MapImport.Name);
|
||||
if (!nameInvalid.IsSuccess)
|
||||
{
|
||||
Snackbar.Add(nameInvalid.returnStr, Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var response = await (await Http.PostAsJsonAsync("api/MapsManager/import", MapImport)).Content.ReadFromJsonAsync<MessageResult<MapInfoDto>>();
|
||||
if (response is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Warning);
|
||||
else if (!response.IsSuccess) Snackbar.Add($"Có lỗi xảy ra: {response.Message}", Severity.Warning);
|
||||
else
|
||||
{
|
||||
if (response.Data is not null)
|
||||
{
|
||||
Maps.Add(response.Data);
|
||||
Table?.ReloadServerData();
|
||||
Snackbar.Add($"Import bản đồ thành công!", Severity.Success);
|
||||
}
|
||||
else Snackbar.Add("Dữ liệu không hợp lệ", Severity.Warning);
|
||||
}
|
||||
MapImport = default!;
|
||||
IsImportMapVisible = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
21
RobotNet.WebApp/Pages/NavigationMapsManager.razor.css
Normal file
21
RobotNet.WebApp/Pages/NavigationMapsManager.razor.css
Normal file
@@ -0,0 +1,21 @@
|
||||
.map-preview{
|
||||
width: 20%;
|
||||
height: 100%;
|
||||
border-left: 1px solid silver;
|
||||
}
|
||||
|
||||
.map-create-item {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: fit-content;
|
||||
}
|
||||
|
||||
.map-create-item img {
|
||||
justify-content: center;
|
||||
width: 400px;
|
||||
height: 300px;
|
||||
object-fit: contain;
|
||||
border-radius: 10px;
|
||||
image-rendering: pixelated;
|
||||
}
|
||||
71
RobotNet.WebApp/Pages/OpenACSSettings.razor
Normal file
71
RobotNet.WebApp/Pages/OpenACSSettings.razor
Normal file
@@ -0,0 +1,71 @@
|
||||
@page "/open-acs"
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
@using RobotNet.RobotShares.OpenACS
|
||||
@using RobotNet.Shares
|
||||
@using RobotNet.WebApp.Robots.Components.OpenACS
|
||||
@attribute [Authorize]
|
||||
|
||||
@inject IHttpClientFactory HttpClientFactory
|
||||
|
||||
<PageTitle>Open ACS</PageTitle>
|
||||
|
||||
<div class="d-flex flex-row w-100 h-100 p-1 position-relative">
|
||||
<div style="width: 35%; max-width: 560px; overflow-y: auto; overflow-x: hidden">
|
||||
<PublishSetting @ref="PublishSettingRef" SettingDto="@PublishSettingDto.PublishSetting" />
|
||||
<TrafficSetting @ref="TrafficSettingRef" SettingDto="@PublishSettingDto.TrafficSetting" />
|
||||
<TrafficRequest />
|
||||
<DashboardConfig />
|
||||
</div>
|
||||
<div style="width: 65%" class="ms-2 flex-grow-1 flex-column">
|
||||
<div style="height: 70%">
|
||||
<ACSLog />
|
||||
</div>
|
||||
<div style="height: 28%" class="flex-grow-1 mt-2">
|
||||
<TrafficACSLockedView />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudOverlay @bind-Visible="OverlayIsVisible" DarkBackground="true" Absolute="true">
|
||||
<MudText Typo="Typo.h1" Color="@Color.Error" Style="font-weight: bold;">Loadding...</MudText>
|
||||
</MudOverlay>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
private OpenACSSettingsDto PublishSettingDto = new();
|
||||
private bool OverlayIsVisible = false;
|
||||
|
||||
private PublishSetting PublishSettingRef = default!;
|
||||
private TrafficSetting TrafficSettingRef = default!;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
await LoadSettings();
|
||||
}
|
||||
|
||||
private async Task LoadSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
OverlayIsVisible = true;
|
||||
StateHasChanged();
|
||||
|
||||
using var client = HttpClientFactory.CreateClient("RobotManagerAPI");
|
||||
var settings = await client.GetFromJsonAsync<MessageResult<OpenACSSettingsDto>>("api/OpenACSSettings");
|
||||
if (settings is null || settings.Data is null || !settings.IsSuccess) PublishSettingDto = new();
|
||||
else PublishSettingDto = settings.Data;
|
||||
|
||||
PublishSettingRef.UpdateSettings(PublishSettingDto.PublishSetting);
|
||||
TrafficSettingRef.UpdateSettings(PublishSettingDto.TrafficSetting);
|
||||
|
||||
OverlayIsVisible = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
}
|
||||
}
|
||||
}
|
||||
108
RobotNet.WebApp/Pages/RobotDetail.razor
Normal file
108
RobotNet.WebApp/Pages/RobotDetail.razor
Normal file
@@ -0,0 +1,108 @@
|
||||
@page "/robots/detail/{RobotId}"
|
||||
@attribute [Authorize]
|
||||
|
||||
@implements IAsyncDisposable
|
||||
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
@using RobotNet.RobotShares.Dtos
|
||||
@using RobotNet.Shares
|
||||
@using RobotNet.WebApp.Clients
|
||||
@using RobotNet.WebApp.Robots.Components.Robot
|
||||
|
||||
@inject RobotHubClient RobotHub
|
||||
@inject IHttpClientFactory HttpFactory
|
||||
|
||||
<PageTitle>Robot Detail</PageTitle>
|
||||
|
||||
<div class="d-flex flex-row w-100 h-100 p-1 position-relative">
|
||||
<div style="width: 35%; max-width: 560px">
|
||||
<RobotAction @ref="@RobotActionRef" Robot="@Robot" />
|
||||
<RobotTestRandom @ref="@RobotTestRandomRef" Robot="@Robot" />
|
||||
</div>
|
||||
<div style="width: 65%" class="ms-2 flex-grow-1">
|
||||
<RobotInfomation @ref="@RobotInfomationRef" />
|
||||
</div>
|
||||
|
||||
<MudOverlay @bind-Visible="IsDeactive" DarkBackground="true" Absolute="true">
|
||||
<MudText Typo="Typo.h1" Color="@Color.Error" Style="font-weight: bold;">@DeactiveStr</MudText>
|
||||
</MudOverlay>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string RobotId { get; set; } = "";
|
||||
|
||||
private RobotDto Robot = new();
|
||||
private RobotInfomation RobotInfomationRef = default!;
|
||||
private RobotAction RobotActionRef = default!;
|
||||
private RobotTestRandom RobotTestRandomRef = default!;
|
||||
private bool IsDeactive;
|
||||
private string DeactiveStr = "Robot Empty";
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
RobotHub.VDA5050InfoChanged += VDA5050InfoChanged;
|
||||
RobotHub.RobotDetailDeactive += RobotDetailDeactive;
|
||||
await RobotHub.StartAsync();
|
||||
|
||||
await LoadRobot();
|
||||
}
|
||||
|
||||
private async Task LoadRobot()
|
||||
{
|
||||
try
|
||||
{
|
||||
IsDeactive = true;
|
||||
StateHasChanged();
|
||||
|
||||
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
|
||||
var result = await Http.GetFromJsonAsync<MessageResult<RobotDto?>>($"api/Robots/{RobotId}");
|
||||
if (result is null || result.Data is null || !result.IsSuccess) return;
|
||||
Robot = result.Data;
|
||||
|
||||
await RobotHub.RobotDetailActive(RobotId);
|
||||
|
||||
IsDeactive = false;
|
||||
StateHasChanged();
|
||||
await RobotActionRef.LoadNodes();
|
||||
await RobotActionRef.LoadActionAsync();
|
||||
await RobotTestRandomRef.LoadNodes();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
}
|
||||
}
|
||||
|
||||
private void VDA5050InfoChanged(RobotVDA5050StateDto state)
|
||||
{
|
||||
if (state.RobotId == RobotId)
|
||||
{
|
||||
Robot.Online = state.Online;
|
||||
RobotInfomationRef.UpdateState(state);
|
||||
RobotActionRef.UpdateState(state.Online, state.IsWorking);
|
||||
RobotTestRandomRef.UpdateState(state.Online, state.IsWorking);
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void RobotDetailDeactive()
|
||||
{
|
||||
DeactiveStr = "Deactive";
|
||||
IsDeactive = true;
|
||||
StateHasChanged();
|
||||
RobotHub.VDA5050InfoChanged -= VDA5050InfoChanged;
|
||||
RobotHub.RobotDetailDeactive -= RobotDetailDeactive;
|
||||
_ = RobotHub.StopAsync();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
RobotHub.VDA5050InfoChanged -= VDA5050InfoChanged;
|
||||
RobotHub.RobotDetailDeactive -= RobotDetailDeactive;
|
||||
await RobotHub.StopAsync();
|
||||
}
|
||||
}
|
||||
315
RobotNet.WebApp/Pages/RobotManager.razor
Normal file
315
RobotNet.WebApp/Pages/RobotManager.razor
Normal file
@@ -0,0 +1,315 @@
|
||||
@page "/robots"
|
||||
@attribute [Authorize]
|
||||
@implements IAsyncDisposable
|
||||
|
||||
@using RobotNet.MapShares
|
||||
@using RobotNet.RobotShares.Dtos
|
||||
@using RobotNet.Shares
|
||||
@using RobotNet.WebApp.Clients
|
||||
@using RobotNet.WebApp.Robots.Components
|
||||
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService Dialog
|
||||
@inject IHttpClientFactory HttpFactory
|
||||
@inject IJSRuntime JSRuntime
|
||||
@inject NavigationManager NavManager
|
||||
@inject RobotHubClient RobotHub
|
||||
|
||||
<PageTitle>Robot Manager</PageTitle>
|
||||
|
||||
<div class="d-flex flex-column overflow-hidden w-100 h-100 p-2">
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<MudTextField Value="txtSearch" T="string" Label="Search" Variant="Variant.Outlined" Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
AdornmentColor="Color.Secondary" Style="max-width: 550px" TextChanged="TextSearchChanged" />
|
||||
|
||||
<MudButton Class="me-3" Variant="Variant.Filled" Color="Color.Secondary" OnClick="AddSimulation" Size="Size.Large">Simulation</MudButton>
|
||||
<MudButton StartIcon="@Icons.Material.Filled.Add" Variant="Variant.Filled" Color="Color.Primary" Size="Size.Large" OnClick="OpenCreateRobot">
|
||||
NEW
|
||||
</MudButton>
|
||||
</div>
|
||||
<div class="d-flex" style="height: 92%">
|
||||
<MudTable Class="w-100" @ref="Table" T="RobotDto" Items="@RobotsShow" Loading="@IsLoading" Dense Hover FixedHeader ReadOnly Striped RowClass="cursor-pointer"
|
||||
ServerData="ReloadData" MultiSelection @bind-SelectedItems="@RobotSelecteds"
|
||||
Outlined="true" Height="95%">
|
||||
<HeaderContent>
|
||||
<MudTh>Name</MudTh>
|
||||
<MudTh>Id</MudTh>
|
||||
<MudTh>Model</MudTh>
|
||||
<MudTh>Map</MudTh>
|
||||
<MudTh>NavigationType</MudTh>
|
||||
<MudTh>Online</MudTh>
|
||||
<MudTh>State</MudTh>
|
||||
<MudTh>Pin</MudTh>
|
||||
<MudTh></MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="Name">@context.Name</MudTd>
|
||||
<MudTd DataLabel="Id">@context.RobotId</MudTd>
|
||||
<MudTd DataLabel="Model">@context.ModelName</MudTd>
|
||||
<MudTd DataLabel="Map">@context.MapName</MudTd>
|
||||
<MudTd DataLabel="NavigationType">@context.NavigationType</MudTd>
|
||||
<MudTd DataLabel="Online">
|
||||
<MudAvatar Color="@(context.Online ? Color.Success : Color.Default)" Size="Size.Small"></MudAvatar>
|
||||
</MudTd>
|
||||
<MudTd DataLabel="State">@context.State</MudTd>
|
||||
<MudTd DataLabel="Pin">@($"{context.Battery} %")</MudTd>
|
||||
<MudTd>
|
||||
<div class="d-flex justify-content-center">
|
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" aria-label="Delete" Color="Color.Secondary" OnClick="() => DeleteRobot(context)" />
|
||||
<MudIconButton Icon="@Icons.Material.Filled.TrendingFlat" aria-label="Show" Color="Color.Primary" OnClick="@(() =>NavManager.NavigateTo($"/robots/detail/{context.RobotId}"))" />
|
||||
</div>
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
<PagerContent>
|
||||
<MudTablePager />
|
||||
</PagerContent>
|
||||
</MudTable>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudDialog @bind-Visible="IsCreateRobotVisible">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
Create New Robot
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudContainer Class="d-flex flex-column">
|
||||
<MudFocusTrap DefaultFocus="DefaultFocus.FirstChild">
|
||||
<MudTextField Class="my-2" Variant="Variant.Outlined"
|
||||
@bind-Value="RobotCreate.Name" T="string"
|
||||
Label="Name" Required="true" Validation="@(new Func<string, IEnumerable<string>>(MapEditorHelper.NameValidation))"
|
||||
RequiredError="Robot's' name is required!" Counter="127" />
|
||||
<MudTextField Class="my-2" Variant="Variant.Outlined"
|
||||
@bind-Value="RobotCreate.RobotId" T="string"
|
||||
Label="RobotId" Required="true" Validation="@(new Func<string, IEnumerable<string>>(MapEditorHelper.RobotIdValidation))"
|
||||
RequiredError="Robot's' Id is required!" Counter="127" />
|
||||
<MudSelect Class="my-2" T="RobotModelDto" Label="Model" AnchorOrigin="Origin.BottomLeft" @bind-Value="RobotModelSelected" Variant="Variant.Outlined">
|
||||
@foreach (var model in ListRobotModels)
|
||||
{
|
||||
<MudSelectItem Value="@model">@model.ModelName</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
</MudFocusTrap>
|
||||
</MudContainer>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@(() => IsCreateRobotVisible = false)" Variant="Variant.Filled">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="CreateRobot" Variant="Variant.Filled">Create</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
private string? txtSearch { get; set; }
|
||||
private bool IsLoading { get; set; }
|
||||
|
||||
private MudTable<RobotDto>? Table;
|
||||
private readonly List<RobotDto> Robots = new();
|
||||
private List<RobotDto> RobotsShow = new();
|
||||
private HashSet<RobotDto> RobotSelecteds = [];
|
||||
|
||||
private bool IsCreateRobotVisible { get; set; }
|
||||
private readonly RobotCreateModel RobotCreate = new();
|
||||
private readonly List<RobotModelDto> ListRobotModels = new();
|
||||
private RobotModelDto? RobotModelSelected { get; set; }
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
await LoadRobots();
|
||||
RobotHub.IsOnlineChanged += RobotIsOnlineChanged;
|
||||
await RobotHub.StartAsync();
|
||||
}
|
||||
|
||||
private void RobotIsOnlineChanged(IEnumerable<RobotOnlineStateDto> robots)
|
||||
{
|
||||
foreach (var robot in robots)
|
||||
{
|
||||
var robotDto = Robots.FirstOrDefault(r => r.RobotId == robot.RobotId);
|
||||
if (robotDto is null) continue;
|
||||
robotDto.Online = robot.IsOnline;
|
||||
robotDto.State = robot.State;
|
||||
robotDto.Battery = robot.Battery;
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task LoadRobots()
|
||||
{
|
||||
IsLoading = true;
|
||||
Robots.Clear();
|
||||
StateHasChanged();
|
||||
|
||||
using var Http = HttpFactory.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 null || !robots.Data.Any())
|
||||
{
|
||||
Snackbar.Add("Không có robot nào", Severity.Warning);
|
||||
RobotsShow.Clear();
|
||||
Table?.ReloadServerData();
|
||||
}
|
||||
else
|
||||
{
|
||||
Robots.AddRange(robots.Data.OrderByDescending(robot => robot.Online));
|
||||
Table?.ReloadServerData();
|
||||
}
|
||||
IsLoading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private bool FilterFunc(RobotDto robot)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(txtSearch))
|
||||
return true;
|
||||
if (robot.Name.Contains(txtSearch, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
if (robot.RobotId.Contains(txtSearch, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
if (robot.ModelName.Contains(txtSearch, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
if (robot.MapName.ToString().Contains(txtSearch, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
if (robot.State.ToString().Contains(txtSearch, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
if (robot.NavigationType.ToString().Contains(txtSearch, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private Task<TableData<RobotDto>> ReloadData(TableState state, CancellationToken _)
|
||||
{
|
||||
var robots = new List<RobotDto>();
|
||||
Robots.ForEach(robot =>
|
||||
{
|
||||
if (FilterFunc(robot)) robots.Add(robot);
|
||||
});
|
||||
RobotsShow = robots.Skip(state.Page * state.PageSize).Take(state.PageSize).ToList();
|
||||
return Task.FromResult(new TableData<RobotDto>() { TotalItems = robots.Count(), Items = RobotsShow });
|
||||
}
|
||||
|
||||
private async Task DeleteRobot(RobotDto robot)
|
||||
{
|
||||
var parameters = new DialogParameters<ConfirmDialog>
|
||||
{
|
||||
{ x => x.Content, "Bạn có chắc chắn muốn xóa robot đi không?" },
|
||||
{ x => x.ConfirmText, "Delete" },
|
||||
{ x => x.Color, Color.Secondary }
|
||||
};
|
||||
var ConfirmDelete = await Dialog.ShowAsync<ConfirmDialog>("Xoá Robot Model", parameters);
|
||||
var result = await ConfirmDelete.Result;
|
||||
if (result is not null && result.Data is not null && bool.TryParse(result.Data.ToString(), out bool data) && data)
|
||||
{
|
||||
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
|
||||
var delete = await Http.DeleteFromJsonAsync<MessageResult>($"api/Robots/{robot.RobotId}");
|
||||
if (delete is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!delete.IsSuccess) Snackbar.Add($"Có lỗi xảy ra: {delete.Message}", Severity.Error);
|
||||
else
|
||||
{
|
||||
Robots.Remove(robot);
|
||||
Snackbar.Add("Xóa robot thành công!", Severity.Success);
|
||||
Table?.ReloadServerData();
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void TextSearchChanged(string text)
|
||||
{
|
||||
txtSearch = text;
|
||||
Table?.ReloadServerData();
|
||||
}
|
||||
|
||||
private async Task OpenCreateRobot()
|
||||
{
|
||||
ListRobotModels.Clear();
|
||||
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
|
||||
var robotmodels = await Http.GetFromJsonAsync<IEnumerable<RobotModelDto>>($"api/RobotModels?txtSearch={txtSearch}");
|
||||
if (robotmodels is null || robotmodels.Count() == 0)
|
||||
{
|
||||
Snackbar.Add("Vui lòng tạo robot model", Severity.Error);
|
||||
return;
|
||||
}
|
||||
else ListRobotModels.AddRange(robotmodels);
|
||||
|
||||
RobotModelSelected = ListRobotModels.First();
|
||||
RobotCreate.Name = "";
|
||||
RobotCreate.RobotId = "";
|
||||
RobotCreate.ModelId = Guid.Empty;
|
||||
IsCreateRobotVisible = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task CreateRobot()
|
||||
{
|
||||
if (RobotModelSelected is null)
|
||||
{
|
||||
Snackbar.Add("Hãy chọn robot model!", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(RobotCreate.Name))
|
||||
{
|
||||
Snackbar.Add("Trường tên không được để trống", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var nameInvalid = MapEditorHelper.NameChecking(RobotCreate.Name);
|
||||
if (!nameInvalid.IsSuccess)
|
||||
{
|
||||
Snackbar.Add(nameInvalid.returnStr, Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(RobotCreate.RobotId))
|
||||
{
|
||||
Snackbar.Add("Trường RobotId không được để trống", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
RobotCreate.ModelId = RobotModelSelected.Id;
|
||||
|
||||
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
|
||||
var create = await (await Http.PostAsJsonAsync("api/Robots", RobotCreate)).Content.ReadFromJsonAsync<MessageResult<RobotDto>>();
|
||||
if (create is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!create.IsSuccess) Snackbar.Add($"Có lỗi xảy ra: {create.Message}", Severity.Error);
|
||||
else if (create.Data is null) Snackbar.Add("Tạo robot không thành công", Severity.Error);
|
||||
else
|
||||
{
|
||||
Robots.Add(new()
|
||||
{
|
||||
Id = create.Data.Id,
|
||||
RobotId = create.Data.RobotId,
|
||||
Name = create.Data.Name,
|
||||
ModelId = create.Data.ModelId,
|
||||
ModelName = create.Data.ModelName,
|
||||
NavigationType = create.Data.NavigationType,
|
||||
});
|
||||
Table?.ReloadServerData();
|
||||
IsCreateRobotVisible = false;
|
||||
Snackbar.Add("Tạo robot thành công!", Severity.Success);
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task AddSimulation()
|
||||
{
|
||||
if (!RobotSelecteds.Any()) return;
|
||||
var robotIds = RobotSelecteds.Select(r => r.RobotId).ToList();
|
||||
|
||||
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
|
||||
var onRobot = await (await Http.PostAsJsonAsync($"api/Robots/simulation", robotIds)).Content.ReadFromJsonAsync<MessageResult>();
|
||||
if (onRobot is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!onRobot.IsSuccess) Snackbar.Add($"Có lỗi xảy ra: {onRobot.Message}", Severity.Error);
|
||||
else Snackbar.Add("Khởi tạo thành công!", Severity.Success);
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
RobotHub.IsOnlineChanged -= RobotIsOnlineChanged;
|
||||
await RobotHub.StopAsync();
|
||||
}
|
||||
}
|
||||
464
RobotNet.WebApp/Pages/RobotModelManager.razor
Normal file
464
RobotNet.WebApp/Pages/RobotModelManager.razor
Normal file
@@ -0,0 +1,464 @@
|
||||
@page "/robots/model"
|
||||
@attribute [Authorize]
|
||||
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
@using RobotNet.MapShares
|
||||
@using RobotNet.RobotShares.Dtos
|
||||
@using RobotNet.RobotShares.Enums
|
||||
@using RobotNet.Shares
|
||||
@using RobotNet.WebApp.Robots.Components
|
||||
@using RobotNet.WebApp.Robots.Components.Robot
|
||||
@using System.Net.Http.Headers
|
||||
|
||||
@inject IHttpClientFactory HttpFactory
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService Dialog
|
||||
|
||||
<PageTitle>Robot Model</PageTitle>
|
||||
|
||||
<style>
|
||||
.selected {
|
||||
background-color: #3399ff !important;
|
||||
}
|
||||
|
||||
.selected > td {
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.selected > td .mud-input {
|
||||
color: white !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="d-flex flex-row w-100 h-100 p-2 overflow-hidden">
|
||||
<div class="d-flex h-100 flex-column flex-grow-1 pe-2">
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<MudTextField Value="txtSearch" T="string" Label="Search" Variant="Variant.Outlined" Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
AdornmentColor="Color.Secondary" ValueChanged="TextSearchChanged" Style="max-width: 550px" />
|
||||
<MudButton StartIcon="@Icons.Material.Filled.Add" Variant="Variant.Filled" Color="Color.Primary" Size="Size.Large" OnClick="OpenCreateRobotModel">
|
||||
NEW
|
||||
</MudButton>
|
||||
</div>
|
||||
<div class="d-flex" style="height: 92%">
|
||||
<MudTable Class="w-100" @ref="Table" Items="@RobotModelsShow" T="RobotModelDto" Dense=true Hover=true ReadOnly=true FixedHeader=true RowClass="cursor-pointer" Striped="true"
|
||||
ServerData="ReloadData" Loading=@IsLoading Outlined="true" RowClassFunc="@SelectedRowClassFunc" OnRowClick="RowClickEvent" Height="95%">
|
||||
<HeaderContent>
|
||||
<MudTh>Nr</MudTh>
|
||||
<MudTh>Name</MudTh>
|
||||
<MudTh>Length (m)</MudTh>
|
||||
<MudTh>Width (m)</MudTh>
|
||||
<MudTh>NavigationPointX (m)</MudTh>
|
||||
<MudTh>NavigationPointY (m)</MudTh>
|
||||
<MudTh>NavigationType</MudTh>
|
||||
<MudTh></MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="Nr">
|
||||
@(Table?.CurrentPage * Table?.RowsPerPage + RobotModelsShow.IndexOf(context) + 1)
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Name">
|
||||
@context.ModelName
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Length">
|
||||
@context.Length
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Width">
|
||||
@context.Width
|
||||
</MudTd>
|
||||
<MudTd DataLabel="OriginX">
|
||||
@context.OriginX
|
||||
</MudTd>
|
||||
<MudTd DataLabel="OriginY">
|
||||
@context.OriginY
|
||||
</MudTd>
|
||||
<MudTd DataLabel="NavigationType">
|
||||
@context.NavigationType
|
||||
</MudTd>
|
||||
<MudTd>
|
||||
<div class="d-flex flex-row-reverse">
|
||||
<MudMenu Icon="@Icons.Material.Filled.MoreVert" AnchorOrigin="Origin.BottomCenter">
|
||||
<MudMenuItem OnClick="(() => OpenUpdateRobotModel(context))" Icon="@Icons.Material.Filled.Edit" IconColor="Color.Info">Edit</MudMenuItem>
|
||||
<MudMenuItem OnClick="(() => DeleteRobotModel(context.Id))" Icon="@Icons.Material.Filled.Delete" IconColor="Color.Error">Delete</MudMenuItem>
|
||||
</MudMenu>
|
||||
</div>
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
<PagerContent>
|
||||
<div class="d-flex w-100 flex-row-reverse">
|
||||
<MudTablePager Style="width: 100%;" PageSizeOptions="new[] {25 , 100, 200}" />
|
||||
</div>
|
||||
</PagerContent>
|
||||
</MudTable>
|
||||
</div>
|
||||
</div>
|
||||
<div class="robot-preview">
|
||||
<RobotModelPreview @ref="@RobotModelPreviewRef"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudDialog @bind-Visible="IsCreateRobotModelVisible">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
Create New Robot Model
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudContainer Class="d-flex flex-column" Style="max-height: 700px; overflow-y: auto">
|
||||
<MudTextField Class="my-2" ShrinkLabel
|
||||
@bind-Value="RobotModelCreateModel.ModelName" T="string"
|
||||
Label="Name" Required="true" RequiredError="Name is required!"
|
||||
Counter="18" Variant="Variant.Outlined"
|
||||
Validation="@(new Func<string, IEnumerable<string>>(MapEditorHelper.NameValidation))" />
|
||||
<div class="d-flex flex-row my-2">
|
||||
<MudNumericField Class="me-2" @bind-Value="RobotModelCreateModel.Length" Label="Length" Step="0.1" Min="0" Variant="Variant.Outlined" />
|
||||
<MudNumericField Class="ms-2" @bind-Value="RobotModelCreateModel.Width" Label="Width" Step="0.1" Min="0" Variant="Variant.Outlined" />
|
||||
</div>
|
||||
<div class="d-flex flex-row my-2">
|
||||
<MudNumericField Class="me-2" @bind-Value="RobotModelCreateModel.OriginX" Label="NavigationPointX" Step="0.1" Variant="Variant.Outlined" />
|
||||
<MudNumericField Class="ms-2" @bind-Value="RobotModelCreateModel.OriginY" Label="NavigationPointY" Step="0.1" Variant="Variant.Outlined" />
|
||||
</div>
|
||||
<MudSelect Class="my-2" T="NavigationType" Label="Navigation Type" Variant="Variant.Outlined" @bind-Value="RobotModelCreateModel.NavigationType">
|
||||
@foreach (NavigationType type in Enum.GetValues(typeof(NavigationType)))
|
||||
{
|
||||
<MudSelectItem Value="@type">@type</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<div class="d-flex flex-column">
|
||||
<div class="d-flex flex-row my-2">
|
||||
<InputFile id="fileRobotModelImageCreate" OnChange="RobotModelCreateImageChanged" accept=".png" hidden />
|
||||
<MudButton HtmlTag="label"
|
||||
Variant="Variant.Filled"
|
||||
Color="Color.Primary"
|
||||
StartIcon="@Icons.Material.Filled.CloudUpload"
|
||||
for="fileRobotModelImageCreate">
|
||||
Robot Model Image
|
||||
</MudButton>
|
||||
</div>
|
||||
<div class="d-flex mb-2">
|
||||
<div class="robot-create-item">
|
||||
<img alt="Robot Model Image" src="@ProjectionImageFilePreview" style="image-rendering: pixelated;" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</MudContainer>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@(() => IsCreateRobotModelVisible = false)" Variant="Variant.Filled">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="CreateNewRobotModel" Variant="Variant.Filled">Create</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
<MudDialog @bind-Visible="IsUpdateRobotModelVisible">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
Update Robot Model
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudContainer Class="d-flex flex-column" Style="max-height: 700px;">
|
||||
<MudTextField Class="my-2"
|
||||
@bind-Value="RobotModelUpdateModel.ModelName" T="string"
|
||||
Label="RobotModel's name" Required="true"
|
||||
RequiredError="Robot Model name is required!" Counter="127" Variant="Variant.Outlined"
|
||||
Validation="@(new Func<string, IEnumerable<string>>(MapEditorHelper.NameValidation))" />
|
||||
<div class="d-flex flex-row my-2">
|
||||
<MudNumericField Class="me-2" @bind-Value="RobotModelUpdateModel.Length" Label="Length" Step="0.1" Variant="Variant.Outlined" />
|
||||
<MudNumericField Class="ms-2" @bind-Value="RobotModelUpdateModel.Width" Label="Width" Step="0.1" Variant="Variant.Outlined" />
|
||||
</div>
|
||||
<div class="d-flex flex-row my-2">
|
||||
<MudNumericField Class="me-2" @bind-Value="RobotModelUpdateModel.OriginX" Label="NavigationPointX" Step="0.1" Variant="Variant.Outlined" />
|
||||
<MudNumericField Class="ms-2" @bind-Value="RobotModelUpdateModel.OriginY" Label="NavigationPointY" Step="0.1" Variant="Variant.Outlined" />
|
||||
</div>
|
||||
</MudContainer>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@(() => IsUpdateRobotModelVisible = false)" Variant="Variant.Filled">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="UpdateRobotModel" Variant="Variant.Filled">Update</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
private string txtSearch = "";
|
||||
private bool IsLoading = false;
|
||||
|
||||
private RobotModelPreview RobotModelPreviewRef = default!;
|
||||
|
||||
private List<RobotModelDto> RobotModels = [];
|
||||
private List<RobotModelDto> RobotModelsShow = [];
|
||||
private MudTable<RobotModelDto>? Table;
|
||||
|
||||
private int selectedRowNumber = -1;
|
||||
private RobotModelDto RobotModelSelected = new();
|
||||
|
||||
private bool IsCreateRobotModelVisible { get; set; }
|
||||
private readonly RobotModelCreateModel RobotModelCreateModel = new();
|
||||
private IBrowserFile? RobotModelCreateImage { get; set; }
|
||||
private string? ProjectionImageFilePreview { get; set; }
|
||||
|
||||
private bool IsUpdateRobotModelVisible { get; set; }
|
||||
private readonly RobotModelUpdateModel RobotModelUpdateModel = new();
|
||||
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
await LoadRobotModels();
|
||||
}
|
||||
|
||||
private async Task LoadRobotModels()
|
||||
{
|
||||
try
|
||||
{
|
||||
IsLoading = true;
|
||||
RobotModels.Clear();
|
||||
StateHasChanged();
|
||||
|
||||
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
|
||||
var robotmodels = await Http.GetFromJsonAsync<IEnumerable<RobotModelDto>>($"api/RobotModels?txtSearch={txtSearch}");
|
||||
RobotModels.AddRange(robotmodels ?? []);
|
||||
|
||||
Table?.ReloadServerData();
|
||||
IsLoading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void TextSearchChanged(string text)
|
||||
{
|
||||
txtSearch = text;
|
||||
Table?.ReloadServerData();
|
||||
}
|
||||
|
||||
private bool FilterFunc(RobotModelDto robotmodel)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(txtSearch))
|
||||
return true;
|
||||
if (robotmodel.ModelName is not null && robotmodel.ModelName.Contains(txtSearch, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
if ($"{robotmodel.ModelName}".Contains(txtSearch))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private Task<TableData<RobotModelDto>> ReloadData(TableState state, CancellationToken _)
|
||||
{
|
||||
RobotModelsShow.Clear();
|
||||
var tasks = new List<RobotModelDto>();
|
||||
RobotModels.ForEach(task =>
|
||||
{
|
||||
if (FilterFunc(task)) tasks.Add(task);
|
||||
});
|
||||
RobotModelsShow = tasks.Skip(state.Page * state.PageSize).Take(state.PageSize).ToList();
|
||||
return Task.FromResult(new TableData<RobotModelDto>() { TotalItems = tasks.Count, Items = RobotModelsShow });
|
||||
}
|
||||
|
||||
private void RowClickEvent(TableRowClickEventArgs<RobotModelDto> tableRowClickEventArgs) { }
|
||||
|
||||
private string SelectedRowClassFunc(RobotModelDto element, int rowNumber)
|
||||
{
|
||||
if (selectedRowNumber == rowNumber && Table?.SelectedItem != null && !Table.SelectedItem.Equals(element))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
else if (selectedRowNumber == rowNumber && Table?.SelectedItem != null && Table.SelectedItem.Equals(element))
|
||||
{
|
||||
return "selected";
|
||||
}
|
||||
else if (Table?.SelectedItem != null && Table.SelectedItem.Equals(element))
|
||||
{
|
||||
selectedRowNumber = rowNumber;
|
||||
RobotModelSelected = element;
|
||||
RobotModelPreviewRef.SetRobotPreview(RobotModelSelected);
|
||||
return "selected";
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenCreateRobotModel()
|
||||
{
|
||||
RobotModelCreateModel.ModelName = string.Empty;
|
||||
RobotModelCreateModel.OriginX = 0;
|
||||
RobotModelCreateModel.OriginY = 0;
|
||||
RobotModelCreateModel.Length = 0;
|
||||
RobotModelCreateModel.Width = 0;
|
||||
RobotModelCreateModel.NavigationType = NavigationType.Differential;
|
||||
ProjectionImageFilePreview = "/images/Image-not-found.png";
|
||||
RobotModelCreateImage = null;
|
||||
IsCreateRobotModelVisible = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task RobotModelCreateImageChanged(InputFileChangeEventArgs e)
|
||||
{
|
||||
RobotModelCreateImage = e.File;
|
||||
if (RobotModelCreateImage is not null)
|
||||
{
|
||||
var buffers = new byte[RobotModelCreateImage.Size];
|
||||
var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
||||
await using var fs = new FileStream(path, FileMode.Create);
|
||||
await RobotModelCreateImage.OpenReadStream(RobotModelCreateImage.Size).CopyToAsync(fs);
|
||||
fs.Position = 0;
|
||||
await fs.ReadAsync(buffers);
|
||||
fs.Close();
|
||||
File.Delete(path);
|
||||
|
||||
ProjectionImageFilePreview = $"data:{RobotModelCreateImage.ContentType};base64,{Convert.ToBase64String(buffers)}";
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task CreateNewRobotModel()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (RobotModelCreateImage is null || string.IsNullOrEmpty(ProjectionImageFilePreview))
|
||||
{
|
||||
Snackbar.Add("Ảnh robot chưa được chọn.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(RobotModelCreateModel.ModelName))
|
||||
{
|
||||
Snackbar.Add("Map's name không được để trống.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var nameInvalid = MapEditorHelper.NameChecking(RobotModelCreateModel.ModelName);
|
||||
if (!nameInvalid.IsSuccess)
|
||||
{
|
||||
Snackbar.Add(nameInvalid.returnStr, Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
using var content = new MultipartFormDataContent
|
||||
{
|
||||
{ new StringContent(RobotModelCreateModel.ModelName ?? String.Empty), nameof(RobotModelCreateModel.ModelName) },
|
||||
{ new StringContent(RobotModelCreateModel.OriginX.ToString()), nameof(RobotModelCreateModel.OriginX) },
|
||||
{ new StringContent(RobotModelCreateModel.OriginY.ToString()), nameof(RobotModelCreateModel.OriginY) },
|
||||
{ new StringContent(RobotModelCreateModel.Length.ToString()), nameof(RobotModelCreateModel.Length) },
|
||||
{ new StringContent(RobotModelCreateModel.Width.ToString()), nameof(RobotModelCreateModel.Width) },
|
||||
{ new StringContent(RobotModelCreateModel.NavigationType.ToString()), nameof(RobotModelCreateModel.NavigationType) }
|
||||
};
|
||||
|
||||
var fileContent = new StreamContent(RobotModelCreateImage.OpenReadStream(maxAllowedSize: 2048000));
|
||||
fileContent.Headers.ContentType = new MediaTypeHeaderValue(RobotModelCreateImage.ContentType);
|
||||
content.Add(fileContent, "Image", RobotModelCreateImage.Name);
|
||||
|
||||
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
|
||||
var response = await (await Http.PostAsync("api/RobotModels", content)).Content.ReadFromJsonAsync<MessageResult<RobotModelDto>>();
|
||||
if (response is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!response.IsSuccess) Snackbar.Add(response.Message ?? "Lỗi chưa xác định.", Severity.Error);
|
||||
else if (response.Data is null) Snackbar.Add("Hệ thống không thể tạo robot model này", Severity.Error);
|
||||
else
|
||||
{
|
||||
RobotModels.Add(response.Data);
|
||||
Table?.ReloadServerData();
|
||||
Snackbar.Add($"Tạo robot model {RobotModelCreateModel.ModelName} thành công.", Severity.Success);
|
||||
}
|
||||
|
||||
IsCreateRobotModelVisible = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenUpdateRobotModel(RobotModelDto robotmodel)
|
||||
{
|
||||
RobotModelUpdateModel.Id = robotmodel.Id;
|
||||
RobotModelUpdateModel.ModelName = robotmodel.ModelName;
|
||||
RobotModelUpdateModel.OriginX = robotmodel.OriginX;
|
||||
RobotModelUpdateModel.OriginY = robotmodel.OriginY;
|
||||
RobotModelUpdateModel.Length = robotmodel.Length;
|
||||
RobotModelUpdateModel.Width = robotmodel.Width;
|
||||
IsUpdateRobotModelVisible = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task UpdateRobotModel()
|
||||
{
|
||||
var nameErrors = MapEditorHelper.NameChecking(RobotModelUpdateModel.ModelName);
|
||||
if (!nameErrors.IsSuccess)
|
||||
{
|
||||
Snackbar.Add(nameErrors.returnStr, Severity.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
|
||||
var result = await (await Http.PutAsJsonAsync($"api/RobotModels", RobotModelUpdateModel)).Content.ReadFromJsonAsync<MessageResult<RobotModelDto>>();
|
||||
if (result == null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!result.IsSuccess) Snackbar.Add(result.Message, Severity.Error);
|
||||
else if (result.Data is null)
|
||||
{
|
||||
Snackbar.Add("Hệ thống không thể cập nhật robot model này", Severity.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
var robotmodel = RobotModels.FirstOrDefault(rm => rm.Id == RobotModelUpdateModel.Id);
|
||||
if (robotmodel is not null)
|
||||
{
|
||||
robotmodel.ModelName = result.Data.ModelName;
|
||||
robotmodel.OriginX = result.Data.OriginX;
|
||||
robotmodel.OriginY = result.Data.OriginY;
|
||||
robotmodel.Width = result.Data.Width;
|
||||
robotmodel.Length = result.Data.Length;
|
||||
Snackbar.Add("Cập nhật thành công", Severity.Success);
|
||||
}
|
||||
else Snackbar.Add("Robot Model không tồn tại", Severity.Error);
|
||||
}
|
||||
|
||||
IsUpdateRobotModelVisible = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task DeleteRobotModel(Guid robotId)
|
||||
{
|
||||
var parameters = new DialogParameters<ConfirmDialog>
|
||||
{
|
||||
{ x => x.Content, "Bạn có chắc chắn muốn xóa robot model đi không?" },
|
||||
{ x => x.ConfirmText, "Delete" },
|
||||
{ x => x.Color, Color.Secondary }
|
||||
};
|
||||
var ConfirmDelete = await Dialog.ShowAsync<ConfirmDialog>("Xoá Robot Model", parameters);
|
||||
var result = await ConfirmDelete.Result;
|
||||
if (result is not null && result.Data is not null && bool.TryParse(result.Data.ToString(), out bool data) && data)
|
||||
{
|
||||
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
|
||||
var response = await Http.DeleteFromJsonAsync<MessageResult>($"api/RobotModels/{robotId}");
|
||||
if (response is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!response.IsSuccess) Snackbar.Add(response.Message ?? "Lỗi chưa xác định.", Severity.Error);
|
||||
else
|
||||
{
|
||||
var robotmodel = RobotModels.FirstOrDefault(m => m.Id == robotId);
|
||||
if (robotmodel is not null)
|
||||
{
|
||||
if (robotmodel.Id == RobotModelSelected.Id)
|
||||
{
|
||||
RobotModelPreviewRef.SetRobotPreview(null);
|
||||
Table?.SetSelectedItem(null);
|
||||
selectedRowNumber = -1;
|
||||
}
|
||||
RobotModels.Remove(robotmodel);
|
||||
Table?.ReloadServerData();
|
||||
Snackbar.Add($"Xóa robot model thành công.", Severity.Success);
|
||||
}
|
||||
else Snackbar.Add($"Robot Model không tồn tại.", Severity.Warning);
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
21
RobotNet.WebApp/Pages/RobotModelManager.razor.css
Normal file
21
RobotNet.WebApp/Pages/RobotModelManager.razor.css
Normal file
@@ -0,0 +1,21 @@
|
||||
.robot-preview {
|
||||
width: 20%;
|
||||
height: 100%;
|
||||
border-left: 1px solid silver;
|
||||
}
|
||||
|
||||
.robot-create-item {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 300px;
|
||||
}
|
||||
|
||||
.robot-create-item img {
|
||||
justify-content: center;
|
||||
width: 400px;
|
||||
height: 300px;
|
||||
object-fit: contain;
|
||||
border-radius: 10px;
|
||||
image-rendering: pixelated;
|
||||
}
|
||||
251
RobotNet.WebApp/Pages/RobotMonitoring.razor
Normal file
251
RobotNet.WebApp/Pages/RobotMonitoring.razor
Normal file
@@ -0,0 +1,251 @@
|
||||
@page "/robots/monitor"
|
||||
@attribute [Authorize]
|
||||
@implements IAsyncDisposable
|
||||
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
@using RobotNet.MapShares.Dtos
|
||||
@using RobotNet.RobotShares.Dtos
|
||||
@using RobotNet.RobotShares.Enums
|
||||
@using RobotNet.Shares
|
||||
@using RobotNet.WebApp.Clients
|
||||
@using RobotNet.WebApp.Robots.Components.Monitoring
|
||||
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IHttpClientFactory HttpFactory
|
||||
@inject RobotHubClient RobotHub
|
||||
|
||||
<PageTitle>Robot Monitoring</PageTitle>
|
||||
|
||||
<div class="d-flex flex-row w-100 h-100 position-relative">
|
||||
<div class="d-flex h-100 flex-grow-1 flex-column">
|
||||
<MonitorToolbar @ref="MonitorToolbarRef" Model="@ToolBarModel" ExpandChanged="ExpandChanged" ButtonEventClick="ButtonEventClick"
|
||||
CheckedEventClick="ToolbarCheckedClick" MapChanged="MapChanged" RobotChanged="RobotChanged" />
|
||||
<div class="flex-grow-1 w-100">
|
||||
<MonitorMap @ref="MonitorMapRef" ShowGrid="@ToolBarModel.ShowGrid" ShowName="@ToolBarModel.ShowName" ShowPath="@ToolBarModel.ShowPath" ShowLaser="@ToolBarModel.ShowLaser" ShowElement="@ToolBarModel.ShowElement"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="h-100 d-flex flex-column align-items-center" style="width: fit-content; border-left: 2px solid black;">
|
||||
<MonitorInfomation @ref="@MonitorInfomationRef" />
|
||||
</div>
|
||||
|
||||
<MudOverlay @bind-Visible="IsDeactive" DarkBackground="true" Absolute="true">
|
||||
<MudText Typo="Typo.h1" Color="@Color.Error" Style="font-weight: bold;">@IsDeactiveText</MudText>
|
||||
</MudOverlay>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
|
||||
private MonitorMap MonitorMapRef = null!;
|
||||
private MonitorToolbar MonitorToolbarRef = null!;
|
||||
private MonitorInfomation MonitorInfomationRef = null!;
|
||||
private MonitorToolBarModel ToolBarModel = new()
|
||||
{
|
||||
ShowGrid = false,
|
||||
ShowName = true,
|
||||
ShowPath = true,
|
||||
FocusRobot = false,
|
||||
ShowLaser = false,
|
||||
ShowElement = true,
|
||||
};
|
||||
|
||||
private List<MapInfoDto> Maps = [];
|
||||
private Guid MapIdSelected = new();
|
||||
|
||||
private bool IsDeactive = false;
|
||||
private string IsDeactiveText = "Deactive";
|
||||
private RobotInfomationDto RobotSelected = new();
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
RobotHub.MapDeactive += OnDeactive;
|
||||
RobotHub.UpdateChanged += OnUpdateChanged;
|
||||
RobotHub.ElementsStateChanged += ElementsStateChanged;
|
||||
await RobotHub.StartAsync();
|
||||
|
||||
await LoadMaps();
|
||||
}
|
||||
|
||||
private async Task LoadMaps()
|
||||
{
|
||||
try
|
||||
{
|
||||
IsDeactive = true;
|
||||
IsDeactiveText = "IsLoading...";
|
||||
Maps.Clear();
|
||||
StateHasChanged();
|
||||
|
||||
using var Http = HttpFactory.CreateClient("MapManagerAPI");
|
||||
var maps = await Http.GetFromJsonAsync<IEnumerable<MapInfoDto>>($"api/MapsManager?txtSearch=");
|
||||
|
||||
if (maps is null || maps.Count() == 0)
|
||||
{
|
||||
IsDeactiveText = "Map Empty";
|
||||
StateHasChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
var mapsActive = maps.Where(m => m.Active).ToList();
|
||||
if (mapsActive.Count == 0)
|
||||
{
|
||||
IsDeactiveText = "Map Empty";
|
||||
StateHasChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
Maps.AddRange(mapsActive ?? []);
|
||||
|
||||
if (Maps.Count > 0)
|
||||
{
|
||||
MonitorToolbarRef.LoadMaps(Maps, Maps[0]);
|
||||
await LoadMapData(Maps[0].Id);
|
||||
}
|
||||
|
||||
IsDeactive = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadMapData(Guid Id)
|
||||
{
|
||||
try
|
||||
{
|
||||
IsDeactive = true;
|
||||
IsDeactiveText = "IsLoading...";
|
||||
StateHasChanged();
|
||||
|
||||
using var Http = HttpFactory.CreateClient("MapManagerAPI");
|
||||
var mapDataResult = await Http.GetFromJsonAsync<MessageResult<MapDataDto>>($"api/MapsData/{Id}");
|
||||
if (mapDataResult is not null && mapDataResult.Data is not null)
|
||||
{
|
||||
await MonitorMapRef.LoadMap(null);
|
||||
await MonitorMapRef.LoadMap(mapDataResult.Data);
|
||||
MapIdSelected = mapDataResult.Data.Id;
|
||||
IsDeactive = false;
|
||||
if (RobotHub.IsConnected) await RobotHub.MapActive(MapIdSelected);
|
||||
}
|
||||
else IsDeactiveText = "Map Not Existed";
|
||||
|
||||
IsDeactive = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
catch
|
||||
{
|
||||
IsDeactiveText = "Map Not Existed";
|
||||
StateHasChanged();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task ToolbarCheckedClick(MonitorToolbarCheckedType type, bool value)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case MonitorToolbarCheckedType.ShowGrid:
|
||||
ToolBarModel.ShowGrid = value;
|
||||
break;
|
||||
case MonitorToolbarCheckedType.ShowName:
|
||||
ToolBarModel.ShowName = value;
|
||||
break;
|
||||
case MonitorToolbarCheckedType.ShowPath:
|
||||
ToolBarModel.ShowPath = value;
|
||||
break;
|
||||
case MonitorToolbarCheckedType.ShowLaser:
|
||||
ToolBarModel.ShowLaser = value;
|
||||
break;
|
||||
case MonitorToolbarCheckedType.ShowElement:
|
||||
ToolBarModel.ShowElement = value;
|
||||
break;
|
||||
case MonitorToolbarCheckedType.FocusRobot:
|
||||
ToolBarModel.FocusRobot = value;
|
||||
MonitorMapRef.FocusRobot(value);
|
||||
if (value) await MonitorMapRef.FocusRobotAsync();
|
||||
break;
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void ExpandChanged(bool value) => MonitorInfomationRef.ExpandedClick(value);
|
||||
|
||||
private async Task ButtonEventClick(MonitorToolbarButtonType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case MonitorToolbarButtonType.Fit:
|
||||
await MonitorMapRef.ScaleFitContentAsync();
|
||||
break;
|
||||
case MonitorToolbarButtonType.Focus:
|
||||
await MonitorMapRef.FocusRobotAsync();
|
||||
break;
|
||||
case MonitorToolbarButtonType.ZoomIn:
|
||||
await MonitorMapRef.ScaleZoom(0.5);
|
||||
break;
|
||||
case MonitorToolbarButtonType.ZoomOut:
|
||||
await MonitorMapRef.ScaleZoom(-0.5);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task MapChanged(MapInfoDto map)
|
||||
{
|
||||
if (map.Id != MapIdSelected) await LoadMapData(map.Id);
|
||||
}
|
||||
|
||||
private void RobotChanged(RobotInfomationDto robot)
|
||||
{
|
||||
if(robot.RobotId != RobotSelected.RobotId)
|
||||
{
|
||||
RobotSelected = robot;
|
||||
MonitorMapRef.RobotSelectedChange(RobotSelected.RobotId);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsUpdateing = false;
|
||||
private void OnUpdateChanged(IEnumerable<RobotInfomationDto> robotInfos)
|
||||
{
|
||||
if (IsUpdateing) return;
|
||||
IsUpdateing = true;
|
||||
InvokeAsync(async () =>
|
||||
{
|
||||
var robots = robotInfos.Where(r => r.MapId == MapIdSelected).ToList();
|
||||
await MonitorMapRef.SetRobotPosition([.. robots]);
|
||||
MonitorToolbarRef.LoadRobots([.. robotInfos]);
|
||||
var robotSelect = robots.FirstOrDefault(r => r.RobotId == RobotSelected.RobotId);
|
||||
if (robotSelect is not null) MonitorInfomationRef.UpdateState(robotSelect);
|
||||
IsUpdateing = false;
|
||||
});
|
||||
}
|
||||
|
||||
private void ElementsStateChanged(IEnumerable<ElementDto> elementsState)
|
||||
{
|
||||
_ = InvokeAsync(() =>
|
||||
{
|
||||
var elements = elementsState.Where(e => e.MapId == MapIdSelected).ToList();
|
||||
MonitorMapRef.ElementStateUpdated([.. elements]);
|
||||
});
|
||||
}
|
||||
|
||||
private void OnDeactive()
|
||||
{
|
||||
IsDeactiveText = "Deactive";
|
||||
IsDeactive = true;
|
||||
StateHasChanged();
|
||||
RobotHub.UpdateChanged -= OnUpdateChanged;
|
||||
RobotHub.MapDeactive -= OnDeactive;
|
||||
_ = RobotHub.StopAsync();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
RobotHub.MapDeactive -= OnDeactive;
|
||||
RobotHub.UpdateChanged -= OnUpdateChanged;
|
||||
await RobotHub.StopAsync();
|
||||
}
|
||||
}
|
||||
431
RobotNet.WebApp/Pages/RobotTrafficManager.razor
Normal file
431
RobotNet.WebApp/Pages/RobotTrafficManager.razor
Normal file
@@ -0,0 +1,431 @@
|
||||
@page "/traffic-manager"
|
||||
@attribute [Authorize]
|
||||
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
@using RobotNet.MapShares.Dtos
|
||||
@using RobotNet.RobotShares.Dtos
|
||||
@using RobotNet.RobotShares.Models
|
||||
@using RobotNet.Shares
|
||||
@using RobotNet.WebApp.Clients
|
||||
@using RobotNet.WebApp.Robots.Components
|
||||
@using RobotNet.WebApp.Robots.Components.Traffic
|
||||
|
||||
@inject ISnackbar Snackbar
|
||||
@inject TrafficHubClient TrafficHub
|
||||
@inject IDialogService Dialog
|
||||
@inject IHttpClientFactory HttpFactory
|
||||
|
||||
<PageTitle>Traffic Manager</PageTitle>
|
||||
|
||||
<style>
|
||||
.selected {
|
||||
background-color: #3399ff !important;
|
||||
}
|
||||
|
||||
.selected > td {
|
||||
color: white !important;
|
||||
}
|
||||
|
||||
.selected > td .mud-input {
|
||||
color: white !important;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="d-flex flex-row w-100 h-100 p-2 overflow-hidden position-relative">
|
||||
<div class="d-flex h-100 flex-column flex-grow-1 pe-2">
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<MudTextField Value="txtSearch" T="string" Label="Search" Variant="Variant.Outlined" Adornment="Adornment.End" AdornmentIcon="@Icons.Material.Filled.Search"
|
||||
AdornmentColor="Color.Secondary" Style="width: 40%; max-width: 400px" TextChanged="TextSearchChanged" />
|
||||
<MudSelect @bind-Value="@MapSelected" Label="Maps" T="TrafficMapDto" Style="width: 30%; max-width: 300px" Variant="Variant.Outlined" @bind-Value:after="MapChanged">
|
||||
@foreach (var map in Maps)
|
||||
{
|
||||
<MudSelectItem T="TrafficMapDto" Value="@map">@map.MapName</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
@* <MudButton Class="ms-2" StartIcon="@Icons.Material.Filled.Add" Variant="Variant.Filled" Color="Color.Primary" Size="Size.Large">
|
||||
Add Lock
|
||||
</MudButton> *@
|
||||
</div>
|
||||
<div class="d-flex" style="height: 92%">
|
||||
<MudTable Class="w-100" @ref="Table" T="TrafficAgentDto" Items="@AgentShow" Loading="@IsLoading" Dense Hover FixedHeader ReadOnly Striped RowClass="cursor-pointer"
|
||||
ServerData="ReloadData" Outlined="true" Height="95%" RowClassFunc="@SelectedRowClassFunc" OnRowClick="RowClickEvent">
|
||||
<HeaderContent>
|
||||
<MudTh>Nr</MudTh>
|
||||
<MudTh>RobotId</MudTh>
|
||||
<MudTh>Traffic State</MudTh>
|
||||
<MudTh>Target Node</MudTh>
|
||||
<MudTh>Release Node</MudTh>
|
||||
<MudTh>In Node</MudTh>
|
||||
<MudTh>Locked Node</MudTh>
|
||||
<MudTh></MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd DataLabel="Nr">
|
||||
@(Table?.CurrentPage * Table?.RowsPerPage + AgentShow.IndexOf(context) + 1)
|
||||
</MudTd>
|
||||
<MudTd DataLabel="RobotId">
|
||||
@context.RobotId
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Traffic State">
|
||||
@context.State
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Target Node">
|
||||
@(context.Nodes.Count > 0 ? (string.IsNullOrEmpty(context.Nodes[^1].Name) ? context.Nodes[^1].Id.ToString("N").Substring(0, 4) : context.Nodes[^1].Name) : "")
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Release Node">
|
||||
@(context.ReleaseNode is null ? "" : string.IsNullOrEmpty(context.ReleaseNode.Name) ? context.ReleaseNode.Id.ToString("N").Substring(0, 4) : context.ReleaseNode.Name)
|
||||
</MudTd>
|
||||
<MudTd DataLabel="In Node">
|
||||
@(context.InNode is null ? "" : string.IsNullOrEmpty(context.InNode.Name) ? context.InNode.Id.ToString("N").Substring(0, 4) : context.InNode.Name)
|
||||
</MudTd>
|
||||
<MudTd DataLabel="Locked Node">
|
||||
@(context.LockedNodes.Count > 0 ? (string.IsNullOrEmpty(context.LockedNodes[^1].Name) ? context.LockedNodes[^1].Id.ToString("N").Substring(0, 4) : context.LockedNodes[^1].Name) : "")
|
||||
</MudTd>
|
||||
<MudTd>
|
||||
<div class="d-flex flex-row-reverse">
|
||||
<MudMenu Icon="@Icons.Material.Filled.MoreVert" AnchorOrigin="Origin.BottomCenter">
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.Edit" IconColor="Color.Info" OnClick="@(async () => await OpenUpdateAgent(context))">Edit</MudMenuItem>
|
||||
<MudMenuItem Icon="@Icons.Material.Filled.Delete" IconColor="Color.Error" OnClick="@(async () => await DeleteAgent(context))">Delete</MudMenuItem>
|
||||
</MudMenu>
|
||||
</div>
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
<PagerContent>
|
||||
<div class="d-flex w-100 flex-row-reverse">
|
||||
<MudTablePager Style="width: 100%;" PageSizeOptions="new[] {25 , 100, 200}" />
|
||||
</div>
|
||||
</PagerContent>
|
||||
</MudTable>
|
||||
</div>
|
||||
</div>
|
||||
<div class="agent-preview">
|
||||
<TrafficAgentReview @ref="TrafficAgentReviewRef" />
|
||||
</div>
|
||||
<MudOverlay @bind-Visible="IsDeactive" DarkBackground="true" Absolute="true">
|
||||
<MudText Typo="Typo.h1" Color="@Color.Error" Style="font-weight: bold;">@DeactiveStr</MudText>
|
||||
</MudOverlay>
|
||||
</div>
|
||||
|
||||
<MudDialog @bind-Visible="IsEditAgentVisible">
|
||||
<TitleContent>
|
||||
<MudText Typo="Typo.h6">
|
||||
Edit Agent @AgentUpdate.AgentId
|
||||
</MudText>
|
||||
</TitleContent>
|
||||
<DialogContent>
|
||||
<MudContainer Class="d-flex flex-column">
|
||||
<div class="d-flex flex-row">
|
||||
<MudAutocomplete T="NodeDto" Variant="Variant.Outlined" Label="Node" SearchFunc="NodeSearch"
|
||||
MaxItems="@Nodes.Count" ToStringFunc="@(e=> e == null ? null : $"{e.Name}")" ValueChanged="NodeChanged" ShowProgressIndicator="true">
|
||||
<NoItemsTemplate>
|
||||
<MudText Align="Align.Center" Class="px-4 py-1">
|
||||
No items found
|
||||
</MudText>
|
||||
</NoItemsTemplate>
|
||||
</MudAutocomplete>
|
||||
<MudButton Class="d-flex flex-grow-1 mt-2 mb-1 ms-2" Variant="Variant.Filled" Color="Color.Info" OnClick="AddNode">Add</MudButton>
|
||||
</div>
|
||||
|
||||
<div class="paper-nodes">
|
||||
@foreach (var node in AgentUpdate.LockedNodes)
|
||||
{
|
||||
<div class="m-1" style="height: fit-content">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Info" Style="text-transform:none" OnClick="@(() => AgentUpdate.LockedNodes.Remove(node))">
|
||||
@(string.IsNullOrEmpty(node.Name) ? node.Id.ToString("N").Substring(0, 4) : node.Name)
|
||||
</MudButton>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</MudContainer>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="@(() => IsEditAgentVisible = false)" Variant="Variant.Filled">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="UpdateAgent" Variant="Variant.Filled">Update</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
private string? txtSearch { get; set; }
|
||||
private bool IsLoading { get; set; }
|
||||
|
||||
private bool IsDeactive;
|
||||
private string DeactiveStr = "Robot Empty";
|
||||
|
||||
private MudTable<TrafficAgentDto>? Table;
|
||||
private readonly List<TrafficAgentDto> Agents = [];
|
||||
private List<TrafficAgentDto> AgentShow = [];
|
||||
|
||||
private int selectedRowNumber = -1;
|
||||
private TrafficAgentDto? AgentSelected;
|
||||
|
||||
private List<TrafficMapDto> Maps = [];
|
||||
private TrafficMapDto? MapSelected;
|
||||
private TrafficAgentReview TrafficAgentReviewRef = default!;
|
||||
|
||||
private bool IsEditAgentVisible;
|
||||
private readonly UpdateAgentLockerModel AgentUpdate = new();
|
||||
private List<NodeDto> Nodes = [];
|
||||
private NodeDto? SelectedNode;
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
if (!firstRender) return;
|
||||
|
||||
TrafficHub.TrafficAgentUpdated += TrafficAgentUpdated;
|
||||
TrafficHub.MapDeactive += MapDeactive;
|
||||
await TrafficHub.StartAsync();
|
||||
await LoadTrafficMaps();
|
||||
}
|
||||
|
||||
private async Task LoadTrafficMaps()
|
||||
{
|
||||
IsLoading = true;
|
||||
StateHasChanged();
|
||||
|
||||
var trafficMaps = await TrafficHub.LoadTrafficMaps();
|
||||
if (!trafficMaps.IsSuccess) Snackbar.Add(trafficMaps.Message, Severity.Warning);
|
||||
else if (trafficMaps.Data is null || !trafficMaps.Data.Any())
|
||||
{
|
||||
Snackbar.Add("Không có bản đồ nào được tải lên", Severity.Warning);
|
||||
IsLoading = false;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
Maps = [.. trafficMaps.Data];
|
||||
if (Maps.Count > 0)
|
||||
{
|
||||
MapSelected = Maps.First();
|
||||
Agents.Clear();
|
||||
Agents.AddRange(MapSelected.Agents);
|
||||
Table?.ReloadServerData();
|
||||
await TrafficHub.TrafficActive(MapSelected.MapId);
|
||||
}
|
||||
}
|
||||
|
||||
IsLoading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void TextSearchChanged(string text)
|
||||
{
|
||||
txtSearch = text;
|
||||
Table?.ReloadServerData();
|
||||
}
|
||||
|
||||
private bool FilterFunc(TrafficAgentDto robot)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(txtSearch))
|
||||
return true;
|
||||
if (robot.RobotId.Contains(txtSearch, StringComparison.OrdinalIgnoreCase))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private Task<TableData<TrafficAgentDto>> ReloadData(TableState state, CancellationToken _)
|
||||
{
|
||||
AgentShow.Clear();
|
||||
var agents = new List<TrafficAgentDto>();
|
||||
Agents.ForEach(agent =>
|
||||
{
|
||||
if (FilterFunc(agent)) agents.Add(agent);
|
||||
});
|
||||
AgentShow = agents.Skip(state.Page * state.PageSize).Take(state.PageSize).ToList();
|
||||
return Task.FromResult(new TableData<TrafficAgentDto>() { TotalItems = agents.Count(), Items = AgentShow });
|
||||
}
|
||||
|
||||
private void RowClickEvent(TableRowClickEventArgs<TrafficAgentDto> tableRowClickEventArgs) { }
|
||||
|
||||
private string SelectedRowClassFunc(TrafficAgentDto element, int rowNumber)
|
||||
{
|
||||
if (selectedRowNumber == rowNumber && Table?.SelectedItem != null && !Table.SelectedItem.Equals(element))
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
else if (selectedRowNumber == rowNumber && Table?.SelectedItem != null && Table.SelectedItem.Equals(element))
|
||||
{
|
||||
return "selected";
|
||||
}
|
||||
else if (Table?.SelectedItem != null && Table.SelectedItem.Equals(element))
|
||||
{
|
||||
selectedRowNumber = rowNumber;
|
||||
AgentSelected = element;
|
||||
TrafficAgentReviewRef.UpdateState(AgentSelected);
|
||||
return "selected";
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private async Task MapChanged()
|
||||
{
|
||||
if (MapSelected is not null)
|
||||
{
|
||||
var trafficMap = await TrafficHub.LoadTrafficMap(MapSelected.MapId);
|
||||
if (!trafficMap.IsSuccess) Snackbar.Add(trafficMap.Message, Severity.Warning);
|
||||
else if (trafficMap.Data is null)
|
||||
{
|
||||
Snackbar.Add("Không có agent nào trong bản đồ này", Severity.Warning);
|
||||
Agents.Clear();
|
||||
AgentShow.Clear();
|
||||
if (Table is not null) await Table.ReloadServerData();
|
||||
}
|
||||
else
|
||||
{
|
||||
Agents.Clear();
|
||||
Agents.AddRange(trafficMap.Data.Agents);
|
||||
if (Table is not null) await Table.ReloadServerData();
|
||||
await TrafficHub.TrafficActive(MapSelected.MapId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TrafficAgentUpdated(IEnumerable<TrafficAgentDto> agents)
|
||||
{
|
||||
bool isNewUpdate = false;
|
||||
foreach (var newagent in agents)
|
||||
{
|
||||
var agent = Agents.FirstOrDefault(a => a.RobotId == newagent.RobotId);
|
||||
if (agent is null)
|
||||
{
|
||||
isNewUpdate = true;
|
||||
Agents.Add(newagent);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((agent.ReleaseNode is null && newagent.ReleaseNode is not null) || (agent.ReleaseNode is not null && newagent.ReleaseNode is null) ||
|
||||
(agent.ReleaseNode is not null && newagent.ReleaseNode is not null && agent.ReleaseNode.Id != newagent.ReleaseNode.Id) ||
|
||||
(agent.InNode is null && newagent.InNode is not null) || (agent.InNode is not null && newagent.InNode is null) ||
|
||||
(agent.InNode is not null && newagent.InNode is not null && agent.InNode.Id != newagent.InNode.Id) ||
|
||||
agent.State != newagent.State ||
|
||||
(agent.Nodes.Count > 0 && newagent.Nodes.Count == 0) || (agent.Nodes.Count == 0 && newagent.Nodes.Count > 0) ||
|
||||
(agent.Nodes.Count > 0 && newagent.Nodes.Count > 0 && agent.Nodes[^1].Id != newagent.Nodes[^1].Id) ||
|
||||
(agent.LockedNodes.Count > 0 && newagent.LockedNodes.Count == 0) || (agent.LockedNodes.Count == 0 && newagent.LockedNodes.Count > 0) ||
|
||||
(agent.LockedNodes.Count > 0 && newagent.LockedNodes.Count > 0 && agent.LockedNodes[^1].Id != newagent.LockedNodes[^1].Id)
|
||||
) isNewUpdate = true;
|
||||
agent.Nodes = [.. newagent.Nodes];
|
||||
agent.ReleaseNode = newagent.ReleaseNode;
|
||||
agent.LockedNodes = [.. newagent.LockedNodes];
|
||||
agent.InNode = newagent.InNode;
|
||||
agent.State = newagent.State;
|
||||
agent.SubNodes = [.. newagent.SubNodes];
|
||||
agent.GiveWayNodes = [.. newagent.GiveWayNodes];
|
||||
agent.ConflictNode = newagent.ConflictNode;
|
||||
agent.ConflictAgentId = newagent.ConflictAgentId;
|
||||
}
|
||||
if (AgentSelected is not null && newagent.RobotId == AgentSelected.RobotId) TrafficAgentReviewRef.UpdateState(AgentSelected);
|
||||
}
|
||||
if (isNewUpdate) Table?.ReloadServerData();
|
||||
}
|
||||
|
||||
private void MapDeactive()
|
||||
{
|
||||
DeactiveStr = "Deactive";
|
||||
IsDeactive = true;
|
||||
StateHasChanged();
|
||||
TrafficHub.TrafficAgentUpdated -= TrafficAgentUpdated;
|
||||
TrafficHub.MapDeactive -= MapDeactive;
|
||||
_ = TrafficHub.StopAsync();
|
||||
}
|
||||
|
||||
private async Task DeleteAgent(TrafficAgentDto agent)
|
||||
{
|
||||
var parameters = new DialogParameters<ConfirmDialog>
|
||||
{
|
||||
{ x => x.Content, "Bạn có chắc chắn muốn xóa agent đi không?" },
|
||||
{ x => x.ConfirmText, "Delete" },
|
||||
{ x => x.Color, Color.Secondary }
|
||||
};
|
||||
var ConfirmDelete = await Dialog.ShowAsync<ConfirmDialog>("Xoá Agent", parameters);
|
||||
var result = await ConfirmDelete.Result;
|
||||
if (result is not null && result.Data is not null && bool.TryParse(result.Data.ToString(), out bool data) && data)
|
||||
{
|
||||
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
|
||||
var delete = await Http.DeleteFromJsonAsync<MessageResult>($"api/TrafficManager/{MapSelected?.MapId}/{agent.RobotId}");
|
||||
if (delete is null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!delete.IsSuccess) Snackbar.Add($"Có lỗi xảy ra: {delete.Message}", Severity.Error);
|
||||
else
|
||||
{
|
||||
Agents.Remove(agent);
|
||||
Snackbar.Add("Xóa robot thành công!", Severity.Success);
|
||||
Table?.ReloadServerData();
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task OpenUpdateAgent(TrafficAgentDto agent)
|
||||
{
|
||||
AgentUpdate.AgentId = agent.RobotId;
|
||||
AgentUpdate.LockedNodes = agent.LockedNodes;
|
||||
AgentUpdate.MapId = MapSelected is null ? Guid.Empty : MapSelected.MapId;
|
||||
await LoadNodes();
|
||||
IsEditAgentVisible = true;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task UpdateAgent()
|
||||
{
|
||||
using var Http = HttpFactory.CreateClient("RobotManagerAPI");
|
||||
var result = await (await Http.PutAsJsonAsync($"api/TrafficManager", AgentUpdate)).Content.ReadFromJsonAsync<MessageResult>();
|
||||
if (result == null) Snackbar.Add("Lỗi giao tiếp với hệ thống", Severity.Error);
|
||||
else if (!result.IsSuccess) Snackbar.Add(result.Message, Severity.Error);
|
||||
else Snackbar.Add("Cập nhật thành công", Severity.Success);
|
||||
|
||||
IsEditAgentVisible = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public async Task LoadNodes()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var Http = HttpFactory.CreateClient("MapManagerAPI");
|
||||
var result = await Http.GetFromJsonAsync<NodeDto[]>($"api/Nodes/{MapSelected?.MapId}");
|
||||
if (result is not null) Nodes = result.Where(n => !string.IsNullOrEmpty(n.Name)).ToList();
|
||||
}
|
||||
catch (AccessTokenNotAvailableException ex)
|
||||
{
|
||||
ex.Redirect();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<IEnumerable<NodeDto>> NodeSearch(string value, CancellationToken token)
|
||||
{
|
||||
await Task.Delay(5, token);
|
||||
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
return Nodes.Select(n => n);
|
||||
}
|
||||
|
||||
return Nodes.Where(x => x.Name.Contains(value, StringComparison.InvariantCultureIgnoreCase)).Select(n => n);
|
||||
}
|
||||
|
||||
private void NodeChanged(NodeDto value)
|
||||
{
|
||||
if (SelectedNode is null || value.Id != SelectedNode.Id) SelectedNode = value;
|
||||
}
|
||||
|
||||
private void AddNode()
|
||||
{
|
||||
if (SelectedNode is not null && !AgentUpdate.LockedNodes.Any(n => n.Id == SelectedNode.Id)) AgentUpdate.LockedNodes.Add(new()
|
||||
{
|
||||
Id = SelectedNode.Id,
|
||||
X = SelectedNode.X,
|
||||
Y = SelectedNode.Y,
|
||||
Name = SelectedNode.Name,
|
||||
});
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
TrafficHub.TrafficAgentUpdated -= TrafficAgentUpdated;
|
||||
TrafficHub.MapDeactive -= MapDeactive;
|
||||
await TrafficHub.StopAsync();
|
||||
}
|
||||
}
|
||||
19
RobotNet.WebApp/Pages/RobotTrafficManager.razor.css
Normal file
19
RobotNet.WebApp/Pages/RobotTrafficManager.razor.css
Normal file
@@ -0,0 +1,19 @@
|
||||
.agent-preview {
|
||||
width: 30%;
|
||||
height: 100%;
|
||||
border-left: 1px solid silver;
|
||||
}
|
||||
|
||||
.paper-nodes {
|
||||
padding: 5px;
|
||||
border: 1px solid silver;
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-content: flex-start;
|
||||
overflow-x: hidden;
|
||||
overflow-y: auto;
|
||||
width: 100%;
|
||||
max-width: 530px;
|
||||
height: 200px;
|
||||
}
|
||||
602
RobotNet.WebApp/Pages/SEHC_DA3_Line1_HMI.razor
Normal file
602
RobotNet.WebApp/Pages/SEHC_DA3_Line1_HMI.razor
Normal file
@@ -0,0 +1,602 @@
|
||||
@layout Layout.HMILayout
|
||||
@page "/sehc/da3/line1"
|
||||
|
||||
@using Microsoft.AspNetCore.SignalR.Client
|
||||
@using RobotNet.Script.Shares
|
||||
@using RobotNet.WebApp.Clients
|
||||
|
||||
@attribute [Authorize]
|
||||
@implements IAsyncDisposable
|
||||
|
||||
@inject HMIHubClient hmiClient
|
||||
@inject ISnackbar Snackbar
|
||||
@inject IDialogService Dialog
|
||||
|
||||
<div class="w-100 h-100 position-relative overflow-hidden">
|
||||
<div class="w-100 h-100 position-absolute top-0 start-0 overflow-hidden d-flex flex-row">
|
||||
<div class="h-100 d-flex flex-column justify-content-start align-items-center p-2" style="width: 10%; border-right: 2px solid #34495e;">
|
||||
<!-- Card thông tin số nhiệm vụ - HMI Industrial Style -->
|
||||
<div class="mb-3 w-100 user-select-none position-relative" @onclick="CallResetStep" style="
|
||||
background: linear-gradient(145deg, #34495e, #2c3e50);
|
||||
border: 2px solid #7f8c8d;
|
||||
border-radius: 8px;
|
||||
box-shadow:
|
||||
inset 0 2px 4px rgba(255, 255, 255, 0.1),
|
||||
0 4px 8px rgba(0, 0, 0, 0.3);
|
||||
color: #ecf0f1;
|
||||
font-family: 'Courier New', monospace;
|
||||
">
|
||||
<div class="text-center py-2" style="
|
||||
background: linear-gradient(145deg, #3498db, #2980b9);
|
||||
border-bottom: 1px solid #34495e;
|
||||
border-radius: 6px 6px 0 0;
|
||||
font-size: 18px;
|
||||
font-weight: bold;
|
||||
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
|
||||
color: white;
|
||||
">
|
||||
STEP NUMBER
|
||||
</div>
|
||||
<div class="text-center py-3" style="
|
||||
background: linear-gradient(145deg, #1a252f, #16202b);
|
||||
border-radius: 0 0 6px 6px;
|
||||
">
|
||||
<div style="
|
||||
font-size: 48px;
|
||||
font-weight: bold;
|
||||
color: #00ff00;
|
||||
text-shadow: 0 0 8px #00ff00;
|
||||
font-family: 'Courier New', monospace;
|
||||
letter-spacing: 2px;
|
||||
">
|
||||
@Line1_HMI_Model.SEHCMissionStep
|
||||
</div>
|
||||
</div>
|
||||
<MudOverlay Visible="Line1_HMI_Model.Request_Reset_SEHC_DA3_Line1" DarkBackground AutoClose="false" Absolute>
|
||||
<div class="d-flex flex-column justify-content-center">
|
||||
<div class="d-flex justify-content-center">
|
||||
<MudProgressCircular Color="Color.Secondary" Size="Size.Large" Indeterminate="true" />
|
||||
</div>
|
||||
</div>
|
||||
</MudOverlay>
|
||||
</div>
|
||||
|
||||
<button class="mb-3 w-100 hmi-button onoff @hmiBtnIsWorkingClass">
|
||||
WORKING @(Line1_HMI_Model.IsWorking ? "ON" : "OFF")
|
||||
</button>
|
||||
|
||||
<button class="mb-3 w-100 hmi-button onoff @hmiBtnHasEmptyTrolleyClass" @onclick="ToggleHasEmptyTrolley">
|
||||
EMPTY TROLLEY @(Line1_HMI_Model.Has_Empty_Trolley ? "ON" : "OFF")
|
||||
</button>
|
||||
|
||||
<button class="mb-3 w-100 hmi-button onoff @hmiBtnGoHomeClass" @onclick="ToggleGoHome">
|
||||
GO HOME
|
||||
</button>
|
||||
|
||||
<!-- Image Trolley - Full Width -->
|
||||
<div class="mb-3 w-100" @onclick="ToggleHasFullTrolley">
|
||||
<img src="sehc/trolley.png" class="@trolleyFullClass" alt="Trolley" style="
|
||||
width: 100%;
|
||||
height: auto;
|
||||
object-fit: cover;
|
||||
">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="h-100 d-flex flex-column" style="width: 45%; overflow: hidden; border-left: 1px solid red;">
|
||||
<div class="d-flex flex-row justify-content-between align-items-center gap-3 p-3" style="height: 15%;">
|
||||
<button class="hmi-button start @hmiBtnEnAutoAClass" @onclick="ToggleAutoManualA">@(Line1_HMI_Model.EnableAutoA ? "AUTO" : "MANUAL")</button>
|
||||
<button class="hmi-button request @hmiBtnInAClass" @onclick="ToggleReqInA">REQ IN A<br>@(Line1_HMI_Model.Req_In_A ? "ON" : "OFF")</button>
|
||||
<button class="hmi-button request @hmiBtnInBesideAClass" @onclick="ToggleReqInBesideA">REQ IN BESIDE A<br>@(Line1_HMI_Model.Req_In_Beside_A ? "ON" : "OFF")</button>
|
||||
<button class="hmi-button close @hmiBtnCloseAClass" @onclick="ToggleReqCloseCylenderA">REQ CLOSE A<br>@(Line1_HMI_Model.Req_Close_Cylinder_A ? "ON" : "OFF")</button>
|
||||
</div>
|
||||
|
||||
<div class="w-100 d-flex flex-row" style="height: 85%;">
|
||||
<div class="h-100 d-flex flex-grow-1" style="position: relative;">
|
||||
<img src="sehc/amr.png" class="@amrReadyUndockAClass" style="height: calc(75% * 0.25); width: auto; object-fit: contain; position: absolute; right: 0%; top: 40%;" />
|
||||
</div>
|
||||
|
||||
<div class="h-100 d-flex flex-column" style="width: auto;">
|
||||
<div style="height: 90%; position: relative;">
|
||||
<div class="access-status @accessInAClass"
|
||||
style="position: absolute; width: 80%; height: 2%; left: 10%; bottom: -2%; border-radius: 3px; display: flex; align-items: center; justify-content: center; color: white; font-size: 16px; font-weight: bold;">
|
||||
</div>
|
||||
<div class="access-status @accessInBesideAClass"
|
||||
style="position: absolute; width: 3%; height: 70%; left: 5%; top: 19%; border-radius: 3px; display: flex; align-items: center; justify-content: center; color: white; font-size: 16px; font-weight: bold;">
|
||||
</div>
|
||||
<img src="sehc/station.png" style="height: 100%; width: auto; object-fit: contain;" />
|
||||
<img src="sehc/amr.png" class="@amrInAClass" style="position: absolute; transform: rotate(90deg); top: 37%; left: 21.5%; width: 60%; height: 30%; object-fit: contain;" />
|
||||
<img src="sehc/trolley.png" class="@trolleyAClass" style="position: absolute; top: 5.5%; right: 1%; width: 95%; height: 95%; object-fit: contain;" />
|
||||
<div class="@cylinderStateAClass" style="position: absolute; top: 10%; left: 12.5%;"></div>
|
||||
<div class="@cylinderStateAClass" style="position: absolute; top: 90%; left: 12.5%;"></div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex align-items-center justify-content-center" style="height: 10%;">
|
||||
<div id="station-left-indicator" class="station-indicator @indicatorAClass">
|
||||
<div class="direction-track">
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="center-dot"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="h-100 d-flex flex-column" style="width: 45%; overflow: hidden; border-left: 1px solid red;">
|
||||
<div class="d-flex flex-row-reverse justify-content-between align-items-center gap-3 p-3" style="height: 15%;">
|
||||
<button class="hmi-button start @hmiBtnEnAutoBClass" @onclick="ToggleAutoManualB">@(Line1_HMI_Model.EnableAutoB ? "AUTO" : "MANUAL")</button>
|
||||
<button class="hmi-button request @hmiBtnInBClass" @onclick="ToggleReqInB"> REQ IN B<br>@(Line1_HMI_Model.Req_In_B ? "ON" : "OFF")</button>
|
||||
<button class="hmi-button request @hmiBtnInBesideBClass" @onclick="ToggleReqInBesideB"> REQ IN BESIDE B<br>@(Line1_HMI_Model.Req_In_Beside_B ? "ON" : "OFF")</button>
|
||||
<button class="hmi-button close @hmiBtnCloseBClass" @onclick="ToggleReqCloseCylenderB">REQ CLOSE B<br>@(Line1_HMI_Model.Req_Close_Cylinder_B ? "ON" : "OFF")</button>
|
||||
</div>
|
||||
|
||||
<div class="w-100 d-flex flex-row-reverse" style="height: 85%;">
|
||||
<div class="h-100 d-flex flex-grow-1" style="position: relative;">
|
||||
<img src="sehc/amr.png" class="@amrReadyUndockBClass" style="transform: rotate(180deg); height: calc(75% * 0.25); width: auto; object-fit: contain; position: absolute; left: 0%; top: 40%;" />
|
||||
</div>
|
||||
|
||||
<div class="h-100 d-flex flex-column" style="width: auto;">
|
||||
<div style="height: 90%; position: relative;">
|
||||
<div class="access-status @accessInBClass"
|
||||
style="position: absolute; width: 80%; height: 2%; left: 10%; bottom: -2%; border-radius: 3px; display: flex; align-items: center; justify-content: center; color: white; font-size: 16px; font-weight: bold;">
|
||||
</div>
|
||||
<div class="access-status @accessInBesideBClass"
|
||||
style="position: absolute; width: 3%; height: 70%; right: 5%; top: 19%; border-radius: 3px; display: flex; align-items: center; justify-content: center; color: white; font-size: 16px; font-weight: bold;">
|
||||
</div>
|
||||
<img src="sehc/station.png" style="transform: scaleX(-1); height: 100%; width: auto; object-fit: contain;" />
|
||||
<img src="sehc/amr.png" class="@amrInBClass" style="position: absolute; transform: rotate(90deg); top: 37%; right: 21.5%; width: 60%; height: 30%; object-fit: contain;" />
|
||||
<img src="sehc/trolley.png" class="@trolleyBClass" style="position: absolute; top: 5.5%; left: 1%; width: 95%; height: 95%; object-fit: contain;" />
|
||||
<div class="@cylinderStateBClass" style="position: absolute; top: 10%; right: 12.5%;"></div>
|
||||
<div class="@cylinderStateBClass" style="position: absolute; top: 90%; right: 12.5%;"></div>
|
||||
</div>
|
||||
|
||||
<div style="height: 10%;">
|
||||
<div id="station-right-indicator" class="station-indicator @indicatorBClass">
|
||||
<div class="direction-track">
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="arrow-flow"></div>
|
||||
<div class="center-dot"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<MudOverlay Visible="DisableControl" DarkBackground AutoClose="false">
|
||||
<div class="d-flex flex-column justify-content-center">
|
||||
<div class="d-flex justify-content-center">
|
||||
<MudProgressCircular Color="Color.Secondary" Size="Size.Large" Indeterminate="true" />
|
||||
</div>
|
||||
<div>
|
||||
<MudText Typo="Typo.h3">CONNECTING ...</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudOverlay>
|
||||
|
||||
<MudOverlay Visible="DisableProcess" DarkBackground AutoClose="false">
|
||||
<div class="d-flex flex-column justify-content-center">
|
||||
<div class="d-flex justify-content-center">
|
||||
<MudProgressCircular Color="Color.Secondary" Size="Size.Large" Indeterminate="true" />
|
||||
</div>
|
||||
<div>
|
||||
<MudText Typo="Typo.h3">WAIT FOR RUNNING ...</MudText>
|
||||
</div>
|
||||
</div>
|
||||
</MudOverlay>
|
||||
|
||||
@code {
|
||||
private bool DisableControl = true;
|
||||
private bool DisableProcess => !DisableControl && processorState != ProcessorState.Running;
|
||||
private ProcessorState processorState = ProcessorState.Idle;
|
||||
|
||||
private string hmiBtnResetStepClass => $"{(Line1_HMI_Model.Request_Reset_SEHC_DA3_Line1 ? "inactive" : "")}";
|
||||
private string hmiBtnIsWorkingClass => $"{(Line1_HMI_Model.IsWorking ? "" : "inactive")}";
|
||||
private string hmiBtnHasEmptyTrolleyClass => $"{(Line1_HMI_Model.Has_Empty_Trolley ? "" : "inactive")}";
|
||||
private string hmiBtnGoHomeClass => $"{(Line1_HMI_Model.Request_GoHome ? "inactive" : "")}";
|
||||
|
||||
private string hmiBtnEnAutoAClass => $"{(Line1_HMI_Model.EnableAutoA ? "" : "off")}";
|
||||
private string hmiBtnInAClass => $"{(Line1_HMI_Model.EnableAutoA ? "inactive" : "")} {(Line1_HMI_Model.Req_In_A ? "" : "off")}";
|
||||
private string hmiBtnInBesideAClass => $"{(Line1_HMI_Model.EnableAutoA ? "inactive" : "")} {(Line1_HMI_Model.Req_In_Beside_A ? "" : "off")}";
|
||||
private string hmiBtnCloseAClass => $"{(Line1_HMI_Model.EnableAutoA ? "inactive" : "")} {(Line1_HMI_Model.Req_Close_Cylinder_A ? "" : "off")}";
|
||||
|
||||
private string hmiBtnEnAutoBClass => $"{(Line1_HMI_Model.EnableAutoB ? "" : "off")}";
|
||||
private string hmiBtnInBClass => $"{(Line1_HMI_Model.EnableAutoB ? "inactive" : "")} {(Line1_HMI_Model.Req_In_B ? "" : "off")}";
|
||||
private string hmiBtnInBesideBClass => $"{(Line1_HMI_Model.EnableAutoB ? "inactive" : "")} {(Line1_HMI_Model.Req_In_Beside_B ? "" : "off")}";
|
||||
private string hmiBtnCloseBClass => $"{(Line1_HMI_Model.EnableAutoB ? "inactive" : "")} {(Line1_HMI_Model.Req_Close_Cylinder_B ? "" : "off")}";
|
||||
|
||||
private string cylinderStateAClass => $"{(Line1_HMI_Model.Cylinder_Opened_A ? "" : "led-indicator")}";
|
||||
private string cylinderStateBClass => $"{(Line1_HMI_Model.Cylinder_Opened_B ? "" : "led-indicator")}";
|
||||
|
||||
private string trolleyAClass => $"{(Line1_HMI_Model.Empty_A ? "trolley-inactive" : "")}";
|
||||
private string trolleyBClass => $"{(Line1_HMI_Model.Empty_B ? "trolley-inactive" : "")}";
|
||||
private string trolleyFullClass => $"{(Line1_HMI_Model.AGV_Push_Noti_Mem ? "" : "trolley-inactive")}";
|
||||
|
||||
private string indicatorAClass => GetIndicatorAClass();
|
||||
private string indicatorBClass => GetIndicatorBClass();
|
||||
|
||||
private string amrReadyUndockAClass => $"{(Line1_HMI_Model.AMR_Ready_Undock_A ? "" : "image-inactive")}";
|
||||
private string amrReadyUndockBClass => $"{(Line1_HMI_Model.AMR_Ready_Undock_B ? "" : "image-inactive")}";
|
||||
|
||||
private string amrInAClass => $"{(Line1_HMI_Model.AMR_In_Station_A ? "" : "image-inactive")}";
|
||||
private string amrInBClass => $"{(Line1_HMI_Model.AMR_In_Station_B ? "" : "image-inactive")}";
|
||||
|
||||
private string accessInAClass => Line1_HMI_Model.Access_In_A ? "access-allowed" : "access-denied";
|
||||
private string accessInBClass => Line1_HMI_Model.Access_In_B ? "access-allowed" : "access-denied";
|
||||
private string accessInBesideAClass => Line1_HMI_Model.Access_In_Beside_A ? "access-allowed" : "access-denied";
|
||||
private string accessInBesideBClass => Line1_HMI_Model.Access_In_Beside_B ? "access-allowed" : "access-denied";
|
||||
|
||||
private SEHC_DA3_Line1_HMI_Model Line1_HMI_Model;
|
||||
|
||||
IDictionary<string, string> SyncVariables = new Dictionary<string, string>()
|
||||
{
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.IsWorking), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.SEHCMissionStep), "-1" },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.EnableAutoA), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.EnableAutoB), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Request_Reset_SEHC_DA3_Line1), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.AMR_In_Station_A), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.AMR_In_Station_B), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.AMR_Ready_Undock_A), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.AMR_Ready_Undock_B), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Req_In_A), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Req_In_B), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Req_In_Beside_A), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Req_In_Beside_B), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Req_Close_Cylinder_A), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Req_Close_Cylinder_B), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Robot_Working_A), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Robot_Working_B), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Empty_A), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Empty_B), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Cylinder_Opened_A), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Cylinder_Opened_B), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Access_In_A), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Access_In_B), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Access_In_Beside_A), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Access_In_Beside_B), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.AGV_Push_Noti_Mem), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Has_Empty_Trolley), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyInStationA), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyInStationB), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyOutStationA), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyOutStationB), bool.FalseString },
|
||||
{nameof(SEHC_DA3_Line1_HMI_Model.Request_GoHome), bool.FalseString },
|
||||
};
|
||||
|
||||
System.Timers.Timer timer = new System.Timers.Timer(300)
|
||||
{
|
||||
AutoReset = true,
|
||||
};
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
timer.Elapsed += OnTimerElapsed;
|
||||
|
||||
hmiClient.ConnectionStateChanged += OnConnectionStateChanged;
|
||||
hmiClient.StateChanged += OnProcessStateChanged;
|
||||
|
||||
await hmiClient.StartAsync();
|
||||
|
||||
timer.Start();
|
||||
OnProcessStateChanged(await hmiClient.GetState());
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
void OnConnectionStateChanged(HubConnectionState state)
|
||||
{
|
||||
Console.WriteLine($"HubConnectionState={state}");
|
||||
DisableControl = state != HubConnectionState.Connected;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void OnProcessStateChanged(ProcessorState state)
|
||||
{
|
||||
processorState = state;
|
||||
if (state == ProcessorState.Running)
|
||||
{
|
||||
if (!timer.Enabled)
|
||||
{
|
||||
timer.Start();
|
||||
}
|
||||
}
|
||||
else if (timer.Enabled)
|
||||
{
|
||||
timer.Stop();
|
||||
}
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
void OnTimerElapsed(object? sender, System.Timers.ElapsedEventArgs e)
|
||||
{
|
||||
InvokeAsync(async Task () =>
|
||||
{
|
||||
var variables = await hmiClient.GetVariables(SyncVariables.Keys);
|
||||
foreach (var key in variables.Keys)
|
||||
{
|
||||
SyncVariables[key] = variables[key];
|
||||
}
|
||||
|
||||
Line1_HMI_Model.IsWorking = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.IsWorking)]);
|
||||
Line1_HMI_Model.SEHCMissionStep = int.TryParse(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.SEHCMissionStep)], out int step) ? step : -1;
|
||||
Line1_HMI_Model.EnableAutoA = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.EnableAutoA)]);
|
||||
Line1_HMI_Model.EnableAutoB = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.EnableAutoB)]);
|
||||
Line1_HMI_Model.Request_Reset_SEHC_DA3_Line1 = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Request_Reset_SEHC_DA3_Line1)]);
|
||||
Line1_HMI_Model.AMR_In_Station_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.AMR_In_Station_A)]);
|
||||
Line1_HMI_Model.AMR_In_Station_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.AMR_In_Station_B)]);
|
||||
Line1_HMI_Model.AMR_Ready_Undock_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.AMR_Ready_Undock_A)]);
|
||||
Line1_HMI_Model.AMR_Ready_Undock_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.AMR_Ready_Undock_B)]);
|
||||
Line1_HMI_Model.Req_In_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Req_In_A)]);
|
||||
Line1_HMI_Model.Req_In_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Req_In_B)]);
|
||||
Line1_HMI_Model.Req_In_Beside_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Req_In_Beside_A)]);
|
||||
Line1_HMI_Model.Req_In_Beside_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Req_In_Beside_B)]);
|
||||
Line1_HMI_Model.Req_Close_Cylinder_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Req_Close_Cylinder_A)]);
|
||||
Line1_HMI_Model.Req_Close_Cylinder_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Req_Close_Cylinder_B)]);
|
||||
Line1_HMI_Model.Robot_Working_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Robot_Working_A)]);
|
||||
Line1_HMI_Model.Robot_Working_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Robot_Working_B)]);
|
||||
Line1_HMI_Model.Empty_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Empty_A)]);
|
||||
Line1_HMI_Model.Empty_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Empty_B)]);
|
||||
Line1_HMI_Model.Cylinder_Opened_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Cylinder_Opened_A)]);
|
||||
Line1_HMI_Model.Cylinder_Opened_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Cylinder_Opened_B)]);
|
||||
Line1_HMI_Model.Access_In_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Access_In_A)]);
|
||||
Line1_HMI_Model.Access_In_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Access_In_B)]);
|
||||
Line1_HMI_Model.Access_In_Beside_A = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Access_In_Beside_A)]);
|
||||
Line1_HMI_Model.Access_In_Beside_B = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Access_In_Beside_B)]);
|
||||
Line1_HMI_Model.AGV_Push_Noti_Mem = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.AGV_Push_Noti_Mem)]);
|
||||
Line1_HMI_Model.Has_Empty_Trolley = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Has_Empty_Trolley)]);
|
||||
Line1_HMI_Model.MoveTrolleyInStationA = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyInStationA)]);
|
||||
Line1_HMI_Model.MoveTrolleyInStationB = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyInStationB)]);
|
||||
Line1_HMI_Model.MoveTrolleyOutStationA = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyOutStationA)]);
|
||||
Line1_HMI_Model.MoveTrolleyOutStationB = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.MoveTrolleyOutStationB)]);
|
||||
Line1_HMI_Model.Request_GoHome = bool.TrueString.Equals(SyncVariables[nameof(SEHC_DA3_Line1_HMI_Model.Request_GoHome)]);
|
||||
StateHasChanged();
|
||||
}).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
string GetIndicatorAClass()
|
||||
{
|
||||
if (Line1_HMI_Model.Robot_Working_A) return "working";
|
||||
|
||||
if (Line1_HMI_Model.IsWorking)
|
||||
{
|
||||
if (Line1_HMI_Model.MoveTrolleyOutStationA)
|
||||
{
|
||||
return "request-out";
|
||||
}
|
||||
else if (Line1_HMI_Model.MoveTrolleyInStationA)
|
||||
{
|
||||
return "request-in";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "standby";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return "hidden";
|
||||
}
|
||||
}
|
||||
|
||||
string GetIndicatorBClass()
|
||||
{
|
||||
if (Line1_HMI_Model.Robot_Working_B) return "working";
|
||||
|
||||
if (Line1_HMI_Model.IsWorking)
|
||||
{
|
||||
if (Line1_HMI_Model.MoveTrolleyOutStationB)
|
||||
{
|
||||
return "request-out";
|
||||
}
|
||||
else if (Line1_HMI_Model.MoveTrolleyInStationB)
|
||||
{
|
||||
return "request-in";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "standby";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return "hidden";
|
||||
}
|
||||
}
|
||||
|
||||
async Task ToggleAutoManualA()
|
||||
{
|
||||
var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.EnableAutoA), Line1_HMI_Model.EnableAutoA ? bool.FalseString : bool.TrueString);
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error);
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
async Task ToggleAutoManualB()
|
||||
{
|
||||
var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.EnableAutoB), Line1_HMI_Model.EnableAutoB ? bool.FalseString : bool.TrueString);
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error);
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
async Task ToggleReqInA()
|
||||
{
|
||||
if (Line1_HMI_Model.EnableAutoA) return;
|
||||
var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Req_In_A), Line1_HMI_Model.Req_In_A ? bool.FalseString : bool.TrueString);
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error);
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
async Task ToggleReqInBesideA()
|
||||
{
|
||||
if (Line1_HMI_Model.EnableAutoA) return;
|
||||
var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Req_In_Beside_A), Line1_HMI_Model.Req_In_Beside_A ? bool.FalseString : bool.TrueString);
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error);
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
async Task ToggleReqCloseCylenderA()
|
||||
{
|
||||
if (Line1_HMI_Model.EnableAutoA) return;
|
||||
var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Req_Close_Cylinder_A), Line1_HMI_Model.Req_Close_Cylinder_A ? bool.FalseString : bool.TrueString);
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error);
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
async Task ToggleReqInB()
|
||||
{
|
||||
if (Line1_HMI_Model.EnableAutoB) return;
|
||||
var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Req_In_B), Line1_HMI_Model.Req_In_B ? bool.FalseString : bool.TrueString);
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error);
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
async Task ToggleReqInBesideB()
|
||||
{
|
||||
if (Line1_HMI_Model.EnableAutoB) return;
|
||||
var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Req_In_Beside_B), Line1_HMI_Model.Req_In_Beside_B ? bool.FalseString : bool.TrueString);
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error);
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
async Task ToggleReqCloseCylenderB()
|
||||
{
|
||||
if (Line1_HMI_Model.EnableAutoB) return;
|
||||
var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Req_Close_Cylinder_B), Line1_HMI_Model.Req_Close_Cylinder_B ? bool.FalseString : bool.TrueString);
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error);
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
async Task ToggleHasEmptyTrolley()
|
||||
{
|
||||
var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Has_Empty_Trolley), Line1_HMI_Model.Has_Empty_Trolley ? bool.FalseString : bool.TrueString);
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error);
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
async Task ToggleGoHome()
|
||||
{
|
||||
if (Line1_HMI_Model.Request_GoHome) return;
|
||||
|
||||
var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Request_GoHome), bool.TrueString);
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error);
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
async Task ToggleHasFullTrolley()
|
||||
{
|
||||
var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.AGV_Push_Noti_Mem), Line1_HMI_Model.AGV_Push_Noti_Mem ? bool.FalseString : bool.TrueString);
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error);
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
async Task CallResetStep()
|
||||
{
|
||||
if (Line1_HMI_Model.Request_Reset_SEHC_DA3_Line1) return;
|
||||
bool? confirm = await Dialog.ShowMessageBox(
|
||||
"Reset Mission State",
|
||||
"Hãy xác nhận đặt lại trạng thái hoạt động!",
|
||||
yesText: "Yes", cancelText: "Cancel");
|
||||
|
||||
if (confirm != true) return;
|
||||
|
||||
var result = await hmiClient.SetVariable(nameof(SEHC_DA3_Line1_HMI_Model.Request_Reset_SEHC_DA3_Line1), bool.TrueString);
|
||||
if (result == null)
|
||||
{
|
||||
Snackbar.Add("HMI client SetVariable failed to receiver response from server", Severity.Error);
|
||||
}
|
||||
else if (!result.IsSuccess)
|
||||
{
|
||||
Snackbar.Add($"HMI client SetVariable error: {result.Message}", Severity.Error);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
timer.Stop();
|
||||
|
||||
hmiClient.ConnectionStateChanged -= OnConnectionStateChanged;
|
||||
hmiClient.StateChanged -= OnProcessStateChanged;
|
||||
|
||||
await hmiClient.StopAsync();
|
||||
}
|
||||
}
|
||||
37
RobotNet.WebApp/Pages/SEHC_DA3_Line1_HMI.razor.cs
Normal file
37
RobotNet.WebApp/Pages/SEHC_DA3_Line1_HMI.razor.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
namespace RobotNet.WebApp.Pages;
|
||||
|
||||
public struct SEHC_DA3_Line1_HMI_Model
|
||||
{
|
||||
public bool IsWorking;
|
||||
public int SEHCMissionStep;
|
||||
public bool EnableAutoA;
|
||||
public bool EnableAutoB;
|
||||
public bool Request_Reset_SEHC_DA3_Line1;
|
||||
public bool AMR_In_Station_A;
|
||||
public bool AMR_In_Station_B;
|
||||
public bool AMR_Ready_Undock_A;
|
||||
public bool AMR_Ready_Undock_B;
|
||||
public bool Req_In_A;
|
||||
public bool Req_In_B;
|
||||
public bool Req_In_Beside_A;
|
||||
public bool Req_In_Beside_B;
|
||||
public bool Req_Close_Cylinder_A;
|
||||
public bool Req_Close_Cylinder_B;
|
||||
public bool Robot_Working_A;
|
||||
public bool Robot_Working_B;
|
||||
public bool Empty_A;
|
||||
public bool Empty_B;
|
||||
public bool Cylinder_Opened_A;
|
||||
public bool Cylinder_Opened_B;
|
||||
public bool Access_In_A;
|
||||
public bool Access_In_B;
|
||||
public bool Access_In_Beside_A;
|
||||
public bool Access_In_Beside_B;
|
||||
public bool AGV_Push_Noti_Mem;
|
||||
public bool Has_Empty_Trolley;
|
||||
public bool MoveTrolleyInStationA;
|
||||
public bool MoveTrolleyInStationB;
|
||||
public bool MoveTrolleyOutStationA;
|
||||
public bool MoveTrolleyOutStationB;
|
||||
public bool Request_GoHome;
|
||||
}
|
||||
554
RobotNet.WebApp/Pages/SEHC_DA3_Line1_HMI.razor.css
Normal file
554
RobotNet.WebApp/Pages/SEHC_DA3_Line1_HMI.razor.css
Normal file
@@ -0,0 +1,554 @@
|
||||
/* HMI Button Styles */
|
||||
.hmi-button {
|
||||
background: linear-gradient(145deg, #e6e6e6, #cccccc);
|
||||
border: 2px solid #999999;
|
||||
border-radius: 8px;
|
||||
color: #333333;
|
||||
font-weight: bold;
|
||||
font-size: 18px;
|
||||
padding: 0 16px;
|
||||
margin: 0 4px;
|
||||
min-width: 120px;
|
||||
height: 80%;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
box-shadow: 3px 3px 6px rgba(0, 0, 0, 0.3), inset 1px 1px 3px rgba(255, 255, 255, 0.8);
|
||||
text-shadow: 1px 1px 1px rgba(255, 255, 255, 0.8);
|
||||
position: relative;
|
||||
user-select: none;
|
||||
white-space: nowrap;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.hmi-button:hover {
|
||||
background: linear-gradient(145deg, #f0f0f0, #d6d6d6);
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.hmi-button:active {
|
||||
background: linear-gradient(145deg, #cccccc, #b3b3b3);
|
||||
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3), inset 2px 2px 4px rgba(0, 0, 0, 0.2);
|
||||
transform: translateY(1px);
|
||||
}
|
||||
|
||||
.hmi-button.start {
|
||||
background: linear-gradient(145deg, #4CAF50, #45a049);
|
||||
color: white;
|
||||
border-color: #2e7d32;
|
||||
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.hmi-button.start:hover {
|
||||
background: linear-gradient(145deg, #5cbf60, #4fa152);
|
||||
}
|
||||
|
||||
.hmi-button.request {
|
||||
background: linear-gradient(145deg, #2196F3, #1976D2);
|
||||
color: white;
|
||||
border-color: #0d47a1;
|
||||
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.hmi-button.request:hover {
|
||||
background: linear-gradient(145deg, #42a5f5, #1e88e5);
|
||||
}
|
||||
|
||||
.hmi-button.close {
|
||||
background: linear-gradient(145deg, #FF9800, #F57C00);
|
||||
color: white;
|
||||
border-color: #bf360c;
|
||||
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.hmi-button.close:hover {
|
||||
background: linear-gradient(145deg, #ffb74d, #fb8c00);
|
||||
}
|
||||
|
||||
.hmi-button.onoff {
|
||||
background: linear-gradient(145deg, #2196F3, #1976D2);
|
||||
color: white;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
padding: 18px 8px;
|
||||
height: 60px;
|
||||
font-weight: bold;
|
||||
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
|
||||
box-shadow: 3px 3px 6px rgba(0, 0, 0, 0.3), inset 1px 1px 3px rgba(255, 255, 255, 0.2);
|
||||
transition: all 0.2s ease;
|
||||
cursor: pointer;
|
||||
font-family: 'Courier New', monospace;
|
||||
}
|
||||
|
||||
.hmi-button.onoff:hover {
|
||||
background: linear-gradient(145deg, #42a5f5, #1e88e5);
|
||||
}
|
||||
|
||||
.hmi-button.off {
|
||||
filter: grayscale(100%);
|
||||
}
|
||||
/* Station Direction Indicator Styles */
|
||||
.station-indicator {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 90%;
|
||||
height: 80%;
|
||||
margin: 0 auto;
|
||||
position: relative;
|
||||
background: transparent;
|
||||
border: none;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.direction-track {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: relative;
|
||||
padding: 0 15px;
|
||||
}
|
||||
|
||||
.arrow-flow {
|
||||
position: absolute;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
opacity: 0;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.arrow-flow::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
width: 0;
|
||||
height: 0;
|
||||
border-left: 8px solid transparent;
|
||||
border-right: 8px solid transparent;
|
||||
border-bottom: 12px solid #00ff00;
|
||||
transform: translate(-50%, -50%) rotate(90deg);
|
||||
}
|
||||
|
||||
/* Station States - COPIED EXACTLY FROM WORKING VERSION */
|
||||
.station-indicator.request-in {
|
||||
border-color: transparent;
|
||||
box-shadow: none;
|
||||
animation: none;
|
||||
}
|
||||
|
||||
.station-indicator.request-in .arrow-flow {
|
||||
animation: flow-in-left 1.2s infinite linear;
|
||||
}
|
||||
|
||||
.station-indicator.request-in .arrow-flow:nth-child(1),
|
||||
.station-indicator.request-in .arrow-flow:nth-child(3),
|
||||
.station-indicator.request-in .arrow-flow:nth-child(5),
|
||||
.station-indicator.request-in .arrow-flow:nth-child(7) {
|
||||
animation: flow-in-left 0.8s infinite linear;
|
||||
}
|
||||
|
||||
.station-indicator.request-in .arrow-flow:nth-child(2),
|
||||
.station-indicator.request-in .arrow-flow:nth-child(4),
|
||||
.station-indicator.request-in .arrow-flow:nth-child(6),
|
||||
.station-indicator.request-in .arrow-flow:nth-child(8) {
|
||||
animation: flow-in-right 0.8s infinite linear;
|
||||
}
|
||||
|
||||
/* Mũi tên bên trái hướng về phải (→) */
|
||||
.station-indicator.request-in .arrow-flow:nth-child(1)::before,
|
||||
.station-indicator.request-in .arrow-flow:nth-child(3)::before,
|
||||
.station-indicator.request-in .arrow-flow:nth-child(5)::before,
|
||||
.station-indicator.request-in .arrow-flow:nth-child(7)::before {
|
||||
transform: translate(-50%, -50%) rotate(90deg);
|
||||
}
|
||||
|
||||
/* Mũi tên bên phải hướng về trái (←) */
|
||||
.station-indicator.request-in .arrow-flow:nth-child(2)::before,
|
||||
.station-indicator.request-in .arrow-flow:nth-child(4)::before,
|
||||
.station-indicator.request-in .arrow-flow:nth-child(6)::before,
|
||||
.station-indicator.request-in .arrow-flow:nth-child(8)::before {
|
||||
transform: translate(-50%, -50%) rotate(-90deg);
|
||||
}
|
||||
|
||||
.station-indicator.request-in .arrow-flow::before {
|
||||
border-bottom-color: #00ff00;
|
||||
color: #00ff00;
|
||||
}
|
||||
|
||||
.station-indicator.request-out {
|
||||
border-color: transparent;
|
||||
box-shadow: none;
|
||||
animation: none;
|
||||
}
|
||||
|
||||
.station-indicator.request-out .arrow-flow {
|
||||
animation: flow-out-left 1.2s infinite linear;
|
||||
}
|
||||
|
||||
.station-indicator.request-out .arrow-flow:nth-child(1),
|
||||
.station-indicator.request-out .arrow-flow:nth-child(3),
|
||||
.station-indicator.request-out .arrow-flow:nth-child(5),
|
||||
.station-indicator.request-out .arrow-flow:nth-child(7) {
|
||||
animation: flow-out-left 0.8s infinite linear;
|
||||
}
|
||||
|
||||
.station-indicator.request-out .arrow-flow:nth-child(2),
|
||||
.station-indicator.request-out .arrow-flow:nth-child(4),
|
||||
.station-indicator.request-out .arrow-flow:nth-child(6),
|
||||
.station-indicator.request-out .arrow-flow:nth-child(8) {
|
||||
animation: flow-out-right 0.8s infinite linear;
|
||||
}
|
||||
|
||||
/* Mũi tên bên trái hướng ra trái (←) */
|
||||
.station-indicator.request-out .arrow-flow:nth-child(1)::before,
|
||||
.station-indicator.request-out .arrow-flow:nth-child(3)::before,
|
||||
.station-indicator.request-out .arrow-flow:nth-child(5)::before,
|
||||
.station-indicator.request-out .arrow-flow:nth-child(7)::before {
|
||||
transform: translate(-50%, -50%) rotate(-90deg);
|
||||
}
|
||||
|
||||
/* Mũi tên bên phải hướng ra phải (→) */
|
||||
.station-indicator.request-out .arrow-flow:nth-child(2)::before,
|
||||
.station-indicator.request-out .arrow-flow:nth-child(4)::before,
|
||||
.station-indicator.request-out .arrow-flow:nth-child(6)::before,
|
||||
.station-indicator.request-out .arrow-flow:nth-child(8)::before {
|
||||
transform: translate(-50%, -50%) rotate(90deg);
|
||||
}
|
||||
|
||||
.station-indicator.request-out .arrow-flow::before {
|
||||
border-bottom-color: #ff6600;
|
||||
color: #ff6600;
|
||||
transform: translate(-50%, -50%) rotate(-90deg);
|
||||
}
|
||||
|
||||
.station-indicator.standby {
|
||||
border-color: transparent;
|
||||
animation: none;
|
||||
}
|
||||
|
||||
.station-indicator.standby .center-dot {
|
||||
background: radial-gradient(circle, #333 30%, #555 70%);
|
||||
animation: none;
|
||||
}
|
||||
|
||||
.station-indicator.hidden {
|
||||
opacity: 0;
|
||||
transform: scale(0.8);
|
||||
filter: blur(2px);
|
||||
}
|
||||
|
||||
/* Working state for station indicator */
|
||||
.station-indicator.working {
|
||||
border-color: transparent;
|
||||
box-shadow: none;
|
||||
animation: none;
|
||||
background: transparent;
|
||||
border: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.station-indicator.working .direction-track {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.station-indicator.working::after {
|
||||
content: 'WORKING';
|
||||
color: #27ae60;
|
||||
font-weight: bold;
|
||||
font-size: 20px;
|
||||
font-family: 'Courier New', monospace;
|
||||
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
|
||||
letter-spacing: 2px;
|
||||
animation: working-pulse 1.5s infinite ease-in-out;
|
||||
}
|
||||
|
||||
@keyframes working-pulse {
|
||||
0%, 100% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
50% {
|
||||
opacity: 0.7;
|
||||
transform: scale(1.05);
|
||||
}
|
||||
}
|
||||
|
||||
/* Center Station Dot */
|
||||
.center-dot {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
width: 30px;
|
||||
height: 30px;
|
||||
border-radius: 50%;
|
||||
background: radial-gradient(circle, #333 30%, #555 70%);
|
||||
border: 2px solid #666;
|
||||
box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.1), 0 2px 8px rgba(0, 0, 0, 0.3);
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
/* Flow from both sides to center (IN) */
|
||||
@keyframes flow-in-left {
|
||||
0% {
|
||||
left: -25px;
|
||||
opacity: 0;
|
||||
transform: scale(0.5);
|
||||
}
|
||||
|
||||
20% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
80% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
100% {
|
||||
left: calc(50% - 15px);
|
||||
opacity: 0;
|
||||
transform: scale(1.2);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes flow-in-right {
|
||||
0% {
|
||||
right: -25px;
|
||||
opacity: 0;
|
||||
transform: scale(0.5);
|
||||
}
|
||||
|
||||
20% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
80% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
100% {
|
||||
right: calc(50% - 15px);
|
||||
opacity: 0;
|
||||
transform: scale(1.2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Flow from center to both sides (OUT) */
|
||||
@keyframes flow-out-left {
|
||||
0% {
|
||||
left: calc(50% - 15px);
|
||||
opacity: 0;
|
||||
transform: scale(1.2);
|
||||
}
|
||||
|
||||
20% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
80% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
100% {
|
||||
left: -25px;
|
||||
opacity: 0;
|
||||
transform: scale(0.5);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes flow-out-right {
|
||||
0% {
|
||||
right: calc(50% - 15px);
|
||||
opacity: 0;
|
||||
transform: scale(1.2);
|
||||
}
|
||||
|
||||
20% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
80% {
|
||||
opacity: 1;
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
100% {
|
||||
right: -25px;
|
||||
opacity: 0;
|
||||
transform: scale(0.5);
|
||||
}
|
||||
}
|
||||
|
||||
/* Multiple Arrow Generation - COPIED EXACTLY FROM WORKING VERSION */
|
||||
.station-indicator.request-in .arrow-flow:nth-child(1) {
|
||||
animation-delay: 0s;
|
||||
}
|
||||
|
||||
.station-indicator.request-in .arrow-flow:nth-child(2) {
|
||||
animation-delay: 0.05s;
|
||||
}
|
||||
|
||||
.station-indicator.request-in .arrow-flow:nth-child(3) {
|
||||
animation-delay: 0.2s;
|
||||
}
|
||||
|
||||
.station-indicator.request-in .arrow-flow:nth-child(4) {
|
||||
animation-delay: 0.25s;
|
||||
}
|
||||
|
||||
.station-indicator.request-in .arrow-flow:nth-child(5) {
|
||||
animation-delay: 0.4s;
|
||||
}
|
||||
|
||||
.station-indicator.request-in .arrow-flow:nth-child(6) {
|
||||
animation-delay: 0.45s;
|
||||
}
|
||||
|
||||
.station-indicator.request-in .arrow-flow:nth-child(7) {
|
||||
animation-delay: 0.6s;
|
||||
}
|
||||
|
||||
.station-indicator.request-in .arrow-flow:nth-child(8) {
|
||||
animation-delay: 0.65s;
|
||||
}
|
||||
|
||||
.station-indicator.request-out .arrow-flow:nth-child(1) {
|
||||
animation-delay: 0s;
|
||||
}
|
||||
|
||||
.station-indicator.request-out .arrow-flow:nth-child(2) {
|
||||
animation-delay: 0.05s;
|
||||
}
|
||||
|
||||
.station-indicator.request-out .arrow-flow:nth-child(3) {
|
||||
animation-delay: 0.2s;
|
||||
}
|
||||
|
||||
.station-indicator.request-out .arrow-flow:nth-child(4) {
|
||||
animation-delay: 0.25s;
|
||||
}
|
||||
|
||||
.station-indicator.request-out .arrow-flow:nth-child(5) {
|
||||
animation-delay: 0.4s;
|
||||
}
|
||||
|
||||
.station-indicator.request-out .arrow-flow:nth-child(6) {
|
||||
animation-delay: 0.45s;
|
||||
}
|
||||
|
||||
.station-indicator.request-out .arrow-flow:nth-child(7) {
|
||||
animation-delay: 0.6s;
|
||||
}
|
||||
|
||||
.station-indicator.request-out .arrow-flow:nth-child(8) {
|
||||
animation-delay: 0.65s;
|
||||
}
|
||||
|
||||
/* Inactive State for Images */
|
||||
.image-inactive {
|
||||
opacity: 0.3;
|
||||
filter: grayscale(100%) brightness(0.7);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.image-inactive:hover {
|
||||
opacity: 0.5;
|
||||
filter: grayscale(80%) brightness(0.8);
|
||||
}
|
||||
|
||||
.inactive {
|
||||
opacity: 0.3;
|
||||
filter: grayscale(100%) brightness(0.7);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.inactive:hover {
|
||||
opacity: 0.5;
|
||||
filter: grayscale(80%) brightness(0.8);
|
||||
}
|
||||
|
||||
/* Specific inactive states for AMR and Trolley */
|
||||
.amr-inactive {
|
||||
opacity: 0.25;
|
||||
filter: grayscale(100%) brightness(0.6) contrast(0.8);
|
||||
transition: all 0.4s ease;
|
||||
border-color: #666 !important;
|
||||
background-color: rgba(120, 120, 120, 0.1) !important;
|
||||
}
|
||||
|
||||
.trolley-inactive {
|
||||
opacity: 0.3;
|
||||
filter: grayscale(100%) brightness(0.7) contrast(0.9);
|
||||
transition: all 0.4s ease;
|
||||
border-color: #666 !important;
|
||||
background-color: rgba(120, 120, 120, 0.1) !important;
|
||||
}
|
||||
|
||||
/* Inactive hover effects */
|
||||
.amr-inactive:hover,
|
||||
.trolley-inactive:hover {
|
||||
opacity: 0.4;
|
||||
filter: grayscale(90%) brightness(0.8);
|
||||
}
|
||||
|
||||
/* LED indicators with turning on effect */
|
||||
.led-indicator {
|
||||
width: 5.5%;
|
||||
height: 7.5%;
|
||||
background: linear-gradient(145deg, #27ae60, #2ecc71);
|
||||
border: 2px solid #1e8449;
|
||||
box-shadow: inset 0 1px 3px rgba(255, 255, 255, 0.3), 0 0 10px rgba(39, 174, 96, 0.8), 0 0 20px rgba(39, 174, 96, 0.4);
|
||||
animation: turning-on 2s infinite ease-in-out;
|
||||
}
|
||||
|
||||
@keyframes turning-on {
|
||||
0%, 100% {
|
||||
opacity: 1;
|
||||
box-shadow: inset 0 1px 3px rgba(255, 255, 255, 0.3), 0 0 10px rgba(39, 174, 96, 0.8), 0 0 20px rgba(39, 174, 96, 0.4);
|
||||
transform: scale(1);
|
||||
}
|
||||
|
||||
50% {
|
||||
opacity: 0.6;
|
||||
box-shadow: inset 0 1px 3px rgba(255, 255, 255, 0.1), 0 0 5px rgba(39, 174, 96, 0.4), 0 0 10px rgba(39, 174, 96, 0.2);
|
||||
transform: scale(0.95);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Access Status Indicator */
|
||||
.access-status {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.access-status.access-allowed {
|
||||
background-color: #28a745;
|
||||
/*border: 2px solid #1e7e34;*/
|
||||
}
|
||||
|
||||
.access-status.access-denied {
|
||||
background-color: #dc3545;
|
||||
/*border: 2px solid #bd2130;*/
|
||||
}
|
||||
|
||||
.access-status.access-allowed::before {
|
||||
content: "✓";
|
||||
}
|
||||
|
||||
.access-status.access-denied::before {
|
||||
content: "✗";
|
||||
}
|
||||
121
RobotNet.WebApp/Pages/ScriptEditor.razor
Normal file
121
RobotNet.WebApp/Pages/ScriptEditor.razor
Normal file
@@ -0,0 +1,121 @@
|
||||
@page "/script-editor"
|
||||
@attribute [Authorize]
|
||||
@implements IAsyncDisposable
|
||||
|
||||
@using RobotNet.Script.Shares
|
||||
@using RobotNet.WebApp.Clients
|
||||
@using RobotNet.WebApp.Scripts.Components
|
||||
@using RobotNet.WebApp.Scripts.Models
|
||||
|
||||
@inject IHttpClientFactory httpFactory
|
||||
@inject ProcessorHubClient processorHub
|
||||
|
||||
<PageTitle>Script Editor</PageTitle>
|
||||
|
||||
<CascadingValue Value="Workspace">
|
||||
<div class="editor-container" @onmouseup="DisableResize" @onmouseleave="DisableResize" @onmousemove="MouseMoveOnEditorContainer"
|
||||
@oncontextmenu:stopPropagation @oncontextmenu:preventDefault>
|
||||
<div class="editor-hierachy" style="width: @(HierachyWidth)px;">
|
||||
<SidebarActions />
|
||||
<EditorHierachy @ref="hierachyRef" />
|
||||
</div>
|
||||
<div class="split-vertical-view" @onmousedown:preventDefault @onmousedown:stopPropagation @onmousedown="EnableResizeHierachy"></div>
|
||||
<div class="editor-content">
|
||||
<Editor @ref="editorRef" />
|
||||
<div class="split-horizontal-view" @onmousedown:preventDefault @onmousedown:stopPropagation @onmousedown="EnableResizeConsole"></div>
|
||||
<div class="editor-console" style="height: @(ConsoleHeight)px;">
|
||||
<ProcessorControl @ref="processorControlRef" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CascadingValue>
|
||||
|
||||
|
||||
@code {
|
||||
private EditorHierachy hierachyRef = default!;
|
||||
private Editor editorRef = null!;
|
||||
private ProcessorControl processorControlRef = null!;
|
||||
|
||||
private int HierachyWidth = 300;
|
||||
private int ConsoleHeight = 300;
|
||||
private bool isDraggingHierachy = false;
|
||||
private bool isDraggingConsole = false;
|
||||
private ScriptWorkspace Workspace = default!;
|
||||
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
|
||||
Workspace = new(httpFactory);
|
||||
await Workspace.InitializeAsync();
|
||||
}
|
||||
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await base.OnAfterRenderAsync(firstRender);
|
||||
|
||||
if(firstRender)
|
||||
{
|
||||
processorHub.StateChanged += OnProcessStateChanged;
|
||||
await processorHub.StartAsync();
|
||||
|
||||
OnProcessStateChanged(await processorHub.GetState());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnProcessStateChanged(ProcessorState state)
|
||||
{
|
||||
Workspace.ProcessorState = state;
|
||||
editorRef.OnProcessStateChanged(state);
|
||||
}
|
||||
|
||||
private void EnableResizeHierachy()
|
||||
{
|
||||
isDraggingHierachy = true;
|
||||
}
|
||||
|
||||
private void EnableResizeConsole()
|
||||
{
|
||||
isDraggingConsole = true;
|
||||
}
|
||||
|
||||
private void DisableResize()
|
||||
{
|
||||
isDraggingHierachy = false;
|
||||
isDraggingConsole = false;
|
||||
}
|
||||
|
||||
private void MouseMoveOnEditorContainer(MouseEventArgs e)
|
||||
{
|
||||
if (isDraggingHierachy)
|
||||
{
|
||||
HierachyWidth += (int)e.MovementX;
|
||||
|
||||
if (HierachyWidth < 150)
|
||||
{
|
||||
HierachyWidth = 150;
|
||||
}
|
||||
else if (HierachyWidth > 500)
|
||||
{
|
||||
HierachyWidth = 500;
|
||||
}
|
||||
}
|
||||
else if (isDraggingConsole)
|
||||
{
|
||||
// ConsoleHeight -= (int)e.MovementY;
|
||||
// StateHasChanged();
|
||||
// Console.WriteLine($"ConsoleHeight={ConsoleHeight}");
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
processorHub.StateChanged -= OnProcessStateChanged;
|
||||
await processorHub.StopAsync();
|
||||
|
||||
Workspace.Dispose();
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
62
RobotNet.WebApp/Pages/ScriptEditor.razor.css
Normal file
62
RobotNet.WebApp/Pages/ScriptEditor.razor.css
Normal file
@@ -0,0 +1,62 @@
|
||||
.editor-container {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.split-vertical-view {
|
||||
height: 100%;
|
||||
transition-duration: 500ms;
|
||||
transition-property: background-color;
|
||||
background-color: transparent;
|
||||
border-right: 1px solid grey;
|
||||
width: 5px;
|
||||
}
|
||||
|
||||
.split-vertical-view:hover {
|
||||
background-color: dodgerblue;
|
||||
border-right: 1px solid dodgerblue;
|
||||
cursor: col-resize;
|
||||
}
|
||||
|
||||
.editor-hierachy {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.editor-content {
|
||||
height: 100%;
|
||||
flex-grow: 1;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.editor-code {
|
||||
width: 100%;
|
||||
flex-grow: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.split-horizontal-view {
|
||||
width: 100%;
|
||||
transition-duration: 500ms;
|
||||
transition-property: background-color;
|
||||
background-color: transparent;
|
||||
border-top: 1px solid grey;
|
||||
height: 5px;
|
||||
}
|
||||
|
||||
.split-horizontal-view:hover {
|
||||
background-color: dodgerblue;
|
||||
border-right: 1px solid dodgerblue;
|
||||
cursor: row-resize;
|
||||
}
|
||||
|
||||
.editor-console {
|
||||
width: 100%;
|
||||
}
|
||||
38
RobotNet.WebApp/Pages/ScriptManager.razor
Normal file
38
RobotNet.WebApp/Pages/ScriptManager.razor
Normal file
@@ -0,0 +1,38 @@
|
||||
@page "/script-manager"
|
||||
@attribute [Authorize]
|
||||
@implements IAsyncDisposable
|
||||
|
||||
@using RobotNet.WebApp.Clients
|
||||
@using RobotNet.WebApp.Scripts.Components.Dashboards
|
||||
|
||||
@inject ProcessorHubClient ProcessorHub
|
||||
|
||||
<PageTitle>Script Manager</PageTitle>
|
||||
|
||||
<div class="w-100 h-100 position-relative overflow-hidden">
|
||||
<div class="w-100 h-100 position-absolute top-0 start-0 overflow-x-hidden overflow-y-auto d-flex flex-column">
|
||||
<CascadingValue Value="ProcessorHub">
|
||||
<ProcessController />
|
||||
<div class="flex-grow-1 w-100 position-relative overflow-hidden">
|
||||
<div class="w-100 h-100 position-absolute top-0 start-0 overflow-hidden d-flex flex-row">
|
||||
<RobotNet.WebApp.Scripts.Components.Dashboards.Variables />
|
||||
<RobotNet.WebApp.Scripts.Components.Dashboards.Tasks />
|
||||
<RobotNet.WebApp.Scripts.Components.Dashboards.Missions />
|
||||
</div>
|
||||
</div>
|
||||
</CascadingValue>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@code {
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await base.OnInitializedAsync();
|
||||
await ProcessorHub.StartAsync();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await ProcessorHub.StopAsync();
|
||||
}
|
||||
}
|
||||
25
RobotNet.WebApp/Pages/User.razor
Normal file
25
RobotNet.WebApp/Pages/User.razor
Normal file
@@ -0,0 +1,25 @@
|
||||
@page "/user"
|
||||
@attribute [Authorize]
|
||||
|
||||
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
|
||||
|
||||
@inject NavigationManager Navigation
|
||||
|
||||
<AuthorizeView>
|
||||
<Authorized>
|
||||
<div class="d-flex flex-column m-3">
|
||||
<h3>User <b>@context.User.Identity?.Name</b></h3>
|
||||
<div>
|
||||
<MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.Logout" IconColor="Color.Secondary" Size="Size.Large" OnClick="BeginLogOut">Logout</MudButton>
|
||||
</div>
|
||||
</div>
|
||||
</Authorized>
|
||||
</AuthorizeView>
|
||||
|
||||
@code {
|
||||
|
||||
public void BeginLogOut()
|
||||
{
|
||||
Navigation.NavigateToLogout("authentication/logout");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user