Skip to content

Commit

Permalink
Update Number display to clientside formatting for stats pages. (#4602)
Browse files Browse the repository at this point in the history
* Update Number display to clientside formatting.
* Switch a test to number comparison.
* Simplify html generation from js.
  • Loading branch information
ryuyu committed Aug 30, 2017
1 parent 450fc6c commit b0aff95
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/NuGetGallery/Controllers/StatisticsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ private void ProcessReport(StatisticsPackagesReport report, string[] groupby, st

if (groupby != null)
{
Tuple<StatisticsPivot.TableEntry[][], string> result = StatisticsPivot.GroupBy(report.Facts, pivot);
Tuple<StatisticsPivot.TableEntry[][], int> result = StatisticsPivot.GroupBy(report.Facts, pivot);

if (id != null)
{
Expand Down Expand Up @@ -355,7 +355,7 @@ private void ProcessReport(StatisticsPackagesReport report, string[] groupby, st
}

report.Table = null;
report.Total = report.Facts.Sum(fact => fact.Amount).ToNuGetNumberString();
report.Total = report.Facts.Sum(fact => fact.Amount);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/NuGetGallery/Scripts/gallery/stats-dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ var setupHiddenRows = function (data) {
if (item.Uri != null) {
content = $(document.createElement("a"));
content.attr("href", item.Uri);
content.text(item.Data);
} else {
var textValue = item.IsNumeric ? parseInt(item.Data).toLocaleString() : item.Data;
content = $(document.createElement("span"));
content.attr("aria-label", item.Data);
content.attr("aria-label", textValue);
content.text(textValue);
}

content.text(item.Data);
tempTd.append(content);
tdArr.push(tempTd);
}
Expand Down
4 changes: 2 additions & 2 deletions src/NuGetGallery/ViewModels/StatisticsPackagesReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace NuGetGallery
public class StatisticsPackagesReport
{
public IList<StatisticsPackagesItemViewModel> Rows { get; private set; }
public string Total { get; set; }
public int Total { get; set; }

public IList<StatisticsDimension> Dimensions { get; private set; }
public IList<StatisticsFact> Facts { get; set; }
Expand All @@ -24,7 +24,7 @@ public class StatisticsPackagesReport

public StatisticsPackagesReport()
{
Total = String.Empty;
Total = 0;
Id = String.Empty;
Columns = Enumerable.Empty<string>();
Facts = new List<StatisticsFact>();
Expand Down
6 changes: 3 additions & 3 deletions src/NuGetGallery/ViewModels/StatisticsPivot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace NuGetGallery
{
public class StatisticsPivot
{
public static Tuple<TableEntry[][], string> GroupBy(IList<StatisticsFact> facts, string[] pivot)
public static Tuple<TableEntry[][], int> GroupBy(IList<StatisticsFact> facts, string[] pivot)
{
// Firstly take the facts and the pivot vector and produce a tree structure

Expand All @@ -36,7 +36,7 @@ public static Tuple<TableEntry[][], string> GroupBy(IList<StatisticsFact> facts,

PopulateTable(level, table);

return new Tuple<TableEntry[][], string>(table, level.Total.ToNuGetNumberString());
return new Tuple<TableEntry[][], int>(table, level.Total);
}

private static void AddOrderedNext(Level level)
Expand All @@ -61,7 +61,7 @@ private static void InnerPopulateTable(Level level, TableEntry[][] table, ref in
if (item.Value.Next == null)
{
table[row][col] = new TableEntry { Data = item.Key };
table[row][col + 1] = new TableEntry { Data = item.Value.Amount.ToNuGetNumberString(), IsNumeric = true };
table[row][col + 1] = new TableEntry { Data = item.Value.Amount.ToString(), IsNumeric = true };
row++;
}
else
Expand Down
5 changes: 5 additions & 0 deletions src/NuGetGallery/Views/Statistics/_PivotTable.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
<a data-bind="attr: { href: Uri }, text: Data"></a>
<!-- /ko -->
<!-- ko ifnot: Uri -->
<!-- ko if: IsNumeric -->
<span data-bind="attr: { 'aria-label': Data }, text: parseInt(Data).toLocaleString()" tabindex="0"></span>
<!-- /ko -->
<!-- ko ifnot: IsNumeric -->
<span data-bind="attr: { 'aria-label': Data }, text: Data" tabindex="0"></span>
<!-- /ko -->
<!-- /ko -->
</td>
<!-- /ko -->
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ public async Task StatisticsHomePage_Per_Package_ValidateReportStructureAndAvail
}

Assert.Equal(603, sum);
Assert.Equal("603", actualReport.Total);
Assert.Equal(603, actualReport.Total);
Assert.True(actualReport.LastUpdatedUtc.HasValue);
Assert.Equal(updatedUtc, actualReport.LastUpdatedUtc.Value);
}
Expand Down Expand Up @@ -518,7 +518,7 @@ public async Task StatisticsHomePage_Per_Package_ValidateReportStructureAndAvail
}

Assert.Equal(603, sum);
Assert.Equal("603", actualReport.Total);
Assert.Equal(603, actualReport.Total);
Assert.True(actualReport.LastUpdatedUtc.HasValue);
Assert.Equal(updatedUtc, actualReport.LastUpdatedUtc.Value);
Assert.DoesNotContain(invalidDimension, actualReport.Columns);
Expand Down Expand Up @@ -620,7 +620,7 @@ public async Task Statistics_By_Client_Operation_ValidateReportStructureAndAvail
}

Assert.Equal(502, sum);
Assert.Equal("502", actualReport.Total);
Assert.Equal(502, actualReport.Total);
Assert.True(actualReport.LastUpdatedUtc.HasValue);
Assert.Equal(updatedUtc, actualReport.LastUpdatedUtc.Value);
}
Expand Down

0 comments on commit b0aff95

Please sign in to comment.