Add user-specific persistent grid/band layouts support
Implemented user-customizable, persistent grid and band layouts for CatalogsGrid and MassDataGrid. Added backend API, database entity, and repository for storing layouts per user. Refactored grids to support dynamic band/column rendering, layout management UI, and per-user storage via localStorage and the new API. Registered all necessary services and updated data context. Enables flexible, user-specific grid experiences with saved layouts.
This commit is contained in:
@@ -15,6 +15,7 @@ public partial class ApplicationDbContext : DbContext
|
||||
}
|
||||
|
||||
public virtual DbSet<VwmyCatalog> VwmyCatalogs { get; set; }
|
||||
public virtual DbSet<SmfLayout> SmfLayouts { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
@@ -51,6 +52,37 @@ public partial class ApplicationDbContext : DbContext
|
||||
.HasColumnName(catCfg.ChangedWhoColumnName);
|
||||
});
|
||||
|
||||
modelBuilder.Entity<SmfLayout>(entity =>
|
||||
{
|
||||
entity.HasKey(e => e.Guid);
|
||||
entity.ToTable("TBDD_SMF_LAYOUT", tb => tb.HasTrigger("TBDD_SMF_LAYOUT_AFT_UPD"));
|
||||
|
||||
entity.Property(e => e.Guid).HasColumnName("GUID");
|
||||
entity.Property(e => e.Active).HasColumnName("ACTIVE");
|
||||
entity.Property(e => e.LayoutType)
|
||||
.HasMaxLength(50)
|
||||
.HasColumnName("LAYOUT_TYPE");
|
||||
entity.Property(e => e.LayoutKey)
|
||||
.HasMaxLength(150)
|
||||
.HasColumnName("LAYOUT_KEY");
|
||||
entity.Property(e => e.UserName)
|
||||
.HasMaxLength(50)
|
||||
.HasColumnName("USER_NAME");
|
||||
entity.Property(e => e.LayoutData).HasColumnName("LAYOUT_DATA");
|
||||
entity.Property(e => e.AddedWho)
|
||||
.HasMaxLength(50)
|
||||
.HasColumnName("ADDED_WHO");
|
||||
entity.Property(e => e.AddedWhen)
|
||||
.HasColumnType("datetime")
|
||||
.HasColumnName("ADDED_WHEN");
|
||||
entity.Property(e => e.ChangedWho)
|
||||
.HasMaxLength(50)
|
||||
.HasColumnName("CHANGED_WHO");
|
||||
entity.Property(e => e.ChangedWhen)
|
||||
.HasColumnType("datetime")
|
||||
.HasColumnName("CHANGED_WHEN");
|
||||
});
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
|
||||
66
DbFirst.Infrastructure/Repositories/LayoutRepository.cs
Normal file
66
DbFirst.Infrastructure/Repositories/LayoutRepository.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using DbFirst.Application.Repositories;
|
||||
using DbFirst.Domain.Entities;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DbFirst.Infrastructure.Repositories;
|
||||
|
||||
public class LayoutRepository : ILayoutRepository
|
||||
{
|
||||
private readonly ApplicationDbContext _db;
|
||||
|
||||
public LayoutRepository(ApplicationDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public async Task<SmfLayout?> GetAsync(string layoutType, string layoutKey, string userName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return await _db.SmfLayouts.AsNoTracking()
|
||||
.FirstOrDefaultAsync(x => x.LayoutType == layoutType && x.LayoutKey == layoutKey && x.UserName == userName, cancellationToken);
|
||||
}
|
||||
|
||||
public async Task<SmfLayout> UpsertAsync(string layoutType, string layoutKey, string userName, byte[] layoutData, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _db.SmfLayouts
|
||||
.FirstOrDefaultAsync(x => x.LayoutType == layoutType && x.LayoutKey == layoutKey && x.UserName == userName, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
entity = new SmfLayout
|
||||
{
|
||||
Active = true,
|
||||
LayoutType = layoutType,
|
||||
LayoutKey = layoutKey,
|
||||
UserName = userName,
|
||||
LayoutData = layoutData,
|
||||
AddedWho = userName,
|
||||
AddedWhen = DateTime.Now
|
||||
};
|
||||
_db.SmfLayouts.Add(entity);
|
||||
}
|
||||
else
|
||||
{
|
||||
entity.Active = true;
|
||||
entity.LayoutData = layoutData;
|
||||
entity.ChangedWho = userName;
|
||||
}
|
||||
|
||||
await _db.SaveChangesAsync(cancellationToken);
|
||||
return entity;
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteAsync(string layoutType, string layoutKey, string userName, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var entity = await _db.SmfLayouts
|
||||
.FirstOrDefaultAsync(x => x.LayoutType == layoutType && x.LayoutKey == layoutKey && x.UserName == userName, cancellationToken);
|
||||
|
||||
if (entity == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_db.SmfLayouts.Remove(entity);
|
||||
await _db.SaveChangesAsync(cancellationToken);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user