From dd37cc133599825f7905094bb7ce7cfb2fcd4e6d Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Fri, 8 Jun 2018 08:44:20 -0500 Subject: [PATCH] add rule count to list details closes #55 --- .../FilterList/FilterListService.cs | 22 +++++++++++++++---- .../FilterList/ListDetailsDto.cs | 1 + .../ClientApp/components/ListDetails.tsx | 15 ++++++++++--- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/FilterLists.Services/FilterList/FilterListService.cs b/src/FilterLists.Services/FilterList/FilterListService.cs index a05321826..0b8cca287 100644 --- a/src/FilterLists.Services/FilterList/FilterListService.cs +++ b/src/FilterLists.Services/FilterList/FilterListService.cs @@ -26,10 +26,24 @@ public async Task> GetAllSummariesAsync() public async Task GetDetailsAsync(int id) { - return await DbContext.FilterLists.AsNoTracking() - .ProjectTo() - .FirstAsync(x => x.Id == id) - .FilterParentListFromMaintainerAdditionalLists(); + var details = await DbContext.FilterLists.AsNoTracking() + .ProjectTo() + .FirstAsync(x => x.Id == id) + .FilterParentListFromMaintainerAdditionalLists(); + details.RuleCount = await GetActiveRuleCount(details); + return details; + } + + private async Task GetActiveRuleCount(ListDetailsDto details) + { + return await DbContext.Snapshots.Where(s => s.FilterListId == details.Id && s.IsCompleted) + .Include(s => s.AddedSnapshotRules) + .SelectMany(sr => sr.AddedSnapshotRules) + .CountAsync() - + await DbContext.Snapshots.Where(s => s.FilterListId == details.Id && s.IsCompleted) + .Include(s => s.RemovedSnapshotRules) + .SelectMany(sr => sr.RemovedSnapshotRules) + .CountAsync(); } } } \ No newline at end of file diff --git a/src/FilterLists.Services/FilterList/ListDetailsDto.cs b/src/FilterLists.Services/FilterList/ListDetailsDto.cs index 5c8d67ff2..3fc956494 100644 --- a/src/FilterLists.Services/FilterList/ListDetailsDto.cs +++ b/src/FilterLists.Services/FilterList/ListDetailsDto.cs @@ -23,6 +23,7 @@ public class ListDetailsDto public string Name { get; set; } public string PolicyUrl { get; set; } public DateTime? PublishedDate { get; set; } + public int RuleCount { get; set; } public string SubmissionUrl { get; set; } public ListSyntaxDto Syntax { get; set; } public string ViewUrl { get; set; } diff --git a/src/FilterLists.Web/ClientApp/components/ListDetails.tsx b/src/FilterLists.Web/ClientApp/components/ListDetails.tsx index 337bf1b8e..b21a84f32 100644 --- a/src/FilterLists.Web/ClientApp/components/ListDetails.tsx +++ b/src/FilterLists.Web/ClientApp/components/ListDetails.tsx @@ -54,6 +54,7 @@ function ListInfo(props: any) {
    + @@ -92,8 +93,7 @@ function Languages(props: any) { ?
  • Languages:

      - {props.languages.map( - (language: any) =>
    • {language}
    • )} + {props.languages.map((language: any) =>
    • {language}
    • )}
  • :
  • @@ -102,6 +102,14 @@ function Languages(props: any) { : null; } +function RuleCount(props: any) { + return props.count + ?
  • +

    Rule Count: {props.count.toLocaleString()}

    +
  • + : null; +} + function PublishedDate(props: any) { return props.date ?
  • @@ -298,6 +306,7 @@ interface IFilterListDetailsDto { maintainers: IListMaintainerDto[]; policyUrl: string; publishedDate: string; + ruleCount: number; submissionUrl: string; syntax: IListSyntaxDto[]; viewUrl: string; @@ -331,4 +340,4 @@ interface IListSyntaxDto { interface ISyntaxSupportedSoftwareDto { homeUrl: string; name: string; -} \ No newline at end of file +}; \ No newline at end of file