mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-06 13:00:55 +00:00
Сделал добавление картриджей через форму
This commit is contained in:
1 parent
70bfae943b
commit
10c499e671
27 files changed
+922
-36
No files matched your search
@@ -1,25 +1,179 @@
|
||||
<RadzenStack>
|
||||
<RadzenFormField Text="Модель">
|
||||
<RadzenAutoComplete/>
|
||||
</RadzenFormField>
|
||||
<RadzenFormField Text="Производитель">
|
||||
<RadzenAutoComplete/>
|
||||
</RadzenFormField>
|
||||
<RadzenCard Variant="Variant.Flat" Style="padding: 0;">
|
||||
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Center">
|
||||
<RadzenText Text="Разделитель:"/>
|
||||
<RadzenTextBox />
|
||||
<RadzenText />
|
||||
<RadzenNumeric TValue="int"/>
|
||||
<RadzenText/>
|
||||
<RadzenNumeric TValue="int" />
|
||||
</RadzenStack>
|
||||
<RadzenStack Style="height: 180px;">
|
||||
@inject HttpClient http
|
||||
@inject DialogService DialogService
|
||||
@using CartriX.Shared.Classes
|
||||
@using CartriX.Shared.Models.Cartridge
|
||||
|
||||
|
||||
<RadzenStack Gap="8px">
|
||||
<RadzenFormField Text="Модель">
|
||||
<RadzenAutoComplete @bind-Value="@FieldModelValue" Data="@ModelSuggestions" @bind-Value:after="@OnModelChanged" OpenOnFocus="true" />
|
||||
</RadzenFormField>
|
||||
|
||||
<RadzenFormField Text="Производитель">
|
||||
<RadzenAutoComplete @bind-Value="FieldManufacturerValue" Data="@ManufacturerSuggestions" OpenOnFocus="true" />
|
||||
</RadzenFormField>
|
||||
<RadzenFormField Text="Объем тоннера">
|
||||
<RadzenNumeric TValue="uint" @bind-Value="FieldVolumeValue" />
|
||||
</RadzenFormField>
|
||||
|
||||
<RadzenStack Orientation="Orientation.Horizontal" Gap="8px" AlignItems="AlignItems.Stretch">
|
||||
<RadzenCard Variant="Variant.Outlined" Style="padding: 8px;">
|
||||
<RadzenStack Orientation="Orientation.Horizontal">
|
||||
<RadzenText Text="Фильтр" Style="flex: 1;" />
|
||||
<RadzenButton Icon="help" Size="ButtonSize.ExtraSmall" Click="@ShowFilterHelp" />
|
||||
</RadzenStack>
|
||||
<RadzenStack Gap="8px" Orientation="Orientation.Vertical" AlignItems="AlignItems.Stretch" Style="width: 115px">
|
||||
<RadzenFormField Text="Разделитель">
|
||||
<RadzenTextBox MaxLength="1" @bind-Value="filterValue.sepparetSymbol" @bind-Value:after="OnFilterChanged" />
|
||||
</RadzenFormField>
|
||||
<RadzenFormField Text="Отсечь слева">
|
||||
<RadzenNumeric TValue="byte" @bind-Value="filterValue.leftCut" @bind-Value:after="OnFilterChanged" />
|
||||
</RadzenFormField>
|
||||
<RadzenFormField Text="Отсечь справа">
|
||||
<RadzenNumeric TValue="byte" @bind-Value="filterValue.rightCut" @bind-Value:after="OnFilterChanged" />
|
||||
</RadzenFormField>
|
||||
</RadzenStack>
|
||||
</RadzenCard>
|
||||
|
||||
<RadzenStack Style="flex: 1;" Gap="8px">
|
||||
<RadzenCard Variant="Variant.Flat" Style="padding: 4px; flex: 1; overflow-y: scroll;">
|
||||
<RadzenStack Orientation="Orientation.Horizontal" Gap="4px" Wrap="FlexWrap.Wrap">
|
||||
@if (ListModelFamiliesValue.Count == 0)
|
||||
{
|
||||
<RadzenText Text="Нету ничего" />
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var ModelFamily in ListModelFamiliesValue)
|
||||
{
|
||||
<RadzenBadge Text="@ModelFamily" onclick="@(() => RemoveFamilyModel(ModelFamily))"
|
||||
Style="cursor: pointer;" />
|
||||
}
|
||||
}
|
||||
</RadzenStack>
|
||||
</RadzenCard>
|
||||
|
||||
<RadzenStack Orientation="Orientation.Horizontal">
|
||||
<RadzenAutoComplete Style="flex: 1;" Placeholder="Семейство моделей" @bind-Value="FieldModelFamilyValue"
|
||||
Data="@FilteredFamilySuggestions" OpenOnFocus="true" />
|
||||
<RadzenButton Icon="add" Click="AddFamilyModel"
|
||||
Disabled="@string.IsNullOrWhiteSpace(FieldModelFamilyValue)" />
|
||||
</RadzenStack>
|
||||
</RadzenStack>
|
||||
</RadzenCard>
|
||||
</RadzenStack>
|
||||
|
||||
<RadzenButton Text="Добавить картридж" Icon="add" Click="@SubmitCartridge" Disabled="@(!IsFormValid())" />
|
||||
</RadzenStack>
|
||||
|
||||
@code {
|
||||
List<string> ModelSuggestions = new();
|
||||
List<string> ManufacturerSuggestions = new();
|
||||
class Filter
|
||||
{
|
||||
public string sepparetSymbol { get; set; } = string.Empty;
|
||||
public byte leftCut { get; set; }
|
||||
public byte rightCut { get; set; }
|
||||
}
|
||||
|
||||
string FieldModelValue = default!;
|
||||
string FieldManufacturerValue = string.Empty;
|
||||
uint FieldVolumeValue;
|
||||
string FieldModelFamilyValue = string.Empty;
|
||||
List<string> ListModelFamiliesValue = new();
|
||||
Filter filterValue = new()
|
||||
{
|
||||
sepparetSymbol = "/",
|
||||
leftCut = 0,
|
||||
rightCut = 0
|
||||
};
|
||||
|
||||
List<string> FilteredFamilySuggestions = new();
|
||||
|
||||
async Task OnModelChanged()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(FieldModelValue))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ListModelFamiliesValue = ApplyFilter(FieldModelValue);
|
||||
StateHasChanged();
|
||||
}
|
||||
async Task OnFilterChanged()
|
||||
{
|
||||
ListModelFamiliesValue = ApplyFilter(FieldModelValue);
|
||||
}
|
||||
List<string> ApplyFilter(string rawModel)
|
||||
{
|
||||
List<string> parsedModels = new();
|
||||
string model = rawModel.Trim();
|
||||
if (filterValue.leftCut > 0 && filterValue.leftCut < model.Length)
|
||||
{
|
||||
model = model.Substring(filterValue.leftCut);
|
||||
}
|
||||
if (filterValue.rightCut > 0 && filterValue.rightCut < model.Length)
|
||||
{
|
||||
model = model.Substring(0, model.Length - filterValue.rightCut);
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(filterValue.sepparetSymbol) && model.Contains(filterValue.sepparetSymbol))
|
||||
{
|
||||
var list = model.Split(filterValue.sepparetSymbol);
|
||||
foreach (var item in list)
|
||||
{
|
||||
var family = CartridgeParser.GetCartridgeFamily(item);
|
||||
parsedModels.Add(family);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var family = CartridgeParser.GetCartridgeFamily(model);
|
||||
parsedModels.Add(family);
|
||||
}
|
||||
|
||||
return parsedModels;
|
||||
}
|
||||
async Task AddFamilyModel()
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(FieldModelFamilyValue)
|
||||
&& !ListModelFamiliesValue.Contains(FieldModelFamilyValue))
|
||||
{
|
||||
ListModelFamiliesValue.Add(FieldModelFamilyValue);
|
||||
FieldModelFamilyValue = string.Empty;
|
||||
}
|
||||
}
|
||||
async Task RemoveFamilyModel(string value)
|
||||
{
|
||||
ListModelFamiliesValue.Remove(value);
|
||||
StateHasChanged();
|
||||
}
|
||||
bool IsFormValid()
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(FieldModelValue) && !string.IsNullOrWhiteSpace(FieldManufacturerValue) &&
|
||||
ListModelFamiliesValue.Count > 0;
|
||||
}
|
||||
async Task SubmitCartridge()
|
||||
{
|
||||
var data = new CartridgeAdd()
|
||||
{
|
||||
ModelName = FieldModelValue,
|
||||
ManufacturerName = FieldManufacturerValue,
|
||||
SupportedArticles = ListModelFamiliesValue,
|
||||
Volume = FieldVolumeValue
|
||||
};
|
||||
await http.PostAsJsonAsync(ApiRoutes.Cartridge.AddCartridge, data);
|
||||
|
||||
DialogService.Close();
|
||||
}
|
||||
async Task ShowFilterHelp()
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
async Task ShowSuccessMessage(string message)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
async Task ShowErrorMessage(string message)
|
||||
{
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user