diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e0cbc2524..1e8ae7f1e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -963,6 +963,20 @@ class ApplicationController < ActionController::Base end end + # gitlab分页定制 + def paginateHelperForGitlab obj, pre_size=15 + @obj_count = obj.count + @obj_pages = Paginator.new @obj_count, pre_size, params['page'] + if obj.kind_of? ActiveRecord::Base or obj.kind_of? ActiveRecord::Relation + obj.limit(@obj_pages.per_page).offset(@obj_pages.offset) + elsif obj.kind_of? Array + obj[0, @obj_pages.per_page] + else + logger.error "[ApplicationController] Error : application_controller#paginateHelper ===> unknow category: #{obj.class}" + raise RuntimeError, 'unknow type, Please input you type into this helper.' + end + end + #查找首页相关信息 def find_first_page @first_page = FirstPage.find_by_page_type('project') diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index b081230d1..0a139e648 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -36,17 +36,17 @@ class RepositoriesController < ApplicationController before_filter :find_repository, :only => [:edit, :update, :destroy, :committers] before_filter :find_project_repository, :except => [:commits, :shixun_show, :new, :create, :newcreate, :edit, :update, :destroy, :committers, - :newrepo, :to_gitlab, :forked, :export_rep_static, :training_project_extend, :shixun_entry] + :newrepo, :to_gitlab, :forked, :export_rep_static, :training_project_extend, :shixun_entry, :shixun_commit_diff] # 实训项目新增 - before_filter :find_project_and_repository, :only => [:commits, :shixun_show, :shixun_entry] + before_filter :find_project_and_repository, :only => [:commits, :shixun_show, :shixun_entry, :shixun_commit_diff] # 连接gitlab # before_filter :connect_gitlab, :only => [:quality_analysis, :commit_diff] before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue] # before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff] - before_filter :authorize_visible , :except => [:shixun_show, :newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff] + before_filter :authorize_visible , :except => [:shixun_show, :newrepo,:newcreate,:fork, :to_gitlab, :forked, :project_archive, :quality_analysis, :commit_diff, :shixun_commit_diff] # 版本库新增权限 # before_filter :show_rep, :only => [:show, :stats, :revisions, :revision, :diff, :commit_diff ] accept_rss_auth :revisions @@ -620,11 +620,15 @@ update @project_menu_type = 5 @entry = @repository.entry(@path, @rev) (show_error_not_found; return) unless @entry - limit = 10 + limit = 15 # 每次页面的换回值从1开始,但是gitlab的页面查询是从0开始,所以先改变page的类型减一在改回来 @commits = @g.commits(@shixun.gpid, page:(params[:page].to_i - 1).to_s, ref_name:@rev) @commits_count = params[:commit_count].nil? ? @g.user_static(@shixun.gpid, :rev => @rev).count : params[:commit_count].to_i - @commits_pages = Paginator.new @commits_count, limit, params[:page] + # @commits_pages = Paginator.new @commits_count, limit, params[:page] + + @commits_pages = Paginator.new @commits_count, limit, params['page'] || 1 + @offset ||= @commits_pages.offset + @commits = paginateHelperForGitlab @commits, limit render :layout => 'base_shixun' end @@ -798,6 +802,17 @@ update render :layout => 'base_projects' end + def shixun_commit_diff + @commit_diff = @g.commit_diff(@shixun.gpid, params[:changeset_id]) + diff = ActiveSupport::JSON.decode(@commit_diff.to_json).first + diff = OpenStruct.new(diff) + @diff_file = Trustie::Gitlab::Diff::File.new(diff) + + + # @commit_details = @g.commit(@project.gpid, params[:changeset]) + render :layout => 'base_shixun' + end + # 实训项目 # 每次提交对应的文件差异 def commit diff --git a/app/views/repositories/_link_to_functions.html.erb b/app/views/repositories/_link_to_functions.html.erb index 5f0c80292..8e92cb14f 100644 --- a/app/views/repositories/_link_to_functions.html.erb +++ b/app/views/repositories/_link_to_functions.html.erb @@ -27,7 +27,7 @@ <% else %> <% if params[:controller] == "shixuns" && params[:action] == "entry_edit" %> 保存 - <% elsif params[:action] == "shixun_entry" %> + <% elsif params[:action] == "shixun_entry" || params[:action] == "entry_update" %> <%= link_to "编辑", entry_edit_shixun_path(@shixun, :path => @path, :rev => @rev), :class => "fl mr5", :remote => true %> <% end %> <% end %> diff --git a/app/views/repositories/commits.html.erb b/app/views/repositories/commits.html.erb index ef58abfa6..0502b6235 100644 --- a/app/views/repositories/commits.html.erb +++ b/app/views/repositories/commits.html.erb @@ -16,12 +16,12 @@ <%= time_tag(commit.created_at) %>前 <%= link_to_user_mail(commit.author_email, "pullreques_pull_name fl ml10") %>

<%= commit.title %>

- <%= link_to truncate(commit.short_id, :length => 20), {:controller => 'repositories', :action => 'commits', :id => @shixun.id, :changeset_id => commit.id}, :target => "_blank", :class => "fr mr15 c_grey" %> + <%= link_to truncate(commit.short_id, :length => 20), {:controller => 'repositories', :action => 'shixun_commit_diff', :id => @shixun, :changeset_id => commit.id}, :target => "_blank", :class => "fr mr15 c_grey" %> <% unless get_commit_issues(commit.short_id, @shixun.id, 0).nil? %> <% get_commit_issues(commit.short_id, @shixun.id, 0).each do |issue_id| %>
<% if issue_id == "more" %> - <%= link_to "更多", {:controller => 'repositories', :action => 'commit_diff', :id => @shixun.id, :changeset => commit.id}, :target => "_blank", :class => "commit_id_value mr5" %> + <%= link_to "更多", {:controller => 'repositories', :action => 'commit_diff', :id => @shixun, :changeset => commit.id}, :target => "_blank", :class => "commit_id_value mr5" %> <% else %> <%= link_to "##{issue_id}", issue_path(issue_id), :target => "_blank", :class => "commit_id_value mr5" %> <% end %> @@ -35,15 +35,15 @@
<% end %> +
-
+
    <%= pagination_links_full @commits_pages, @commits_count, :per_page_links => false, :remote => false, :flag => true, :is_new => true %>
-
<%= call_hook(:view_repositories_show_contextual, { :repository => @repository, :project => @shixun }) %> <% html_title(l(:label_change_plural)) -%> diff --git a/app/views/repositories/shixun_commit_diff.html.erb b/app/views/repositories/shixun_commit_diff.html.erb new file mode 100644 index 000000000..1570978b9 --- /dev/null +++ b/app/views/repositories/shixun_commit_diff.html.erb @@ -0,0 +1,24 @@ +
+
+
+ <%=link_to "返回提交历史".html_safe, + {:action => 'commits', :path => to_path_param(@path), :id => @shixun, :repository_id => @repository.identifier_param, + :rev => @rev, :page => 1 ,:commit_count =>"#{@changesets_all_count}"}, :class => "fl linkBlue2 mt3" %> +
+
+ <% unless @commit_diff.blank? %> + <% @commit_diff.each do |commit_diff| %> + +
+ <%= render :partial => 'repositories/change_diff', :locals => {:change => commit_diff} %> +
+ <% end %> + <% else %> + <%= render "welcome/no_data" %> + <% end %> + +
diff --git a/config/routes.rb b/config/routes.rb index 2838903d1..8eda09b76 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1341,7 +1341,7 @@ RedmineApp::Application.routes.draw do get 'projects/:id/repository/:repository_id/changes(/*path(.:ext))', :to => 'repositories#changes' # shixun get 'shixuns/:id/repository/:repository_id/commits(/*path(.:ext))', :to => 'repositories#commits' - get 'shixuns/:id/repository/:repository_id/commits/:changeset_id', :to => 'repositories#commits' + get 'shixuns/:id/repository/:repository_id/shixun_commit_diff/:changeset_id', :to => 'repositories#shixun_commit_diff' get 'projects/:id/repository/:repository_id/revisions/:rev', :to => 'repositories#revision' get 'projects/:id/repository/:repository_id/revision', :to => 'repositories#revision'