admin: add common-code crud and business-day rules
This commit is contained in:
@@ -0,0 +1,177 @@
|
||||
@page "/admin/common-codes"
|
||||
@using TaxBaik.Web.Services.AdminClients
|
||||
@using TaxBaik.Domain.Entities
|
||||
@attribute [Authorize]
|
||||
@inject ICommonCodeBrowserClient CommonCodeClient
|
||||
@inject ISnackbar Snackbar
|
||||
|
||||
<PageTitle>공통관리</PageTitle>
|
||||
|
||||
<section class="admin-page-hero">
|
||||
<div>
|
||||
<MudText Typo="Typo.caption" Class="admin-eyebrow">System</MudText>
|
||||
<MudText Typo="Typo.h4" Class="admin-page-title">공통관리</MudText>
|
||||
<MudText Typo="Typo.body2" Class="admin-page-subtitle">공통코드 그룹과 항목을 일관된 기준으로 관리합니다.</MudText>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<MudGrid Spacing="2">
|
||||
<MudItem XS="12" MD="4">
|
||||
<MudPaper Class="admin-surface pa-4" Elevation="0">
|
||||
<MudText Typo="Typo.h6" Class="mb-3">그룹</MudText>
|
||||
<MudSelect T="string" Value="@selectedGroup" ValueChanged="OnGroupChanged" Label="코드 그룹" Variant="Variant.Outlined" FullWidth="true">
|
||||
@foreach (var group in groups)
|
||||
{
|
||||
<MudSelectItem Value="@group">@group</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudButton Class="mt-3" Variant="Variant.Filled" Color="Color.Primary" OnClick="PrepareCreate">새 코드 추가</MudButton>
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
|
||||
<MudItem XS="12" MD="8">
|
||||
<MudPaper Class="admin-surface pa-4" Elevation="0">
|
||||
@if (isLoading)
|
||||
{
|
||||
<MudProgressLinear Indeterminate="true" />
|
||||
}
|
||||
else
|
||||
{
|
||||
<MudTable Items="@codes" Dense="true" Hover="true">
|
||||
<HeaderContent>
|
||||
<MudTh>그룹</MudTh>
|
||||
<MudTh>값</MudTh>
|
||||
<MudTh>이름</MudTh>
|
||||
<MudTh>순서</MudTh>
|
||||
<MudTh>상태</MudTh>
|
||||
<MudTh>작업</MudTh>
|
||||
</HeaderContent>
|
||||
<RowTemplate>
|
||||
<MudTd>@context.CodeGroup</MudTd>
|
||||
<MudTd>@context.CodeValue</MudTd>
|
||||
<MudTd>@context.CodeName</MudTd>
|
||||
<MudTd>@context.SortOrder</MudTd>
|
||||
<MudTd>@(context.IsActive ? "활성" : "비활성")</MudTd>
|
||||
<MudTd>
|
||||
<MudButton Size="Size.Small" Variant="Variant.Text" OnClick="@(() => EditCode(context))">수정</MudButton>
|
||||
<MudButton Size="Size.Small" Variant="Variant.Text" Color="Color.Error" OnClick="@(() => DeleteCode(context))">삭제</MudButton>
|
||||
</MudTd>
|
||||
</RowTemplate>
|
||||
</MudTable>
|
||||
|
||||
<MudDivider Class="my-4" />
|
||||
|
||||
<MudForm @ref="form">
|
||||
<MudTextField @bind-Value="editModel.CodeGroup" Label="그룹" Variant="Variant.Outlined" FullWidth="true" Required="true" Disabled="@(!isCreateMode)" Class="mb-3" />
|
||||
<MudTextField @bind-Value="editModel.CodeValue" Label="값" Variant="Variant.Outlined" FullWidth="true" Required="true" Disabled="@(!isCreateMode)" Class="mb-3" />
|
||||
<MudTextField @bind-Value="editModel.CodeName" Label="이름" Variant="Variant.Outlined" FullWidth="true" Required="true" Class="mb-3" />
|
||||
<MudNumericField T="int" @bind-Value="editModel.SortOrder" Label="순서" Variant="Variant.Outlined" FullWidth="true" Class="mb-3" />
|
||||
<MudSwitch @bind-Checked="editModel.IsActive" Color="Color.Primary">활성</MudSwitch>
|
||||
<div class="d-flex gap-2 mt-4">
|
||||
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="SaveCode">저장</MudButton>
|
||||
<MudButton Variant="Variant.Outlined" OnClick="PrepareCreate">초기화</MudButton>
|
||||
</div>
|
||||
</MudForm>
|
||||
}
|
||||
</MudPaper>
|
||||
</MudItem>
|
||||
</MudGrid>
|
||||
|
||||
@code {
|
||||
private List<string> groups = [];
|
||||
private List<CommonCode> codes = [];
|
||||
private string selectedGroup = "";
|
||||
private bool isLoading = true;
|
||||
private MudForm? form;
|
||||
private CommonCode editModel = new();
|
||||
private bool isCreateMode = true;
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
groups = await CommonCodeClient.GetGroupsAsync();
|
||||
selectedGroup = groups.FirstOrDefault() ?? "";
|
||||
await LoadCodes();
|
||||
PrepareCreate();
|
||||
}
|
||||
|
||||
private async Task OnGroupChanged(string value)
|
||||
{
|
||||
selectedGroup = value;
|
||||
await LoadCodes();
|
||||
PrepareCreate();
|
||||
}
|
||||
|
||||
private async Task LoadCodes()
|
||||
{
|
||||
isLoading = true;
|
||||
codes = string.IsNullOrWhiteSpace(selectedGroup)
|
||||
? []
|
||||
: await CommonCodeClient.GetByGroupAsync(selectedGroup);
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
private void PrepareCreate()
|
||||
{
|
||||
isCreateMode = true;
|
||||
editModel = new CommonCode
|
||||
{
|
||||
CodeGroup = selectedGroup,
|
||||
IsActive = true
|
||||
};
|
||||
}
|
||||
|
||||
private void EditCode(CommonCode code)
|
||||
{
|
||||
isCreateMode = false;
|
||||
editModel = new CommonCode
|
||||
{
|
||||
CodeGroup = code.CodeGroup,
|
||||
CodeValue = code.CodeValue,
|
||||
CodeName = code.CodeName,
|
||||
SortOrder = code.SortOrder,
|
||||
IsActive = code.IsActive
|
||||
};
|
||||
}
|
||||
|
||||
private async Task SaveCode()
|
||||
{
|
||||
if (form != null)
|
||||
{
|
||||
await form.Validate();
|
||||
if (!form.IsValid)
|
||||
{
|
||||
Snackbar.Add("필수 항목을 입력하세요.", Severity.Warning);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (editModel.CodeValue.Contains(' '))
|
||||
{
|
||||
Snackbar.Add("code_value에는 공백을 넣을 수 없습니다.", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!await CommonCodeClient.UpsertAsync(editModel))
|
||||
{
|
||||
Snackbar.Add("저장 실패", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
Snackbar.Add("저장되었습니다.", Severity.Success);
|
||||
await LoadCodes();
|
||||
PrepareCreate();
|
||||
}
|
||||
|
||||
private async Task DeleteCode(CommonCode code)
|
||||
{
|
||||
if (!await CommonCodeClient.DeleteAsync(code.CodeGroup, code.CodeValue))
|
||||
{
|
||||
Snackbar.Add("삭제 실패", Severity.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
Snackbar.Add("삭제되었습니다.", Severity.Success);
|
||||
await LoadCodes();
|
||||
PrepareCreate();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user