<% workflow_state = IssueWorkflowState.find_by(issue_id: @issue.id) unless workflow_state # 이슈에 적용 가능한 워크플로우 찾기 workflow = CustomWorkflow.find_for_issue(@issue) if workflow && workflow.start_step workflow_state = IssueWorkflowState.create( issue: @issue, custom_workflow: workflow, current_step: workflow.start_step, started_at: Time.current ) end end %> <% if workflow_state && workflow_state.custom_workflow %> <% steps = workflow_state.custom_workflow.workflow_steps.ordered current_step = workflow_state.current_step %>

워크플로우: <%= workflow_state.custom_workflow.name %>

<% steps.each_with_index do |step, idx| %> <% is_current = current_step && current_step.id == step.id is_completed = current_step && step.position < current_step.position %>
<%= step.name %>
<% if idx < steps.length - 1 %> <% end %> <% end %>
<% if current_step %>
현재 단계: <%= current_step.name %> <% if current_step.workflow_step_assignees.any? %>  |  담당자: <% current_step.workflow_step_assignees.each do |assignee| %> <%= assignee.assignee_name %> <% end %> <% end %> <% if current_step.is_start && @issue.editable?(User.current) %>  |  이슈 편집 <% end %>
<% # 다음 단계 정보 확인 next_step = current_step.next_step next_step_has_group = next_step && next_step.workflow_step_assignees.where(assignee_type: ['role_group', 'department']).any? next_step_group_members = next_step_has_group ? next_step.all_assignee_users : [] %>
<% unless current_step.is_end %> <% if workflow_state.can_proceed?(User.current) %> <% if next_step_has_group && next_step_group_members.count > 1 %> 다음 단계로 → <% else %> <%= link_to '다음 단계로 →'.html_safe, issue_workflow_next_step_path(@issue), method: :post, class: 'button button-positive', style: 'font-size: 11px; padding: 4px 10px;', data: { confirm: '다음 단계로 진행하시겠습니까?' } %> <% end %> <% else %> 다음 단계로 (권한 없음) <% end %> <% else %> ✓ 워크플로우 완료 <% if @issue.status_id != 5 && (User.current.admin? || current_step.assignee?(User.current)) %> <%= link_to '완료 처리'.html_safe, issue_workflow_complete_path(@issue), method: :post, class: 'button button-positive', style: 'font-size: 11px; padding: 4px 10px; margin-left: 10px;', data: { confirm: '이슈를 완료 처리하시겠습니까?' } %> <% end %> <% end %> <% if !current_step.is_start && workflow_state.can_go_back?(User.current) %> <%= link_to '← 이전'.html_safe, issue_workflow_prev_step_path(@issue), method: :post, class: 'button', style: 'font-size: 11px; padding: 4px 10px; margin-left: 5px;', data: { confirm: '이전 단계로 되돌리시겠습니까?' } %> <% end %> <% if !current_step.is_start && (User.current.admin? || current_step.assignee?(User.current)) %> 반려 <% end %> <% if User.current.admin? %> 단계 이동 <% end %>
<% if current_step.due_days.present? %> <% step_started_at = workflow_state.updated_at due_date = step_started_at + current_step.due_days.days remaining = ((due_date - Time.current) / 1.day).to_i %>
<% if remaining < 0 %> 기한 초과 <%= remaining.abs %>일 <% elsif remaining == 0 %> 오늘 마감 <% else %> 남은 기한: <%= remaining %>일 (<%= due_date.strftime('%Y-%m-%d') %>) <% end %>
<% end %> <% end %>
<% if next_step_has_group && next_step_group_members.count > 1 %> <% end %> <% if User.current.admin? %> <% end %> <% end %>