Add folders to the documents plugin
This commit is contained in:
parent
611a29fe2d
commit
dc94e98138
19 changed files with 141 additions and 71 deletions
|
@ -180,6 +180,11 @@ table {
|
||||||
color: #B94A48;
|
color: #B94A48;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Documents
|
||||||
|
.documents-item-folder {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
// Wiki
|
// Wiki
|
||||||
#wikiContent {
|
#wikiContent {
|
||||||
.editsection {
|
.editsection {
|
||||||
|
|
|
@ -39,7 +39,7 @@ de:
|
||||||
supplier: Lieferantin
|
supplier: Lieferantin
|
||||||
document:
|
document:
|
||||||
created_at: Erstellt am
|
created_at: Erstellt am
|
||||||
created_by_user_id: Erstellt von
|
created_by: Erstellt von
|
||||||
data: Daten
|
data: Daten
|
||||||
mime: MIME-Typ
|
mime: MIME-Typ
|
||||||
name: Name
|
name: Name
|
||||||
|
@ -738,15 +738,20 @@ de:
|
||||||
logged_in: Angemeldet!
|
logged_in: Angemeldet!
|
||||||
documents:
|
documents:
|
||||||
create:
|
create:
|
||||||
error: 'Dokument konnte nicht erstellt werden: %{error}'
|
error: 'Dokument oder Ordner konnte nicht erstellt werden: %{error}'
|
||||||
not_allowed_mime: Der Dateityp "%{mime}" ist nicht erlaubt. Bitte kontaktiere einen Administrator um ihn freizuschalten.
|
not_allowed_mime: Der Dateityp "%{mime}" ist nicht erlaubt. Bitte kontaktiere einen Administrator um ihn freizuschalten.
|
||||||
notice: Dokument wurde erstellt
|
notice: Dokument oder Ordner wurde erstellt
|
||||||
destroy:
|
destroy:
|
||||||
error: 'Dokument konnt nicht gelöscht werden: %{error}'
|
error: 'Dokument oder Ordner konnt nicht gelöscht werden: %{error}'
|
||||||
no_right: Du hast nicht genügend Rechte um die Datei zu löschen
|
no_right: Du hast nicht genügend Rechte um die Datei oder den Ordner zu löschen
|
||||||
notice: Dokument wurde gelöscht
|
notice: Dokument oder Ordner wurde gelöscht
|
||||||
|
form:
|
||||||
|
new: Neues Dokument
|
||||||
|
new_folder: Neuer Ordner
|
||||||
|
submit: Erstellen
|
||||||
index:
|
index:
|
||||||
new: Neues Dokument anlegen
|
new: Neues Dokument anlegen
|
||||||
|
new_folder: Neuen Ordner anlegen
|
||||||
title: Dokumente
|
title: Dokumente
|
||||||
multiple_orders_by_articles:
|
multiple_orders_by_articles:
|
||||||
filename: Artikelsortierung aktueller Bestellungen
|
filename: Artikelsortierung aktueller Bestellungen
|
||||||
|
@ -754,8 +759,6 @@ de:
|
||||||
multiple_orders_by_groups:
|
multiple_orders_by_groups:
|
||||||
filename: Gruppensortierung aktueller Bestellungen
|
filename: Gruppensortierung aktueller Bestellungen
|
||||||
title: Aktuelle Bestellungen - Gruppensortierung
|
title: Aktuelle Bestellungen - Gruppensortierung
|
||||||
new:
|
|
||||||
title: Neues Dokument
|
|
||||||
order_by_articles:
|
order_by_articles:
|
||||||
filename: Bestellung %{name}-%{date} - Artikelsortierung
|
filename: Bestellung %{name}-%{date} - Artikelsortierung
|
||||||
rows:
|
rows:
|
||||||
|
|
|
@ -39,7 +39,7 @@ en:
|
||||||
supplier: Supplier
|
supplier: Supplier
|
||||||
document:
|
document:
|
||||||
created_at: Created at
|
created_at: Created at
|
||||||
created_by_user_id: Created by
|
created_by: Created by
|
||||||
data: Data
|
data: Data
|
||||||
mime: MIME type
|
mime: MIME type
|
||||||
name: Name
|
name: Name
|
||||||
|
@ -740,15 +740,20 @@ en:
|
||||||
logged_in: Logged in!
|
logged_in: Logged in!
|
||||||
documents:
|
documents:
|
||||||
create:
|
create:
|
||||||
error: 'Document could not be created: %{error}'
|
error: 'Document or folder could not be created: %{error}'
|
||||||
not_allowed_mime: The filetype "%{mime}" is not allowed. Please contact an administrator to whitelist it.
|
not_allowed_mime: The filetype "%{mime}" is not allowed. Please contact an administrator to whitelist it.
|
||||||
notice: Document was created
|
notice: Document or folder was created
|
||||||
destroy:
|
destroy:
|
||||||
error: 'Document could not be deleted: %{error}'
|
error: 'Document or folder could not be deleted: %{error}'
|
||||||
no_right: You do not have enough rights to delete the document
|
no_right: You do not have enough rights to delete the document or folder
|
||||||
notice: Document was deleted
|
notice: Document or folder was deleted
|
||||||
|
form:
|
||||||
|
new: New Document
|
||||||
|
new_folder: new Folder
|
||||||
|
submit: Create
|
||||||
index:
|
index:
|
||||||
new: Upload new document
|
new: Upload new document
|
||||||
|
new_folder: Create new folder
|
||||||
title: Documents
|
title: Documents
|
||||||
multiple_orders_by_articles:
|
multiple_orders_by_articles:
|
||||||
filename: Current orders sorted by article
|
filename: Current orders sorted by article
|
||||||
|
@ -756,8 +761,6 @@ en:
|
||||||
multiple_orders_by_groups:
|
multiple_orders_by_groups:
|
||||||
filename: Current orders sorted by group
|
filename: Current orders sorted by group
|
||||||
title: Current orders - by group
|
title: Current orders - by group
|
||||||
new:
|
|
||||||
title: New Document
|
|
||||||
order_by_articles:
|
order_by_articles:
|
||||||
filename: Order %{name}-%{date} - by articles
|
filename: Order %{name}-%{date} - by articles
|
||||||
rows:
|
rows:
|
||||||
|
|
|
@ -39,7 +39,7 @@ es:
|
||||||
supplier: Proveedor
|
supplier: Proveedor
|
||||||
document:
|
document:
|
||||||
created_at: Creado en
|
created_at: Creado en
|
||||||
created_by_user_id: Creado por
|
created_by: Creado por
|
||||||
data: Datos
|
data: Datos
|
||||||
mime: Tipo MIME
|
mime: Tipo MIME
|
||||||
name: Nombre
|
name: Nombre
|
||||||
|
@ -749,6 +749,8 @@ es:
|
||||||
error: 'El documento no puede ser borrado: %{error}'
|
error: 'El documento no puede ser borrado: %{error}'
|
||||||
no_right: No puedes borrar este documento
|
no_right: No puedes borrar este documento
|
||||||
notice: Se ha borrado el documento
|
notice: Se ha borrado el documento
|
||||||
|
form:
|
||||||
|
new: Nuevo Documento
|
||||||
index:
|
index:
|
||||||
new: Sube nuevo documento
|
new: Sube nuevo documento
|
||||||
title: Documentos
|
title: Documentos
|
||||||
|
@ -758,8 +760,6 @@ es:
|
||||||
multiple_orders_by_groups:
|
multiple_orders_by_groups:
|
||||||
filename: Pedidos activos ordenados por grupo
|
filename: Pedidos activos ordenados por grupo
|
||||||
title: Pedidos activos - por grupo
|
title: Pedidos activos - por grupo
|
||||||
new:
|
|
||||||
title: Nuevo Documento
|
|
||||||
order_by_articles:
|
order_by_articles:
|
||||||
filename: Pedido %{name}-%{date} - por artículos
|
filename: Pedido %{name}-%{date} - por artículos
|
||||||
rows:
|
rows:
|
||||||
|
|
|
@ -39,7 +39,7 @@ fr:
|
||||||
supplier: Fournisseur-e
|
supplier: Fournisseur-e
|
||||||
document:
|
document:
|
||||||
created_at: Créé le
|
created_at: Créé le
|
||||||
created_by_user_id: Crée par
|
created_by: Crée par
|
||||||
data:
|
data:
|
||||||
mime:
|
mime:
|
||||||
name: Nom
|
name: Nom
|
||||||
|
|
|
@ -39,7 +39,7 @@ nl:
|
||||||
supplier: Leverancier
|
supplier: Leverancier
|
||||||
document:
|
document:
|
||||||
created_at: Upload op
|
created_at: Upload op
|
||||||
created_by_user_id: Upload door
|
created_by: Upload door
|
||||||
data: Data
|
data: Data
|
||||||
mime: MIME-type
|
mime: MIME-type
|
||||||
name: Naam
|
name: Naam
|
||||||
|
@ -745,6 +745,8 @@ nl:
|
||||||
error: 'Document kon niet verwijderd worden: %{error}'
|
error: 'Document kon niet verwijderd worden: %{error}'
|
||||||
no_right: Je hebt niet genoeg rechten om het document te verwijderen
|
no_right: Je hebt niet genoeg rechten om het document te verwijderen
|
||||||
notice: Document is verwijderd
|
notice: Document is verwijderd
|
||||||
|
form:
|
||||||
|
title: Nieuw document
|
||||||
index:
|
index:
|
||||||
new: Nieuw document uploaden
|
new: Nieuw document uploaden
|
||||||
title: Documenten
|
title: Documenten
|
||||||
|
@ -754,8 +756,6 @@ nl:
|
||||||
multiple_orders_by_groups:
|
multiple_orders_by_groups:
|
||||||
filename: Huidige bestellingen per huishouden
|
filename: Huidige bestellingen per huishouden
|
||||||
title: Huidige bestellingen - per huishouden
|
title: Huidige bestellingen - per huishouden
|
||||||
new:
|
|
||||||
title: Nieuw document
|
|
||||||
order_by_articles:
|
order_by_articles:
|
||||||
filename: Bestelling %{name}-%{date} - Artikellijst
|
filename: Bestelling %{name}-%{date} - Artikellijst
|
||||||
rows:
|
rows:
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddParentToDocument < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_reference :documents, :parent, index: true
|
||||||
|
end
|
||||||
|
end
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 20171002000000) do
|
ActiveRecord::Schema.define(version: 20171110000000) do
|
||||||
|
|
||||||
create_table "article_categories", force: :cascade do |t|
|
create_table "article_categories", force: :cascade do |t|
|
||||||
t.string "name", limit: 255, default: "", null: false
|
t.string "name", limit: 255, default: "", null: false
|
||||||
|
@ -83,8 +83,11 @@ ActiveRecord::Schema.define(version: 20171002000000) do
|
||||||
t.integer "created_by_user_id"
|
t.integer "created_by_user_id"
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
|
t.integer "parent_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
add_index "documents", ["parent_id"], name: "index_documents_on_parent_id", using: :btree
|
||||||
|
|
||||||
create_table "financial_link", force: :cascade do |t|
|
create_table "financial_link", force: :cascade do |t|
|
||||||
t.text "note"
|
t.text "note"
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,39 +6,41 @@ class DocumentsController < ApplicationController
|
||||||
def index
|
def index
|
||||||
if params["sort"]
|
if params["sort"]
|
||||||
sort = case params["sort"]
|
sort = case params["sort"]
|
||||||
when "name" then "name"
|
when "name" then "data IS NULL DESC, name"
|
||||||
when "created_at" then "created_at"
|
when "created_at" then "created_at"
|
||||||
when "name_reverse" then "name DESC"
|
when "name_reverse" then "data IS NULL, name DESC"
|
||||||
when "created_at_reverse" then "created_at DESC"
|
when "created_at_reverse" then "created_at DESC"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
sort = "name"
|
sort = "data IS NULL DESC, name"
|
||||||
end
|
end
|
||||||
|
|
||||||
@documents = Document.page(params[:page]).per(@per_page).order(sort)
|
@documents = Document.where(parent: @document).page(params[:page]).per(@per_page).order(sort)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@document = Document.new
|
@document = Document.new parent_id: params[:document_id]
|
||||||
|
@document.mime = '' unless params[:type] == 'folder'
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@document = Document.new
|
@document = Document.new name: params[:document][:name]
|
||||||
@document.data = params[:document][:data].read
|
@document.parent = Document.find_by_id(params[:document][:parent_id])
|
||||||
@document.mime = FileMagic.new(FileMagic::MAGIC_MIME).buffer(@document.data)
|
data = params[:document][:data]
|
||||||
raise t('.not_allowed_mime', mime: @document.mime) unless allowed_mime? @document.mime
|
if data
|
||||||
if params[:document][:name] == ''
|
@document.data = data.read
|
||||||
name = params[:document][:data].original_filename
|
@document.mime = FileMagic.new(FileMagic::MAGIC_MIME).buffer(@document.data)
|
||||||
name = File.basename(name)
|
raise t('.not_allowed_mime', mime: @document.mime) unless allowed_mime? @document.mime
|
||||||
@document.name = name.gsub(/[^\w\.\-]/, '_')
|
if @document.name.empty?
|
||||||
else
|
name = File.basename(data.original_filename)
|
||||||
@document.name = params[:document][:name]
|
@document.name = name.gsub(/[^\w\.\-]/, '_')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@document.created_by = current_user
|
@document.created_by = current_user
|
||||||
@document.save!
|
@document.save!
|
||||||
redirect_to documents_path, notice: t('.notice')
|
redirect_to @document.parent || documents_path, notice: t('.notice')
|
||||||
rescue => error
|
rescue => error
|
||||||
redirect_to documents_path, alert: t('.error', error: error.message)
|
redirect_to @document.parent || documents_path, alert: t('.error', error: error.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
@ -55,7 +57,12 @@ class DocumentsController < ApplicationController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@document = Document.find(params[:id])
|
@document = Document.find(params[:id])
|
||||||
send_data(@document.data, filename: @document.filename, type: @document.mime)
|
if @document.file?
|
||||||
|
send_data(@document.data, filename: @document.filename, type: @document.mime)
|
||||||
|
else
|
||||||
|
index
|
||||||
|
render :index
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def allowed_mime?(mime)
|
def allowed_mime?(mime)
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
class Document < ActiveRecord::Base
|
class Document < ActiveRecord::Base
|
||||||
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
|
include ActsAsTree
|
||||||
|
|
||||||
validates_presence_of :data
|
belongs_to :created_by, class_name: 'User', foreign_key: 'created_by_user_id'
|
||||||
|
|
||||||
|
acts_as_tree
|
||||||
|
|
||||||
|
def file?
|
||||||
|
!folder?
|
||||||
|
end
|
||||||
|
|
||||||
|
def folder?
|
||||||
|
mime.nil?
|
||||||
|
end
|
||||||
|
|
||||||
def filename
|
def filename
|
||||||
types = MIME::Types[mime]
|
types = MIME::Types[mime]
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
%tbody
|
%tbody
|
||||||
- for document in @documents
|
- for document in @documents
|
||||||
%tr
|
%tr
|
||||||
%td= link_to document.name, document
|
%td= link_to document.name, document, class: "documents-item-#{document.folder? ? 'folder' : 'file'}"
|
||||||
%td= format_time(document.created_at)
|
%td= format_time(document.created_at)
|
||||||
%td= h show_user(document.created_by)
|
%td= h show_user(document.created_by)
|
||||||
%td
|
%td
|
||||||
|
|
12
plugins/documents/app/views/documents/_form.html.haml
Normal file
12
plugins/documents/app/views/documents/_form.html.haml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
= simple_form_for @document, validate: true do |f|
|
||||||
|
= f.hidden_field :parent_id
|
||||||
|
.modal-header
|
||||||
|
= close_button :modal
|
||||||
|
%h3= @document.folder? ? t('.new_folder') : t('.new')
|
||||||
|
.modal-body
|
||||||
|
= f.input :name, as: :string, required: @document.folder?
|
||||||
|
- if @document.file?
|
||||||
|
= f.input :data, as: :file, required: true
|
||||||
|
.modal-footer
|
||||||
|
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
|
||||||
|
= f.submit t('.submit'), class: 'btn btn-primary'
|
|
@ -1,7 +1,21 @@
|
||||||
- title t('.title')
|
- title t('.title')
|
||||||
|
|
||||||
- content_for :actionbar do
|
- content_for :actionbar do
|
||||||
= link_to t('.new'), new_document_path, class: 'btn btn-primary'
|
- options = { document_id: @document || 0 }
|
||||||
|
= link_to t('.new_folder'), document_new_path(options.merge(type: :folder)), remote: true, class: 'btn'
|
||||||
|
= link_to t('.new'), document_new_path(options), remote: true, class: 'btn btn-primary'
|
||||||
|
|
||||||
|
- if @document
|
||||||
|
%ul.breadcrumb
|
||||||
|
%li
|
||||||
|
= link_to t('.title'), documents_path
|
||||||
|
%span.divider /
|
||||||
|
- for parent_folder in @document.ancestors.reverse
|
||||||
|
%li
|
||||||
|
= link_to parent_folder.name, parent_folder
|
||||||
|
%span.divider /
|
||||||
|
%li.active
|
||||||
|
= @document.name
|
||||||
|
|
||||||
#documentsTable
|
#documentsTable
|
||||||
= render :partial => "documents"
|
= render :partial => "documents"
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
- title t('.title')
|
|
||||||
|
|
||||||
= simple_form_for(@document) do |f|
|
|
||||||
= f.input :name, as: :string
|
|
||||||
= f.input :data, as: :file
|
|
||||||
.form-actions
|
|
||||||
= f.submit class: 'btn'
|
|
||||||
= link_to t('ui.or_cancel'), :back
|
|
2
plugins/documents/app/views/documents/new.js.haml
Normal file
2
plugins/documents/app/views/documents/new.js.haml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
$('#modalContainer').html('#{j(render("form"))}');
|
||||||
|
$('#modalContainer').modal();
|
|
@ -3,7 +3,7 @@ de:
|
||||||
attributes:
|
attributes:
|
||||||
document:
|
document:
|
||||||
created_at: Erstellt am
|
created_at: Erstellt am
|
||||||
created_by_user_id: Erstellt von
|
created_by: Erstellt von
|
||||||
data: Daten
|
data: Daten
|
||||||
mime: MIME-Typ
|
mime: MIME-Typ
|
||||||
name: Name
|
name: Name
|
||||||
|
@ -18,15 +18,18 @@ de:
|
||||||
documents: Dokumente
|
documents: Dokumente
|
||||||
documents:
|
documents:
|
||||||
create:
|
create:
|
||||||
error: 'Dokument konnte nicht erstellt werden: %{error}'
|
error: 'Dokument oder Ordner konnte nicht erstellt werden: %{error}'
|
||||||
not_allowed_mime: Der Dateityp "%{mime}" ist nicht erlaubt. Bitte kontaktiere einen Administrator um ihn freizuschalten.
|
not_allowed_mime: Der Dateityp "%{mime}" ist nicht erlaubt. Bitte kontaktiere einen Administrator um ihn freizuschalten.
|
||||||
notice: Dokument wurde erstellt
|
notice: Dokument oder Ordner wurde erstellt
|
||||||
destroy:
|
destroy:
|
||||||
error: 'Dokument konnt nicht gelöscht werden: %{error}'
|
error: 'Dokument oder Ordner konnt nicht gelöscht werden: %{error}'
|
||||||
no_right: Du hast nicht genügend Rechte um die Datei zu löschen
|
no_right: Du hast nicht genügend Rechte um die Datei oder den Ordner zu löschen
|
||||||
notice: Dokument wurde gelöscht
|
notice: Dokument oder Ordner wurde gelöscht
|
||||||
|
form:
|
||||||
|
new: Neues Dokument
|
||||||
|
new_folder: Neuer Ordner
|
||||||
|
submit: Erstellen
|
||||||
index:
|
index:
|
||||||
new: Neues Dokument anlegen
|
new: Neues Dokument anlegen
|
||||||
|
new_folder: Neuen Ordner anlegen
|
||||||
title: Dokumente
|
title: Dokumente
|
||||||
new:
|
|
||||||
title: Neues Dokument
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ en:
|
||||||
attributes:
|
attributes:
|
||||||
document:
|
document:
|
||||||
created_at: Created at
|
created_at: Created at
|
||||||
created_by_user_id: Created by
|
created_by: Created by
|
||||||
data: Data
|
data: Data
|
||||||
mime: MIME type
|
mime: MIME type
|
||||||
name: Name
|
name: Name
|
||||||
|
@ -18,15 +18,18 @@ en:
|
||||||
documents: Documents
|
documents: Documents
|
||||||
documents:
|
documents:
|
||||||
create:
|
create:
|
||||||
error: 'Document could not be created: %{error}'
|
error: 'Document or folder could not be created: %{error}'
|
||||||
not_allowed_mime: The filetype "%{mime}" is not allowed. Please contact an administrator to whitelist it.
|
not_allowed_mime: The filetype "%{mime}" is not allowed. Please contact an administrator to whitelist it.
|
||||||
notice: Document was created
|
notice: Document or folder was created
|
||||||
destroy:
|
destroy:
|
||||||
error: 'Document could not be deleted: %{error}'
|
error: 'Document or folder could not be deleted: %{error}'
|
||||||
no_right: You do not have enough rights to delete the document
|
no_right: You do not have enough rights to delete the document or folder
|
||||||
notice: Document was deleted
|
notice: Document or folder was deleted
|
||||||
|
form:
|
||||||
|
new: New Document
|
||||||
|
new_folder: new Folder
|
||||||
|
submit: Create
|
||||||
index:
|
index:
|
||||||
new: Upload new document
|
new: Upload new document
|
||||||
|
new_folder: Create new folder
|
||||||
title: Documents
|
title: Documents
|
||||||
new:
|
|
||||||
title: New Document
|
|
||||||
|
|
|
@ -2,7 +2,10 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
scope '/:foodcoop' do
|
scope '/:foodcoop' do
|
||||||
|
|
||||||
resources :documents
|
resources :documents do
|
||||||
|
get :new
|
||||||
|
get :new_folder
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
class AddParentToDocument < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_reference :documents, :parent, index: true
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue