From 54011e5ca586c6baf1afa4251cfb956ed02e530e Mon Sep 17 00:00:00 2001 From: Archer Lin Date: Thu, 4 Oct 2018 17:44:54 +0800 Subject: [PATCH] add journal show --- app/controllers/admin/chapters_controller.rb | 3 +- app/controllers/admin/journals_controller.rb | 4 +- app/controllers/journals_controller.rb | 39 ++++++++++++++++---- app/views/admin/chapters/edit.html.erb | 2 +- app/views/admin/journals/show.html.erb | 7 +++- app/views/journals/show.html.erb | 4 +- config/locales/en.yml | 2 + config/locales/zh_tw.yml | 2 + 8 files changed, 47 insertions(+), 16 deletions(-) diff --git a/app/controllers/admin/chapters_controller.rb b/app/controllers/admin/chapters_controller.rb index ef06f67..84db07b 100644 --- a/app/controllers/admin/chapters_controller.rb +++ b/app/controllers/admin/chapters_controller.rb @@ -5,9 +5,8 @@ class Admin::ChaptersController < OrbitAdminController end def index - @table_fields = [:title, :author, :page, :author_description] + @table_fields = [:title, :author, :page, :sort_number] @chapters = Chapter.order_by(sort).page(params[:page]).per(10) - render partial: "index" if request.xhr? end diff --git a/app/controllers/admin/journals_controller.rb b/app/controllers/admin/journals_controller.rb index 337ffea..3065d1a 100644 --- a/app/controllers/admin/journals_controller.rb +++ b/app/controllers/admin/journals_controller.rb @@ -33,8 +33,8 @@ class Admin::JournalsController < OrbitAdminController def show @journal = Journal.find(params[:id]) - @chapters = @journal.chapters.page(params[:page]).per(10) - @table_fields = [:title, :author, :page] + @chapters = @journal.chapters.order_by(sort).page(params[:page]).per(10) + @table_fields = [:title, :author, :page, :sort_number] end def destroy diff --git a/app/controllers/journals_controller.rb b/app/controllers/journals_controller.rb index eb29622..d43135c 100644 --- a/app/controllers/journals_controller.rb +++ b/app/controllers/journals_controller.rb @@ -30,7 +30,9 @@ class JournalsController < ApplicationController pub_date: node.pub_date.strftime('%Y-%m-%d'), cover: (OrbitHelper.is_mobile_view ? node.cover.mobile.url : node.cover.url), chapters: node.chapters.count, - link_to_show: OrbitHelper.url_to_show("#{node.to_param}?list=journal"), + link_to_show: OrbitHelper.url_to_show("#{node.to_param}?mode=journal"), + link_to_list: OrbitHelper.url_to_show("#{node.to_param}?mode=many"), + } end { @@ -51,10 +53,12 @@ class JournalsController < ApplicationController def show params = OrbitHelper.params - if params[:list] == 'journal' - show_journal - else + if params[:mode] == 'many' + show_list + elsif params[:mode] == 'chapter' show_chapter + else + show_journal end end @@ -64,7 +68,7 @@ class JournalsController < ApplicationController private - def show_journal + def show_list params = OrbitHelper.params journal = Journal.find_by(uid: params[:uid]) chapters = Chapter.where(journal_id: journal.id).page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) @@ -76,8 +80,7 @@ class JournalsController < ApplicationController author: node.author, author_description: node.author_description, page: node.page, - text: node.text, - link_to_show: OrbitHelper.url_to_show("#{node.to_param}?list=chapter"), + link_to_show: OrbitHelper.url_to_show("#{node.to_param}?mode=chapter"), file: (node.file.present? ? node.file.url : ''), file_class: (node.file.present? ? '' : 'hidden') } @@ -110,7 +113,27 @@ class JournalsController < ApplicationController "text" => chapter.text, "text_title" => t('chapter.text'), "extras" => { - "mode" => "one" + "mode" => "chapter" + } + } + end + + def show_journal + params = OrbitHelper.params + journal = Journal.find_by(uid: params[:uid]) + { + "title" => journal.title, + "title_title" => t('journal.title'), + "author" => journal.author, + "author_title" => t('journal.author'), + "cover" => journal.cover.url, + "cover_title" => t('journal.cover'), + "pub_date" => journal.pub_date, + "pub_date_title" => t('journal.pub_date'), + "pub_information" => journal.pub_information, + "pub_information_title" => t('journal.pub_information'), + "extras" => { + "mode" => "journal" } } end diff --git a/app/views/admin/chapters/edit.html.erb b/app/views/admin/chapters/edit.html.erb index cb17efa..a3c8541 100644 --- a/app/views/admin/chapters/edit.html.erb +++ b/app/views/admin/chapters/edit.html.erb @@ -1,3 +1,3 @@ -<%= form_for @chapter, url: admin_chapter_path(@chapter), html: {class: "form-horizontal main-forms"} do |f| %> +<%= form_for @chapter, url: {action: :update}, html: {class: "form-horizontal main-forms"} do |f| %> <%= render partial: 'form', locals: {f: f} %> <% end %> diff --git a/app/views/admin/journals/show.html.erb b/app/views/admin/journals/show.html.erb index ed81389..17abecb 100644 --- a/app/views/admin/journals/show.html.erb +++ b/app/views/admin/journals/show.html.erb @@ -55,7 +55,10 @@ <%= chapter.page %> + + <%= chapter.sort_number %> + <% end %> @@ -73,14 +76,14 @@