mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-02 10:55:30 -04:00
Entry selector on reader page (closes #168)
This commit is contained in:
parent
8aab113aab
commit
05b4e77fa9
@ -9,6 +9,7 @@ const readerComponent = () => {
|
|||||||
flipAnimation: null,
|
flipAnimation: null,
|
||||||
longPages: false,
|
longPages: false,
|
||||||
lastSavedPage: page,
|
lastSavedPage: page,
|
||||||
|
selectedIndex: 0, // 0: not selected; 1: the first page
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the component by fetching the page dimensions
|
* Initialize the component by fetching the page dimensions
|
||||||
@ -221,10 +222,7 @@ const readerComponent = () => {
|
|||||||
*/
|
*/
|
||||||
showControl(event) {
|
showControl(event) {
|
||||||
const idx = event.currentTarget.id;
|
const idx = event.currentTarget.id;
|
||||||
const pageCount = this.items.length;
|
this.selectedIndex = idx;
|
||||||
const progressText = `Progress: ${idx}/${pageCount} (${(idx/pageCount * 100).toFixed(1)}%)`;
|
|
||||||
$('#progress-label').text(progressText);
|
|
||||||
$('#page-select').val(idx);
|
|
||||||
UIkit.modal($('#modal-sections')).show();
|
UIkit.modal($('#modal-sections')).show();
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
@ -263,19 +261,22 @@ const readerComponent = () => {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Exits the reader, and optionally sets the reading progress tp 100%
|
* Exits the reader, and sets the reading progress tp 100%
|
||||||
*
|
*
|
||||||
* @param {string} exitUrl - The Exit URL
|
* @param {string} exitUrl - The Exit URL
|
||||||
* @param {boolean} [markCompleted] - Whether we should mark the
|
|
||||||
* reading progress to 100%
|
|
||||||
*/
|
*/
|
||||||
exitReader(exitUrl, markCompleted = false) {
|
exitReader(exitUrl) {
|
||||||
if (!markCompleted) {
|
|
||||||
return this.redirect(exitUrl);
|
|
||||||
}
|
|
||||||
this.saveProgress(this.items.length, () => {
|
this.saveProgress(this.items.length, () => {
|
||||||
this.redirect(exitUrl);
|
this.redirect(exitUrl);
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the `change` event for the entry selector
|
||||||
|
*/
|
||||||
|
entryChanged() {
|
||||||
|
const id = $('#entry-select').val();
|
||||||
|
this.redirect(`${base_url}reader/${tid}/${id}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -134,10 +134,11 @@ class Entry
|
|||||||
entries[idx + 1]
|
entries[idx + 1]
|
||||||
end
|
end
|
||||||
|
|
||||||
def previous_entry
|
def previous_entry(username)
|
||||||
idx = @book.entries.index self
|
entries = @book.sorted_entries username
|
||||||
|
idx = entries.index self
|
||||||
return nil if idx.nil? || idx == 0
|
return nil if idx.nil? || idx == 0
|
||||||
@book.entries[idx - 1]
|
entries[idx - 1]
|
||||||
end
|
end
|
||||||
|
|
||||||
def date_added
|
def date_added
|
||||||
|
@ -121,7 +121,7 @@ class Library
|
|||||||
# Get the last read time of the entry. If it hasn't been started, get
|
# Get the last read time of the entry. If it hasn't been started, get
|
||||||
# the last read time of the previous entry
|
# the last read time of the previous entry
|
||||||
last_read = e.load_last_read username
|
last_read = e.load_last_read username
|
||||||
pe = e.previous_entry
|
pe = e.previous_entry username
|
||||||
if last_read.nil? && pe
|
if last_read.nil? && pe
|
||||||
last_read = pe.load_last_read username
|
last_read = pe.load_last_read username
|
||||||
end
|
end
|
||||||
|
@ -30,6 +30,11 @@ struct ReaderRouter
|
|||||||
|
|
||||||
title = (Library.default.get_title env.params.url["title"]).not_nil!
|
title = (Library.default.get_title env.params.url["title"]).not_nil!
|
||||||
entry = (title.get_entry env.params.url["entry"]).not_nil!
|
entry = (title.get_entry env.params.url["entry"]).not_nil!
|
||||||
|
|
||||||
|
sort_opt = SortOptions.from_info_json title.dir, username
|
||||||
|
get_sort_opt
|
||||||
|
entries = title.sorted_entries username, sort_opt
|
||||||
|
|
||||||
page_idx = env.params.url["page"].to_i
|
page_idx = env.params.url["page"].to_i
|
||||||
if page_idx > entry.pages || page_idx <= 0
|
if page_idx > entry.pages || page_idx <= 0
|
||||||
raise "Page #{page_idx} not found."
|
raise "Page #{page_idx} not found."
|
||||||
@ -37,10 +42,12 @@ struct ReaderRouter
|
|||||||
|
|
||||||
exit_url = "#{base_url}book/#{title.id}"
|
exit_url = "#{base_url}book/#{title.id}"
|
||||||
|
|
||||||
next_entry_url = nil
|
next_entry_url = entry.next_entry(username).try do |e|
|
||||||
next_entry = entry.next_entry username
|
"#{base_url}reader/#{title.id}/#{e.id}"
|
||||||
unless next_entry.nil?
|
end
|
||||||
next_entry_url = "#{base_url}reader/#{title.id}/#{next_entry.id}"
|
|
||||||
|
previous_entry_url = entry.previous_entry(username).try do |e|
|
||||||
|
"#{base_url}reader/#{title.id}/#{e.id}"
|
||||||
end
|
end
|
||||||
|
|
||||||
render "src/views/reader.html.ecr"
|
render "src/views/reader.html.ecr"
|
||||||
|
@ -36,7 +36,7 @@
|
|||||||
<%- if next_entry_url -%>
|
<%- if next_entry_url -%>
|
||||||
<button id="next-btn" class="uk-align-center uk-button uk-button-primary" @click="nextEntry('<%= next_entry_url %>')">Next Entry</button>
|
<button id="next-btn" class="uk-align-center uk-button uk-button-primary" @click="nextEntry('<%= next_entry_url %>')">Next Entry</button>
|
||||||
<%- else -%>
|
<%- else -%>
|
||||||
<button id="next-btn" class="uk-align-center uk-button uk-button-primary" @click="exitReader('<%= exit_url %>', true)">Exit Reader</button>
|
<button id="next-btn" class="uk-align-center uk-button uk-button-primary" @click="exitReader('<%= exit_url %>')">Exit Reader</button>
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -68,12 +68,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="uk-modal-body">
|
<div class="uk-modal-body">
|
||||||
<div class="uk-margin">
|
<div class="uk-margin">
|
||||||
<p id="progress-label"></p>
|
<p x-text="`Progress: ${selectedIndex}/${items.length} (${(selectedIndex/items.length * 100).toFixed(1)}%)`"></p>
|
||||||
</div>
|
</div>
|
||||||
<div class="uk-margin">
|
<div class="uk-margin">
|
||||||
<label class="uk-form-label" for="page-select">Jump to page</label>
|
<label class="uk-form-label" for="page-select">Jump to Page</label>
|
||||||
<div class="uk-form-controls">
|
<div class="uk-form-controls">
|
||||||
<select id="page-select" class="uk-select" @change="pageChanged()">
|
<select id="page-select" class="uk-select" @change="pageChanged()" x-model="selectedIndex">
|
||||||
<%- (1..entry.pages).each do |p| -%>
|
<%- (1..entry.pages).each do |p| -%>
|
||||||
<option value="<%= p %>"><%= p %></option>
|
<option value="<%= p %>"><%= p %></option>
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
@ -89,9 +89,33 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<hr class="uk-divider-icon">
|
||||||
|
|
||||||
|
<div class="uk-margin">
|
||||||
|
<label class="uk-form-label" for="entry-select">Jump to Entry</label>
|
||||||
|
<div class="uk-form-controls">
|
||||||
|
<select id="entry-select" class="uk-select" @change="entryChanged()">
|
||||||
|
<% entries.each do |e| %>
|
||||||
|
<option value="<%= e.id %>"
|
||||||
|
<% if e.id == entry.id %>
|
||||||
|
selected
|
||||||
|
<% end %>>
|
||||||
|
<%= e.title %>
|
||||||
|
</option>
|
||||||
|
<% end %>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="uk-modal-footer uk-text-right">
|
<div class="uk-modal-footer uk-text-right">
|
||||||
<button class="uk-button uk-button-danger" type="button" @click="exitReader('<%= exit_url %>')">Exit Reader</button>
|
<% if previous_entry_url %>
|
||||||
|
<a class="uk-button uk-button-default uk-margin-small-right" href="<%= previous_entry_url %>">Previous Entry</a>
|
||||||
|
<% end %>
|
||||||
|
<% if next_entry_url %>
|
||||||
|
<a class="uk-button uk-button-default uk-margin-small-right" href="<%= next_entry_url %>">Next Entry</a>
|
||||||
|
<% end %>
|
||||||
|
<a class="uk-button uk-button-danger" href="<%= exit_url %>">Exit Reader</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user