mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-05 04:15:35 -04:00
WIP last_read property for Entries
This commit is contained in:
parent
ddb6a860ae
commit
d2ad7fef77
@ -287,6 +287,15 @@ class Title
|
|||||||
else
|
else
|
||||||
info.progress[username][entry] = page
|
info.progress[username][entry] = page
|
||||||
end
|
end
|
||||||
|
# should this be a separate method?
|
||||||
|
# eg. def save_last_read(username, entry)
|
||||||
|
# if so, we would need to open the json file twice every
|
||||||
|
# time we save. Does that matter?
|
||||||
|
if info.last_read[username]?.nil?
|
||||||
|
info.last_read[username] = {entry => Time.utc}
|
||||||
|
else
|
||||||
|
info.last_read[username][entry] = Time.utc
|
||||||
|
end
|
||||||
info.save
|
info.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -319,6 +328,18 @@ class Title
|
|||||||
read_pages / total_pages
|
read_pages / total_pages
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def load_last_read(username, entry)
|
||||||
|
last_read = nil
|
||||||
|
TitleInfo.new @dir do |info|
|
||||||
|
unless info.last_read[username]?.nil? ||
|
||||||
|
info.last_read[username][entry]?.nil?
|
||||||
|
last_read = info.last_read[username][entry]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil if last_read.nil?
|
||||||
|
last_read
|
||||||
|
end
|
||||||
|
|
||||||
def next_entry(current_entry_obj)
|
def next_entry(current_entry_obj)
|
||||||
idx = @entries.index current_entry_obj
|
idx = @entries.index current_entry_obj
|
||||||
return nil if idx.nil? || idx == @entries.size - 1
|
return nil if idx.nil? || idx == @entries.size - 1
|
||||||
@ -350,6 +371,7 @@ class TitleInfo
|
|||||||
property entry_display_name = {} of String => String
|
property entry_display_name = {} of String => String
|
||||||
property cover_url = ""
|
property cover_url = ""
|
||||||
property entry_cover_url = {} of String => String
|
property entry_cover_url = {} of String => String
|
||||||
|
property last_read = {} of String => Hash(String, Time)
|
||||||
|
|
||||||
@[JSON::Field(ignore: true)]
|
@[JSON::Field(ignore: true)]
|
||||||
property dir : String = ""
|
property dir : String = ""
|
||||||
|
@ -77,6 +77,7 @@ class MainRouter < Router
|
|||||||
|
|
||||||
percentage = continue_reading_entries.map do |e|
|
percentage = continue_reading_entries.map do |e|
|
||||||
e.book.load_percentage username, e.title
|
e.book.load_percentage username, e.title
|
||||||
|
pp e.book.load_last_read username, e.title
|
||||||
end
|
end
|
||||||
|
|
||||||
layout "home"
|
layout "home"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user