This commit is contained in:
Đăng Nguyễn
2025-09-27 14:47:42 +07:00
parent 2bbcc19076
commit 2640fb92c1
27 changed files with 437 additions and 388 deletions

View File

@@ -0,0 +1,40 @@
@inject HttpClient Http
<div class="d-flex flex-column h-100 w-100">
<span Class="title">@MapName</span>
<div class="d-flex flex-grow-1 w-100 flex-column">
<div class="map-item">
<img src="@imageSrc" alt="map image" onerror="this.onerror=null; this.src='/images/Image-not-found.png';" />
</div>
<MudButton StartIcon="@Icons.Material.Filled.FileDownload" Class="m-2" Size="Size.Small" Variant="Variant.Filled" Color="Color.Primary" Disabled="Disable">
DOWNLOAD
</MudButton>
</div>
</div>
@code {
private bool Disable = true;
private string imageSrc = "/images/Image-not-found.png";
private string MapName = "Map preview";
private Guid MapId = Guid.Empty;
public void SetMapPreview(MapDto? map)
{
if (map is null)
{
Disable = true;
MapName = "Map preview";
imageSrc = "/images/Image-not-found.png";
MapId = Guid.Empty;
}
else
{
imageSrc = $"api/Images/map/{map.Id}?t={DateTime.Now}";
MapName = map.Name;
MapId = map.Id;
Disable = false;
}
StateHasChanged();
}
}

View File

@@ -0,0 +1,42 @@
.map-item {
display: flex;
justify-content: center;
width: 100%;
height: fit-content;
}
.map-item img {
justify-content: center;
width: 95%;
height: 400px;
object-fit: contain;
border-radius: 10px;
image-rendering: pixelated;
}
.title {
display: flex;
height: 77px;
width: 100%;
justify-content: center;
align-content: center;
/*border-bottom: 0.5px solid gray;*/
font-size: 30px;
flex-wrap: wrap;
padding-bottom: .5rem;
}
.map-update-item {
display: flex;
justify-content: center;
width: 100%;
height: fit-content;
}
.map-update-item img {
width: 100%;
height: 400px;
object-fit: contain;
border-radius: 10px;
image-rendering: pixelated;
}

View File

@@ -0,0 +1,165 @@
@inject HttpClient Http
<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 overflow-hidden">
<MudTable @ref="Table" Items="@MapsShow" T="MapDto" Dense Hover ReadOnly FixedHeader RowClass="cursor-pointer" Striped Elevation="10"
ServerData="ReloadData" Loading=@IsLoading RowClassFunc="@SelectedRowClassFunc" OnRowClick="RowClickEvent" Height="90vh" HorizontalScrollbar>
<ToolBarContent>
<MudText Typo="Typo.h6">Maps</MudText>
</ToolBarContent>
<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>
<MudMenuItem Icon="@Icons.Material.Filled.Edit" IconColor="Color.Info">Active</MudMenuItem>
<MudMenuItem Icon="@Icons.Material.Filled.Delete" IconColor="Color.Error">Delete</MudMenuItem>
</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>
@code {
private string txtSearch = "";
private bool IsLoading = false;
private List<MapDto> Maps = [];
private List<MapDto> MapsShow = [];
private int selectedRowNumber = -1;
private MapDto MapSelected = new();
private MudTable<MapDto>? Table;
private MapPreview? MapPreviewRef;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (!firstRender) return;
// await LoadMaps();
}
private async Task LoadMaps()
{
try
{
IsLoading = true;
Maps.Clear();
StateHasChanged();
var maps = await Http.GetFromJsonAsync<IEnumerable<MapDto>>($"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(MapDto 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<MapDto>> ReloadData(TableState state, CancellationToken _)
{
MapsShow.Clear();
var tasks = new List<MapDto>();
Maps.ForEach(map =>
{
if (FilterFunc(map)) tasks.Add(map);
});
MapsShow = tasks.Skip(state.Page * state.PageSize).Take(state.PageSize).ToList();
return Task.FromResult(new TableData<MapDto>() { TotalItems = tasks.Count, Items = MapsShow });
}
private void RowClickEvent(TableRowClickEventArgs<MapDto> tableRowClickEventArgs) { }
private string SelectedRowClassFunc(MapDto 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;
// MapPreviewRef?.SetMapPreview(MapSelected);
return "selected";
}
else
{
return string.Empty;
}
}
}

View File

@@ -0,0 +1,5 @@
.map-preview {
width: 20%;
height: 100%;
border-left: 1px solid silver;
}

View File

@@ -0,0 +1,5 @@
<h3>MapView</h3>
@code {
}