Skip to content

Commit

Permalink
add user workitem list
Browse files Browse the repository at this point in the history
  • Loading branch information
hooopo committed Feb 4, 2020
1 parent 0564586 commit bce899b
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 5 deletions.
13 changes: 12 additions & 1 deletion app/controllers/wf/workitems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@

module Wf
class WorkitemsController < ApplicationController
before_action :find_workitem
before_action :find_workitem, except: [:index]
before_action :check_start, only: [:start]
before_action :check_finish, only: %i[pre_finish finish]

breadcrumb "Workflows", :workflows_path

def index
current_party_ids = [
current_user,
Wf::Workflow.org_classes.map { |org, _org_class| current_user.public_send(org) }
].flatten.map { |x| x.party&.id }
@workitems = Wf::Workitem.joins(:workitem_assignments).where(Wf::WorkitemAssignment.table_name => { party_id: current_party_ids })
@workitems = @workitems.where(state: params[:state].intern) if params[:state]
@workitems = @workitems.where(state: params[:state].intern) if params[:state].present?
@workitems = @workitems.distinct.order("id desc").page(params[:page])
end

def show
breadcrumb @workitem.workflow.name, workflow_path(@workitem.workflow)
breadcrumb @workitem.case.name, workflow_case_path(@workitem.workflow, @workitem.case)
Expand Down
6 changes: 4 additions & 2 deletions app/models/wf/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ def self.user_class
::Wf::User
end

def self.org_class
[::Wf::Group]
def self.org_classes
{
group: ::Wf::Group
}
end

after_save do
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/wf/_nav.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</div>

<div class="navbar-end">
<%= current_user&.name %>
<%= link_to current_user&.name, workitems_path %>
<%= link_to 'Forms', forms_path, class: "navbar-item #{"is-active" if controller_name == "forms"}" %>
<%= link_to 'Workflows', workflows_path, class: "navbar-item #{"is-active" if controller_name.start_with?("workflows")}" %>
</div>
Expand Down
68 changes: 68 additions & 0 deletions app/views/wf/workitems/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<div>
<h2 class="">Stats</h2>
<table class="table table-bordered table-info">
<thead>
<tr>
<th scope="col">All</th>
<th scope="col">Enabled</th>
<th scope="col">Started</th>
<th scope="col">Canceled</th>
<th scope="col">Finished</th>
<th scope="col">Overridden</th>
</tr>
</thead>
<tbody>
<tr>
<td><%= link_to @workitems.unscope(:offset).unscope(:limit).unscope(:order).unscope(:select).count, workitems_path %></td>
<td><%= link_to @workitems.unscope(:offset).unscope(:limit).unscope(:order).unscope(:select).enabled.count, workitems_path(state: :enabled) %></td>
<td><%= link_to @workitems.unscope(:offset).unscope(:limit).unscope(:order).unscope(:select).started.count, workitems_path(state: :started) %></td>
<td><%= link_to @workitems.unscope(:offset).unscope(:limit).unscope(:order).unscope(:select).canceled.count, workitems_path(state: :canceled) %></td>
<td><%= link_to @workitems.unscope(:offset).unscope(:limit).unscope(:order).unscope(:select).finished.count, workitems_path(state: :finished) %></td>
<td><%= link_to @workitems.unscope(:offset).unscope(:limit).unscope(:order).unscope(:select).overridden.count, workitems_path(state: :overridden) %></td>
</tr>
</tbody>
</table>
</div>

<div>
<h2>Workitems</h2>
<table class="table table-bordered table-info">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Transition</th>
<th scope="col">State</th>
<th scope="col">Holding User</th>
<th scope="col">Started At</th>
<th scope="col">Enabled At</th>
<th scope="col">Canceled At</th>
<th scope="col">Finished At</th>
<th scope="col">Overridden At</th>
<th scope="col">Deadline</th>
<th scope="col">Detail</th>
</tr>
</thead>
<tbody>
<% @workitems.each do |workitem| %>
<tr>
<td><%= link_to workitem.id, workitem_path(workitem) %></td>
<td>
<%= link_to workitem.transition.name, workflow_transition_path(workitem.workflow, workitem.transition) %> </td>
<td><%= workitem.state %></td>
<td><%= workitem.holding_user_id %></td>
<td><%= workitem.started_at %></td>
<td><%= workitem.enabled_at %></td>
<td><%= workitem.canceled_at %></td>
<td><%= workitem.finished_at %></td>
<td><%= workitem.overridden_at %></td>
<td><%= workitem.deadline %></td>
<td><%= link_to "Run", workitem_path(workitem), class: 'btn btn-sm btn-success' %></td>
</tr>
<% end %>
</tbody>
</table>
</div>

<div>
<%= paginate @workitems, theme: 'twitter-bootstrap-4' %>
</div>
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
end
end

root to: "workflows#index"
root to: "workitems#index"
end

0 comments on commit bce899b

Please sign in to comment.