OSDN Git Service

Tree ajax log. progress bar & refactoring
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Tue, 10 Jul 2012 20:12:38 +0000 (23:12 +0300)
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Tue, 10 Jul 2012 20:12:38 +0000 (23:12 +0300)
app/assets/images/ajax_loader_tree.gif [new file with mode: 0644]
app/assets/javascripts/application.js
app/helpers/application_helper.rb
app/helpers/tree_helper.rb [new file with mode: 0644]
app/views/refs/_tree.html.haml
app/views/refs/_tree_item.html.haml
app/views/refs/logs_tree.js.haml
app/views/refs/tree.js.haml

diff --git a/app/assets/images/ajax_loader_tree.gif b/app/assets/images/ajax_loader_tree.gif
new file mode 100644 (file)
index 0000000..99d5a0f
Binary files /dev/null and b/app/assets/images/ajax_loader_tree.gif differ
index 4815d18..527b5c7 100644 (file)
@@ -114,3 +114,8 @@ function showDiff(link) {
             return _chosen.apply(this, [default_options]);
     }})
 })(jQuery);
+
+
+function ajaxGet(url) { 
+  $.ajax({type: "GET", url: url, dataType: "script"}); 
+}
index 2697fff..3f15fd9 100644 (file)
@@ -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 (file)
index 0000000..ed3053d
--- /dev/null
@@ -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
index 1965fe4..ba0bd69 100644 (file)
           %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}'); 
   });
 
 
index 3033194..4ce16b2 100644 (file)
@@ -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
index ea83373..402f5aa 100644 (file)
@@ -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))}');
index 600ba62..9cf5505 100644 (file)
@@ -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}'); 
   });