Gitlab提供搜索接口,commit 关联提供搜索功能及局部刷新

This commit is contained in:
huang 2016-12-08 16:36:11 +08:00
parent 0785c71308
commit d98b1e17cc
4 changed files with 17 additions and 7 deletions

View File

@ -63,18 +63,27 @@ class IssuesController < ApplicationController
begin
return render_404 if @project.gpid.nil?
@issue_commit_ids = (params[:issue_commit_ids].is_a?(Array) ? params[:issue_commit_ids] : params[:issue_commit_ids].split(",")) unless params[:issue_commit_ids].nil?
search = params[:search].to_s.lstrip.rstrip
search = params[:search].to_s.strip
@type = params[:type]
limit = 20
limit = 15
g = Gitlab.client
g_project = g.project(@project.gpid)
rev = params[:branch].nil? ? g_project.default_branch : params[:branch]
@commits = g.commits(@project.gpid, page:(params[:page].to_i - 1).to_s, ref_name:rev).select{|commit| commit.title.include?("#{search}")}
@project_branches = g.branches(@project.gpid)
@branch_names = @project_branches.map{|b| b.name}
@default_branch = g_project.default_branch
# 搜索的分页需要单独处理,因为搜索不容易获取总数
if search.present?
@commits = g.commits(@project.gpid, ref_name:rev, :search => search)
@commits_count = @commits.count
@commits_pages = Paginator.new @commits_count, limit, params['page'] || 1
@offset ||= @commits_pages.offset
@commits = paginateHelper @commits,limit
else
@commits = g.commits(@project.gpid, page:(params[:page].to_i - 1).to_s, ref_name:rev, :search => search)
@commits_count = g.user_static(@project.gpid, :rev => rev).count
@commits_pages = Redmine::Pagination::Paginator.new @commits_count, limit, params[:page]
end
rescue Exception => e
puts e
end

View File

@ -25,7 +25,7 @@
<input value="" name="issue_for_commit_ids" id="issue_for_commit_ids" type="hidden">
</table>
<div class="clear">
<div class="clear fl mt10">
<div class="clear fl mt10 mb10">
<a href="javascript:void(0);" class="sy_btn_blue fl" onclick="search_and_branch_for_commit_ids();">确&nbsp;&nbsp;定</a>
<a href="javascript:void(0);" class="sy_btn_grey fl ml10" onclick="hideModal()">取&nbsp;&nbsp;消</a>
</div>

View File

@ -2,6 +2,6 @@
$("#issue_commit_list").html('<%= escape_javascript(render :partial => 'issues/issue_commits_list') %>');
<% else %>
var htmlvalue = "<%= escape_javascript(render :partial => 'issues/issue_commits') %>";
pop_box_new(htmlvalue,760,860);
pop_box_new(htmlvalue,760,600);
<% end %>

View File

@ -52,6 +52,7 @@ class Gitlab::Client
# @option options [String] :ref_name The branch or tag name of a project repository.
# @option options [Integer] :page The page number.
# @option options [Integer] :per_page The number of results per page.
# @option options [String] :search The obj of results's search value.
# @return [Array<Gitlab::ObjectifiedHash>]
def commits(project, options={})
get("/projects/#{project}/repository/commits", :query => options)