mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-05 12:25:32 -04:00
Add SortOptions.from_info_json
This commit is contained in:
parent
69b06a8352
commit
ba16c3db2f
@ -40,6 +40,16 @@ class SortOptions
|
|||||||
self.new method, ascend
|
self.new method, ascend
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.from_info_json(dir, username)
|
||||||
|
opt = SortOptions.new
|
||||||
|
TitleInfo.new dir do |info|
|
||||||
|
if info.sort_by.has_key? username
|
||||||
|
opt = SortOptions.from_tuple info.sort_by[username]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
opt
|
||||||
|
end
|
||||||
|
|
||||||
def to_tuple
|
def to_tuple
|
||||||
{@method.to_s.underscore, ascend}
|
{@method.to_s.underscore, ascend}
|
||||||
end
|
end
|
||||||
@ -489,7 +499,7 @@ class Title
|
|||||||
# When `opt` is not nil, it saves the options to info.json
|
# When `opt` is not nil, it saves the options to info.json
|
||||||
def sorted_entries(username, opt : SortOptions? = nil)
|
def sorted_entries(username, opt : SortOptions? = nil)
|
||||||
if opt.nil?
|
if opt.nil?
|
||||||
opt = load_sort_options username
|
opt = SortOptions.from_info_json @dir, username
|
||||||
else
|
else
|
||||||
TitleInfo.new @dir do |info|
|
TitleInfo.new @dir do |info|
|
||||||
info.sort_by[username] = opt.to_tuple
|
info.sort_by[username] = opt.to_tuple
|
||||||
@ -528,16 +538,6 @@ class Title
|
|||||||
ary
|
ary
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_sort_options(username)
|
|
||||||
opt = SortOptions.new
|
|
||||||
TitleInfo.new @dir do |info|
|
|
||||||
if info.sort_by.has_key? username
|
|
||||||
opt = SortOptions.from_tuple info.sort_by[username]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
opt
|
|
||||||
end
|
|
||||||
|
|
||||||
# === helper methods ===
|
# === helper methods ===
|
||||||
|
|
||||||
# Gets the last read entry in the title. If the entry has been completed,
|
# Gets the last read entry in the title. If the entry has been completed,
|
||||||
@ -793,7 +793,7 @@ class Library
|
|||||||
|
|
||||||
def sorted_titles(username, opt : SortOptions? = nil)
|
def sorted_titles(username, opt : SortOptions? = nil)
|
||||||
if opt.nil?
|
if opt.nil?
|
||||||
opt = load_sort_options username
|
opt = SortOptions.from_info_json @dir, username
|
||||||
else
|
else
|
||||||
TitleInfo.new @dir do |info|
|
TitleInfo.new @dir do |info|
|
||||||
info.sort_by[username] = opt.to_tuple
|
info.sort_by[username] = opt.to_tuple
|
||||||
@ -825,14 +825,4 @@ class Library
|
|||||||
|
|
||||||
ary
|
ary
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_sort_options(username)
|
|
||||||
opt = SortOptions.new
|
|
||||||
TitleInfo.new @dir do |info|
|
|
||||||
if info.sort_by.has_key? username
|
|
||||||
opt = SortOptions.from_tuple info.sort_by[username]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
opt
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
@ -41,7 +41,7 @@ class MainRouter < Router
|
|||||||
begin
|
begin
|
||||||
username = get_username env
|
username = get_username env
|
||||||
|
|
||||||
sort_opt = @context.library.load_sort_options username
|
sort_opt = SortOptions.from_info_json @context.library.dir, username
|
||||||
get_sort_opt
|
get_sort_opt
|
||||||
|
|
||||||
titles = @context.library.sorted_titles username, sort_opt
|
titles = @context.library.sorted_titles username, sort_opt
|
||||||
@ -59,7 +59,7 @@ class MainRouter < Router
|
|||||||
title = (@context.library.get_title env.params.url["title"]).not_nil!
|
title = (@context.library.get_title env.params.url["title"]).not_nil!
|
||||||
username = get_username env
|
username = get_username env
|
||||||
|
|
||||||
sort_opt = title.load_sort_options username
|
sort_opt = SortOptions.from_info_json title.dir, username
|
||||||
get_sort_opt
|
get_sort_opt
|
||||||
|
|
||||||
entries = title.sorted_entries username, sort_opt
|
entries = title.sorted_entries username, sort_opt
|
||||||
|
Loading…
x
Reference in New Issue
Block a user