Browse Source

page alerts implementation.

pull/5889/head
İlkay İlknur 5 years ago
parent
commit
30fdfb882f
  1. 1
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/MainLayout.razor
  2. 32
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Alerts/AlertList.cs
  3. 14
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Alerts/AlertManager.cs
  4. 30
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Alerts/AlertMessage.cs
  5. 15
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Alerts/AlertType.cs
  6. 7
      framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Alerts/IAlertManager.cs
  7. 10
      framework/src/Volo.Abp.BlazoriseUI/Components/AlertWrapper.cs
  8. 16
      framework/src/Volo.Abp.BlazoriseUI/Components/PageAlert.razor
  9. 83
      framework/src/Volo.Abp.BlazoriseUI/Components/PageAlert.razor.cs

1
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/MainLayout.razor

@ -18,6 +18,7 @@
</div>
</nav>
<div class="container">
<PageAlert />
@Body
<UiMessageAlert />

32
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Alerts/AlertList.cs

@ -0,0 +1,32 @@
using System.Collections.ObjectModel;
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Alerts
{
public class AlertList : ObservableCollection<AlertMessage>
{
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));
}
}
}

14
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Alerts/AlertManager.cs

@ -0,0 +1,14 @@
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Alerts
{
public class AlertManager : IAlertManager, IScopedDependency
{
public AlertList Alerts { get; }
public AlertManager()
{
Alerts = new AlertList();
}
}
}

30
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Alerts/AlertMessage.cs

@ -0,0 +1,30 @@
using JetBrains.Annotations;
namespace Volo.Abp.AspNetCore.Components.WebAssembly.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;
}
}
}

15
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Alerts/AlertType.cs

@ -0,0 +1,15 @@
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Alerts
{
public enum AlertType
{
Default,
Primary,
Secondary,
Success,
Danger,
Warning,
Info,
Light,
Dark
}
}

7
framework/src/Volo.Abp.AspNetCore.Components.WebAssembly/Volo/Abp/AspNetCore/Components/WebAssembly/Alerts/IAlertManager.cs

@ -0,0 +1,7 @@
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Alerts
{
public interface IAlertManager
{
AlertList Alerts { get; }
}
}

10
framework/src/Volo.Abp.BlazoriseUI/Components/AlertWrapper.cs

@ -0,0 +1,10 @@
using Volo.Abp.AspNetCore.Components.WebAssembly.Alerts;
namespace Volo.Abp.BlazoriseUI.Components
{
internal class AlertWrapper
{
public AlertMessage AlertMessage { get; set; }
public bool IsVisible { get; set; }
}
}

16
framework/src/Volo.Abp.BlazoriseUI/Components/PageAlert.razor

@ -0,0 +1,16 @@
@foreach (var alert in Alerts)
{
<Alert Visible="@alert.IsVisible" Dismisable="@alert.AlertMessage.Dismissible" Color="@GetAlertColor(alert.AlertMessage.Type)">
@if (!string.IsNullOrEmpty(alert.AlertMessage.Title))
{
<Heading Size="HeadingSize.Is4" Class="alert-heading">
@alert.AlertMessage.Title
@if (alert.AlertMessage.Dismissible)
{
<CloseButton Clicked="() => alert.IsVisible = false" />
}
</Heading>
}
<Paragraph>@alert.AlertMessage.Text</Paragraph>
</Alert>
}

83
framework/src/Volo.Abp.BlazoriseUI/Components/PageAlert.razor.cs

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using Blazorise;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Routing;
using Volo.Abp.AspNetCore.Components.WebAssembly.Alerts;
namespace Volo.Abp.BlazoriseUI.Components
{
public partial class PageAlert : ComponentBase, IDisposable
{
private List<AlertWrapper> Alerts = new List<AlertWrapper>();
[Inject]
protected IAlertManager AlertManager { get; set; }
[Inject]
protected NavigationManager NavigationManager { get; set; }
protected override void OnInitialized()
{
base.OnInitialized();
NavigationManager.LocationChanged += NavigationManager_LocationChanged;
AlertManager.Alerts.CollectionChanged += Alerts_CollectionChanged;
Alerts.AddRange(AlertManager.Alerts.Select(t => new AlertWrapper
{
AlertMessage = t,
IsVisible = true
}));
}
//Since Blazor WASM doesn't support scoped dependency, we need to clear alerts on each location changed event.
private void NavigationManager_LocationChanged(object sender, LocationChangedEventArgs e)
{
AlertManager.Alerts.Clear();
Alerts.Clear();
}
private void Alerts_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
foreach (var item in e.NewItems)
{
Alerts.Add(new AlertWrapper
{
AlertMessage = (AspNetCore.Components.WebAssembly.Alerts.AlertMessage)item,
IsVisible = true
});
}
}
StateHasChanged();
}
protected virtual Color GetAlertColor(AlertType alertType)
{
var color = alertType switch
{
AlertType.Info => Color.Info,
AlertType.Success => Color.Success,
AlertType.Warning => Color.Warning,
AlertType.Danger => Color.Danger,
AlertType.Dark => Color.Dark,
AlertType.Default => Color.None,
AlertType.Light => Color.Light,
AlertType.Primary => Color.Primary,
AlertType.Secondary => Color.Secondary,
_ => Color.None,
};
return color;
}
public void Dispose()
{
NavigationManager.LocationChanged -= NavigationManager_LocationChanged;
AlertManager.Alerts.CollectionChanged -= Alerts_CollectionChanged;
}
}
}
Loading…
Cancel
Save