Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

app: notification list view #204

Merged
merged 87 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
e4df6b7
First implémentation of historic
Theodrosrun Aug 14, 2024
01bc4ce
Cleaning history
Theodrosrun Aug 14, 2024
8538550
Modifying to english
Theodrosrun Aug 14, 2024
3674da6
Merge branch 'dev' into app-notification-list
Theodrosrun Aug 14, 2024
12942c7
Merge branch 'dev' into app-notification-list
Theodrosrun Aug 18, 2024
4f24350
Adding code to active
Theodrosrun Aug 19, 2024
98bf7aa
Splitting active and history
Theodrosrun Aug 19, 2024
67c2188
Removing method
Theodrosrun Aug 19, 2024
73f5717
Removing unused classes
Theodrosrun Aug 19, 2024
8506946
Adding use of mock
Theodrosrun Aug 19, 2024
f42a17a
Removing header
Theodrosrun Aug 19, 2024
e778ba3
Adding channel feature
Theodrosrun Aug 19, 2024
a8cd1b7
Comment
Theodrosrun Aug 19, 2024
df604de
Adding spacer
Theodrosrun Aug 19, 2024
479e9b3
Adding margin
Theodrosrun Aug 19, 2024
25adff1
Adding dialog
Theodrosrun Aug 19, 2024
2afb3ca
Adding margin
Theodrosrun Aug 19, 2024
48f81b8
Factoring parameters
Theodrosrun Aug 19, 2024
0128f38
Removing methods
Theodrosrun Aug 19, 2024
1391fea
Adding configuration
Theodrosrun Aug 20, 2024
0209362
Merge branch 'dev' into app-notification-list
Theodrosrun Aug 20, 2024
4df98a4
Changing table to list
Theodrosrun Aug 20, 2024
41a2f19
Correcting item
Theodrosrun Aug 20, 2024
a1738f8
Harmonizing use
Theodrosrun Aug 20, 2024
fa8a07a
Renaming
Theodrosrun Aug 20, 2024
b06d943
Removing unsued CSS
Theodrosrun Aug 20, 2024
ed3b5ca
Adding serach options for notifiers
Theodrosrun Aug 20, 2024
bd44695
Renmaing
Theodrosrun Aug 20, 2024
bb060b7
Renaming
Theodrosrun Aug 20, 2024
2b1baca
Removing uncessary css style
Theodrosrun Aug 20, 2024
bf698b1
Renaming
Theodrosrun Aug 20, 2024
b670f70
Removing duplication
Theodrosrun Aug 20, 2024
55c9d34
Changing parameter type
Theodrosrun Aug 20, 2024
33aab02
Renaming
Theodrosrun Aug 20, 2024
2bad028
Adding confirmation pop when item is deleted
Theodrosrun Aug 20, 2024
69d3b36
Renaming
Theodrosrun Aug 20, 2024
caadc34
Changing color
Theodrosrun Aug 20, 2024
87c1d47
Splitting view
Theodrosrun Aug 20, 2024
972fed7
Renaming
Theodrosrun Aug 20, 2024
319e315
Removing space
Theodrosrun Aug 20, 2024
2701759
Renaming
Theodrosrun Aug 20, 2024
7005956
Using NotificationService
Theodrosrun Aug 20, 2024
8282946
Removing comment
Theodrosrun Aug 21, 2024
89b95a6
Adding use of notifier service in notfier editor
Theodrosrun Aug 21, 2024
c172e84
Rollback changes
Theodrosrun Aug 21, 2024
203e1c0
Adding role states
Theodrosrun Aug 21, 2024
9ca9576
Adding channel name
Theodrosrun Aug 21, 2024
8de29e1
Renaming
Theodrosrun Aug 21, 2024
407f0ea
Simplifying condition
Theodrosrun Aug 21, 2024
9f3eed1
Renaming
Theodrosrun Aug 21, 2024
c10788e
Comment
Theodrosrun Aug 21, 2024
63b30b0
Merge dev
Theodrosrun Aug 25, 2024
849867e
Correcting methods
Theodrosrun Aug 25, 2024
dca506b
Correcting roles
Theodrosrun Aug 25, 2024
add0c9a
Removing ternary condition
Theodrosrun Aug 25, 2024
72d9344
Merge branch 'dev' into app-notification-list
Theodrosrun Aug 25, 2024
bef12c1
Removing type
Theodrosrun Aug 25, 2024
cfb7da7
Merge branch 'dev' into app-notification-list
Theodrosrun Aug 26, 2024
548f4eb
Using channel GUID
Theodrosrun Aug 26, 2024
4b5ce3f
Adding switch
Theodrosrun Aug 26, 2024
59fcf93
Renaming
Theodrosrun Aug 26, 2024
999527a
Adding explicit type
Theodrosrun Aug 26, 2024
b0f3e32
Adding unmapping
Theodrosrun Aug 26, 2024
e53c21d
Simplify condition
Theodrosrun Aug 26, 2024
9ca1e2a
Simplify condition
Theodrosrun Aug 26, 2024
e49ef10
Removing space
Theodrosrun Aug 26, 2024
9feb960
Comment
Theodrosrun Aug 26, 2024
07a3a25
Removing reset
Theodrosrun Aug 26, 2024
193e0b9
Adding badge
Theodrosrun Aug 26, 2024
18aba87
Adding button
Theodrosrun Aug 26, 2024
7f5249b
Comment
Theodrosrun Aug 26, 2024
41ca270
Adding mock
Theodrosrun Aug 26, 2024
6b2e34a
Adding list
Theodrosrun Aug 26, 2024
12e429d
Addin badge
Theodrosrun Aug 26, 2024
d5a8a64
Typo
Theodrosrun Aug 26, 2024
15375da
Update service
Theodrosrun Aug 26, 2024
ea9c498
Adding counter
Theodrosrun Aug 26, 2024
ea8d6b3
Adding service
Theodrosrun Aug 26, 2024
4ea19bd
Removing useless method
Theodrosrun Aug 26, 2024
b8a54c3
Cleaning code
Theodrosrun Aug 26, 2024
d3096bd
Moving service
Theodrosrun Aug 26, 2024
562e468
Renaming
Theodrosrun Aug 27, 2024
350ac43
Moving mock
Theodrosrun Aug 27, 2024
6835783
Send notif via all notifiers
Theodrosrun Aug 27, 2024
ced56fa
Adding counter saving
Theodrosrun Aug 27, 2024
41e884b
Removing ugly condition
Theodrosrun Aug 27, 2024
dd76246
Adding == true
Theodrosrun Aug 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions src/App/LionkApp/Components/Layout/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
@using Lionk.Auth.Identity
@using Lionk.Notification
@using Microsoft.AspNetCore.Components.Authorization
@inherits LayoutComponentBase
@inject NavigationManager NavManager
@inject NotificationStateService NotificationState
@inject UserAuthenticationStateProvider AuthStateProvider
@inject LionkPalette Theme

<AuthorizeView>
<MudThemeProvider Theme="@_theme" IsDarkMode="_isDarkMode" />
<MudPopoverProvider />
Expand All @@ -15,7 +18,9 @@
<MudIconButton Icon="@Icons.Material.Filled.Menu" Color="Color.Inherit" Edge="Edge.Start" OnClick="@((MouseEventArgs e) => DrawerToggle())" />
<MudText Typo="Typo.h5" Class="ml-3">Lionk</MudText>
<MudSpacer />
<MudIconButton Icon="@Icons.Material.Filled.CircleNotifications" Color="Color.Primary" OnClick="OnNotificationPressed" />
<MudBadge Origin=Origin.CenterLeft Content="@NotificationState.BadgeCounter" Color="Color.Primary">
<MudIconButton Icon="@Icons.Material.Filled.CircleNotifications" Color="Color.Primary" OnClick="OnNotificationPressed" />
</MudBadge>
<MudIconButton Icon="@(DarkLightModeButtonIcon)" Color="Color.Inherit" OnClick="@DarkModeToggle" />
</MudAppBar>
<MudDrawer @bind-Open="_isDrawerOpen" ClipMode="DrawerClipMode.Always" Elevation="2">
Expand Down Expand Up @@ -87,6 +92,15 @@
base.OnInitialized();
UserName = AuthStateProvider.CurrentUser?.Username ?? "Not Logged In";
_theme = new MudTheme { PaletteLight = Theme.LightPalette, PaletteDark = Theme.DarkPalette, LayoutProperties = new LayoutProperties() };
NotificationState.BadgeCounter = NotificationService.GetUnreadNotificationCount();
NotificationState.OnNotificationReceived += IncrementBadgeCounter;
NotificationState.OnBadgeCounterChanged += StateHasChanged;
}

public void Dispose()
{
NotificationState.OnNotificationReceived -= IncrementBadgeCounter;
NotificationState.OnBadgeCounterChanged -= StateHasChanged;
}

private void DarkModeToggle()
Expand Down Expand Up @@ -116,6 +130,11 @@
NavManager.NavigateTo("/auth");
}

private void IncrementBadgeCounter()
{
NotificationState.IncrementBadgeCounter();
}

/// <summary>
/// Switches the dark mode.
/// </summary>
Expand All @@ -125,5 +144,4 @@
true => Icons.Material.Rounded.LightMode,
false => Icons.Material.Outlined.DarkMode,
};

}
23 changes: 0 additions & 23 deletions src/App/LionkApp/Components/Model/Switch.cs

This file was deleted.

71 changes: 32 additions & 39 deletions src/App/LionkApp/Components/Pages/Notification/Active.razor
Original file line number Diff line number Diff line change
@@ -1,31 +1,27 @@
@page "/active"
@using Lionk.Notification
@inject NotificationStateService NotificationState

@if (_forecasts == null)
@if (notifications != null)
{
<MudProgressCircular Color="Color.Default" Indeterminate="true"/>
}
else
{
<MudTable Items="_forecasts" Hover="true" SortLabel="Sort By" Elevation="0" AllowUnsorted="false">
<MudTable Items="notifications" Hover="true" SortLabel="Sort by" Elevation="0" AllowUnsorted="false">
<HeaderContent>
<MudTh>
<MudTableSortLabel InitialDirection="SortDirection.Ascending" SortBy="new Func<WeatherForecast, object>(x => x.Date)">Date</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x => x.TemperatureC)">Temp. (C)</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x => x.TemperatureF)">Temp. (F)</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x => x.Summary!)">Summary</MudTableSortLabel>
</MudTh>
<MudTh><MudTableSortLabel InitialDirection="SortDirection.Ascending" SortBy="new Func<NotificationHistory, object>(x => x.Notification.Timestamp)">Date</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<NotificationHistory, object>(x => x.Notification.Content.Level)">Severity</MudTableSortLabel></MudTh>
<MudTh>Title</MudTh>
<MudTh>Message</MudTh>
<MudTh>Status</MudTh>
<MudTh style="text-align: center;">Actions</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Date">@context.Date</MudTd>
<MudTd DataLabel="Temp. (C)">@context.TemperatureC</MudTd>
<MudTd DataLabel="Temp. (F)">@context.TemperatureF</MudTd>
<MudTd DataLabel="Summary">@context.Summary</MudTd>
<MudTd DataLabel="Date">@context.Notification.Timestamp.ToString("g")</MudTd>
<MudTd DataLabel="Severity">@context.Notification.Content.Level.ToString()</MudTd>
<MudTd DataLabel="Title">@context.Notification.Content.Title</MudTd>
<MudTd DataLabel="Message">@context.Notification.Content.Message</MudTd>
<MudTd DataLabel="Status">Unread</MudTd>
<MudTd style="text-align: center; vertical-align: middle;">
<MudButton Color="Color.Primary" Variant="Variant.Filled" OnClick="@(() => MarkAsRead(@context))">Mark as read</MudButton>
</MudTd>
</RowTemplate>
<PagerContent>
<MudTablePager PageSizeOptions="new[] { 50, 100 }"/>
Expand All @@ -34,28 +30,25 @@ else
}

@code {
private WeatherForecast[]? _forecasts;
List<NotificationHistory>? notifications;

/// <inheritdoc />
protected override async Task OnInitializedAsync()
protected override void OnInitialized()
{
// Simulate asynchronous loading to demonstrate a loading indicator
await Task.Delay(500);

var startDate = DateOnly.FromDateTime(DateTime.Now);
string[] summaries = ["Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"];
_forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = startDate.AddDays(index), TemperatureC = Random.Shared.Next(-20, 55), Summary = summaries[Random.Shared.Next(summaries.Length)] }).ToArray();
LoadUnreadNotifications();
}

private class WeatherForecast
private void LoadUnreadNotifications()
{
public DateOnly Date { get; init; }

public int TemperatureC { get; init; }

public string? Summary { get; init; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
notifications = NotificationService.GetNotifications()
.Where(n => !n.IsRead)
.ToList();
}

private void MarkAsRead(NotificationHistory notification)
{
notification.Read();
NotificationState.DecrementBadgeCounter();
LoadUnreadNotifications();
StateHasChanged();
}
}
78 changes: 70 additions & 8 deletions src/App/LionkApp/Components/Pages/Notification/Configuration.razor
Original file line number Diff line number Diff line change
@@ -1,14 +1,76 @@
@page "/configuration"
@using LionkApp.Components.Model
@using LionkApp.Components.Widgets.Content
@inject IDialogService DialogService
@implements IDisposable
@using LionkApp.Components.Widgets.Content.Notification
@using LionkApp.Components.Widgets.Dialogs
@using Lionk.Notification
@using System.Collections.ObjectModel
@using LionkTest.Notifications.Mock
@using Newtonsoft.Json

<SwitchList SwitchListTitle="Notifier list" Switches="_notifierList"/>

<SwitchList SwitchListTitle="Channel list" Switches="_channelList"/>
<NotifierList/>
<ChannelList/>
<MudButton Variant=Variant.Filled Color=Color.Primary OnClick="SendTestNotification">
Send test notification
</MudButton>

@code {
private readonly List<Switch> _notifierList = [new Switch { Label = "Chimpey", IsEnabled = true }, new Switch { Label = "Nastaran", IsEnabled = true }, new Switch { Label = "Ronflex", IsEnabled = true }];

private readonly List<Switch> _channelList = [new Switch { Label = "Discord", IsEnabled = true }, new Switch { Label = "Telegram", IsEnabled = true }, new Switch { Label = "Push", IsEnabled = true }];
// TODO - Remove mock in LionkApp\Components\Pages\Notification\Mock when ready

private List<INotifier> MockNotifiers = new List<INotifier>
{
new MockNotifier(Guid.NewGuid(), "Chimpey"),
new MockNotifier(Guid.NewGuid(), "Clock alarm"),
new MockNotifier(Guid.NewGuid(), "MX321")
};

private List<IChannel> MockChannels = new List<IChannel>
{
new MockChannel(Guid.NewGuid(), "Discord", new List<IRecipient>(), true),
new MockChannel(Guid.NewGuid(), "Telegram", new List<IRecipient>(), false),
new MockChannel(Guid.NewGuid(), "Push bullet", new List<IRecipient>(), true)
};

public ReadOnlyCollection<INotifier> Notifiers { get; set; } = new List<INotifier>().AsReadOnly();

public ReadOnlyCollection<IChannel> Channels { get; set; } = new List<IChannel>().AsReadOnly();

protected override void OnInitialized()
{
base.OnInitialized();

NotificationService.AddNotifiers(MockNotifiers[0], MockNotifiers[1], MockNotifiers[2]);
NotificationService.AddChannels(MockChannels[0], MockChannels[1], MockChannels[2]);
NotificationService.MapNotifierToChannel(MockNotifiers[0], MockChannels[0], MockChannels[1]);
NotificationService.MapNotifierToChannel(MockNotifiers[1], MockChannels[1], MockChannels[2]);
NotificationService.MapNotifierToChannel(MockNotifiers[2], MockChannels[2], MockChannels[0]);

Notifiers = NotificationService.Notifiers;
Channels = NotificationService.Channels;
}

private void SendTestNotification()
{
Content content = new(Lionk.Notification.Severity.Information, "Test Notification", "This is a test notification.");

foreach (INotifier notifier in MockNotifiers)
{
Notification notification = new(content, notifier);
NotificationService.Send(notification);
}
}

public void Dispose()
{
foreach (var notifier in Notifiers.ToList())
{
NotificationService.RemoveNotifier(notifier);
}

}
foreach (var channel in Channels.ToList())
{
NotificationService.RemoveChannel(channel);
}
}
}
59 changes: 15 additions & 44 deletions src/App/LionkApp/Components/Pages/Notification/History.razor
Original file line number Diff line number Diff line change
@@ -1,61 +1,32 @@
@page "/history"
@using Lionk.Notification

@if (forecasts == null)
@if (notifications != null)
{
<MudProgressCircular Color="Color.Default" Indeterminate="true"/>
}
else
{
<MudTable Items="forecasts" Hover="true" SortLabel="Sort By" Elevation="0" AllowUnsorted="false">
<MudTable Items="notifications" Hover="true" SortLabel="Sort by" Elevation="0" AllowUnsorted="false">
<HeaderContent>
<MudTh>
<MudTableSortLabel InitialDirection="SortDirection.Ascending" SortBy="new Func<WeatherForecast, object>(x => x.Date)">Date</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x => x.TemperatureC)">Temp. (C)</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x => x.TemperatureF)">Temp. (F)</MudTableSortLabel>
</MudTh>
<MudTh>
<MudTableSortLabel SortBy="new Func<WeatherForecast, object>(x => x.Summary!)">Summary</MudTableSortLabel>
</MudTh>
<MudTh><MudTableSortLabel InitialDirection="SortDirection.Ascending" SortBy="new Func<NotificationHistory, object>(x => x.Notification.Timestamp)">Date</MudTableSortLabel></MudTh>
<MudTh><MudTableSortLabel SortBy="new Func<NotificationHistory, object>(x => x.Notification.Content.Level)">Severity</MudTableSortLabel></MudTh>
<MudTh>Title</MudTh>
<MudTh>Message</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Date">@context.Date</MudTd>
<MudTd DataLabel="Temp. (C)">@context.TemperatureC</MudTd>
<MudTd DataLabel="Temp. (F)">@context.TemperatureF</MudTd>
<MudTd DataLabel="Summary">@context.Summary</MudTd>
<MudTd DataLabel="Date">@context.Notification.Timestamp.ToString("g")</MudTd>
<MudTd DataLabel="Severity">@context.Notification.Content.Level.ToString()</MudTd>
<MudTd DataLabel="Title">@context.Notification.Content.Title</MudTd>
<MudTd DataLabel="Message">@context.Notification.Content.Message</MudTd>
</RowTemplate>
<PagerContent>
<MudTablePager PageSizeOptions="new[] { 50, 100 }"/>
<MudTablePager PageSizeOptions="new int[]{50, 100}" />
</PagerContent>
</MudTable>
}

@code {
private WeatherForecast[]? forecasts;

/// <inheritdoc />
protected override async Task OnInitializedAsync()
{
// Simulate asynchronous loading to demonstrate a loading indicator
await Task.Delay(500);

var startDate = DateOnly.FromDateTime(DateTime.Now);
string[] summaries = ["Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"];
forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = startDate.AddDays(index), TemperatureC = Random.Shared.Next(-20, 55), Summary = summaries[Random.Shared.Next(summaries.Length)] }).ToArray();
}
List<NotificationHistory>? notifications;

private class WeatherForecast
protected override void OnInitialized()
{
public DateOnly Date { get; init; }

public int TemperatureC { get; init; }

public string? Summary { get; init; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
notifications = NotificationService.GetNotifications();
}

}
Loading
Loading