diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Alert/AbpAlertTagHelper.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Alert/AbpAlertTagHelper.cs index 0d825b0102..f4d0c33ced 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Alert/AbpAlertTagHelper.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Alert/AbpAlertTagHelper.cs @@ -1,8 +1,10 @@ -namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Alert +using Volo.Abp.AspNetCore.Mvc.UI.Alerts; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Alert { public class AbpAlertTagHelper : AbpTagHelper { - public AbpAlertType AlertType { get; set; } = AbpAlertType.Default; + public AlertType AlertType { get; set; } = AlertType.Default; public bool? Dismissible { get; set; } diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Alert/AbpAlertTagHelperService.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Alert/AbpAlertTagHelperService.cs index de0e811898..769bd1aee5 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Alert/AbpAlertTagHelperService.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Alert/AbpAlertTagHelperService.cs @@ -1,5 +1,6 @@ using System; using Microsoft.AspNetCore.Razor.TagHelpers; +using Volo.Abp.AspNetCore.Mvc.UI.Alerts; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers; namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Alert @@ -20,7 +21,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Alert output.Attributes.Add("role", "alert"); output.Attributes.AddClass("alert"); - if (TagHelper.AlertType != AbpAlertType.Default) + if (TagHelper.AlertType != AlertType.Default) { output.Attributes.AddClass("alert-" + TagHelper.AlertType.ToString().ToLowerInvariant()); } diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/Menu/AbpMenuViewComponent.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/Menu/MainNavbarMenuViewComponent.cs similarity index 100% rename from src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/Menu/AbpMenuViewComponent.cs rename to src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/Menu/MainNavbarMenuViewComponent.cs diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/PageAlerts/Default.cshtml b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/PageAlerts/Default.cshtml new file mode 100644 index 0000000000..fa40f77f14 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/PageAlerts/Default.cshtml @@ -0,0 +1,16 @@ +@model Volo.Abp.AspNetCore.Mvc.UI.Alerts.AlertList +@if (Model.Any()) +{ +
+ @foreach (var alertMessage in Model) + { + + @if (alertMessage.Title != null) + { +

@alertMessage.Title

+ } + @alertMessage.Text +
+ } +
+} \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/PageAlerts/PageAlertsViewComponent.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/PageAlerts/PageAlertsViewComponent.cs new file mode 100644 index 0000000000..c805f20e69 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Components/PageAlerts/PageAlertsViewComponent.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc.UI.Alerts; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Themes.Basic.Components.PageAlerts +{ + public class PageAlertsViewComponent : AbpViewComponent + { + private readonly IAlertManager _alertManager; + + public PageAlertsViewComponent(IAlertManager alertManager) + { + _alertManager = alertManager; + } + + public IViewComponentResult Invoke(string name) + { + return View("~/Themes/Basic/Components/PageAlerts/Default.cshtml", _alertManager.Alerts); + } + } +} diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Application.cshtml b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Application.cshtml index 35792db645..3007b7deec 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Application.cshtml +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Application.cshtml @@ -1,5 +1,6 @@ @using Volo.Abp.AspNetCore.Mvc.AntiForgery @using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Themes.Basic.Components.MainNavbar +@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Themes.Basic.Components.PageAlerts @inject IAbpAntiForgeryManager AbpAntiForgeryManager @{ Layout = null; @@ -25,7 +26,9 @@ @(await Component.InvokeAsync()) -
@* TODO: Create option to select 'container' or 'container-fluid' *@ +
+ @* TODO: Create option to select 'container' or 'container-fluid' *@ + @(await Component.InvokeAsync()) @RenderBody()
diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml index 3ad8a1462d..8d8b4ee4b7 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic/Themes/Basic/Layouts/Empty.cshtml @@ -1,5 +1,6 @@ @using Volo.Abp.AspNetCore.Mvc.AntiForgery @using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Themes.Basic.Components.MainNavbar +@using Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic.Themes.Basic.Components.PageAlerts @inject IAbpAntiForgeryManager AbpAntiForgeryManager @{ Layout = null; @@ -24,6 +25,7 @@
+ @(await Component.InvokeAsync()) @RenderBody()
diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/AbpPageModel.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/RazorPages/AbpPageModel.cs similarity index 93% rename from src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/AbpPageModel.cs rename to src/Volo.Abp.AspNetCore.Mvc.UI/RazorPages/AbpPageModel.cs index 0467bb8841..0c04daed5e 100644 --- a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/AbpPageModel.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/RazorPages/AbpPageModel.cs @@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc.RazorPages; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; +using Volo.Abp.AspNetCore.Mvc.UI.Alerts; using Volo.Abp.AspNetCore.Mvc.Validation; using Volo.Abp.Guids; using Volo.Abp.MultiTenancy; @@ -34,6 +35,10 @@ namespace Volo.Abp.AspNetCore.Mvc.RazorPages public IAuthorizationService AuthorizationService { get; set; } + public IAlertManager AlertManager { get; set; } + + public AlertList Alerts => AlertManager.Alerts; + protected IUnitOfWork CurrentUnitOfWork => UnitOfWorkManager?.Current; public IClock Clock { get; set; } diff --git a/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/ServiceBasedPageModelActivatorProvider.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/RazorPages/ServiceBasedPageModelActivatorProvider.cs similarity index 100% rename from src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/RazorPages/ServiceBasedPageModelActivatorProvider.cs rename to src/Volo.Abp.AspNetCore.Mvc.UI/RazorPages/ServiceBasedPageModelActivatorProvider.cs diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/AlertList.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/AlertList.cs new file mode 100644 index 0000000000..b3b4e1bd8d --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/AlertList.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Alerts +{ + public class AlertList : List + { + public void Add(AlertType type, string text, string title = null, bool dismissible = true) + { + Add(new AlertMessage(type, text, title, dismissible)); + } + + public void Info(string text, string title = null, bool dismissible = true) + { + Add(new AlertMessage(AlertType.Info, text, title, dismissible)); + } + + public void Warning(string text, string title = null, bool dismissible = true) + { + Add(new AlertMessage(AlertType.Warning, text, title, dismissible)); + } + + public void Danger(string text, string title = null, bool dismissible = true) + { + Add(new AlertMessage(AlertType.Danger, text, title, dismissible)); + } + + public void Success(string text, string title = null, bool dismissible = true) + { + Add(new AlertMessage(AlertType.Success, text, title, dismissible)); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/AlertManager.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/AlertManager.cs new file mode 100644 index 0000000000..1a0b993467 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/AlertManager.cs @@ -0,0 +1,14 @@ +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Alerts +{ + public class AlertManager : IAlertManager, IScopedDependency + { + public AlertList Alerts { get; } + + public AlertManager() + { + Alerts = new AlertList(); + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/AlertMessage.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/AlertMessage.cs new file mode 100644 index 0000000000..e484861814 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/AlertMessage.cs @@ -0,0 +1,30 @@ +using JetBrains.Annotations; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Alerts +{ + public class AlertMessage + { + [NotNull] + public string Text + { + get => _text; + set => _text = Check.NotNullOrWhiteSpace(value, nameof(value)); + } + private string _text; + + public AlertType Type { get; set; } + + [CanBeNull] + public string Title { get; set; } + + public bool Dismissible { get; set; } + + public AlertMessage(AlertType type, [NotNull] string text, string title = null, bool dismissible = true) + { + Type = type; + Text = Check.NotNullOrWhiteSpace(text, nameof(text)); + Title = title; + Dismissible = dismissible; + } + } +} \ No newline at end of file diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Alert/AbpAlertType.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/AlertType.cs similarity index 62% rename from src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Alert/AbpAlertType.cs rename to src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/AlertType.cs index f077dc27c4..a9b9ac7b1d 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Alert/AbpAlertType.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/AlertType.cs @@ -1,6 +1,6 @@ -namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Alert +namespace Volo.Abp.AspNetCore.Mvc.UI.Alerts { - public enum AbpAlertType + public enum AlertType { Default, Primary, diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/IAlertManager.cs b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/IAlertManager.cs new file mode 100644 index 0000000000..dbc4d0a3a8 --- /dev/null +++ b/src/Volo.Abp.AspNetCore.Mvc.UI/UI/Alerts/IAlertManager.cs @@ -0,0 +1,7 @@ +namespace Volo.Abp.AspNetCore.Mvc.UI.Alerts +{ + public interface IAlertManager + { + AlertList Alerts { get; } + } +}