-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from TelosLabs/98-add-live-starting-soon-and-p…
…ast-filter-for-sessions Add status filters for Sessions
- Loading branch information
Showing
25 changed files
with
343 additions
and
40 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
class SchedulesController < ApplicationController | ||
def show | ||
@sessions = current_user.sessions | ||
.where(conference: current_conference) | ||
.order(:starts_at) | ||
.includes(:attendees, :speakers, :location, :tags) | ||
@sessions = SessionQuery.new( | ||
relation: current_user.sessions.where(conference: current_conference), | ||
params: filter_params | ||
).call.includes(:attendees, :location, :speakers, :tags).order(:starts_at) | ||
end | ||
|
||
private | ||
|
||
@sessions = @sessions.starts_at(params[:starts_at].to_date) if params[:starts_at].present? | ||
def filter_params | ||
params.permit(:starts_at, :live, :past, :starting_soon) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module SessionHelper | ||
def session_filter_color(scope) | ||
case scope | ||
when "live" | ||
"bg-green-500" | ||
when "past" | ||
"bg-blue-teal-light" | ||
when "starting_soon" | ||
"bg-yellow" | ||
end | ||
end | ||
|
||
def session_filter_params | ||
params.permit(SessionQuery::STATUS_SCOPES) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
class ApplicationRecord < ActiveRecord::Base | ||
primary_abstract_class | ||
|
||
class << self | ||
def send_chain_or(scopes) | ||
return all if scopes.blank? | ||
|
||
base_scope = none | ||
|
||
scopes.each do |scope_name| | ||
scope_to_add = send(scope_name) | ||
base_scope = (base_scope == none) ? scope_to_add : base_scope.or(scope_to_add) | ||
end | ||
|
||
base_scope | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class SessionQuery | ||
STATUS_SCOPES = %w[live starting_soon past].freeze | ||
|
||
def initialize(relation: Session.all, params: {}) | ||
@relation = relation | ||
@params = params | ||
end | ||
|
||
def call | ||
filter_by_date | ||
filter_by_status | ||
|
||
relation | ||
end | ||
|
||
private | ||
|
||
attr_accessor :relation, :params | ||
|
||
def filter_by_date | ||
return if starts_at.blank? | ||
|
||
self.relation = relation.starts_at(starts_at) | ||
end | ||
|
||
def filter_by_status | ||
self.relation = relation.send_chain_or(status_scopes) | ||
end | ||
|
||
def starts_at | ||
@_starts_at ||= params[:starts_at]&.to_date | ||
rescue Date::Error | ||
nil | ||
end | ||
|
||
def status_scopes | ||
STATUS_SCOPES & params.keys | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.