Smart Filters & Dashboard Customization (#2282)

Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
This commit is contained in:
Joe Milazzo 2023-09-12 11:24:47 -07:00 committed by GitHub
parent 3d501c9532
commit 84f85b4f24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
92 changed files with 7149 additions and 555 deletions

View file

@ -6,6 +6,7 @@ using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using API.Constants;
using API.Data.Repositories;
using API.Entities;
using API.Entities.Enums;
using API.Entities.Enums.Theme;
@ -38,6 +39,43 @@ public static class Seed
}
}.ToArray());
public static readonly ImmutableArray<AppUserDashboardStream> DefaultStreams = ImmutableArray.Create(
new List<AppUserDashboardStream>
{
new()
{
Name = "On Deck",
StreamType = DashboardStreamType.OnDeck,
Order = 0,
IsProvided = true,
Visible = true
},
new()
{
Name = "Recently Updated",
StreamType = DashboardStreamType.RecentlyUpdated,
Order = 1,
IsProvided = true,
Visible = true
},
new()
{
Name = "Newly Added",
StreamType = DashboardStreamType.NewlyAdded,
Order = 2,
IsProvided = true,
Visible = true
},
new()
{
Name = "More In",
StreamType = DashboardStreamType.MoreInGenre,
Order = 3,
IsProvided = true,
Visible = false
},
}.ToArray());
public static async Task SeedRoles(RoleManager<AppRole> roleManager)
{
var roles = typeof(PolicyConstants)
@ -74,6 +112,31 @@ public static class Seed
await context.SaveChangesAsync();
}
public static async Task SeedDefaultStreams(IUnitOfWork unitOfWork)
{
var allUsers = await unitOfWork.UserRepository.GetAllUsersAsync(AppUserIncludes.DashboardStreams);
foreach (var user in allUsers)
{
if (user.DashboardStreams.Count != 0) continue;
user.DashboardStreams ??= new List<AppUserDashboardStream>();
foreach (var defaultStream in DefaultStreams)
{
var newStream = new AppUserDashboardStream
{
Name = defaultStream.Name,
IsProvided = defaultStream.IsProvided,
Order = defaultStream.Order,
StreamType = defaultStream.StreamType,
Visible = defaultStream.Visible,
};
user.DashboardStreams.Add(newStream);
}
unitOfWork.UserRepository.Update(user);
await unitOfWork.CommitAsync();
}
}
public static async Task SeedSettings(DataContext context, IDirectoryService directoryService)
{
await context.Database.EnsureCreatedAsync();