Browse Source

Some stuff added to categories and some views.

master
Nils Dittberner 9 years ago
parent
commit
5e58ce2e95
6 changed files with 20 additions and 5 deletions
  1. +1
    -0
      README.md
  2. +2
    -0
      app/controllers/documents_controller.rb
  3. +2
    -1
      app/models/document.rb
  4. +4
    -1
      app/views/categories/index.html.erb
  5. +2
    -0
      app/views/documents/index.html.erb
  6. +9
    -3
      app/views/documents/show.html.erb

+ 1
- 0
README.md View File

@@ -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


+ 2
- 0
app/controllers/documents_controller.rb View File

@@ -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


+ 2
- 1
app/models/document.rb View File

@@ -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


+ 4
- 1
app/views/categories/index.html.erb View File

@@ -6,7 +6,8 @@
<thead>
<tr>
<th>Name</th>
<th colspan="3"></th>
<th># documents</th>
<th colspan="4"></th>
</tr>
</thead>

@@ -14,7 +15,9 @@
<% @categories.order(:name).each do |category| %>
<tr>
<td><%= category.get_fqcn %></td>
<td><%= category.documents.count %></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 'Destroy', category, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>


+ 2
- 0
app/views/documents/index.html.erb View File

@@ -5,6 +5,7 @@
<table>
<thead>
<tr>
<th>Category</th>
<th>Name</th>
<th colspan="3"></th>
</tr>
@@ -13,6 +14,7 @@
<tbody>
<% @documents.each do |document| %>
<tr>
<td><%= document.category.get_fqcn %></td>
<td><%= document.name %></td>
<td><%= link_to 'Show', document %></td>
<td><%= link_to 'Edit', edit_document_path(document) %></td>


+ 9
- 3
app/views/documents/show.html.erb View File

@@ -10,9 +10,15 @@
<%= @document.category.get_fqcn %>
</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 %>
<p>


Loading…
Cancel
Save