Class: Autofill
- Inherits:
-
Object
- Object
- Autofill
- Defined in:
- app/models/autofill.rb
Overview
Mock class to help build forms
Instance Attribute Summary collapse
-
#activities ⇒ Object
Returns the value of attribute activities.
-
#customer ⇒ Object
Returns the value of attribute customer.
-
#date_from ⇒ Object
Returns the value of attribute date_from.
-
#date_to ⇒ Object
Returns the value of attribute date_to.
-
#issues ⇒ Object
Returns the value of attribute issues.
-
#project ⇒ Object
Returns the value of attribute project.
-
#project_id ⇒ Object
“Properties”.
-
#rate ⇒ Object
Returns the value of attribute rate.
-
#time_entries ⇒ Object
Returns the value of attribute time_entries.
-
#total ⇒ Object
Returns the value of attribute total.
-
#total_time ⇒ Object
Returns the value of attribute total_time.
Class Method Summary collapse
Instance Method Summary collapse
-
#errors ⇒ Object
Fake out an AR object.
Instance Attribute Details
#activities ⇒ Object
Returns the value of attribute activities.
7 8 9 |
# File 'app/models/autofill.rb', line 7 def activities @activities end |
#customer ⇒ Object
Returns the value of attribute customer.
10 11 12 |
# File 'app/models/autofill.rb', line 10 def customer @customer end |
#date_from ⇒ Object
Returns the value of attribute date_from.
5 6 7 |
# File 'app/models/autofill.rb', line 5 def date_from @date_from end |
#date_to ⇒ Object
Returns the value of attribute date_to.
6 7 8 |
# File 'app/models/autofill.rb', line 6 def date_to @date_to end |
#issues ⇒ Object
Returns the value of attribute issues.
11 12 13 |
# File 'app/models/autofill.rb', line 11 def issues @issues end |
#project ⇒ Object
Returns the value of attribute project.
9 10 11 |
# File 'app/models/autofill.rb', line 9 def project @project end |
#project_id ⇒ Object
“Properties”
4 5 6 |
# File 'app/models/autofill.rb', line 4 def project_id @project_id end |
#rate ⇒ Object
Returns the value of attribute rate.
8 9 10 |
# File 'app/models/autofill.rb', line 8 def rate @rate end |
#time_entries ⇒ Object
Returns the value of attribute time_entries.
13 14 15 |
# File 'app/models/autofill.rb', line 13 def time_entries @time_entries end |
#total ⇒ Object
Returns the value of attribute total.
14 15 16 |
# File 'app/models/autofill.rb', line 14 def total @total end |
#total_time ⇒ Object
Returns the value of attribute total_time.
12 13 14 |
# File 'app/models/autofill.rb', line 12 def total_time @total_time end |
Class Method Details
.new_from_params(params) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/models/autofill.rb', line 21 def self.new_from_params(params) autofill = Autofill.new return autofill if params.blank? # Get project autofill.project = Project.find_by_id(params[:project_id]) # Get customer autofill.customer = Customer.find_by_id(autofill.project.customer_id) # Customer plugin only has a 1-way relationship # Build date range autofill.date_from = params[:date_from] autofill.date_to = params[:date_to] # Build activities if params[:activities] autofill.activities = params[:activities].collect {|p| p.to_i } end autofill.activities ||= [] # Fetch issues autofill.issues = autofill.project.issues.find(:all, :conditions => ['time_entries.spent_on >= :from AND time_entries.spent_on <= :to AND time_entries.activity_id IN (:activities)', { :from => autofill.date_from, :to => autofill.date_to, :activities => autofill.activities }], :include => [:time_entries]) autofill.total_time = autofill.issues.collect(&:time_entries).flatten.collect(&:hours).sum # Time logged without an issue autofill.time_entries = autofill.project.time_entries.find(:all, :conditions => ['issue_id IS NULL AND spent_on >= :from AND spent_on <= :to AND activity_id IN (:activities)', { :from => autofill.date_from, :to => autofill.date_to, :activities => autofill.activities }]) autofill.total_time += autofill.time_entries.collect(&:hours).sum autofill.total = autofill.total_time.to_f * params[:rate].to_f autofill end |
Instance Method Details
#errors ⇒ Object
Fake out an AR object
17 18 19 |
# File 'app/models/autofill.rb', line 17 def errors return { } end |