Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-01-11 07:42:28 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-01-11 07:42:28 +0300
commit466651553839d77c0f7352399b5714341ff4fa02 (patch)
treea4b2c4ae222d83a0c4a99ca30f10b735973d234e
parente9bf4e411f2d3535c6cda11a29716ed7e0db136a (diff)
parent02adb9ccd605a10984f4af582fcd9b22bfab52d7 (diff)
Merge branch 'flatten-dirs' into 'master'
Flatten the directory hierarchy while there is only one directory descendant In some languages, especially java, the directory structure reflects the package structure.This means that using the file tree browser to reach the directories that matter you have to click a lot of directories containing only another subdirectory. This merge request tries to enhance this by showing and providing the link to the first directory that doesn't contain only one directory. See also [this feature request](http://feedback.gitlab.com/forums/176466-general/suggestions/6236769-jump-forward-to-the-first-folder-that-has-more-tha) This is very similar to what [GitHub does](https://github.com/blog/1877-folder-jumping), but I don't think graying out the empty directories is really necessary. Screenshots: [Before](https://gitlab.com/uploads/marmis85/gitlab-ce/b683a0000f/before.png) - [After](https://gitlab.com/uploads/marmis85/gitlab-ce/a23725a1c1/after.png) I'm actually very new at ruby, rails, haml, and almost everything involved in Gitlab's development... From what I could understand, when we render each directory item in the list we only have the data structure representing the item but not his descendants. To iterate through the hierarchy I call Gitlab::Git:Tree.where() but I'm not sure if this is the most efficient way. I also considered making every directory a clickable link, but I tried that and in the end it wasn't very useful and reduced the click target for the most useful directory. See merge request !275
-rw-r--r--app/helpers/tree_helper.rb10
-rw-r--r--app/views/projects/tree/_tree_item.html.haml3
-rw-r--r--spec/helpers/tree_helper_spec.rb28
3 files changed, 40 insertions, 1 deletions
diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb
index e32aeba5f8f..5a96a208e93 100644
--- a/app/helpers/tree_helper.rb
+++ b/app/helpers/tree_helper.rb
@@ -113,6 +113,16 @@ module TreeHelper
tree_join(@ref, file)
end
+ # returns the relative path of the first subdir that doesn't have only one directory descendand
+ def flatten_tree(tree)
+ subtree = Gitlab::Git::Tree.where(@repository, @commit.id, tree.path)
+ if subtree.count == 1 && subtree.first.dir?
+ return tree_join(tree.name, flatten_tree(subtree.first))
+ else
+ return tree.name
+ end
+ end
+
def leave_edit_message
"Leave edit mode?\nAll unsaved changes will be lost."
end
diff --git a/app/views/projects/tree/_tree_item.html.haml b/app/views/projects/tree/_tree_item.html.haml
index f8cecf9be1f..5adbf93ff8f 100644
--- a/app/views/projects/tree/_tree_item.html.haml
+++ b/app/views/projects/tree/_tree_item.html.haml
@@ -2,7 +2,8 @@
%td.tree-item-file-name
= tree_icon(type)
%span.str-truncated
- = link_to tree_item.name, project_tree_path(@project, tree_join(@id || @commit.id, tree_item.name))
+ - path = flatten_tree(tree_item)
+ = link_to path, project_tree_path(@project, tree_join(@id || @commit.id, path))
%td.tree_time_ago.cgray
= render 'spinner'
%td.hidden-xs.tree_commit
diff --git a/spec/helpers/tree_helper_spec.rb b/spec/helpers/tree_helper_spec.rb
new file mode 100644
index 00000000000..8aa50c4c778
--- /dev/null
+++ b/spec/helpers/tree_helper_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+describe TreeHelper do
+ describe 'flatten_tree' do
+ let(:project) { create(:project) }
+
+ before {
+ @repository = project.repository
+ @commit = project.repository.commit("e56497bb")
+ }
+
+ context "on a directory containing more than one file/directory" do
+ let(:tree_item) { double(name: "files", path: "files") }
+
+ it "should return the directory name" do
+ flatten_tree(tree_item).should match('files')
+ end
+ end
+
+ context "on a directory containing only one directory" do
+ let(:tree_item) { double(name: "foo", path: "foo") }
+
+ it "should return the flattened path" do
+ flatten_tree(tree_item).should match('foo/bar')
+ end
+ end
+ end
+end