diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 7a7fa00..096f572 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -19,6 +19,7 @@ require 'yaml'
class ApplicationController < ActionController::Base
include AuthenticationSystem
+ helper :all
helper :all
before_filter :startup
diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb
index f2a64d6..3ebe9c7 100644
--- a/app/controllers/attachments_controller.rb
+++ b/app/controllers/attachments_controller.rb
@@ -34,6 +34,7 @@ class AttachmentsController < ApplicationController
def create
@attachment.course_id = @course.id
+ @attachment.path = params[:attachment][:path]
@attachment.description = params[:attachment][:description]
@attachment.file_name = "blank"
unless params[:attachment][:file].nil?
@@ -56,6 +57,7 @@ class AttachmentsController < ApplicationController
end
def update
+ @attachment.path = params[:attachment][:path]
@attachment.description = params[:attachment][:description]
unless params[:attachment][:file].nil?
@attachment.file = params[:attachment][:file]
diff --git a/app/helpers/attachments_helper.rb b/app/helpers/attachments_helper.rb
index a4792a6..d0c2fe9 100644
--- a/app/helpers/attachments_helper.rb
+++ b/app/helpers/attachments_helper.rb
@@ -15,4 +15,55 @@
# along with this program. If not, see .
module AttachmentsHelper
+
+ def attachments_to_nested_hash(atts)
+ paths = atts.collect { |item| item.path.nil? ? [] : item.path.split("/") }
+ return nest_path(atts, paths, 0, paths.size-1, 0)
+ end
+
+ def nest_path(items, paths, from, to, level)
+ result = {}
+
+ base = from - 1
+ base = base + 1 while base+1 <= to and paths[base+1][level].nil?
+ if base >= from then
+ result['/'] = items[from..base]
+ end
+
+ start = base+1
+
+ return result if start > to
+
+ folder = paths[start][level]
+ (base+1).upto(to) do |i|
+ if paths[i][level] != folder
+ result[folder] = nest_path(items, paths, start, i-1, level+1)
+ start = i
+ folder = paths[i][level]
+ end
+ end
+
+ if start <= to then
+ result[folder] = nest_path(items, paths, start, to, level+1)
+ end
+
+ return result
+ end
+
+ def nested_attachments_to_html(atts, level=0)
+ out = (level > 0 ? "
" : "")
+ keys = atts.keys.sort
+
+ for att in atts['/'] do
+ out = out + "- #{link_to h(att.file_name), course_attachment_url(@course, att)}
"
+ end if atts['/']
+
+ for key in keys - ['/'] do
+ out = out + "- #{link_to h(key), '#'}
"
+ out = out + nested_attachments_to_html(atts[key], level+1)
+ end
+
+ out = out + "
"
+ end
+
end
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 20ec5e6..ce4344f 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -50,6 +50,8 @@ class Attachment < ActiveRecord::Base
# modificar a descrição, ou algo assim..
errors.add("file", "is needed"[]) if not self.id
end
+
+ errors.add("path", "muito longo") if !@path.nil? and @path.split('/').size > 10
end
# Salva o arquivo fisicamente no HD
@@ -70,4 +72,5 @@ class Attachment < ActiveRecord::Base
# @file_path = "#{RAILS_ROOT}/public/upload/#{course.id}/#{self.id}"
# File.delete(@file_path) if File.exists?(@file_path)
#end
+
end
diff --git a/app/models/course.rb b/app/models/course.rb
index a0d1f82..bf38be9 100644
--- a/app/models/course.rb
+++ b/app/models/course.rb
@@ -21,7 +21,7 @@ class Course < ActiveRecord::Base
# Associacoes
has_many :attachments,
- :order => "file_name",
+ :order => "path, file_name",
:dependent => :destroy
has_many :events,
diff --git a/app/views/attachments/_form.html.haml b/app/views/attachments/_form.html.haml
index d65d8e1..ef64ca1 100644
--- a/app/views/attachments/_form.html.haml
+++ b/app/views/attachments/_form.html.haml
@@ -6,6 +6,11 @@
%p.grey= "Tamanho máximo: #{number_to_human_size(App.max_upload_file_size)}"
%dd= file_field 'attachment', 'file'
+ %dt
+ %label{:for => 'attachment_path'} Diretório
+ %p.grey= "Exemplo: Exercicios/Parte 1"
+ %dd= text_field 'attachment', 'path'
+
%dt
%label{:for => "attachment_description"} Descrição
%dd= preserve(text_area 'attachment', 'description')
diff --git a/app/views/attachments/show.html.haml b/app/views/attachments/show.html.haml
index d8435ac..25a9426 100644
--- a/app/views/attachments/show.html.haml
+++ b/app/views/attachments/show.html.haml
@@ -10,6 +10,9 @@
%dt Arquivo
%dd= link_to h(@attachment.file_name), download_course_attachment_url(@course, @attachment)
+ %dt Pasta
+ %dd= h(@attachment.path)
+
%dt Descrição
%dd= h(@attachment.description)
diff --git a/app/views/courses/show.html.haml b/app/views/courses/show.html.haml
index e0ddec8..ccff2a6 100644
--- a/app/views/courses/show.html.haml
+++ b/app/views/courses/show.html.haml
@@ -32,10 +32,8 @@
%h3 Repositório de Arquivos
.repositorio
- %ul.wiki
- - @course.attachments.each do |att|
- %li{:class => mime_class(att.content_type)}
- = link_to h(att.file_name), course_attachment_url(@course, att)
- - if @course.attachments.empty?
+ = nested_attachments_to_html(attachments_to_nested_hash(@course.attachments))
+ - if @course.attachments.empty?
+ %ul.wiki
%li.no_itens Nenhum arquivo
diff --git a/app/views/stylesheets/wiki.css.erb b/app/views/stylesheets/wiki.css.erb
index 50aceff..0efa8ec 100644
--- a/app/views/stylesheets/wiki.css.erb
+++ b/app/views/stylesheets/wiki.css.erb
@@ -461,6 +461,7 @@ h4.title, h1.title {
.repositorio .mime_document { background-image: url(<%= App.base_path %>/images/tango/x-office-document.png); }
.repositorio .mime_binary { background-image: url(<%= App.base_path %>/images/tango/application-x-executable.png); }
.repositorio .mime_zip { background-image: url(<%= App.base_path %>/images/tango/package-x-generic.png); }
+.repositorio .mime_folder { background-image: url(<%= App.base_path %>/images/tango/folder.png); }
.spinner {
float: right;
@@ -855,6 +856,14 @@ form dt p {
padding-left: 110px !important;
}
+ul.nested {
+ padding-left: 36px;
+}
+
+ul.nested li {
+ padding-top: 5px !important;
+ padding-bottom: 4px !important;
+}
+
/*body { background-image: url(<%= App.base_path %>/prototype/line.png); background-repeat: repeat; }
html * { background-color: transparent !important; }*/
-
diff --git a/db/migrate/037_folders.rb b/db/migrate/037_folders.rb
new file mode 100644
index 0000000..2a21a40
--- /dev/null
+++ b/db/migrate/037_folders.rb
@@ -0,0 +1,9 @@
+class Folders < ActiveRecord::Migration
+ def self.up
+ add_column :attachments, :path, :string
+ end
+
+ def self.down
+ remove_column :attachments, :path
+ end
+end
diff --git a/vendor/plugins/gibberish/lib/gibberish/activerecord_ext.rb b/vendor/plugins/gibberish/lib/gibberish/activerecord_ext.rb
index 85fa4ab..d9b341e 100644
--- a/vendor/plugins/gibberish/lib/gibberish/activerecord_ext.rb
+++ b/vendor/plugins/gibberish/lib/gibberish/activerecord_ext.rb
@@ -1,20 +1,20 @@
-module ActiveRecord
- class Errors
- def full_messages
- full_messages = []
-
- @errors.each_key do |attr|
- @errors[attr].each do |msg|
- next if msg.nil?
-
- if attr == "base"
- full_messages << msg
- else
- full_messages << @base.class.human_attribute_name(attr.send("[]")) + " " + msg
- end
- end
- end
- full_messages
- end
- end
-end
+#module ActiveRecord
+# class Errors
+# def full_messages
+# full_messages = []
+#
+# @errors.each_key do |attr|
+# @errors[attr].each do |msg|
+# next if msg.nil?
+#
+# if attr == "base"
+# full_messages << msg
+# else
+# full_messages << @base.class.human_attribute_name(attr.send("[]")) + " " + msg
+# end
+# end
+# end
+# full_messages
+# end
+# end
+#end