mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 03:15:31 -04:00
Read/unread a directory with API
This commit is contained in:
parent
b449d906ec
commit
ec6a7bd3d9
@ -38,8 +38,12 @@ function showModal(encodedPath, pages, percentage, encodedeTitle, encodedEntryTi
|
||||
styleModal();
|
||||
}
|
||||
|
||||
function updateProgress(titleID, entryID, page) {
|
||||
$.post('/api/progress/' + titleID + '/' + entryID + '/' + page, function(data) {
|
||||
const updateProgress = (tid, eid, page) => {
|
||||
let url = `/api/progress/${tid}/${page}`
|
||||
const query = $.param({entry: eid});
|
||||
if (eid)
|
||||
url += `?${query}`;
|
||||
$.post(url, (data) => {
|
||||
if (data.success) {
|
||||
location.reload();
|
||||
}
|
||||
@ -48,7 +52,7 @@ function updateProgress(titleID, entryID, page) {
|
||||
alert('danger', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const renameSubmit = (name, eid) => {
|
||||
const upload = $('.upload-field');
|
||||
|
@ -258,6 +258,26 @@ class Title
|
||||
end
|
||||
end
|
||||
|
||||
# Set the reading progress of all entries and nested libraries to 100%
|
||||
def read_all(username)
|
||||
@entries.each do |e|
|
||||
save_progress username, e.title, e.pages
|
||||
end
|
||||
titles.each do |t|
|
||||
t.read_all username
|
||||
end
|
||||
end
|
||||
|
||||
# Set the reading progress of all entries and nested libraries to 0%
|
||||
def unread_all(username)
|
||||
@entries.each do |e|
|
||||
save_progress username, e.title, 0
|
||||
end
|
||||
titles.each do |t|
|
||||
t.unread_all username
|
||||
end
|
||||
end
|
||||
|
||||
# For backward backward compatibility with v0.1.0, we save entry titles
|
||||
# instead of IDs in info.json
|
||||
def save_progress(username, entry, page)
|
||||
|
@ -69,16 +69,23 @@ class APIRouter < Router
|
||||
end
|
||||
end
|
||||
|
||||
post "/api/progress/:title/:entry/:page" do |env|
|
||||
post "/api/progress/:title/:page" do |env|
|
||||
begin
|
||||
username = get_username env
|
||||
title = (@context.library.get_title env.params.url["title"])
|
||||
.not_nil!
|
||||
entry = (title.get_entry env.params.url["entry"]).not_nil!
|
||||
page = env.params.url["page"].to_i
|
||||
entry_id = env.params.query["entry"]?
|
||||
|
||||
raise "incorrect page value" if page < 0 || page > entry.pages
|
||||
title.save_progress username, entry.title, page
|
||||
if !entry_id.nil?
|
||||
entry = title.get_entry(entry_id).not_nil!
|
||||
raise "incorrect page value" if page < 0 || page > entry.pages
|
||||
title.save_progress username, entry.title, page
|
||||
elsif page == 0
|
||||
title.unread_all username
|
||||
else
|
||||
title.read_all username
|
||||
end
|
||||
rescue e
|
||||
@context.error e
|
||||
send_json env, {
|
||||
|
Loading…
x
Reference in New Issue
Block a user