Skip to content

Commit

Permalink
Merge pull request opf#5438 from opf/feature/repository_browser_limit…
Browse files Browse the repository at this point in the history
…ation

allow truncating repo browser list - Setting.repository_truncate_at
  • Loading branch information
machisuji committed May 5, 2017
2 parents 59c00d7 + 1061abf commit a377463
Show file tree
Hide file tree
Showing 14 changed files with 137 additions and 25 deletions.
9 changes: 9 additions & 0 deletions app/assets/stylesheets/openproject/_scm.sass
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,12 @@ tr
&.filename
a
margin-left: $repository-entry-filename-margin-left

tr
&.entry
&.truncation-warning
td
div.notification-box
margin-left: $repository-entry-filename-margin-left
margin-top: 0
margin-bottom: 0
4 changes: 3 additions & 1 deletion app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ def show
@repository.update_required_storage
end

@entries = @repository.entries(@path, @rev)
@limit = Setting.repository_truncate_at
@entries = @repository.entries(@path, @rev, limit: @limit)
@changeset = @repository.find_changeset_by_name(@rev)

if request.xhr?
if @entries && @repository.valid?
render(partial: 'dir_list_content')
Expand Down
13 changes: 11 additions & 2 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,17 @@ def entry(path = nil, identifier = nil)
scm.entry(path, identifier)
end

def entries(path = nil, identifier = nil)
scm.entries(path, identifier)
def entries(path = nil, identifier = nil, limit: nil)
entries = scm.entries(path, identifier)

if limit && limit < entries.size
result = OpenProject::Scm::Adapters::Entries.new entries.take(limit)
result.truncated = entries.size - result.size

result
else
entries
end
end

def branches
Expand Down
1 change: 0 additions & 1 deletion app/seeders/random_data/work_package_seeder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def add_changeset(work_package)
user: user,
revision: work_package.id * 10 + changeset_count,
scmid: work_package.id * 10 + changeset_count,
user: user,
work_packages: [work_package],
committer: Faker::Name.name,
committed_on: Date.today,
Expand Down
12 changes: 12 additions & 0 deletions app/views/repositories/_dir_list_content.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See doc/COPYRIGHT.rdoc for more details.
++#%>
<% if @entries.truncated? %>
<tr class="<%= h params[:parent_id] %> entry file truncation-warning">
<td colspan="7" style="padding-left: <%= 18 * params[:depth].to_i %>px;">
<div class="notification-box -warning">
<div class="notification-box--content">
<%= I18n.t "repositories.truncated", limit: @limit, truncated: @entries.truncated %>
</div>
</div>
</td>
</tr>
<% end %>
<% @entries.each do |entry| %>
<% tr_id = Digest::MD5.hexdigest(entry.path)
depth = params[:depth].to_i %>
Expand Down
1 change: 1 addition & 0 deletions app/views/settings/_repositories.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ See doc/COPYRIGHT.rdoc for more details.
<div class="form--field-instructions"><%= l(:text_comma_separated) %></div>
</div>
<div class="form--field"><%= setting_text_field :repository_log_display_limit, size: 6 %></div>
<div class="form--field"><%= setting_text_field :repository_truncate_at, size: 6 %></div>
<div class="form--field"><%= setting_check_box :repository_authentication_caching_enabled %></div>
</section>
<%= render partial: 'repositories_checkout' %>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,7 @@ en:
managed_url: "Managed URL"
password: "Repository Password"
username: "Repository username"
truncated: "Sorry, we had to truncate this directory to %{limit} files. %{truncated} entries were omitted from the list."
named_repository: "%{vendor_name} repository"
update_settings_successful: "The settings have been sucessfully saved."
url: "URL to repository"
Expand Down Expand Up @@ -1902,6 +1903,7 @@ en:
setting_repository_checkout_base_url: "Checkout base URL"
setting_repository_checkout_text: "Checkout instruction text"
setting_repository_log_display_limit: "Maximum number of revisions displayed on file log"
setting_repository_truncate_at: "Maximum number of files displayed in the repository browser"
setting_rest_api_enabled: "Enable REST web service"
setting_self_registration: "Self-registration"
setting_sequential_project_identifiers: "Generate sequential project identifiers"
Expand Down
3 changes: 3 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ registration_footer:
repository_storage_cache_minutes:
default: 720
format: int
repository_truncate_at:
default: 500
format: int
repository_checkout_data:
serialized: true
default:
Expand Down
19 changes: 18 additions & 1 deletion lib/open_project/scm/adapters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,30 @@ module Scm
module Adapters
class Entries < Array
def sort_by_name
sort do |x, y|
sorted = sort do |x, y|
if x.kind == y.kind
x.name.to_s <=> y.name.to_s
else
x.kind <=> y.kind
end
end

entries = Entries.new sorted
entries.truncated = truncated

entries
end

def truncated=(truncated)
@truncated = truncated
end

def truncated
@truncated
end

def truncated?
@truncated
end
end

Expand Down
Binary file modified spec/fixtures/repositories/subversion_repository.tar.gz
Binary file not shown.
24 changes: 12 additions & 12 deletions spec/lib/open_project/scm/adapters/subversion_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,32 +187,32 @@
it 'builds the info object' do
info = adapter.info
expect(info.root_url).to eq(url)
expect(info.lastrev.identifier).to eq('13')
expect(info.lastrev.author).to eq('oliver')
expect(info.lastrev.time).to eq('2016-04-14T19:23:01.74469Z')
expect(info.lastrev.identifier).to eq('14')
expect(info.lastrev.author).to eq('mkahl')
expect(info.lastrev.time.getlocal("+01:00").strftime("%FT%T%:z")).to eq('2017-05-04T14:26:53+01:00')
end
end

describe '.entries' do
it 'reads all entries from the current revision' do
entries = adapter.entries
expect(entries.length).to eq(2)
expect(entries.length).to eq(10)

expect(entries[0].name).to eq('Föbar')
expect(entries[0].path).to eq('Föbar')
expect(entries[1].name).to eq('subversion_test')
expect(entries[1].path).to eq('subversion_test')
expect(entries[1].name).to eq('folder_a')
expect(entries[1].path).to eq('folder_a')
end

it 'contains a reference to the last revision' do
entries = adapter.entries
expect(entries.length).to eq(2)
expect(entries.length).to eq(10)
lastrev = entries[0].lastrev

expect(lastrev.identifier).to eq('13')
expect(lastrev.author).to eq('oliver')
expect(lastrev.message).to eq('')
expect(lastrev.time).to eq('2016-04-14T19:23:01.74469Z')
expect(lastrev.time.getlocal("+01:00").strftime("%FT%T%:z")).to eq('2016-04-14T20:23:01+01:00')
end

it 'reads all entries from the given revision' do
Expand Down Expand Up @@ -284,13 +284,13 @@
describe '.revisions' do
it 'returns all revisions by default' do
revisions = adapter.revisions
expect(revisions.length).to eq(13)
expect(revisions.length).to eq(14)

expect(revisions[0].author).to eq('oliver')
expect(revisions[0].message).to eq("UTF-8 Test")
expect(revisions[0].author).to eq('mkahl')
expect(revisions[0].message.strip).to eq("added some more files to work with")

revisions.each_with_index do |rev, i|
expect(rev.identifier).to eq((13 - i).to_s)
expect(rev.identifier).to eq((14 - i).to_s)
end
end

Expand Down
29 changes: 29 additions & 0 deletions spec/models/repository/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,35 @@
expect(instance.scm).to be_available
end

describe "#entries" do
let(:entries) { instance.entries }

it "lists 10 entries" do
expect(entries.size).to eq 10
end

describe "with limit: 5" do
let(:directories) { entries.select { |e| e.kind == "dir" } }
let(:files) { entries.select { |e| e.kind == "file" } }

let(:limited_entries) { instance.entries limit: 5 }

before do
expect(directories.size).to eq 3
end

it "lists 5 entries only, directories first" do
expected_entries = (directories + files.take(2)).map(&:path)

expect(limited_entries.map(&:path)).to eq expected_entries
end

it "indicates 5 omitted entries" do
expect(limited_entries.truncated).to eq 5
end
end
end

it 'should fetch changesets from scratch' do
expect(instance.changesets.count).to eq(22)
expect(instance.file_changes.count).to eq(34)
Expand Down
37 changes: 33 additions & 4 deletions spec/models/repository/subversion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@
instance.fetch_changesets
instance.reload

expect(instance.changesets.count).to eq(13)
expect(instance.file_changes.count).to eq(25)
expect(instance.changesets.count).to eq(14)
expect(instance.file_changes.count).to eq(34)
expect(instance.changesets.find_by(revision: '1').comments).to eq('Initial import.')
end

Expand All @@ -181,7 +181,7 @@
expect(instance.changesets.count).to eq(5)

instance.fetch_changesets
expect(instance.changesets.count).to eq(13)
expect(instance.changesets.count).to eq(14)
end

it 'should latest changesets' do
Expand Down Expand Up @@ -296,7 +296,7 @@
changeset = instance.find_changeset_by_name('1')
expect(changeset.previous).to be_nil

changeset = instance.find_changeset_by_name('13')
changeset = instance.find_changeset_by_name('14')
expect(changeset.next).to be_nil
end

Expand Down Expand Up @@ -327,6 +327,35 @@ def find_events(user, options = {})
end
end

describe "#entries" do
let(:entries) { instance.entries }

it "lists 10 entries" do
expect(entries.size).to eq 10
end

describe "with limit: 5" do
let(:directories) { entries.select { |e| e.kind == "dir" } }
let(:files) { entries.select { |e| e.kind == "file" } }

let(:limited_entries) { instance.entries limit: 5 }

before do
expect(directories.size).to eq 3
end

it "lists 5 entries only, directories first" do
expected_entries = (directories + files.take(2)).map(&:path)

expect(limited_entries.map(&:path)).to eq expected_entries
end

it "indicates 5 omitted entries" do
expect(limited_entries.truncated).to eq 5
end
end
end

it_behaves_like 'is a countable repository' do
let(:repository) { instance }
end
Expand Down
8 changes: 4 additions & 4 deletions spec_legacy/unit/repository_subversion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
@repository.fetch_changesets
@repository.reload

assert_equal 13, @repository.changesets.count
assert_equal 25, @repository.file_changes.count
assert_equal 14, @repository.changesets.count
assert_equal 34, @repository.file_changes.count
assert_equal 'Initial import.', @repository.changesets.find_by(revision: '1').comments
end

Expand All @@ -58,7 +58,7 @@
assert_equal 5, @repository.changesets.count

@repository.fetch_changesets
assert_equal 13, @repository.changesets.count
assert_equal 14, @repository.changesets.count
end

it 'should latest changesets' do
Expand Down Expand Up @@ -198,7 +198,7 @@
it 'should next nil' do
@repository.fetch_changesets
@repository.reload
changeset = @repository.find_changeset_by_name('13')
changeset = @repository.find_changeset_by_name('14')
assert_nil changeset.next
end

Expand Down

0 comments on commit a377463

Please sign in to comment.