From 308f43b967f2fce1ca28f6529ed781fad0695147 Mon Sep 17 00:00:00 2001 From: Meutel Date: Sun, 5 Jul 2015 20:31:36 +0200 Subject: [PATCH] view author --- app/controllers/authors_controller.rb | 38 +++++++++++++++++++++++++++ app/views/authors/_authors.html.erb | 6 +++++ app/views/authors/_series.html.erb | 1 + app/views/authors/_titles.html.erb | 6 +++++ app/views/authors/authors.js.erb | 1 + app/views/authors/series.js.erb | 1 + app/views/authors/show.html.erb | 22 +++++++++++++++- app/views/authors/titles.js.erb | 1 + config/routes.rb | 8 +++++- 9 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 app/views/authors/_authors.html.erb create mode 100644 app/views/authors/_series.html.erb create mode 100644 app/views/authors/_titles.html.erb create mode 100644 app/views/authors/authors.js.erb create mode 100644 app/views/authors/series.js.erb create mode 100644 app/views/authors/titles.js.erb diff --git a/app/controllers/authors_controller.rb b/app/controllers/authors_controller.rb index dd919ce..098e283 100644 --- a/app/controllers/authors_controller.rb +++ b/app/controllers/authors_controller.rb @@ -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 diff --git a/app/views/authors/_authors.html.erb b/app/views/authors/_authors.html.erb new file mode 100644 index 0000000..66b5806 --- /dev/null +++ b/app/views/authors/_authors.html.erb @@ -0,0 +1,6 @@ +

<%= pluralize(@authors.count, "co-author") %>

+ diff --git a/app/views/authors/_series.html.erb b/app/views/authors/_series.html.erb new file mode 100644 index 0000000..1333ed7 --- /dev/null +++ b/app/views/authors/_series.html.erb @@ -0,0 +1 @@ +TODO diff --git a/app/views/authors/_titles.html.erb b/app/views/authors/_titles.html.erb new file mode 100644 index 0000000..fe12681 --- /dev/null +++ b/app/views/authors/_titles.html.erb @@ -0,0 +1,6 @@ +

<%= pluralize(@books.count, "book") %>

+ diff --git a/app/views/authors/authors.js.erb b/app/views/authors/authors.js.erb new file mode 100644 index 0000000..a10d277 --- /dev/null +++ b/app/views/authors/authors.js.erb @@ -0,0 +1 @@ +$("#tabcontent").html("<%= escape_javascript(render(partial: "authors/authors")) %>"); diff --git a/app/views/authors/series.js.erb b/app/views/authors/series.js.erb new file mode 100644 index 0000000..5b791cd --- /dev/null +++ b/app/views/authors/series.js.erb @@ -0,0 +1 @@ +$("#tabcontent").html("<%= escape_javascript(render(partial: "authors/series")) %>"); diff --git a/app/views/authors/show.html.erb b/app/views/authors/show.html.erb index db6dddd..6e8144d 100644 --- a/app/views/authors/show.html.erb +++ b/app/views/authors/show.html.erb @@ -1 +1,21 @@ -

<%= @author.name %>

+ + +
+<% @tabs.each do |tab| + if tab[:active] %> +<%= render(partial: "authors/#{ tab[:action]}") %> +<% end +end %> +
diff --git a/app/views/authors/titles.js.erb b/app/views/authors/titles.js.erb new file mode 100644 index 0000000..49681eb --- /dev/null +++ b/app/views/authors/titles.js.erb @@ -0,0 +1 @@ +$("#tabcontent").html("<%= escape_javascript(render(partial: "authors/titles")) %>"); diff --git a/config/routes.rb b/config/routes.rb index de6af97..af5e0d0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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'