redmineup 1.1.1 → 1.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.gitlab-ci.yml +7 -18
- data/README.md +74 -153
- data/Rakefile +1 -1
- data/app/assets/images/icons.svg +9 -0
- data/app/assets/javascripts/consumer.js +37 -50
- data/app/assets/javascripts/consumer_worker.js +219 -0
- data/app/assets/javascripts/jquery.colorPicker.min.js +26 -0
- data/app/assets/javascripts/select2_helpers.js +12 -0
- data/app/assets/stylesheets/calendars.css +0 -3
- data/app/assets/stylesheets/redmineup.css +520 -0
- data/app/assets/stylesheets/select2.css +2 -2
- data/app/views/redmineup/_additional_assets.html.erb +1 -0
- data/app/views/redmineup/journals/_history.html.erb +33 -0
- data/config/locales/ar.yml +13 -0
- data/config/locales/az.yml +13 -0
- data/config/locales/bg.yml +13 -0
- data/config/locales/bs.yml +13 -0
- data/config/locales/ca.yml +13 -0
- data/config/locales/cs.yml +1 -0
- data/config/locales/da.yml +13 -0
- data/config/locales/de.yml +1 -0
- data/config/locales/el.yml +13 -0
- data/config/locales/en-GB.yml +14 -0
- data/config/locales/en.yml +1 -0
- data/config/locales/es-PA.yml +14 -0
- data/config/locales/es.yml +1 -0
- data/config/locales/et.yml +13 -0
- data/config/locales/eu.yml +13 -0
- data/config/locales/fa.yml +13 -0
- data/config/locales/fi.yml +13 -0
- data/config/locales/fr.yml +13 -0
- data/config/locales/gl.yml +13 -0
- data/config/locales/he.yml +13 -0
- data/config/locales/hr.yml +13 -0
- data/config/locales/hu.yml +13 -0
- data/config/locales/id.yml +13 -0
- data/config/locales/it.yml +13 -0
- data/config/locales/ja.yml +13 -0
- data/config/locales/ko.yml +13 -0
- data/config/locales/lt.yml +13 -0
- data/config/locales/lv.yml +13 -0
- data/config/locales/mk.yml +13 -0
- data/config/locales/mn.yml +13 -0
- data/config/locales/nl.yml +13 -0
- data/config/locales/no.yml +13 -0
- data/config/locales/pl.yml +13 -0
- data/config/locales/pt-BR.yml +13 -0
- data/config/locales/pt.yml +13 -0
- data/config/locales/ro.yml +13 -0
- data/config/locales/ru.yml +2 -1
- data/config/locales/sk.yml +13 -0
- data/config/locales/sl.yml +13 -0
- data/config/locales/sq.yml +13 -0
- data/config/locales/sr-YU.yml +13 -0
- data/config/locales/sr.yml +13 -0
- data/config/locales/sv.yml +13 -0
- data/config/locales/ta-IN.yml +13 -0
- data/config/locales/th.yml +13 -0
- data/config/locales/tr.yml +13 -0
- data/config/locales/uk.yml +13 -0
- data/config/locales/vi.yml +13 -0
- data/config/locales/zh-TW.yml +13 -0
- data/config/locales/zh.yml +13 -0
- data/config/routes.rb +4 -0
- data/doc/CHANGELOG +119 -24
- data/doc/active-record-mixins.md +156 -0
- data/doc/assets-money-and-utilities.md +71 -0
- data/doc/tagging-and-select2.md +115 -0
- data/lib/action_cable/connection/rup_connection.rb +17 -0
- data/lib/action_cable/server/rup_configuration.rb +1 -9
- data/lib/action_cable/server/rup_server.rb +8 -0
- data/lib/redmineup/acts_as_journalized/hook.rb +16 -0
- data/lib/redmineup/acts_as_journalized/journal_event.rb +30 -0
- data/lib/redmineup/acts_as_journalized/journal_patch.rb +87 -0
- data/lib/redmineup/acts_as_journalized/up_acts_as_journalized.rb +118 -0
- data/lib/redmineup/acts_as_taggable/tag.rb +13 -3
- data/lib/redmineup/acts_as_taggable/up_acts_as_taggable.rb +36 -28
- data/lib/redmineup/acts_as_viewed/up_acts_as_viewed.rb +8 -3
- data/lib/redmineup/currency/formatting.rb +1 -0
- data/lib/redmineup/engine.rb +14 -2
- data/lib/redmineup/helpers/datetime_helper.rb +23 -0
- data/lib/redmineup/helpers/external_assets_helper.rb +14 -6
- data/lib/redmineup/helpers/form_tag_helper.rb +44 -0
- data/lib/redmineup/helpers/journals_helper.rb +53 -0
- data/lib/redmineup/helpers/tags_helper.rb +108 -0
- data/lib/redmineup/helpers/test_helper.rb +12 -0
- data/lib/redmineup/hooks/views_layouts_hook.rb +1 -5
- data/lib/redmineup/money_helper.rb +10 -2
- data/lib/redmineup/patches/action_cable_base_patch.rb +13 -8
- data/lib/redmineup/patches/action_cable_patch.rb +3 -7
- data/lib/redmineup/patches/auto_completes_controller_patch.rb +17 -0
- data/lib/redmineup/patches/compatibility/routing_mapper_patch.rb +5 -18
- data/lib/redmineup/patches/compatibility/sprite_patch.rb +3 -9
- data/lib/redmineup/patches/compatibility_patch.rb +0 -6
- data/lib/redmineup/patches/liquid_patch.rb +13 -22
- data/lib/redmineup/version.rb +1 -1
- data/lib/redmineup.rb +38 -41
- data/redmineup.gemspec +1 -1
- data/test/acts_as_journalized/up_acts_as_journalized_test.rb +106 -0
- data/test/acts_as_taggable/tag_test.rb +12 -9
- data/test/acts_as_viewed/rup_acts_as_viewed_test.rb +12 -0
- data/test/currency_test.rb +7 -0
- data/test/locales_test.rb +12 -0
- data/test/models/journal.rb +38 -0
- data/test/models/journalized_thing.rb +5 -0
- data/test/redmine/acts_as_journalized/journalized_redmine_test.rb +264 -0
- data/test/schema.rb +18 -1
- data/test/tags_helper_view_test.rb +111 -0
- data/test/test_helper.rb +13 -12
- metadata +74 -5
- data/app/assets/stylesheets/money.css +0 -95
- data/lib/redmineup/patches/compatibility/application_controller_patch.rb +0 -32
- data/lib/redmineup/patches/compatibility/user_patch.rb +0 -21
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
module Redmineup
|
|
2
|
+
module ActsAsJournalized
|
|
3
|
+
module JournalPatch
|
|
4
|
+
def self.prepended(base)
|
|
5
|
+
base.extend(ClassMethods)
|
|
6
|
+
base.singleton_class.prepend(IssueOnlyVisible)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
module IssueOnlyVisible
|
|
10
|
+
def visible(*)
|
|
11
|
+
super.where(journalized_type: 'Issue')
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
module ClassMethods
|
|
16
|
+
def up_project_ids(options)
|
|
17
|
+
project = options[:project]
|
|
18
|
+
return [project.id] unless options.fetch(:with_subprojects, Setting.display_subprojects_issues?)
|
|
19
|
+
|
|
20
|
+
project.self_and_descendants.ids
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def visible_for(user = User.current, options = {})
|
|
24
|
+
conditions = Redmineup::ActsAsJournalized.journalized_classes.map do |klass|
|
|
25
|
+
raise ArgumentError, "#{klass.name} must define scope :visible" unless klass.respond_to?(:visible)
|
|
26
|
+
|
|
27
|
+
visible = klass.visible(user).reorder(nil)
|
|
28
|
+
visible = visible.where(klass.table_name => { project_id: up_project_ids(options) }) if options[:project] && klass.column_names.include?('project_id')
|
|
29
|
+
visible = visible.except(:eager_load).left_outer_joins(*visible.eager_load_values) if visible.eager_load_values.any?
|
|
30
|
+
sanitize_sql_array(
|
|
31
|
+
["#{table_name}.journalized_type = ? AND #{table_name}.journalized_id IN (#{visible.select(klass.arel_table[:id]).to_sql})",
|
|
32
|
+
klass.base_class.name]
|
|
33
|
+
)
|
|
34
|
+
end
|
|
35
|
+
conditions.empty? ? none : where(conditions.join(' OR '))
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def up_journalized?
|
|
40
|
+
journalized.respond_to?(:up_journalized?)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def up_start_blank
|
|
44
|
+
@attributes_before_change = {}
|
|
45
|
+
@custom_values_before_change = {}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def editable_by?(usr)
|
|
49
|
+
return super unless up_journalized?
|
|
50
|
+
|
|
51
|
+
permission = journalized.up_journalized_options[:edit_notes_permission]
|
|
52
|
+
return false unless permission && usr&.logged?
|
|
53
|
+
|
|
54
|
+
if permission.respond_to?(:call)
|
|
55
|
+
permission.call(self, usr)
|
|
56
|
+
else
|
|
57
|
+
usr.allowed_to?(permission, journalized.project)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def up_update_notes(usr, text)
|
|
62
|
+
return false unless editable_by?(usr)
|
|
63
|
+
|
|
64
|
+
self.notes = text
|
|
65
|
+
self.updated_by_id = usr.id if has_attribute?(:updated_by_id)
|
|
66
|
+
save
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def add_watcher
|
|
72
|
+
super unless up_journalized?
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def split_private_notes
|
|
76
|
+
up_journalized? || super
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def send_notification
|
|
80
|
+
return super unless up_journalized?
|
|
81
|
+
|
|
82
|
+
notifier = journalized.up_journalized_options[:notify]
|
|
83
|
+
notifier&.call(self) if notify?
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
module Redmineup
|
|
2
|
+
module ActsAsJournalized
|
|
3
|
+
EXCLUDED_ATTRIBUTES = %w(id created_on updated_on created_at updated_at lock_version).freeze
|
|
4
|
+
OPTION_KEYS = %i[association associations only except journalize_create activity notify edit_notes_permission detail_formatter].freeze
|
|
5
|
+
|
|
6
|
+
def self.registry
|
|
7
|
+
@registry ||= []
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.journalized_classes
|
|
11
|
+
registry.filter_map(&:safe_constantize)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.register_activity(klass)
|
|
15
|
+
return unless defined?(::Redmineup::JournalEvent)
|
|
16
|
+
|
|
17
|
+
activity = klass.up_journalized_options[:activity]
|
|
18
|
+
type = (activity[:type] || "#{klass.name.underscore}_journals").to_s
|
|
19
|
+
class_name = klass.name
|
|
20
|
+
::Redmineup::JournalEvent.acts_as_activity_provider(
|
|
21
|
+
type: type,
|
|
22
|
+
author_key: :user_id,
|
|
23
|
+
scope: -> { ::Redmineup::ActsAsJournalized.activity_scope(class_name.constantize) }
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.activity_scope(klass)
|
|
28
|
+
keys = Array(klass.up_journalized_options[:activity][:keys]).map(&:to_s)
|
|
29
|
+
scope = ::Redmineup::JournalEvent.preload(:user, :journalized).where(journalized_type: klass.base_class.name)
|
|
30
|
+
notes = "#{::Journal.table_name}.notes <> ''"
|
|
31
|
+
return scope.where(notes) if keys.empty?
|
|
32
|
+
|
|
33
|
+
details = ::JournalDetail.table_name
|
|
34
|
+
scope.joins("LEFT OUTER JOIN #{details} ON #{details}.journal_id = #{::Journal.table_name}.id")
|
|
35
|
+
.where("#{notes} OR (#{details}.property = 'attr' AND #{details}.prop_key IN (?))", keys).distinct
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.included(base)
|
|
39
|
+
base.extend(ClassMethods)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
module ClassMethods
|
|
43
|
+
def up_acts_as_journalized(options = {})
|
|
44
|
+
options.assert_valid_keys(*OPTION_KEYS)
|
|
45
|
+
if options[:activity] && !options[:activity][:url].respond_to?(:call)
|
|
46
|
+
raise ArgumentError, 'up_acts_as_journalized: activity needs :url lambda'
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class_attribute :up_journalized_options, instance_writer: false
|
|
50
|
+
self.up_journalized_options = options
|
|
51
|
+
|
|
52
|
+
has_many options.fetch(:association, :journals), as: :journalized, class_name: 'Journal', dependent: :destroy, inverse_of: :journalized
|
|
53
|
+
(options[:associations] || {}).each do |association, attributes|
|
|
54
|
+
attributes.each do |attribute|
|
|
55
|
+
define_method("#{association}_#{attribute}") { public_send(association)&.public_send(attribute) }
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
before_save :up_prepare_journal
|
|
59
|
+
after_save :up_save_journal
|
|
60
|
+
include InstanceMethods
|
|
61
|
+
include NoCustomFields unless method_defined?(:custom_field_values)
|
|
62
|
+
|
|
63
|
+
Redmineup::ActsAsJournalized.registry << name unless Redmineup::ActsAsJournalized.registry.include?(name)
|
|
64
|
+
Redmineup::ActsAsJournalized.register_activity(self) if options[:activity]
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
module NoCustomFields
|
|
69
|
+
def custom_field_values
|
|
70
|
+
[]
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
module InstanceMethods
|
|
75
|
+
def up_journalized?
|
|
76
|
+
true
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def init_journal(user = User.current, notes = '')
|
|
80
|
+
@current_journal ||= Journal.new(journalized: self, user: user, notes: notes).tap do
|
|
81
|
+
@tag_list = Redmineup::ActsAsTaggable::TagList.new(*@tag_list) if @tag_list
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def current_journal
|
|
86
|
+
@current_journal
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def clear_journal
|
|
90
|
+
@current_journal = nil
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def journalized_attribute_names
|
|
94
|
+
options = up_journalized_options
|
|
95
|
+
names = self.class.column_names - EXCLUDED_ATTRIBUTES - Array(options[:except]).map(&:to_s)
|
|
96
|
+
names = names.reject { |name| name.end_with?('_count') }
|
|
97
|
+
names &= Array(options[:only]).map(&:to_s) if options[:only]
|
|
98
|
+
names << 'tag_list' if respond_to?(:tag_list) && !Array(options[:except]).map(&:to_s).include?('tag_list')
|
|
99
|
+
names + (options[:associations] || {}).flat_map { |association, attributes| attributes.map { |attribute| "#{association}_#{attribute}" } }
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
private
|
|
103
|
+
|
|
104
|
+
def up_prepare_journal
|
|
105
|
+
current_journal.up_start_blank if current_journal && new_record? && up_journalized_options[:journalize_create]
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def up_save_journal
|
|
109
|
+
return unless current_journal
|
|
110
|
+
|
|
111
|
+
current_journal.save
|
|
112
|
+
clear_journal
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
ActiveRecord::Base.include Redmineup::ActsAsJournalized
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require 'digest/md5'
|
|
2
|
+
|
|
1
3
|
module Redmineup
|
|
2
4
|
module ActsAsTaggable #:nodoc:
|
|
3
5
|
class Tag < ActiveRecord::Base #:nodoc:
|
|
@@ -17,6 +19,10 @@ module Redmineup
|
|
|
17
19
|
where("LOWER(name) LIKE LOWER(?)", name).first || create(:name => name)
|
|
18
20
|
end
|
|
19
21
|
|
|
22
|
+
def self.color_from_name(str)
|
|
23
|
+
"##{Digest::MD5.hexdigest(str.to_s)[0..5]}"
|
|
24
|
+
end
|
|
25
|
+
|
|
20
26
|
def ==(object)
|
|
21
27
|
super || (object.is_a?(Tag) && name == object.name)
|
|
22
28
|
end
|
|
@@ -30,11 +36,15 @@ module Redmineup
|
|
|
30
36
|
end
|
|
31
37
|
|
|
32
38
|
def color
|
|
33
|
-
|
|
39
|
+
if self.class.column_names.include?('color')
|
|
40
|
+
db_color = read_attribute(:color)
|
|
41
|
+
return ('#' + "%06x" % db_color) unless db_color.nil?
|
|
42
|
+
end
|
|
43
|
+
self.class.color_from_name(name)
|
|
34
44
|
end
|
|
35
45
|
|
|
36
46
|
def color=(color)
|
|
37
|
-
write_attribute(:color, color.
|
|
47
|
+
write_attribute(:color, color.sub(/\A#/, '').hex) unless color.blank?
|
|
38
48
|
end
|
|
39
49
|
|
|
40
50
|
class << self
|
|
@@ -74,7 +84,7 @@ module Redmineup
|
|
|
74
84
|
having = 'COUNT(*) > 0'
|
|
75
85
|
having = [having, at_least, at_most].compact.join(' AND ')
|
|
76
86
|
group_by = "#{Tag.table_name}.id, #{Tag.table_name}.name"
|
|
77
|
-
|
|
87
|
+
group_by << ", #{Tag.table_name}.color" if column_names.include?('color')
|
|
78
88
|
|
|
79
89
|
select_condition = if self.column_names.include?('color')
|
|
80
90
|
"#{Tag.table_name}.id, #{Tag.table_name}.name, #{Tag.table_name}.color, COUNT(*) AS count"
|
|
@@ -52,6 +52,7 @@ module Redmineup
|
|
|
52
52
|
if !self.connection.table_exists?(tag_name_table)
|
|
53
53
|
self.connection.create_table(tag_name_table) do |t|
|
|
54
54
|
t.column :name, :string
|
|
55
|
+
t.column :color, :integer
|
|
55
56
|
end
|
|
56
57
|
end
|
|
57
58
|
|
|
@@ -64,6 +65,7 @@ module Redmineup
|
|
|
64
65
|
# You should make sure that the column created is
|
|
65
66
|
# long enough to store the required class names.
|
|
66
67
|
t.column :taggable_type, :string
|
|
68
|
+
t.column :color, :integer, default: nil
|
|
67
69
|
|
|
68
70
|
t.column :created_at, :datetime
|
|
69
71
|
end
|
|
@@ -82,16 +84,16 @@ module Redmineup
|
|
|
82
84
|
#
|
|
83
85
|
# E.g.: ActiveRecord::Base.add_tags_column(:tags, name: :color, type: :string, default: nil)
|
|
84
86
|
def add_tags_column(table_name = :tags, **options)
|
|
85
|
-
tag_column = options
|
|
87
|
+
tag_column = options
|
|
86
88
|
tag_column.assert_valid_keys(:name, :type, :default)
|
|
87
89
|
|
|
88
90
|
raise ArgumentError, "Table `#{table_name}' not found" unless self.connection.table_exists?(table_name)
|
|
89
91
|
|
|
90
92
|
self.table_name = table_name
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
return if connection.column_exists?(table_name, tag_column[:name])
|
|
94
|
+
|
|
95
|
+
connection.add_column table_name, tag_column[:name], tag_column[:type], default: tag_column[:default]
|
|
96
|
+
reset_column_information
|
|
95
97
|
end
|
|
96
98
|
|
|
97
99
|
# Remove the up_acts_as_taggable specific columns
|
|
@@ -127,42 +129,48 @@ module Redmineup
|
|
|
127
129
|
#Return all avalible tags for a project or global
|
|
128
130
|
#Example: Question.available_tags(:project => @project_id )
|
|
129
131
|
def available_tags(options = {})
|
|
130
|
-
projects = [[options[:project]], options[:projects]].flatten.compact
|
|
131
132
|
limit = options[:limit].to_i.zero? ? 30 : options[:limit].to_i
|
|
132
|
-
|
|
133
|
-
class_name = quote_string_value(base_class.name)
|
|
134
|
-
join = []
|
|
135
|
-
join << "JOIN #{Tagging.table_name} ON #{Tagging.table_name}.tag_id = #{Tag.table_name}.id "
|
|
136
|
-
join << "JOIN #{table_name} ON #{table_name}.id = #{Tagging.table_name}.taggable_id
|
|
137
|
-
AND #{Tagging.table_name}.taggable_type = #{class_name} "
|
|
138
|
-
if attribute_names.include?('project_id') && projects.any?
|
|
139
|
-
join << "JOIN #{Project.table_name} ON #{Project.table_name}.id = #{table_name}.project_id"
|
|
140
|
-
scope = scope.where("#{table_name}.project_id IN (%s)", projects.map(&:id).join(','))
|
|
141
|
-
end
|
|
133
|
+
counts_sql = Tag.connection.unprepared_statement { tagged_records_scope(options).to_sql }
|
|
142
134
|
|
|
143
|
-
|
|
135
|
+
scope = Tag.joins("JOIN (#{counts_sql}) tag_counts ON tag_counts.tag_id = #{Tag.table_name}.id")
|
|
136
|
+
scope = scope.select("#{Tag.table_name}.*, tag_counts.count AS count")
|
|
137
|
+
if options[:name_like].present?
|
|
144
138
|
scope = scope.where("LOWER(#{Tag.table_name}.name) LIKE LOWER(?)", "%#{options[:name_like]}%")
|
|
145
139
|
end
|
|
140
|
+
scope.order("#{Tag.table_name}.name").limit(limit)
|
|
141
|
+
end
|
|
146
142
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
143
|
+
# tag_id => number of visible taggables. Extension point for available_tags.
|
|
144
|
+
def tagged_records_scope(options = {})
|
|
145
|
+
projects = [[options[:project]], options[:projects]].flatten.compact
|
|
146
|
+
scope = Tagging.unscoped.
|
|
147
|
+
joins("JOIN #{table_name} ON #{table_name}.id = #{Tagging.table_name}.taggable_id").
|
|
148
|
+
where("#{Tagging.table_name}.taggable_type = ?", base_class.name).
|
|
149
|
+
group("#{Tagging.table_name}.tag_id").
|
|
150
|
+
select("#{Tagging.table_name}.tag_id, COUNT(DISTINCT #{Tagging.table_name}.taggable_id) AS count")
|
|
151
|
+
|
|
152
|
+
projects_joined = false
|
|
153
|
+
if attribute_names.include?('project_id') && projects.any?
|
|
154
|
+
scope = scope.joins("JOIN #{Project.table_name} ON #{Project.table_name}.id = #{table_name}.project_id").
|
|
155
|
+
where("#{table_name}.project_id IN (?)", projects.map(&:id))
|
|
156
|
+
projects_joined = true
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
if options[:open_only] && reflect_on_association(:status)&.klass == IssueStatus
|
|
160
|
+
scope = scope.joins("JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{table_name}.status_id").
|
|
161
|
+
where(IssueStatus.table_name => { is_closed: false })
|
|
162
|
+
end
|
|
150
163
|
|
|
151
164
|
if base_class.respond_to?(:visible_condition)
|
|
152
165
|
visible_condition = base_class.visible_condition(User.current)
|
|
153
|
-
if visible_condition.include?('project_id') &&
|
|
154
|
-
|
|
166
|
+
if visible_condition.include?('project_id') && !projects_joined
|
|
167
|
+
scope = scope.joins("JOIN #{Project.table_name} ON #{Project.table_name}.id = #{table_name}.project_id")
|
|
155
168
|
end
|
|
156
169
|
scope = scope.where(visible_condition)
|
|
157
170
|
end
|
|
158
|
-
scope = scope.joins(join.join(' '))
|
|
159
|
-
scope = scope.select("#{Tag.table_name}.*, COUNT(DISTINCT #{Tagging.table_name}.taggable_id) AS count")
|
|
160
|
-
scope = scope.group("#{Tag.table_name}.id, #{Tag.table_name}.name #{group_fields}")
|
|
161
|
-
scope = scope.having('COUNT(*) > 0')
|
|
162
|
-
scope = scope.order("#{Tag.table_name}.name")
|
|
163
|
-
scope = scope.limit(limit)
|
|
164
171
|
scope
|
|
165
172
|
end
|
|
173
|
+
|
|
166
174
|
# Returns an array of related tags.
|
|
167
175
|
# Related tags are all the other tags that are found on the models tagged with the provided tags.
|
|
168
176
|
#
|
|
@@ -113,8 +113,13 @@ module Redmineup
|
|
|
113
113
|
# Add to the User (or whatever the viewer is) a has_many viewings
|
|
114
114
|
viewer_as_class = viewer_class.constantize
|
|
115
115
|
return if viewer_as_class.instance_methods.include?('find_in_viewings')
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
# Subclasses loaded earlier (Person < User) keep their own association set, so add it to them as well.
|
|
117
|
+
([viewer_as_class] + viewer_as_class.descendants).each do |klass|
|
|
118
|
+
next if klass.reflect_on_association(:viewings)
|
|
119
|
+
|
|
120
|
+
klass.class_eval do
|
|
121
|
+
has_many :viewings, foreign_key: :viewer_id, class_name: viewing_class.to_s, dependent: :delete_all
|
|
122
|
+
end
|
|
118
123
|
end
|
|
119
124
|
end
|
|
120
125
|
end
|
|
@@ -235,7 +240,7 @@ module Redmineup
|
|
|
235
240
|
t.column :viewer_id, :integer
|
|
236
241
|
t.column :viewed_id, :integer
|
|
237
242
|
t.column :viewed_type, :string
|
|
238
|
-
t.column :ip, :string, :limit => '
|
|
243
|
+
t.column :ip, :string, :limit => '45'
|
|
239
244
|
t.column :created_at, :datetime
|
|
240
245
|
end
|
|
241
246
|
|
|
@@ -59,6 +59,7 @@ module Redmineup
|
|
|
59
59
|
decimal_part << '0' while decimal_part.length < (currency.decimal_places + 1)
|
|
60
60
|
decimal_part
|
|
61
61
|
end
|
|
62
|
+
formatted.sub!(/\..*/, '') if currency.decimal_places.zero?
|
|
62
63
|
formatted.gsub!(/\./, rules[:decimal_mark]) unless '.' == rules[:decimal_mark]
|
|
63
64
|
end
|
|
64
65
|
|
data/lib/redmineup/engine.rb
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
module Redmineup
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
class Engine < Rails::Engine
|
|
3
|
+
config.to_prepare do
|
|
4
|
+
next unless defined?(::Redmine::Plugin)
|
|
5
|
+
|
|
6
|
+
require 'auto_completes_controller'
|
|
7
|
+
|
|
8
|
+
require File.expand_path('../redmineup/patches/compatibility_patch', __dir__)
|
|
9
|
+
require File.expand_path('../redmineup/patches/auto_completes_controller_patch', __dir__)
|
|
10
|
+
|
|
11
|
+
require File.expand_path('../redmineup/hooks/views_layouts_hook', __dir__)
|
|
12
|
+
|
|
13
|
+
require File.expand_path('../redmineup/acts_as_journalized/hook', __dir__)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
4
16
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Redmineup
|
|
2
|
+
module DatetimeHelper
|
|
3
|
+
def convert_time_to_user_timezone(time)
|
|
4
|
+
if User.current.time_zone
|
|
5
|
+
time.in_time_zone(User.current.time_zone)
|
|
6
|
+
else
|
|
7
|
+
time.utc? ? time.localtime : time
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def convert_time_to_utc(time = Time.now)
|
|
12
|
+
return Time.now.utc if time.blank?
|
|
13
|
+
return time.utc if time.respond_to?(:utc)
|
|
14
|
+
|
|
15
|
+
time_zone = User.current.time_zone
|
|
16
|
+
return Time.parse(time).utc unless time_zone
|
|
17
|
+
|
|
18
|
+
Time.use_zone(time_zone) do
|
|
19
|
+
Time.zone.parse(time).utc
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -2,19 +2,27 @@ module Redmineup
|
|
|
2
2
|
module ExternalAssetsHelper
|
|
3
3
|
include ActionView::Helpers::JavaScriptHelper
|
|
4
4
|
|
|
5
|
+
def redmineup_assets
|
|
6
|
+
return if @redmineup_assets_included
|
|
7
|
+
|
|
8
|
+
@redmineup_assets_included = true
|
|
9
|
+
javascript_include_tag('consumer', plugin: GEM_NAME) +
|
|
10
|
+
javascript_include_tag('select2', plugin: GEM_NAME) +
|
|
11
|
+
javascript_include_tag('select2_helpers', plugin: GEM_NAME) +
|
|
12
|
+
javascript_include_tag('jquery.colorPicker.min', plugin: GEM_NAME) +
|
|
13
|
+
stylesheet_link_tag('redmineup', plugin: GEM_NAME) +
|
|
14
|
+
javascript_tag("window.redmineupWorkerUrl = #{asset_path('consumer_worker.js', plugin: GEM_NAME).to_json};")
|
|
15
|
+
end
|
|
16
|
+
|
|
5
17
|
def select2_assets
|
|
6
|
-
|
|
7
|
-
@select2_tag_included = true
|
|
8
|
-
javascript_include_tag('select2', plugin: GEM_NAME) +
|
|
9
|
-
stylesheet_link_tag('select2', plugin: GEM_NAME) +
|
|
10
|
-
javascript_include_tag('select2_helpers', plugin: GEM_NAME)
|
|
18
|
+
redmineup_assets
|
|
11
19
|
end
|
|
12
20
|
|
|
13
21
|
def chartjs_assets
|
|
14
22
|
return if @chartjs_tag_included
|
|
23
|
+
|
|
15
24
|
@chartjs_tag_included = true
|
|
16
25
|
javascript_include_tag('chart.min', plugin: GEM_NAME)
|
|
17
26
|
end
|
|
18
|
-
|
|
19
27
|
end
|
|
20
28
|
end
|
|
@@ -18,6 +18,7 @@ module Redmineup
|
|
|
18
18
|
# * <tt>:allow_clear</tt> Provides support for clearable selections. Default value false.
|
|
19
19
|
# * <tt>:min_input_length</tt> Minimum number of characters required to start a search. Default value 0.
|
|
20
20
|
# * <tt>:format_state</tt> Defines template of search results in the drop-down.
|
|
21
|
+
# * <tt>:on_select</tt> Global JS callback name bound to `select2:select` event.
|
|
21
22
|
# * <tt>:tags</tt> Used to enable tagging feature.
|
|
22
23
|
#
|
|
23
24
|
# <b>Note:</b> The HTML specification says when +multiple+ parameter passed to select and all options got deselected
|
|
@@ -49,6 +50,32 @@ module Redmineup
|
|
|
49
50
|
|
|
50
51
|
alias select2 select2_tag
|
|
51
52
|
|
|
53
|
+
# Renders a select2 tag field for a tag list (standalone, no form object).
|
|
54
|
+
# Analogous to text_field_tag.
|
|
55
|
+
#
|
|
56
|
+
# ==== Example
|
|
57
|
+
# tag_list_field_tag 'entry[tag_list]', entry.tag_list,
|
|
58
|
+
# url: auto_complete_taggable_tags_path(taggable_type: 'DriveEntry')
|
|
59
|
+
def tag_list_field_tag(name, value = [], options = {})
|
|
60
|
+
url = options.delete(:url)
|
|
61
|
+
taggable_type = options.delete(:taggable_type)
|
|
62
|
+
width = options.delete(:width)
|
|
63
|
+
project_id = options.delete(:project_id)
|
|
64
|
+
placeholder = options.delete(:placeholder)
|
|
65
|
+
select2_tag(
|
|
66
|
+
name,
|
|
67
|
+
options_for_select(value, value),
|
|
68
|
+
{
|
|
69
|
+
multiple: true,
|
|
70
|
+
style: "width: #{width || '95%'};",
|
|
71
|
+
width: 'style',
|
|
72
|
+
url: url || auto_complete_taggable_tags_path(taggable_type: taggable_type, project_id: project_id),
|
|
73
|
+
placeholder: placeholder || l(:lable_redmineup_add_tag),
|
|
74
|
+
tags: true
|
|
75
|
+
}.merge(options)
|
|
76
|
+
)
|
|
77
|
+
end
|
|
78
|
+
|
|
52
79
|
# Transforms select filters of +type+ fields into select2
|
|
53
80
|
#
|
|
54
81
|
# ==== Examples
|
|
@@ -86,3 +113,20 @@ module Redmineup
|
|
|
86
113
|
|
|
87
114
|
end
|
|
88
115
|
end
|
|
116
|
+
|
|
117
|
+
# Extends Rails FormBuilder with tag_list_field, analogous to f.text_field.
|
|
118
|
+
#
|
|
119
|
+
# ==== Example
|
|
120
|
+
# <%= f.tag_list_field :tag_list %>
|
|
121
|
+
ActionView::Helpers::FormBuilder.class_eval do
|
|
122
|
+
def tag_list_field(method, **options)
|
|
123
|
+
url = options.fetch(:url) {
|
|
124
|
+
@template.auto_complete_taggable_tags_path(taggable_type: @object.class.name)
|
|
125
|
+
}
|
|
126
|
+
@template.tag_list_field_tag(
|
|
127
|
+
"#{@object_name}[#{method}]",
|
|
128
|
+
@object.public_send(method),
|
|
129
|
+
{url: url}.merge(options.except(:url))
|
|
130
|
+
)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
module Redmineup
|
|
2
|
+
module JournalsHelper
|
|
3
|
+
def up_journal_detail(detail, journal, options = {})
|
|
4
|
+
formatter = journal.journalized.up_journalized_options[:detail_formatter]
|
|
5
|
+
text = formatter&.call(detail, journal)
|
|
6
|
+
return text if text
|
|
7
|
+
|
|
8
|
+
label, old_value, value = up_journal_detail_values(detail, journal)
|
|
9
|
+
text =
|
|
10
|
+
if detail.old_value.blank? && detail.value.present?
|
|
11
|
+
l(:text_journal_set_to, label: label, value: value)
|
|
12
|
+
elsif detail.value.blank?
|
|
13
|
+
l(:text_journal_deleted, label: label, old: old_value)
|
|
14
|
+
else
|
|
15
|
+
l(:text_journal_changed, label: label, old: old_value, new: value)
|
|
16
|
+
end
|
|
17
|
+
options[:no_html] ? text : text.html_safe
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def up_render_journal_history(journals, show_notes: true)
|
|
21
|
+
render partial: 'redmineup/journals/history', locals: { journals: journals, show_notes: show_notes }
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def up_journal_new_markup?
|
|
25
|
+
Gem::Version.new(Redmine::VERSION.to_s) >= Gem::Version.new('6.1')
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def up_journal_detail_values(detail, journal)
|
|
31
|
+
record = journal.journalized
|
|
32
|
+
if detail.property == 'cf'
|
|
33
|
+
field = CustomField.find_by(id: detail.prop_key)
|
|
34
|
+
return [h(detail.prop_key), h(detail.old_value), h(detail.value)] unless field
|
|
35
|
+
|
|
36
|
+
format = ->(v) { v.blank? ? '' : field.format.formatted_value(self, field, v, record, false) }
|
|
37
|
+
[h(field.name), h(format.call(detail.old_value)), h(format.call(detail.value))]
|
|
38
|
+
else
|
|
39
|
+
key = detail.prop_key.to_s
|
|
40
|
+
name = key.delete_suffix('_id')
|
|
41
|
+
reflection = record.class.reflect_on_association(name) if name != key
|
|
42
|
+
format = lambda do |v|
|
|
43
|
+
next '' if v.blank?
|
|
44
|
+
next v.to_s unless reflection
|
|
45
|
+
|
|
46
|
+
target = reflection.klass.find_by(id: v)
|
|
47
|
+
target && (!target.respond_to?(:visible?) || target.visible?) ? target.to_s : v.to_s
|
|
48
|
+
end
|
|
49
|
+
[h(l("field_#{key}", default: l("field_#{name}", default: name.humanize))), h(format.call(detail.old_value)), h(format.call(detail.value))]
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|