view author

This commit is contained in:
Meutel 2015-07-05 20:31:36 +02:00
parent 346ccf6449
commit 308f43b967
9 changed files with 82 additions and 2 deletions

View File

@ -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

View 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>

View File

@ -0,0 +1 @@
TODO

View 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>

View File

@ -0,0 +1 @@
$("#tabcontent").html("<%= escape_javascript(render(partial: "authors/authors")) %>");

View File

@ -0,0 +1 @@
$("#tabcontent").html("<%= escape_javascript(render(partial: "authors/series")) %>");

View File

@ -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>

View File

@ -0,0 +1 @@
$("#tabcontent").html("<%= escape_javascript(render(partial: "authors/titles")) %>");

View File

@ -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'