From f88a2617e65ecc037d3f885965efcee39745163d Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 10 Jul 2012 23:12:38 +0300 Subject: [PATCH] Tree ajax log. progress bar & refactoring --- app/assets/images/ajax_loader_tree.gif | Bin 0 -> 6531 bytes app/assets/javascripts/application.js | 5 +++++ app/helpers/application_helper.rb | 4 ++++ app/helpers/tree_helper.rb | 27 +++++++++++++++++++++++++ app/views/refs/_tree.html.haml | 10 +++++---- app/views/refs/_tree_item.html.haml | 18 +++++++---------- app/views/refs/logs_tree.js.haml | 2 +- app/views/refs/tree.js.haml | 5 +++-- 8 files changed, 53 insertions(+), 18 deletions(-) create mode 100644 app/assets/images/ajax_loader_tree.gif create mode 100644 app/helpers/tree_helper.rb 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 GIT binary patch literal 6531 zcmZ?wbhEHb6k!lySjxZ<6BV;&-I_bM?zFVE965I6&AT@xMJ01)%}Gg1*|TrYlV?w^ zT)Oh-*Pougo+ZncY}vNu$)hJ{&Yk)4?Mq8jOHN)+OkB*CO-E$-=?Lz`&pbvJ2!*2DV8KlL9n8npiaibR3khYG-k7ReEGF<lb(nE zlqq$4_`Ja8On_Tf=`@v@CYK7;EjJ53xf;&HCs9%F?8VF2)}YAD*`1^)(LbSGk)40) zG%=ahZZ8FP@mY~EVo~!IotXFpCp6|NCsgtzu5uO<7N9N3%Q&Lm{iHIrFru_N!CnqcC%B3r7 zR;{V2s@bz^&yz<_rc9dh<=dB(q?9e&z!A~c^X1c*GpEihS+=C4tOODZb7sx?^Y2ei zUe1+kSJtdsQ&U$%i@0E$?l399LQ}&`gyBU~1ke0KXF5K9urLui_V96wpG&)U@~4;* zyNrwnf(p*>FOby49|Trm43O1Ex2vY4ktcIB}ukzy+{2O zBqcf7WY5+fc9xY@P`J7;09$BdmNIi@fm8M_L=giD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=CDfxCuSxHH8_MA!{PEJn= zMUFaIF;-`OahVD60`i>k{DOR96L@4LBm_1n$qPyI2}{UJ2p@}04VGbK6qS)!>`h#G z0jmGXaMXWwB-DS9?l!3L4W1pKQ6GhEy2IoEkI0U`6Gsayx0o0yEjB!95@^-nyv$0} zP@AD`lhzzQPI0!Gl_5cVs;6eXRW%VQUUubyUA* dROXOYlvL#6V%nL_Ey*I!A$CS#tCJ&xH2~D>Bhml> literal 0 HcmV?d00001 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 4815d180dfb..527b5c795e1 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 2697fff433e..3f15fd9237f 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 00000000000..ed3053d8af5 --- /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 1965fe45b36..ba0bd69116b 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 30331944a7f..4ce16b22ddd 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 ea8337398a4..402f5aa72bc 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 600ba62606e..9cf55057a6a 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}'); }); -- GitLab