Skip to content

Commit

Permalink
Extract the first_level_user_job_roles and views.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Guo committed Nov 13, 2024
1 parent 12c74e3 commit e134cd5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
1 change: 1 addition & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class HomeController < ApplicationController
before_action :set_breadcrumbs, if: -> { request.format.html? }

def index
@first_level_user_job_roles = current_user&.user_job_roles
redirect_to admin_root_path if current_user&.admin?
end

Expand Down
17 changes: 17 additions & 0 deletions app/views/home/_user_job_roles.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<% user_job_roles.each do |role| %>
<h4><%= role.title %> <small class="text-muted float-end"><%= role.company %></small></h4>
<div class="row">
<% role.managed_user_job_roles.each do |role| %>
<div class="col-3">
<div class="card my-3">
<div class="card-body">
<div class="text-center">
<div><%= role.user.chinese_name %></div>
<small class="text-muted"><%= role.title %></small>
</div>
</div>
</div>
</div>
<% end %>
</div>
<% end %>
32 changes: 8 additions & 24 deletions app/views/home/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,12 @@

<%= render 'login_button' unless current_user.present? %>

<section class="container mt-4">
<div class="row">
<div class="col-12">
<% if current_user&.user_job_roles&.present? %>
<% current_user.user_job_roles.each do |role| %>
<h4><%= role.title %> <small class="text-muted float-end"><%= role.company %></small></h4>
<div class="row">
<% role.managed_user_job_roles.each do |role| %>
<div class="col-3">
<div class="card my-3">
<div class="card-body">
<div class="text-center">
<div><%= role.user.chinese_name %></div>
<small class="text-muted"><%= role.title %></small>
</div>
</div>
</div>
</div>
<% end %>
</div>
<% end %>
<% end %>
<% if @first_level_user_job_roles.present? %>
<section class="container mt-4">
<div class="row">
<div class="col-12">
<%= render partial: 'user_job_roles', locals: { user_job_roles: @first_level_user_job_roles } %>
</div>
</div>
</div>
</section>
</section>
<% end %>

0 comments on commit e134cd5

Please sign in to comment.