Please review pull request #73: (#7869) Fix missing diff in dashboard Event tab opened by (eshamow)

Description:

Modify event message to replace the word "changed"
to link to a diff against the previously stored
version. Needs some additional logic to prevent
calling against a diff that wasn't previously
stored, but this is no different from current
behavior and should be refactored separately.

Modify spec file to match this behavior.

Modify behavior of report helper to check for
md5s before modifying to add filebucket links

NOTE - this is a resurrection of
https://github.com/puppetlabs/puppet-dashboard/pull/70,
with the changes requested by Nick Lewis appended.

  • Opened: Tue Dec 20 05:30:26 UTC 2011
  • Based on: puppetlabs:master (f0f694f115d8bc52955b5968f01f08308484ca11)
  • Requested merge: eshamow:7869_dashboard_filebucket_diffs (a262a805900913203a8a53aa03e04387c8f9400d)

Diff follows:

diff --git a/app/helpers/reports_helper.rb b/app/helpers/reports_helper.rb
index 41cd1fc..e980798 100644
--- a/app/helpers/reports_helper.rb
+++ b/app/helpers/reports_helper.rb
@@ -1,12 +1,19 @@
 module ReportsHelper
   def popup_md5s( string, options = {} )
     if SETTINGS.use_file_bucket_diffs
-      string.gsub(/\{md5\}[a-fA-F0-9]{32}/) do |match|
-        if options[:exclude_md5s] and options[:exclude_md5s].include? match
-          match
-        else
-          link_to_function options[:label] || match, "display_file_popup('#{url_for :controller => :files, :action ="" :show, :file => match.sub('{md5}','')}')", :class => 'popup-md5'
+      hashes = string.scan(/\{md5\}[a-fA-F0-9]{32}/)
+      
+      # if we have a message containing md5s, evaluate for filebucket link
+      if hashes.length != 0
+        string.gsub(/changed/, link_to_function( "\\&", "display_file_popup('#{url_for :controller => :files, :action ="" :diff, :file1 => hashes[0].sub('{md5}',''), :file2 => hashes[1].sub('{md5}','')}')", :class => 'popup-md5')).gsub(/\{md5\}[a-fA-F0-9]{32}/) do |match|
+          if options[:exclude_md5s] and options[:exclude_md5s].include? match
+            match
+          else
+            link_to_function options[:label] || match, "display_file_popup('#{url_for :controller => :files, :action ="" :show, :file => match.sub('{md5}','')}')", :class => 'popup-md5'
+          end
         end
+      else
+        string
       end
     else
       string
diff --git a/spec/helpers/reports_helper_spec.rb b/spec/helpers/reports_helper_spec.rb
index 23133b7..981503c 100644
--- a/spec/helpers/reports_helper_spec.rb
+++ b/spec/helpers/reports_helper_spec.rb
@@ -9,7 +9,13 @@
 
     it "should make anything that looks like an md5 into a filebucket link" do
       helper.popup_md5s(@text).gsub(/\s/, '').should == <<-HEREDOC.gsub(/\s/, '')
-        content changed '<a
+        content <a
+          class=\"popup-md5\"
+          href=""
+          _onclick_=\"display_file_popup( '/files/diff?file1=b84b7c77fb71f0d945f186513a09e185&amp;file2=d28d2d3560fa76f0dbb1a452f8c38169'); 
+          return false;\">
+          changed
+        </a> '<a
           class=\"popup-md5\"
           href=""
           _onclick_=\"display_file_popup( '/files/show?file=b84b7c77fb71f0d945f186513a09e185'); return false;\">
@@ -25,7 +31,13 @@
 
     it "should make the link text be a label if it's passed in" do
       helper.popup_md5s(@text, :label => 'foo').gsub(/\s/, '').should == <<-HEREDOC.gsub(/\s/, '')
-        content changed '<a
+        content <a
+          class=\"popup-md5\"
+          href=""
+          _onclick_=\"display_file_popup( '/files/diff?file1=b84b7c77fb71f0d945f186513a09e185&amp;file2=d28d2d3560fa76f0dbb1a452f8c38169'); 
+          return false;\">
+          changed
+        </a> '<a
           class=\"popup-md5\"
           href=""
           _onclick_=\"display_file_popup( '/files/show?file=b84b7c77fb71f0d945f186513a09e185'); return false;\">
@@ -41,7 +53,13 @@
 
     it "should not link md5s if they're in the excluded list" do
       helper.popup_md5s(@text, :exclude_md5s => ['{md5}d28d2d3560fa76f0dbb1a452f8c38169']).gsub(/\s/, '').should == <<-HEREDOC.gsub(/\s/, '')
-        content changed '<a
+        content <a
+          class=\"popup-md5\"
+          href=""
+          _onclick_=\"display_file_popup( '/files/diff?file1=b84b7c77fb71f0d945f186513a09e185&amp;file2=d28d2d3560fa76f0dbb1a452f8c38169'); 
+          return false;\">
+          changed
+        </a> '<a
           class=\"popup-md5\"
           href=""
           _onclick_=\"display_file_popup( '/files/show?file=b84b7c77fb71f0d945f186513a09e185'); return false;\">

    

--
You received this message because you are subscribed to the Google Groups "Puppet Developers" group.
To post to this group, send email to puppet-dev@googlegroups.com.
To unsubscribe from this group, send email to puppet-dev+unsubscr...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to