Skip to content

Commit

Permalink
Merge pull request #388 from NeoCoderMatrix86/386-invalid-file-alert-…
Browse files Browse the repository at this point in the history
…is-not-cleared

Invalid file alert is not cleared
  • Loading branch information
NeoCoderMatrix86 authored Sep 17, 2024
2 parents 875f524 + 4d2efc3 commit 86e557e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 165 deletions.
160 changes: 11 additions & 149 deletions AudioCuesheetEditor/Pages/ViewModeImport.razor
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ along with Foobar. If not, see
@inject ImportManager _importManager

<Validations @ref="validations">
<Steps SelectedStep="@SelectedStep" SelectedStepChanged="@OnSelectedStepChanged">
<Steps @bind-SelectedStep="selectedStep" NavigationAllowed="NavigationAllowed">
<Items>
<Step Name="selectFiles" Completed="selectFilesCompleted">@_localizer["Select files"]</Step>
<Step Name="selectFiles" Completed="SelectFilesCompleted">@_localizer["Select files"]</Step>
<Step Name="validateData">@_localizer["Validate"]</Step>
</Items>
<Content>
Expand All @@ -41,7 +41,7 @@ along with Foobar. If not, see
<Field class="dragNDropFile mb-3" ondragover="dragOver(event, this)" ondragleave="dragLeave(event, this)" ondrop="dropFiles(event, this, 'dropFileInput')">
<svg class="dragNDropFileIcon" xmlns="http://www.w3.org/2000/svg" width="50" height="43" viewBox="0 0 50 43"><path d="M48.4 26.5c-.9 0-1.7.7-1.7 1.7v11.6h-43.3v-11.6c0-.9-.7-1.7-1.7-1.7s-1.7.7-1.7 1.7v13.2c0 .9.7 1.7 1.7 1.7h46.7c.9 0 1.7-.7 1.7-1.7v-13.2c0-1-.7-1.7-1.7-1.7zm-24.5 6.1c.3.3.8.5 1.2.5.4 0 .9-.2 1.2-.5l10-11.6c.7-.7.7-1.7 0-2.4s-1.7-.7-2.4 0l-7.1 8.3v-25.3c0-.9-.7-1.7-1.7-1.7s-1.7.7-1.7 1.7v25.3l-7.1-8.3c-.7-.7-1.7-.7-2.4 0s-.7 1.7 0 2.4l10 11.6z"></path></svg>
<FileEdit id="dropFileInput" Multiple Filter="@dragNDropUploadFilter" Changed="OnDropFileChanged" AutoReset="false"></FileEdit>
<FieldLabel for="dropFileInput">@((MarkupString)(_localizer["Choose file or drag it here"].ToString()))</FieldLabel>
<FieldLabel for="dropFileInput">@((MarkupString)(_localizer["Choose file or drag it here"]))</FieldLabel>
</Field>
@foreach (var invalidFileName in invalidDropFileNames)
{
Expand All @@ -51,55 +51,6 @@ along with Foobar. If not, see
<CloseButton />
</Alert>
}
<Divider />
<Tooltip Placement="TooltipPlacement.Top" Text="@_localizer["Import textfile tooltip"]">
<Field Horizontal="true">
<FieldLabel ColumnSize="ColumnSize.Is2.OnFullHD.Is3.OnDesktop.Is4.OnTablet.Is5.OnMobile">@_localizer["Textfile"]</FieldLabel>
<FieldBody ColumnSize="ColumnSize.Is10.OnFullHD.Is9.OnDesktop.Is8.OnTablet.Is12.OnMobile">
<FileEdit Filter="@FileMimeTypes.Text" Changed="OnTextImportFileChanged" AutoReset="false"></FileEdit>
</FieldBody>
</Field>
</Tooltip>
@foreach (var invalidFileName in invalidTextImportFileNames)
{
<Alert @ref="alertInvalidFile" Color="Color.Danger" Visible Dismisable>
<AlertMessage>@_localizer["Invalid file"]</AlertMessage>
<AlertDescription>@String.Format(_localizer["You dropped an invalid file ({0}) that can not be processed."], invalidFileName)</AlertDescription>
<CloseButton />
</Alert>
}
<Tooltip Placement="TooltipPlacement.Top" Text="@_localizer["Import cuesheet tooltip"]">
<Field Horizontal="true">
<FieldLabel ColumnSize="ColumnSize.Is2.OnFullHD.Is3.OnDesktop.Is4.OnTablet.Is5.OnMobile">@_localizer["Cuesheet"]</FieldLabel>
<FieldBody ColumnSize="ColumnSize.Is10.OnFullHD.Is9.OnDesktop.Is8.OnTablet.Is12.OnMobile">
<FileEdit Filter="@FileExtensions.Cuesheet" Changed="OnCuesheetfileChanged" AutoReset="false"></FileEdit>
</FieldBody>
</Field>
</Tooltip>
@foreach (var invalidFileName in invalidCuesheetfileNames)
{
<Alert @ref="alertInvalidFile" Color="Color.Danger" Visible Dismisable>
<AlertMessage>@_localizer["Invalid file"]</AlertMessage>
<AlertDescription>@String.Format(_localizer["You dropped an invalid file ({0}) that can not be processed."], invalidFileName)</AlertDescription>
<CloseButton />
</Alert>
}
<Tooltip Placement="TooltipPlacement.Top" Text="@_localizer["Import project tooltip"]">
<Field Horizontal="true">
<FieldLabel ColumnSize="ColumnSize.Is2.OnFullHD.Is3.OnDesktop.Is4.OnTablet.Is5.OnMobile">@_localizer["Project filename"]</FieldLabel>
<FieldBody ColumnSize="ColumnSize.Is10.OnFullHD.Is9.OnDesktop.Is8.OnTablet.Is12.OnMobile">
<FileEdit Filter="@FileExtensions.Projectfile" Changed="OnProjectfileChanged" AutoReset="false"></FileEdit>
</FieldBody>
</Field>
</Tooltip>
@foreach (var invalidFileName in invalidProjectfileNames)
{
<Alert @ref="alertInvalidFile" Color="Color.Danger" Visible Dismisable>
<AlertMessage>@_localizer["Invalid file"]</AlertMessage>
<AlertDescription>@String.Format(_localizer["You dropped an invalid file ({0}) that can not be processed."], invalidFileName)</AlertDescription>
<CloseButton />
</Alert>
}
</CardBody>
</Card>
</StepPanel>
Expand Down Expand Up @@ -205,16 +156,11 @@ along with Foobar. If not, see
Boolean cuesheetSplitPointsVisible = true;
Boolean importFileContentVisible = true;
Boolean importOptionsVisible = true;
Boolean selectFilesCompleted = false;
Boolean userChangedSelectedStep = false;
Boolean displaySplitPoints = false;
Boolean displayFileContent = true;
Boolean displayEditImportOptions = true;
Alert? alertInvalidFile;
ModalDialog? modalDialog;
List<String> invalidTextImportFileNames = new();
List<String> invalidCuesheetfileNames = new();
List<String> invalidProjectfileNames = new();
List<String> invalidDropFileNames = new();

HotKeysContext? hotKeysContext;
Expand All @@ -238,100 +184,16 @@ along with Foobar. If not, see
.Add(Key.Enter, OnEnterKeyDown);
}

async Task OnSelectedStepChanged(String name)
{
userChangedSelectedStep = true;
switch (name)
{
case "selectFiles":
selectedStep = name;
break;
case "validateData":
if ((_sessionStateContainer.ImportCuesheet != null) || (_sessionStateContainer.Importfile != null))
{
selectFilesCompleted = true;
selectedStep = name;
}
else
{
if (modalDialog != null)
{
modalDialog.Title = _localizer["Not possible!"];
modalDialog.Text = _localizer["Please select files for import before going to validation!"];
modalDialog.ModalSize = ModalSize.Small;
modalDialog.Mode = ModalDialog.DialogMode.Alert;
await modalDialog.ShowModal();
}
}
break;
}
}
Boolean SelectFilesCompleted => (_sessionStateContainer.ImportCuesheet != null) || (_sessionStateContainer.Importfile != null);

String SelectedStep
bool NavigationAllowed(StepNavigationContext context)
{
get
if (context.CurrentStepName == "selectFiles" && context.NextStepName == "validateData")
{
if ((userChangedSelectedStep == false) && ((_sessionStateContainer.ImportCuesheet != null) || (_sessionStateContainer.Importfile != null)))
{
selectFilesCompleted = true;
selectedStep = "validateData";
}
return selectedStep;
return SelectFilesCompleted;
}
}

private async Task OnTextImportFileChanged(FileChangedEventArgs e)
{
invalidTextImportFileNames.Clear();
if (e.Files.FirstOrDefault() != null)
{
var file = e.Files.First();
if (IOUtility.CheckFileMimeType(file, FileMimeTypes.Text, FileExtensions.Text) == false)
{
invalidTextImportFileNames.Add(file.Name);
}
else
{
await OnFileChanged(new List<IFileEntry>() { file });
}
StateHasChanged();
}
}

private async Task OnCuesheetfileChanged(FileChangedEventArgs e)
{
invalidCuesheetfileNames.Clear();
if (e.Files.FirstOrDefault() != null)
{
var file = e.Files.First();
if (IOUtility.CheckFileMimeType(file, FileMimeTypes.Cuesheet, FileExtensions.Cuesheet) == false)
{
invalidCuesheetfileNames.Add(file.Name);
}
else
{
await OnFileChanged(new List<IFileEntry>() { file });
}
StateHasChanged();
}
}

private async Task OnProjectfileChanged(FileChangedEventArgs e)
{
invalidProjectfileNames.Clear();
if (e.Files.FirstOrDefault() != null)
{
var file = e.Files.First();
if (IOUtility.CheckFileMimeType(file, FileMimeTypes.Projectfile, FileExtensions.Projectfile) == false)
{
invalidProjectfileNames.Add(file.Name);
}
else
{
await OnFileChanged(new List<IFileEntry>() { file });
}
StateHasChanged();
}
return true;
}

private async Task OnDropFileChanged(FileChangedEventArgs e)
Expand Down Expand Up @@ -374,7 +236,7 @@ along with Foobar. If not, see
displaySplitPoints = importedFiles.ContainsValue(ImportFileType.ProjectFile);
displayFileContent = importedFiles.ContainsValue(ImportFileType.Textfile);
displayEditImportOptions = importedFiles.ContainsValue(ImportFileType.Textfile);
await OnSelectedStepChanged("validateData");
selectedStep = "validateData";
StateHasChanged();
}

Expand Down Expand Up @@ -405,10 +267,10 @@ along with Foobar. If not, see
StateHasChanged();
}

async Task AbortImport()
void AbortImport()
{
_sessionStateContainer.ResetImport();
await OnSelectedStepChanged("selectFiles");
selectedStep = "selectFiles";
}

private void LocalizationService_LocalizationChanged(object? sender, EventArgs args)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
"Choose file or drag it here": "<strong>Wählen Sie die Dateien</strong><span> oder ziehen Sie diese hier her</span>",
"Invalid file": "Ungültige Datei",
"You dropped an invalid file ({0}) that can not be processed.": "Sie haben eine ungültige Datei ({0}) selektiert, die nicht verarbeitet werden kann.",
"Import textfile tooltip": "Textdatei importieren und Daten über reguläre Ausdrücke extrahieren",
"Textfile": "Textdatei",
"Import cuesheet tooltip": "Importieren Sie ein Cuesheet und extrahieren Sie alle Daten daraus",
"Cuesheet": "Cuesheet",
"Import project tooltip": "Ein gespeichertes Projekt importieren",
"Project filename": "Projektdatei",
"Validate data for import": "Daten für den Import validieren",
"Recognition of import data finished": "Analyse der Importdateien abgeschlossen",
"Please validate the following data recognized by import assistant. Once you have validated all input, you can confirm import of data.": "Bitte validieren sie die analysierten und angezeigten Dateien. Anschließend können Sie die Daten bestätigen und den Import durchführen.",
Expand Down Expand Up @@ -42,8 +36,6 @@
"Begin": "Beginn",
"End": "Ende",
"Length": "Länge",
"Not possible!": "Ungültig!",
"Please select files for import before going to validation!": "Bitte selektieren Sie Dateien bevor Sie zur Validierung wechseln!",
"Textimportscheme cuesheet": "Import Schema Cuesheet",
"Textimportscheme track": "Import Schema Titel",
"Import Options": "Importoptionen",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
"Choose file or drag it here": "<strong>Choose files</strong><span> or drag them here</span>",
"Invalid file": "Invalid file",
"You dropped an invalid file ({0}) that can not be processed.": "You dropped an invalid file ({0}) that can not be processed.",
"Import textfile tooltip": "Import a plain text file and extract data via regular expressions",
"Textfile": "Textfile",
"Import cuesheet tooltip": "Import a cuesheet file and extract all data from it",
"Cuesheet": "Cuesheet",
"Import project tooltip": "Import a saved project",
"Project filename": "Project filename",
"Validate data for import": "Validate data for import",
"Recognition of import data finished": "Recognition of import data finished",
"Please validate the following data recognized by import assistant. Once you have validated all input, you can confirm import of data.": "Please validate the following data recognized by import assistant. Once you have validated all input, you can confirm import of data.",
Expand Down Expand Up @@ -41,8 +35,6 @@
"Begin": "Begin",
"End": "End",
"Length": "Length",
"Not possible!": "Not possible!",
"Please select files for import before going to validation!": "Please select files for import before going to validation!",
"Textimportscheme cuesheet": "Textimport scheme cuesheet",
"Textimportscheme track": "Textimport scheme track",
"Import Options": "Import options",
Expand Down

0 comments on commit 86e557e

Please sign in to comment.