Merge pull request #750 from hishamco/alert-component

Use ModuleMessage component everywhere
This commit is contained in:
Shaun Walker 2020-10-01 10:05:43 -04:00 committed by GitHub
commit 5f56bc288b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 23 deletions

View File

@ -70,7 +70,7 @@
</span> </span>
</div> </div>
} }
@((MarkupString) _message) <ModuleMessage @ref=_message></ModuleMessage>
</div> </div>
@if (_image != string.Empty) @if (_image != string.Empty)
{ {
@ -91,9 +91,9 @@
private string _progressbarid = string.Empty; private string _progressbarid = string.Empty;
private string _filter = "*"; private string _filter = "*";
private bool _haseditpermission = false; private bool _haseditpermission = false;
private string _message = string.Empty;
private string _image = string.Empty; private string _image = string.Empty;
private string _guid; private string _guid;
private ModuleMessage _message = new ModuleMessage();
[Parameter] [Parameter]
public string Id { get; set; } // optional - for setting the id of the FileManager component for accessibility public string Id { get; set; } // optional - for setting the id of the FileManager component for accessibility
@ -205,7 +205,6 @@
private async Task FolderChanged(ChangeEventArgs e) private async Task FolderChanged(ChangeEventArgs e)
{ {
_message = string.Empty;
try try
{ {
FolderId = int.Parse((string)e.Value); FolderId = int.Parse((string)e.Value);
@ -217,13 +216,14 @@
catch (Exception ex) catch (Exception ex)
{ {
await logger.LogError(ex, "Error Loading Files {Error}", ex.Message); await logger.LogError(ex, "Error Loading Files {Error}", ex.Message);
_message = "<br /><div class=\"alert alert-danger\" role=\"alert\">Error Loading Files</div>";
_message.Message = "Error Loading Files";
_message.Type = MessageType.Error;
} }
} }
private async Task FileChanged(ChangeEventArgs e) private async Task FileChanged(ChangeEventArgs e)
{ {
_message = string.Empty;
FileId = int.Parse((string)e.Value); FileId = int.Parse((string)e.Value);
await SetImage(); await SetImage();
@ -273,7 +273,10 @@
if (result == string.Empty) if (result == string.Empty)
{ {
await logger.LogInformation("File Upload Succeeded {Files}", upload); await logger.LogInformation("File Upload Succeeded {Files}", upload);
_message = "<br /><div class=\"alert alert-success\" role=\"alert\">File Upload Succeeded</div>";
_message.Message = "File Upload Succeeded";
_message.Type = MessageType.Success;
await GetFiles(); await GetFiles();
if (upload.Length == 1) if (upload.Length == 1)
@ -290,30 +293,36 @@
else else
{ {
await logger.LogError("File Upload Failed For {Files}", result.Replace(",", ", ")); await logger.LogError("File Upload Failed For {Files}", result.Replace(",", ", "));
_message = "<br /><div class=\"alert alert-danger\" role=\"alert\">File Upload Failed</div>";
_message.Message = "File Upload Failed";
_message.Type = MessageType.Error;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
await logger.LogError(ex, "File Upload Failed {Error}", ex.Message); await logger.LogError(ex, "File Upload Failed {Error}", ex.Message);
_message = "<br /><div class=\"alert alert-danger\" role=\"alert\">File Upload Failed</div>";
_message.Message = "File Upload Failed";
_message.Type = MessageType.Error;
} }
} }
else else
{ {
_message = "<br /><div class=\"alert alert-warning\" role=\"alert\">You Have Not Selected A File To Upload</div>"; _message.Message = "You Have Not Selected A File To Upload";
_message.Type = MessageType.Warning;
} }
} }
private async Task DeleteFile() private async Task DeleteFile()
{ {
_message = string.Empty;
try try
{ {
await FileService.DeleteFileAsync(FileId); await FileService.DeleteFileAsync(FileId);
await logger.LogInformation("File Deleted {File}", FileId); await logger.LogInformation("File Deleted {File}", FileId);
_message = "<br /><div class=\"alert alert-success\" role=\"alert\">File Deleted</div>";
_message.Message = "File Deleted";
_message.Type = MessageType.Success;
await GetFiles(); await GetFiles();
FileId = -1; FileId = -1;
await SetImage(); await SetImage();
@ -322,7 +331,9 @@
catch (Exception ex) catch (Exception ex)
{ {
await logger.LogError(ex, "Error Deleting File {File} {Error}", FileId, ex.Message); await logger.LogError(ex, "Error Deleting File {File} {Error}", FileId, ex.Message);
_message = "<br /><div class=\"alert alert-danger\" role=\"alert\">Error Deleting File</div>";
_message.Message = "Error Deleting File";
_message.Type = MessageType.Error;
} }
} }

View File

@ -8,7 +8,7 @@
@if (_filemanagervisible) @if (_filemanagervisible)
{ {
<FileManager @ref="_fileManager" Filter="@Constants.ImageFiles" /> <FileManager @ref="_fileManager" Filter="@Constants.ImageFiles" />
@((MarkupString)_message) <ModuleMessage @ref=_message></ModuleMessage>
<br /> <br />
} }
<div class="row justify-content-center" style="margin-bottom: 20px;"> <div class="row justify-content-center" style="margin-bottom: 20px;">
@ -85,7 +85,7 @@
private FileManager _fileManager; private FileManager _fileManager;
private string _content = string.Empty; private string _content = string.Empty;
private string _original = string.Empty; private string _original = string.Empty;
private string _message = string.Empty; private ModuleMessage _message = new ModuleMessage();
[Parameter] [Parameter]
public string Content { get; set; } public string Content { get; set; }
@ -144,7 +144,6 @@
public void CloseFileManager() public void CloseFileManager()
{ {
_filemanagervisible = false; _filemanagervisible = false;
_message = string.Empty;
StateHasChanged(); StateHasChanged();
} }
@ -189,17 +188,16 @@
var interop = new RichTextEditorInterop(JSRuntime); var interop = new RichTextEditorInterop(JSRuntime);
await interop.InsertImage(_editorElement, ContentUrl(fileid)); await interop.InsertImage(_editorElement, ContentUrl(fileid));
_filemanagervisible = false; _filemanagervisible = false;
_message = string.Empty;
} }
else else
{ {
_message = "<br /><div class=\"alert alert-warning\" role=\"alert\">You Must Select An Image To Insert</div>"; _message.Message = "You Must Select An Image To Insert";
_message.Type = MessageType.Warning;
} }
} }
else else
{ {
_filemanagervisible = true; _filemanagervisible = true;
_message = string.Empty;
} }
StateHasChanged(); StateHasChanged();
} }

View File

@ -119,7 +119,7 @@
<div class="row"> <div class="row">
<div class="mx-auto text-center"> <div class="mx-auto text-center">
<button type="button" class="btn btn-success" @onclick="Install">Install Now</button><br /><br /> <button type="button" class="btn btn-success" @onclick="Install">Install Now</button><br /><br />
@((MarkupString) _message) <ModuleMessage @ref=_message></ModuleMessage>
</div> </div>
<div class="app-progress-indicator" style="@_loadingDisplay"></div> <div class="app-progress-indicator" style="@_loadingDisplay"></div>
</div> </div>
@ -135,7 +135,7 @@
private string _hostPassword = ""; private string _hostPassword = "";
private string _confirmPassword = ""; private string _confirmPassword = "";
private string _hostEmail = ""; private string _hostEmail = "";
private string _message = ""; private ModuleMessage _message = new ModuleMessage();
private string _integratedSecurityDisplay = "display: none;"; private string _integratedSecurityDisplay = "display: none;";
private string _loadingDisplay = "display: none;"; private string _loadingDisplay = "display: none;";
@ -201,13 +201,15 @@
} }
else else
{ {
_message = "<div class=\"alert alert-danger\" role=\"alert\">" + installation.Message + "</div>"; _message.Message = installation.Message;
_message.Type = MessageType.Error;
_loadingDisplay = "display: none;"; _loadingDisplay = "display: none;";
} }
} }
else else
{ {
_message = "<div class=\"alert alert-danger\" role=\"alert\">Please Enter All Fields And Ensure Passwords Match And Are Greater Than 5 Characters In Length</div>"; _message.Message = "Please Enter All Fields And Ensure Passwords Match And Are Greater Than 5 Characters In Length";
_message.Type = MessageType.Error;
} }
} }