Module: Xrono::ApplicationHelper

Includes:
Acl9::Helpers
Defined in:
app/helpers/xrono/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#bootstrap_icon(name) ⇒ Object



5
6
7
# File 'app/helpers/xrono/application_helper.rb', line 5

def bootstrap_icon(name)
  ('i', nil, :class => "icon-#{name}")
end

#external_work_percentage(user, start_date, end_date) ⇒ Object



9
10
11
12
13
14
# File 'app/helpers/xrono/application_helper.rb', line 9

def external_work_percentage(user, start_date, end_date)
  if @site_settings.client
    internal = user.percentage_work_for(@site_settings.client, start_date, end_date)
    (100 - internal).to_s
  end
end

#label_type_for(hour_type) ⇒ Object



33
34
35
36
37
38
39
# File 'app/helpers/xrono/application_helper.rb', line 33

def label_type_for(hour_type)
  {
    'Overtime' => 'important',
    'PTO'      => 'success',
    'CTO'      => 'warning'
  }[hour_type]
end

#last_effective_date(start_date) ⇒ Object



16
17
18
19
20
21
22
# File 'app/helpers/xrono/application_helper.rb', line 16

def last_effective_date(start_date)
  if start_date.end_of_week > Date.current
    Date.current
  else
    start_date.end_of_week
  end
end

#project_completion_metric(project) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/helpers/xrono/application_helper.rb', line 41

def project_completion_metric(project)
  work_unit_hours_array = Array.new # Empty array to work with

  # Take the summation of estimated_hours on a ticket from the project
  estimated_hours = Ticket.for_project(project).sum(:estimated_hours)
  
  # Push the work unit hours in if the ticket on the project has estimated hours
  work_unit_hours = WorkUnit.for_project(project).on_estimated_ticket.sum(:hours)
  
  # Calculatre the projects completion as a percent
  percent = (((work_unit_hours / estimated_hours)).to_f * 100.00).to_i rescue 0
  [percent, 100].min # Make sure you don't go over 100 percent and confuse the graphs
end

#render_label_for(hour_type) ⇒ Object



24
25
26
27
28
29
30
31
# File 'app/helpers/xrono/application_helper.rb', line 24

def render_label_for(hour_type)
  label_type = label_type_for(hour_type)
  if label_type
    haml_tag(:div, :class => 'label ' << label_type) do
      haml_concat hour_type
    end
  end
end