From 847357dae758245306f141df55d832a151f7fe16 Mon Sep 17 00:00:00 2001 From: madhekare Date: Wed, 7 Apr 2021 20:56:03 -0700 Subject: [PATCH] pagination happening now --- Gemfile | 3 + Gemfile.lock | 2 + app/controllers/application_controller.rb | 1 + app/controllers/conferences_controller.rb | 3 +- app/helpers/application_helper.rb | 1 + app/helpers/conference_helper.rb | 1 + app/views/conferences/show.html.haml | 3 + config/initializers/pagy.rb | 175 ++++++++++++++++++++++ 8 files changed, 188 insertions(+), 1 deletion(-) create mode 100644 config/initializers/pagy.rb diff --git a/Gemfile b/Gemfile index 4391debb..d2a721ef 100644 --- a/Gemfile +++ b/Gemfile @@ -224,6 +224,9 @@ gem 'icalendar' # for making external requests easier gem 'httparty' +#pagination +gem 'pagy', '<4.0' + # Use guard and spring for testing in development group :development do # to launch specs when files are modified diff --git a/Gemfile.lock b/Gemfile.lock index f1b8f1cf..8e27a41a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -364,6 +364,7 @@ GEM rack-openid (~> 1.3.1) open4 (1.3.4) orm_adapter (0.5.0) + pagy (3.12.0) paper_trail (10.3.1) activerecord (>= 4.2) request_store (~> 1.1) @@ -735,6 +736,7 @@ DEPENDENCIES omniauth-github omniauth-google-oauth2 omniauth-openid + pagy (< 4.0) paper_trail pdf-inspector pg diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c9f93a30..b2e925e7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,6 +3,7 @@ class ApplicationController < ActionController::Base before_action :set_paper_trail_whodunnit include ApplicationHelper + include Pagy::Backend add_flash_types :error protect_from_forgery with: :exception, prepend: true before_action :store_location diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index 1827ad95..987d0cab 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -72,7 +72,8 @@ class ConferencesController < ApplicationController @sponsors = @conference.sponsors end if splashpage.include_happening_now - @events_schedules = get_happening_now_events_schedules(@conference) + @event_list = get_happening_now_events_schedules(@conference) + @pagy, @events_schedules = pagy_array(@event_list, items: 2) @happening_now_url = happening_now_conference_schedule_path(conference_id: @conference.short_title, format: :json) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1c7f5da6..7578e99c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true module ApplicationHelper + include Pagy::Frontend # Returns a string build from the start and end date of the given conference. # # If the conference is only one day long diff --git a/app/helpers/conference_helper.rb b/app/helpers/conference_helper.rb index c392a814..ad9971a3 100644 --- a/app/helpers/conference_helper.rb +++ b/app/helpers/conference_helper.rb @@ -3,6 +3,7 @@ DEFAULT_LOGO = 'snapcon_logo.png' DEFAULT_COLOR = '#0B3559' + module ConferenceHelper # Return true if only call_for_papers or call_for_tracks or call_for_booths is open def one_call_open(*calls) diff --git a/app/views/conferences/show.html.haml b/app/views/conferences/show.html.haml index 140a4e57..0112f121 100644 --- a/app/views/conferences/show.html.haml +++ b/app/views/conferences/show.html.haml @@ -57,6 +57,8 @@ %h2.text-center Happening Now - for event_schedule in @events_schedules = render 'schedules/event', conference: @conference, event_schedule: event_schedule, event: event_schedule.event + .container{:style => "margin:auto; width:50%"} + != pagy_nav(@pagy) - else .row %h3.text-center There are no events happening now. @@ -67,6 +69,7 @@ = markdown(@conference.description, escape_html=false) .trapezoid + -# calls for content, or program - if @conference.splashpage.include_cfp = render 'call_for_content', conference: @conference, diff --git a/config/initializers/pagy.rb b/config/initializers/pagy.rb new file mode 100644 index 00000000..6f5e8550 --- /dev/null +++ b/config/initializers/pagy.rb @@ -0,0 +1,175 @@ +# encoding: utf-8 +# frozen_string_literal: true + +# Pagy initializer file (4.1.0) +# Customize only what you really need and notice that Pagy works also without any of the following lines. +# Should you just cherry pick part of this file, please maintain the require-order of the extras + + +# Extras +# See https://ddnexus.github.io/pagy/extras + + +# Backend Extras + +# Array extra: Paginate arrays efficiently, avoiding expensive array-wrapping and without overriding +# See https://ddnexus.github.io/pagy/extras/array +require 'pagy/extras/array' + +# Countless extra: Paginate without any count, saving one query per rendering +# See https://ddnexus.github.io/pagy/extras/countless +# require 'pagy/extras/countless' +# Pagy::VARS[:cycle] = false # default + +# Elasticsearch Rails extra: Paginate `ElasticsearchRails::Results` objects +# See https://ddnexus.github.io/pagy/extras/elasticsearch_rails +# default :pagy_search method: change only if you use +# also the searchkick extra that defines the same +# VARS[:elasticsearch_rails_search_method] = :pagy_search +# require 'pagy/extras/elasticsearch_rails' + +# Searchkick extra: Paginate `Searchkick::Results` objects +# See https://ddnexus.github.io/pagy/extras/searchkick +# default :pagy_search method: change only if you use +# also the elasticsearch_rails extra that defines the same +# VARS[:searchkick_search_method] = :pagy_search +# require 'pagy/extras/searchkick' + +# Frontend Extras + +# Bootstrap extra: Add nav, nav_js and combo_nav_js helpers and templates for Bootstrap pagination +# See https://ddnexus.github.io/pagy/extras/bootstrap +# require 'pagy/extras/bootstrap' + +# Bulma extra: Add nav, nav_js and combo_nav_js helpers and templates for Bulma pagination +# See https://ddnexus.github.io/pagy/extras/bulma +# require 'pagy/extras/bulma' + +# Foundation extra: Add nav, nav_js and combo_nav_js helpers and templates for Foundation pagination +# See https://ddnexus.github.io/pagy/extras/foundation +# require 'pagy/extras/foundation' + +# Materialize extra: Add nav, nav_js and combo_nav_js helpers for Materialize pagination +# See https://ddnexus.github.io/pagy/extras/materialize +# require 'pagy/extras/materialize' + +# Navs extra: Add nav_js and combo_nav_js javascript helpers +# Notice: the other frontend extras add their own framework-styled versions, +# so require this extra only if you need the unstyled version +# See https://ddnexus.github.io/pagy/extras/navs +# require 'pagy/extras/navs' + +# Semantic extra: Add nav, nav_js and combo_nav_js helpers for Semantic UI pagination +# See https://ddnexus.github.io/pagy/extras/semantic +# require 'pagy/extras/semantic' + +# UIkit extra: Add nav helper and templates for UIkit pagination +# See https://ddnexus.github.io/pagy/extras/uikit +# require 'pagy/extras/uikit' + +# Multi size var used by the *_nav_js helpers +# See https://ddnexus.github.io/pagy/extras/navs#steps +# Pagy::VARS[:steps] = { 0 => [2,3,3,2], 540 => [3,5,5,3], 720 => [5,7,7,5] } # example + + +# Feature Extras + +# Headers extra: http response headers (and other helpers) useful for API pagination +# See http://ddnexus.github.io/pagy/extras/headers +# require 'pagy/extras/headers' +# Pagy::VARS[:headers] = { page: 'Current-Page', items: 'Page-Items', count: 'Total-Count', pages: 'Total-Pages' } # default + +# Support extra: Extra support for features like: incremental, infinite, auto-scroll pagination +# See https://ddnexus.github.io/pagy/extras/support +# require 'pagy/extras/support' + +# Items extra: Allow the client to request a custom number of items per page with an optional selector UI +# See https://ddnexus.github.io/pagy/extras/items +# require 'pagy/extras/items' +# Pagy::VARS[:items_param] = :items # default +# Pagy::VARS[:max_items] = 100 # default + +# Overflow extra: Allow for easy handling of overflowing pages +# See https://ddnexus.github.io/pagy/extras/overflow +# require 'pagy/extras/overflow' +# Pagy::VARS[:overflow] = :empty_page # default (other options: :last_page and :exception) + +# Metadata extra: Provides the pagination metadata to Javascript frameworks like Vue.js, react.js, etc. +# See https://ddnexus.github.io/pagy/extras/metadata +# you must require the shared internal extra (BEFORE the metadata extra) ONLY if you need also the :sequels +# require 'pagy/extras/shared' +# require 'pagy/extras/metadata' +# For performance reason, you should explicitly set ONLY the metadata you use in the frontend +# Pagy::VARS[:metadata] = [:scaffold_url, :count, :page, :prev, :next, :last] # example + +# Trim extra: Remove the page=1 param from links +# See https://ddnexus.github.io/pagy/extras/trim +# require 'pagy/extras/trim' + + + +# Pagy Variables +# See https://ddnexus.github.io/pagy/api/pagy#variables +# All the Pagy::VARS are set for all the Pagy instances but can be overridden +# per instance by just passing them to Pagy.new or the #pagy controller method + + +# Instance variables +# See https://ddnexus.github.io/pagy/api/pagy#instance-variables +# Pagy::VARS[:items] = 20 # default + + +# Other Variables +# See https://ddnexus.github.io/pagy/api/pagy#other-variables +# Pagy::VARS[:size] = [1,4,4,1] # default +# Pagy::VARS[:page_param] = :page # default +# Pagy::VARS[:params] = {} # default +# Pagy::VARS[:anchor] = '#anchor' # example +# Pagy::VARS[:link_extra] = 'data-remote="true"' # example + + +# Rails + +# Rails: extras assets path required by the helpers that use javascript +# (pagy*_nav_js, pagy*_combo_nav_js, and pagy_items_selector_js) +# See https://ddnexus.github.io/pagy/extras#javascript +# Rails.application.config.assets.paths << Pagy.root.join('javascripts') + + +# I18n + +# Pagy internal I18n: ~18x faster using ~10x less memory than the i18n gem +# See https://ddnexus.github.io/pagy/api/frontend#i18n +# Notice: No need to configure anything in this section if your app uses only "en" +# or if you use the i18n extra below +# +# Examples: +# load the "de" built-in locale: +# Pagy::I18n.load(locale: 'de') +# +# load the "de" locale defined in the custom file at :filepath: +# Pagy::I18n.load(locale: 'de', filepath: 'path/to/pagy-de.yml') +# +# load the "de", "en" and "es" built-in locales: +# (the first passed :locale will be used also as the default_locale) +# Pagy::I18n.load({locale: 'de'}, +# {locale: 'en'}, +# {locale: 'es'}) +# +# load the "en" built-in locale, a custom "es" locale, +# and a totally custom locale complete with a custom :pluralize proc: +# (the first passed :locale will be used also as the default_locale) +# Pagy::I18n.load({locale: 'en'}, +# {locale: 'es', filepath: 'path/to/pagy-es.yml'}, +# {locale: 'xyz', # not built-in +# filepath: 'path/to/pagy-xyz.yml', +# pluralize: lambda{|count| ... } ) + + +# I18n extra: uses the standard i18n gem which is ~18x slower using ~10x more memory +# than the default pagy internal i18n (see above) +# See https://ddnexus.github.io/pagy/extras/i18n +# require 'pagy/extras/i18n' + +# Default i18n key +# Pagy::VARS[:i18n_key] = 'pagy.item_name' # default \ No newline at end of file