first commit -push

This commit is contained in:
dungtt
2025-10-15 15:15:53 +07:00
parent 674ae395be
commit a9577c5756
885 changed files with 74595 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
@inject ISnackbar Snackbar
<MudDialog>
<TitleContent>
<MudText Typo="Typo.h6">
@Title
</MudText>
</TitleContent>
<DialogContent>
<div class="d-flex flex-column" style="width: 500px;">
<MudTextField @bind-Value="FileName" Label="@Label" Class="mb-3" ShrinkLabel Variant="Variant.Outlined"
DebounceInterval="500" OnDebounceIntervalElapsed="ValidateName" OnBlur="ValidateName"
Error="@NameError" ErrorText="@NameErrorText" Adornment="@AdornmentVisible" AdornmentText=".cs" />
</div>
</DialogContent>
<DialogActions>
<MudButton OnClick="OnCancel">Cancel</MudButton>
<MudButton Color="Color.Primary" OnClick="OnCreate" Disabled="@CreateButtonDisable">Create</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter]
private IMudDialogInstance Dialog { get; set; } = null!;
[Parameter]
public string FolderName { get; set; } = "";
[Parameter]
public bool IsFolder { get; set; } = false;
private string Title => $"Tạo mới {(IsFolder ? "folder" : "file code")}";
private string Label => $"/{FolderName}";
private Adornment AdornmentVisible => IsFolder ? Adornment.None : Adornment.End;
private string FileName { get; set; } = "";
private string NameErrorText = "";
private bool NameError = false;
private bool CreateButtonDisable => NameError;
private void OnCancel() => Dialog.Cancel();
public void OnCreate()
{
ValidateName();
if (NameError)
{
Snackbar.Add("Tên chưa đúng!", Severity.Error);
}
else
{
Dialog.Close(DialogResult.Ok(FileName));
}
}
private void ValidateName()
{
NameErrorText = string.IsNullOrEmpty(FileName) ? "Tên không được để trống" : "";
NameError = !string.IsNullOrEmpty(NameErrorText);
}
}

View File

@@ -0,0 +1,98 @@
@inject ISnackbar Snackbar
<MudDialog>
<TitleContent>
<MudText Typo="Typo.h6">
Danh sách script sẽ xóa
</MudText>
</TitleContent>
<DialogContent>
<div class="d-flex flex-column ms-3 overflow-y-scroll overflow-x-auto" style="height: 200px; width: 500px;">
@foreach (var file in DeleteList)
{
<span>
@file
</span>
}
</div>
</DialogContent>
<DialogActions>
<MudButton OnClick="OnCancel">Cancel</MudButton>
<MudButton Color="Color.Primary" OnClick="OnDelete">Delete</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter]
private IMudDialogInstance Dialog { get; set; } = null!;
[Parameter]
public ScriptWorkspace Workspace { get; set; } = null!;
private IEnumerable<string> DeleteList = [];
protected override void OnInitialized()
{
base.OnInitialized();
if (Workspace.SelectedFile is not null)
{
DeleteList = [Workspace.SelectedFile.Path];
StateHasChanged();
}
else if (Workspace.SelectedFolder is not null)
{
DeleteList = GetListFromFolder(Workspace.SelectedFolder);
StateHasChanged();
}
}
private IEnumerable<string> GetListFromFolder(ScriptFolderModel folder)
{
var list = new List<string>();
list.Add(folder.Path);
foreach (var dir in folder.Folders)
{
list.AddRange(GetListFromFolder(dir));
}
foreach (var file in folder.Files)
{
list.Add(file.Path);
}
return list;
}
private void OnCancel() => Dialog.Cancel();
private async Task OnDelete()
{
if (Workspace.SelectedFile is not null)
{
var result = await Workspace.DeleteFile(Workspace.SelectedFile);
if (result.IsSuccess)
{
Dialog.Close();
}
else
{
Snackbar.Add(result.Message, Severity.Error);
}
}
else if (Workspace.SelectedFolder is not null)
{
var result = await Workspace.DeleteFolder(Workspace.SelectedFolder);
if (result.IsSuccess)
{
Dialog.Close();
}
else
{
Snackbar.Add(result.Message, Severity.Error);
}
}
}
}

View File

@@ -0,0 +1,107 @@
@inject ISnackbar Snackbar
<MudDialog>
<TitleContent>
<MudText Typo="Typo.h6">
@Title
</MudText>
</TitleContent>
<DialogContent>
<div class="d-flex flex-column" style="width: 500px;">
<MudTextField @bind-Value="FileName" Label="@Label" Class="mb-3" ShrinkLabel Variant="Variant.Outlined"
DebounceInterval="500" OnDebounceIntervalElapsed="ValidateName" OnBlur="ValidateName"
Error="@NameError" ErrorText="@NameErrorText" Adornment="@AdornmentVisible" AdornmentText=".cs" />
</div>
</DialogContent>
<DialogActions>
<MudButton OnClick="OnCancel">Cancel</MudButton>
<MudButton Color="Color.Primary" OnClick="OnRename" Disabled="@RenameDisabled">Rename</MudButton>
</DialogActions>
</MudDialog>
@code {
[CascadingParameter]
private IMudDialogInstance Dialog { get; set; } = null!;
[Parameter]
public ScriptWorkspace Workspace { get; set; } = null!;
private bool IsFolder;
private string Label = "";
private string Title => IsFolder ? "Rename folder" : "Rename file";
private string NameErrorText = "";
private bool NameError = false;
private string FileName = "";
private string OldName = "";
private bool RenameDisabled => FileName == OldName;
private Adornment AdornmentVisible => IsFolder ? Adornment.None : Adornment.End;
protected override void OnInitialized()
{
base.OnInitialized();
if (Workspace.SelectedFile is not null)
{
IsFolder = false;
Label = Workspace.SelectedFile.Parrent?.Name ?? "/";
FileName = Workspace.SelectedFile.Name;
if (FileName.EndsWith(".cs"))
{
FileName = FileName.Substring(0, FileName.Length - 3);
}
OldName = FileName;
}
else if (Workspace.SelectedFolder is not null)
{
IsFolder = true;
Label = Workspace.SelectedFolder.Parrent?.Name ?? "/";
FileName = Workspace.SelectedFolder.Name;
OldName = FileName;
}
}
private void ValidateName()
{
NameErrorText = string.IsNullOrEmpty(FileName) ? "Tên không được để trống" : "";
NameError = !string.IsNullOrEmpty(NameErrorText);
}
private void OnCancel() => Dialog.Cancel();
private async Task OnRename()
{
ValidateName();
if (NameError)
{
Snackbar.Add("Tên chưa đúng!", Severity.Error);
}
else
{
if (Workspace.SelectedFile is not null)
{
var result = await Workspace.Rename(Workspace.SelectedFile, FileName.EndsWith(".cs") ? FileName : FileName + ".cs");
if (result.IsSuccess)
{
Dialog.Close();
}
else
{
Snackbar.Add(result.Message, Severity.Error);
}
}
else if (Workspace.SelectedFolder is not null)
{
var result = await Workspace.Rename(Workspace.SelectedFolder, FileName);
if (result.IsSuccess)
{
Dialog.Close();
}
else
{
Snackbar.Add(result.Message, Severity.Error);
}
}
}
}
}