Commit 8abc7575 authored by Adam Buckland's avatar Adam Buckland

Update tree view to sort folders with submodules

Currently trees are sorted in the fashion:
- folders
- files
- submodules
with each section sorted alphabetically

This changes to this system:
- folders and submodules (sorted together)
- files
parent 551ffc0a
...@@ -82,6 +82,7 @@ v 8.11.0 (unreleased) ...@@ -82,6 +82,7 @@ v 8.11.0 (unreleased)
- Adds support for pending invitation project members importing projects - Adds support for pending invitation project members importing projects
- Update devise initializer to turn on changed password notification emails. !5648 (tombell) - Update devise initializer to turn on changed password notification emails. !5648 (tombell)
- Avoid to show the original password field when password is automatically set. !5712 (duduribeiro) - Avoid to show the original password field when password is automatically set. !5712 (duduribeiro)
- Sort folders with submodules in Files view !5521
v 8.10.5 (unreleased) v 8.10.5 (unreleased)
......
...@@ -4,23 +4,11 @@ module TreeHelper ...@@ -4,23 +4,11 @@ module TreeHelper
# #
# contents - A Grit::Tree object for the current tree # contents - A Grit::Tree object for the current tree
def render_tree(tree) def render_tree(tree)
# Render Folders before Files/Submodules # Sort submodules and folders together by name ahead of files
folders, files, submodules = tree.trees, tree.blobs, tree.submodules folders, files, submodules = tree.trees, tree.blobs, tree.submodules
tree = "" tree = ""
items = (folders + submodules).sort_by(&:name) + files
# Render folders if we have any tree << render(partial: "projects/tree/tree_row", collection: items) if items.present?
tree << render(partial: 'projects/tree/tree_item', collection: folders,
locals: { type: 'folder' }) if folders.present?
# Render files if we have any
tree << render(partial: 'projects/tree/blob_item', collection: files,
locals: { type: 'file' }) if files.present?
# Render submodules if we have any
tree << render(partial: 'projects/tree/submodule_item',
collection: submodules) if submodules.present?
tree.html_safe tree.html_safe
end end
......
- if tree_row.type == :tree
= render partial: 'projects/tree/tree_item', object: tree_row, as: 'tree_item', locals: { type: 'folder' }
- elsif tree_row.type == :blob
= render partial: 'projects/tree/blob_item', object: tree_row, as: 'blob_item', locals: { type: 'file' }
- elsif tree_row.type == :commit
= render partial: 'projects/tree/submodule_item', object: tree_row, as: 'submodule_item'
require 'spec_helper'
feature 'User views files page', feature: true do
include WaitForAjax
let(:user) { create(:user) }
let(:project) { create(:forked_project_with_submodules) }
before do
project.team << [user, :master]
login_as user
visit namespace_project_tree_path(project.namespace, project, project.repository.root_ref)
end
scenario 'user sees folders and submodules sorted together, followed by files' do
rows = all('td.tree-item-file-name').map(&:text)
tree = project.repository.tree
folders = tree.trees.map(&:name)
files = tree.blobs.map(&:name)
submodules = tree.submodules.map do |submodule|
submodule.name + " @ " + submodule.id[0..7]
end
sorted_titles = (folders + submodules).sort + files
expect(rows).to eq(sorted_titles)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment