Skip to content

Commit

Permalink
Enhance compatibility with Redmine 5
Browse files Browse the repository at this point in the history
  • Loading branch information
nanego committed Nov 21, 2023
1 parent a864369 commit fa06da9
Show file tree
Hide file tree
Showing 27 changed files with 216 additions and 151 deletions.
2 changes: 1 addition & 1 deletion app/overrides/roles/permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
Deface::Override.new :virtual_path => 'roles/permissions',
:name => 'add-trackers-permissions-box',
:insert_after => ".permissions",
:partial => "roles/trackers_permissions.html"
:partial => "roles/trackers_permissions"
29 changes: 1 addition & 28 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
require 'redmine'
require 'redmine_tiny_features/hooks'

Rails.application.config.to_prepare do
require_dependency 'redmine_tiny_features/custom_field_enumeration_patch'
require_dependency 'redmine_tiny_features/custom_field_patch'
require_dependency 'redmine_tiny_features/field_format_patch'
require_dependency 'redmine_tiny_features/issue_query_patch'
require_dependency 'redmine_tiny_features/issue_patch'
require_dependency 'redmine_tiny_features/issue_status_patch'
require_dependency 'redmine_tiny_features/issue_statuses_helper_patch'
require_dependency 'redmine_tiny_features/issues_helper_patch'
require_dependency 'redmine_tiny_features/issues_controller_patch'
require_dependency 'redmine_tiny_features/journal_patch'
require_dependency 'redmine_tiny_features/mailer_patch'
require_dependency 'redmine_tiny_features/principal_patch'
require_dependency 'redmine_tiny_features/project_query_patch'
require_dependency 'redmine_tiny_features/project_patch'
require_dependency 'redmine_tiny_features/projects_helper_patch'
require_dependency 'redmine_tiny_features/queries_helper_patch'
require_dependency 'redmine_tiny_features/query_patch'
require_dependency 'redmine_tiny_features/queries_controller_patch'
require_dependency 'redmine_tiny_features/roles_controller_patch'
require_dependency 'redmine_tiny_features/tracker_patch'
require_dependency 'redmine_tiny_features/time_entry_query_patch'
require_dependency 'redmine_tiny_features/user_patch'
require_dependency 'redmine_tiny_features/users_helper_patch'
require_dependency 'redmine_tiny_features/user_preference_patch'
end
require_relative 'lib/redmine_tiny_features/hooks'

Redmine::Plugin.register :redmine_tiny_features do
name 'Redmine Tiny Features plugin'
Expand Down
14 changes: 11 additions & 3 deletions lib/redmine_tiny_features/custom_field_enumeration_patch.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
require_dependency 'custom_field_enumeration'

class CustomFieldEnumeration < ActiveRecord::Base
has_many :disabled_custom_field_enumerations, :dependent => :delete_all
end
module RedmineTinyFeatures
module CustomFieldEnumerationPatch
def self.included(base)
base.class_eval do
has_many :disabled_custom_field_enumerations, :dependent => :delete_all
end
end
end
end

CustomFieldEnumeration.send(:include, RedmineTinyFeatures::CustomFieldEnumerationPatch)
21 changes: 15 additions & 6 deletions lib/redmine_tiny_features/custom_field_patch.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
require_dependency 'custom_field'

class CustomField < ActiveRecord::Base
##### PATCH ,to call the destroy method of (CustomFieldEnumeration has :dependent => :delete_all)
has_many :enumerations, lambda {order(:position)},
:class_name => 'CustomFieldEnumeration',
:dependent => :destroy
end
module RedmineTinyFeatures
module CustomFieldPatch
def self.included(base)
base.class_eval do
has_many :enumerations, lambda {order(:position)},
:class_name => 'CustomFieldEnumeration',
:dependent => :destroy

safe_attributes("steps", "min_value", "max_value")
end
end
end
end

CustomField.send(:include, RedmineTinyFeatures::CustomFieldPatch)
97 changes: 49 additions & 48 deletions lib/redmine_tiny_features/field_format_patch.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'redmine/field_format'

module Redmine
module FieldFormat
module RedmineTinyFeatures
module FieldFormatPatch

class EnumerationFormat < RecordList
module EnumerationFormat
def possible_values_records(custom_field, object = nil)
enumerations = custom_field.enumerations.active
if object.present? && object.try(:project).present?
Expand All @@ -14,9 +14,9 @@ def possible_values_records(custom_field, object = nil)
end
end

class List < Base
module List
# Renders the edit tag as check box or radio tags
def check_box_edit_tag(view, tag_id, tag_name, custom_value, options={})
def check_box_edit_tag(view, tag_id, tag_name, custom_value, options = {})
opts = []
unless custom_value.custom_field.multiple? || custom_value.custom_field.is_required?
opts << ["(#{l(:label_none)})", '']
Expand Down Expand Up @@ -47,59 +47,60 @@ def check_box_edit_tag(view, tag_id, tag_name, custom_value, options={})
view.content_tag('span', s, options.merge(:class => css))
end
end
end
end

class RangeFormat < Numeric
add 'range'
Redmine::FieldFormat::EnumerationFormat.prepend RedmineTinyFeatures::FieldFormatPatch::EnumerationFormat
Redmine::FieldFormat::List.prepend RedmineTinyFeatures::FieldFormatPatch::List

self.form_partial = 'custom_fields/formats/range'
module Redmine::FieldFormat
class RangeFormat < Numeric
add 'range'

def label
"label_range"
end
self.form_partial = 'custom_fields/formats/range'

def label
"label_range"
end

field_attributes :steps, :min_value, :max_value

def edit_tag(view, tag_id, tag_name, custom_value, options = {})
edit_tag = view.range_field_tag(tag_name,
custom_value.value || custom_value.custom_field.default_value,
options.merge(id: tag_id,
min: custom_value.custom_field.min_value,
max: custom_value.custom_field.max_value,
step: custom_value.custom_field.steps))
edit_tag << view.content_tag(:span, custom_value.value, class: "range_selected_value")
edit_tag << view.javascript_tag(
<<~JAVASCRIPT
$(document).on("input change", "##{tag_id}", function(e) {
var value = $(this).val();
$(this).next('.range_selected_value').html(value);
})
field_attributes :steps, :min_value, :max_value

def edit_tag(view, tag_id, tag_name, custom_value, options = {})
edit_tag = view.range_field_tag(tag_name,
custom_value.value || custom_value.custom_field.default_value,
options.merge(id: tag_id,
min: custom_value.custom_field.min_value,
max: custom_value.custom_field.max_value,
step: custom_value.custom_field.steps))
edit_tag << view.content_tag(:span, custom_value.value, class: "range_selected_value")
edit_tag << view.javascript_tag(
<<~JAVASCRIPT
$(document).on("input change", "##{tag_id}", function(e) {
var value = $(this).val();
$(this).next('.range_selected_value').html(value);
})
JAVASCRIPT
)
edit_tag
end
)
edit_tag
end

def cast_single_value(custom_field, value, customized = nil)
value.to_i
end
def cast_single_value(custom_field, value, customized = nil)
value.to_i
end

def validate_single_value(custom_field, value, customized = nil)
errs = super
errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless /^[+-]?\d+$/.match?(value.to_s.strip)
errs
end
def validate_single_value(custom_field, value, customized = nil)
errs = super
errs << ::I18n.t('activerecord.errors.messages.not_a_number') unless /^[+-]?\d+$/.match?(value.to_s.strip)
errs
end

def query_filter_options(custom_field, query)
{ :type => :integer }
end
def query_filter_options(custom_field, query)
{ :type => :integer }
end

def group_statement(custom_field)
order_statement(custom_field)
end
def group_statement(custom_field)
order_statement(custom_field)
end

end
end

class CustomField < ActiveRecord::Base
safe_attributes("steps", "min_value", "max_value")
end
30 changes: 29 additions & 1 deletion lib/redmine_tiny_features/hooks.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module RedmineTinyFeatures
class Hooks < Redmine::Hook::ViewListener
#adds our css on each page
# adds our css on each page
def view_layouts_base_html_head(context)
stylesheet_link_tag("tiny_features", :plugin => "redmine_tiny_features") +
javascript_include_tag('redmine_tiny_features.js', plugin: 'redmine_tiny_features')
Expand All @@ -14,6 +14,34 @@ def controller_journals_edit_post(context = {})
end
end
end
end

class ModelHook < Redmine::Hook::Listener
def after_plugins_loaded(_context = {})
require_relative 'custom_field_enumeration_patch'
require_relative 'custom_field_patch'
require_relative 'field_format_patch'
require_relative 'issue_query_patch'
require_relative 'issue_patch'
require_relative 'issue_status_patch'
require_relative 'issue_statuses_helper_patch'
require_relative 'issues_helper_patch'
require_relative 'issues_controller_patch'
require_relative 'journal_patch'
require_relative 'mailer_patch'
require_relative 'principal_patch'
require_relative 'project_query_patch'
require_relative 'project_patch'
require_relative 'projects_helper_patch'
require_relative 'queries_helper_patch'
require_relative 'query_patch'
require_relative 'queries_controller_patch'
require_relative 'roles_controller_patch'
require_relative 'tracker_patch'
require_relative 'time_entry_query_patch'
require_relative 'user_patch'
require_relative 'users_helper_patch'
require_relative 'user_preference_patch'
end
end
end
6 changes: 5 additions & 1 deletion lib/redmine_tiny_features/issue_status_patch.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require_dependency 'issue_status'

module RedmineTinyFeatures::IssueStatusPatch

end

class IssueStatus < ActiveRecord::Base
safe_attributes 'color', 'status_ids' #,'suggested_status_ids'

Expand All @@ -26,4 +30,4 @@ def self.valid_color_list
def css_classes
"status-#{color}"
end
end
end
6 changes: 3 additions & 3 deletions lib/redmine_tiny_features/issue_statuses_helper_patch.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require_dependency 'issue_statuses_helper'

module RedmineTinyFeatures
module IssueStatusesHelper
module IssueStatusesHelperPatch
def valid_color_list
IssueStatus.valid_color_list.collect {|o| [l(o.last), o.first]}
end
end
end

IssueStatusesHelper.prepend RedmineTinyFeatures::IssueStatusesHelper
ActionView::Base.send(:include, IssueStatusesHelper)
IssueStatusesHelper.prepend RedmineTinyFeatures::IssueStatusesHelperPatch
ActionView::Base.send(:include, IssueStatusesHelper)
4 changes: 4 additions & 0 deletions lib/redmine_tiny_features/issues_controller_patch.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require_dependency 'issues_controller'

module RedmineTinyFeatures::IssuesControllerPatch

end

class IssuesController

append_before_action :find_optional_project_for_new_issue, :only => [:new]
Expand Down
4 changes: 2 additions & 2 deletions lib/redmine_tiny_features/issues_helper_patch.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_dependency 'issues_helper'

module RedmineTinyFeatures
module IssuesHelper
module IssuesHelperPatch

def show_detail(detail, no_html = false, options = {})
case detail.property
Expand Down Expand Up @@ -45,5 +45,5 @@ def actions_dropdown(&block)
end
end

IssuesHelper.prepend RedmineTinyFeatures::IssuesHelper
IssuesHelper.prepend RedmineTinyFeatures::IssuesHelperPatch
ActionView::Base.prepend IssuesHelper
5 changes: 3 additions & 2 deletions lib/redmine_tiny_features/journal_patch.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require_dependency 'journal'

class Journal < ActiveRecord::Base

module RedmineTinyFeatures::JournalPatch
# Adds a journal detail for a note that was removed
def journalize_note(journal)
details <<
Expand All @@ -19,3 +18,5 @@ def note_removed(journal)
end
end
end

Journal.prepend RedmineTinyFeatures::JournalPatch
4 changes: 4 additions & 0 deletions lib/redmine_tiny_features/mailer_patch.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require_dependency 'mailer'

module RedmineTinyFeatures::MailerPatch

end

class Mailer < ActionMailer::Base

# Sends reminders to issue assignees
Expand Down
4 changes: 4 additions & 0 deletions lib/redmine_tiny_features/principal_patch.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require_dependency 'principal'

module RedmineTinyFeatures::PrincipalPatch

end

class Principal < ActiveRecord::Base

# Principals that are members of a collection of projects with pagination
Expand Down
4 changes: 4 additions & 0 deletions lib/redmine_tiny_features/project_patch.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
require_dependency 'project'

module RedmineTinyFeatures::ProjectPatch

end

class Project < ActiveRecord::Base

has_many :disabled_custom_field_enumerations, :dependent => :delete_all
Expand Down
4 changes: 2 additions & 2 deletions lib/redmine_tiny_features/project_query_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ProjectQuery < Query
self.available_columns << QueryColumn.new(:module_enabled, :sortable => false, :default_order => 'asc')
end

module PluginRedmineTinyFeatures
module RedmineTinyFeatures
module ProjectQueryPatch

def initialize_available_filters
Expand Down Expand Up @@ -35,4 +35,4 @@ def sql_for_module_enabled_field(field, operator, value)
end
end

ProjectQuery.prepend PluginRedmineTinyFeatures::ProjectQueryPatch
ProjectQuery.prepend RedmineTinyFeatures::ProjectQueryPatch
6 changes: 3 additions & 3 deletions lib/redmine_tiny_features/projects_helper_patch.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_dependency 'projects_helper'

module PluginRedmineTinyFeatures
module ProjectsHelper
module RedmineTinyFeatures
module ProjectsHelperPatch
def project_settings_tabs
super.tap do |tabs|
if User.current.allowed_to?(:manage_project_enumerations, @project)
Expand All @@ -17,5 +17,5 @@ def project_settings_tabs
end
end

ProjectsHelper.prepend PluginRedmineTinyFeatures::ProjectsHelper
ProjectsHelper.prepend RedmineTinyFeatures::ProjectsHelperPatch
ActionView::Base.send(:include, ProjectsHelper)
Loading

0 comments on commit fa06da9

Please sign in to comment.