From 2559f65f35a9760534e6afe515263670def543a2 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Tue, 29 Dec 2020 04:33:55 +0000 Subject: [PATCH] Display the entries and sub-titles count --- src/library/title.cr | 14 ++++++++++++-- src/views/components/card.html.ecr | 2 +- src/views/title.html.ecr | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/library/title.cr b/src/library/title.cr index 52e9838..d72bb48 100644 --- a/src/library/title.cr +++ b/src/library/title.cr @@ -108,8 +108,18 @@ class Title ary.reverse end - def size - @entries.size + @title_ids.size + # Returns a string the describes the content of the title + # e.g., - 3 titles and 1 entry + # - 4 entries + # - 1 title + def content_label + ary = [] of String + tsize = titles.size + esize = entries.size + + ary << "#{tsize} #{tsize > 1 ? "titles" : "title"}" if tsize > 0 + ary << "#{esize} #{esize > 1 ? "entries" : "entry"}" if esize > 0 + ary.join " and " end def get_entry(eid) diff --git a/src/views/components/card.html.ecr b/src/views/components/card.html.ecr index a116fee..b85d39e 100644 --- a/src/views/components/card.html.ecr +++ b/src/views/components/card.html.ecr @@ -76,7 +76,7 @@ <% end %> <% if item.is_a? Title %> <% if grouped_count == 1 %> -

<%= item.size %> entries

+

<%= item.content_label %>

<% else %>

<%= grouped_count %> new entries

<% end %> diff --git a/src/views/title.html.ecr b/src/views/title.html.ecr index 9d22f22..53db6ab 100644 --- a/src/views/title.html.ecr +++ b/src/views/title.html.ecr @@ -32,7 +32,7 @@ <%- end -%>
  • <%= title.display_name %>
  • -

    <%= title.size %> entries found

    +

    <%= title.content_label %> found