Alphabetize files and folders

fixes #10036

This commit removes the ability to sort files and folders by
dragging and replaces it with a default of alphabetizing every
item.

Test plan:
  *Folder
    1. Go the to files page http://localhost:3000/dashboard/files
    2. Create a folder named "d_folder" then add a folder named "a_folder"
    3. Ensure "a_folder" is before "d_folder"
  *Files
    1. Go the to files page http://localhost:3000/dashboard/files
    2. Upload a file named "d_file.txt" then add a file named
"a_file.txt" (must have characters in the file"
    3. Ensure "a_file.txt" is before "d_file.txt"

Change-Id: I3776ff996e338f8aa6fc3858b59e1460b8b1cdf0
Reviewed-on: https://gerrit.instructure.com/13554
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Zach Pendleton <zachp@instructure.com>
This commit is contained in:
Sterling Cobb 2012-08-27 15:42:45 -06:00
parent 0e78c63102
commit 3b0fada705
10 changed files with 497 additions and 223 deletions

View File

@ -1535,23 +1535,26 @@ class User < ActiveRecord::Base
end
def self.file_structure_for(context, user)
res = {
results = {
:contexts => [context],
:collaborations => [],
:folders => [],
:folders_with_subcontent => [],
:files => []
}
context_codes = res[:contexts].map{|c| c.asset_string }
context_codes = results[:contexts].map{|c| c.asset_string }
if !context.is_a?(User) && user
res[:collaborations] = user.collaborations.active.find(:all, :include => [:user, :users]).select{|c| c.context_id && c.context_type && context_codes.include?("#{c.context_type.underscore}_#{c.context_id}") }
res[:collaborations] = res[:collaborations].sort_by{|c| c.created_at}.reverse
results[:collaborations] = user.collaborations.active.find(:all, :include => [:user, :users]).select{|c| c.context_id && c.context_type && context_codes.include?("#{c.context_type.underscore}_#{c.context_id}") }
results[:collaborations] = results[:collaborations].sort_by{|c| c.created_at}.reverse
end
res[:contexts].each do |context|
res[:folders] += context.active_folders_with_sub_folders
results[:contexts].each do |context|
results[:folders] += context.active_folders_with_sub_folders
end
res[:folders] = res[:folders].sort_by{|f| [f.parent_folder_id || 0, f.position || 0, f.name || "", f.created_at]}
res
results[:folders] = results[:folders].sort_by{|f| [f.parent_folder_id || 0, f.position || 0, f.name || "", f.created_at]}
results
end
def generate_reminders_if_changed

View File

@ -10,7 +10,6 @@
</div>
<div class="links">
<a href='#' class="preview_item_link no-hover" style="<%= hidden unless content_file && !content_file.errored? && content_file.scribd_doc && can_do(content_file, @current_user, :update) rescue false %>" title="<%= t 'links.preview_file', "Preview this file" %>"><%= image_tag "preview.png" %></a>
<a href='#' class="reorder_item_link move no-hover" style="<%= hidden unless can_do(content_file, @current_user, :update) rescue false %>" title="<%= t 'links.drag_to_reorder', "Drag to reorder files in this folder" %>"><%= image_tag "move-ns.png" %></a>
<a href="#" class="edit_item_link no-hover" style="<%= "display: none;" unless (can_do(content_file, @current_user, :update) rescue false) %>" title="<%= t 'links.rename', "Rename this file" %>"><%= image_tag "edit.png" %></a>
<a href="#" class="delete_item_link no-hover" style="<%= "display: none;" unless (can_do(content_file, @current_user, :delete) rescue false) %>" title="<%= t 'links.delete', "Delete this file" %>"><%= image_tag "delete.png" %></a>
</div>

View File

@ -126,7 +126,6 @@
<a href="#" class="lock_item_link no-hover folder_url" title="<%= t 'links.lock_folder', "Lock this Folder" %>"><%= image_tag "lock.png" %></a>
<a href="#" class="unlock_item_link no-hover folder_url" style="display: none;" title="<%= t 'links.unlock_folder', "Unlock this Folder" %>"><%= image_tag "unlock.png" %></a>
</span>
<a href="#" class="sort_icon" title="<%= t 'alts.drag_to_reorder', "Drag to reorder" %>""><%= image_tag "move-ns.png" %></a>
<a href="#" class="rename_item_link no-hover"><%= image_tag "edit.png" %></a>
<a href="#" class="delete_item_link no-hover"><%= image_tag "delete.png" %></a>
</div>
@ -149,7 +148,6 @@
<a href="#" class="lock_item_link no-hover attachment_url" title="<%= t 'links.lock_file', "Lock this File" %>"><%= image_tag "lock.png" %></a>
<a href="#" class="unlock_item_link no-hover attachment_url" style="display: none;" title="<%= t 'links.unlock_file', "Unlock this File" %>"><%= image_tag "unlock.png" %></a>
</span>
<a href="#" class="sort_icon" title="<%= t 'links.reorder_file', 'Drag to reorder' %>"><%= image_tag "move-ns.png" %></a>
<a href="#" class="rename_item_link no-hover attachment_url" title="<%= t 'links.rename_file', "Rename this File" %>"><%= image_tag "edit.png" %></a>
<a href="#" class="delete_item_link no-hover attachment_url" title="<%= t 'links.delete_file', "Delete this File" %>"><%= image_tag "delete.png" %></a>
</div>

File diff suppressed because it is too large Load Diff

1
spec/fixtures/files/a_file.txt vendored Normal file
View File

@ -0,0 +1 @@
asdf

1
spec/fixtures/files/b_file.txt vendored Normal file
View File

@ -0,0 +1 @@
asdfasdfa

1
spec/fixtures/files/c_file.txt vendored Normal file
View File

@ -0,0 +1 @@
sdfasfd

View File

@ -900,7 +900,10 @@ end
"cc_full_test.zip" => File.read(File.dirname(__FILE__) + '/../fixtures/migration/cc_full_test.zip'),
"cc_ark_test.zip" => File.read(File.dirname(__FILE__) + '/../fixtures/migration/cc_ark_test.zip'),
"canvas_cc_minimum.zip" => File.read(File.dirname(__FILE__) + '/../fixtures/migration/canvas_cc_minimum.zip'),
"qti.zip" => File.read(File.dirname(__FILE__) + '/../fixtures/migration/package_identifier/qti.zip')
"qti.zip" => File.read(File.dirname(__FILE__) + '/../fixtures/migration/package_identifier/qti.zip'),
"a_file.txt" => File.read(File.dirname(__FILE__) + '/../fixtures/files/a_file.txt'),
"b_file.txt" => File.read(File.dirname(__FILE__) + '/../fixtures/files/b_file.txt'),
"c_file.txt" => File.read(File.dirname(__FILE__) + '/../fixtures/files/c_file.txt')
}
def get_file(filename, data = nil)

View File

@ -1,6 +1,20 @@
require File.expand_path(File.dirname(__FILE__) + '/common')
require File.expand_path(File.dirname(__FILE__) + '/helpers/files_common')
def add_folders(name = 'new folder', number_to_add = 1)
1..number_to_add.times do |number|
keep_trying_until do
f(".add_folder_link").click
wait_for_animations
f("#files_content .add_folder_form #folder_name").should be_displayed
end
new_folder = f("#files_content .add_folder_form #folder_name")
new_folder.send_keys(name)
new_folder.send_keys(:return)
wait_for_ajax_requests
end
end
def make_folder_actions_visible
driver.execute_script("$('.folder_item').addClass('folder_item_hover')")
end
@ -35,6 +49,7 @@ shared_examples_for "files selenium tests" do
wait_for_animations
f("#files_content .add_folder_form #folder_name").should be_displayed
end
f("#files_content .add_folder_form #folder_name").send_keys("my folder\n")
wait_for_ajax_requests
f(".node.folder span").should have_class('ui-droppable')
@ -44,30 +59,16 @@ shared_examples_for "files selenium tests" do
end
end
describe "files without s3 and forked tests" do
it_should_behave_like "in-process server selenium tests"
def add_folders(name = 'new folder', number_to_add = 1)
1..number_to_add.times do |number|
keep_trying_until do
f(".add_folder_link").click
wait_for_animations
f("#files_content .add_folder_form #folder_name").should be_displayed
end
new_folder = f("#files_content .add_folder_form #folder_name")
new_folder.send_keys(name + "#{number}")
new_folder.send_keys(:return)
wait_for_ajax_requests
end
end
before (:each) do
@folder_name = "my folder"
course_with_teacher_logged_in
get "/dashboard/files"
wait_for_ajaximations
add_folders(@folder_name)
Folder.last.name.should == @folder_name + '0'
Folder.last.name.should == @folder_name
@folder_css = ".folder_#{Folder.last.id}"
make_folder_actions_visible
end
@ -94,17 +95,6 @@ describe "files without s3 and forked tests" do
f('#files_content').should_not include_text(@folder_name)
end
it "should allow dragging folders to re-arrange them" do
pending('drag and drop not working')
expected_folder_text = 'my folder'
add_folders('new folder', 2)
fj('.folder_item:visible:first').text.should == expected_folder_text
make_folder_actions_visible
driver.action.drag_and_drop(move_icons[0], move_icons[1]).perform
wait_for_ajaximations
fj('.folder_item:visible:last').text.should == expected_folder_text
end
it "should allow locking a folder" do
f(@folder_css + ' .lock_item_link').click
lock_form = f('#lock_folder_form')
@ -114,6 +104,7 @@ describe "files without s3 and forked tests" do
f(@folder_css + ' .header img').should have_attribute('alt', 'Locked Folder')
Folder.last.locked.should be_true
end
end
describe "files local tests" do
@ -123,6 +114,7 @@ describe "files local tests" do
Setting.set("file_storage_test_override", "local")
end
context "as a teacher" do
before (:each) do
@ -250,8 +242,10 @@ describe "files local tests" do
fj('.file .item_icon:visible').should have_attribute('alt', 'Locked File')
Folder.last.attachments.last.locked.should be_true
end
end
describe "files S3 tests" do
it_should_behave_like "files selenium tests"
prepend_before(:each) { Setting.set("file_storage_test_override", "s3") }
@ -419,3 +413,81 @@ describe "zip file uploads" do
end
end
describe "common file behaviors" do
it_should_behave_like "forked server selenium tests"
before(:each) do
course_with_teacher_logged_in
get "/dashboard/files"
end
context "when creating new folders" do
let(:folder_a_name) { "a_folder" }
let(:folder_b_name) { "b_folder" }
let(:folder_c_name) { "c_folder" }
before(:each) do
add_folders(folder_b_name)
add_folders(folder_a_name)
add_folders(folder_c_name)
end
it "orders file structure folders alphabetically" do
folder_elements = ff('#files_structure_list > .context > ul > .node.folder > .name')
folder_elements[0].text.should == folder_a_name
folder_elements[1].text.should == folder_b_name
folder_elements[2].text.should == folder_c_name
end
it "orders file content folders alphabetically" do
folder_elements = ff('#files_content > .folder_item.folder > .header > .name')
folder_elements[0].text.should == folder_a_name
folder_elements[1].text.should == folder_b_name
folder_elements[2].text.should == folder_c_name
end
end
context "when creating new files" do
def add_file(file_fullpath)
attachment_field = keep_trying_until do
fj('#add_file_link').click # fj to avoid selenium caching
attachment_field = f('#attachment_uploaded_data')
attachment_field.should be_displayed
attachment_field
end
attachment_field.send_keys(file_fullpath)
f('.add_file_form').submit
wait_for_ajaximations
wait_for_js
end
before(:each) do
@a_filename, a_fullpath, a_data = get_file("a_file.txt")
@b_filename, b_fullpath, b_data = get_file("b_file.txt")
@c_filename, c_fullpath, c_data = get_file("c_file.txt")
add_file(c_fullpath)
add_file(a_fullpath)
add_file(b_fullpath)
end
it "orders file structure files alphabetically" do
file_elements = ff('#files_structure_list > .context > ul > .file > .name')
file_elements[0].text.should == @a_filename
file_elements[1].text.should == @b_filename
file_elements[2].text.should == @c_filename
end
it "orders file content files alphabetically" do
file_elements = ff('#files_content > .folder_item.file > .header > .name')
file_elements[0].text.should == @a_filename
file_elements[1].text.should == @b_filename
file_elements[2].text.should == @c_filename
end
end
end

View File

@ -54,4 +54,5 @@ shared_examples_for "files selenium shared" do
resp.code.should == "200"
end
end
end
end