mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-04 20:05:29 -04:00
Add Recently Added to home
This commit is contained in:
parent
49193b9b00
commit
808074e478
@ -17,7 +17,8 @@ end
|
||||
class Entry
|
||||
property zip_path : String, book : Title, title : String,
|
||||
size : String, pages : Int32, id : String, title_id : String,
|
||||
encoded_path : String, encoded_title : String, mtime : Time
|
||||
encoded_path : String, encoded_title : String, mtime : Time,
|
||||
date_added : Time
|
||||
|
||||
def initialize(path, @book, @title_id, storage)
|
||||
@zip_path = path
|
||||
@ -33,6 +34,7 @@ class Entry
|
||||
file.close
|
||||
@id = storage.get_id @zip_path, false
|
||||
@mtime = File.info(@zip_path).modification_time
|
||||
@date_added = load_date_added
|
||||
end
|
||||
|
||||
def to_json(json : JSON::Builder)
|
||||
@ -89,6 +91,20 @@ class Entry
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private def load_date_added
|
||||
date_added = nil
|
||||
TitleInfo.new @book.dir do |info|
|
||||
info_da = info.date_added[@title]?
|
||||
if info_da.nil?
|
||||
date_added = info.date_added[@title] = ctime @zip_path
|
||||
info.save
|
||||
else
|
||||
date_added = info_da
|
||||
end
|
||||
end
|
||||
date_added.not_nil! # is it ok to set not_nil! here?
|
||||
end
|
||||
end
|
||||
|
||||
class Title
|
||||
@ -384,6 +400,7 @@ class TitleInfo
|
||||
property cover_url = ""
|
||||
property entry_cover_url = {} of String => String
|
||||
property last_read = {} of String => Hash(String, Time)
|
||||
property date_added = {} of String => Time
|
||||
|
||||
@[JSON::Field(ignore: true)]
|
||||
property dir : String = ""
|
||||
@ -486,7 +503,7 @@ class Library
|
||||
get_continue_reading_entry username, t
|
||||
}.select Entry
|
||||
|
||||
continue_reading = continue_reading_entries.map_with_index { |e, i|
|
||||
continue_reading = continue_reading_entries.map { |e|
|
||||
{
|
||||
entry: e,
|
||||
percentage: e.book.load_percentage(username, e.title),
|
||||
@ -495,12 +512,26 @@ class Library
|
||||
}
|
||||
|
||||
# Sort by by last_read, most recent first (nils at the end)
|
||||
continue_reading.sort! do |a, b|
|
||||
continue_reading.sort! { |a, b|
|
||||
next 0 if a[:last_read].nil? && b[:last_read].nil?
|
||||
next 1 if a[:last_read].nil?
|
||||
next -1 if b[:last_read].nil?
|
||||
b[:last_read].not_nil! <=> a[:last_read].not_nil!
|
||||
}[0..11]
|
||||
end
|
||||
|
||||
def get_recently_added_entries(username)
|
||||
entries = [] of Entry
|
||||
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)
|
||||
}
|
||||
}
|
||||
recently_added.sort! { |a, b| b[:entry].date_added <=> a[:entry].date_added }[0..11]
|
||||
end
|
||||
|
||||
|
||||
|
@ -67,6 +67,7 @@ class MainRouter < Router
|
||||
begin
|
||||
username = get_username env
|
||||
continue_reading = @context.library.get_continue_reading_entries username
|
||||
recently_added = @context.library.get_recently_added_entries username
|
||||
|
||||
layout "home"
|
||||
rescue e
|
||||
|
@ -20,6 +20,28 @@
|
||||
</div>
|
||||
<%- end -%>
|
||||
|
||||
<%- unless recently_added.empty? -%>
|
||||
<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 %>">
|
||||
<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">
|
||||
<img data-src="<%= ra[:entry].cover_url %>" alt="" data-width data-height uk-img>
|
||||
</div>
|
||||
<div class="uk-card-body">
|
||||
<div class="uk-card-badge uk-label"><%= (ra[:percentage] * 100).round(1) %>%</div>
|
||||
<h3 class="uk-card-title break-word" data-title="<%= ra[:entry].display_name.gsub("\"", """) %>"><%= ra[:entry].display_name %></h3>
|
||||
<p><%= ra[:entry].pages %> pages</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
<%- end -%>
|
||||
</div>
|
||||
<%- end -%>
|
||||
|
||||
<!-- TODO: DRY this code with calls in other ecr files? eg. title.ecr -->
|
||||
<div id="modal" class="uk-flex-top" uk-modal>
|
||||
<div class="uk-modal-dialog uk-margin-auto-vertical">
|
||||
|
Loading…
x
Reference in New Issue
Block a user