<%= f.label :dynamic_assign_by, class: "label" %>
<%= f.select :dynamic_assign_by_id, options_for_select(@workflow.transitions.where("id != ?", @transition.id).all.map{|x| [x.name, x.id]} || []), {include_blank: 'What other transition you want to do the assignment for this transition?'}, class: "form-control custom-select" %>
================================================
FILE: bin/rails
================================================
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails gems
# installed from the root of your application.
ENGINE_ROOT = File.expand_path('..', __dir__)
ENGINE_PATH = File.expand_path('../lib/wf/engine', __dir__)
APP_PATH = File.expand_path('../test/dummy/config/application', __dir__)
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
require 'rails/all'
require 'rails/engine/commands'
================================================
FILE: config/routes.rb
================================================
# frozen_string_literal: true
Wf::Engine.routes.draw do
resources :workflows do
resources :transitions
resources :places
resources :arcs
resources :cases
end
resources :arcs do
resources :guards
end
resources :forms do
resources :fields
end
resources :transitions do
resources :static_assignments
end
resources :workitems do
resources :workitem_assignments, only: %i[new create destroy]
resources :comments, only: %i[new create destroy]
member do
put :start
get :pre_finish
put :finish
end
end
root to: "workitems#index"
end
================================================
FILE: db/migrate/20200130201043_init.rb
================================================
# frozen_string_literal: true
class Init < ActiveRecord::Migration[6.0]
def change
create_table "wf_arcs", force: :cascade do |t|
t.bigint "workflow_id"
t.bigint "transition_id"
t.bigint "place_id"
t.integer "direction", default: 0, comment: "0-in, 1-out"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "guards_count", default: 0
end
create_table "wf_case_assignments", comment: "Manual per-case assignments of transition to parties", force: :cascade do |t|
t.bigint "case_id"
t.bigint "transition_id"
t.bigint "party_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index %w[case_id transition_id party_id], name: "wf_ctp_u", unique: true
end
create_table "wf_cases", force: :cascade do |t|
t.bigint "workflow_id"
t.string "targetable_type", comment: "point to target type of Application."
t.string "targetable_id", comment: "point to target ID of Application."
t.integer "state", default: 0, comment: "0-created, 1-active, 2-suspended, 3-canceled, 4-finished"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "wf_comments", force: :cascade do |t|
t.bigint "workitem_id"
t.string "user_id"
t.text "body"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["user_id"], name: "index_wf_comments_on_user_id"
t.index ["workitem_id"], name: "index_wf_comments_on_workitem_id"
end
create_table "wf_demo_targets", comment: "For demo, useless.", force: :cascade do |t|
t.string "name"
t.string "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "wf_field_values", force: :cascade do |t|
t.bigint "workflow_id"
t.bigint "transition_id"
t.bigint "form_id"
t.bigint "field_id"
t.text "value"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["field_id"], name: "index_wf_field_values_on_field_id"
t.index ["form_id"], name: "index_wf_field_values_on_form_id"
t.index ["transition_id"], name: "index_wf_field_values_on_transition_id"
t.index ["workflow_id"], name: "index_wf_field_values_on_workflow_id"
end
create_table "wf_fields", force: :cascade do |t|
t.string "name"
t.bigint "form_id"
t.integer "position", default: 0
t.integer "field_type", default: 0
t.string "field_type_name"
t.string "default_value"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["form_id"], name: "index_wf_fields_on_form_id"
end
create_table "wf_forms", force: :cascade do |t|
t.string "name"
t.text "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "wf_groups", comment: "For demo", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "wf_guards", force: :cascade do |t|
t.bigint "arc_id"
t.bigint "workflow_id"
t.string "fieldable_type"
t.string "fieldable_id"
t.string "op"
t.string "value"
t.string "exp"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["arc_id"], name: "index_wf_guards_on_arc_id"
t.index ["workflow_id"], name: "index_wf_guards_on_workflow_id"
end
create_table "wf_parties", comment: "for groups or roles or users or positions etc.", force: :cascade do |t|
t.string "partable_type"
t.string "partable_id"
t.string "party_name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index %w[partable_type partable_id], name: "index_wf_parties_on_partable_type_and_partable_id", unique: true
end
create_table "wf_places", force: :cascade do |t|
t.bigint "workflow_id"
t.string "name"
t.text "description"
t.integer "sort_order", default: 0
t.integer "place_type", default: 0, comment: "类型:0-start,1-normal,2-end"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "wf_tokens", force: :cascade do |t|
t.bigint "workflow_id"
t.bigint "case_id"
t.string "targetable_type"
t.string "targetable_id"
t.bigint "place_id"
t.integer "state", default: 0, comment: "0-free, 1-locked, 2-canceled, 3-consumed"
t.bigint "locked_workitem_id"
if /mysql/i.match?(ActiveRecord::Base.connection.adapter_name)
t.datetime "produced_at", default: -> { "current_timestamp" }
elsif /postgre/i.match?(ActiveRecord::Base.connection.adapter_name)
t.datetime "produced_at", default: -> { "timezone('utc'::text, now())" }
end
t.datetime "locked_at"
t.datetime "canceled_at"
t.datetime "consumed_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "wf_transition_static_assignments", comment: "pre assignment for transition", force: :cascade do |t|
t.bigint "party_id"
t.bigint "transition_id"
t.bigint "workflow_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index %w[transition_id party_id], name: "wf_tp_u", unique: true
end
create_table "wf_transitions", force: :cascade do |t|
t.string "name"
t.text "description"
t.bigint "workflow_id"
t.integer "sort_order", default: 0
t.integer "trigger_limit", comment: "use with timed trigger, after x minitues, trigger exec"
t.integer "trigger_type", default: 0, comment: "0-user,1-automatic, 2-message,3-time"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "form_id"
t.string "enable_callback", default: "Wf::Callbacks::EnableDefault"
t.string "fire_callback", default: "Wf::Callbacks::FireDefault"
t.string "notification_callback", default: "Wf::Callbacks::NotificationDefault"
t.string "time_callback", default: "Wf::Callbacks::TimeDefault"
t.string "deadline_callback", default: "Wf::Callbacks::DeadlineDefault"
t.string "hold_timeout_callback", default: "Wf::Callbacks::HoldTimeoutDefault"
t.string "assignment_callback", default: "Wf::Callbacks::AssignmentDefault"
t.string "unassignment_callback", default: "Wf::Callbacks::UnassignmentDefault"
end
create_table "wf_users", comment: "For demo", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "group_id"
end
create_table "wf_workflows", force: :cascade do |t|
t.string "name"
t.text "description"
t.boolean "is_valid", default: false
t.string "creator_id"
t.text "error_msg"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "wf_workitem_assignments", force: :cascade do |t|
t.bigint "party_id"
t.bigint "workitem_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index %w[workitem_id party_id], name: "wf_wp_u", unique: true
end
create_table "wf_workitems", force: :cascade do |t|
t.bigint "case_id"
t.bigint "workflow_id"
t.bigint "transition_id"
t.string "targetable_type", comment: "point to type of Application target: Task or Issue or PullRequest or Project etc."
t.string "targetable_id", comment: "point to id of Application target: task_id or issue_id or pull_request_id or project_id etc."
t.integer "state", default: 0, comment: "0-enabled, 1-started, 2-canceled, 3-finished,4-overridden"
if /mysql/i.match?(ActiveRecord::Base.connection.adapter_name)
t.datetime "enabled_at", default: -> { "current_timestamp" }
elsif /postgre/i.match?(ActiveRecord::Base.connection.adapter_name)
t.datetime "enabled_at", default: -> { "timezone('utc'::text, now())" }
end
t.datetime "started_at"
t.datetime "canceled_at"
t.datetime "finished_at"
t.datetime "overridden_at"
t.datetime "deadline", comment: ""
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.datetime "trigger_time", comment: "set when transition_trigger=TIME & trigger_limit present"
t.string "holding_user_id", comment: "id of App user"
if /mysql/i.match?(ActiveRecord::Base.connection.adapter_name)
t.json "payload", comment: "store user input payload for workitem."
elsif /postgre/i.match?(ActiveRecord::Base.connection.adapter_name)
t.json "payload", default: {}, comment: "store user input payload for workitem."
end
t.index %w[state trigger_time], name: "index_wf_workitems_on_state_and_trigger_time"
end
end
end
================================================
FILE: db/migrate/20200130201641_init_some_data.rb
================================================
# frozen_string_literal: true
class InitSomeData < ActiveRecord::Migration[6.0]
def change
5.times do |i|
Wf::Group.create(name: "Group#{i}")
end
10.times do |i|
Wf::User.create(name: "User#{i}", group: Wf::Group.all.sample)
end
10.times { |i| Wf::DemoTarget.create(name: "target #{i}") }
end
end
================================================
FILE: db/migrate/20200131200455_create_wf_entries.rb
================================================
# frozen_string_literal: true
class CreateWfEntries < ActiveRecord::Migration[6.0]
def change
create_table :wf_entries, comment: "user input data for workitem with form." do |t|
t.string :user_id, index: true
t.bigint :workitem_id, index: true
if /mysql/i.match?(ActiveRecord::Base.connection.adapter_name)
t.json "payload"
elsif /postgre/i.match?(ActiveRecord::Base.connection.adapter_name)
t.json "payload", default: {}
end
t.timestamps
end
remove_column :wf_workitems, :payload
add_column :wf_field_values, :entry_id, :bigint, index: true
add_index :wf_entries, %i[workitem_id user_id], unique: true
end
end
================================================
FILE: db/migrate/20200201001543_add_target_field_name_for_guard.rb
================================================
# frozen_string_literal: true
class AddTargetFieldNameForGuard < ActiveRecord::Migration[6.0]
def change
add_column :wf_guards, :target_attr_name, :string, comment: "point to workflow targetable's attribute"
end
end
================================================
FILE: db/migrate/20200212120019_remove_targetable_from_workitem.rb
================================================
# frozen_string_literal: true
class RemoveTargetableFromWorkitem < ActiveRecord::Migration[6.0]
def change
remove_column :wf_workitems, :targetable_id
remove_column :wf_workitems, :targetable_type
end
end
================================================
FILE: db/migrate/20200213085258_add_formable.rb
================================================
# frozen_string_literal: true
class AddFormable < ActiveRecord::Migration[6.0]
def change
add_column :wf_transitions, :form_type, :string, default: "Wf::Form"
add_index :wf_transitions, %i[form_type form_id]
end
end
================================================
FILE: db/migrate/20200213125753_add_form_id_for_entry.rb
================================================
# frozen_string_literal: true
class AddFormIdForEntry < ActiveRecord::Migration[6.0]
def change
add_column :wf_entries, :form_id, :bigint, index: true
end
end
================================================
FILE: db/migrate/20200213130900_remove_workflow_id_from_form_related.rb
================================================
# frozen_string_literal: true
class RemoveWorkflowIdFromFormRelated < ActiveRecord::Migration[6.0]
def change
remove_column :wf_field_values, :transition_id
remove_column :wf_field_values, :workflow_id
end
end
================================================
FILE: db/migrate/20200220070839_remove_unused_column.rb
================================================
# frozen_string_literal: true
class RemoveUnusedColumn < ActiveRecord::Migration[6.0]
def change
remove_column :wf_guards, :target_attr_name
end
end
================================================
FILE: db/migrate/20200220072512_add_sub_workflow.rb
================================================
# frozen_string_literal: true
class AddSubWorkflow < ActiveRecord::Migration[6.0]
def change
add_column :wf_transitions, :sub_workflow_id, :bigint, index: true
add_column :wf_cases, :started_by_workitem_id, :bigint, index: true, comment: "As a sub workflow instance, it is started by one workitem."
end
end
================================================
FILE: db/migrate/20200222150432_add_multi_instance.rb
================================================
# frozen_string_literal: true
class AddMultiInstance < ActiveRecord::Migration[6.0]
def change
add_column :wf_transitions, :multiple_instance, :boolean, default: false, comment: "multiple instance mode or not"
add_column :wf_transitions, :finish_condition, :string, comment: "set finish condition for parent workitem.", default: "Wf::MultipleInstances::AllFinish"
add_column :wf_workitems, :children_count, :integer, default: 0
add_column :wf_workitems, :children_finished_count, :integer, default: 0
add_column :wf_workitems, :forked, :boolean, default: false
add_column :wf_workitems, :parent_id, :bigint, comment: "parent workitem id"
end
end
================================================
FILE: db/migrate/20200226195134_add_dynamic_assign_by.rb
================================================
# frozen_string_literal: true
class AddDynamicAssignBy < ActiveRecord::Migration[6.0]
def change
add_column :wf_transitions, :dynamic_assign_by_id, :bigint, comment: "dynamic assign by other transition", index: true
end
end
================================================
FILE: lib/tasks/wf_tasks.rake
================================================
# frozen_string_literal: true
desc "Wf tasks"
task wf: :environment do
url = "http://service-technology.org/files/lola/lola-2.0.tar.gz"
path = Rails.root.join("tmp", "lola.tar.gz").to_s
puts "Downloading, wait!"
puts `wget http://service-technology.org/files/lola/lola-2.0.tar.gz -v -t0 -O #{path}` unless File.exist?(path)
puts `cd #{Rails.root.join("tmp")} && tar -zxvf lola.tar.gz`
puts `cd #{Rails.root.join("tmp/lola-2.0")} && ./configure`
puts `cd #{Rails.root.join("tmp/lola-2.0")} && make`
puts `cd #{Rails.root.join("tmp/lola-2.0")} && sudo make install`
puts `lola --help`
end
================================================
FILE: lib/wf/engine.rb
================================================
# frozen_string_literal: true
module Wf
class Engine < ::Rails::Engine
isolate_namespace Wf
config.autoload_paths += %W[
#{config.root}/app/models/wf/concerns
]
config.to_prepare do
require_dependency(Rails.root + "config/initializers/wf_config.rb")
rescue LoadError
puts("config/initializers/wf_config.rb not found.")
end
end
end
require "bootstrap"
require "bootstrap4-kaminari-views"
require "jquery-rails"
require "kaminari"
require "simple_command"
require "loaf"
require "graphviz"
require "rgl/adjacency"
require "rgl/dijkstra"
require "rgl/topsort"
require "rgl/traversal"
require "rgl/path"
require "active_record/connection_adapters/postgresql_adapter.rb"
require "select2-rails"
require "mini_racer"
================================================
FILE: lib/wf/version.rb
================================================
# frozen_string_literal: true
module Wf
VERSION = "0.2.5"
end
================================================
FILE: lib/wf.rb
================================================
# frozen_string_literal: true
require "wf/engine"
module Wf
class << self
attr_accessor :enable_callbacks
attr_accessor :fire_callbacks
attr_accessor :assignment_callbacks
attr_accessor :unassignment_callbacks
attr_accessor :notification_callbacks
attr_accessor :time_callbacks
attr_accessor :deadline_callbacks
attr_accessor :hold_timeout_callbacks
attr_accessor :form_class
attr_accessor :entry_class
attr_accessor :field_class
attr_accessor :user_class
attr_accessor :org_classes
attr_accessor :finish_conditions
attr_accessor :use_lola
end
self.enable_callbacks = ["Wf::Callbacks::EnableDefault"]
self.fire_callbacks = ["Wf::Callbacks::FireDefault"]
self.assignment_callbacks = ["Wf::Callbacks::AssignmentDefault"]
self.unassignment_callbacks = ["Wf::Callbacks::UnassignmentDefault"]
self.notification_callbacks = ["Wf::Callbacks::NotificationDefault"]
self.deadline_callbacks = ["Wf::Callbacks::DeadlineDefault"]
self.time_callbacks = ["Wf::Callbacks::TimeDefault"]
self.hold_timeout_callbacks = ["Wf::Callbacks::HoldTimeoutDefault"]
self.form_class = "::Wf::Form"
self.entry_class = "::Wf::Entry"
self.field_class = "::Wf::Field"
self.user_class = "::Wf::User"
self.org_classes = { group: "::Wf::Group" }
self.finish_conditions = ["Wf::MultipleInstances::AllFinish"]
self.use_lola = false
end
================================================
FILE: lola.md
================================================
## LoLA
LoLA is a Petri nets model-checking tool. To install LoLA, download lola-2.0.tar.gz from http://home.gna.org/service-tech/lola/index.html and extract it. You will need a working C++ compiler such as GCC or Clang. On Linux and OS X, LoLA can be compiled with ./configure and make. On Windows, you might need a Unix-like environment via Cygwin.
LoLA can answer reachability queries using the flag '-f' followed by 'REACHABLE' and a formula, e.g.:
lola petrinet.lola -f "REACHABLE DEADLOCK" # Tests whether a dead marking can be reached
lola petrinet.lola -f "REACHABLE (p = 1 AND q > 2)" # Tests whether a marking M such that
# M(p) = 1 and M(q) > 2 can be reached
lola petrinet.lola -f "REACHABLE (p + q = 1 OR r > 2)" # Tests whether a marking M such that
# M(p) + M(q) = 1 or M(r) > 2 can be reached
lola petrinet.lola -f "REACHABLE FIREABLE(t)" # Tests whether it is possible to reach a marking
# at which t is fireable
Positive reachability queries can be witnessed by a state and a path using flags -s and -p respectively.
The tool documentation can be found at http://download.gna.org/service-tech/lola/lola.pdf.
## Check Workflow Net
```
## generate lola format file.
# PLACE P1,P2,P3;
# MARKING P1;
# TRANSITION T1
# CONSUME P1:1;
# PRODUCE P3:1;
# TRANSITION T2
# CONSUME P3:1;
# PRODUCE P2:1;
## checking
# reachability of final marking
# lola /Users/hooopo/w/wf/test/dummy/tmp/1-1582990693.lola --formula="AGEF(P1 = 0 AND P3 = 0 AND P2 = 1)" --json=/Users/hooopo/w/wf/test/dummy/tmp/1-reachability_of_final_marking.json
# quasiliveness
# lola /Users/hooopo/w/wf/test/dummy/tmp/1-1582990693.lola --formula="AG NOT FIREABLE (T1)" --json=/Users/hooopo/w/wf/test/dummy/tmp/1-dead_transition_1.json
# lola /Users/hooopo/w/wf/test/dummy/tmp/1-1582990693.lola --formula="AG NOT FIREABLE (T2)" --json=/Users/hooopo/w/wf/test/dummy/tmp/1-dead_transition_2.json
# deadlock
# lola /Users/hooopo/w/wf/test/dummy/tmp/1-1582990693.lola --formula="EF (DEADLOCK AND (P2 = 0))" --json=/Users/hooopo/w/wf/test/dummy/tmp/1-deadlock.json
```
================================================
FILE: screenshots/.keep
================================================
================================================
FILE: test/controllers/wf/arcs_controller_test.rb
================================================
# frozen_string_literal: true
require "test_helper"
module Wf
class ArcsControllerTest < ActionDispatch::IntegrationTest
include Engine.routes.url_helpers
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/controllers/wf/cases_controller_test.rb
================================================
# frozen_string_literal: true
require "test_helper"
module Wf
class CasesControllerTest < ActionDispatch::IntegrationTest
include Engine.routes.url_helpers
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/controllers/wf/comments_controller_test.rb
================================================
# frozen_string_literal: true
require "test_helper"
module Wf
class CommentsControllerTest < ActionDispatch::IntegrationTest
include Engine.routes.url_helpers
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/controllers/wf/fields_controller_test.rb
================================================
# frozen_string_literal: true
require "test_helper"
module Wf
class FieldsControllerTest < ActionDispatch::IntegrationTest
include Engine.routes.url_helpers
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/controllers/wf/forms_controller_test.rb
================================================
# frozen_string_literal: true
require "test_helper"
module Wf
class FormsControllerTest < ActionDispatch::IntegrationTest
include Engine.routes.url_helpers
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/controllers/wf/guards_controller_test.rb
================================================
# frozen_string_literal: true
require "test_helper"
module Wf
class GuardsControllerTest < ActionDispatch::IntegrationTest
include Engine.routes.url_helpers
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/controllers/wf/places_controller_test.rb
================================================
# frozen_string_literal: true
require "test_helper"
module Wf
class PlacesControllerTest < ActionDispatch::IntegrationTest
include Engine.routes.url_helpers
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/controllers/wf/static_assignments_controller_test.rb
================================================
# frozen_string_literal: true
require "test_helper"
module Wf
class StaticAssignmentsControllerTest < ActionDispatch::IntegrationTest
include Engine.routes.url_helpers
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/controllers/wf/transitions_controller_test.rb
================================================
# frozen_string_literal: true
require "test_helper"
module Wf
class TransitionsControllerTest < ActionDispatch::IntegrationTest
include Engine.routes.url_helpers
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/controllers/wf/workflows_controller_test.rb
================================================
# frozen_string_literal: true
require "test_helper"
module Wf
class WorkflowsControllerTest < ActionDispatch::IntegrationTest
include Engine.routes.url_helpers
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/controllers/wf/workitem_assignments_controller_test.rb
================================================
# frozen_string_literal: true
require "test_helper"
module Wf
class WorkitemAssignmentsControllerTest < ActionDispatch::IntegrationTest
include Engine.routes.url_helpers
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/controllers/wf/workitems_controller_test.rb
================================================
# frozen_string_literal: true
require "test_helper"
module Wf
class WorkitemsControllerTest < ActionDispatch::IntegrationTest
include Engine.routes.url_helpers
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/dummy/.ruby-version
================================================
ruby-3.1.1
================================================
FILE: test/dummy/Rakefile
================================================
# frozen_string_literal: true
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require_relative "config/application"
Rails.application.load_tasks
================================================
FILE: test/dummy/app/assets/config/manifest.js
================================================
//= link_tree ../images
//= link_directory ../stylesheets .css
//= link wf_manifest.js
================================================
FILE: test/dummy/app/assets/images/.keep
================================================
================================================
FILE: test/dummy/app/assets/stylesheets/application.css
================================================
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*/
================================================
FILE: test/dummy/app/channels/application_cable/channel.rb
================================================
# frozen_string_literal: true
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
================================================
FILE: test/dummy/app/channels/application_cable/connection.rb
================================================
# frozen_string_literal: true
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
================================================
FILE: test/dummy/app/controllers/application_controller.rb
================================================
# frozen_string_literal: true
class ApplicationController < ActionController::Base
def current_user
Wf::User.first
end
helper_method :current_user
end
================================================
FILE: test/dummy/app/controllers/concerns/.keep
================================================
================================================
FILE: test/dummy/app/helpers/application_helper.rb
================================================
# frozen_string_literal: true
module ApplicationHelper
end
================================================
FILE: test/dummy/app/javascript/packs/application.js
================================================
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require activestorage
//= require_tree .
================================================
FILE: test/dummy/app/jobs/application_job.rb
================================================
# frozen_string_literal: true
class ApplicationJob < ActiveJob::Base
# Automatically retry jobs that encountered a deadlock
# retry_on ActiveRecord::Deadlocked
# Most jobs are safe to ignore if the underlying records are no longer available
# discard_on ActiveJob::DeserializationError
end
================================================
FILE: test/dummy/app/mailers/application_mailer.rb
================================================
# frozen_string_literal: true
class ApplicationMailer < ActionMailer::Base
default from: "from@example.com"
layout "mailer"
end
================================================
FILE: test/dummy/app/models/application_record.rb
================================================
# frozen_string_literal: true
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
================================================
FILE: test/dummy/app/models/concerns/.keep
================================================
================================================
FILE: test/dummy/app/models/entry.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_entries
#
# id :integer not null, primary key
# user_id :string
# workitem_id :integer
# payload :json default("{}")
# created_at :datetime not null
# updated_at :datetime not null
#
class Entry < ApplicationRecord
belongs_to :form
belongs_to :user, class_name: Wf.user_class.to_s
belongs_to :workitem, class_name: "Wf::Workitem"
has_many :field_values
after_initialize do
self.payload = {} if payload.blank?
end
def json
field_values.includes(:field).map { |x| [x.field_id.to_i, { field_id: x.id.to_i, field_name: x.field.name, value: x.value_after_cast }] }.to_h
end
def update_payload!
update(payload: json)
end
end
================================================
FILE: test/dummy/app/models/field.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_fields
#
# id :integer not null, primary key
# name :string
# form_id :integer
# position :integer default("0")
# field_type :integer default("0")
# field_type_name :string
# default_value :string
# created_at :datetime not null
# updated_at :datetime not null
#
class Field < ApplicationRecord
belongs_to :form, touch: true
enum field_type: {
string: 0,
integer: 1,
boolean: 2,
date: 3,
datetime: 4,
decimal: 5,
float: 6,
json: 7,
text: 8,
"string[]": 20,
"integer[]": 21,
"date[]": 23,
"datetime[]": 24,
"decimal[]": 25,
"float[]": 26,
"json[]": 27,
"text[]": 28
}
# TODO: array type
def field_type_for_view
case field_type
when "string"
"text_field"
when "integer"
"number_field"
when "date"
"date_field"
when "datetime"
"datetime_field"
when "boolean"
"check_box"
when "text"
"text_area"
else
"text_field"
end
end
def array?
field_type.to_s.match(/^(\w+)(\[\])?$/)[2] == "[]"
end
delegate :cast, to: :type_for_cast
def type_for_cast
type = field_type.to_s.match(/^(\w+)(\[\])?$/)[1]
if array?
ActiveRecord::Type.lookup(type.to_sym, adapter: :postgresql, array: true)
else
ActiveRecord::Type.lookup(type.to_sym, adapter: :postgresql)
end
end
end
================================================
FILE: test/dummy/app/models/field_value.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_field_values
#
# id :integer not null, primary key
# workflow_id :integer
# transition_id :integer
# form_id :integer
# field_id :integer
# value :text
# created_at :datetime not null
# updated_at :datetime not null
# entry_id :integer
#
class FieldValue < ApplicationRecord
belongs_to :form
belongs_to :field
belongs_to :entry
def value_after_cast
ov = self[:value]
if field.array? && !ov.is_a?(Array)
v = begin
JSON.parse(ov)
rescue StandardError
[]
end
field.type_for_cast.cast(v)
else
field.type_for_cast.cast(ov)
end
end
def value=(v)
self[:value] = if field.array?
Array(v.as_json)
else
v
end
end
def value
value_after_cast
end
end
================================================
FILE: test/dummy/app/models/form.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_forms
#
# id :integer not null, primary key
# name :string
# description :text
# created_at :datetime not null
# updated_at :datetime not null
#
class Form < ApplicationRecord
has_many :fields, dependent: :destroy
has_many :entries
end
================================================
FILE: test/dummy/app/views/layouts/application.html.erb
================================================
Dummy
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= yield %>
================================================
FILE: test/dummy/app/views/layouts/mailer.html.erb
================================================
<%= yield %>
================================================
FILE: test/dummy/app/views/layouts/mailer.text.erb
================================================
<%= yield %>
================================================
FILE: test/dummy/bin/rails
================================================
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
================================================
FILE: test/dummy/bin/rake
================================================
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run
================================================
FILE: test/dummy/bin/setup
================================================
#!/usr/bin/env ruby
require 'fileutils'
# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
FileUtils.chdir APP_ROOT do
# This script is a way to setup or update your development environment automatically.
# This script is idempotent, so that you can run it at anytime and get an expectable outcome.
# Add necessary setup steps to this file.
puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
# puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml')
# FileUtils.cp 'config/database.yml.sample', 'config/database.yml'
# end
puts "\n== Preparing database =="
system! 'bin/rails db:prepare'
puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'
puts "\n== Restarting application server =="
system! 'bin/rails restart'
end
================================================
FILE: test/dummy/config/application.rb
================================================
# frozen_string_literal: true
require_relative "boot"
require "rails/all"
Bundler.require(*Rails.groups)
require "wf"
module Dummy
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 6.0
# Settings in config/environments/* take precedence over those specified here.
# Application configuration can go into files in config/initializers
# -- all .rb files in that directory are automatically loaded after loading
# the framework and any gems in your application.
end
end
================================================
FILE: test/dummy/config/boot.rb
================================================
# frozen_string_literal: true
# Set up gems listed in the Gemfile.
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", __dir__)
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
$LOAD_PATH.unshift File.expand_path("../../../lib", __dir__)
================================================
FILE: test/dummy/config/cable.yml
================================================
development:
adapter: async
test:
adapter: test
production:
adapter: redis
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
channel_prefix: dummy_production
================================================
FILE: test/dummy/config/database.yml
================================================
# PostgreSQL. Versions 9.3 and up are supported.
#
# Install the pg driver:
# gem install pg
# On macOS with Homebrew:
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
# On macOS with MacPorts:
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
# On Windows:
# gem install pg
# Choose the win32 build.
# Install PostgreSQL and put its /bin directory on your path.
#
# Configure Using Gemfile
# gem 'pg'
#
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: wf_dummy_development
# The specified database role being used to connect to postgres.
# To create additional roles in postgres see `$ createuser --help`.
# When left blank, postgres will use the default role. This is
# the same name as the operating system user that initialized the database.
#username: dummy
# The password associated with the postgres role (username).
#password:
# Connect on a TCP socket. Omitted by default since the client uses a
# domain socket that doesn't need configuration. Windows does not have
# domain sockets, so uncomment these lines.
#host: localhost
# The TCP port the server listens on. Defaults to 5432.
# If your server runs on a different port number, change accordingly.
#port: 5432
# Schema search path. The server defaults to $user,public
#schema_search_path: myapp,sharedapp,public
# Minimum log levels, in increasing order:
# debug5, debug4, debug3, debug2, debug1,
# log, notice, warning, error, fatal, and panic
# Defaults to warning.
#min_messages: notice
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: dummy_test
# As with config/credentials.yml, you never want to store sensitive information,
# like your database password, in your source code. If your source code is
# ever seen by anyone, they now have access to your database.
#
# Instead, provide the password as a unix environment variable when you boot
# the app. Read https://guides.rubyonrails.org/configuring.html#configuring-a-database
# for a full rundown on how to provide these environment variables in a
# production deployment.
#
# On Heroku and other platform providers, you may have a full connection URL
# available as an environment variable. For example:
#
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
#
# You can use this database configuration with:
#
# production:
# url: <%= ENV['DATABASE_URL'] %>
#
production:
<<: *default
database: dummy_production
username: dummy
password: <%= ENV['DUMMY_DATABASE_PASSWORD'] %>
================================================
FILE: test/dummy/config/environment.rb
================================================
# frozen_string_literal: true
# Load the Rails application.
require_relative "application"
# Initialize the Rails application.
Rails.application.initialize!
================================================
FILE: test/dummy/config/environments/development.rb
================================================
# frozen_string_literal: true
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Do not eager load code on boot.
config.eager_load = false
# Show full error reports.
config.consider_all_requests_local = true
# Enable/disable caching. By default caching is disabled.
# Run rails dev:cache to toggle caching.
if Rails.root.join("tmp", "caching-dev.txt").exist?
config.action_controller.perform_caching = true
config.action_controller.enable_fragment_cache_logging = true
config.cache_store = :memory_store
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{2.days.to_i}"
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
# Highlight code that triggered database queries in logs.
config.active_record.verbose_query_logs = true
# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true
# Suppress logger output for asset requests.
config.assets.quiet = true
# Raises error for missing translations.
# config.action_view.raise_on_missing_translations = true
# Use an evented file watcher to asynchronously detect changes in source code,
# routes, locales, etc. This feature depends on the listen gem.
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker
end
================================================
FILE: test/dummy/config/environments/production.rb
================================================
# frozen_string_literal: true
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true
# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
# config.require_master_key = true
# Disable serving static files from the `/public` folder by default since
# Apache or NGINX already handles this.
config.public_file_server.enabled = ENV["RAILS_SERVE_STATIC_FILES"].present?
# Compress CSS using a preprocessor.
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
# config.action_controller.asset_host = 'http://assets.example.com'
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :local
# Mount Action Cable outside main process or domain.
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
# Use the lowest log level to ensure availability of diagnostic information
# when problems arise.
config.log_level = :debug
# Prepend all log lines with the following tags.
config.log_tags = [:request_id]
# Use a different cache store in production.
# config.cache_store = :mem_cache_store
# Use a real queuing backend for Active Job (and separate queues per environment).
# config.active_job.queue_adapter = :resque
# config.active_job.queue_name_prefix = "dummy_production"
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new
# Use a different logger for distributed setups.
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
# Inserts middleware to perform automatic connection switching.
# The `database_selector` hash is used to pass options to the DatabaseSelector
# middleware. The `delay` is used to determine how long to wait after a write
# to send a subsequent read to the primary.
#
# The `database_resolver` class is used by the middleware to determine which
# database is appropriate to use based on the time delay.
#
# The `database_resolver_context` class is used by the middleware to set
# timestamps for the last write to the primary. The resolver uses the context
# class timestamps to determine how long to wait before reading from the
# replica.
#
# By default Rails will store a last write timestamp in the session. The
# DatabaseSelector middleware is designed as such you can define your own
# strategy for connection switching and pass that into the middleware through
# these configuration options.
# config.active_record.database_selector = { delay: 2.seconds }
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
# config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session
end
================================================
FILE: test/dummy/config/environments/test.rb
================================================
# frozen_string_literal: true
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
config.cache_classes = false
# Do not eager load code on boot. This avoids loading your whole application
# just for the purpose of running a single test. If you are using a tool that
# preloads Rails for running tests, you may have to set it to true.
config.eager_load = false
# Configure public file server for tests with Cache-Control for performance.
config.public_file_server.enabled = true
config.public_file_server.headers = {
"Cache-Control" => "public, max-age=#{1.hour.to_i}"
}
# Show full error reports and disable caching.
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.cache_store = :null_store
# Raise exceptions instead of rendering exception templates.
config.action_dispatch.show_exceptions = false
# Disable request forgery protection in test environment.
config.action_controller.allow_forgery_protection = false
# Store uploaded files on the local file system in a temporary directory.
config.active_storage.service = :test
config.action_mailer.perform_caching = false
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr
# Raises error for missing translations.
# config.action_view.raise_on_missing_translations = true
end
================================================
FILE: test/dummy/config/initializers/application_controller_renderer.rb
================================================
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# ActiveSupport::Reloader.to_prepare do
# ApplicationController.renderer.defaults.merge!(
# http_host: 'example.org',
# https: false
# )
# end
================================================
FILE: test/dummy/config/initializers/assets.rb
================================================
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = "1.0"
# Add additional assets to the asset load path.
# Rails.application.config.assets.paths << Emoji.images_path
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in the app/assets
# folder are already added.
# Rails.application.config.assets.precompile += %w( admin.js admin.css )
================================================
FILE: test/dummy/config/initializers/backtrace_silencers.rb
================================================
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
# Rails.backtrace_cleaner.remove_silencers!
================================================
FILE: test/dummy/config/initializers/content_security_policy.rb
================================================
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Define an application-wide content security policy
# For further information see the following documentation
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
# Rails.application.config.content_security_policy do |policy|
# policy.default_src :self, :https
# policy.font_src :self, :https, :data
# policy.img_src :self, :https, :data
# policy.object_src :none
# policy.script_src :self, :https
# policy.style_src :self, :https
# # Specify URI for violation reports
# # policy.report_uri "/csp-violation-report-endpoint"
# end
# If you are using UJS then enable automatic nonce generation
# Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16) }
# Set the nonce only to specific directives
# Rails.application.config.content_security_policy_nonce_directives = %w(script-src)
# Report CSP violations to a specified URI
# For further information see the following documentation:
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy-Report-Only
# Rails.application.config.content_security_policy_report_only = true
================================================
FILE: test/dummy/config/initializers/cookies_serializer.rb
================================================
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Specify a serializer for the signed and encrypted cookie jars.
# Valid options are :json, :marshal, and :hybrid.
Rails.application.config.action_dispatch.cookies_serializer = :json
================================================
FILE: test/dummy/config/initializers/filter_parameter_logging.rb
================================================
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Configure sensitive parameters which will be filtered from the log file.
Rails.application.config.filter_parameters += [:password]
================================================
FILE: test/dummy/config/initializers/inflections.rb
================================================
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format. Inflections
# are locale specific, and you may define rules for as many different
# locales as you wish. All of these examples are active by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person', 'people'
# inflect.uncountable %w( fish sheep )
# end
# These inflection rules are supported but not enabled by default:
# ActiveSupport::Inflector.inflections(:en) do |inflect|
# inflect.acronym 'RESTful'
# end
================================================
FILE: test/dummy/config/initializers/mime_types.rb
================================================
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
================================================
FILE: test/dummy/config/initializers/my_assignment_callback.rb
================================================
# frozen_string_literal: true
class MyAssignmentCallback
def perform(_workitem_id)
Wf::Party.all.sample(2)
end
end
Wf.assignment_callbacks = ["Wf::Callbacks::AssignmentDefault", "MyAssignmentCallback"]
================================================
FILE: test/dummy/config/initializers/wf_config.rb
================================================
# frozen_string_literal: true
# TODO: use setter
Wf.user_class = "::Wf::User"
Wf.org_classes = { group: "::Wf::Group" }
Wf.form_class = "Wf::Form"
Wf.entry_class = "Wf::Entry"
Wf.field_class = "Wf::Field"
================================================
FILE: test/dummy/config/initializers/wrap_parameters.rb
================================================
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
# This file contains settings for ActionController::ParamsWrapper which
# is enabled by default.
# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
ActiveSupport.on_load(:action_controller) do
wrap_parameters format: [:json]
end
# To enable root element in JSON for ActiveRecord objects.
# ActiveSupport.on_load(:active_record) do
# self.include_root_in_json = true
# end
================================================
FILE: test/dummy/config/locales/en.yml
================================================
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t 'hello'
#
# In views, this is aliased to just `t`:
#
# <%= t('hello') %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# The following keys must be escaped otherwise they will not be retrieved by
# the default I18n backend:
#
# true, false, on, off, yes, no
#
# Instead, surround them with single quotes.
#
# en:
# 'true': 'foo'
#
# To learn more, please read the Rails Internationalization guide
# available at https://guides.rubyonrails.org/i18n.html.
en:
hello: "Hello world"
================================================
FILE: test/dummy/config/mysql_database.yml
================================================
development:
prepared_statements: false
encoding: utf8mb4
socket: /tmp/mysql.sock
adapter: mysql2
database: petri_flow_dev
username: root
min_messages: warning
pool: 5
timeout: 5000
checkout_timeout: <%= ENV['CHECKOUT_TIMEOUT'] || 5 %>
test:
prepared_statements: false
encoding: utf8mb4
socket: /tmp/mysql.sock
adapter: mysql2
database: petri_flow_test
username: root
min_messages: warning
pool: 5
timeout: 5000
================================================
FILE: test/dummy/config/puma.rb
================================================
# frozen_string_literal: true
# Puma can serve each request in a thread from an internal thread pool.
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match
# the maximum value specified for Puma. Default is set to 5 threads for minimum
# and maximum; this matches the default thread size of Active Record.
#
max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count }
threads min_threads_count, max_threads_count
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
#
port ENV.fetch("PORT") { 3000 }
# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the `pidfile` that Puma will use.
pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" }
# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked web server processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory.
#
# preload_app!
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart
================================================
FILE: test/dummy/config/routes.rb
================================================
# frozen_string_literal: true
Rails.application.routes.draw do
mount Wf::Engine => "/wf"
end
================================================
FILE: test/dummy/config/spring.rb
================================================
# frozen_string_literal: true
Spring.watch(
".ruby-version",
".rbenv-vars",
"tmp/restart.txt",
"tmp/caching-dev.txt"
)
================================================
FILE: test/dummy/config/storage.yml
================================================
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
# Use rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
# service: S3
# access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
# secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
# region: us-east-1
# bucket: your_own_bucket
# Remember not to checkin your GCS keyfile to a repository
# google:
# service: GCS
# project: your_project
# credentials: <%= Rails.root.join("path/to/gcs.keyfile") %>
# bucket: your_own_bucket
# Use rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)
# microsoft:
# service: AzureStorage
# storage_account_name: your_account_name
# storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>
# container: your_container_name
# mirror:
# service: Mirror
# primary: local
# mirrors: [ amazon, google, microsoft ]
================================================
FILE: test/dummy/config.ru
================================================
# frozen_string_literal: true
# This file is used by Rack-based servers to start the application.
require_relative "config/environment"
run Rails.application
================================================
FILE: test/dummy/db/migrate/20200213081814_new_form.rb
================================================
# frozen_string_literal: true
class NewForm < ActiveRecord::Migration[6.0]
def change
create_table "field_values", force: :cascade do |t|
t.bigint "form_id"
t.bigint "field_id"
t.text "value"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "fields", force: :cascade do |t|
t.string "name"
t.bigint "form_id"
t.integer "position", default: 0
t.integer "field_type", default: 0
t.string "field_type_name"
t.string "default_value"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["form_id"], name: "index_fields_on_form_id"
end
create_table "forms", force: :cascade do |t|
t.string "name"
t.text "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table :entries do |t|
t.string :user_id, index: true
t.bigint :workitem_id, index: true
t.json "payload"
t.timestamps
end
add_index :entries, %i[workitem_id user_id], unique: true
end
end
================================================
FILE: test/dummy/db/migrate/20200213133942_add_form_id_in_entry1.rb
================================================
# frozen_string_literal: true
class AddFormIdInEntry1 < ActiveRecord::Migration[6.0]
def change
add_column :entries, :form_id, :bigint, index: true
end
end
================================================
FILE: test/dummy/db/migrate/20200214005535_add_entry_id_for_field_values1.rb
================================================
# frozen_string_literal: true
class AddEntryIdForFieldValues1 < ActiveRecord::Migration[6.0]
def change
add_column :field_values, :entry_id, :bigint, index: true
end
end
================================================
FILE: test/dummy/db/schema.rb
================================================
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `rails
# db:schema:load`. When creating a new database, `rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2020_02_26_195134) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "entries", force: :cascade do |t|
t.string "user_id"
t.bigint "workitem_id"
t.json "payload"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "form_id"
t.index ["user_id"], name: "index_entries_on_user_id"
t.index ["workitem_id", "user_id"], name: "index_entries_on_workitem_id_and_user_id", unique: true
t.index ["workitem_id"], name: "index_entries_on_workitem_id"
end
create_table "field_values", force: :cascade do |t|
t.bigint "form_id"
t.bigint "field_id"
t.text "value"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "entry_id"
end
create_table "fields", force: :cascade do |t|
t.string "name"
t.bigint "form_id"
t.integer "position", default: 0
t.integer "field_type", default: 0
t.string "field_type_name"
t.string "default_value"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["form_id"], name: "index_fields_on_form_id"
end
create_table "forms", force: :cascade do |t|
t.string "name"
t.text "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "wf_arcs", force: :cascade do |t|
t.bigint "workflow_id"
t.bigint "transition_id"
t.bigint "place_id"
t.integer "direction", default: 0, comment: "0-in, 1-out"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "guards_count", default: 0
end
create_table "wf_case_assignments", comment: "Manual per-case assignments of transition to parties", force: :cascade do |t|
t.bigint "case_id"
t.bigint "transition_id"
t.bigint "party_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["case_id", "transition_id", "party_id"], name: "wf_ctp_u", unique: true
end
create_table "wf_cases", force: :cascade do |t|
t.bigint "workflow_id"
t.string "targetable_type", comment: "point to target type of Application."
t.string "targetable_id", comment: "point to target ID of Application."
t.integer "state", default: 0, comment: "0-created, 1-active, 2-suspended, 3-canceled, 4-finished"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "started_by_workitem_id", comment: "As a sub workflow instance, it is started by one workitem."
end
create_table "wf_comments", force: :cascade do |t|
t.bigint "workitem_id"
t.string "user_id"
t.text "body"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["user_id"], name: "index_wf_comments_on_user_id"
t.index ["workitem_id"], name: "index_wf_comments_on_workitem_id"
end
create_table "wf_demo_targets", comment: "For demo, useless.", force: :cascade do |t|
t.string "name"
t.string "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "wf_entries", comment: "user input data for workitem with form.", force: :cascade do |t|
t.string "user_id"
t.bigint "workitem_id"
t.json "payload", default: {}
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "form_id"
t.index ["user_id"], name: "index_wf_entries_on_user_id"
t.index ["workitem_id", "user_id"], name: "index_wf_entries_on_workitem_id_and_user_id", unique: true
t.index ["workitem_id"], name: "index_wf_entries_on_workitem_id"
end
create_table "wf_field_values", force: :cascade do |t|
t.bigint "form_id"
t.bigint "field_id"
t.text "value"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "entry_id"
t.index ["field_id"], name: "index_wf_field_values_on_field_id"
t.index ["form_id"], name: "index_wf_field_values_on_form_id"
end
create_table "wf_fields", force: :cascade do |t|
t.string "name"
t.bigint "form_id"
t.integer "position", default: 0
t.integer "field_type", default: 0
t.string "field_type_name"
t.string "default_value"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["form_id"], name: "index_wf_fields_on_form_id"
end
create_table "wf_forms", force: :cascade do |t|
t.string "name"
t.text "description"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "wf_groups", comment: "For demo", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "wf_guards", force: :cascade do |t|
t.bigint "arc_id"
t.bigint "workflow_id"
t.string "fieldable_type"
t.string "fieldable_id"
t.string "op"
t.string "value"
t.string "exp"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["arc_id"], name: "index_wf_guards_on_arc_id"
t.index ["workflow_id"], name: "index_wf_guards_on_workflow_id"
end
create_table "wf_parties", comment: "for groups or roles or users or positions etc.", force: :cascade do |t|
t.string "partable_type"
t.string "partable_id"
t.string "party_name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["partable_type", "partable_id"], name: "index_wf_parties_on_partable_type_and_partable_id", unique: true
end
create_table "wf_places", force: :cascade do |t|
t.bigint "workflow_id"
t.string "name"
t.text "description"
t.integer "sort_order", default: 0
t.integer "place_type", default: 0, comment: "类型:0-start,1-normal,2-end"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "wf_tokens", force: :cascade do |t|
t.bigint "workflow_id"
t.bigint "case_id"
t.string "targetable_type"
t.string "targetable_id"
t.bigint "place_id"
t.integer "state", default: 0, comment: "0-free, 1-locked, 2-canceled, 3-consumed"
t.bigint "locked_workitem_id"
t.datetime "produced_at", default: -> { "timezone('utc'::text, now())" }
t.datetime "locked_at"
t.datetime "canceled_at"
t.datetime "consumed_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "wf_transition_static_assignments", comment: "pre assignment for transition", force: :cascade do |t|
t.bigint "party_id"
t.bigint "transition_id"
t.bigint "workflow_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["transition_id", "party_id"], name: "wf_tp_u", unique: true
end
create_table "wf_transitions", force: :cascade do |t|
t.string "name"
t.text "description"
t.bigint "workflow_id"
t.integer "sort_order", default: 0
t.integer "trigger_limit", comment: "use with timed trigger, after x minitues, trigger exec"
t.integer "trigger_type", default: 0, comment: "0-user,1-automatic, 2-message,3-time"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "form_id"
t.string "enable_callback", default: "Wf::Callbacks::EnableDefault"
t.string "fire_callback", default: "Wf::Callbacks::FireDefault"
t.string "notification_callback", default: "Wf::Callbacks::NotificationDefault"
t.string "time_callback", default: "Wf::Callbacks::TimeDefault"
t.string "deadline_callback", default: "Wf::Callbacks::DeadlineDefault"
t.string "hold_timeout_callback", default: "Wf::Callbacks::HoldTimeoutDefault"
t.string "assignment_callback", default: "Wf::Callbacks::AssignmentDefault"
t.string "unassignment_callback", default: "Wf::Callbacks::UnassignmentDefault"
t.string "form_type", default: "Wf::Form"
t.bigint "sub_workflow_id"
t.boolean "multiple_instance", default: false, comment: "multiple instance mode or not"
t.string "finish_condition", default: "Wf::MultipleInstances::AllFinish", comment: "set finish condition for parent workitem."
t.bigint "dynamic_assign_by_id", comment: "dynamic assign by other transition"
t.index ["form_type", "form_id"], name: "index_wf_transitions_on_form_type_and_form_id"
end
create_table "wf_users", comment: "For demo", force: :cascade do |t|
t.string "name"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.bigint "group_id"
end
create_table "wf_workflows", force: :cascade do |t|
t.string "name"
t.text "description"
t.boolean "is_valid", default: false
t.string "creator_id"
t.text "error_msg"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
end
create_table "wf_workitem_assignments", force: :cascade do |t|
t.bigint "party_id"
t.bigint "workitem_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["workitem_id", "party_id"], name: "wf_wp_u", unique: true
end
create_table "wf_workitems", force: :cascade do |t|
t.bigint "case_id"
t.bigint "workflow_id"
t.bigint "transition_id"
t.integer "state", default: 0, comment: "0-enabled, 1-started, 2-canceled, 3-finished,4-overridden"
t.datetime "enabled_at", default: -> { "timezone('utc'::text, now())" }
t.datetime "started_at"
t.datetime "canceled_at"
t.datetime "finished_at"
t.datetime "overridden_at"
t.datetime "deadline"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.datetime "trigger_time", comment: "set when transition_trigger=TIME & trigger_limit present"
t.string "holding_user_id", comment: "id of App user"
t.integer "children_count", default: 0
t.integer "children_finished_count", default: 0
t.boolean "forked", default: false
t.bigint "parent_id", comment: "parent workitem id"
t.index ["state", "trigger_time"], name: "index_wf_workitems_on_state_and_trigger_time"
end
end
================================================
FILE: test/dummy/db/seeds.rb
================================================
# frozen_string_literal: true
Wf::Workflow.destroy_all
Wf::Case.destroy_all
Wf::Transition.destroy_all
Wf::Place.destroy_all
Wf::Arc.destroy_all
Wf::Form.destroy_all
form = Wf.form_class.constantize.create(name: "From One")
name_field = form.fields.create!(name: :name, field_type: :string)
age_field = form.fields.create!(name: :age, field_type: :integer)
form2 = Wf.form_class.constantize.create(name: "From Two")
score_field = form2.fields.create!(name: :score, field_type: :integer)
proc do
seq = Wf::Workflow.create(name: "Seq Workflow")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p = seq.places.create!(place_type: :normal, name: "p")
t1 = seq.transitions.create!(name: "t1")
t2 = seq.transitions.create!(name: "t2")
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :out, transition: t1, place: p)
arc3 = seq.arcs.create!(direction: :in, transition: t2, place: p)
arc4 = seq.arcs.create!(direction: :out, transition: t2, place: e)
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with automatic transition")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p = seq.places.create!(place_type: :normal, name: "p")
t1 = seq.transitions.create!(name: "t1")
t2 = seq.transitions.create!(name: "t2", trigger_type: :automatic)
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :out, transition: t1, place: p)
arc3 = seq.arcs.create!(direction: :in, transition: t2, place: p)
arc4 = seq.arcs.create!(direction: :out, transition: t2, place: e)
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with timed transition")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p = seq.places.create!(place_type: :normal, name: "p")
t1 = seq.transitions.create!(name: "t1")
t2 = seq.transitions.create!(name: "t2", trigger_type: :time, trigger_limit: 1)
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :out, transition: t1, place: p)
arc3 = seq.arcs.create!(direction: :in, transition: t2, place: p)
arc4 = seq.arcs.create!(direction: :out, transition: t2, place: e)
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with timed split")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p = seq.places.create!(place_type: :normal, name: "p")
t1 = seq.transitions.create!(name: "t1")
t2 = seq.transitions.create!(name: "t2")
t3 = seq.transitions.create!(name: "t3", trigger_type: :time, trigger_limit: 1)
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :in, transition: t3, place: s)
arc3 = seq.arcs.create!(direction: :out, transition: t1, place: p)
arc4 = seq.arcs.create!(direction: :in, transition: t2, place: p)
arc5 = seq.arcs.create!(direction: :out, transition: t2, place: e)
arc6 = seq.arcs.create!(direction: :out, transition: t3, place: e)
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with guard")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p1 = seq.places.create!(place_type: :normal, name: "p1")
p2 = seq.places.create!(place_type: :normal, name: "p2")
t1 = seq.transitions.create!(name: "t1", form: form)
t2 = seq.transitions.create!(name: "t2")
t3 = seq.transitions.create!(name: "t3")
arc2 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc3 = seq.arcs.create!(direction: :out, transition: t1, place: p1)
arc3 = seq.arcs.create!(direction: :out, transition: t1, place: p2)
arc4 = seq.arcs.create!(direction: :in, transition: t2, place: p1)
arc5 = seq.arcs.create!(direction: :in, transition: t3, place: p2)
arc6 = seq.arcs.create!(direction: :out, transition: t2, place: e)
arc7 = seq.arcs.create!(direction: :out, transition: t3, place: e)
arc3.guards.create!(fieldable: age_field, op: ">".to_sym, value: 18)
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with parallel routing")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p1 = seq.places.create!(place_type: :normal, name: "p1")
p2 = seq.places.create!(place_type: :normal, name: "p2")
p3 = seq.places.create!(place_type: :normal, name: "p3")
p4 = seq.places.create!(place_type: :normal, name: "p4")
t1 = seq.transitions.create!(name: "t1", form: form)
t2 = seq.transitions.create!(name: "t2")
t3 = seq.transitions.create!(name: "t3")
t4 = seq.transitions.create!(name: "t4")
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :out, transition: t1, place: p1)
arc3 = seq.arcs.create!(direction: :out, transition: t1, place: p2)
arc4 = seq.arcs.create!(direction: :in, transition: t2, place: p1)
arc5 = seq.arcs.create!(direction: :in, transition: t3, place: p2)
arc6 = seq.arcs.create!(direction: :out, transition: t2, place: p3)
arc7 = seq.arcs.create!(direction: :out, transition: t3, place: p4)
arc8 = seq.arcs.create!(direction: :in, transition: t4, place: p3)
arc9 = seq.arcs.create!(direction: :in, transition: t4, place: p4)
arc10 = seq.arcs.create!(direction: :out, transition: t4, place: e)
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with iterative routing")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p = seq.places.create!(place_type: :normal, name: "p")
t1 = seq.transitions.create!(name: "t1", form: form)
t2 = seq.transitions.create!(name: "t2")
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :out, transition: t1, place: p)
arc3 = seq.arcs.create!(direction: :in, transition: t2, place: p)
arc4 = seq.arcs.create!(direction: :out, transition: t2, place: e)
arc5 = seq.arcs.create!(direction: :out, transition: t1, place: s)
arc5.guards.create!(fieldable: age_field, op: ">".to_sym, value: 18)
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with expression guard")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p1 = seq.places.create!(place_type: :normal, name: "p1")
p2 = seq.places.create!(place_type: :normal, name: "p2")
t1 = seq.transitions.create!(name: "t1", form: form)
t2 = seq.transitions.create!(name: "t2")
t3 = seq.transitions.create!(name: "t3")
arc2 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc3 = seq.arcs.create!(direction: :out, transition: t1, place: p1)
arc3 = seq.arcs.create!(direction: :out, transition: t1, place: p2)
arc4 = seq.arcs.create!(direction: :in, transition: t2, place: p1)
arc5 = seq.arcs.create!(direction: :in, transition: t3, place: p2)
arc6 = seq.arcs.create!(direction: :out, transition: t2, place: e)
arc7 = seq.arcs.create!(direction: :out, transition: t3, place: e)
exp = <<~JS
let age_great_than_18 = function(){
if (workitem.form.age > 18) {
return "Yes"
} else {
return "No"
}
};
age_great_than_18();
JS
arc3.guards.create!(exp: exp, op: "=".to_sym, value: "Yes")
end.call
proc do
sub_workflow = Wf::Workflow.where(name: "Seq Workflow").first
seq = Wf::Workflow.create(name: "Workflow with sub workflow")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p = seq.places.create!(place_type: :normal, name: "p")
t1 = seq.transitions.create!(name: "t1", sub_workflow: sub_workflow, trigger_type: :message)
t2 = seq.transitions.create!(name: "t2")
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :out, transition: t1, place: p)
arc3 = seq.arcs.create!(direction: :in, transition: t2, place: p)
arc4 = seq.arcs.create!(direction: :out, transition: t2, place: e)
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with multiple instances")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p = seq.places.create!(place_type: :normal, name: "p")
t1 = seq.transitions.create!(name: "t1", trigger_type: :user, multiple_instance: true, form: form2)
t2 = seq.transitions.create!(name: "t2")
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :out, transition: t1, place: p)
arc3 = seq.arcs.create!(direction: :in, transition: t2, place: p)
arc4 = seq.arcs.create!(direction: :out, transition: t2, place: e)
Wf::User.all.sample(3).each do |user|
t1.transition_static_assignments.create!(party: user.party)
end
end.call
proc do
seq = Wf::Workflow.create(name: "Workflow with AssigmentCallback")
s = seq.places.create!(place_type: :start, name: "start")
e = seq.places.create!(place_type: :end, name: "end")
p = seq.places.create!(place_type: :normal, name: "p")
t1 = seq.transitions.create!(name: "t1", assignment_callback: "MyAssignmentCallback")
t2 = seq.transitions.create!(name: "t2")
arc1 = seq.arcs.create!(direction: :in, transition: t1, place: s)
arc2 = seq.arcs.create!(direction: :out, transition: t1, place: p)
arc3 = seq.arcs.create!(direction: :in, transition: t2, place: p)
arc4 = seq.arcs.create!(direction: :out, transition: t2, place: e)
end.call
================================================
FILE: test/dummy/lib/assets/.keep
================================================
================================================
FILE: test/dummy/log/.keep
================================================
================================================
FILE: test/dummy/public/404.html
================================================
The page you were looking for doesn't exist (404)
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
If you are the application owner check the logs for more information.
================================================
FILE: test/dummy/public/422.html
================================================
The change you wanted was rejected (422)
The change you wanted was rejected.
Maybe you tried to change something you didn't have access to.
If you are the application owner check the logs for more information.
================================================
FILE: test/dummy/public/500.html
================================================
We're sorry, but something went wrong (500)
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
================================================
FILE: test/dummy/storage/.keep
================================================
================================================
FILE: test/fixtures/wf/case_assignments.yml
================================================
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
================================================
FILE: test/fixtures/wf/comments.yml
================================================
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
================================================
FILE: test/fixtures/wf/demo_targets.yml
================================================
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
================================================
FILE: test/fixtures/wf/entries.yml
================================================
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
================================================
FILE: test/fixtures/wf/field_values.yml
================================================
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
================================================
FILE: test/fixtures/wf/fields.yml
================================================
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
================================================
FILE: test/fixtures/wf/forms.yml
================================================
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
================================================
FILE: test/fixtures/wf/guards.yml
================================================
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
================================================
FILE: test/fixtures/wf/parties.yml
================================================
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
================================================
FILE: test/fixtures/wf/transition_static_assignments.yml
================================================
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
================================================
FILE: test/fixtures/wf/users.yml
================================================
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
================================================
FILE: test/fixtures/wf/workitem_assignments.yml
================================================
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
================================================
FILE: test/integration/navigation_test.rb
================================================
# frozen_string_literal: true
require "test_helper"
class NavigationTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
================================================
FILE: test/models/wf/case_assignment_test.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_case_assignments
#
# id :integer not null, primary key
# case_id :integer
# transition_id :integer
# party_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# frozen_string_literal: true
require "test_helper"
module Wf
class CaseAssignmentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/models/wf/comment_test.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_comments
#
# id :integer not null, primary key
# workitem_id :integer
# user_id :string
# body :text
# created_at :datetime not null
# updated_at :datetime not null
#
# frozen_string_literal: true
require "test_helper"
module Wf
class CommentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/models/wf/demo_target_test.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_demo_targets
#
# id :integer not null, primary key
# name :string
# description :string
# created_at :datetime not null
# updated_at :datetime not null
#
require "test_helper"
module Wf
class DemoTargetTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/models/wf/entry_test.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_entries
#
# id :integer not null, primary key
# user_id :string
# workitem_id :integer
# payload :json default("{}")
# created_at :datetime not null
# updated_at :datetime not null
# form_id :integer
#
require "test_helper"
module Wf
class EntryTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/models/wf/field_test.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_fields
#
# id :integer not null, primary key
# name :string
# form_id :integer
# position :integer default("0")
# field_type :integer default("0")
# field_type_name :string
# default_value :string
# created_at :datetime not null
# updated_at :datetime not null
#
require "test_helper"
module Wf
class FieldTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/models/wf/field_value_test.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_field_values
#
# id :integer not null, primary key
# form_id :integer
# field_id :integer
# value :text
# created_at :datetime not null
# updated_at :datetime not null
# entry_id :integer
#
require "test_helper"
module Wf
class FieldValueTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/models/wf/form_test.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_forms
#
# id :integer not null, primary key
# name :string
# description :text
# created_at :datetime not null
# updated_at :datetime not null
#
require "test_helper"
module Wf
class FormTest < ActiveSupport::TestCase
test "the truth" do
assert true
end
end
end
================================================
FILE: test/models/wf/guard_test.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_guards
#
# id :integer not null, primary key
# arc_id :integer
# workflow_id :integer
# fieldable_type :string
# fieldable_id :string
# op :string
# value :string
# exp :string
# created_at :datetime not null
# updated_at :datetime not null
#
require "test_helper"
module Wf
class GuardTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/models/wf/party_test.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_parties
#
# id :integer not null, primary key
# partable_type :string
# partable_id :string
# party_name :string
# created_at :datetime not null
# updated_at :datetime not null
#
require "test_helper"
module Wf
class PartyTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/models/wf/transition_static_assignment_test.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_transition_static_assignments
#
# id :integer not null, primary key
# party_id :integer
# transition_id :integer
# workflow_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
require "test_helper"
module Wf
class TransitionStaticAssignmentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/models/wf/user_test.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_users
#
# id :integer not null, primary key
# name :string
# created_at :datetime not null
# updated_at :datetime not null
# group_id :integer
#
require "test_helper"
module Wf
class UserTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/models/wf/wf_test.rb
================================================
# frozen_string_literal: true
require "test_helper"
module Wf
class WfTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/models/wf/workitem_assignment_test.rb
================================================
# frozen_string_literal: true
# == Schema Information
#
# Table name: wf_workitem_assignments
#
# id :integer not null, primary key
# party_id :integer
# workitem_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
require "test_helper"
module Wf
class WorkitemAssignmentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
end
================================================
FILE: test/test_helper.rb
================================================
# frozen_string_literal: true
# Configure Rails Environment
ENV["RAILS_ENV"] = "test"
require_relative "../test/dummy/config/environment"
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../test/dummy/db/migrate", __dir__)]
ActiveRecord::Migrator.migrations_paths << File.expand_path("../db/migrate", __dir__)
require "rails/test_help"
# Filter out the backtrace from minitest while preserving the one from other libraries.
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
# Load fixtures from the engine
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
ActiveSupport::TestCase.fixture_path = File.expand_path("fixtures", __dir__)
ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
ActiveSupport::TestCase.file_fixture_path = ActiveSupport::TestCase.fixture_path + "/files"
ActiveSupport::TestCase.fixtures :all
end
================================================
FILE: wf.gemspec
================================================
# frozen_string_literal: true
$LOAD_PATH.push File.expand_path("lib", __dir__)
# Maintain your gem's version:
require "wf/version"
# Describe your gem and declare its dependencies:
Gem::Specification.new do |spec|
spec.name = "petri_flow"
spec.version = Wf::VERSION
spec.authors = ["Hooopo Wang"]
spec.email = ["hoooopo@gmail.com"]
spec.homepage = "https://github.com/hooopo/petri_flow"
spec.summary = "Petri Net Workflow Engine for Ruby."
spec.description = "Petri Net Workflow Engine for Ruby."
spec.license = "MIT"
spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
spec.add_dependency "bootstrap", "~> 4.4.1"
spec.add_dependency "bootstrap4-kaminari-views"
spec.add_dependency "jquery-rails"
spec.add_dependency "kaminari"
spec.add_dependency "loaf"
spec.add_dependency "mini_racer"
spec.add_dependency "pg"
spec.add_dependency "rails"
spec.add_dependency "rgl"
spec.add_dependency "ruby-graphviz"
spec.add_dependency "select2-rails-2020"
spec.add_dependency "simple_command"
end