]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3101 fix the Collapse link
authorsimonbrandhof <simon.brandhof@gmail.com>
Sun, 18 Dec 2011 11:25:20 +0000 (12:25 +0100)
committersimonbrandhof <simon.brandhof@gmail.com>
Sun, 18 Dec 2011 12:16:35 +0000 (13:16 +0100)
Refactoring: define the constant ResourceHelper::DUPLICATION_SNIPPET_DEFAULT_NB_OF_LINES=6

sonar-server/src/main/webapp/WEB-INF/app/helpers/resource_helper.rb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_duplications.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_duplications_source_snippet.html.erb
sonar-server/src/main/webapp/javascripts/duplications.js

index a45515959d554c7e68407d2e749cb757abe427ba..60547cb2b264dc8f6ee6b3fce9fe635754e3d021 100644 (file)
@@ -18,5 +18,5 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
 #
 module ResourceHelper
-  
+  DUPLICATION_SNIPPET_DEFAULT_NB_OF_LINES = 6
 end
\ No newline at end of file
index abc6aae8d317afa98e327a81144ae7b5446613d4..3fc24f80bac2fe493289f08ac4b2435cae6ee23d 100644 (file)
@@ -45,9 +45,9 @@
             external = resource.root_id != @resource.root_id
             lines_count = dup[:lines_count].to_i
             from_line = dup[:from_line].to_i
-            to_line = from_line + (lines_count > 5 ? 5 : lines_count)
+            included_to_line = from_line + [ResourceHelper::DUPLICATION_SNIPPET_DEFAULT_NB_OF_LINES, lines_count].min - 1
             lines_count = dup[:lines_count].to_i
-            update_snippet_script = "updateDuplicationLines('#{url_for :action => :show_duplication_snippet, :params => {:id => resource.id, :original_resource_id => @resource.id}}',#{group_index}, #{index}, #{lines_count}, #{from_line}, #{to_line});"
+            update_snippet_script = "updateDuplicationLines('#{url_for :action => :show_duplication_snippet, :params => {:id => resource.id, :original_resource_id => @resource.id}}',#{group_index}, #{index}, #{lines_count}, #{from_line}, #{included_to_line});"
           %>
             <p id="duplName-<%= group_index -%>-<%= index -%>" class="<%= 'selected' if index==0 -%>">
               <a href="#" onclick="return <%= update_snippet_script -%>;"><%= resource.name -%></a>
             from_line = duplication[:from_line].to_i
             lines_count = duplication[:lines_count].to_i
             external = resource.root_id != @resource.root_id
-            to_line = from_line + (lines_count > 5 ? 5 : lines_count)
+            included_to_line = from_line + [ResourceHelper::DUPLICATION_SNIPPET_DEFAULT_NB_OF_LINES, lines_count].min - 1
           %>
           <div id="source-<%= group_index -%>">
-            <%= render :partial => 'duplications_source_snippet', :locals => {:resource => resource, :original_resource => @resource, :from_line => from_line, :to_line => to_line, :lines_count => lines_count, :external => external, :group_index => group_index} -%>
+            <%= render :partial => 'duplications_source_snippet', :locals => {:resource => resource, :original_resource => @resource, :from_line => from_line, :to_line => included_to_line, :lines_count => lines_count, :external => external, :group_index => group_index} -%>
           </div>
         </td>
       </tr>
index 02b4460950f6a085f865b46922abf1e555a9b17f..a4c3490b1774d3ee9cfabcbf9fe5eaebf7e7e537 100644 (file)
@@ -1,4 +1,4 @@
-<div class="<%= 'expanded' if to_line == from_line + lines_count -%>">
+<div class="<%= 'expanded' if to_line == from_line + lines_count -1 -%>">
   <%
      if external
        parent_project = resource.project
 
   <%= snapshot_source_to_html(resource.last_snapshot, {:line_range => from_line..to_line}) -%>
 
-  <% if lines_count > 5 %>
+  <% if lines_count > ResourceHelper::DUPLICATION_SNIPPET_DEFAULT_NB_OF_LINES %>
     <p class="small">
       <%
-         if to_line < from_line + lines_count
+         if to_line < from_line + lines_count -1
            link_text = message('duplications.expand')
-           to_line = from_line + lines_count - 1
+           included_to_line = from_line + lines_count - 1
          else
            link_text = message('duplications.collapse')
-           to_line = from_line + 5
+           included_to_line = from_line + ResourceHelper::DUPLICATION_SNIPPET_DEFAULT_NB_OF_LINES - 1
          end
       %>
       <%= link_to_remote link_text,
-                         :url => {:action => :show_duplication_snippet, :params => {:id => resource.id, :original_resource_id => original_resource.id, :from_line => from_line, :to_line => to_line, :lines_count => lines_count, :group_index => group_index}},
+                         :url => {:action => :show_duplication_snippet, :params => {:id => resource.id, :original_resource_id => original_resource.id, :from_line => from_line, :to_line => included_to_line, :lines_count => lines_count, :group_index => group_index}},
                          :update => "source-#{group_index}",
                          :before => "$('expanding-#{group_index}').addClassName('loading')" -%>
       <span id="expanding-<%= group_index -%>"></span>
index 94f122f2fd75031dd57c755fc046e910f78efeb3..d8664f19ccee8793290cbaeb882bf98713edd340 100644 (file)
@@ -8,9 +8,9 @@ function updateDuplicationLines(url, groupId, itemId, linesCount, fromLine, toLi
   $('duplLoading-' + groupId).addClassName('loading');
 
   if ($('source-' + groupId).childElements()[0].hasClassName('expanded')) {
-         toLine = fromLine + linesCount;
+    toLine = fromLine + linesCount -1;
   }
-  
+
   new Ajax.Updater('source-' + groupId, url + "&to_line=" + toLine + "&from_line=" + fromLine + "&lines_count=" + linesCount + "&group_index=" + groupId, {asynchronous:true, evalScripts:true});
   return false;
 }
\ No newline at end of file