Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View refactorings #8

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 49 additions & 13 deletions app/helpers/code_review_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,57 @@
module CodeReviewHelper
unloadable
def show_assignments(assignments, project, options = {})
html = "#{l(:review_assignments)}:"
assignments.each do |assignment|
issue = assignment.issue
html << link_to("##{issue.id} ", {:controller => 'issues', :action => 'show', :id => issue.id},
:class => issue.css_classes, :title => "#{issue}(#{issue.status})")
end if assignments

link = link_to(l(:button_add), {:controller => 'code_review',
:action => 'assign', :id=>project, :action_type => options[:action_type],
:rev => options[:rev], :rev_to => options[:rev_to], :path => options[:path],
:change_id => options[:change_id], :attachment_id => options[:attachment_id],
:changeset_id => options[:changeset_id]}, :class => 'icon icon-add')
links = if assignments
assignments.map do |assignment|
issue = assignment.issue
link_to("##{issue.id} ", {:controller => 'issues', :action => 'show', :id => issue.id},
:class => issue.css_classes, :title => "#{issue}(#{issue.status})")
end
else
[]
end

html << link if link
links << link_to(
l(:button_add),
options.merge(controller: 'code_review', action: 'assign', id: project),
class: 'icon icon-add'
)

html
safe_join links
end

def progress_for_changeset(changeset)
progress = if changeset.review_count > 0
content_tag(:span, style: "white-space: nowrap") do
progress_bar(
[changeset.closed_review_pourcent, changeset.completed_review_pourcent],
:width => '60px',
:legend => "#{changeset.closed_review_count}/#{changeset.review_count} #{l(:label_closed_issues)}"
)
end

elsif changeset.assignment_count > 0
if (changeset.open_assignment_count > 0)
l(:code_review_assigned)
else
l(:code_review_reviewed)
end

elsif User.current.allowed_to?(:assign_code_review, @project)
content_tag(:span, style: "white-space: nowrap") do
l(:lable_no_code_reviews)
end + ':'.html_safe +
content_tag(:span, style: "white-space: nowrap") do
link_to(l(:label_assign_review), {:controller => 'code_review',
:action => 'assign', :id=>@project,
:rev => changeset.revision,
:changeset_id => changeset.id})
end
end

content_tag(:p, class: "progress-info", style: "white-space: nowrap;") do
progress
end if progress
end
end
7 changes: 5 additions & 2 deletions app/models/code_review_project_setting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ class CodeReviewProjectSetting < ActiveRecord::Base
AUTORELATION_TYPE_RELATES = 1
AUTORELATION_TYPE_BLOCKS = 2

def self.find_for(project)
where(project_id: project.id).first
end

def self.find_or_create(project)
setting = CodeReviewProjectSetting.find_by_project_id(project.id)
unless setting
unless setting = find_for(project)
setting = CodeReviewProjectSetting.new
setting.project_id = project.id
return setting if project.trackers.length == 0
Expand Down
82 changes: 0 additions & 82 deletions app/views/code_review/_body_bottom.html.erb

This file was deleted.

17 changes: 9 additions & 8 deletions app/views/code_review/_change_attachement_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-%>
<%
parameters = request.parameters
id = parameters[:id].to_i
attachment = Attachment.find(id)
return '' unless attachment.is_text? or attachment.is_diff?
review_id = parameters[:review_id] unless parameters[:review_id].blank?
attachment = Attachment.find(params[:id])
url = url_for :controller => 'code_review', :action => 'update_attachment_view', :id => project
-%>
%>

<% if attachment.is_text? or attachment.is_diff? %>

<div id="code_review">
<div id="review_comment"/>
</div>

<script type="text/javascript">
$(document).ready(function(){
$('#code_review').load('<%=url%>', {'attachment_id': '<%=id%>', 'review_id': '<%=review_id%>'});
$('#code_review').load('<%= j url %>', {'attachment_id': '<%= attachment.id %>', 'review_id': '<%= j params[:review_id].to_s %>'});
});
</script>
</script>

<% end %>
27 changes: 27 additions & 0 deletions app/views/code_review/_change_diff_view.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<% if @repository.find_changeset_by_name(params[:rev]) %>

<%
rev_to = params['rev_to']
review_id = params['review_id']
rev = params['rev']
path = params['path'].blank? ? '.' : Array(params['path']).join('/')

url = url_for controller: 'code_review', action: 'update_diff_view', id: project, repository_id: @repository.identifier_param
%>

<div id="code_review"></div>

<%= javascript_tag do %>
$(document).ready(function(){
$('#code_review').load('<%= j url %>', {
rev: '<%= j rev %>',
path:'<%= j path %>',
review_id: '<%= j review_id %>',
action_type:'<%= j action_name %>',
rev_to: '<%= j rev_to %>'});
});
<% end %>

<% else %>
<%= render partial: 'code_review/change_entry_norevision_view', locals: { project: project } %>
<% end %>
14 changes: 5 additions & 9 deletions app/views/code_review/_change_entry_norevision_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-%>
<%
parameters = request.parameters
path = parameters['path']
rev = parameters['rev']
path = params[:path]
rev = params[:rev]
repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param")
unless path.blank? or path.empty?
changesets = @repository.latest_changesets(path, rev, Setting.repository_log_display_limit.to_i)
change = changesets[0]

if change
unless path.blank?
if change = @repository.latest_changesets(path, rev, 1).first
link = link_to(l(:label_add_review), {:controller => 'code_review',
:action => 'forward_to_revision', :id => project, :path => path, :rev => rev, :repository_id => repository_id},
:class => 'icon icon-edit')
Expand All @@ -36,4 +32,4 @@ unless path.blank? or path.empty?
</script>
<% end %>

<% end %>
<% end %>
10 changes: 3 additions & 7 deletions app/views/code_review/_change_repository_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
<%

if @changesets
changeset_ids = ''
@changesets.each { |changeset|
changeset_ids << changeset.revision
changeset_ids << ','
}
changeset_ids = safe_join @changesets.map(&:revision), ','

repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param")
url = url_for :controller => 'code_review', :action => 'update_revisions_view', :id => project, :repository_id => repository_id
Expand All @@ -34,8 +30,8 @@ if @changesets

<script type="text/javascript">
$(document).ready(function(){
$('#code_review_revisions').load('<%=url%>', {changeset_ids: '<%=raw changeset_ids%>'});
$('#code_review_revisions').load('<%=url%>', {changeset_ids: '<%= j changeset_ids%>'});
});
</script>

<% end %>
<% end %>
37 changes: 14 additions & 23 deletions app/views/code_review/_change_revision_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,23 @@
-%>
<%
repository_id = @repository.identifier_param if @repository.respond_to?("identifier_param")

if @changeset
urlprefix = url_for(:controller => 'repositories', :action => 'revisions', :id => project, :repository_id => repository_id) +
'/' + @changeset.identifier + '/entry'
%>
<%- if User.current.allowed_to?(:assign_code_review, @project) -%>
<div id="code_review_assignments">
<%=h l(:review_assignments)%>
<% @changeset.code_review_assignments.each do |assignment|
issue = assignment.issue %>
<%= link_to("##{issue.id} ", {:controller => 'issues', :action => 'show', :id => issue.id},
:class => issue.css_classes, :title => "#{issue}(#{issue.status})") %>
<% end if @changeset.code_review_assignments %>

<%= link_to(l(:button_add), {:controller => 'code_review',
:action => 'assign', :id=>project,
:rev => @changeset.revision,
:changeset_id => @changeset.id, :repository_id => repository_id}, :class => 'icon icon-add') %>
</div>
<%- end -%>
<% if User.current.allowed_to?(:assign_code_review, @project) %>
<div id="code_review_assignments">
<%= l :review_assignments %>:
<%= show_assignments @changeset.code_review_assignments, @project,
{ rev: @changeset.revision, changeset_id: @changeset.id,
repository_id: repository_id } %>
</div>
<% end %>

<script type="text/javascript">
$('#changes-legend').after($('#code_review_assignments'));
urlprefix = '<%=urlprefix%>';
urlprefix = '<%= j urlprefix%>';
<% @changeset.changes.each{|change| %>
var reviewlist = [];
<%
Expand All @@ -51,7 +45,7 @@ if @changeset
:controller => 'code_review', :action => 'show', :id => project, :review_id => review.id, :repository_id => repository_id)
%>
var review = new CodeReview(<%=review.id%>);
review.url = '<%=url%>';
review.url = '<%= j url%>';
<% if review.is_closed? %>
review.is_closed = true;
<% end %>
Expand All @@ -60,13 +54,10 @@ if @changeset
cnt += 1

}
relative_path = change.path || ""
if relative_path[0] != ?/
relative_path = '/' + relative_path
end
escaped_relative_path = relative_path.gsub("'"){"\\'"}
path = change.path || ""
abs_path = path.start_with?(?/) ? path : "/#{path}"
%>
code_reviews_map['<%=escaped_relative_path-%>'] = reviewlist;
code_reviews_map['<%= j abs_path -%>'] = reviewlist;
<%
}
%>
Expand Down
Loading