Paginate Alt Styles, sort by most recent first-seen date

This commit is contained in:
Emi Matchu 2024-09-30 17:35:18 -07:00
parent 2a9818b2d1
commit dd8426fefd
6 changed files with 20 additions and 13 deletions

View file

@ -51,3 +51,9 @@
margin: 0 auto
position: relative
z-index: 1
.rainbow-pool-pagination
margin-block: .5em
display: flex
justify-content: center
gap: 1em

View file

@ -1,3 +0,0 @@
[role=navigation]
margin-block: .5em
text-align: center

View file

@ -2,8 +2,7 @@ class AltStylesController < ApplicationController
before_action :support_staff_only, except: [:index]
def index
@all_alt_styles = AltStyle.includes(:species, :color).
order(:species_id, :color_id)
@all_alt_styles = AltStyle.includes(:species, :color)
@all_colors = @all_alt_styles.map(&:color).uniq.sort_by(&:name)
@all_species = @all_alt_styles.map(&:species).uniq.sort_by(&:name)
@ -16,7 +15,9 @@ class AltStylesController < ApplicationController
@color = find_color
@species = find_species
@alt_styles = @all_alt_styles.includes(:swf_assets)
@alt_styles = @all_alt_styles.includes(:swf_assets).
by_creation_date.order(:color_id, :species_id, :series_name).
paginate(page: params[:page], per_page: 30)
@alt_styles.where!(series_name: @series_name) if @series_name.present?
@alt_styles.merge!(@color.alt_styles) if @color
@alt_styles.merge!(@species.alt_styles) if @species

View file

@ -20,6 +20,9 @@ class AltStyle < ApplicationRecord
species = Species.find_by_name!(species_name)
where(series_name:, color_id: color.id, species_id: species.id)
}
scope :by_creation_date, -> {
order("DATE(created_at) DESC")
}
def name
I18n.translate('pet_types.human_name', color_human_name: color.human_name,

View file

@ -26,10 +26,11 @@
selected: @species&.human_name, include_blank: "Species…"
= f.submit "Go"
- @alt_styles.group_by(&:species).each do |species, species_styles|
%h2.alt-styles-header= species.human_name
%ul.rainbow-pool-list
= render partial: "alt_style", collection: species_styles
= will_paginate @alt_styles, class: "rainbow-pool-pagination"
%ul.rainbow-pool-list= render @alt_styles
= will_paginate @alt_styles, class: "rainbow-pool-pagination"
- content_for :stylesheets do
= stylesheet_link_tag "application/rainbow-pool"

View file

@ -8,12 +8,11 @@
= form.select :species, @species_names, selected: @selected_species&.human_name, include_blank: "Species…"
= form.submit "Go"
= will_paginate @pet_types
= will_paginate @pet_types, class: "rainbow-pool-pagination"
%ui.rainbow-pool-list= render @pet_types
= will_paginate @pet_types
= will_paginate @pet_types, class: "rainbow-pool-pagination"
- content_for :stylesheets do
= stylesheet_link_tag "application/rainbow-pool"
= page_stylesheet_link_tag "pet_types/index"