rename root to library and add home with on deck WIP

This commit is contained in:
Jared Turner 2020-05-18 21:06:14 +01:00
parent 392b3d8339
commit 16734c2c59
5 changed files with 106 additions and 2 deletions

View File

@ -324,6 +324,29 @@ class Title
return nil if idx.nil? || idx == @entries.size - 1 return nil if idx.nil? || idx == @entries.size - 1
@entries[idx + 1] @entries[idx + 1]
end end
def get_on_deck_entry(username)
# this assumes @entries is in order (low to high), otherwise we would need to sort first
# TODO: what happens if no entry has progress > 0
idx_latest_read_entry_reverse = -99 # hack to set var, refactor this and `return nil if` below
@entries.reverse.each_with_index do |e, i|
if load_progress(username, e.title) > 0
idx_latest_read_entry_reverse = i
break
end
end
return nil if idx_latest_read_entry_reverse == -99
latest_read_entry = @entries.reverse[idx_latest_read_entry_reverse]
if load_progress(username, latest_read_entry.title) == latest_read_entry.pages
# return next entry (if exists)
if idx_latest_read_entry_reverse - 1 >= 0
return @entries.reverse[idx_latest_read_entry_reverse - 1]
end
else # return in progress entry
return latest_read_entry
end
return nil
end
end end
class TitleInfo class TitleInfo

View File

@ -32,12 +32,12 @@ class MainRouter < Router
end end
end end
get "/" do |env| get "/library" do |env|
begin begin
titles = @context.library.titles titles = @context.library.titles
username = get_username env username = get_username env
percentage = titles.map &.load_percentage username percentage = titles.map &.load_percentage username
layout "index" layout "library"
rescue e rescue e
@context.error e @context.error e
env.response.status_code = 500 env.response.status_code = 500
@ -62,5 +62,23 @@ class MainRouter < Router
base_url = @context.config.mangadex["base_url"] base_url = @context.config.mangadex["base_url"]
layout "download" layout "download"
end end
get "/" do |env|
begin
titles = @context.library.titles
username = get_username env
on_deck_entries = [] of Entry
titles.each do |title|
on_deck_entry = title.get_on_deck_entry username
on_deck_entries << on_deck_entry if on_deck_entry # ingnore titles without latest on deck entry
end
layout "home"
rescue e
@context.error e
env.response.status_code = 500
end
end
end end
end end

62
src/views/home.ecr Normal file
View File

@ -0,0 +1,62 @@
<%- unless on_deck_entries.empty? -%>
<h2 class="uk-title home-headings">On Deck</h2>
<div id="item-container-continue" class="uk-child-width-1-4@m uk-child-width-1-2" uk-grid>
<%- on_deck_entries.each_with_index do |e, i| -%>
<div class="item" data-mtime="<%= e.mtime.to_unix %>" data-progress="" id="<%= e.id %>"> <!-- TODO: add percentage -->
<a class="acard"> <!-- Add percentage rounded below v -->
<div class="uk-card uk-card-default" onclick="showModal(&quot;<%= e.encoded_path %>&quot;, '<%= e.pages %>', <%= "0" %>, &quot;<%= e.book.encoded_display_name %>&quot;, &quot;<%= e.encoded_display_name %>&quot;, '<%= e.title_id %>', '<%= e.id %>')">
<div class="uk-card-media-top">
<img data-src="<%= e.cover_url %>" alt="" data-width data-height uk-img>
</div>
<div class="uk-card-body">
<div class="uk-card-badge uk-label"><%= "" %>%</div> <!-- TODO: add percentage rounded -->
<h3 class="uk-card-title break-word" data-title="<%= e.display_name.gsub("\"", "&quot;") %>"><%= e.display_name %></h3>
<p><%= e.pages %> pages</p>
</div>
</div>
</a>
</div>
<%- end -%>
</div>
<%- end -%>
<!-- TODO: DRY this code with calls in other ecr files? eg. title.ecr -->
<div id="modal" class="uk-flex-top" uk-modal>
<div class="uk-modal-dialog uk-margin-auto-vertical">
<button class="uk-modal-close-default" type="button" uk-close></button>
<div class="uk-modal-header">
<div>
<h3 class="uk-modal-title break-word" id="modal-title"><span></span>
&nbsp;
<% if is_admin %>
<a class="uk-icon-button" uk-icon="icon:pencil"></a>
<% end %>
</h3>
</div>
<p class="uk-text-meta uk-margin-remove-bottom break-word" id="path-text"></p>
<p class="uk-text-meta uk-margin-remove-top" id="pages-text"></p>
</div>
<div class="uk-modal-body">
<p>Read</p>
<p uk-margin>
<a id="beginning-btn" class="uk-button uk-button-default">From beginning</a>
<a id="continue-btn" class="uk-button uk-button-primary"></a>
</p>
<p>Progress</p>
<p uk-margin>
<button id="read-btn" class="uk-button uk-button-default">Mark as read (100%)</button>
<button id="unread-btn" class="uk-button uk-button-default">Mark as unread (0%)</button>
</p>
</div>
</div>
</div>
<% content_for "script" do %>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jQuery.dotdotdot/4.0.11/dotdotdot.js"></script>
<script src="/js/dots.js"></script>
<script src="/js/alert.js"></script>
<script src="/js/title.js"></script>
<script src="/js/search.js"></script>
<script src="/js/sort-items.js"></script>
<% end %>

View File

@ -42,6 +42,7 @@
<a class="uk-navbar-item uk-logo" href="/"><img src="/img/icon.png"></a> <a class="uk-navbar-item uk-logo" href="/"><img src="/img/icon.png"></a>
<ul class="uk-navbar-nav"> <ul class="uk-navbar-nav">
<li><a href="/">Home</a></li> <li><a href="/">Home</a></li>
<li><a href="/library">Library</a></li>
<% if is_admin %> <% if is_admin %>
<li><a href="/admin">Admin</a></li> <li><a href="/admin">Admin</a></li>
<li><a href="/download">Download</a></li> <li><a href="/download">Download</a></li>