diff --git a/app/assets/images/ajax_loader_tree.gif b/app/assets/images/ajax_loader_tree.gif new file mode 100644 index 0000000000000000000000000000000000000000..99d5a0f37f3e0fda2d0564e5977e3afac9bc08eb Binary files /dev/null and b/app/assets/images/ajax_loader_tree.gif differ diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 4815d180dfbf4c9e1f31e21e2097fc3f789e55b7..527b5c795e14012b2a79e15b132fd9aee1529062 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -114,3 +114,8 @@ function showDiff(link) { return _chosen.apply(this, [default_options]); }}) })(jQuery); + + +function ajaxGet(url) { + $.ajax({type: "GET", url: url, dataType: "script"}); +} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 2697fff433ec88f8bac77693e295e7559c3d6a19..3f15fd9237f38b3c8b8d27133063bdf6deafcc49 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -134,4 +134,8 @@ module ApplicationHelper end active ? "current" : nil end + + def hexdigest(string) + Digest::SHA1.hexdigest string + end end diff --git a/app/helpers/tree_helper.rb b/app/helpers/tree_helper.rb new file mode 100644 index 0000000000000000000000000000000000000000..ed3053d8af59d649ddad414e4719e1ccf9f65a0a --- /dev/null +++ b/app/helpers/tree_helper.rb @@ -0,0 +1,27 @@ +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" + else + image_tag "file_bin.png" + end + else + image_tag "file_dir.png" + end + end + + def tree_hex_class(content) + "file_#{hexdigest(content.name)}" + end + + def tree_full_path(content) + if params[:path] + File.join(params[:path], content.name) + else + content.name + end + end +end diff --git a/app/views/refs/_tree.html.haml b/app/views/refs/_tree.html.haml index 1965fe45b365cc8a3f8bfceee2664e604e952e6e..ba0bd69116b5b831bc191284ec5828dbee5a31b5 100644 --- a/app/views/refs/_tree.html.haml +++ b/app/views/refs/_tree.html.haml @@ -29,12 +29,13 @@ %td %td + - index = 0 - contents.select{ |i| i.is_a?(Grit::Tree)}.each do |content| - = render :partial => "refs/tree_item", :locals => { :content => content } + = render :partial => "refs/tree_item", :locals => { :content => content, :index => (index += 1) } - contents.select{ |i| i.is_a?(Grit::Blob)}.each do |content| - = render :partial => "refs/tree_item", :locals => { :content => content } + = render :partial => "refs/tree_item", :locals => { :content => content, :index => (index += 1) } - contents.select{ |i| i.is_a?(Grit::Submodule)}.each do |content| - = render :partial => "refs/submodule_item", :locals => { :content => content } + = render :partial => "refs/submodule_item", :locals => { :content => content, :index => (index += 1) } - if content = contents.select{ |c| c.is_a?(Grit::Blob) and c.name =~ /^readme/i }.first .file_holder#README @@ -58,8 +59,9 @@ }); + // Load last commit log for each file in tree $(window).load(function(){ - $.ajax({type: "GET", url: '#{@logs_path}', dataType: "script"}); + ajaxGet('#{@logs_path}'); }); diff --git a/app/views/refs/_tree_item.html.haml b/app/views/refs/_tree_item.html.haml index 30331944a7f306a7083a3c5dce0611eb7e3064fa..4ce16b22ddd6d59345e1f6d631d077ea5cd61bd1 100644 --- a/app/views/refs/_tree_item.html.haml +++ b/app/views/refs/_tree_item.html.haml @@ -1,15 +1,11 @@ -- file = params[:path] ? File.join(params[:path], content.name) : content.name -%tr{ :class => "tree-item file_#{Digest::SHA1.hexdigest(content.name)}", :url => tree_file_project_ref_path(@project, @ref, file) } +- file = tree_full_path(content) +%tr{ :class => "tree-item #{tree_hex_class(content)}", :url => tree_file_project_ref_path(@project, @ref, file) } %td.tree-item-file-name - - if content.is_a?(Grit::Blob) - - if content.text? - = image_tag "file_txt.png", :class => "tree-ico" - - elsif content.image? - = image_tag "file_img.png", :class => "tree-ico" - - else - = image_tag "file_bin.png", :class => "tree-ico" - - else - = image_tag "file_dir.png", :class => "tree-ico" + = tree_icon(content) = link_to truncate(content.name, :length => 40), tree_file_project_ref_path(@project, @ref || @commit.id, file), :remote => :true %td.tree_time_ago.cgray + - if index == 1 + %span.log_loading + Loading commit data.. + = image_tag "ajax_loader_tree.gif", :width => 14 %td.tree_commit diff --git a/app/views/refs/logs_tree.js.haml b/app/views/refs/logs_tree.js.haml index ea8337398a45f48e700e654cd658c2ef1e1b2696..402f5aa72bc742f21ad6c6acefcf37912b8a49f9 100644 --- a/app/views/refs/logs_tree.js.haml +++ b/app/views/refs/logs_tree.js.haml @@ -4,6 +4,6 @@ - tm = @project.team_member_by_name_or_email(content_commit.author_email, content_commit.author_name) :plain - var row = $("table.table_#{@hex_path} tr.file_#{Digest::SHA1.hexdigest(file_name)}"); + var row = $("table.table_#{@hex_path} tr.file_#{hexdigest(file_name)}"); row.find("td.tree_time_ago").html('#{escape_javascript(time_ago_in_words(content_commit.committed_date))} ago'); row.find("td.tree_commit").html('#{escape_javascript(render("tree_commit", :tm => tm, :content_commit => content_commit))}'); diff --git a/app/views/refs/tree.js.haml b/app/views/refs/tree.js.haml index 600ba62606ef0bdf96e0a1f62dc550fdbe593ae8..9cf55057a6aa48a87653ca4fab518111ccb1747d 100644 --- a/app/views/refs/tree.js.haml +++ b/app/views/refs/tree.js.haml @@ -1,9 +1,10 @@ :plain + // Load Files list $("#tree-holder").html("#{escape_javascript(render(:partial => "tree", :locals => {:repo => @repo, :commit => @commit, :tree => @tree}))}"); $("#tree-content-holder").show("slide", { direction: "right" }, 150); $('.project-refs-form #path').val("#{params[:path]}"); - + // Load last commit log for each file in tree $('#tree-slider').waitForImages(function() { - $.ajax({type: "GET", url: '#{@logs_path}', dataType: "script"}); + ajaxGet('#{@logs_path}'); });