view author
This commit is contained in:
parent
346ccf6449
commit
308f43b967
@ -6,6 +6,13 @@ class AuthorsController < ApplicationController
|
||||
def show
|
||||
@author = Author.find(params[:id])
|
||||
@title = @author.name
|
||||
@tabs = [
|
||||
{ action: :titles, label: "Titles", active: true, icon: "book" },
|
||||
{ action: :series, label: "Series", active: false, icon: "list" },
|
||||
{ action: :authors, label: "Co-Authors", active: false, icon: "user" },
|
||||
]
|
||||
# active tab
|
||||
titles
|
||||
end
|
||||
|
||||
def index
|
||||
@ -18,4 +25,35 @@ class AuthorsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def titles
|
||||
@author = Author.find(params[:id])
|
||||
@books = @author.books.sort{|b1,b2|b1.sort <=> b2.sort}
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def series
|
||||
@author = Author.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def authors
|
||||
@author = Author.find(params[:id])
|
||||
@authors = Array.new
|
||||
@author.books.each do |b|
|
||||
@authors.concat b.authors
|
||||
end
|
||||
@authors.uniq!
|
||||
@authors.select! {|a| a != @author}
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
6
app/views/authors/_authors.html.erb
Normal file
6
app/views/authors/_authors.html.erb
Normal file
@ -0,0 +1,6 @@
|
||||
<h2><%= pluralize(@authors.count, "co-author") %></h2>
|
||||
<ul>
|
||||
<% @authors.each do |a| %>
|
||||
<li><%= link_to a.name, a %></li>
|
||||
<% end %>
|
||||
</ul>
|
1
app/views/authors/_series.html.erb
Normal file
1
app/views/authors/_series.html.erb
Normal file
@ -0,0 +1 @@
|
||||
TODO
|
6
app/views/authors/_titles.html.erb
Normal file
6
app/views/authors/_titles.html.erb
Normal file
@ -0,0 +1,6 @@
|
||||
<h2><%= pluralize(@books.count, "book") %></h2>
|
||||
<ul>
|
||||
<% @books.each do |b| %>
|
||||
<li><%= link_to b.title, b %></li>
|
||||
<% end %>
|
||||
</ul>
|
1
app/views/authors/authors.js.erb
Normal file
1
app/views/authors/authors.js.erb
Normal file
@ -0,0 +1 @@
|
||||
$("#tabcontent").html("<%= escape_javascript(render(partial: "authors/authors")) %>");
|
1
app/views/authors/series.js.erb
Normal file
1
app/views/authors/series.js.erb
Normal file
@ -0,0 +1 @@
|
||||
$("#tabcontent").html("<%= escape_javascript(render(partial: "authors/series")) %>");
|
@ -1 +1,21 @@
|
||||
<h1><%= @author.name %></h1>
|
||||
<div class="page-header">
|
||||
<h1>
|
||||
<span class="glyphicon glyphicon-user"></span> <%= @author.name %>
|
||||
</h1>
|
||||
</div>
|
||||
<ul id="tabs" class="nav nav-tabs">
|
||||
<% @tabs.each do |tab| %>
|
||||
<li role="presentation" class="<%= tab[:active] ? "active" : "" %>">
|
||||
<%= link_to({ controller: "authors", action: tab[:action], id: @author}, { data: { toggle: 'tab', target: tab[:action] }, remote: true }) do %>
|
||||
<span class="glyphicon glyphicon-<%= tab[:icon] %>"></span> <%= tab[:label] %>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<div id="tabcontent" class="tab-content">
|
||||
<% @tabs.each do |tab|
|
||||
if tab[:active] %>
|
||||
<%= render(partial: "authors/#{ tab[:action]}") %>
|
||||
<% end
|
||||
end %>
|
||||
</div>
|
||||
|
1
app/views/authors/titles.js.erb
Normal file
1
app/views/authors/titles.js.erb
Normal file
@ -0,0 +1 @@
|
||||
$("#tabcontent").html("<%= escape_javascript(render(partial: "authors/titles")) %>");
|
@ -6,7 +6,13 @@ Rails.application.routes.draw do
|
||||
get 'cover', on: :member
|
||||
end
|
||||
get '/books/:id/data/:data_format/' => 'data#show', as: "book_data"
|
||||
resources :authors, only: [ :index, :show ]
|
||||
resources :authors, only: [ :index, :show ] do
|
||||
member do
|
||||
get 'titles'
|
||||
get 'series'
|
||||
get 'authors'
|
||||
end
|
||||
end
|
||||
resources :series, only: [ :index, :show ]
|
||||
#get 'series/:id' => 'series#show'
|
||||
#get 'series' => 'series#index'
|
||||
|
Loading…
Reference in New Issue
Block a user