Merge pull request #45 from CactusPuppy/177261601-embed-happening-now-events-in-conference-splashpage

Embed happening now events in conference splashpage
This commit is contained in:
kingdish 2021-04-12 13:38:29 +08:00 committed by GitHub
commit 41a0193ad3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 291 additions and 34 deletions

View file

@ -221,6 +221,9 @@ gem 'dalli'
gem 'icalendar'
# pagination
gem 'pagy', '<4.0'
# Use guard and spring for testing in development
group :development do
# to launch specs when files are modified

View file

@ -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)
@ -734,6 +735,7 @@ DEPENDENCIES
omniauth-github
omniauth-google-oauth2
omniauth-openid
pagy (< 4.0)
paper_trail
pdf-inspector
pg

View file

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

View file

@ -50,7 +50,7 @@ module Admin
:include_venue, :include_registrations,
:include_tickets, :include_lodgings,
:include_sponsors, :include_social_media,
:include_booths)
:include_booths, :include_happening_now)
end
end
end

View file

@ -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

View file

@ -1,6 +1,10 @@
# frozen_string_literal: true
EVENTS_PER_PAGE = 3
class ConferencesController < ApplicationController
include ConferenceHelper
protect_from_forgery with: :null_session
before_action :respond_to_options
load_and_authorize_resource find_by: :short_title, except: :show
@ -56,6 +60,13 @@ class ConferencesController < ApplicationController
if splashpage.include_booths
@booths = @conference.confirmed_booths.order('title')
end
if splashpage.include_happening_now
events_schedules_list = get_happening_now_events_schedules(@conference)
@events_schedules_limit = EVENTS_PER_PAGE
@events_schedules_length = events_schedules_list.length
@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)
end
end
if splashpage.include_registrations || splashpage.include_tickets
@tickets = @conference.tickets.visible.order('price_cents')

View file

@ -1,6 +1,8 @@
# frozen_string_literal: true
class SchedulesController < ApplicationController
include ConferenceHelper
load_and_authorize_resource
before_action :respond_to_options
load_resource :conference, find_by: :short_title
@ -67,15 +69,12 @@ class SchedulesController < ApplicationController
end
def happening_now
@events_schedules = @program.selected_event_schedules(
includes: [:room, { event: %i[track event_type speakers submitter] }]
).select(&:happening_now?)
@events_schedules = [] unless @events_schedules
@events_schedules = get_happening_now_events_schedules(@conference)
@current_time = Time.now.in_time_zone(@conference.timezone)
respond_to do |format|
format.html
format.json { render json: @events_schedules.as_json(root: false, include: :event) }
format.json { render json: @events_schedules.to_json(root: false, include: :event) }
end
end

View file

@ -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

View file

@ -77,4 +77,12 @@ module ConferenceHelper
end
calendar
end
def get_happening_now_events_schedules(conference)
events_schedules = conference.program.selected_event_schedules(
includes: [:room, { event: %i[track event_type speakers submitter] }]
).select(&:happening_now?)
events_schedules ||= []
events_schedules
end
end

View file

@ -11,6 +11,7 @@
# banner_photo_updated_at :datetime
# include_booths :boolean
# include_cfp :boolean default(FALSE)
# include_happening_now :boolean
# include_lodgings :boolean
# include_program :boolean
# include_registrations :boolean

View file

@ -25,6 +25,8 @@
= f.input :include_tracks, label: 'Include confirmed tracks', input_html: { checked: params[:action] == 'new' || @splashpage.try(:include_tracks) }
%li
= f.input :include_booths, label: "Include confirmed #{(t'booth').pluralize}", input_html: { checked: params[:action] == 'new' || @splashpage.try(:include_booths) }
%li
= f.input :include_happening_now, label: 'Include events happening now', input_html: { checked: params[:action] == 'new' || @splashpage.try(:include_happening_now) }
%li
= f.input :include_registrations, label: 'Display the registration period', input_html: { checked: params[:action] == 'new' || @splashpage.try(:include_registrations) }

View file

@ -27,6 +27,9 @@
%li
%i{ class: "fa-li #{icon_for_todo @splashpage.include_booths?}" }
Include confirmed #{(t'booth').pluralize}
%li
%i{ class: "fa-li #{icon_for_todo @splashpage.include_happening_now?}" }
Include events happening now
%li
%i{ class: "fa-li #{icon_for_todo @splashpage.include_registrations?}" }
Display the registration period

View file

@ -0,0 +1,32 @@
= content_for :happening_now do
#happening-now
= render 'happening_now', conference: conference,
events_schedules: events_schedules, pagy: pagy,
events_schedules_length: events_schedules_length,
events_schedules_limit: events_schedules_limit
= content_for :about do
#about
.row
%h2.text-left{ style: 'margin-bottom:30px' } About the Conference
= markdown(conference.description, false)
%section#about-and-happening-now
.container
.row
-# happening now events are displayed second in md or lg view
- if conference.splashpage.include_happening_now && conference.splashpage.include_program
- if conference.description.present?
.col-md-6.col-md-push-6.col-lg-4.col-lg-push-8
= yield :happening_now
- else
.col-md-12
= yield :happening_now
- if conference.description.present?
- if conference.splashpage.include_happening_now && conference.splashpage.include_program
.col-md-6.col-md-pull-6.col-lg-8.col-lg-pull-4
= yield :about
- else
.col-md-12
= yield :about
.trapezoid

View file

@ -0,0 +1,12 @@
- if conference.splashpage.include_program && 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, is_brief: true
- 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

@ -26,11 +26,3 @@
- if venue.country != 'US'
&bull;
= venue.country_name
- unless conference.description.blank?
%section#about
.container
.row
.col-md-8.col-md-offset-2
= markdown(conference.description, escape_html=false)
.trapezoid

View file

@ -41,9 +41,16 @@
- if @conference.code_of_conduct.present?
= render 'code_of_conduct', organization: @conference.organization
-# header/description
-# header
= render 'header', conference: @conference, venue: @conference.venue
-# description / happening now
- if @conference.splashpage.include_happening_now? || @conference.description.present?
= render 'about_and_happening_now', conference: @conference,
events_schedules: @events_schedules, pagy: @pagy,
events_schedules_length: @events_schedules_length,
events_schedules_limit: @events_schedules_limit
-# calls for content, or program
- if @conference.splashpage.include_cfp
= render 'call_for_content', conference: @conference,

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

@ -2,8 +2,9 @@
- header_color = event.event_type&.color || '#f5f5f5'
.trapezoid{ style: 'color: white; top: 12px; z-index: 100;' }
.panel-heading{ style: "background-color: #{header_color}; color: #{ contrast_color(header_color) }; border-radius: 4px" }
- event.speakers_ordered.each do |speaker|
= image_tag speaker.profile_picture, class: 'img-circle pull-right', alt: speaker.name, style: 'padding: 2px;'
- if !defined?(is_brief) || is_brief == false
- event.speakers_ordered.each do |speaker|
= image_tag speaker.profile_picture, class: 'img-circle pull-right', alt: speaker.name, style: 'padding: 2px;'
%p
= canceled_replacement_event_label(event, event_schedule)
@ -14,7 +15,8 @@
%br
%small{ style: "color: #{contrast_color(header_color)}" }
= event.subtitle
.trapezoid{ style: "color: #{header_color}; top: 12px;" }
.trapezoid{ style: "color: #{header_color}; border-top-color: #{header_color}; top: 12px;" }
.panel-body
%h4
@ -26,20 +28,21 @@
= markdown(truncate(event.abstract, length: 400))
-# TODO: More informative text or aria-label.
= link_to 'more', conference_program_proposal_path(@conference.short_title, event.id) if event.abstract.length > 400
- if event_schedule.present?
= inyourtz(event_schedule.start_time) do
- if !defined?(is_brief) || is_brief == false
- if event_schedule.present?
= inyourtz(event_schedule.start_time) do
%span.track
%span.fa.fa-clock-o
%span.label{ style: 'background-color: grey' }
= event_schedule.start_time.strftime('%l:%M %P')
\-
= event_schedule.end_time.strftime('%l:%M %P')
%span.track
%span.fa.fa-clock-o
%span.fa.fa-map-marker
%span.label{ style: 'background-color: grey' }
= event_schedule.start_time.strftime('%l:%M %P')
\-
= event_schedule.end_time.strftime('%l:%M %P')
%span.track
%span.fa.fa-map-marker
%span.label{ style: 'background-color: grey' }
= event_schedule.room.name
- if event.track
%span.track
%span.fa.fa-road
%span.label{ style: "background-color: #{event.track.color}; color: #{ contrast_color(event.track.color) }" }
= event.track.name
= event_schedule.room.name
- if event.track
%span.track
%span.fa.fa-road
%span.label{ style: "background-color: #{event.track.color}; color: #{ contrast_color(event.track.color) }" }
= event.track.name

164
config/initializers/pagy.rb Normal file
View file

@ -0,0 +1,164 @@
# 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

View file

@ -0,0 +1,5 @@
class AddIncludeHappeningNowToSplashpages < ActiveRecord::Migration[5.2]
def change
add_column :splashpages, :include_happening_now, :boolean
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_03_06_185903) do
ActiveRecord::Schema.define(version: 2021_04_01_050437) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -442,6 +442,7 @@ ActiveRecord::Schema.define(version: 2021_03_06_185903) do
t.boolean "include_cfp", default: false
t.boolean "include_booths"
t.boolean "shuffle_highlights", default: false, null: false
t.boolean "include_happening_now"
end
create_table "sponsors", force: :cascade do |t|

View file

@ -11,6 +11,7 @@
# banner_photo_updated_at :datetime
# include_booths :boolean
# include_cfp :boolean default(FALSE)
# include_happening_now :boolean
# include_lodgings :boolean
# include_program :boolean
# include_registrations :boolean
@ -44,6 +45,7 @@ FactoryBot.define do
include_sponsors { true }
include_lodgings { true }
include_cfp { true }
include_happening_now { true }
end
end
end