Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 7d2bced

Browse files
author
Laurent Curau
authored
Merge pull request #520 from alphagov/laurent/dataset-count
Count datasets with at least one datafile instead of counting datasets marked as published
2 parents c63a7a6 + da2971c commit 7d2bced

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

app/controllers/home_controller.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ def dashboard
1212
@datasets_count = Dataset.count
1313
@datafiles_count = Link.count
1414
@publishers_count = Organisation.count
15-
@published_datasets_count = Dataset.published.count
16-
@draft_datasets_count = Dataset.draft.count
17-
@unpublished_datasets_count = Dataset.with_no_datafiles.count
15+
@datasets_published_with_datafiles_count = Dataset.with_datafiles.distinct.count
16+
@datasets_published_with_no_datafiles_count = Dataset.with_no_datafiles.count
1817
@datafiles_count_by_format = Datafile.group(:format).count.sort_by { |_k, value| value }.reverse
1918
@broken_links_count = Link.broken.count
2019
end

app/models/dataset.rb

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Dataset < ApplicationRecord
3939

4040
scope :owned_by, ->(creator_id) { where(creator_id: creator_id) }
4141
scope :published, ->{ where(status: "published") }
42+
scope :with_datafiles, ->{ joins(:datafiles) }
4243
scope :with_no_datafiles, ->{ left_outer_joins(:datafiles).where(links: { id: nil } ) }
4344
scope :draft, ->{ where(status: "draft") }
4445

app/views/home/dashboard.html.erb

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,21 @@
1010
<div class="column-one-third">
1111
<div class="data">
1212
<span class="data-item bold-xlarge"><%= number_with_delimiter(@datasets_count) %></span>
13-
<span class="data-item bold-xsmall">datasets</span>
13+
<span class="data-item bold-xsmall"><%= 'dataset'.pluralize(@datasets_count) %> in total</span>
1414
</div>
1515
</div>
1616

1717
<div class="column-one-third">
1818
<div class="data">
19-
<span class="data-item bold-xlarge"><%= number_with_delimiter(@published_datasets_count) %></span>
20-
<span class="data-item bold-xsmall">published datasets</span>
19+
<span class="data-item bold-xlarge"><%= number_with_delimiter(@datasets_published_with_datafiles_count) %></span>
20+
<span class="data-item bold-xsmall"><%= 'dataset'.pluralize(@datasets_published_with_datafiles_count) %> published with datafiles</span>
2121
</div>
2222
</div>
2323

2424
<div class="column-one-third">
2525
<div class="data">
26-
<span class="data-item bold-xlarge"><%= number_with_delimiter(@unpublished_datasets_count) %></span>
27-
<span class="data-item bold-xsmall">datasets with no datafiles</span>
26+
<span class="data-item bold-xlarge"><%= number_with_delimiter(@datasets_published_with_no_datafiles_count) %></span>
27+
<span class="data-item bold-xsmall"><%= 'dataset'.pluralize(@datasets_published_with_no_datafiles_count) %> published with no datafiles</span>
2828
</div>
2929
</div>
3030
</div>
@@ -33,21 +33,21 @@
3333
<div class="column-one-third">
3434
<div class="data">
3535
<span class="data-item bold-xlarge"><%= number_with_delimiter(@datafiles_count) %></span>
36-
<span class="data-item bold-xsmall">datafiles</span>
36+
<span class="data-item bold-xsmall"><%= 'datafile'.pluralize(@datafiles_count) %> in total</span>
3737
</div>
3838
</div>
3939

4040
<div class="column-one-third">
4141
<div class="data">
4242
<span class="data-item bold-xlarge"><%= number_with_delimiter(@publishers_count) %></span>
43-
<span class="data-item bold-xsmall">Publishers</span>
43+
<span class="data-item bold-xsmall"><%= 'publisher'.pluralize(@publishers_count) %></span>
4444
</div>
4545
</div>
4646

4747
<div class="column-one-third">
4848
<div class="data">
4949
<span class="data-item bold-xlarge"><%= number_with_delimiter(@broken_links_count) %></span>
50-
<span class="data-item bold-xsmall">Broken links</span>
50+
<span class="data-item bold-xsmall">broken <%= 'link'.pluralize(@broken_links_count) %></span>
5151
</div>
5252
</div>
5353
</div>
@@ -61,7 +61,7 @@
6161
<tbody>
6262
<% @datafiles_count_by_format.each do |format, format_count| %>
6363
<tr>
64-
<th><%= format %></th>
64+
<th><%= format.presence || "Not specified" %></th>
6565
<td><%= format_count %></td>
6666
</tr>
6767
<% end %>

0 commit comments

Comments
 (0)