Refactoring: define the constant ResourceHelper::DUPLICATION_SNIPPET_DEFAULT_NB_OF_LINES=6
# 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
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>
-<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>
$('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