Sha256: 1edc23dcdaf29ffd6f2d0110d939ca5ae23e431ca5c3c697b3aaa855385f235b

Contents?: true

Size: 1.38 KB

Versions: 3

Compression:

Stored size: 1.38 KB

Contents

class Alert < ActiveRecord::Base
  acts_as_paranoid
  after_create :notify_users
  belongs_to :organization
  belongs_to :user

  def get_shift
    if self.alert_type == "Time Off"
        Timeoff.find_by_id(self.alert_type_id)
    elsif self.alert_type == "Cancellation"
        @cancellation = Cancellation.find_by_id(self.alert_type_id)
        if !@cancellation.nil?
          @cancellation.shift
        end 
    elsif self.alert_type == "Late Notice"
        @lateness = Lateness.find_by_id(self.alert_type_id)
        if !@lateness.nil?
          @lateness.shift
        end 
    elsif self.alert_type == "Swap"
       @swap = Swap.find_by_id(self.alert_type_id)
       if !@swap.nil? 
        @swap.shift
       end
    elsif self.alert_type =="unavailable"
       @unavailable = Unavailable.find_by_id(self.alert_type_id)
       if !@unavailable.nil? 
        @unavailable.shift
       end
    elsif self.alert_type =="Fill Shift"
      Shift.find_by_id(self.alert_type_id)   
    end
  end

  def get_shift_job
    @swap = Swap.find_by_id(self.alert_type_id)
    if !@swap.nil? 
      @swap.shift.job.name
    end
  end
  
  def find_time_off
    Timeoff.find_by_id(self.alert_type_id)
  end

  private
  
  def notify_users
    org_name = self.organization.name
    org_name = org_name.gsub(" ", "_") if org_name.include?(" ")
    Pusher.trigger(org_name, 'new-alert', {:message => ''})
  end

  

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pshq_engine-0.1.6 app/models/alert.rb
pshq_engine-0.1.5 app/models/alert.rb
pshq_engine-0.0.1 app/models/alert.rb