Skip to content

Commit

Permalink
Document uploads, revisions, and grid view for documents
Browse files Browse the repository at this point in the history
  • Loading branch information
gbprz committed Jul 15, 2014
1 parent a53844a commit 62026ea
Show file tree
Hide file tree
Showing 54 changed files with 114 additions and 24 deletions.
Binary file added app/assets/images/icons/eye_icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/eye_icon.psd
Binary file not shown.
Binary file added app/assets/images/icons/fp_ex.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/fs_logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_doc.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_doc_40.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_doc_50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_folder.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_folder_50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_odp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_odp_40.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_odp_50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_ods.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_ods_40.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_ods_50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_odt.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_odt_40.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_odt_50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_other.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_other_40.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_other_50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_pdf.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_pdf_40.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_pdf_50.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_ppt.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/assets/images/icons/icon_ppt_40.png
Binary file added app/assets/images/icons/icon_ppt_50.png
Binary file added app/assets/images/icons/icon_xls.png
Binary file added app/assets/images/icons/icon_xls_40.png
Binary file added app/assets/images/icons/icon_xls_50.png
Binary file added app/assets/images/icons/noeye_icon.png
Binary file added app/assets/images/icons/nowrite_icon.png
Binary file added app/assets/images/icons/search_button.png
Binary file added app/assets/images/icons/search_ex.png
Binary file added app/assets/images/icons/search_ex_hover.png
Binary file added app/assets/images/icons/tipsy-east.gif
Binary file added app/assets/images/icons/tipsy-north.gif
Binary file added app/assets/images/icons/tipsy-south.gif
Binary file added app/assets/images/icons/tipsy-west.gif
Binary file added app/assets/images/icons/write_icon.png
Binary file added app/assets/images/icons/write_icon.psd
Diff not rendered.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Expand Up @@ -14,5 +14,6 @@
//= require jquery_ujs
//= require bootstrap
//= require bootstrap/modal
//= require bootstrap/alert
//= require turbolinks
//= require_tree .
7 changes: 6 additions & 1 deletion app/assets/stylesheets/application.css.scss
Expand Up @@ -22,4 +22,9 @@ $btn-default-color: #FFFFFF;
$input-border-focus: #CC0000;

@import "bootstrap";
@import "bootstrap/theme";
@import "bootstrap/theme";

.alert {
margin-left: 0px;
border-radius: 0px;
}
5 changes: 5 additions & 0 deletions app/assets/stylesheets/documents.css.scss
@@ -1,3 +1,8 @@
// Place all the styles related to the documents controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

.document_tile {
padding: 2px;
border: 1px solid grey;
}
2 changes: 1 addition & 1 deletion app/controllers/categories_controller.rb
Expand Up @@ -8,7 +8,7 @@ def index
def show
@category = Category.find params[:id]
@subcategories = @category.children
@documents = Document.where(category_id: @category.id)
@documents = Document.where(category_id: @category.id).each_slice(5).to_a

respond_to do |format|
format.html {}
Expand Down
30 changes: 28 additions & 2 deletions app/controllers/documents_controller.rb
@@ -1,11 +1,33 @@
class DocumentsController < ApplicationController

def show
@document = Document.find_by_id(params[:id])
if !@document.nil?
@document = @document.current_revision.last
send_data(@document.file_data, :type => @document.file_type, :filename => @document.file_name, :disposition => "inline")
else
flash[:error] = "Could not find document"
redirect_to root_path
end
end

def create
@document = Document.new(document_params)

category = Category.find_by_id(@document.category_id)
if !@document.save
flash[:error] = "Unable to upload document :("
flash[:error] = "Unable to upload document"
else
# Create the initial revision of the new document
@revision = Revision.new(file_name: revision_params.original_filename,
file_type: revision_params.content_type,
file_data: revision_params.read,
document_id: @document.id,
position: 0
)
if !@revision.save
flash[:error] = "Unable to upload revision"
end
end

if !category.nil?
Expand All @@ -20,4 +42,8 @@ def document_params
params.require(:document).permit(:title, :description,
:category_id, :is_writeable, :is_private, :category_id)
end
end

def revision_params
params[:document][:revision][:file]
end
end
8 changes: 8 additions & 0 deletions app/helpers/documents_helper.rb
@@ -1,2 +1,10 @@
module DocumentsHelper

def document_icon(extension)
case extension
when "pdf" then "icon_pdf.png"
else "icon_other.png"
end
end

end
8 changes: 8 additions & 0 deletions app/models/document.rb
@@ -1,2 +1,10 @@
class Document < ActiveRecord::Base

belongs_to :user
has_many :revisions, dependent: :destroy

def current_revision
Revision.where(document_id: id).order("created_at desc")
end

end
18 changes: 14 additions & 4 deletions app/models/revision.rb
@@ -1,10 +1,20 @@
class Revision < ActiveRecord::Base

attachable
belongs_to :document
belongs_to :user

validates :file_name, presence: true
validates :file_type, presence: true
validates :file_size, numericality: { only_integer: true }
validates_associated :document


def extension_type
ext = case file_type
# PDF Files
when "application/pdf" then "pdf"
when "application/msword" then "doc"
when "application/vnd.oasis.opendocument.text" then "odt"
else "other"
end
ext
end

end
8 changes: 6 additions & 2 deletions app/views/categories/_documents.html.erb
@@ -1,7 +1,11 @@
<div class="categories_grid">
<% if @documents %>
<% @documents.each do |doc| %>
<%= doc.title %><br />
<% @documents.each do |doc_row| %>
<div class="row">
<% doc_row.each do |doc| %>
<%= render partial: "documents/document_tile", locals: { doc: doc } %>
<% end %>
</div>
<% end %>
<% end %>
</div>
32 changes: 18 additions & 14 deletions app/views/categories/_form.html.erb
@@ -1,24 +1,28 @@
<%= form_for :document, html: { multipart: true }, url: documents_path, method: :post do |f| %>
<div class="modal-body">
<%= f.label :title %>
<%= f.text_field :title %>
<div class="form-group">
<%= f.label :title %>
<%= f.text_field :title, :class => "form-control" %>
</div>
<br />

<%= f.label :description %>
<%= f.text_field :description %>
<div class="form-group">
<%= f.label :description %>
<%= f.text_field :description, :class => "form-control" %>
</div>
<br />

<%= f.label "Visible to Everyone" %>
<%= f.check_box :is_private %>
<br />
<span> Checking this box will make this document visible to everyone.</span>
<br />
<div class="form-group">
<%= f.label "Visible to Everyone" %>
<span style="font-size: 10px"> Checking this box will make this document visible to everyone.</span>
<%= f.check_box :is_private, :class => "checkbox" %>
</div>

<%= f.label "Everyone Can Edit" %>
<%= f.check_box :is_writable %>
<br />
<span> Checking this box will make it so that everone can edit this document.</span>
<br />
<div class="form-group">
<%= f.label "Everyone Can Edit" %>
<span style="font-size: 10px"> Checking this box will make it so that everone can edit this document.</span>
<%= f.check_box :is_writable, :class => "checkbox" %>
</div>

<hr />
<%= f.fields_for :revision do |rev| %>
Expand Down
10 changes: 10 additions & 0 deletions app/views/documents/_document_tile.html.erb
@@ -0,0 +1,10 @@
<div class="col-sm-2">
<div class= "unstyled_link">
<div class="media">
<%= link_to doc do %>
<%= image_tag "icons/#{document_icon(doc.current_revision.last.extension_type)}" %>
<%= doc.title %>
<% end %>
</div>
</div>
</div>
8 changes: 8 additions & 0 deletions app/views/layouts/_messages.html.erb
@@ -0,0 +1,8 @@
<% flash.each do |name, msg| %>
<% if msg.is_a?(String) %>
<div class="alert alert-<%= name == :notice ? "success" : "danger" %>" >
<a class="close" data-dismiss="alert">&#215;</a>
<%= content_tag :div, msg, :id => "flash_#{name}" %>
</div>
<% end %>
<% end %>
1 change: 1 addition & 0 deletions app/views/layouts/application.html.erb
Expand Up @@ -9,6 +9,7 @@
</head>
<body>

<%= render partial: "layouts/messages" %>
<div class="page">
<%= render partial: "layouts/header" %>
<hr />
Expand Down

0 comments on commit 62026ea

Please sign in to comment.