Merge pull request #3530 from sbwalker/dev

allow AddModuleMessage to support displaying the message at the bottom of the module instance
This commit is contained in:
Shaun Walker 2023-12-04 09:57:10 -05:00 committed by GitHub
commit 31315e5ba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 60 additions and 39 deletions

View File

@ -261,7 +261,12 @@ namespace Oqtane.Modules
// UI methods
public void AddModuleMessage(string message, MessageType type)
{
ModuleInstance.AddModuleMessage(message, type);
AddModuleMessage(message, type, "top");
}
public void AddModuleMessage(string message, MessageType type, string position)
{
ModuleInstance.AddModuleMessage(message, type, position);
}
public void ClearModuleMessage()

View File

@ -5,7 +5,10 @@
@if (CurrentException is null)
{
<ModuleMessage Message="@_message" Type="@_messageType"/>
if (_messagePosition == "top")
{
<ModuleMessage Message="@_message" Type="@_messageType" />
}
@if (ModuleType != null)
{
<DynamicComponent Type="@ModuleType" Parameters="@ModuleParameters"></DynamicComponent>
@ -14,6 +17,10 @@
<div class="app-progress-indicator"></div>
}
}
if (_messagePosition == "bottom")
{
<ModuleMessage Message="@_message" Type="@_messageType" />
}
}
else
{
@ -24,49 +31,58 @@ else
}
@code {
private string _message;
private string _error;
private MessageType _messageType;
private bool _progressIndicator = false;
private string _message;
private string _error;
private MessageType _messageType;
private string _messagePosition;
private bool _progressIndicator = false;
private Type ModuleType { get; set; }
private IDictionary<string, object> ModuleParameters { get; set; }
private Type ModuleType { get; set; }
private IDictionary<string, object> ModuleParameters { get; set; }
[CascadingParameter]
protected PageState PageState { get; set; }
[CascadingParameter]
protected PageState PageState { get; set; }
[CascadingParameter]
private Module ModuleState { get; set; }
[CascadingParameter]
private Module ModuleState { get; set; }
private ModuleMessage ModuleMessage { get; set; }
private ModuleMessage ModuleMessage { get; set; }
protected override void OnParametersSet()
{
_message = "";
if (!string.IsNullOrEmpty(ModuleState.ModuleType))
{
ModuleType = Type.GetType(ModuleState.ModuleType);
if (ModuleType != null)
{
ModuleParameters = new Dictionary<string, object> { { "ModuleInstance", this } };
return;
}
// module does not exist with typename specified
_message = string.Format(Localizer["Error.Module.InvalidName"], Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0));
_messageType = MessageType.Error;
}
else
{
_message = string.Format(Localizer["Error.Module.InvalidType"], ModuleState.ModuleDefinitionName);
_messageType = MessageType.Error;
}
}
protected override void OnParametersSet()
{
_message = "";
if (!string.IsNullOrEmpty(ModuleState.ModuleType))
{
ModuleType = Type.GetType(ModuleState.ModuleType);
if (ModuleType != null)
{
ModuleParameters = new Dictionary<string, object> { { "ModuleInstance", this } };
return;
}
// module does not exist with typename specified
_message = string.Format(Localizer["Error.Module.InvalidName"], Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0));
_messageType = MessageType.Error;
_messagePosition = "top";
}
else
{
_message = string.Format(Localizer["Error.Module.InvalidType"], ModuleState.ModuleDefinitionName);
_messageType = MessageType.Error;
_messagePosition = "top";
}
}
public void AddModuleMessage(string message, MessageType type)
{
_message = message;
_messageType = type;
_progressIndicator = false;
public void AddModuleMessage(string message, MessageType type)
{
AddModuleMessage(message, type, "top");
}
public void AddModuleMessage(string message, MessageType type, string position)
{
_message = message;
_messageType = type;
_messagePosition = position;
_progressIndicator = false;
StateHasChanged();
}