| @@ -18,6 +18,7 @@ gem 'filewatcher', '~> 0.5.3' | |||||
| [Docsplit](http://documentcloud.github.io/docsplit/#installation) | [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 graphicsmagick | ||||
| sudo apt-get --no-install-recommends install poppler-data | sudo apt-get --no-install-recommends install poppler-data | ||||
| sudo apt-get --no-install-recommends install ghostscript | sudo apt-get --no-install-recommends install ghostscript | ||||
| @@ -6,6 +6,8 @@ class DocumentsController < ApplicationController | |||||
| def index | def index | ||||
| if params[:search] | if params[:search] | ||||
| @documents = User.find(session[:user_id]).documents.contains_word(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 | else | ||||
| @documents = User.find(session[:user_id]).documents | @documents = User.find(session[:user_id]).documents | ||||
| end | end | ||||
| @@ -6,6 +6,7 @@ class Document < ApplicationRecord | |||||
| has_attached_file :doc, | has_attached_file :doc, | ||||
| { | { | ||||
| styles: { thumb: ["200x", :png] }, | |||||
| adapter_options: { hash_digest: Digest::SHA256 }, | adapter_options: { hash_digest: Digest::SHA256 }, | ||||
| url: "/system/:class/:attachment/:id_partition/:style/:hash.:extension", | url: "/system/:class/:attachment/:id_partition/:style/:hash.:extension", | ||||
| hash_secret: Rails.application.secrets.secret_key_base | hash_secret: Rails.application.secrets.secret_key_base | ||||
| @@ -15,7 +16,7 @@ class Document < ApplicationRecord | |||||
| after_save :generate_content | after_save :generate_content | ||||
| scope :contains_word, -> (word) { joins(:content).where("text like ?", "%#{word}%") } | scope :contains_word, -> (word) { joins(:content).where("text like ?", "%#{word}%") } | ||||
| scope :belongs_to_category, -> (category_id) { where(category_id: category_id ) } | |||||
| private | private | ||||
| def generate_content | def generate_content | ||||
| @@ -6,7 +6,8 @@ | |||||
| <thead> | <thead> | ||||
| <tr> | <tr> | ||||
| <th>Name</th> | <th>Name</th> | ||||
| <th colspan="3"></th> | |||||
| <th># documents</th> | |||||
| <th colspan="4"></th> | |||||
| </tr> | </tr> | ||||
| </thead> | </thead> | ||||
| @@ -14,7 +15,9 @@ | |||||
| <% @categories.order(:name).each do |category| %> | <% @categories.order(:name).each do |category| %> | ||||
| <tr> | <tr> | ||||
| <td><%= category.get_fqcn %></td> | <td><%= category.get_fqcn %></td> | ||||
| <td><%= category.documents.count %></td> | |||||
| <td><%= link_to 'Show', category %></td> | <td><%= link_to 'Show', category %></td> | ||||
| <td><%= link_to 'Show documents in category', documents_path(category: category.id) %></td> | |||||
| <td><%= link_to 'Edit', edit_category_path(category) %></td> | <td><%= link_to 'Edit', edit_category_path(category) %></td> | ||||
| <td><%= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %></td> | <td><%= link_to 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %></td> | ||||
| </tr> | </tr> | ||||
| @@ -5,6 +5,7 @@ | |||||
| <table> | <table> | ||||
| <thead> | <thead> | ||||
| <tr> | <tr> | ||||
| <th>Category</th> | |||||
| <th>Name</th> | <th>Name</th> | ||||
| <th colspan="3"></th> | <th colspan="3"></th> | ||||
| </tr> | </tr> | ||||
| @@ -13,6 +14,7 @@ | |||||
| <tbody> | <tbody> | ||||
| <% @documents.each do |document| %> | <% @documents.each do |document| %> | ||||
| <tr> | <tr> | ||||
| <td><%= document.category.get_fqcn %></td> | |||||
| <td><%= document.name %></td> | <td><%= document.name %></td> | ||||
| <td><%= link_to 'Show', document %></td> | <td><%= link_to 'Show', document %></td> | ||||
| <td><%= link_to 'Edit', edit_document_path(document) %></td> | <td><%= link_to 'Edit', edit_document_path(document) %></td> | ||||
| @@ -10,9 +10,15 @@ | |||||
| <%= @document.category.get_fqcn %> | <%= @document.category.get_fqcn %> | ||||
| </p> | </p> | ||||
| <p> | |||||
| <%= link_to @document.doc_file_name, @document.doc.url %> | |||||
| </p> | |||||
| <% if File.exists?(@document.doc.path(:thumb)) %> | |||||
| <p> | |||||
| <%= link_to image_tag(@document.doc.url(:thumb), alt: 'Thumbnail of PDF'), @document.doc.url %> | |||||
| </p> | |||||
| <% else %> | |||||
| <p> | |||||
| <%= link_to @document.doc_file_name, @document.doc.url %> | |||||
| </p> | |||||
| <% end %> | |||||
| <% if @document.content %> | <% if @document.content %> | ||||
| <p> | <p> | ||||