Skip to content

Commit

Permalink
Compatibility with Redmine 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
anteo committed May 8, 2015
1 parent e05a8a4 commit 37bedaa
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 51 deletions.
3 changes: 2 additions & 1 deletion README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ Do not forget to check whether issue is just created. Here we create the new iss

== Compatibility

This plug-in is compatible with Redmine 1.2.x, 1.3.x, 1.4.x, 2.x.x
This plug-in is compatible with Redmine 1.2.x, 1.3.x, 1.4.x, 2.x.x, 3.x.x (starting from version 0.1.0)

== Changelog

[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.5)
[0.0.5] Compatibility with latest versions of Redmine 2.x.x
[0.0.4] * Added ability to enable workflows globally for all projects. No need to enable 'Custom workflows' project module anymore. Just go to the 'Administration' -> 'Custom workflows' section and enable or disable your workflows in one place.
* Fixed bug with 'Status transition prohibited' when updating the issue status by the repository commit
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/custom_workflows_controller.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
class CustomWorkflowsController < ApplicationController
unloadable

layout 'admin'
before_filter :require_admin
before_filter :find_workflow, :only => [:show, :edit, :update, :destroy]

def index
@workflows = CustomWorkflow.find(:all, :include => [:projects])
@workflows = CustomWorkflow.includes(:projects).all
respond_to do |format|
format.html
end
Expand Down
10 changes: 3 additions & 7 deletions app/models/custom_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ def initialize(message)
end

class CustomWorkflow < ActiveRecord::Base
unloadable

attr_protected :id
has_and_belongs_to_many :projects
acts_as_list

default_scope :order => 'position ASC'
validates_presence_of :name
validates_uniqueness_of :name, :case_sensitive => false
validate :validate_syntax

if Gem::Version.new(Rails::VERSION::STRING) < Gem::Version.new("3.1.0")
named_scope :for_all, :conditions => {:is_for_all => true}
else
scope :for_all, where(:is_for_all => true)
end
default_scope { order(:position => :asc) }
scope :for_all, lambda { where(:is_for_all => true) }

def validate_syntax
issue = Issue.new
Expand Down
31 changes: 14 additions & 17 deletions app/views/custom_workflows/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

<div class="splitcontent">
<div class="splitcontentleft box">
<p><%= f.text_field :name, :required => true, :size => 50 %></p>

<p><%= f.text_area :description, :cols => 40, :rows => 5 %></p>
<p><label><%= f.check_box :is_for_all, :onclick => "checkAndDisable('custom_workflow_enabled_projects', this.checked);", :no_label => true %> <%= l(:field_enabled_for_all_projects) %></label></p>

<p>
<label><%= f.check_box :is_for_all, :onclick => "checkAndDisable('custom_workflow_enabled_projects', this.checked);", :no_label => true %> <%= l(:field_enabled_for_all_projects) %></label>
</p>
</div>

<div class="splitcontentright">
Expand Down Expand Up @@ -40,25 +43,19 @@
</fieldset>

<script type="text/javascript">
jQuery('#custom_workflow_before_save').taboverride(2, true);
jQuery('#custom_workflow_after_save').taboverride(2, true);
function checkAndDisable(id, checked) {
if (checked) {
jQuery('#'+id).find('input[type=checkbox]').attr('checked', true).attr('disabled', true);
} else {
jQuery('#'+id).find('input[type=checkbox]').removeAttr('checked').removeAttr('disabled');
jQuery('#custom_workflow_before_save').taboverride(2, true);
jQuery('#custom_workflow_after_save').taboverride(2, true);
function checkAndDisable(id, checked) {
if (checked) {
jQuery('#' + id).find('input[type=checkbox]').attr('checked', true).attr('disabled', true);
} else {
jQuery('#' + id).find('input[type=checkbox]').removeAttr('checked').removeAttr('disabled');
}
}
}
</script>

<%= wikitoolbar_for :custom_workflow_description %>
<% content_for :header_tags do %>
<% if (Redmine::VERSION::ARRAY <=> [2,1,0]) < 0 %>
<%= javascript_include_tag "jquery-1.8.1.min.js", :plugin => 'redmine_custom_workflows' %>
<script type="text/javascript">
jQuery.noConflict();
</script>
<% end %>
<%= javascript_include_tag "tab_override", :plugin => 'redmine_custom_workflows' %>
<%= javascript_include_tag "tab_override", :plugin => 'redmine_custom_workflows' %>
<% end %>
2 changes: 0 additions & 2 deletions assets/javascripts/jquery-1.8.1.min.js

This file was deleted.

20 changes: 15 additions & 5 deletions assets/stylesheets/style.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
#admin-menu a.custom-workflows {
background-image: url(../../../images/ticket_go.png);
background-image: url(../../../images/ticket_go.png);
}

table.list.custom-workflows td { vertical-align: middle; }
table.list.custom-workflows td {
vertical-align: middle;
}

#custom_workflow_description, #custom_workflow_name { width: 98%; }
#custom_workflow_description, #custom_workflow_name {
width: 98%;
}

#custom_workflow_before_save, #custom_workflow_after_save { width: 98%; font-size: 11px; }
#custom_workflow_before_save, #custom_workflow_after_save {
width: 98%;
font-size: 11px;
}

#custom_workflow_enabled_projects ul { max-height: 200px; overflow-y: auto; }
#custom_workflow_enabled_projects ul {
max-height: 200px;
overflow-y: auto;
}
2 changes: 1 addition & 1 deletion db/migrate/20120831064944_create_example_workflow.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

class CreateExampleWorkflow < ActiveRecord::Migration
def self.up
CustomWorkflow.create(:name => "Duration/Done Ratio/Status correlation", :description => <<EOD, :script => <<EOS)
CustomWorkflow.create!(:name => 'Duration/Done Ratio/Status correlation', :description => <<EOD, :script => <<EOS)
Set up a correlation between the start date, due date, done ratio and status of issues.
* If done ratio is changed to 100% and status is "In Process", status changes to "Resolved"
Expand Down
11 changes: 2 additions & 9 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'redmine'
require 'redmine_custom_workflows/hooks'

to_prepare = Proc.new do
Rails.application.config.to_prepare do
unless Project.include?(RedmineCustomWorkflows::ProjectPatch)
Project.send(:include, RedmineCustomWorkflows::ProjectPatch)
end
Expand All @@ -16,18 +16,11 @@
end
end

if Redmine::VERSION::MAJOR >= 2
Rails.configuration.to_prepare(&to_prepare)
else
require 'dispatcher'
Dispatcher.to_prepare(:redmine_custom_workflows, &to_prepare)
end

Redmine::Plugin.register :redmine_custom_workflows do
name 'Redmine Custom Workflow plugin'
author 'Anton Argirov'
description 'Allows to create custom workflows for issues, defined in the plain Ruby language'
version '0.0.5'
version '0.1.0'
url 'http://redmine.academ.org'

menu :admin_menu, :custom_workflows, {:controller => 'custom_workflows', :action => 'index'}, :caption => :label_custom_workflow_plural
Expand Down
7 changes: 3 additions & 4 deletions lib/redmine_custom_workflows/helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module RedmineCustomWorkflows
module Helper
unloadable

# Renders a tree of projects as a nested set of unordered lists
# The given collection may be a subset of the whole project tree
Expand All @@ -13,12 +12,12 @@ def custom_workflows_render_nested_projects(projects)
projects.sort_by(&:lft).each do |project|
# set the project environment to please macros.
@project = project
if (ancestors.empty? || project.is_descendant_of?(ancestors.last))
if ancestors.empty? || project.is_descendant_of?(ancestors.last)
s << "<ul class='projects #{ ancestors.empty? ? 'root' : nil}'>\n"
else
ancestors.pop
s << "</li>"
while (ancestors.any? && !project.is_descendant_of?(ancestors.last))
s << '</li>'
while ancestors.any? && !project.is_descendant_of?(ancestors.last)
ancestors.pop
s << "</ul></li>\n"
end
Expand Down
1 change: 0 additions & 1 deletion lib/redmine_custom_workflows/issue_patch.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module RedmineCustomWorkflows
module IssuePatch
unloadable

def self.included(base)
base.send(:include, InstanceMethods)
Expand Down
1 change: 0 additions & 1 deletion lib/redmine_custom_workflows/project_patch.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module RedmineCustomWorkflows
module ProjectPatch
unloadable

def self.included(base)
base.send :include, InstanceMethods
Expand Down
1 change: 0 additions & 1 deletion lib/redmine_custom_workflows/projects_helper_patch.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module RedmineCustomWorkflows
module ProjectsHelperPatch
unloadable

def self.included(base)
base.send(:include, InstanceMethods)
Expand Down

0 comments on commit 37bedaa

Please sign in to comment.