mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 03:15:31 -04:00
Show progress for titles and nested titles
This commit is contained in:
parent
aa269f26ee
commit
c8be2849b9
@ -339,14 +339,18 @@ class Title
|
||||
page / entry_obj.pages
|
||||
end
|
||||
|
||||
def deep_read_page_count(username) : Int32
|
||||
entries.map { |e| load_progress username, e.title }.sum +
|
||||
titles.map { |t| t.deep_read_page_count username }.flatten.sum
|
||||
end
|
||||
|
||||
def deep_total_page_count : Int32
|
||||
entries.map { |e| e.pages }.sum +
|
||||
titles.map { |t| t.deep_total_page_count }.flatten.sum
|
||||
end
|
||||
|
||||
def load_percentage(username)
|
||||
return 0.0 if @entries.empty?
|
||||
read_pages = total_pages = 0
|
||||
@entries.each do |e|
|
||||
read_pages += load_progress username, e.title
|
||||
total_pages += e.pages
|
||||
end
|
||||
read_pages / total_pages
|
||||
deep_read_page_count(username) / deep_total_page_count
|
||||
end
|
||||
|
||||
def load_last_read(username, entry)
|
||||
|
@ -56,6 +56,7 @@ class MainRouter < Router
|
||||
percentage = title.entries.map { |e|
|
||||
title.load_percentage username, e.title
|
||||
}
|
||||
title_percentage = title.titles.map &.load_percentage username
|
||||
layout "title"
|
||||
rescue e
|
||||
@context.error e
|
||||
|
@ -8,7 +8,7 @@
|
||||
<% else %>
|
||||
<% grouped_count = 1 %>
|
||||
<% end %>
|
||||
<div class="item" data-mtime="<%= item.mtime.to_unix %>" data-progress="<%= progress || 0.0 %>"
|
||||
<div class="item" data-mtime="<%= item.mtime.to_unix %>" data-progress="<%= progress %>"
|
||||
<% if item.is_a? Entry %>
|
||||
id="<%= item.id %>"
|
||||
<% end %>>
|
||||
@ -20,7 +20,7 @@
|
||||
|
||||
<div class="uk-card uk-card-default"
|
||||
<% if item.is_a? Entry %>
|
||||
onclick="showModal("<%= item.encoded_path %>", '<%= item.pages %>', <%= (progress.not_nil! * 100).round(1) %>, "<%= item.book.encoded_display_name %>", "<%= item.encoded_display_name %>", '<%= item.title_id %>', '<%= item.id %>')"
|
||||
onclick="showModal("<%= item.encoded_path %>", '<%= item.pages %>', <%= (progress * 100).round(1) %>, "<%= item.book.encoded_display_name %>", "<%= item.encoded_display_name %>", '<%= item.title_id %>', '<%= item.id %>')"
|
||||
<% end %>>
|
||||
|
||||
<div class="uk-card-media-top">
|
||||
@ -28,9 +28,7 @@
|
||||
</div>
|
||||
|
||||
<div class="uk-card-body">
|
||||
<% unless (item.is_a? Title && item.entries.size == 0) || progress.nil? %>
|
||||
<div class="uk-card-badge uk-label"><%= (progress * 100).round(1) %>%</div>
|
||||
<% end %>
|
||||
|
||||
<h3 class="uk-card-title break-word" data-title="<%= item.display_name.gsub("\"", """) %>"><%= item.display_name %></h3>
|
||||
<% if item.is_a? Entry %>
|
||||
|
@ -33,7 +33,7 @@
|
||||
</div>
|
||||
<div id="item-container" class="uk-child-width-1-4@m uk-child-width-1-2" uk-grid>
|
||||
<% title.titles.each_with_index do |item, i| %>
|
||||
<% progress = nil %>
|
||||
<% progress = title_percentage[i] %>
|
||||
<%= render_component "card" %>
|
||||
<% end %>
|
||||
<% title.entries.each_with_index do |item, i| %>
|
||||
|
Loading…
x
Reference in New Issue
Block a user