Initial commit: Tasks.Module
This commit is contained in:
@@ -0,0 +1,167 @@
|
||||
@using Tasks.Module.Models
|
||||
@using Tasks.Module.Services
|
||||
@inject ICategoryService CategoryService
|
||||
@inject ITagService TagService
|
||||
|
||||
<MudDialog>
|
||||
<DialogContent>
|
||||
@if (IsChild)
|
||||
{
|
||||
<MudAlert Severity="Severity.Info" Class="mb-3">
|
||||
Adding sub-task to: <strong>@ParentTitle</strong>
|
||||
</MudAlert>
|
||||
}
|
||||
|
||||
<MudTextField @bind-Value="Task.Title" Label="Title" Required="true" Class="mb-3" />
|
||||
<MudTextField @bind-Value="Task.Description" Label="Description" Lines="3" Class="mb-3" />
|
||||
|
||||
<MudSelect T="string" @bind-Value="_categoryId" Label="Category" Clearable="true" Class="mb-3">
|
||||
@foreach (var cat in _flatCategories)
|
||||
{
|
||||
<MudSelectItem T="string" Value="cat.Id">
|
||||
@if (cat.Depth > 0)
|
||||
{
|
||||
@for (int i = 0; i < cat.Depth; i++)
|
||||
{
|
||||
<text> </text>
|
||||
}
|
||||
<text>└ </text>
|
||||
}
|
||||
@cat.Name
|
||||
</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
|
||||
<MudSelect T="int" @bind-Value="_priority" Label="Priority" Class="mb-3" Style="max-width: 200px;">
|
||||
<MudSelectItem T="int" Value="0">Low</MudSelectItem>
|
||||
<MudSelectItem T="int" Value="1">Medium</MudSelectItem>
|
||||
<MudSelectItem T="int" Value="2">High</MudSelectItem>
|
||||
</MudSelect>
|
||||
|
||||
<MudSelect T="string" @bind-Value="_selectedTagId" Label="Add Tag" Clearable="true" Class="mb-3">
|
||||
@foreach (var tag in _availableTags)
|
||||
{
|
||||
<MudSelectItem T="string" Value="tag.Id">@tag.Name</MudSelectItem>
|
||||
}
|
||||
</MudSelect>
|
||||
<MudButton Variant="Variant.Outlined" Color="Color.Primary" Size="Size.Small" OnClick="AddSelectedTag" Disabled="string.IsNullOrEmpty(_selectedTagId)">Add</MudButton>
|
||||
|
||||
@if (_selectedTagIds.Count > 0)
|
||||
{
|
||||
<div class="mb-3 d-flex flex-wrap gap-1">
|
||||
@foreach (var tagId in _selectedTagIds)
|
||||
{
|
||||
var tag = _allTags.FirstOrDefault(t => t.Id == tagId);
|
||||
if (tag != null)
|
||||
{
|
||||
<MudChip T="string" Color="Color.Primary" Size="Size.Small" OnClick="() => RemoveTag(tagId)">@tag.Name</MudChip>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
<MudDatePicker @bind-Date="Task.DueDate" Label="Due Date" Class="mb-3" />
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<MudButton OnClick="Cancel">Cancel</MudButton>
|
||||
<MudButton Color="Color.Primary" OnClick="Submit">Save</MudButton>
|
||||
</DialogActions>
|
||||
</MudDialog>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public CreateTodoItemDto Task { get; set; } = new();
|
||||
|
||||
[Parameter]
|
||||
public bool IsUpdate { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public bool IsChild { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public string? ParentTitle { get; set; }
|
||||
|
||||
[CascadingParameter]
|
||||
private IMudDialogInstance? MudDialog { get; set; }
|
||||
|
||||
private List<FlatCategory> _flatCategories = new();
|
||||
private List<TagDto> _allTags = new();
|
||||
private List<TagDto> _availableTags = new();
|
||||
private int _priority = 0;
|
||||
private string? _selectedTagId;
|
||||
private List<string> _selectedTagIds = new();
|
||||
private string? _categoryId = null;
|
||||
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
await LoadData();
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
var hierarchy = await CategoryService.GetHierarchyAsync();
|
||||
_flatCategories = FlattenCategories(hierarchy);
|
||||
|
||||
_allTags = await TagService.GetAllAsync();
|
||||
_availableTags = _allTags.ToList();
|
||||
|
||||
_priority = Task.Priority;
|
||||
|
||||
if (!string.IsNullOrEmpty(Task.CategoryId) && _flatCategories.Any(c => c.Id == Task.CategoryId))
|
||||
{
|
||||
_categoryId = Task.CategoryId;
|
||||
}
|
||||
else
|
||||
{
|
||||
_categoryId = null;
|
||||
}
|
||||
|
||||
_selectedTagIds = Task.TagIds?.ToList() ?? new List<string>();
|
||||
_availableTags = _allTags.Where(t => !_selectedTagIds.Contains(t.Id)).ToList();
|
||||
}
|
||||
|
||||
private List<FlatCategory> FlattenCategories(List<CategoryDto> categories, int depth = 0)
|
||||
{
|
||||
var result = new List<FlatCategory>();
|
||||
foreach (var cat in categories)
|
||||
{
|
||||
result.Add(new FlatCategory { Id = cat.Id, Name = cat.Name, Depth = depth });
|
||||
if (cat.Children.Count > 0)
|
||||
{
|
||||
result.AddRange(FlattenCategories(cat.Children, depth + 1));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void AddSelectedTag()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_selectedTagId) && !_selectedTagIds.Contains(_selectedTagId))
|
||||
{
|
||||
_selectedTagIds.Add(_selectedTagId);
|
||||
_availableTags = _allTags.Where(t => !_selectedTagIds.Contains(t.Id)).ToList();
|
||||
_selectedTagId = null;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void RemoveTag(string tagId)
|
||||
{
|
||||
_selectedTagIds.Remove(tagId);
|
||||
_availableTags = _allTags.Where(t => !_selectedTagIds.Contains(t.Id)).ToList();
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void Submit()
|
||||
{
|
||||
Task.Priority = _priority;
|
||||
Task.CategoryId = _categoryId;
|
||||
Task.TagIds = _selectedTagIds;
|
||||
MudDialog?.Close(DialogResult.Ok(true));
|
||||
}
|
||||
|
||||
private void Cancel()
|
||||
{
|
||||
MudDialog?.Cancel();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user