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 ? "