petri_flow 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/config/wf_manifest.js +2 -0
  6. data/app/assets/javascripts/wf/application.js +4 -0
  7. data/app/assets/stylesheets/wf/application.scss +2 -0
  8. data/app/assets/stylesheets/wf/arcs.css +4 -0
  9. data/app/assets/stylesheets/wf/cases.css +4 -0
  10. data/app/assets/stylesheets/wf/comments.css +4 -0
  11. data/app/assets/stylesheets/wf/fields.css +4 -0
  12. data/app/assets/stylesheets/wf/forms.css +4 -0
  13. data/app/assets/stylesheets/wf/guards.css +4 -0
  14. data/app/assets/stylesheets/wf/places.css +4 -0
  15. data/app/assets/stylesheets/wf/transitions.css +4 -0
  16. data/app/assets/stylesheets/wf/workflows.css +4 -0
  17. data/app/assets/stylesheets/wf/workitem_assignments.css +4 -0
  18. data/app/assets/stylesheets/wf/workitems.css +4 -0
  19. data/app/controllers/wf/application_controller.rb +14 -0
  20. data/app/controllers/wf/arcs_controller.rb +61 -0
  21. data/app/controllers/wf/cases_controller.rb +48 -0
  22. data/app/controllers/wf/comments_controller.rb +30 -0
  23. data/app/controllers/wf/fields_controller.rb +54 -0
  24. data/app/controllers/wf/forms_controller.rb +59 -0
  25. data/app/controllers/wf/guards_controller.rb +58 -0
  26. data/app/controllers/wf/places_controller.rb +53 -0
  27. data/app/controllers/wf/transitions_controller.rb +69 -0
  28. data/app/controllers/wf/workflows_controller.rb +59 -0
  29. data/app/controllers/wf/workitem_assignments_controller.rb +30 -0
  30. data/app/controllers/wf/workitems_controller.rb +79 -0
  31. data/app/helpers/wf/application_helper.rb +6 -0
  32. data/app/helpers/wf/arcs_helper.rb +6 -0
  33. data/app/helpers/wf/cases_helper.rb +6 -0
  34. data/app/helpers/wf/comments_helper.rb +6 -0
  35. data/app/helpers/wf/fields_helper.rb +6 -0
  36. data/app/helpers/wf/forms_helper.rb +6 -0
  37. data/app/helpers/wf/guards_helper.rb +6 -0
  38. data/app/helpers/wf/places_helper.rb +6 -0
  39. data/app/helpers/wf/transitions_helper.rb +6 -0
  40. data/app/helpers/wf/workflows_helper.rb +6 -0
  41. data/app/helpers/wf/workitem_assignments_helper.rb +6 -0
  42. data/app/helpers/wf/workitems_helper.rb +6 -0
  43. data/app/jobs/wf/application_job.rb +6 -0
  44. data/app/jobs/wf/fire_timed_workitem_job.rb +15 -0
  45. data/app/mailers/wf/application_mailer.rb +8 -0
  46. data/app/models/wf/application_record.rb +7 -0
  47. data/app/models/wf/arc.rb +42 -0
  48. data/app/models/wf/callbacks/assignment_default.rb +12 -0
  49. data/app/models/wf/callbacks/deadline_default.rb +11 -0
  50. data/app/models/wf/callbacks/enable_default.rb +11 -0
  51. data/app/models/wf/callbacks/fire_default.rb +11 -0
  52. data/app/models/wf/callbacks/hold_timeout_default.rb +11 -0
  53. data/app/models/wf/callbacks/notification_default.rb +11 -0
  54. data/app/models/wf/callbacks/time_default.rb +11 -0
  55. data/app/models/wf/callbacks/unassignment_default.rb +11 -0
  56. data/app/models/wf/case.rb +44 -0
  57. data/app/models/wf/case_assignment.rb +22 -0
  58. data/app/models/wf/case_command/add_comment.rb +17 -0
  59. data/app/models/wf/case_command/add_manual_assignment.rb +17 -0
  60. data/app/models/wf/case_command/add_token.rb +20 -0
  61. data/app/models/wf/case_command/add_workitem_assignment.rb +35 -0
  62. data/app/models/wf/case_command/begin_workitem_action.rb +33 -0
  63. data/app/models/wf/case_command/cancel.rb +17 -0
  64. data/app/models/wf/case_command/cancel_workitem.rb +20 -0
  65. data/app/models/wf/case_command/clear_manual_assignments.rb +16 -0
  66. data/app/models/wf/case_command/clear_workitem_assignments.rb +20 -0
  67. data/app/models/wf/case_command/consume_token.rb +23 -0
  68. data/app/models/wf/case_command/enable_transitions.rb +33 -0
  69. data/app/models/wf/case_command/end_workitem_action.rb +25 -0
  70. data/app/models/wf/case_command/finish_workitem.rb +18 -0
  71. data/app/models/wf/case_command/finished_p.rb +28 -0
  72. data/app/models/wf/case_command/fire_message_transition.rb +20 -0
  73. data/app/models/wf/case_command/fire_transition_internal.rb +41 -0
  74. data/app/models/wf/case_command/lock_token.rb +21 -0
  75. data/app/models/wf/case_command/new.rb +17 -0
  76. data/app/models/wf/case_command/release_token.rb +20 -0
  77. data/app/models/wf/case_command/remove_manual_assignment.rb +17 -0
  78. data/app/models/wf/case_command/remove_workitem_assignment.rb +24 -0
  79. data/app/models/wf/case_command/resume.rb +17 -0
  80. data/app/models/wf/case_command/set_workitem_assignments.rb +32 -0
  81. data/app/models/wf/case_command/start_case.rb +19 -0
  82. data/app/models/wf/case_command/start_workitem.rb +26 -0
  83. data/app/models/wf/case_command/suspend.rb +17 -0
  84. data/app/models/wf/case_command/sweep_automatic_transitions.rb +31 -0
  85. data/app/models/wf/case_command/sweep_timed_transitions.rb +16 -0
  86. data/app/models/wf/case_command/workitem_action.rb +20 -0
  87. data/app/models/wf/comment.rb +21 -0
  88. data/app/models/wf/demo_target.rb +18 -0
  89. data/app/models/wf/entry.rb +33 -0
  90. data/app/models/wf/field.rb +53 -0
  91. data/app/models/wf/field_value.rb +30 -0
  92. data/app/models/wf/form.rb +18 -0
  93. data/app/models/wf/group.rb +21 -0
  94. data/app/models/wf/guard.rb +73 -0
  95. data/app/models/wf/party.rb +22 -0
  96. data/app/models/wf/place.rb +28 -0
  97. data/app/models/wf/token.rb +37 -0
  98. data/app/models/wf/transition.rb +49 -0
  99. data/app/models/wf/transition_static_assignment.rb +21 -0
  100. data/app/models/wf/user.rb +26 -0
  101. data/app/models/wf/workflow.rb +182 -0
  102. data/app/models/wf/workitem.rb +78 -0
  103. data/app/models/wf/workitem_assignment.rb +19 -0
  104. data/app/views/layouts/wf/_alert.html.erb +4 -0
  105. data/app/views/layouts/wf/_footer.html.erb +13 -0
  106. data/app/views/layouts/wf/_nav.html.erb +13 -0
  107. data/app/views/layouts/wf/_notice.html.erb +4 -0
  108. data/app/views/layouts/wf/application.html.erb +34 -0
  109. data/app/views/wf/arcs/_form.html.erb +40 -0
  110. data/app/views/wf/arcs/edit.html.erb +1 -0
  111. data/app/views/wf/arcs/new.html.erb +1 -0
  112. data/app/views/wf/arcs/show.html.erb +67 -0
  113. data/app/views/wf/cases/_form.html.erb +27 -0
  114. data/app/views/wf/cases/index.html.erb +35 -0
  115. data/app/views/wf/cases/new.html.erb +1 -0
  116. data/app/views/wf/cases/show.html.erb +113 -0
  117. data/app/views/wf/comments/new.html.erb +27 -0
  118. data/app/views/wf/fields/_form.html.erb +42 -0
  119. data/app/views/wf/fields/edit.html.erb +1 -0
  120. data/app/views/wf/fields/new.html.erb +1 -0
  121. data/app/views/wf/forms/_form.html.erb +32 -0
  122. data/app/views/wf/forms/edit.html.erb +1 -0
  123. data/app/views/wf/forms/index.html.erb +32 -0
  124. data/app/views/wf/forms/new.html.erb +1 -0
  125. data/app/views/wf/forms/show.html.erb +53 -0
  126. data/app/views/wf/guards/_form.html.erb +43 -0
  127. data/app/views/wf/guards/edit.html.erb +1 -0
  128. data/app/views/wf/guards/new.html.erb +1 -0
  129. data/app/views/wf/places/_form.html.erb +43 -0
  130. data/app/views/wf/places/edit.html.erb +1 -0
  131. data/app/views/wf/places/new.html.erb +1 -0
  132. data/app/views/wf/transitions/_form.html.erb +92 -0
  133. data/app/views/wf/transitions/edit.html.erb +1 -0
  134. data/app/views/wf/transitions/new.html.erb +1 -0
  135. data/app/views/wf/workflows/_form.html.erb +32 -0
  136. data/app/views/wf/workflows/edit.html.erb +1 -0
  137. data/app/views/wf/workflows/index.html.erb +38 -0
  138. data/app/views/wf/workflows/new.html.erb +1 -0
  139. data/app/views/wf/workflows/show.html.erb +177 -0
  140. data/app/views/wf/workitem_assignments/new.html.erb +27 -0
  141. data/app/views/wf/workitems/index.html.erb +68 -0
  142. data/app/views/wf/workitems/pre_finish.html.erb +33 -0
  143. data/app/views/wf/workitems/show.html.erb +211 -0
  144. data/config/routes.rb +30 -0
  145. data/db/migrate/20200130201043_init.rb +226 -0
  146. data/db/migrate/20200130201641_init_some_data.rb +15 -0
  147. data/db/migrate/20200131200455_create_wf_entries.rb +19 -0
  148. data/db/migrate/20200201001543_add_target_field_name_for_guard.rb +7 -0
  149. data/lib/tasks/wf_tasks.rake +5 -0
  150. data/lib/wf/engine.rb +10 -0
  151. data/lib/wf/version.rb +5 -0
  152. data/lib/wf.rb +7 -0
  153. metadata +312 -0
@@ -0,0 +1,211 @@
1
+ <div class="float-right">
2
+ <%= link_to 'Back to Case', workflow_case_path(@workitem.workflow, @workitem.case), class: 'btn btn-primary' %>
3
+ </div>
4
+ <div>
5
+ <h2>Transition</h2>
6
+ <table class="table table-bordered table-info">
7
+ <thead>
8
+ <tr>
9
+ <th scope="col">ID</th>
10
+ <th scope="col">Name</th>
11
+ <th scope="col">Description</th>
12
+ <th scope="col">Trigger Limit</th>
13
+ <th scope="col">Trigger Type</th>
14
+ <th scope="col">Sort Order</th>
15
+ <th scope="col">Custom Form</th>
16
+ </tr>
17
+ </thead>
18
+ <tbody>
19
+ <tr>
20
+ <td><%= @workitem.transition.id %></td>
21
+ <td><%= @workitem.transition.name %></td>
22
+ <td><%= @workitem.transition.description %></td>
23
+ <td><%= @workitem.transition.trigger_limit %></td>
24
+ <td><%= @workitem.transition.trigger_type %></td>
25
+ <td><%= @workitem.transition.sort_order %></td>
26
+
27
+ <td>
28
+ <% if @workitem.transition.form %>
29
+ <%= link_to @workitem.transition.form.name, form_path(@workitem.transition.form) %>
30
+ <% else %>
31
+ No Form
32
+ <% end %>
33
+ </td>
34
+ </tr>
35
+ </tbody>
36
+ </table>
37
+ </div>
38
+
39
+ <div>
40
+ <h2>Detail</h2>
41
+ <table class="table table-bordered table-info">
42
+ <thead>
43
+ <tr>
44
+ <th scope="col">ID</th>
45
+ <th scope="col">Transition</th>
46
+ <th scope="col">State</th>
47
+ <th scope="col">Holding User</th>
48
+ <th scope="col">Started At</th>
49
+ <th scope="col">Enabled At</th>
50
+ <th scope="col">Canceled At</th>
51
+ <th scope="col">Finished At</th>
52
+ <th scope="col">Overridden At</th>
53
+ <th scope="col">Deadline</th>
54
+ </tr>
55
+ </thead>
56
+ <tbody>
57
+ <tr>
58
+ <td><%= @workitem.id %></td>
59
+ <td>
60
+ <%= link_to @workitem.transition.name, workflow_transition_path(@workitem.workflow, @workitem.transition) %> </td>
61
+ <td><%= @workitem.state %></td>
62
+ <td><%= @workitem.holding_user_id %></td>
63
+ <td><%= @workitem.started_at %></td>
64
+ <td><%= @workitem.enabled_at %></td>
65
+ <td><%= @workitem.canceled_at %></td>
66
+ <td><%= @workitem.finished_at %></td>
67
+ <td><%= @workitem.overridden_at %></td>
68
+ <td><%= @workitem.deadline %></td>
69
+ </tr>
70
+ </tbody>
71
+ </table>
72
+ </div>
73
+
74
+ <% if @workitem.transition.form %>
75
+ <div>
76
+ <h2>Entries</h2>
77
+ <table class="table table-bordered table-info">
78
+ <thead>
79
+ <tr>
80
+ <th scope="col">ID</th>
81
+ <th scope="col">User</th>
82
+ <th scope="col">Payload</th>
83
+ </tr>
84
+ </thead>
85
+ <tbody>
86
+ <% @workitem.entries.each do |entry| %>
87
+ <tr>
88
+ <td><%= entry.id %></td>
89
+ <td><%= entry.user_id %></td>
90
+ <td>
91
+ <pre>
92
+ <%= JSON.pretty_generate(entry.payload) %>
93
+ </pre>
94
+ </td>
95
+ </tr>
96
+ <% end %>
97
+ </tbody>
98
+ </table>
99
+ </div>
100
+ <% end %>
101
+
102
+ <div>
103
+ <h2>Assignments</h2>
104
+ <table class="table table-bordered table-info">
105
+ <thead>
106
+ <tr>
107
+ <th scope="col">ID</th>
108
+ <th scope="col">Party ID</th>
109
+ <th scope="col">Name</th>
110
+ <th scope="col">Created At</th>
111
+ <th scope="col">Action</th>
112
+ </tr>
113
+ </thead>
114
+ <tbody>
115
+ <% @workitem.workitem_assignments.includes(:party).each do |assignment|%>
116
+ <tr>
117
+ <td><%= assignment.id %></td>
118
+ <td><%= assignment.party_id %></td>
119
+ <td>
120
+ <%= assignment.party.party_name %> </td>
121
+ <td><%= assignment.created_at %></td>
122
+ <td><%= link_to "Remove", workitem_workitem_assignment_path(@workitem, party_id: assignment.party_id), remote: true, method: :delete, data: {confirm: 'confirm?'}, class: 'btn btn-sm btn-info' %></td>
123
+ </tr>
124
+ <% end %>
125
+ <tr>
126
+ <td colspan="5">
127
+ <% if @workitem.transition.user? && (@workitem.started? || @workitem.enabled?) %>
128
+ <% if @workitem.finished_by?(current_user) %>
129
+ <%= link_to "Pre Finish Workitem", pre_finish_workitem_path(@workitem), class: 'btn btn-sm btn-dark' %>
130
+ <% elsif @workitem.started_by?(current_user)%>
131
+ <%= link_to "Start Workitem", start_workitem_path(@workitem), method: :put, class: 'btn btn-sm btn-dark' %>
132
+ <% else %>
133
+ You can not start workitem, Please assign to youself.
134
+ <% end %>
135
+ <%= link_to "Re Assign", new_workitem_workitem_assignment_path(@workitem), class: 'btn btn-success btn-sm' %>
136
+ <%= link_to "Assign Yourself", new_workitem_workitem_assignment_path(@workitem, party_id: current_user.party&.id), class: 'btn btn-success btn-sm' %>
137
+ <%= link_to "Add Comment", new_workitem_comment_path(@workitem), class: 'btn btn-success btn-sm' %>
138
+ <% end %>
139
+ </td>
140
+ </tr>
141
+ </tbody>
142
+ </table>
143
+ </div>
144
+
145
+ <div>
146
+ <h2>Comments</h2>
147
+ <table class="table table-bordered table-info">
148
+ <thead>
149
+ <tr>
150
+ <th scope="col">ID</th>
151
+ <th scope="col">Body</th>
152
+ <th scope="col">User</th>
153
+ <th scope="col">Created At</th>
154
+ <th scope="col">Action</th>
155
+ </tr>
156
+ </thead>
157
+ <tbody>
158
+ <% @workitem.comments.order("id DESC").each do |comment| %>
159
+ <tr>
160
+ <td><%= comment.id %></td>
161
+ <td>
162
+ <%= comment.body %> </td>
163
+ <td><%= comment.user_id %></td>
164
+ <td><%= comment.created_at %></td>
165
+ <td><%= link_to "Delete", workitem_comment_path(@workitem, comment), remote: true, method: :delete, data: {confirm: 'confirm?', disable_with: 'Waiting...'}, class: 'btn btn-sm btn-info' %></td>
166
+ </tr>
167
+ <% end %>
168
+ </tbody>
169
+ </table>
170
+ </div>
171
+
172
+ <div>
173
+ <h2>All Workitems</h2>
174
+ <table class="table table-bordered table-info">
175
+ <thead>
176
+ <tr>
177
+ <th scope="col">ID</th>
178
+ <th scope="col">Transition</th>
179
+ <th scope="col">State</th>
180
+ <th scope="col">Trigger Type</th>
181
+ <th scope="col">Holding User</th>
182
+ <th scope="col">Started At</th>
183
+ <th scope="col">Enabled At</th>
184
+ <th scope="col">Canceled At</th>
185
+ <th scope="col">Finished At</th>
186
+ <th scope="col">Overridden At</th>
187
+ <th scope="col">Deadline</th>
188
+ <th scope="col">Action</th>
189
+ </tr>
190
+ </thead>
191
+ <tbody>
192
+ <% @workitem.case.workitems.includes(:transition).each do |workitem| %>
193
+ <tr>
194
+ <td><%= link_to workitem.id, workitem_path(workitem) %></td>
195
+ <td>
196
+ <%= workitem.transition.name %> </td>
197
+ <td><%= workitem.state %></td>
198
+ <td><%= workitem.transition.trigger_type %></td>
199
+ <td><%= workitem.holding_user_id %></td>
200
+ <td><%= workitem.started_at %></td>
201
+ <td><%= workitem.enabled_at %></td>
202
+ <td><%= workitem.canceled_at %></td>
203
+ <td><%= workitem.finished_at %></td>
204
+ <td><%= workitem.overridden_at %></td>
205
+ <td><%= workitem.deadline %></td>
206
+ <td><%= link_to "Run", workitem_path(workitem), class: 'btn btn-sm btn-success' %></td>
207
+ </tr>
208
+ <% end %>
209
+ </tbody>
210
+ </table>
211
+ </div>
data/config/routes.rb ADDED
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ Wf::Engine.routes.draw do
4
+ resources :workflows do
5
+ resources :transitions
6
+ resources :places
7
+ resources :arcs
8
+ resources :cases
9
+ end
10
+
11
+ resources :arcs do
12
+ resources :guards
13
+ end
14
+
15
+ resources :forms do
16
+ resources :fields
17
+ end
18
+
19
+ resources :workitems do
20
+ resources :workitem_assignments, only: %i[new create destroy]
21
+ resources :comments, only: %i[new create destroy]
22
+ member do
23
+ put :start
24
+ get :pre_finish
25
+ put :finish
26
+ end
27
+ end
28
+
29
+ root to: "workitems#index"
30
+ end
@@ -0,0 +1,226 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Init < ActiveRecord::Migration[6.0]
4
+ def change
5
+ create_table "wf_arcs", force: :cascade do |t|
6
+ t.bigint "workflow_id"
7
+ t.bigint "transition_id"
8
+ t.bigint "place_id"
9
+ t.integer "direction", default: 0, comment: "0-in, 1-out"
10
+ t.datetime "created_at", precision: 6, null: false
11
+ t.datetime "updated_at", precision: 6, null: false
12
+ t.integer "guards_count", default: 0
13
+ end
14
+
15
+ create_table "wf_case_assignments", comment: "Manual per-case assignments of transition to parties", force: :cascade do |t|
16
+ t.bigint "case_id"
17
+ t.bigint "transition_id"
18
+ t.bigint "party_id"
19
+ t.datetime "created_at", precision: 6, null: false
20
+ t.datetime "updated_at", precision: 6, null: false
21
+ t.index %w[case_id transition_id party_id], name: "wf_ctp_u", unique: true
22
+ end
23
+
24
+ create_table "wf_cases", force: :cascade do |t|
25
+ t.bigint "workflow_id"
26
+ t.string "targetable_type", comment: "point to target type of Application."
27
+ t.string "targetable_id", comment: "point to target ID of Application."
28
+ t.integer "state", default: 0, comment: "0-created, 1-active, 2-suspended, 3-canceled, 4-finished"
29
+ t.datetime "created_at", precision: 6, null: false
30
+ t.datetime "updated_at", precision: 6, null: false
31
+ end
32
+
33
+ create_table "wf_comments", force: :cascade do |t|
34
+ t.bigint "workitem_id"
35
+ t.string "user_id"
36
+ t.text "body"
37
+ t.datetime "created_at", precision: 6, null: false
38
+ t.datetime "updated_at", precision: 6, null: false
39
+ t.index ["user_id"], name: "index_wf_comments_on_user_id"
40
+ t.index ["workitem_id"], name: "index_wf_comments_on_workitem_id"
41
+ end
42
+
43
+ create_table "wf_demo_targets", comment: "For demo, useless.", force: :cascade do |t|
44
+ t.string "name"
45
+ t.string "description"
46
+ t.datetime "created_at", precision: 6, null: false
47
+ t.datetime "updated_at", precision: 6, null: false
48
+ end
49
+
50
+ create_table "wf_field_values", force: :cascade do |t|
51
+ t.bigint "workflow_id"
52
+ t.bigint "transition_id"
53
+ t.bigint "form_id"
54
+ t.bigint "field_id"
55
+ t.text "value"
56
+ t.datetime "created_at", precision: 6, null: false
57
+ t.datetime "updated_at", precision: 6, null: false
58
+ t.index ["field_id"], name: "index_wf_field_values_on_field_id"
59
+ t.index ["form_id"], name: "index_wf_field_values_on_form_id"
60
+ t.index ["transition_id"], name: "index_wf_field_values_on_transition_id"
61
+ t.index ["workflow_id"], name: "index_wf_field_values_on_workflow_id"
62
+ end
63
+
64
+ create_table "wf_fields", force: :cascade do |t|
65
+ t.string "name"
66
+ t.bigint "form_id"
67
+ t.integer "position", default: 0
68
+ t.integer "field_type", default: 0
69
+ t.string "field_type_name"
70
+ t.string "default_value"
71
+ t.datetime "created_at", precision: 6, null: false
72
+ t.datetime "updated_at", precision: 6, null: false
73
+ t.index ["form_id"], name: "index_wf_fields_on_form_id"
74
+ end
75
+
76
+ create_table "wf_forms", force: :cascade do |t|
77
+ t.string "name"
78
+ t.text "description"
79
+ t.datetime "created_at", precision: 6, null: false
80
+ t.datetime "updated_at", precision: 6, null: false
81
+ end
82
+
83
+ create_table "wf_groups", comment: "For demo", force: :cascade do |t|
84
+ t.string "name"
85
+ t.datetime "created_at", precision: 6, null: false
86
+ t.datetime "updated_at", precision: 6, null: false
87
+ end
88
+
89
+ create_table "wf_guards", force: :cascade do |t|
90
+ t.bigint "arc_id"
91
+ t.bigint "workflow_id"
92
+ t.string "fieldable_type"
93
+ t.string "fieldable_id"
94
+ t.string "op"
95
+ t.string "value"
96
+ t.string "exp"
97
+ t.datetime "created_at", precision: 6, null: false
98
+ t.datetime "updated_at", precision: 6, null: false
99
+ t.index ["arc_id"], name: "index_wf_guards_on_arc_id"
100
+ t.index ["workflow_id"], name: "index_wf_guards_on_workflow_id"
101
+ end
102
+
103
+ create_table "wf_parties", comment: "for groups or roles or users or positions etc.", force: :cascade do |t|
104
+ t.string "partable_type"
105
+ t.string "partable_id"
106
+ t.string "party_name"
107
+ t.datetime "created_at", precision: 6, null: false
108
+ t.datetime "updated_at", precision: 6, null: false
109
+ t.index %w[partable_type partable_id], name: "index_wf_parties_on_partable_type_and_partable_id", unique: true
110
+ end
111
+
112
+ create_table "wf_places", force: :cascade do |t|
113
+ t.bigint "workflow_id"
114
+ t.string "name"
115
+ t.text "description"
116
+ t.integer "sort_order", default: 0
117
+ t.integer "place_type", default: 0, comment: "类型:0-start,1-normal,2-end"
118
+ t.datetime "created_at", precision: 6, null: false
119
+ t.datetime "updated_at", precision: 6, null: false
120
+ end
121
+
122
+ create_table "wf_tokens", force: :cascade do |t|
123
+ t.bigint "workflow_id"
124
+ t.bigint "case_id"
125
+ t.string "targetable_type"
126
+ t.string "targetable_id"
127
+ t.bigint "place_id"
128
+ t.integer "state", default: 0, comment: "0-free, 1-locked, 2-canceled, 3-consumed"
129
+ t.bigint "locked_workitem_id"
130
+ if /mysql/i.match?(ActiveRecord::Base.connection.adapter_name)
131
+ t.datetime "produced_at", default: -> { "current_timestamp" }
132
+ elsif /postgre/i.match?(ActiveRecord::Base.connection.adapter_name)
133
+ t.datetime "produced_at", default: -> { "timezone('utc'::text, now())" }
134
+ end
135
+ t.datetime "locked_at"
136
+ t.datetime "canceled_at"
137
+ t.datetime "consumed_at"
138
+ t.datetime "created_at", precision: 6, null: false
139
+ t.datetime "updated_at", precision: 6, null: false
140
+ end
141
+
142
+ create_table "wf_transition_static_assignments", comment: "pre assignment for transition", force: :cascade do |t|
143
+ t.bigint "party_id"
144
+ t.bigint "transition_id"
145
+ t.bigint "workflow_id"
146
+ t.datetime "created_at", precision: 6, null: false
147
+ t.datetime "updated_at", precision: 6, null: false
148
+ t.index %w[transition_id party_id], name: "wf_tp_u", unique: true
149
+ end
150
+
151
+ create_table "wf_transitions", force: :cascade do |t|
152
+ t.string "name"
153
+ t.text "description"
154
+ t.bigint "workflow_id"
155
+ t.integer "sort_order", default: 0
156
+ t.integer "trigger_limit", comment: "use with timed trigger, after x minitues, trigger exec"
157
+ t.integer "trigger_type", default: 0, comment: "0-user,1-automatic, 2-message,3-time"
158
+ t.datetime "created_at", precision: 6, null: false
159
+ t.datetime "updated_at", precision: 6, null: false
160
+ t.bigint "form_id"
161
+ t.string "enable_callback", default: "Wf::Callbacks::EnableDefault"
162
+ t.string "fire_callback", default: "Wf::Callbacks::FireDefault"
163
+ t.string "notification_callback", default: "Wf::Callbacks::NotificationDefault"
164
+ t.string "time_callback", default: "Wf::Callbacks::TimeDefault"
165
+ t.string "deadline_callback", default: "Wf::Callbacks::DeadlineDefault"
166
+ t.string "hold_timeout_callback", default: "Wf::Callbacks::HoldTimeoutDefault"
167
+ t.string "assignment_callback", default: "Wf::Callbacks::AssignmentDefault"
168
+ t.string "unassignment_callback", default: "Wf::Callbacks::UnassignmentDefault"
169
+ end
170
+
171
+ create_table "wf_users", comment: "For demo", force: :cascade do |t|
172
+ t.string "name"
173
+ t.datetime "created_at", precision: 6, null: false
174
+ t.datetime "updated_at", precision: 6, null: false
175
+ t.bigint "group_id"
176
+ end
177
+
178
+ create_table "wf_workflows", force: :cascade do |t|
179
+ t.string "name"
180
+ t.text "description"
181
+ t.boolean "is_valid", default: false
182
+ t.string "creator_id"
183
+ t.text "error_msg"
184
+ t.datetime "created_at", precision: 6, null: false
185
+ t.datetime "updated_at", precision: 6, null: false
186
+ end
187
+
188
+ create_table "wf_workitem_assignments", force: :cascade do |t|
189
+ t.bigint "party_id"
190
+ t.bigint "workitem_id"
191
+ t.datetime "created_at", precision: 6, null: false
192
+ t.datetime "updated_at", precision: 6, null: false
193
+ t.index %w[workitem_id party_id], name: "wf_wp_u", unique: true
194
+ end
195
+
196
+ create_table "wf_workitems", force: :cascade do |t|
197
+ t.bigint "case_id"
198
+ t.bigint "workflow_id"
199
+ t.bigint "transition_id"
200
+ t.string "targetable_type", comment: "point to type of Application target: Task or Issue or PullRequest or Project etc."
201
+ t.string "targetable_id", comment: "point to id of Application target: task_id or issue_id or pull_request_id or project_id etc."
202
+ t.integer "state", default: 0, comment: "0-enabled, 1-started, 2-canceled, 3-finished,4-overridden"
203
+ if /mysql/i.match?(ActiveRecord::Base.connection.adapter_name)
204
+ t.datetime "enabled_at", default: -> { "current_timestamp" }
205
+ elsif /postgre/i.match?(ActiveRecord::Base.connection.adapter_name)
206
+ t.datetime "enabled_at", default: -> { "timezone('utc'::text, now())" }
207
+ end
208
+ t.datetime "started_at"
209
+ t.datetime "canceled_at"
210
+ t.datetime "finished_at"
211
+ t.datetime "overridden_at"
212
+ t.datetime "deadline", comment: ""
213
+ t.datetime "created_at", precision: 6, null: false
214
+ t.datetime "updated_at", precision: 6, null: false
215
+ t.datetime "trigger_time", comment: "set when transition_trigger=TIME & trigger_limit present"
216
+ t.string "holding_user_id", comment: "id of App user"
217
+ if /mysql/i.match?(ActiveRecord::Base.connection.adapter_name)
218
+ t.json "payload", comment: "store user input payload for workitem."
219
+ elsif /postgre/i.match?(ActiveRecord::Base.connection.adapter_name)
220
+ t.json "payload", default: {}, comment: "store user input payload for workitem."
221
+ end
222
+
223
+ t.index %w[state trigger_time], name: "index_wf_workitems_on_state_and_trigger_time"
224
+ end
225
+ end
226
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class InitSomeData < ActiveRecord::Migration[6.0]
4
+ def change
5
+ 5.times do |i|
6
+ Wf::Group.create(name: "Group#{i}")
7
+ end
8
+
9
+ 10.times do |i|
10
+ Wf::User.create(name: "User#{i}", group: Wf::Group.all.sample)
11
+ end
12
+
13
+ 10.times { |i| Wf::DemoTarget.create(name: "target #{i}") }
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateWfEntries < ActiveRecord::Migration[6.0]
4
+ def change
5
+ create_table :wf_entries, comment: "user input data for workitem with form." do |t|
6
+ t.string :user_id, index: true
7
+ t.bigint :workitem_id, index: true
8
+ if /mysql/i.match?(ActiveRecord::Base.connection.adapter_name)
9
+ t.json "payload"
10
+ elsif /postgre/i.match?(ActiveRecord::Base.connection.adapter_name)
11
+ t.json "payload", default: {}
12
+ end
13
+ t.timestamps
14
+ end
15
+ remove_column :wf_workitems, :payload
16
+ add_column :wf_field_values, :entry_id, :bigint, index: true
17
+ add_index :wf_entries, %i[workitem_id user_id], unique: true
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddTargetFieldNameForGuard < ActiveRecord::Migration[6.0]
4
+ def change
5
+ add_column :wf_guards, :target_attr_name, :string, comment: "point to workflow targetable's attribute"
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ # desc "Explaining what the task does"
3
+ # task :wf do
4
+ # # Task goes here
5
+ # end
data/lib/wf/engine.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wf
4
+ class Engine < ::Rails::Engine
5
+ isolate_namespace Wf
6
+ config.autoload_paths += %W[
7
+ #{config.root}/app/models/wf/concerns
8
+ ]
9
+ end
10
+ end
data/lib/wf/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wf
4
+ VERSION = "0.1.0"
5
+ end
data/lib/wf.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "wf/engine"
4
+
5
+ module Wf
6
+ # Your code goes here...
7
+ end