%= javascript_tag do %>
function toggleDept(id) {
var children = document.querySelectorAll('.dept-children-' + id);
var toggle = document.getElementById('toggle-' + id);
children.forEach(function(el) {
if (el.style.display === 'none') {
el.style.display = 'flex';
toggle.textContent = '[-]';
} else {
el.style.display = 'none';
toggle.textContent = '[+]';
}
});
}
<% end %>
조직도
<%= link_to '조직도 관리', '/org_chart', class: 'button' %>
<% ceo = Department.ceo.first %>
<% if ceo %>
<%# CEO 레벨 %>
CEO
<%= ceo.name %>
<% if ceo.effective_leader %>
<%= ceo.has_acting_leader? ? '대결: ' : '' %><%= ceo.effective_leader.name %>
<% end %>
<% executives = Department.executives.sorted %>
<% if executives.any? %>
<%# C-Level 레벨 %>
C-Level
<% executives.each do |exec| %>
<%= exec.type_name %>
<%= exec.name %>
<% if exec.effective_leader %>
<%= exec.has_acting_leader? ? '대결: ' : '' %><%= exec.effective_leader.name %>
<% else %>
(담당자)
<% end %>
<%= exec.all_members.count %>명
<%# C-Level 산하 본부/팀 %>
<% exec_divisions = Department.divisions.where(parent_id: exec.id).sorted %>
<% exec_teams = Department.teams.where(parent_id: exec.id).sorted %>
<% if exec_divisions.any? || exec_teams.any? %>
<% exec_divisions.each do |div| %>
<%= render_org_branch(div) %>
<% end %>
<% exec_teams.each do |team| %>
팀
<%= team.name %>
<% if team.effective_leader %>
<%= team.has_acting_leader? ? '대결: ' : '' %><%= team.effective_leader.name %>
<% else %>
(팀장 미지정)
<% end %>
<%= team.all_members.count %>명
<% end %>
<% end %>
<% end %>
<% end %>
<%# CEO 직속 본부/팀 (C-Level 거치지 않는) %>
<% direct_divisions = Department.divisions.where(parent_id: [nil, ceo.id]).sorted %>
<% direct_teams = Department.teams.where(parent_id: [nil, ceo.id]).sorted %>
<% if direct_divisions.any? || direct_teams.any? %>
본부/팀
<% direct_divisions.each do |div| %>
<%= render_org_branch(div) %>
<% end %>
<% direct_teams.each do |team| %>
팀
<%= team.name %>
<% if team.effective_leader %>
<%= team.has_acting_leader? ? '대결: ' : '' %><%= team.effective_leader.name %>
<% else %>
(팀장 미지정)
<% end %>
<%= team.all_members.count %>명
<% end %>
<% end %>
<% else %>
조직도가 설정되지 않았습니다.
<%= link_to 'CEO 등록하기', new_department_path(type: 'ceo'), class: 'button-positive' %>
<% end %>