diff --git a/README.rdoc b/README.rdoc index ae57295..f3cb53e 100644 --- a/README.rdoc +++ b/README.rdoc @@ -101,7 +101,8 @@ This plug-in is compatible with Redmine 1.2.x, 1.3.x, 1.4.x, 2.x.x, 3.x.x (start Redmine 3.x.x branch: -[0.1.1] Import/export ability +[0.1.1] * Import/export ability + * Administrator can activate/deactivate workflows globally [0.1.0] Compatibility with Redmine 3.x, support of Redmine 2.x.x has dropped (for Redmine 2.x.x please use version 0.0.6) Redmine 2.x.x branch: diff --git a/app/controllers/custom_workflows_controller.rb b/app/controllers/custom_workflows_controller.rb index f5eb760..e9c57cf 100644 --- a/app/controllers/custom_workflows_controller.rb +++ b/app/controllers/custom_workflows_controller.rb @@ -2,7 +2,7 @@ class CustomWorkflowsController < ApplicationController layout 'admin' before_filter :require_admin - before_filter :find_workflow, :only => [:show, :edit, :update, :destroy, :export] + before_filter :find_workflow, :only => [:show, :edit, :update, :destroy, :export, :change_status] def index @workflows = CustomWorkflow.includes(:projects).all @@ -36,6 +36,7 @@ class CustomWorkflowsController < ApplicationController xml = params[:file].read begin @workflow = CustomWorkflow.import_from_xml(xml) + @workflow.active = false if @workflow.save flash[:notice] = l(:notice_successful_import) else @@ -63,6 +64,14 @@ class CustomWorkflowsController < ApplicationController end end + def change_status + respond_to do |format| + @workflow.update_attributes(:active => params[:active]) + flash[:notice] = l(:notice_successful_status_change) + format.html { redirect_to(custom_workflows_path) } + end + end + def update respond_to do |format| if @workflow.update_attributes(params[:custom_workflow]) diff --git a/app/models/custom_workflow.rb b/app/models/custom_workflow.rb index e0d6c82..2b3d66c 100644 --- a/app/models/custom_workflow.rb +++ b/app/models/custom_workflow.rb @@ -20,6 +20,7 @@ class CustomWorkflow < ActiveRecord::Base default_scope { order(:position => :asc) } scope :for_all, lambda { where(:is_for_all => true) } + scope :active, lambda { where(:active => true) } class << self def import_from_xml(xml) diff --git a/app/views/custom_workflows/_form.html.erb b/app/views/custom_workflows/_form.html.erb index 5a642a8..ffdc292 100644 --- a/app/views/custom_workflows/_form.html.erb +++ b/app/views/custom_workflows/_form.html.erb @@ -7,6 +7,7 @@

<%= f.text_area :description, :cols => 40, :rows => 5 %>

<%= f.check_box :is_for_all, :onclick => "checkAndDisable('custom_workflow_enabled_projects', this.checked);", :label => :field_enabled_for_all_projects %>

+

<%= f.check_box :active, :label => :field_custom_workflow_active %>

diff --git a/app/views/custom_workflows/index.html.erb b/app/views/custom_workflows/index.html.erb index d37f928..35f30af 100644 --- a/app/views/custom_workflows/index.html.erb +++ b/app/views/custom_workflows/index.html.erb @@ -21,7 +21,7 @@ <% @workflows.each do |workflow| %> - "> + <%= 'disabled' unless workflow.active? %>"> <%= link_to(workflow.name, edit_custom_workflow_path(workflow)) %> <%= textilizable(workflow.description) %> <%= mail_to workflow.author if workflow.author.present? %> @@ -36,6 +36,11 @@ <%= reorder_links("custom_workflow", {:action => 'update', :id => workflow}) %> + <% if workflow.active? %> + <%= link_to(l(:button_custom_workflow_deactivate), custom_workflow_status_path(workflow, :active => false), :class => 'icon icon-inactive', :method => :post) %> + <% else %> + <%= link_to(l(:button_custom_workflow_activate), custom_workflow_status_path(workflow, :active => true), :class => 'icon icon-active', :method => :post) %> + <% end %> <%= link_to(l(:label_custom_workflow_export), export_custom_workflow_path(workflow), :class => 'icon icon-export', :method => :get) %> <%= 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) %> diff --git a/app/views/projects/settings/_custom_workflow.html.erb b/app/views/projects/settings/_custom_workflow.html.erb index b3a4e8d..d7de42c 100644 --- a/app/views/projects/settings/_custom_workflow.html.erb +++ b/app/views/projects/settings/_custom_workflow.html.erb @@ -6,8 +6,17 @@ <% if CustomWorkflow.exists? %>
<% CustomWorkflow.all.each do |w| %> -
-
<%= textilizable(w.description) %>
+
+ +
+
<%= textilizable(w.description) %>
<% end %>
<% else %> diff --git a/assets/images/active.png b/assets/images/active.png new file mode 100644 index 0000000..a662809 Binary files /dev/null and b/assets/images/active.png differ diff --git a/assets/images/inactive.png b/assets/images/inactive.png new file mode 100644 index 0000000..6998b88 Binary files /dev/null and b/assets/images/inactive.png differ diff --git a/assets/stylesheets/style.css b/assets/stylesheets/style.css index 5260306..d6e4dce 100644 --- a/assets/stylesheets/style.css +++ b/assets/stylesheets/style.css @@ -2,6 +2,10 @@ background-image: url(../../../images/ticket_go.png); } +#tab-content-custom_workflows .disabled { + color: silver; +} + table.list.custom-workflows td { vertical-align: middle; } @@ -10,6 +14,10 @@ table.list.custom-workflows td.description { text-align: left; } +table.list.custom-workflows tr.disabled { + color: silver; +} + #custom_workflow_description, #custom_workflow_name { width: 98%; } @@ -26,3 +34,5 @@ table.list.custom-workflows td.description { .icon-export { background-image: url(../images/export.png); } .icon-import { background-image: url(../images/import.png); } +.icon-active { background-image: url(../images/active.png); } +.icon-inactive { background-image: url(../images/inactive.png); } diff --git a/config/locales/en.yml b/config/locales/en.yml index dbb4025..4b213cc 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -11,6 +11,8 @@ en: label_custom_workflow_import: "Import workflow" button_import: "Import" + button_custom_workflow_activate: "Activate" + button_custom_workflow_deactivate: "Deactivate" field_after_save: "Workflow script executable after saving the issue" field_before_save: "Workflow script executable before saving the issue" @@ -18,10 +20,12 @@ en: field_enabled_for_all_projects: "Enabled for all projects" field_custom_workflow_author: "Author's e-mail" field_custom_workflow_file: "Select the XML file previously exported process" + field_custom_workflow_active: "Active" field_custom_workflow: script: "Workflow script" notice_successful_import: "Custom workflow has successfully imported" + notice_successful_status_change: "Status has successfully changed" error_failed_import: "Error importing custom workflow (unknown format? please see log)" activerecord: @@ -36,4 +40,6 @@ en: text_custom_workflow_after_save_note: You can update or create related issues here. Note that this script will be also executed for the newly created issues. So make appropriate checks to prevent infinite recursion. text_custom_workflow_general_note: Both scripts are executed in the context of the issue like ordinary before_save and after_save callbacks. So use methods and properties of the issue directly (or through "self"). Instance variables (@variable) are also allowed and may be used if needed. text_no_enabled_projects: No projects - text_custom_workflow_author: Will be included in exported XML \ No newline at end of file + text_custom_workflow_author: Will be included in exported XML + text_custom_workflow_disabled: disabled by admin + text_custom_workflow_is_for_all: enabled for all projects \ No newline at end of file diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 0374270..b0a89df 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -11,6 +11,8 @@ ru: label_custom_workflow_import: "Импорт процесса" button_import: "Импортировать" + button_custom_workflow_activate: "Активировать" + button_custom_workflow_deactivate: "Деактивировать" field_after_save: "Сценарий выполняемый после сохранения задачи" field_before_save: "Сценарий выполняемый перед сохранением задачи" @@ -18,10 +20,12 @@ ru: field_enabled_for_all_projects: "Разрешен для всех проектов" field_custom_workflow_author: "E-Mail адрес автора" field_custom_workflow_file: "Выберите XML файл ранее экспортированного процесса" + field_custom_workflow_active: "Активен" field_custom_workflow: script: "Сценарий" notice_successful_import: "Рабочий процесс успешно импортирован" + notice_successful_status_change: "Статус успешно изменен" error_failed_import: "Ошибка импорта рабочего процесса (неверный формат? смотри журнал)" activerecord: @@ -36,4 +40,6 @@ ru: text_custom_workflow_after_save_note: Вы можете обновлять и создавать задачи (в том числе и связанные задачи) здесь. Обратите внимание, что данный сценарий будет также выполняться и для вновь создаваемых задач. Поэтому используйте дополнительные проверки, чтобы избежать бесконечной рекурсии. text_custom_workflow_general_note: Оба сценария исполняются в контексте задачи, как и обычные обратные вызовы before_save и after_save. Поэтому используйте методы и свойства задачи напрямую или через ключевое слово self. text_no_enabled_projects: Нет проектов - text_custom_workflow_author: Будет использован в XML файле при экспорте \ No newline at end of file + text_custom_workflow_author: Будет использован в XML файле при экспорте + text_custom_workflow_disabled: отключен администратором + text_custom_workflow_is_for_all: разрешен для всех проектов \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 14684bc..d5d0df0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,4 +3,5 @@ RedmineApp::Application.routes.draw do resources :custom_workflows post '/custom_workflows/:id', :to => 'custom_workflows#update' get '/custom_workflows/:id/export', :to => 'custom_workflows#export', :as => 'export_custom_workflow' + post '/custom_workflows/:id/change_status', :to => 'custom_workflows#change_status', :as => 'custom_workflow_status' end diff --git a/db/migrate/20150526134840_add_active_field_to_custom_workflows.rb b/db/migrate/20150526134840_add_active_field_to_custom_workflows.rb new file mode 100644 index 0000000..0dfb9bc --- /dev/null +++ b/db/migrate/20150526134840_add_active_field_to_custom_workflows.rb @@ -0,0 +1,5 @@ +class AddActiveFieldToCustomWorkflows < ActiveRecord::Migration + def change + add_column :custom_workflows, :active, :boolean, :null => false, :default => true + end +end diff --git a/lib/redmine_custom_workflows/project_patch.rb b/lib/redmine_custom_workflows/project_patch.rb index 80bc427..15e1215 100644 --- a/lib/redmine_custom_workflows/project_patch.rb +++ b/lib/redmine_custom_workflows/project_patch.rb @@ -13,7 +13,7 @@ module RedmineCustomWorkflows module InstanceMethods def enabled_custom_workflows - (CustomWorkflow.for_all + custom_workflows).uniq.sort + (CustomWorkflow.for_all + custom_workflows).select { |w| w.active? }.uniq.sort end end end