diff --git a/README.md b/README.md index c7bd3fc..5f32267 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ gem 'filewatcher', '~> 0.5.3' [Docsplit](http://documentcloud.github.io/docsplit/#installation) ``` +sudo apt-get install imagemagick sudo apt-get --no-install-recommends install graphicsmagick sudo apt-get --no-install-recommends install poppler-data sudo apt-get --no-install-recommends install ghostscript diff --git a/app/controllers/documents_controller.rb b/app/controllers/documents_controller.rb index bedcbdf..096c45a 100644 --- a/app/controllers/documents_controller.rb +++ b/app/controllers/documents_controller.rb @@ -6,6 +6,8 @@ class DocumentsController < ApplicationController def index if params[:search] @documents = User.find(session[:user_id]).documents.contains_word(params[:search]) + elsif params[:category] + @documents = User.find(session[:user_id]).documents.belongs_to_category(params[:category]) else @documents = User.find(session[:user_id]).documents end diff --git a/app/models/document.rb b/app/models/document.rb index f20888e..9107288 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -6,6 +6,7 @@ class Document < ApplicationRecord has_attached_file :doc, { + styles: { thumb: ["200x", :png] }, adapter_options: { hash_digest: Digest::SHA256 }, url: "/system/:class/:attachment/:id_partition/:style/:hash.:extension", hash_secret: Rails.application.secrets.secret_key_base @@ -15,7 +16,7 @@ class Document < ApplicationRecord after_save :generate_content scope :contains_word, -> (word) { joins(:content).where("text like ?", "%#{word}%") } - + scope :belongs_to_category, -> (category_id) { where(category_id: category_id ) } private def generate_content diff --git a/app/views/categories/index.html.erb b/app/views/categories/index.html.erb index d28af96..d45d5b0 100644 --- a/app/views/categories/index.html.erb +++ b/app/views/categories/index.html.erb @@ -6,7 +6,8 @@ Name - + # documents + @@ -14,7 +15,9 @@ <% @categories.order(:name).each do |category| %> <%= category.get_fqcn %> + <%= category.documents.count %> <%= link_to 'Show', category %> + <%= link_to 'Show documents in category', documents_path(category: category.id) %> <%= link_to 'Edit', edit_category_path(category) %> <%= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %> diff --git a/app/views/documents/index.html.erb b/app/views/documents/index.html.erb index 8802042..bebb3a9 100644 --- a/app/views/documents/index.html.erb +++ b/app/views/documents/index.html.erb @@ -5,6 +5,7 @@ + @@ -13,6 +14,7 @@ <% @documents.each do |document| %> + diff --git a/app/views/documents/show.html.erb b/app/views/documents/show.html.erb index 0a37380..4f14c92 100644 --- a/app/views/documents/show.html.erb +++ b/app/views/documents/show.html.erb @@ -10,9 +10,15 @@ <%= @document.category.get_fqcn %>

-

- <%= link_to @document.doc_file_name, @document.doc.url %> -

+<% if File.exists?(@document.doc.path(:thumb)) %> +

+ <%= link_to image_tag(@document.doc.url(:thumb), alt: 'Thumbnail of PDF'), @document.doc.url %> +

+<% else %> +

+ <%= link_to @document.doc_file_name, @document.doc.url %> +

+<% end %> <% if @document.content %>

Category Name
<%= document.category.get_fqcn %> <%= document.name %> <%= link_to 'Show', document %> <%= link_to 'Edit', edit_document_path(document) %>