Update browse page to new layout and add sorting
parent
249117f80a
commit
100273f5bf
@ -0,0 +1,23 @@
|
||||
class AsciicastListDecorator < ApplicationDecorator
|
||||
|
||||
PER_PAGE = 12
|
||||
|
||||
attr_reader :page, :per_page
|
||||
|
||||
delegate_all
|
||||
|
||||
def initialize(model, page, per_page = nil)
|
||||
super(model)
|
||||
@page = page
|
||||
@per_page = per_page || PER_PAGE
|
||||
end
|
||||
|
||||
def category_name
|
||||
"#{category.to_s.capitalize} asciicasts"
|
||||
end
|
||||
|
||||
def items
|
||||
PaginatingDecorator.new(model.items.paginate(page, per_page))
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,15 @@
|
||||
class AsciicastList
|
||||
|
||||
attr_reader :category, :order, :repository
|
||||
|
||||
def initialize(category, order, repository = Asciicast)
|
||||
@category = (category || :all).to_sym
|
||||
@order = (order || :recency).to_sym
|
||||
@repository = repository
|
||||
end
|
||||
|
||||
def items
|
||||
repository.for_category_ordered(category, order)
|
||||
end
|
||||
|
||||
end
|
@ -1,9 +1,30 @@
|
||||
section.supplimental
|
||||
.wrapper
|
||||
.main
|
||||
h1 = @category_name
|
||||
= render :partial => 'asciicasts/previews', :locals => { :asciicasts => @asciicasts }
|
||||
= paginate @asciicasts
|
||||
.asciicasts-list-page
|
||||
.container
|
||||
.row
|
||||
.col-md-3
|
||||
= render 'shared/browse_categories', current_category: asciicast_list.category
|
||||
|
||||
.extras
|
||||
= render :partial => 'shared/browse_categories'
|
||||
.col-md-9
|
||||
.row
|
||||
.col-md-6
|
||||
h2 = asciicast_list.category_name
|
||||
|
||||
.col-md-6.text-right
|
||||
.sorting
|
||||
span Sort by
|
||||
.btn-group.text-left
|
||||
button.btn.btn-default.dropdown-toggle[type="button" data-toggle="dropdown"]
|
||||
| #{asciicast_list.order}
|
||||
span.caret
|
||||
ul.dropdown-menu[role="menu"]
|
||||
li
|
||||
a href="?order=recency"
|
||||
| recency
|
||||
li
|
||||
a href="?order=popularity"
|
||||
| popularity
|
||||
|
||||
.row.asciicast-list
|
||||
.col-md-12
|
||||
= render 'asciicasts/previews', asciicasts: asciicast_list.items, per_row: 2
|
||||
= paginate asciicast_list.items
|
||||
|
@ -0,0 +1,3 @@
|
||||
<li>
|
||||
<%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, :remote => remote %>
|
||||
</li>
|
@ -0,0 +1,3 @@
|
||||
<li class="disabled">
|
||||
<%= link_to raw(t 'views.pagination.truncate'), '#' %>
|
||||
</li>
|
@ -0,0 +1,3 @@
|
||||
<li>
|
||||
<%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, {:remote => remote} %>
|
||||
</li>
|
@ -0,0 +1,3 @@
|
||||
<li>
|
||||
<%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, :rel => 'next', :remote => remote %>
|
||||
</li>
|
@ -0,0 +1,3 @@
|
||||
<li class="<%= 'active' if page.current? %>">
|
||||
<%= link_to page, page.current? ? '#' : url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
|
||||
</li>
|
@ -0,0 +1,15 @@
|
||||
<%= paginator.render do -%>
|
||||
<ul class="pagination">
|
||||
<%= first_page_tag unless current_page.first? %>
|
||||
<%= prev_page_tag unless current_page.first? %>
|
||||
<% each_page do |page| -%>
|
||||
<% if page.left_outer? || page.right_outer? || page.inside_window? -%>
|
||||
<%= page_tag page %>
|
||||
<% elsif !page.was_truncated? -%>
|
||||
<%= gap_tag %>
|
||||
<% end -%>
|
||||
<% end -%>
|
||||
<%= next_page_tag unless current_page.last? %>
|
||||
<%= last_page_tag unless current_page.last? %>
|
||||
</ul>
|
||||
<% end -%>
|
@ -0,0 +1,3 @@
|
||||
<li>
|
||||
<%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, :rel => 'prev', :remote => remote %>
|
||||
</li>
|
@ -1,17 +0,0 @@
|
||||
<h1>Browse</h1>
|
||||
|
||||
<ul class="delimited">
|
||||
<li>
|
||||
<%= link_to_category 'All', browse_path, :all %>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<%= link_to_category 'Popular', popular_path, :popular %>
|
||||
</li>
|
||||
|
||||
<% if current_user -%>
|
||||
<li>
|
||||
<%= link_to 'Mine', profile_path(current_user) %>
|
||||
</li>
|
||||
<% end -%>
|
||||
</ul>
|
@ -0,0 +1,5 @@
|
||||
h2 Browse
|
||||
|
||||
= category_links current_category do |categories|
|
||||
= categories.link_to 'All', browse_path, :all
|
||||
= categories.link_to 'Featured', category_path(:featured), :featured
|
@ -0,0 +1,34 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe AsciicastListDecorator do
|
||||
|
||||
let(:decorator) { described_class.new(list, 3, 10) }
|
||||
let(:list) { double('list', category: :foo, items: items) }
|
||||
let(:items) { double('items', paginate: paginated) }
|
||||
let(:paginated) { [Asciicast.new] }
|
||||
|
||||
describe '#category_name' do
|
||||
subject { decorator.category_name }
|
||||
|
||||
it { should eq('Foo asciicasts') }
|
||||
end
|
||||
|
||||
describe '#items' do
|
||||
subject { decorator.items }
|
||||
|
||||
it 'returns the items paginated' do
|
||||
expect(subject).to eq(paginated)
|
||||
expect(items).to have_received(:paginate).with(3, 10)
|
||||
end
|
||||
|
||||
it 'wraps the paginated items in a PaginatingDecorator' do
|
||||
paginating_decorator = double('paginating_decorator')
|
||||
|
||||
allow(PaginatingDecorator).to receive(:new).
|
||||
with(paginated) { paginating_decorator }
|
||||
|
||||
expect(subject).to be(paginating_decorator)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -0,0 +1,63 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe AsciicastList do
|
||||
|
||||
let(:list) { described_class.new(category, order, repository) }
|
||||
|
||||
let(:category) { 'featured' }
|
||||
let(:order) { 'recency' }
|
||||
let(:repository) { double('repository') }
|
||||
|
||||
describe '#category' do
|
||||
subject { list.category }
|
||||
|
||||
context "when it was passed as a string" do
|
||||
let(:category) { 'thecat' }
|
||||
|
||||
it { should eq(:thecat) }
|
||||
end
|
||||
|
||||
context "when it was passed as nil" do
|
||||
let(:category) { nil }
|
||||
|
||||
it { should eq(:all) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#order' do
|
||||
subject { list.order }
|
||||
|
||||
context "when it was passed as a string" do
|
||||
let(:order) { 'thecat' }
|
||||
|
||||
it { should eq(:thecat) }
|
||||
end
|
||||
|
||||
context "when it was passed as nil" do
|
||||
let(:order) { nil }
|
||||
|
||||
it { should eq(:recency) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#items' do
|
||||
subject { list.items }
|
||||
|
||||
let(:category) { 'foo' }
|
||||
let(:order) { 'bar' }
|
||||
let(:asciicasts) { [Asciicast.new] }
|
||||
|
||||
before do
|
||||
allow(repository).to receive(:for_category_ordered) { asciicasts }
|
||||
subject
|
||||
end
|
||||
|
||||
it { should eq(asciicasts) }
|
||||
|
||||
it 'calls for_category_ordered on repository with proper args' do
|
||||
expect(repository).to have_received(:for_category_ordered).
|
||||
with(:foo, :bar)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue