mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
add updated date to summary view
This commit is contained in:
parent
861e349b6b
commit
7189f2ead0
4 changed files with 60 additions and 20 deletions
|
|
@ -18,13 +18,40 @@ public FilterListService(FilterListsDbContext dbContext) : base(dbContext)
|
|||
}
|
||||
|
||||
public async Task<IEnumerable<ListSummaryDto>> GetAllSummariesAsync()
|
||||
{
|
||||
var summaries = await GetSummaryDtos();
|
||||
var latestUpdatedSnapshots = await GetLatestUpdatedSnapshots();
|
||||
return summaries.Join(latestUpdatedSnapshots, summary => summary.Id, snap => snap.FilterListId,
|
||||
(summary, snap) => new ListSummaryDto
|
||||
{
|
||||
Id = summary.Id,
|
||||
AddedDate = summary.AddedDate,
|
||||
Languages = summary.Languages,
|
||||
Name = summary.Name,
|
||||
UpdatedDate = snap.CreatedDateUtc,
|
||||
ViewUrl = summary.ViewUrl
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<List<ListSummaryDto>> GetSummaryDtos()
|
||||
{
|
||||
return await DbContext.FilterLists.AsNoTracking()
|
||||
.OrderBy(x => x.Name)
|
||||
.OrderBy(list => list.Name)
|
||||
.ProjectTo<ListSummaryDto>()
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
private async Task<List<Data.Entities.Snapshot>> GetLatestUpdatedSnapshots()
|
||||
{
|
||||
return await DbContext.Snapshots.AsNoTracking()
|
||||
.Where(snap =>
|
||||
snap.IsCompleted &&
|
||||
(snap.AddedSnapshotRules.Count > 0 || snap.RemovedSnapshotRules.Count > 0))
|
||||
.GroupBy(snap => snap.FilterListId,
|
||||
(key, x) => x.OrderByDescending(y => y.CreatedDateUtc).First())
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<ListDetailsDto> GetDetailsAsync(int id)
|
||||
{
|
||||
var details = await DbContext.FilterLists.AsNoTracking()
|
||||
|
|
@ -38,27 +65,24 @@ public async Task<ListDetailsDto> GetDetailsAsync(int id)
|
|||
|
||||
private async Task<int> GetActiveRuleCount(ListDetailsDto details)
|
||||
{
|
||||
return await DbContext.Snapshots.Where(s => s.FilterListId == details.Id && s.IsCompleted)
|
||||
.Include(s => s.AddedSnapshotRules)
|
||||
return await DbContext.Snapshots.AsNoTracking()
|
||||
.Where(s => s.FilterListId == details.Id && s.IsCompleted)
|
||||
.SelectMany(sr => sr.AddedSnapshotRules)
|
||||
.CountAsync() -
|
||||
await DbContext.Snapshots.Where(s => s.FilterListId == details.Id && s.IsCompleted)
|
||||
.Include(s => s.RemovedSnapshotRules)
|
||||
await DbContext.Snapshots.AsNoTracking()
|
||||
.Where(s => s.FilterListId == details.Id && s.IsCompleted)
|
||||
.SelectMany(sr => sr.RemovedSnapshotRules)
|
||||
.CountAsync();
|
||||
}
|
||||
|
||||
private async Task<DateTime?> GetUpdatedDate(ListDetailsDto details)
|
||||
{
|
||||
return details.DiscontinuedDate != null
|
||||
? (DateTime?) null
|
||||
: await DbContext.Snapshots.Where(s => s.FilterListId == details.Id && s.IsCompleted)
|
||||
.Include(s => s.AddedSnapshotRules)
|
||||
.Include(s => s.RemovedSnapshotRules)
|
||||
.Where(s => s.AddedSnapshotRules.Count > 0 || s.RemovedSnapshotRules.Count > 0)
|
||||
.Select(s => s.CreatedDateUtc)
|
||||
.OrderByDescending(s => s.Date)
|
||||
.FirstAsync();
|
||||
return await DbContext.Snapshots.AsNoTracking()
|
||||
.Where(s => s.FilterListId == details.Id && s.IsCompleted &&
|
||||
(s.AddedSnapshotRules.Count > 0 || s.RemovedSnapshotRules.Count > 0))
|
||||
.Select(s => s.CreatedDateUtc)
|
||||
.OrderByDescending(s => s.Date)
|
||||
.FirstAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -8,9 +8,10 @@ namespace FilterLists.Services.FilterList
|
|||
public class ListSummaryDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public DateTime CreatedDateUtc { get; set; }
|
||||
public DateTime AddedDate { get; set; }
|
||||
public IEnumerable<ListLanguagesDto> Languages { get; set; }
|
||||
public string Name { get; set; }
|
||||
public DateTime UpdatedDate { get; set; }
|
||||
public string ViewUrl { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -10,7 +10,8 @@ public MappingProfiles()
|
|||
{
|
||||
CreateMap<Data.Entities.FilterList, ListSummaryDto>()
|
||||
.ForMember(dto => dto.Languages,
|
||||
conf => conf.MapFrom(list => list.FilterListLanguages.Select(listLangs => listLangs.Language)));
|
||||
conf => conf.MapFrom(list => list.FilterListLanguages.Select(listLangs => listLangs.Language)))
|
||||
.ForMember(dto => dto.AddedDate, conf => conf.MapFrom(list => list.CreatedDateUtc));
|
||||
CreateMap<Data.Entities.FilterList, ListDetailsDto>()
|
||||
.ForMember(dto => dto.Languages,
|
||||
conf => conf.MapFrom(list => list.FilterListLanguages.Select(listLangs => listLangs.Language.Name)))
|
||||
|
|
|
|||
|
|
@ -94,15 +94,28 @@ export class Home extends React.Component<RouteComponentProps<{}>, IHomeState> {
|
|||
className: "d-none d-sm-block"
|
||||
},
|
||||
{
|
||||
Header: "Added",
|
||||
accessor: "createdDateUtc",
|
||||
Header: "Updated",
|
||||
accessor: "updatedDate",
|
||||
filterable: true,
|
||||
filterMethod: (filter: any, row: any) => row[filter.id].toUpperCase()
|
||||
.includes(filter.value.toUpperCase()),
|
||||
sortMethod: (a: any, b: any) => a > b ? 1 : -1,
|
||||
Cell: (cell: any) => <div>{moment(cell.value).format("M-D-YY")}</div>,
|
||||
style: { whiteSpace: "inherit" },
|
||||
width: 70,
|
||||
width: 75,
|
||||
headerClassName: "d-none d-sm-block",
|
||||
className: "d-none d-sm-block"
|
||||
},
|
||||
{
|
||||
Header: "Added",
|
||||
accessor: "addedDate",
|
||||
filterable: true,
|
||||
filterMethod: (filter: any, row: any) => row[filter.id].toUpperCase()
|
||||
.includes(filter.value.toUpperCase()),
|
||||
sortMethod: (a: any, b: any) => a > b ? 1 : -1,
|
||||
Cell: (cell: any) => <div>{moment(cell.value).format("M-D-YY")}</div>,
|
||||
style: { whiteSpace: "inherit" },
|
||||
width: 75,
|
||||
headerClassName: "d-none d-sm-block",
|
||||
className: "d-none d-sm-block"
|
||||
},
|
||||
|
|
@ -148,9 +161,10 @@ export class Home extends React.Component<RouteComponentProps<{}>, IHomeState> {
|
|||
|
||||
interface IListDto {
|
||||
id: number;
|
||||
createdDateUtc: string;
|
||||
addedDate: string;
|
||||
name: string;
|
||||
languages: IListLanguageDto[];
|
||||
updatedDate: string;
|
||||
viewUrl: string;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue