Commit f88a2617e65ecc037d3f885965efcee39745163d
1 parent
1a2bacfb
Exists in
master
and in
4 other branches
Tree ajax log. progress bar & refactoring
Showing
8 changed files
with
53 additions
and
18 deletions
Show diff stats
6.38 KB
app/assets/javascripts/application.js
app/helpers/application_helper.rb
| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | +module TreeHelper | |
| 2 | + def tree_icon(content) | |
| 3 | + if content.is_a?(Grit::Blob) | |
| 4 | + if content.text? | |
| 5 | + image_tag "file_txt.png" | |
| 6 | + elsif content.image? | |
| 7 | + image_tag "file_img.png" | |
| 8 | + else | |
| 9 | + image_tag "file_bin.png" | |
| 10 | + end | |
| 11 | + else | |
| 12 | + image_tag "file_dir.png" | |
| 13 | + end | |
| 14 | + end | |
| 15 | + | |
| 16 | + def tree_hex_class(content) | |
| 17 | + "file_#{hexdigest(content.name)}" | |
| 18 | + end | |
| 19 | + | |
| 20 | + def tree_full_path(content) | |
| 21 | + if params[:path] | |
| 22 | + File.join(params[:path], content.name) | |
| 23 | + else | |
| 24 | + content.name | |
| 25 | + end | |
| 26 | + end | |
| 27 | +end | ... | ... |
app/views/refs/_tree.html.haml
| ... | ... | @@ -29,12 +29,13 @@ |
| 29 | 29 | %td |
| 30 | 30 | %td |
| 31 | 31 | |
| 32 | + - index = 0 | |
| 32 | 33 | - contents.select{ |i| i.is_a?(Grit::Tree)}.each do |content| |
| 33 | - = render :partial => "refs/tree_item", :locals => { :content => content } | |
| 34 | + = render :partial => "refs/tree_item", :locals => { :content => content, :index => (index += 1) } | |
| 34 | 35 | - contents.select{ |i| i.is_a?(Grit::Blob)}.each do |content| |
| 35 | - = render :partial => "refs/tree_item", :locals => { :content => content } | |
| 36 | + = render :partial => "refs/tree_item", :locals => { :content => content, :index => (index += 1) } | |
| 36 | 37 | - contents.select{ |i| i.is_a?(Grit::Submodule)}.each do |content| |
| 37 | - = render :partial => "refs/submodule_item", :locals => { :content => content } | |
| 38 | + = render :partial => "refs/submodule_item", :locals => { :content => content, :index => (index += 1) } | |
| 38 | 39 | |
| 39 | 40 | - if content = contents.select{ |c| c.is_a?(Grit::Blob) and c.name =~ /^readme/i }.first |
| 40 | 41 | .file_holder#README |
| ... | ... | @@ -58,8 +59,9 @@ |
| 58 | 59 | |
| 59 | 60 | }); |
| 60 | 61 | |
| 62 | + // Load last commit log for each file in tree | |
| 61 | 63 | $(window).load(function(){ |
| 62 | - $.ajax({type: "GET", url: '#{@logs_path}', dataType: "script"}); | |
| 64 | + ajaxGet('#{@logs_path}'); | |
| 63 | 65 | }); |
| 64 | 66 | |
| 65 | 67 | ... | ... |
app/views/refs/_tree_item.html.haml
| 1 | -- file = params[:path] ? File.join(params[:path], content.name) : content.name | |
| 2 | -%tr{ :class => "tree-item file_#{Digest::SHA1.hexdigest(content.name)}", :url => tree_file_project_ref_path(@project, @ref, file) } | |
| 1 | +- file = tree_full_path(content) | |
| 2 | +%tr{ :class => "tree-item #{tree_hex_class(content)}", :url => tree_file_project_ref_path(@project, @ref, file) } | |
| 3 | 3 | %td.tree-item-file-name |
| 4 | - - if content.is_a?(Grit::Blob) | |
| 5 | - - if content.text? | |
| 6 | - = image_tag "file_txt.png", :class => "tree-ico" | |
| 7 | - - elsif content.image? | |
| 8 | - = image_tag "file_img.png", :class => "tree-ico" | |
| 9 | - - else | |
| 10 | - = image_tag "file_bin.png", :class => "tree-ico" | |
| 11 | - - else | |
| 12 | - = image_tag "file_dir.png", :class => "tree-ico" | |
| 4 | + = tree_icon(content) | |
| 13 | 5 | = link_to truncate(content.name, :length => 40), tree_file_project_ref_path(@project, @ref || @commit.id, file), :remote => :true |
| 14 | 6 | %td.tree_time_ago.cgray |
| 7 | + - if index == 1 | |
| 8 | + %span.log_loading | |
| 9 | + Loading commit data.. | |
| 10 | + = image_tag "ajax_loader_tree.gif", :width => 14 | |
| 15 | 11 | %td.tree_commit | ... | ... |
app/views/refs/logs_tree.js.haml
| ... | ... | @@ -4,6 +4,6 @@ |
| 4 | 4 | - tm = @project.team_member_by_name_or_email(content_commit.author_email, content_commit.author_name) |
| 5 | 5 | |
| 6 | 6 | :plain |
| 7 | - var row = $("table.table_#{@hex_path} tr.file_#{Digest::SHA1.hexdigest(file_name)}"); | |
| 7 | + var row = $("table.table_#{@hex_path} tr.file_#{hexdigest(file_name)}"); | |
| 8 | 8 | row.find("td.tree_time_ago").html('#{escape_javascript(time_ago_in_words(content_commit.committed_date))} ago'); |
| 9 | 9 | row.find("td.tree_commit").html('#{escape_javascript(render("tree_commit", :tm => tm, :content_commit => content_commit))}'); | ... | ... |
app/views/refs/tree.js.haml
| 1 | 1 | :plain |
| 2 | + // Load Files list | |
| 2 | 3 | $("#tree-holder").html("#{escape_javascript(render(:partial => "tree", :locals => {:repo => @repo, :commit => @commit, :tree => @tree}))}"); |
| 3 | 4 | $("#tree-content-holder").show("slide", { direction: "right" }, 150); |
| 4 | 5 | $('.project-refs-form #path').val("#{params[:path]}"); |
| 5 | 6 | |
| 6 | - | |
| 7 | + // Load last commit log for each file in tree | |
| 7 | 8 | $('#tree-slider').waitForImages(function() { |
| 8 | - $.ajax({type: "GET", url: '#{@logs_path}', dataType: "script"}); | |
| 9 | + ajaxGet('#{@logs_path}'); | |
| 9 | 10 | }); | ... | ... |