[feat]Use Ajax for paginating happening_now

This commit is contained in:
Jimmy 2021-04-09 17:16:16 +08:00 committed by CactusPuppy
parent 46094306af
commit 0c73d24f05
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82
6 changed files with 26 additions and 14 deletions

View file

@ -54,6 +54,7 @@
//= require selectize //= require selectize
//= require bootstrap-select //= require bootstrap-select
//= require osem-survey //= require osem-survey
//= require pagy
$(document).ready(function() { $(document).ready(function() {
$('a[disabled=disabled]').click(function(event){ $('a[disabled=disabled]').click(function(event){
@ -63,4 +64,6 @@ $(document).ready(function() {
$('body').smoothScroll({ $('body').smoothScroll({
delegateSelector: 'a.smoothscroll' delegateSelector: 'a.smoothscroll'
}); });
window.addEventListener("load", Pagy.init);
}); });

View file

@ -77,7 +77,7 @@ class ConferencesController < ApplicationController
events_schedules_list = get_happening_now_events_schedules(@conference) events_schedules_list = get_happening_now_events_schedules(@conference)
@events_schedules_limit = EVENTS_PER_PAGE @events_schedules_limit = EVENTS_PER_PAGE
@events_schedules_length = events_schedules_list.length @events_schedules_length = events_schedules_list.length
@pagy, @events_schedules = pagy_array(events_schedules_list, items: @events_schedules_limit) @pagy, @events_schedules = pagy_array(events_schedules_list, items: @events_schedules_limit, link_extra: 'data-remote="true"')
@happening_now_url = happening_now_conference_schedule_path(conference_id: @conference.short_title, format: :json) @happening_now_url = happening_now_conference_schedule_path(conference_id: @conference.short_title, format: :json)
end end
end end

View file

@ -4,18 +4,10 @@
-# happening now events are displayed second in md or lg view -# happening now events are displayed second in md or lg view
.col-md-6.col-md-push-6.col-lg-4.col-lg-push-8 .col-md-6.col-md-push-6.col-lg-4.col-lg-push-8
#happening-now #happening-now
- if conference.splashpage.include_happening_now = render 'happening_now', conference: conference,
- if @events_schedules.any? events_schedules: events_schedules, pagy: pagy,
.row events_schedules_length: events_schedules_length,
%h2.text-center{ style: 'margin-bottom:30px' } Happening Now events_schedules_limit: events_schedules_limit
- events_schedules.each do |event_schedule|
= render 'schedules/event', conference: conference, event_schedule: event_schedule, event: event_schedule.event
- if events_schedules_length > events_schedules_limit
.container{ style: 'width:100%; text-align:center' }
!= pagy_bootstrap_nav(pagy)
- else
.row
%h3.text-center There are no events happening now.
- if conference.description.present? - if conference.description.present?
.col-md-6.col-md-pull-6.col-lg-8.col-lg-pull-4 .col-md-6.col-md-pull-6.col-lg-8.col-lg-pull-4
#about #about

View file

@ -0,0 +1,12 @@
- if conference.splashpage.include_happening_now
- if events_schedules.any?
.row
%h2.text-center{ style: 'margin-bottom:30px' } Happening Now
- events_schedules.each do |event_schedule|
= render 'schedules/event', conference: conference, event_schedule: event_schedule, event: event_schedule.event
- if events_schedules_length > events_schedules_limit
.container{ style: 'width:100%; text-align:center' }
!= pagy_bootstrap_nav_js(pagy)
- else
.row
%h3.text-center There are no events happening now.

View file

@ -0,0 +1,5 @@
$('#happening-now').html("<%= j(render 'happening_now', conference: @conference,
events_schedules: @events_schedules, pagy: @pagy,
events_schedules_length: @events_schedules_length,
events_schedules_limit: @events_schedules_limit)%>");
Pagy.init(document.getElementById('happening-now'));

View file

@ -124,7 +124,7 @@ require 'pagy/extras/bootstrap'
# Rails: extras assets path required by the helpers that use javascript # Rails: extras assets path required by the helpers that use javascript
# (pagy*_nav_js, pagy*_combo_nav_js, and pagy_items_selector_js) # (pagy*_nav_js, pagy*_combo_nav_js, and pagy_items_selector_js)
# See https://ddnexus.github.io/pagy/extras#javascript # See https://ddnexus.github.io/pagy/extras#javascript
# Rails.application.config.assets.paths << Pagy.root.join('javascripts') Rails.application.config.assets.paths << Pagy.root.join('javascripts')
# I18n # I18n