Custom Workflow plugin on 1.21 (#8672)

This commit is contained in:
Anton Argirov 2012-09-10 12:51:44 +07:00
parent ae48e0be6c
commit 4f477012f3
9 changed files with 16 additions and 12 deletions

View File

@ -29,7 +29,7 @@ First, you need to define your own custom workflow(s). We already included one,
Go to the *Administration* section, then select <b>Custom workflows</b>. A list of defined workflows will appear. Here you can create new workflow, update, reorder and delete existing workflows. The order of workflows specifies the order in which workflow scripts will be executed. Go to the *Administration* section, then select <b>Custom workflows</b>. A list of defined workflows will appear. Here you can create new workflow, update, reorder and delete existing workflows. The order of workflows specifies the order in which workflow scripts will be executed.
Then click the <b>Create a custom workflow</b> button. Enter a short name, full description and script itself. Below you will see two textareas. Fill one or both textareas by Ruby-language scripts that will be executed before and after saving the issue (on before_save and after_save callbacks respectively). Then click the <b>Create a custom workflow</b> button. Enter a short name and full description. Below you will see two textareas. Fill one or both textareas by Ruby-language scripts that will be executed before and after saving the issue (on before_save and after_save callbacks respectively).
Both scripts are executed in the context of the issue. So access properties and methods of the issue directly (or through keyword "self"). You can also raise exceptions by <b>raise WorkflowError, "Your message"</b>. If you change some properties of the issue before saving it, it will be revalidated then and additional validation errors can appear. Both scripts are executed in the context of the issue. So access properties and methods of the issue directly (or through keyword "self"). You can also raise exceptions by <b>raise WorkflowError, "Your message"</b>. If you change some properties of the issue before saving it, it will be revalidated then and additional validation errors can appear.
@ -87,9 +87,10 @@ Do not forget to check whether issue is just created. Here we create the new iss
== Compatibility == Compatibility
This plug-in is compatible with Redmine 1.4.x, 2.0.x, 2.1.x This plug-in is compatible with Redmine 1.2.x, 1.3.x, 1.4.x, 2.0.x, 2.1.x
== Changelog == Changelog
[0.0.3] Compatibility with 1.2.x, 1.3.x
[0.0.2] Added ability to define after_save script along with before_save, improved logging, changed context of executing script to the issue. [0.0.2] Added ability to define after_save script along with before_save, improved logging, changed context of executing script to the issue.
[0.0.1] Initial commit [0.0.1] Initial commit

View File

@ -19,13 +19,13 @@ class CustomWorkflow < ActiveRecord::Base
issue = Issue.new issue = Issue.new
issue.send :instance_variable_set, :@issue, issue # compatibility with 0.0.1 issue.send :instance_variable_set, :@issue, issue # compatibility with 0.0.1
begin begin
issue.instance_eval(before_save) issue.instance_eval(before_save) if respond_to?(:before_save) && before_save
rescue WorkflowError => e rescue WorkflowError => e
rescue Exception => e rescue Exception => e
errors.add :before_save, :invalid_script, :error => e errors.add :before_save, :invalid_script, :error => e
end end
begin begin
issue.instance_eval(after_save) issue.instance_eval(after_save) if respond_to?(:after_save) && after_save
rescue WorkflowError => e rescue WorkflowError => e
rescue Exception => e rescue Exception => e
errors.add :after_save, :invalid_script, :error => e errors.add :after_save, :invalid_script, :error => e

View File

@ -1,8 +1,8 @@
<h2><%= link_to l(:label_custom_workflow_plural), custom_workflows_path %> &#187; <%= @workflow %></h2> <h2><%= link_to l(:label_custom_workflow_plural), custom_workflows_path %> &#187; <%= @workflow %></h2>
<%= error_messages_for @workflow %> <%= error_messages_for 'workflow' %>
<% form = labelled_form_for @workflow do |f| %> <% form = form_for @workflow, :builder => (TabularFormBuilder rescue Redmine::Views::LabelledFormBuilder) do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %> <%= render :partial => 'form', :locals => {:f => f} %>
<%= submit_tag l(:button_save) %> <%= submit_tag l(:button_save) %>
<% end %> <% end %>

View File

@ -21,7 +21,7 @@
<tr class="<%= cycle("odd", "even") %>"> <tr class="<%= cycle("odd", "even") %>">
<td class="name"><%= link_to(workflow.name, edit_custom_workflow_path(workflow)) %></td> <td class="name"><%= link_to(workflow.name, edit_custom_workflow_path(workflow)) %></td>
<td><%= textilizable(workflow.description) %></td> <td><%= textilizable(workflow.description) %></td>
<td align="center"><%= reorder_links("custom_workflow", {:action => 'update', :id => workflow}, :put) %></td> <td align="center"><%= reorder_links("custom_workflow", {:action => 'update', :id => workflow}) %></td>
<td class="buttons"> <td class="buttons">
<%= link_to(l(:button_delete), workflow, :class => 'icon icon-del', :data => {:confirm => l(:text_are_you_sure)}, :confirm => l(:text_are_you_sure), :method => :delete) %> <%= link_to(l(:button_delete), workflow, :class => 'icon icon-del', :data => {:confirm => l(:text_are_you_sure)}, :confirm => l(:text_are_you_sure), :method => :delete) %>
</td> </td>

View File

@ -1,8 +1,8 @@
<h2><%= link_to l(:label_custom_workflow_plural), custom_workflows_path %> &#187; <%= l(:label_custom_workflow_new) %></h2> <h2><%= link_to l(:label_custom_workflow_plural), custom_workflows_path %> &#187; <%= l(:label_custom_workflow_new) %></h2>
<%= error_messages_for @workflow %> <%= error_messages_for 'workflow' %>
<% form = labelled_form_for @workflow do |f| %> <% form = form_for @workflow, :builder => (TabularFormBuilder rescue Redmine::Views::LabelledFormBuilder) do |f| %>
<%= render :partial => 'form', :locals => {:f => f} %> <%= render :partial => 'form', :locals => {:f => f} %>
<%= submit_tag l(:button_create) %> <%= submit_tag l(:button_create) %>
<% end %> <% end %>

View File

@ -1,9 +1,11 @@
if Redmine::VERSION::MAJOR >= 2 if Redmine::VERSION::MAJOR >= 2
RedmineApp::Application.routes.draw do RedmineApp::Application.routes.draw do
resources :custom_workflows resources :custom_workflows
post '/custom_workflows/:id', :to => 'custom_workflows#update'
end end
else else
ActionController::Routing::Routes.draw do |map| ActionController::Routing::Routes.draw do |map|
map.resources :custom_workflows map.resources :custom_workflows
map.connect '/custom_workflows/:id', :controller => 'custom_workflows', :action => 'update', :conditions => { :method => :post }
end end
end end

View File

@ -12,7 +12,7 @@ Set up a correlation between the start date, due date, done ratio and status of
To use this script properly, turn off "Use current date as start date for new issues" option in the settings as this script already do it own way. To use this script properly, turn off "Use current date as start date for new issues" option in the settings as this script already do it own way.
EOD EOD
if @issue.done_ratio_changed? if @issue.done_ratio_changed?
if @issue.done_ratio==100 && @issue.status_id=2 if @issue.done_ratio==100 && @issue.status_id==2
@issue.status_id=3 @issue.status_id=3
elsif [1,3,4].include?(@issue.status_id) && @issue.done_ratio<100 elsif [1,3,4].include?(@issue.status_id) && @issue.done_ratio<100
@issue.status_id=2 @issue.status_id=2

View File

@ -2,7 +2,7 @@ class AddAfterSaveToCustomWorkflows < ActiveRecord::Migration
def self.up def self.up
rename_column :custom_workflows, :script, :before_save rename_column :custom_workflows, :script, :before_save
change_column :custom_workflows, :before_save, :text, :null => false, :default => "" change_column :custom_workflows, :before_save, :text, :null => false, :default => ""
add_column :custom_workflows, :after_save, :text, :null => false, :default => "" add_column :custom_workflows, :after_save, :text, :null => false, :default => "", :after => :before_save
end end
def self.down def self.down
remove_column :custom_workflows, :after_save remove_column :custom_workflows, :after_save

View File

@ -1,3 +1,4 @@
require 'redmine'
require 'redmine_custom_workflows/hooks' require 'redmine_custom_workflows/hooks'
to_prepare = Proc.new do to_prepare = Proc.new do
@ -23,7 +24,7 @@ Redmine::Plugin.register :redmine_custom_workflows do
name 'Redmine Custom Workflow plugin' name 'Redmine Custom Workflow plugin'
author 'Anton Argirov' author 'Anton Argirov'
description 'Allows to create custom workflows for issues, defined in the plain Ruby language' description 'Allows to create custom workflows for issues, defined in the plain Ruby language'
version '0.0.1' version '0.0.3'
url 'http://redmine.academ.org' url 'http://redmine.academ.org'
menu :admin_menu, :custom_workflows, {:controller => 'custom_workflows', :action => 'index'}, :caption => :label_custom_workflow_plural menu :admin_menu, :custom_workflows, {:controller => 'custom_workflows', :action => 'index'}, :caption => :label_custom_workflow_plural