Merge branch 'ajax-filter-commits' into 'master'
Ajax filter commits Fixes #3509 ![Screenshot_2016-01-06_13.07.53](/uploads/7400d855d8207e37e3c0ec09cb2265e9/Screenshot_2016-01-06_13.07.53.png) See merge request !2314
This commit is contained in:
commit
0d59e7b90f
9 changed files with 87 additions and 70 deletions
|
@ -23,6 +23,7 @@ v 8.4.0 (unreleased)
|
|||
- Validate README format before displaying
|
||||
- Enable Microsoft Azure OAuth2 support (Janis Meybohm)
|
||||
- Add file finder feature in tree view (koreamic)
|
||||
- Ajax filter by message for commits page
|
||||
|
||||
v 8.3.3 (unreleased)
|
||||
- Get "Merge when build succeeds" to work when commits were pushed to MR target branch while builds were running
|
||||
|
|
|
@ -1,15 +1,5 @@
|
|||
class @CommitsList
|
||||
@data =
|
||||
ref: null
|
||||
limit: 0
|
||||
offset: 0
|
||||
@disable = false
|
||||
|
||||
@showProgress: ->
|
||||
$('.loading').show()
|
||||
|
||||
@hideProgress: ->
|
||||
$('.loading').hide()
|
||||
@timer = null
|
||||
|
||||
@init: (ref, limit) ->
|
||||
$("body").on "click", ".day-commits-table li.commit", (event) ->
|
||||
|
@ -18,38 +8,32 @@ class @CommitsList
|
|||
e.stopPropagation()
|
||||
return false
|
||||
|
||||
@data.ref = ref
|
||||
@data.limit = limit
|
||||
@data.offset = limit
|
||||
Pager.init limit, false
|
||||
|
||||
this.initLoadMore()
|
||||
this.showProgress()
|
||||
@content = $("#commits-list")
|
||||
@searchField = $("#commits-search")
|
||||
@initSearch()
|
||||
|
||||
@initSearch: ->
|
||||
@timer = null
|
||||
@searchField.keyup =>
|
||||
clearTimeout(@timer)
|
||||
@timer = setTimeout(@filterResults, 500)
|
||||
|
||||
@filterResults: =>
|
||||
form = $(".commits-search-form")
|
||||
search = @searchField.val()
|
||||
commitsUrl = form.attr("action") + '?' + form.serialize()
|
||||
@content.fadeTo('fast', 0.5)
|
||||
|
||||
@getOld: ->
|
||||
this.showProgress()
|
||||
$.ajax
|
||||
type: "GET"
|
||||
url: location.href
|
||||
data: @data
|
||||
complete: this.hideProgress
|
||||
success: (data) ->
|
||||
CommitsList.append(data.count, data.html)
|
||||
url: form.attr("action")
|
||||
data: form.serialize()
|
||||
complete: =>
|
||||
@content.fadeTo('fast', 1.0)
|
||||
success: (data) =>
|
||||
@content.html(data.html)
|
||||
# Change url so if user reload a page - search results are saved
|
||||
history.replaceState {page: commitsUrl}, document.title, commitsUrl
|
||||
dataType: "json"
|
||||
|
||||
@append: (count, html) ->
|
||||
$("#commits-list").append(html)
|
||||
if count > 0
|
||||
@data.offset += count
|
||||
else
|
||||
@disable = true
|
||||
|
||||
@initLoadMore: ->
|
||||
$(document).unbind('scroll')
|
||||
$(document).endlessScroll
|
||||
bottomPixels: 400
|
||||
fireDelay: 1000
|
||||
fireOnce: true
|
||||
ceaseFire: =>
|
||||
@disable
|
||||
callback: =>
|
||||
this.getOld()
|
||||
|
|
|
@ -72,6 +72,15 @@
|
|||
> p:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.block-controls {
|
||||
float: right;
|
||||
|
||||
.control {
|
||||
float: left;
|
||||
margin-left: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.cover-block {
|
||||
|
|
|
@ -28,10 +28,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
.commits-feed-holder {
|
||||
float: right;
|
||||
}
|
||||
|
||||
li.commit {
|
||||
list-style: none;
|
||||
|
||||
|
|
|
@ -8,10 +8,16 @@ class Projects::CommitsController < Projects::ApplicationController
|
|||
before_action :authorize_download_code!
|
||||
|
||||
def show
|
||||
@repo = @project.repository
|
||||
@limit, @offset = (params[:limit] || 40).to_i, (params[:offset] || 0).to_i
|
||||
search = params[:search]
|
||||
|
||||
@commits =
|
||||
if search.present?
|
||||
@repository.find_commits_by_message(search, @ref, @path, @limit, @offset).compact
|
||||
else
|
||||
@repository.commits(@ref, @path, @limit, @offset)
|
||||
end
|
||||
|
||||
@commits = @repo.commits(@ref, @path, @limit, @offset)
|
||||
@note_counts = project.notes.where(commit_id: @commits.map(&:id)).
|
||||
group(:commit_id).count
|
||||
|
||||
|
|
|
@ -92,9 +92,12 @@ class Repository
|
|||
commits
|
||||
end
|
||||
|
||||
def find_commits_by_message(query)
|
||||
def find_commits_by_message(query, ref = nil, path = nil, limit = 1000, offset = 0)
|
||||
ref ||= root_ref
|
||||
|
||||
# Limited to 1000 commits for now, could be parameterized?
|
||||
args = %W(#{Gitlab.config.git.bin_path} log --pretty=%H --max-count 1000 --grep=#{query})
|
||||
args = %W(#{Gitlab.config.git.bin_path} log #{ref} --pretty=%H --skip #{offset} --max-count #{limit} --grep=#{query})
|
||||
args = args.concat(%W(-- #{path})) if path.present?
|
||||
|
||||
git_log_results = Gitlab::Popen.popen(args, path_to_repo).first.lines.map(&:chomp)
|
||||
commits = git_log_results.map { |c| commit(c) }
|
||||
|
|
|
@ -10,26 +10,30 @@
|
|||
.tree-ref-holder
|
||||
= render 'shared/ref_switcher', destination: 'commits'
|
||||
|
||||
.commits-feed-holder.hidden-xs.hidden-sm
|
||||
.block-controls.hidden-xs.hidden-sm
|
||||
- if create_mr_button?(@repository.root_ref, @ref)
|
||||
= link_to create_mr_path(@repository.root_ref, @ref), class: 'btn btn-success' do
|
||||
= icon('plus')
|
||||
Create Merge Request
|
||||
.control
|
||||
= link_to create_mr_path(@repository.root_ref, @ref), class: 'btn btn-success' do
|
||||
= icon('plus')
|
||||
Create Merge Request
|
||||
|
||||
.control
|
||||
= form_tag(namespace_project_commits_path(@project.namespace, @project, @id), method: :get, class: 'pull-left commits-search-form') do
|
||||
= search_field_tag :search, params[:search], { placeholder: 'Filter by commit message', id: 'commits-search', class: 'form-control search-text-input', spellcheck: false }
|
||||
|
||||
- if current_user && current_user.private_token
|
||||
= link_to namespace_project_commits_path(@project.namespace, @project, @ref, {format: :atom, private_token: current_user.private_token}), title: "Commits Feed", class: 'prepend-left-10 btn' do
|
||||
= icon("rss")
|
||||
.control
|
||||
= link_to namespace_project_commits_path(@project.namespace, @project, @ref, {format: :atom, private_token: current_user.private_token}), title: "Commits Feed", class: 'btn' do
|
||||
= icon("rss")
|
||||
|
||||
|
||||
%ul.breadcrumb.repo-breadcrumb
|
||||
= commits_breadcrumbs
|
||||
|
||||
%div{id: dom_id(@project)}
|
||||
#commits-list= render "commits", project: @project
|
||||
#commits-list.content_list= render "commits", project: @project
|
||||
.clear
|
||||
= spinner
|
||||
|
||||
- if @commits.count == @limit
|
||||
:javascript
|
||||
CommitsList.init("#{@ref}", #{@limit});
|
||||
|
||||
:javascript
|
||||
CommitsList.init("#{@ref}", #{@limit});
|
||||
|
|
|
@ -55,3 +55,8 @@ Feature: Project Commits
|
|||
Scenario: I browse a commit with an image
|
||||
Given I visit a commit with an image that changed
|
||||
Then The diff links to both the previous and current image
|
||||
|
||||
@javascript
|
||||
Scenario: I filter commits by message
|
||||
When I search "submodules" commits
|
||||
Then I should see only "submodules" commits
|
||||
|
|
|
@ -124,4 +124,13 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps
|
|||
expect(page).to have_content "build: pending"
|
||||
expect(page).to have_content "1 build"
|
||||
end
|
||||
|
||||
step 'I search "submodules" commits' do
|
||||
fill_in 'commits-search', with: 'submodules'
|
||||
end
|
||||
|
||||
step 'I should see only "submodules" commits' do
|
||||
expect(page).to have_content "More submodules"
|
||||
expect(page).not_to have_content "Change some files"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue