Module: EmployeesHelper
- Defined in:
- app/helpers/employees_helper.rb
Overview
View helper for employee-related UI components.
Instance Method Summary collapse
-
#employee_command_options(employee) ⇒ Array<String>
Builds the command links available for an employee record.
-
#employee_goals_link(employee = @employee) ⇒ String
Renders a link to the employee's goals with an open-goal count badge.
-
#employee_tab_options(employee = @employee) ⇒ Hash
Builds the tab navigation configuration for an employee detail page.
-
#setup_employee(employee) ⇒ Employee
Builds a new employee with all required nested records for creation.
-
#setup_sales_goal(employee, year) ⇒ Employee
Builds monthly sales goals for the employee for the given year.
-
#strength_video(st) ⇒ String
Renders a thumbnail linked to a StrengthsFinder video.
-
#strength_video_link(st) ⇒ String
Renders a link to open a StrengthsFinder video in a fancybox iframe.
Instance Method Details
#employee_command_options(employee) ⇒ Array<String>
Builds the command links available for an employee record.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/helpers/employees_helper.rb', line 57 def (employee) [].tap do |links| if can?(:update, employee) links << link_to('Edit Employee Details', edit_employee_path(employee)) links << link_to('Reset Sales Watch', reset_sales_watch_employee_path(employee)) end links << link_to('Edit Preferences', edit_preferences_employee_path(employee)) if can?(:update_preferences, employee) links << link_to('Time Off', user_time_off_path(employee)) links << link_to(fa_icon('key', text: 'Login as this employee'), become_employee_url(employee)) if can?(:impersonate, employee) end end |
#employee_goals_link(employee = @employee) ⇒ String
Renders a link to the employee's goals with an open-goal count badge.
131 132 133 134 135 136 |
# File 'app/helpers/employees_helper.rb', line 131 def employee_goals_link(employee = @employee) title = fa_icon('bullseye', text: 'My Goals') goal_size = employee.open_employee_goals.size title << content_tag(:span, goal_size, class: 'badge bg-secondary') if goal_size > 0 link_to title.html_safe, employee_path(employee, tab: "goals") end |
#employee_tab_options(employee = @employee) ⇒ Hash
Builds the tab navigation configuration for an employee detail page.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/helpers/employees_helper.rb', line 72 def (employee = @employee) tabs_hsh = {} tabs_hsh[:main] = { remote_href: tab_main_employee_path(employee) } tabs_hsh[:praises] = { remote_href: tab_praises_employee_path(employee) } tabs_hsh[:training] = { remote_href: tab_training_employee_path(employee) } tabs_hsh[:goals] = { remote_href: tab_goals_employee_path(employee) } tabs_hsh[:strengths] = { remote_href: tab_strengths_employee_path(employee) } tabs_hsh[:reviews] = { remote_href: tab_reviews_employee_path(employee) } tabs_hsh[:sales_commissions] = { remote_href: tab_sales_commissions_employee_path(employee) } tabs_hsh[:subordinates] = { remote_href: tab_subordinates_employee_path(employee) } if employee.managed_employees.active_employees.present? tabs_hsh[:assets] = { remote_href: tab_assets_employee_path(employee) } tabs_hsh[:public_reviews] = { remote_href: tab_public_reviews_employee_path(employee) } tabs_hsh[:preferences] = { remote_href: tab_preferences_employee_path(employee) } tabs_hsh[:scheduler] = { remote_href: tab_scheduler_employee_path(employee) } tabs_hsh[:system] = { remote_href: tab_system_employee_path(employee) } tabs_hsh[:sms] = { remote_href: (employee), counter: employee..unread.size } tabs_hsh[:login_activity] = { remote_href: employee_login_activities_path(employee), title: 'Login Activity' } # hsh[:communications] = { remote_href: employee_communications_path(employee) } tabs_hsh[:vouchers] = { remote_href: search_and_show_searches_path( type: 'VoucherSearch', set_limit: 30, query_params: { supplier_id_eq: employee.id }, selected_columns: %i[voucher_link state company_name category payment_method invoice_number invoice_date gl_date currency business_unit_name total open_amount due_date prority], sort_columns: ['priority', 'gl_date desc'], links: { 'New Voucher' => new_voucher_path(supplier_id: employee.id) } ) } tabs_hsh[:payments] = { remote_href: search_and_show_searches_path( type: 'OutgoingPaymentSearch', set_limit: 30, query_params: { supplier_id_eq: employee.id }, selected_columns: %i[outgoing_payment_link state company_name category payment_method reference_number payment_date gl_date currency total], sort_columns: ['reference_number desc'], links: { 'New Payment' => new_outgoing_payment_path(supplier_id: employee.id) } ) } tabs_hsh[:receipts] = { remote_href: search_and_show_searches_path( type: 'ReceiptSearch', set_limit: 30, query_params: { customer_id_eq: employee.id }, selected_columns: %i[receipt_link state company_name customer_name reference_number receipt_date currency total], sort_columns: ['id desc'], links: { 'New Receipt' => new_receipt_path(customer_id: employee.id) } ) } tabs_hsh[:attachments] = { counter: employee.all_uploads.size, remote_href: employee_uploads_path(employee) } tabs_hsh[:training][:counter] = employee.assigned_or_requested_employee_topics.size if tabs_hsh[:training] tabs_hsh[:praises][:counter] = employee.praises.size if tabs_hsh[:praises] tabs_hsh[:goals][:counter] = employee.open_employee_goals.size if tabs_hsh[:goals] tabs_hsh[:reviews][:counter] = employee.open_employee_reviews.size if tabs_hsh[:reviews] tabs_hsh.delete_if { |k, _v| cannot?(:"read_#{k}", employee) } end |
#setup_employee(employee) ⇒ Employee
Builds a new employee with all required nested records for creation.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/helpers/employees_helper.rb', line 8 def setup_employee(employee) employee.tap do |emp| emp.inactive = false if emp.inactive.nil? emp.build_employee_record(activities_per_day: EmployeeRecord::DEFAULT_ACTIVITIES_PER_DAY, activities_per_day_priority_tiers: EmployeeRecord::DEFAULT_ACTIVITIES_PER_DAY_PRIORITY_TIERS) unless emp.employee_record emp.build_employee_account(authentication_mode: Account::AUTH_GOOGLE, role_ids: [Role.find_by(name: 'employee').id]) unless emp.employee_account %w[email phone fax].each do |category| emp.contact_points.build(category: category) unless emp.contact_points.any? { |c| c.category == category } end emp.build_billing_address unless emp.billing_address (1..34).to_a.each do |i| emp.employee_record.strength_themes.build(priority: i) unless emp.employee_record.strength_themes.find { |s| s.priority.to_i == i } end emp.build_employee_phone_status unless emp.employee_phone_status end end |
#setup_sales_goal(employee, year) ⇒ Employee
Builds monthly sales goals for the employee for the given year.
28 29 30 31 32 33 34 |
# File 'app/helpers/employees_helper.rb', line 28 def setup_sales_goal(employee, year) employee.tap do |employee| (1..12).to_a.each do |month| employee.sales_goals.build(month: month, year: year) if employee.sales_goals.all(conditions: { month: month, year: year }).empty? end end end |
#strength_video(st) ⇒ String
Renders a thumbnail linked to a StrengthsFinder video.
39 40 41 |
# File 'app/helpers/employees_helper.rb', line 39 def strength_video(st) link_to image_tag("//img.youtube.com/vi/#{st.youtube_id}/3.jpg"), "http://www.youtube.com/watch?v=#{st.youtube_id}" end |
#strength_video_link(st) ⇒ String
Renders a link to open a StrengthsFinder video in a fancybox iframe.
46 47 48 49 50 51 52 |
# File 'app/helpers/employees_helper.rb', line 46 def strength_video_link(st) link_to fa_icon('youtube', family: 'fab', text: st.name), "http://www.youtube.com/embed/#{st.youtube_id}?autoplay=1", class: 'various', title: st.description, data: { fancybox: 'strength-videos', type: 'iframe', 'bs-toggle': 'tooltip', placement: 'left' } end |