Commit e24b51a8 authored by Mario Manno's avatar Mario Manno Committed by Mario Manno

update scopes

Conflicts:
	app/models/conference.rb
	app/models/event.rb
parent 859cca19
......@@ -41,7 +41,7 @@ class ScheduleController < ApplicationController
@rooms = @conference.rooms.public.find(params[:room_ids])
@events = Hash.new
@rooms.each do |room|
@events[room] = room.events.accepted.public.scheduled_on(@day).order(:start_time).all
@events[room] = room.events.accepted.is_public.scheduled_on(@day).order(:start_time).all
end
respond_to do |format|
......
......@@ -26,26 +26,26 @@ class Conference < ActiveRecord::Base
:timezone
validates_inclusion_of :feedback_enabled, :in => [true, false]
validates_uniqueness_of :acronym
validates_format_of :acronym, with: /^[a-zA-Z0-9_-]*$/
validates_format_of :acronym, with: /\A[a-zA-Z0-9_-]*\z/
validate :days_do_not_overlap
after_update :update_timeslots
has_paper_trail
scope :has_submission, lambda { |person|
scope :has_submission, ->(person) {
joins(events: [{event_people: :person}])
.where(EventPerson.arel_table[:event_role].in(["speaker","moderator"]))
.where(Person.arel_table[:id].eq(person.id)).group(:"conferences.id")
}
scope :creation_order, order("conferences.created_at DESC")
scope :creation_order, -> { order("conferences.created_at DESC") }
scope :accessible_by_crew, lambda { |user|
scope :accessible_by_crew, ->(user) {
joins(:conference_users).where(conference_users: {user_id: user})
}
scope :accessible_by_orga, lambda { |user|
scope :accessible_by_orga, ->(user) {
joins(:conference_users).where(conference_users: {user_id: user, role: 'orga'})
}
......
......@@ -17,7 +17,7 @@ class Day < ActiveRecord::Base
has_paper_trail meta: {associated_id: :conference_id, associated_type: "Conference"}
default_scope order(:start_date)
default_scope { order(start_date: :asc) }
validates_presence_of :start_date, message: "missing start date"
validates_presence_of :end_date, message: "missing end date"
......
......@@ -36,19 +36,19 @@ class Event < ActiveRecord::Base
after_save :update_conflicts
scope :accepted, where(self.arel_table[:state].in(%w{confirmed unconfirmed}))
scope :associated_with, lambda {|person| joins(:event_people).where(:"event_people.person_id" => person.id)}
scope :candidates, where(state: %w{new review unconfirmed confirmed})
scope :confirmed, where(state: :confirmed)
scope :no_conflicts, includes(:conflicts).where(:"conflicts.event_id" => nil)
scope :public, where(public: true)
scope :scheduled_on, lambda {|day| where(self.arel_table[:start_time].gteq(day.start_date.to_datetime)).where(self.arel_table[:start_time].lteq(day.end_date.to_datetime)).where(self.arel_table[:room_id].not_eq(nil)) }
scope :scheduled, where(self.arel_table[:start_time].not_eq(nil).and(self.arel_table[:room_id].not_eq(nil)))
scope :unscheduled, where(self.arel_table[:start_time].eq(nil).or(self.arel_table[:room_id].eq(nil)))
scope :without_speaker, where("speaker_count = 0")
scope :with_speaker, where("speaker_count > 0")
has_paper_trail
scope :accepted, -> { where(self.arel_table[:state].in(%w{confirmed unconfirmed})) }
scope :associated_with, ->(person) { joins(:event_people).where(:"event_people.person_id" => person.id) }
scope :candidates, -> { where(state: %w{new review unconfirmed confirmed}) }
scope :confirmed, -> { where(state: :confirmed) }
scope :no_conflicts, -> { includes(:conflicts).where(:"conflicts.event_id" => nil) }
scope :is_public, -> { where(public: true) }
scope :scheduled_on, ->(day) { where(self.arel_table[:start_time].gteq(day.start_date.to_datetime)).where(self.arel_table[:start_time].lteq(day.end_date.to_datetime)).where(self.arel_table[:room_id].not_eq(nil)) }
scope :scheduled, -> { where(self.arel_table[:start_time].not_eq(nil).and(self.arel_table[:room_id].not_eq(nil))) }
scope :unscheduled, -> { where(self.arel_table[:start_time].eq(nil).or(self.arel_table[:room_id].eq(nil))) }
scope :without_speaker, -> { where("speaker_count = 0") }
scope :with_speaker, -> { where("speaker_count > 0") }
has_paper_trail
state_machine do
state :new
......
......@@ -8,7 +8,7 @@ class EventAttachment < ActiveRecord::Base
has_paper_trail meta: {associated_id: :event_id, associated_type: "Event"}
scope :public, where(public: true)
scope :public, -> { where(public: true) }
def link_title
if self.title.present?
......
......@@ -11,7 +11,7 @@ class EventPerson < ActiveRecord::Base
has_paper_trail meta: {associated_id: :event_id, associated_type: "Event"}
scope :presenter, where(event_role: ["speaker", "moderator"])
scope :presenter, -> { where(event_role: ["speaker", "moderator"]) }
def update_speaker_count
event = Event.find(self.event_id)
......
......@@ -10,7 +10,7 @@ class Notification < ActiveRecord::Base
# TODO
#validate :locale_is_valid
scope :with_locale, lambda { |code| where(self.arel_table[:locale].eq(code)) }
scope :with_locale, ->(code) { where(self.arel_table[:locale].eq(code)) }
VARIABLES = {
'conference' => 'Conference name',
......
......@@ -5,7 +5,7 @@ class Person < ActiveRecord::Base
has_many :availabilities, dependent: :destroy
has_many :event_people, dependent: :destroy
has_many :event_ratings, dependent: :destroy
has_many :events, through: :event_people, uniq: true
has_many :events, -> { uniq }, through: :event_people
has_many :im_accounts, dependent: :destroy
has_many :languages, as: :attachable, dependent: :destroy
has_many :links, as: :linkable, dependent: :destroy
......@@ -33,16 +33,16 @@ class Person < ActiveRecord::Base
#validates_inclusion_of :gender, in: GENDERS, allow_nil: true
scope :involved_in, lambda { |conference|
scope :involved_in, ->(conference) {
joins(events: :conference).where(:"conferences.id" => conference.id).group(:"people.id")
}
scope :speaking_at, lambda { |conference|
scope :speaking_at, ->(conference) {
joins(events: :conference).where(:"conferences.id" => conference.id).where(:"event_people.event_role" => ["speaker", "moderator"]).where(:"events.state" => ["unconfirmed", "confirmed"]).group(:"people.id")
}
scope :publicly_speaking_at, lambda { |conference|
scope :publicly_speaking_at, ->(conference) {
joins(events: :conference).where(:"conferences.id" => conference.id).where(:"event_people.event_role" => ["speaker", "moderator"]).where(:"events.public" => true).where(:"events.state" => ["unconfirmed", "confirmed"]).group(:"people.id")
}
scope :confirmed, lambda { |conference|
scope :confirmed, ->(conference) {
joins(events: :conference).where(:"conferences.id" => conference.id).where(:"events.state" => "confirmed")
}
......
......@@ -5,9 +5,9 @@ class Room < ActiveRecord::Base
has_paper_trail meta: {associated_id: :conference_id, associated_type: "Conference"}
default_scope order(:rank)
default_scope -> { order(:rank) }
scope :public, where(public: true)
scope :is_public, -> { where(public: true) }
def to_s
"Room: #{self.name}"
......
......@@ -2,7 +2,7 @@ class Track < ActiveRecord::Base
belongs_to :conference
default_scope order(:name)
default_scope -> { order(:name) }
has_paper_trail meta: {associated_id: :conference_id, associated_type: "Conference"}
......
......@@ -28,7 +28,7 @@ class User < ActiveRecord::Base
validate :conference_user_valid
validate :only_one_role_per_conference
scope :confirmed, where(arel_table[:confirmed_at].not_eq(nil))
scope :confirmed, -> { where(arel_table[:confirmed_at].not_eq(nil)) }
def check_default_values
self.role ||= 'submitter'
......
......@@ -120,7 +120,7 @@ class StaticProgramExport
day_index += 1
end
@conference.events.public.confirmed.scheduled.each do |event|
@conference.events.is_public.confirmed.scheduled.each do |event|
paths << {source: "events/#{event.id}", target: "events/#{event.id}.html"}
paths << {source: "events/#{event.id}.ics", target: "events/#{event.id}.ics"}
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment