mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-05 12:25:32 -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();
|
styleModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateProgress(titleID, entryID, page) {
|
const updateProgress = (tid, eid, page) => {
|
||||||
$.post('/api/progress/' + titleID + '/' + entryID + '/' + page, function(data) {
|
let url = `/api/progress/${tid}/${page}`
|
||||||
|
const query = $.param({entry: eid});
|
||||||
|
if (eid)
|
||||||
|
url += `?${query}`;
|
||||||
|
$.post(url, (data) => {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
@ -48,7 +52,7 @@ function updateProgress(titleID, entryID, page) {
|
|||||||
alert('danger', error);
|
alert('danger', error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
const renameSubmit = (name, eid) => {
|
const renameSubmit = (name, eid) => {
|
||||||
const upload = $('.upload-field');
|
const upload = $('.upload-field');
|
||||||
|
@ -258,6 +258,26 @@ class Title
|
|||||||
end
|
end
|
||||||
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
|
# For backward backward compatibility with v0.1.0, we save entry titles
|
||||||
# instead of IDs in info.json
|
# instead of IDs in info.json
|
||||||
def save_progress(username, entry, page)
|
def save_progress(username, entry, page)
|
||||||
|
@ -69,16 +69,23 @@ class APIRouter < Router
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
post "/api/progress/:title/:entry/:page" do |env|
|
post "/api/progress/:title/:page" do |env|
|
||||||
begin
|
begin
|
||||||
username = get_username env
|
username = get_username env
|
||||||
title = (@context.library.get_title env.params.url["title"])
|
title = (@context.library.get_title env.params.url["title"])
|
||||||
.not_nil!
|
.not_nil!
|
||||||
entry = (title.get_entry env.params.url["entry"]).not_nil!
|
|
||||||
page = env.params.url["page"].to_i
|
page = env.params.url["page"].to_i
|
||||||
|
entry_id = env.params.query["entry"]?
|
||||||
|
|
||||||
raise "incorrect page value" if page < 0 || page > entry.pages
|
if !entry_id.nil?
|
||||||
title.save_progress username, entry.title, page
|
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
|
rescue e
|
||||||
@context.error e
|
@context.error e
|
||||||
send_json env, {
|
send_json env, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user