Skip to content
This repository was archived by the owner on Aug 31, 2018. It is now read-only.

Fix error when not selecting an action #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ test/dummy/log/*.log
test/dummy/tmp/
test/dummy/.sass-cache
spec/
.idea/
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
workflowable (0.0.1)
workflowable (1.0)
jbuilder
jquery-rails
nested_form
Expand All @@ -27,7 +27,7 @@ GEM
activerecord-deprecated_finders (~> 1.0.2)
activesupport (= 4.0.4)
arel (~> 4.0.0)
activerecord-deprecated_finders (1.0.3)
activerecord-deprecated_finders (1.0.4)
activesupport (4.0.4)
i18n (~> 0.6, >= 0.6.9)
minitest (~> 4.2)
Expand Down Expand Up @@ -64,10 +64,10 @@ GEM
rspec (>= 2.14, < 4.0)
hike (1.2.3)
i18n (0.6.9)
jbuilder (2.1.2)
jbuilder (2.3.1)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (3.1.1)
jquery-rails (3.1.3)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
listen (2.7.1)
Expand Down Expand Up @@ -138,7 +138,7 @@ GEM
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
slop (3.5.0)
sprockets (2.12.0)
sprockets (2.12.4)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
Expand Down
74 changes: 22 additions & 52 deletions app/models/workflowable/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,98 +16,68 @@
module Workflowable
class Action < ActiveRecord::Base
has_many :workflow_actions
has_many :workflows, :through=>:workflow_actions
has_many :workflows, :through => :workflow_actions
has_many :stage_actions
has_many :stages, :through=>:stage_actions
has_many :stages, :through => :stage_actions
validate :validate_action_plugin
validates :name, :uniqueness=>true
validates :name, :uniqueness => true

before_save :reject_blank_values


serialize :options, Hash

def reject_blank_values
options.each{|k,v| v.reject!{ |k,v| v.blank? }}
options.reject!{|k,v| v.blank?}
options.each { |k, v| v.reject! { |k, v| v.blank? } }
options.reject! { |k, v| v.blank? }
end

def validate_action_plugin
begin
if(Workflowable::Actions.constants.include?(action_plugin.to_sym))
#if(Workflowable::Actions::Action.subclasses.include?(("Workflowable::Actions::"+action_plugin).constantize))
return true
end
rescue
unless Workflowable::Actions.constants.include?(action_plugin.to_sym)
errors.add :action_plugin, "is invalid"
end
errors.add :action_plugin, "is invalid"
end

def autocomplete(field_type, value, options={}, workflow=nil, object=nil, current_stage=nil, next_stage=nil, user=nil)
("Workflowable::Actions::"+action_plugin).constantize.autocomplete(field_type, value, options, workflow, object, current_stage, next_stage, user)
"Workflowable::Actions::#{action_plugin}".constantize.autocomplete(field_type, value, options, workflow, object, current_stage, next_stage, user)
end


def run(options={}, workflow, object, current_stage, next_stage, user)
options ||={}
plugin = ("Workflowable::Actions::"+action_plugin).constantize#("Workflowable::Actions::" + self.action_plugin.to_s).constantize
plugin = "Workflowable::Actions::#{action_plugin}".constantize #("Workflowable::Actions::" + self.action_plugin.to_s).constantize
plugin.new(self.available_options(options), workflow, object, current_stage, next_stage, user).run

end


def validate_options(options={}, workflow=nil, object=nil, current_stage=nil, next_stage=nil, user=nil)
plugin = ("Workflowable::Actions::"+action_plugin).constantize#("Workflowable::Actions::" + self.action_plugin.to_s).constantize
results = plugin.new(self.available_options(options), workflow, object, current_stage, next_stage, user).validate_options

return results
plugin = "Workflowable::Actions::#{action_plugin}".constantize #("Workflowable::Actions::" + self.action_plugin.to_s).constantize
plugin.new(self.available_options(options), workflow, object, current_stage, next_stage, user).validate_options
end


def available_options(options={}, workflow=nil, object=nil, current_stage=nil, next_stage=nil, user=nil)
options ||={}

# value_options = options.with_indifferent_access.deep_dup.each{|k1,v1|
# v1.reject!{|k2,v2| k2!= "value" || v2.blank?};
# v1[:user_specified]=true;
# }
# default_options = options.with_indifferent_access.deep_dup.each{ |k1,v1|
# v1.reject!{|k2,v2| k2!= "default" || v2.blank? }
# }



value_options = options.with_indifferent_access.each{|k1,v1|
v1.reject{|k2,v2| k2 != "value" || v2.blank?};
v1[:user_specified]=true;
value_options = options.with_indifferent_access.each { |k1, v1|
v1.reject { |k2, v2| k2 != "value" || v2.blank? }
v1[:user_specified] = true
}



default_options = options.with_indifferent_access.each{ |k1,v1|
v1.reject{|k2,v2| k2 != "default" || v2.blank? }
default_options = options.with_indifferent_access.each { |k1, v1|
v1.reject { |k2, v2| k2 != "default" || v2.blank? }
}

options = self.options.with_indifferent_access.deep_merge(default_options)

options = value_options.with_indifferent_access.deep_merge(options)
if(action_plugin)
all_options = ("Workflowable::Actions::"+action_plugin).constantize.options(options, workflow, object, current_stage, next_stage, user)

if action_plugin.present?
"Workflowable::Actions::#{action_plugin}".constantize.options(options, workflow, object, current_stage, next_stage, user)
else
all_options = {}
{}
end


end

def action_plugin_options
("Workflowable::Actions::"+action_plugin).constantize.options
"Workflowable::Actions::#{action_plugin}".constantize.options
end


def action_plugin_name
("Workflowable::Actions::"+action_plugin).constantize.name
"Workflowable::Actions::#{action_plugin}".constantize.name
end

end
end