36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'app/models/dunlop/workflow_instance_batch_model.rb', line 36
def workflow_step_map(user, options = {})
batch_ids = pluck(:id)
workflow_instance_class = self.name.sub(/WorkflowInstanceBatch/, 'WorkflowInstance').constantize
workflow_instance_class.workflow_step_classes.map.with_object(Hash.new{|h, k| h[k] = {}}) do |klass, hash|
step_counts_scope = klass.joins(:workflow_instance).where(workflow_instances: {workflow_instance_batch_id: batch_ids})
if options[:archived].present?
step_counts_scope = step_counts_scope.where.not(workflow_instances: {archived_at: nil})
else
step_counts_scope = step_counts_scope.where(workflow_instances: {archived_at: nil})
end
step_counts = step_counts_scope.group("#{klass.table_name}.state", 'workflow_instances.workflow_instance_batch_id').count
step_counts.each do |(state, batch_id), count|
hash[batch_id][klass] ||= Hash.new{|h, k| h[k] = {}}
hash[batch_id][klass][state] = count
end
end
end
|