mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 11:25:29 -04:00
Group Recently Added by neighbouring Title
This commit is contained in:
parent
5ed2a8affa
commit
aaf0a3c6af
@ -525,15 +525,44 @@ class Library
|
||||
titles.each do |t|
|
||||
t.entries.each { |e| entries << e }
|
||||
end
|
||||
recently_added = entries.map { |e|
|
||||
{
|
||||
entry: e,
|
||||
percentage: e.book.load_percentage(username, e.title)
|
||||
entries.sort! { |a, b| b.date_added <=> a.date_added }
|
||||
# Only grab entries form the last 3 months
|
||||
# otherwise we will be grouping neighbours by Title for the entire
|
||||
# library every time. Is this premature optimisation or reasonable optimisation?
|
||||
entries.select! { |e| e.date_added > 3.months.ago }
|
||||
|
||||
i = 0
|
||||
recently_added = [] of NamedTuple(entry: Entry, percentage: Float64, grouped_count: Int32)
|
||||
while i <= entries.size - 1
|
||||
grouped_count = neighbouring_title_count(entries, i)
|
||||
if grouped_count > 1
|
||||
# delete grouped entries (except for first)
|
||||
entries.delete_at(i+1..i+grouped_count-1)
|
||||
end
|
||||
recently_added << {
|
||||
entry: entries[i],
|
||||
percentage: entries[i].book.load_percentage(username, entries[i].title),
|
||||
grouped_count: grouped_count
|
||||
}
|
||||
}
|
||||
recently_added.sort! { |a, b| b[:entry].date_added <=> a[:entry].date_added }[0..11]
|
||||
i += 1
|
||||
end
|
||||
|
||||
recently_added[0..11]
|
||||
end
|
||||
|
||||
private def neighbouring_title_count(entries, index : Int32)
|
||||
count = 1
|
||||
book_title = entries[index].book.title
|
||||
while index < entries.size - 1
|
||||
if book_title == entries[index+1].book.title # is it ok to compare via book.title?
|
||||
count += 1
|
||||
else
|
||||
break
|
||||
end
|
||||
index += 1
|
||||
end
|
||||
count
|
||||
end
|
||||
|
||||
private def get_continue_reading_entry(username, title)
|
||||
in_progress_entries = title.entries.select do |e|
|
||||
|
@ -24,7 +24,8 @@
|
||||
<h2 class="uk-title home-headings">Recently Added</h2>
|
||||
<div id="item-container-continue" class="uk-child-width-1-4@m uk-child-width-1-2" uk-grid>
|
||||
<%- recently_added.each do |ra| -%>
|
||||
<div class="item" data-mtime="<%= ra[:entry].mtime.to_unix %>" data-progress="<%= ra[:percentage] %>" id="<%= ra[:entry].id %>">
|
||||
<%- if ra[:grouped_count] == 1 -%>
|
||||
<div class="item" data-progress="<%= ra[:percentage] %>" id="<%= ra[:entry].id %>">
|
||||
<a class="acard">
|
||||
<div class="uk-card uk-card-default" onclick="showModal("<%= ra[:entry].encoded_path %>", '<%= ra[:entry].pages %>', <%= (ra[:percentage] * 100).round(1) %>, "<%= ra[:entry].book.encoded_display_name %>", "<%= ra[:entry].encoded_display_name %>", '<%= ra[:entry].title_id %>', '<%= ra[:entry].id %>')">
|
||||
<div class="uk-card-media-top">
|
||||
@ -38,6 +39,21 @@
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<%- else -%>
|
||||
<div class="item">
|
||||
<a class="acard" href="/book/<%= ra[:entry].book.id %>">
|
||||
<div class="uk-card uk-card-default">
|
||||
<div class="uk-card-media-top">
|
||||
<img data-src="<%= ra[:entry].cover_url %>" data-width data-height alt="" uk-img>
|
||||
</div>
|
||||
<div class="uk-card-body">
|
||||
<h3 class="uk-card-title break-word" data-title="<%= ra[:entry].book.display_name.gsub("\"", """) %>"><%= ra[:entry].book.display_name %></h3>
|
||||
<p><%= ra[:grouped_count] %> new entries</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<%- end -%>
|
||||
<%- end -%>
|
||||
</div>
|
||||
<%- end -%>
|
||||
|
Loading…
x
Reference in New Issue
Block a user