From aa3584f66a3f48f6f66147f1fa7f1806281e97f0 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Mon, 7 Aug 2017 15:46:44 +0800 Subject: [PATCH] added few modifications --- app/controllers/e_papers_controller.rb | 36 +++++++++------ app/models/paper.rb | 1 + app/models/topic.rb | 3 -- app/views/admin/e_papers/_form.html.erb | 37 +++++++++++++-- app/views/admin/e_papers/_index.html.erb | 2 +- app/views/admin/e_papers/show.html.erb | 2 +- app/views/admin/topics/_form.html.erb | 59 ++++++++++++++++++++++-- 7 files changed, 116 insertions(+), 24 deletions(-) diff --git a/app/controllers/e_papers_controller.rb b/app/controllers/e_papers_controller.rb index dd82d52..4679904 100644 --- a/app/controllers/e_papers_controller.rb +++ b/app/controllers/e_papers_controller.rb @@ -49,17 +49,22 @@ class EPapersController < ApplicationController def show params = OrbitHelper.params paper = Paper.find_by(:uid => params[:uid]) - - topics = paper.topics.collect do |topic| - desc = ActionView::Base.full_sanitizer.sanitize(topic.content) - { - "link_to_show" => OrbitHelper.url_to_show(topic.to_param) + "?method=showtopic", - "episode" => topic.episode, - "content" => topic.content, - "description" => desc[0..100], - "publish_date" => topic.created_at - } - end + paper_thumb = !paper.image.nil? && !paper.image.url.nil? ? paper.image.thumb.url : "http://www.placehold.it/400x400/EFEFEF/AAAAAA" + paper_full = !paper.image.nil? && !paper.image.url.nil? ? paper.image.url : "http://www.placehold.it/1000x1000/EFEFEF/AAAAAA" + topics = paper.topics.collect do |topic| + desc = ActionView::Base.full_sanitizer.sanitize(topic.content) + timg = !topic.image.nil? && !topic.image.url.nil? ? topic.image.thumb.url : "http://www.placehold.it/400x400/EFEFEF/AAAAAA" + fimg = !topic.image.nil? && !topic.image.url.nil? ? topic.image.url : "http://www.placehold.it/1000x1000/EFEFEF/AAAAAA" + { + "link_to_show" => OrbitHelper.url_to_show(topic.to_param) + "?method=showtopic", + "episode" => topic.episode, + "content" => topic.content, + "description" => desc[0..100], + "publish_date" => topic.created_at, + "image_thumb" => timg, + "image_full" => fimg + } + end { "data" => { "title" => paper.title, @@ -67,6 +72,8 @@ class EPapersController < ApplicationController "description" => paper.description, "category" => paper.category.title, "publish_date" => paper.created_at, + "paper_thumb_image" => paper_thumb, + "paper_full_image" => paper_full, "th_title" => t('e_paper.title'), "th_category" => t('category'), "th_period" => t('e_paper.period'), @@ -111,11 +118,14 @@ class EPapersController < ApplicationController def showtopic params = OrbitHelper.params topic = Topic.where(:uid => params[:uid]).first - + timg = !topic.image.nil? && !topic.image.url.nil? ? topic.image.thumb.url : "http://www.placehold.it/400x400/EFEFEF/AAAAAA" + fimg = !topic.image.nil? && !topic.image.url.nil? ? topic.image.url : "http://www.placehold.it/1000x1000/EFEFEF/AAAAAA" { "episode" => topic.episode, "content" => topic.content, - "publish_date" => topic.created_at + "publish_date" => topic.created_at, + "image_thumb" => timg, + "image_full" => fimg } end diff --git a/app/models/paper.rb b/app/models/paper.rb index 8c90db9..b9f9f2f 100644 --- a/app/models/paper.rb +++ b/app/models/paper.rb @@ -12,6 +12,7 @@ class Paper field :mailed, type: Boolean, default: false field :ready_to_send, type: Boolean, default: false + mount_uploader :image, ImageUploader has_many :topics, :dependent => :destroy diff --git a/app/models/topic.rb b/app/models/topic.rb index 4c77d28..2ca74ae 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -2,9 +2,6 @@ class Topic include Mongoid::Document include Mongoid::Timestamps - - include OrbitCategory::Categorizable - include OrbitTag::Taggable include Slug diff --git a/app/views/admin/e_papers/_form.html.erb b/app/views/admin/e_papers/_form.html.erb index e3758e8..a3343e2 100644 --- a/app/views/admin/e_papers/_form.html.erb +++ b/app/views/admin/e_papers/_form.html.erb @@ -7,8 +7,6 @@ <%= javascript_include_tag "lib/bootstrap-fileupload" %> <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> - <%= javascript_include_tag "lib/modal-preview" %> - <%= javascript_include_tag "lib/file-type" %> <% end %> <%#= f.error_messages %>
@@ -21,6 +19,9 @@
  • <%= t(:basic) %>
  • +
  • + <%= t(:image) %> +
  • @@ -38,8 +39,38 @@ +
    - + +
    + +
    +
    +
    + <% if @paper.image.file %> + <%= image_tag @paper.image %> + <% else %> + + <% end %> +
    +
    + + <%= t(:select_image) %> + <%= t(:change) %> + <%= f.file_field :image %> + + <%= t(:cancel) %> +
    + +
    +
    +
    +
    +
    + +