From 1d3f7007c64578ec6cdae51da35c60a18b6600f4 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Wed, 31 Dec 2008 03:54:23 -0600 Subject: [PATCH] Manage Uploaded Files A less abstruse interface for deleting files (this time, many at-a-shot). Available from the Edit Web page. --- app/controllers/admin_controller.rb | 17 +++++++++++++++++ app/controllers/file_controller.rb | 4 ++-- app/controllers/wiki_controller.rb | 4 ++++ app/models/web.rb | 4 ++++ app/views/admin/edit_web.rhtml | 5 +++++ app/views/wiki/file_list.html.erb | 25 +++++++++++++++++++++++++ config/routes.rb | 1 + 7 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 app/views/wiki/file_list.html.erb diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index feadf9f4..e4996966 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -120,6 +120,23 @@ class AdminController < ApplicationController redirect_to :controller => 'admin', :web => @web_name, :action => 'edit_web' end end + + def delete_files + return unless is_post + some_deleted = false + if wiki.authenticate(params['system_password']) + params.each do |file, p| + if p == 'delete' + WikiFile.find_by_file_name(file).destroy + some_deleted = true + end + end + flash[:info] = "File(s) successfully deleted." if some_deleted + else + flash[:error] = password_error(params['system_password']) + end + redirect_to :controller => 'wiki', :web => @web_name, :action => 'file_list' + end private diff --git a/app/controllers/file_controller.rb b/app/controllers/file_controller.rb index ce5f560f..2364abc1 100644 --- a/app/controllers/file_controller.rb +++ b/app/controllers/file_controller.rb @@ -17,7 +17,7 @@ class FileController < ApplicationController new_file = @web.wiki_files.create(params['file']) if new_file.valid? flash[:info] = "File '#{@file_name}' successfully uploaded" - return_to_last_remembered + redirect_to_page(@page_name) else # pass the file with errors back into the form @file = new_file @@ -34,7 +34,7 @@ class FileController < ApplicationController end end end - + def delete @file_name = params['id'] file = WikiFile.find_by_file_name(@file_name) diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index bdfdf048..f9812e26 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -53,6 +53,10 @@ class WikiController < ApplicationController @authors = @page_names_by_author.keys.sort end + def file_list + @web.file_list + end + def export_html stylesheet = File.read(File.join(RAILS_ROOT, 'public', 'stylesheets', 'instiki.css')) export_pages_as_zip('html') do |page| diff --git a/app/models/web.rb b/app/models/web.rb index 4afe8e98..6bacace4 100644 --- a/app/models/web.rb +++ b/app/models/web.rb @@ -46,6 +46,10 @@ class Web < ActiveRecord::Base def has_file?(file_name) WikiFile.find_by_file_name(file_name) != nil end + + def file_list + WikiFile.find(:all, :order => 'file_name') + end def description(file_name) file = WikiFile.find_by_file_name(file_name) diff --git a/app/views/admin/edit_web.rhtml b/app/views/admin/edit_web.rhtml index 0fc270aa..bc57beea 100644 --- a/app/views/admin/edit_web.rhtml +++ b/app/views/admin/edit_web.rhtml @@ -112,6 +112,11 @@ :onsubmit => "return checkSystemPassword(document.getElementById('system_password_orphaned').value)", 'accept-charset' => 'utf-8' }) do %> +
+ <%= link_to ' Manage uploaded files', + {:controller => 'wiki', :web => @web.address, :action => 'file_list'}, :style => 'font-weight:bold' %> + for this web (<%= @web.name %>) +

Clean up this web (<%= @web.name %>) by entering the system password diff --git a/app/views/wiki/file_list.html.erb b/app/views/wiki/file_list.html.erb new file mode 100644 index 00000000..3e815317 --- /dev/null +++ b/app/views/wiki/file_list.html.erb @@ -0,0 +1,25 @@ +<%- @title = "Uploaded Files" -%> + +<% form_tag({ :controller => 'admin', :action => 'delete_files', :web => @web.address }, + {'method' => 'post', 'accept-charset' => 'utf-8' }) do +%> +

+

+ Uploaded Files in <%= @web.name %> +

+ +

Check the files you wish to delete.

+ + + <%= password_field_tag "system_password", '', :class => "disableAutoComplete" %> + and <%= submit_tag("Delete Files") %> +
+<%- end %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 11dfee9a..e9e08492 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -12,6 +12,7 @@ ActionController::Routing::Routes.draw do |map| map.connect 'create_system', :controller => 'admin', :action => 'create_system' map.connect 'create_web', :controller => 'admin', :action => 'create_web' map.connect 'delete_web', :controller => 'admin', :action => 'delete_web' + map.connect 'delete_files', :controller => 'admin', :action => 'delete_files' map.connect 'web_list', :controller => 'wiki', :action => 'web_list' connect_to_web map, ':web/edit_web', :controller => 'admin', :action => 'edit_web'