Module: Hydra::SubmissionWorkflow
- Included in:
- HydraHelperBehavior
- Defined in:
- lib/hydra/submission_workflow.rb
Overview
will move to lib/hydra/workflow/submission_workflow in release 5.x
Class Method Summary collapse
-
.included(base) ⇒ Object
When in this module is incuded in a controller (e.g. responds to :before_filter) add the validate_worflow_step method to the before filter chain.
Instance Method Summary collapse
-
#all_edit_partials ⇒ Object
Returns an array of all edit partials for the current content type.
-
#find_workflow_step_by_name(name) ⇒ Object
Convenience method to return an entire workflow step by name.
-
#first_step_in_workflow ⇒ Object
Convenience method to return the first step of a models workflow.
-
#get_af_model_from_params ⇒ Object
Reutrns a symbolized model name determined by parameters.
-
#get_af_model_from_solr ⇒ Object
Convenience method to return the model from the @document objects has_model_s field.
-
#last_step_in_workflow ⇒ Object
Convenience method to return the last step of a models workflow.
-
#model_config ⇒ Object
Will return the entire workflow configuration for the current model.
- #next_step(id) ⇒ Object
-
#next_step_in_workflow(current_step) ⇒ Object
Returns the name field for the next step in the configuration for the current model given the current step.
-
#previous_show_partials(current_step) ⇒ Object
Returns an array of display partials for steps previous to the given step.
-
#validate_workflow_step ⇒ Object
To be used in a before_filter.
-
#workflow_config ⇒ Object
The configuration hash.
-
#workflow_partial_for_step(step) ⇒ Object
Convenience method to return the partial for any given step by name.
Class Method Details
.included(base) ⇒ Object
When in this module is incuded in a controller (e.g. responds to :before_filter) add the validate_worflow_step method to the before filter chain.
8 9 10 |
# File 'lib/hydra/submission_workflow.rb', line 8 def self.included(base) base.before_filter :validate_workflow_step if base.respond_to?(:before_filter) end |
Instance Method Details
#all_edit_partials ⇒ Object
Returns an array of all edit partials for the current content type.
87 88 89 90 91 92 93 94 95 |
# File 'lib/hydra/submission_workflow.rb', line 87 def all_edit_partials edit_partials = [] unless model_config.nil? model_config.each do |config| edit_partials << config[:edit_partial] end end edit_partials end |
#find_workflow_step_by_name(name) ⇒ Object
Convenience method to return an entire workflow step by name.
68 69 70 |
# File 'lib/hydra/submission_workflow.rb', line 68 def find_workflow_step_by_name(name) model_config.find{|config| config[:name] == name.to_s} unless model_config.nil? end |
#first_step_in_workflow ⇒ Object
Convenience method to return the first step of a models workflow.
39 40 41 |
# File 'lib/hydra/submission_workflow.rb', line 39 def first_step_in_workflow model_config.first[:name] unless model_config.nil? end |
#get_af_model_from_params ⇒ Object
Reutrns a symbolized model name determined by parameters.
116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/hydra/submission_workflow.rb', line 116 def get_af_model_from_params if params.has_key?(:content_type) return params[:content_type].pluralize.to_sym elsif params[:id] begin af = ActiveFedora::Base.load_instance_from_solr(params[:id]) return "#{ActiveFedora::ContentModel.known_models_for( af ).first}".underscore.pluralize.to_sym rescue ActiveFedora::ObjectNotFoundError => e nil end end end |
#get_af_model_from_solr ⇒ Object
Convenience method to return the model from the @document objects has_model_s field.
130 131 132 |
# File 'lib/hydra/submission_workflow.rb', line 130 def get_af_model_from_solr @document[:has_model_s].first.gsub("info:fedora/afmodel:","").underscore.pluralize.to_sym end |
#last_step_in_workflow ⇒ Object
Convenience method to return the last step of a models workflow.
44 45 46 |
# File 'lib/hydra/submission_workflow.rb', line 44 def last_step_in_workflow model_config.last[:name] unless model_config.nil? end |
#model_config ⇒ Object
Will return the entire workflow configuration for the current model. We determing model first by seeing the @document object is a SolrDocument. If it is we will determing from the has_model_s field. Otherwise we will attempt to determine by the parameters (content_type directly passed or the id of an object).
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/hydra/submission_workflow.rb', line 100 def model_config # If we can get it directly from solr get it there. if !@document.nil? and @document.is_a?(SolrDocument) _model = get_af_model_from_solr return workflow_config[_model] if !_model.nil? and workflow_config.has_key?(_model) # If we can get the model from the params get it there. elsif params.has_key?(:content_type) or params.has_key?(:id) _model = get_af_model_from_params return workflow_config[_model] if workflow_config.has_key?(_model) and _model else nil #raise Hydra::WorkflowError end end |
#next_step(id) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/hydra/submission_workflow.rb', line 48 def next_step(id) return_params = {:wf_step=>next_step_in_workflow(params[:wf_step])} if params[:new_asset] return_params[:new_asset] = true end if params[:wf_step] == last_step_in_workflow or params.has_key?(:finish) return_params[:viewing_context] = "browse" return_params[:action] = "show" return_params.delete(:wf_step) return catalog_path(id, return_params) end return catalog_path(id,return_params) end |
#next_step_in_workflow(current_step) ⇒ Object
Returns the name field for the next step in the configuration for the current model given the current step.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hydra/submission_workflow.rb', line 24 def next_step_in_workflow(current_step) unless model_config.nil? if current_step.blank? # The first edit step won't have a wf_step param so we will need to pass it off to the 2nd step. return next_step_in_workflow(first_step_in_workflow) else model_config.each_with_index do |step,i| return model_config[i+1][:name] if step[:name] == current_step.to_s and step != model_config.last end end end nil end |
#previous_show_partials(current_step) ⇒ Object
Returns an array of display partials for steps previous to the given step.
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/hydra/submission_workflow.rb', line 73 def previous_show_partials(current_step) previous_partials = [] # if there is no step then we are on the first step of the workflow and don't need to display anything. return previous_partials if current_step.blank? unless model_config.nil? model_config.each do |config| break if config[:name] == current_step.to_s previous_partials << config[:show_partial] end end previous_partials end |
#validate_workflow_step ⇒ Object
To be used in a before_filter. This will call a method with the #af_model_#action_param_validation. If that method returns false then we will redirect back. The controller method doing the validation should set an appropriate flash message.
13 14 15 16 17 18 19 20 21 |
# File 'lib/hydra/submission_workflow.rb', line 13 def validate_workflow_step unless model_config.nil? # we may want to use the workflow name instead of or in addition to the action in the validation naming convention. validation_method = "#{get_af_model_from_params}_#{params[:action]}_validation".to_sym if self.respond_to?(validation_method) and self.send(validation_method) === false redirect_to :back end end end |
#workflow_config ⇒ Object
The configuration hash. This should probably live somewhere else and get read in so it can be properly configured at the application level. But for now it’s here.
135 136 137 |
# File 'lib/hydra/submission_workflow.rb', line 135 def workflow_config Hydra.config[:submission_workflow] end |
#workflow_partial_for_step(step) ⇒ Object
Convenience method to return the partial for any given step by name.
63 64 65 |
# File 'lib/hydra/submission_workflow.rb', line 63 def workflow_partial_for_step(step) find_workflow_step_by_name(step)[:edit_partial] end |