ErrorBoundary
This commit is contained in:
@ -123,4 +123,7 @@
|
|||||||
<data name="Error.Module.InvalidType" xml:space="preserve">
|
<data name="Error.Module.InvalidType" xml:space="preserve">
|
||||||
<value>Module Type Is Invalid For {0}</value>
|
<value>Module Type Is Invalid For {0}</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Error.Module.Exception" xml:space="preserve">
|
||||||
|
<value>Program error in module {0}</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
@ -1,17 +1,30 @@
|
|||||||
@namespace Oqtane.UI
|
@namespace Oqtane.UI
|
||||||
@inject IStringLocalizer<ModuleInstance> Localizer
|
@inject IStringLocalizer<ModuleInstance> Localizer
|
||||||
|
|
||||||
<ModuleMessage Message="@_message" Type="@_messagetype" />
|
<ErrorBoundary>
|
||||||
@DynamicComponent
|
<ErrorContent>
|
||||||
@if (_progressindicator)
|
<ModuleMessage Message="@ErrorMessage(context)" Type="@MessageType.Error"/>
|
||||||
{
|
</ErrorContent>
|
||||||
<div class="app-progress-indicator"></div>
|
<ChildContent>
|
||||||
}
|
<ModuleMessage Message="@_message" Type="@_messageType"/>
|
||||||
|
@if (ModuleType != null)
|
||||||
|
{
|
||||||
|
<DynamicComponent Type="@ModuleType" Parameters="@ModuleParameters"></DynamicComponent>
|
||||||
|
@if (_progressIndicator)
|
||||||
|
{
|
||||||
|
<div class="app-progress-indicator"></div>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</ChildContent>
|
||||||
|
</ErrorBoundary>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private string _message;
|
private string _message;
|
||||||
private MessageType _messagetype;
|
private MessageType _messageType;
|
||||||
private bool _progressindicator = false;
|
private bool _progressIndicator = false;
|
||||||
|
|
||||||
|
private Type ModuleType { get; set; }
|
||||||
|
private IDictionary<string, object> ModuleParameters { get; set; }
|
||||||
|
|
||||||
[CascadingParameter]
|
[CascadingParameter]
|
||||||
protected PageState PageState { get; set; }
|
protected PageState PageState { get; set; }
|
||||||
@ -26,53 +39,54 @@
|
|||||||
protected override void OnParametersSet()
|
protected override void OnParametersSet()
|
||||||
{
|
{
|
||||||
_message = "";
|
_message = "";
|
||||||
|
if (!string.IsNullOrEmpty(ModuleState.ModuleType))
|
||||||
DynamicComponent = builder =>
|
|
||||||
{
|
{
|
||||||
Type moduleType = null;
|
ModuleType = Type.GetType(ModuleState.ModuleType);
|
||||||
if (!string.IsNullOrEmpty(ModuleState.ModuleType))
|
if (ModuleType != null)
|
||||||
{
|
{
|
||||||
moduleType = Type.GetType(ModuleState.ModuleType);
|
ModuleParameters = new Dictionary<string, object> { { "ModuleInstance", this } };
|
||||||
|
return;
|
||||||
if (moduleType != null)
|
|
||||||
{
|
|
||||||
builder.OpenComponent(0, moduleType);
|
|
||||||
builder.AddAttribute(1, "ModuleInstance", this);
|
|
||||||
builder.CloseComponent();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// module does not exist with typename specified
|
|
||||||
_message = string.Format(Localizer["Error.Module.InvalidName"], Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0));
|
|
||||||
_messagetype = MessageType.Error;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
// module does not exist with typename specified
|
||||||
{
|
_message = string.Format(Localizer["Error.Module.InvalidName"], Utilities.GetTypeNameLastSegment(ModuleState.ModuleType, 0));
|
||||||
_message = string.Format(Localizer["Error.Module.InvalidType"], ModuleState.ModuleDefinitionName);
|
_messageType = MessageType.Error;
|
||||||
_messagetype = MessageType.Error;
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
};
|
_message = string.Format(Localizer["Error.Module.InvalidType"], ModuleState.ModuleDefinitionName);
|
||||||
|
_messageType = MessageType.Error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddModuleMessage(string message, MessageType type)
|
public void AddModuleMessage(string message, MessageType type)
|
||||||
{
|
{
|
||||||
_message = message;
|
_message = message;
|
||||||
_messagetype = type;
|
_messageType = type;
|
||||||
_progressindicator = false;
|
_progressIndicator = false;
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowProgressIndicator()
|
public void ShowProgressIndicator()
|
||||||
{
|
{
|
||||||
_progressindicator = true;
|
_progressIndicator = true;
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HideProgressIndicator()
|
public void HideProgressIndicator()
|
||||||
{
|
{
|
||||||
_progressindicator = false;
|
_progressIndicator = false;
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private string ErrorMessage(Exception context)
|
||||||
|
{
|
||||||
|
var message = string.Format(Localizer["Error.Module.Exception"], ModuleState.ModuleDefinitionName);
|
||||||
|
if (UserSecurity.IsAuthorized(PageState.User, RoleNames.Host))
|
||||||
|
{
|
||||||
|
return $"{message}<br />{context}";
|
||||||
|
}
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user