From b5328879f5c0131721a3cd71969f7579376d8498 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 3 Oct 2012 17:01:16 -0400 Subject: Rename tree.js to tree.js.coffee --- app/assets/javascripts/tree.js | 30 ------------------------------ app/assets/javascripts/tree.js.coffee | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 30 deletions(-) delete mode 100644 app/assets/javascripts/tree.js create mode 100644 app/assets/javascripts/tree.js.coffee diff --git a/app/assets/javascripts/tree.js b/app/assets/javascripts/tree.js deleted file mode 100644 index 1c62751ad25..00000000000 --- a/app/assets/javascripts/tree.js +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Tree slider for code browse - * - */ -var Tree = { - init: - function() { - $('#tree-slider .tree-item-file-name a, .breadcrumb li > a').live("click", function() { - $("#tree-content-holder").hide("slide", { direction: "left" }, 150) - }) - - $('.project-refs-form').live({ - "ajax:beforeSend": function() { - $("#tree-content-holder").hide("slide", { direction: "left" }, 150); - } - }) - - $("#tree-slider .tree-item").live('click', function(e){ - if(e.target.nodeName != "A") { - link = $(this).find(".tree-item-file-name a"); - link.trigger("click"); - } - }); - - $('#tree-slider .tree-item-file-name a, .breadcrumb a, .project-refs-form').live({ - "ajax:beforeSend": function() { $('.tree_progress').addClass("loading"); }, - "ajax:complete": function() { $('.tree_progress').removeClass("loading"); } - }); - } -} diff --git a/app/assets/javascripts/tree.js.coffee b/app/assets/javascripts/tree.js.coffee new file mode 100644 index 00000000000..200f1e063e4 --- /dev/null +++ b/app/assets/javascripts/tree.js.coffee @@ -0,0 +1,20 @@ +# Code browser tree slider + +$ -> + if $('#tree-slider').length > 0 + # Show the "Loading commit data" for only the first element + $('span.log_loading:first').removeClass('hide') + + $('#tree-slider .tree-item-file-name a, .breadcrumb li > a').live "click", -> + $("#tree-content-holder").hide("slide", { direction: "left" }, 150) + + $('.project-refs-form').live + "ajax:beforeSend": -> $("#tree-content-holder").hide("slide", { direction: "left" }, 150) + + # Make the entire tree-item row clickable, but not if clicking another link (like a commit message) + $("#tree-slider .tree-item").live 'click', (e) -> + $('.tree-item-file-name a', this).trigger('click') if (e.target.nodeName != "A") + + $('#tree-slider .tree-item-file-name a, .breadcrumb a, .project-refs-form').live + "ajax:beforeSend": -> $('.tree_progress').addClass("loading") + "ajax:complete": -> $('.tree_progress').removeClass("loading") -- cgit v1.2.1 From 96b4acf5e7e1d73e06b84efd31f1bc433bd79a1c Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 3 Oct 2012 18:28:50 -0400 Subject: Remove locals from tree/tree_file and just use "object" instead --- app/views/tree/_tree.html.haml | 4 +++- app/views/tree/_tree_file.html.haml | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/views/tree/_tree.html.haml b/app/views/tree/_tree.html.haml index 3e805d57fd4..c25907fb147 100644 --- a/app/views/tree/_tree.html.haml +++ b/app/views/tree/_tree.html.haml @@ -6,11 +6,13 @@ - tree.breadcrumbs(6) do |link| \/ %li= link + .clear %div.tree_progress + %div#tree-content-holder.tree-content-holder - if tree.is_blob? - = render partial: "tree/tree_file", locals: { name: tree.name, content: tree.data, file: tree } + = render partial: "tree/tree_file", object: tree - else - contents = tree.contents %table#tree-slider{class: "table_#{@hex_path} tree-table" } diff --git a/app/views/tree/_tree_file.html.haml b/app/views/tree/_tree_file.html.haml index 93f7be28d21..82aaed24bdc 100644 --- a/app/views/tree/_tree_file.html.haml +++ b/app/views/tree/_tree_file.html.haml @@ -2,32 +2,32 @@ .file_title %i.icon-file %span.file_name - = name.force_encoding('utf-8') - %small #{file.mode} + = tree_file.name.force_encoding('utf-8') + %small #{tree_file.mode} %span.options = link_to "raw", project_blob_path(@project, @id), class: "btn very_small", target: "_blank" = link_to "history", project_commits_path(@project, @id), class: "btn very_small" = link_to "blame", project_blame_path(@project, @id), class: "btn very_small" - - if file.text? - - if gitlab_markdown?(name) + - if tree_file.text? + - if gitlab_markdown?(tree_file.name) .file_content.wiki = preserve do - = markdown(file.data) - - elsif markup?(name) + = markdown(tree_file.data) + - elsif markup?(tree_file.name) .file_content.wiki - = raw GitHub::Markup.render(name, file.data) + = raw GitHub::Markup.render(tree_file.name, tree_file.data) - else .file_content.code - - unless file.empty? + - unless tree_file.empty? %div{class: current_user.dark_scheme ? "black" : "white"} = preserve do - = raw file.colorize(options: { linenos: 'True'}) + = raw tree_file.colorize(options: { linenos: 'True'}) - else %h4.nothing_here_message Empty file - - elsif file.image? + - elsif tree_file.image? .file_content.image_file - %img{ src: "data:#{file.mime_type};base64,#{Base64.encode64(file.data)}"} + %img{ src: "data:#{tree_file.mime_type};base64,#{Base64.encode64(tree_file.data)}"} - else .file_content.blob_file @@ -37,4 +37,4 @@ %br = image_tag "download.png", width: 64 %h3 - Download (#{file.mb_size}) + Download (#{tree_file.mb_size}) -- cgit v1.2.1 From 37c3474f683be3deac8ba1e90183029d2f49bcdc Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 3 Oct 2012 18:29:15 -0400 Subject: Tree.init() JS is no longer required --- app/views/tree/show.html.haml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/views/tree/show.html.haml b/app/views/tree/show.html.haml index 591818ce6e3..a4034f22fac 100644 --- a/app/views/tree/show.html.haml +++ b/app/views/tree/show.html.haml @@ -1,8 +1,3 @@ = render "head" %div#tree-holder.tree-holder - = render "tree", commit: @commit, tree: @tree - -:javascript - $(function() { - Tree.init(); - }); + = render "tree", tree: @tree -- cgit v1.2.1 From a8fad4ff9c1ae5adbe55989a44dad56a6a9b56e6 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 3 Oct 2012 18:30:27 -0400 Subject: Remove locals from tree/submodule_item, use "object" instead --- app/views/tree/_submodule_item.html.haml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/views/tree/_submodule_item.html.haml b/app/views/tree/_submodule_item.html.haml index 6b9f5877028..cfb0256ce88 100644 --- a/app/views/tree/_submodule_item.html.haml +++ b/app/views/tree/_submodule_item.html.haml @@ -1,13 +1,11 @@ -- url = content.url(@ref) rescue nil -- name = content.basename +- url = submodule_item.url(@ref) rescue nil +- name = submodule_item.basename - return unless url %tr{ class: "tree-item", url: url } %td.tree-item-file-name = image_tag "submodule.png" %strong= truncate(name, length: 40) %td - %code= content.id[0..10] + %code= submodule_item.id[0..10] %td = link_to truncate(url, length: 40), url - - -- cgit v1.2.1 From 388d72e6bf9c3e72113b8c16d1cc266b41870eb9 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 3 Oct 2012 18:40:56 -0400 Subject: Add render_tree helper; simplify (speed up) tree_icon --- app/assets/javascripts/tree.js.coffee | 1 + app/decorators/tree_decorator.rb | 4 +-- app/helpers/tree_helper.rb | 47 +++++++++++++++++++++-------------- app/views/tree/_tree.html.haml | 17 ++++--------- app/views/tree/_tree_item.html.haml | 14 +++++------ app/views/tree/show.js.haml | 2 +- 6 files changed, 44 insertions(+), 41 deletions(-) diff --git a/app/assets/javascripts/tree.js.coffee b/app/assets/javascripts/tree.js.coffee index 200f1e063e4..83cc08dc0fa 100644 --- a/app/assets/javascripts/tree.js.coffee +++ b/app/assets/javascripts/tree.js.coffee @@ -15,6 +15,7 @@ $ -> $("#tree-slider .tree-item").live 'click', (e) -> $('.tree-item-file-name a', this).trigger('click') if (e.target.nodeName != "A") + # Show/Hide the loading spinner $('#tree-slider .tree-item-file-name a, .breadcrumb a, .project-refs-form').live "ajax:beforeSend": -> $('.tree_progress').addClass("loading") "ajax:complete": -> $('.tree_progress').removeClass("loading") diff --git a/app/decorators/tree_decorator.rb b/app/decorators/tree_decorator.rb index 38236c2c553..754868f5805 100644 --- a/app/decorators/tree_decorator.rb +++ b/app/decorators/tree_decorator.rb @@ -8,14 +8,14 @@ class TreeDecorator < ApplicationDecorator #parts = parts[0...-1] if is_blob? - yield(h.link_to("..", "#", remote: :true)) if parts.count > max_links + yield(h.link_to("..", "#", remote: true)) if parts.count > max_links parts.each do |part| part_path = File.join(part_path, part) unless part_path.empty? part_path = part if part_path.empty? next unless parts.last(2).include?(part) if parts.count > max_links - yield(h.link_to(h.truncate(part, length: 40), h.project_tree_path(project, h.tree_join(ref, part_path)), remote: :true)) + yield(h.link_to(h.truncate(part, length: 40), h.project_tree_path(project, h.tree_join(ref, part_path)), remote: true)) end end end diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb index 81a16989405..65c2379917c 100644 --- a/app/helpers/tree_helper.rb +++ b/app/helpers/tree_helper.rb @@ -1,29 +1,40 @@ module TreeHelper - def tree_icon(content) - if content.is_a?(Grit::Blob) - if content.text? - image_tag "file_txt.png" - elsif content.image? - image_tag "file_img.png" + # Sorts a repository's tree so that folders are before files and renders + # their corresponding partials + # + # contents - A Grit::Tree object for the current tree + def render_tree(contents) + # Render Folders before Files/Submodules + folders, files = contents.partition { |v| v.kind_of?(Grit::Tree) } + + tree = "" + + # Render folders if we have any + tree += render partial: 'tree/tree_item', collection: folders, locals: {type: 'folder'} if folders.present? + + files.each do |f| + if f.respond_to?(:url) + # Object is a Submodule + tree += render partial: 'tree/submodule_item', object: f else - image_tag "file_bin.png" + # Object is a Blob + tree += render partial: 'tree/tree_item', object: f, locals: {type: 'file'} end - else - image_tag "file_dir.png" end + + tree.html_safe end - def tree_hex_class(content) - "file_#{hexdigest(content.name)}" + # Return an image icon depending on the file type + # + # type - String type of the tree item; either 'folder' or 'file' + def tree_icon(type) + image = type == 'folder' ? 'file_dir.png' : 'file_txt.png' + image_tag(image, size: '16x16') end - def tree_full_path(content) - content.name.force_encoding('utf-8') - if params[:path] - File.join(params[:path], content.name) - else - content.name - end + def tree_hex_class(content) + "file_#{hexdigest(content.name)}" end # Public: Determines if a given filename is compatible with GitHub::Markup. diff --git a/app/views/tree/_tree.html.haml b/app/views/tree/_tree.html.haml index c25907fb147..920a70b58a2 100644 --- a/app/views/tree/_tree.html.haml +++ b/app/views/tree/_tree.html.haml @@ -14,7 +14,6 @@ - if tree.is_blob? = render partial: "tree/tree_file", object: tree - else - - contents = tree.contents %table#tree-slider{class: "table_#{@hex_path} tree-table" } %thead %th Name @@ -24,22 +23,16 @@ = link_to "History", tree.history_path, class: "right" - if tree.up_dir? - %tr{ class: "tree-item", url: tree.up_dir_path } + %tr.tree-item %td.tree-item-file-name - = image_tag "file_empty.png" - = link_to "..", tree.up_dir_path, remote: :true + = image_tag "file_empty.png", size: '16x16' + = link_to "..", tree.up_dir_path, remote: true %td %td - - index = 0 - - contents.select{ |i| i.is_a?(Grit::Tree)}.each do |content| - = render partial: "tree/tree_item", locals: { content: content, index: (index += 1) } - - contents.select{ |i| i.is_a?(Grit::Blob)}.each do |content| - = render partial: "tree/tree_item", locals: { content: content, index: (index += 1) } - - contents.select{ |i| i.is_a?(Grit::Submodule)}.each do |content| - = render partial: "tree/submodule_item", locals: { content: content, index: (index += 1) } + = render_tree(tree.contents) - - if content = contents.select{ |c| c.is_a?(Grit::Blob) and c.name =~ /^readme/i }.first + - if content = tree.contents.find { |c| c.is_a?(Grit::Blob) and c.name =~ /^readme/i } .file_holder#README .file_title %i.icon-file diff --git a/app/views/tree/_tree_item.html.haml b/app/views/tree/_tree_item.html.haml index 226c380ff82..87311e194d4 100644 --- a/app/views/tree/_tree_item.html.haml +++ b/app/views/tree/_tree_item.html.haml @@ -1,11 +1,9 @@ -- file = tree_full_path(content) -%tr{ class: "tree-item #{tree_hex_class(content)}", url: project_tree_path(@project, tree_join(@id, file)) } +%tr{ class: "tree-item #{tree_hex_class(tree_item)}" } %td.tree-item-file-name - = tree_icon(content) - %strong= link_to truncate(content.name, length: 40), project_tree_path(@project, tree_join(@id || @commit.id, file)), remote: :true + = tree_icon(type) + %strong= link_to truncate(tree_item.name, length: 40), project_tree_path(@project, tree_join(@id || @commit.id, tree_item.name)), remote: true %td.tree_time_ago.cgray - - if index == 1 - %span.log_loading - Loading commit data.. - = image_tag "ajax_loader_tree.gif", width: 14 + %span.log_loading.hide + Loading commit data... + = image_tag "ajax_loader_tree.gif", width: 14 %td.tree_commit diff --git a/app/views/tree/show.js.haml b/app/views/tree/show.js.haml index 174e3e03a52..fadd5e2251f 100644 --- a/app/views/tree/show.js.haml +++ b/app/views/tree/show.js.haml @@ -1,6 +1,6 @@ :plain // Load Files list - $("#tree-holder").html("#{escape_javascript(render(partial: "tree", locals: {commit: @commit, tree: @tree}))}"); + $("#tree-holder").html("#{escape_javascript(render(partial: "tree", locals: {tree: @tree}))}"); $("#tree-content-holder").show("slide", { direction: "right" }, 150); $('.project-refs-form #path').val("#{@path}"); -- cgit v1.2.1 From 187e192cdf4470fa07a62aa0720c586b6dde2bde Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Wed, 3 Oct 2012 19:11:39 -0400 Subject: Use official Grit 2.5.0 --- Gemfile | 2 +- Gemfile.lock | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index 042fbc4d3a3..d0701732eac 100644 --- a/Gemfile +++ b/Gemfile @@ -22,7 +22,7 @@ gem 'omniauth-twitter' gem 'omniauth-github' # GITLAB patched libs -gem "grit", :git => "https://github.com/gitlabhq/grit.git", :ref => "7f35cb98ff17d534a07e3ce6ec3d580f67402837" +gem "grit", '2.5.0' gem "omniauth-ldap", :git => "https://github.com/gitlabhq/omniauth-ldap.git", :ref => "f038dd852d7bd473a557e385d5d7c2fd5dc1dc2e" gem 'yaml_db', :git => "https://github.com/gitlabhq/yaml_db.git" gem 'grack', :git => "https://github.com/gitlabhq/grack.git" diff --git a/Gemfile.lock b/Gemfile.lock index 3c3bea9d7ca..b54773edc5c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,16 +11,6 @@ GIT grack (1.0.0) rack (~> 1.4.1) -GIT - remote: https://github.com/gitlabhq/grit.git - revision: 7f35cb98ff17d534a07e3ce6ec3d580f67402837 - ref: 7f35cb98ff17d534a07e3ce6ec3d580f67402837 - specs: - grit (2.5.0) - diff-lcs (~> 1.1) - mime-types (~> 1.15) - posix-spawn (~> 0.3.6) - GIT remote: https://github.com/gitlabhq/omniauth-ldap.git revision: f038dd852d7bd473a557e385d5d7c2fd5dc1dc2e @@ -157,6 +147,10 @@ GEM rack rack-mount gratr19 (0.4.4.1) + grit (2.5.0) + diff-lcs (~> 1.1) + mime-types (~> 1.15) + posix-spawn (~> 0.3.6) growl (1.0.3) guard (1.3.2) listen (>= 0.4.2) @@ -421,7 +415,7 @@ DEPENDENCIES gitolite (= 1.1.0) grack! grape (~> 0.2.1) - grit! + grit (= 2.5.0) growl guard-rspec guard-spinach -- cgit v1.2.1 From 332fc328a394ec1e6110af872d5cb51c920a4306 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 4 Oct 2012 14:19:17 -0400 Subject: Revert "Use official Grit 2.5.0" This reverts commit 187e192cdf4470fa07a62aa0720c586b6dde2bde. [ci skip] --- Gemfile | 2 +- Gemfile.lock | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index d0701732eac..042fbc4d3a3 100644 --- a/Gemfile +++ b/Gemfile @@ -22,7 +22,7 @@ gem 'omniauth-twitter' gem 'omniauth-github' # GITLAB patched libs -gem "grit", '2.5.0' +gem "grit", :git => "https://github.com/gitlabhq/grit.git", :ref => "7f35cb98ff17d534a07e3ce6ec3d580f67402837" gem "omniauth-ldap", :git => "https://github.com/gitlabhq/omniauth-ldap.git", :ref => "f038dd852d7bd473a557e385d5d7c2fd5dc1dc2e" gem 'yaml_db', :git => "https://github.com/gitlabhq/yaml_db.git" gem 'grack', :git => "https://github.com/gitlabhq/grack.git" diff --git a/Gemfile.lock b/Gemfile.lock index b54773edc5c..3c3bea9d7ca 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -11,6 +11,16 @@ GIT grack (1.0.0) rack (~> 1.4.1) +GIT + remote: https://github.com/gitlabhq/grit.git + revision: 7f35cb98ff17d534a07e3ce6ec3d580f67402837 + ref: 7f35cb98ff17d534a07e3ce6ec3d580f67402837 + specs: + grit (2.5.0) + diff-lcs (~> 1.1) + mime-types (~> 1.15) + posix-spawn (~> 0.3.6) + GIT remote: https://github.com/gitlabhq/omniauth-ldap.git revision: f038dd852d7bd473a557e385d5d7c2fd5dc1dc2e @@ -147,10 +157,6 @@ GEM rack rack-mount gratr19 (0.4.4.1) - grit (2.5.0) - diff-lcs (~> 1.1) - mime-types (~> 1.15) - posix-spawn (~> 0.3.6) growl (1.0.3) guard (1.3.2) listen (>= 0.4.2) @@ -415,7 +421,7 @@ DEPENDENCIES gitolite (= 1.1.0) grack! grape (~> 0.2.1) - grit (= 2.5.0) + grit! growl guard-rspec guard-spinach -- cgit v1.2.1