redmine_crm 0.0.23 → 0.0.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/doc/CHANGELOG +4 -0
- data/lib/redmine_crm.rb +28 -20
- data/lib/redmine_crm/{rcrm_acts_as_taggable.rb → acts_as_taggable/rcrm_acts_as_taggable.rb} +93 -87
- data/lib/redmine_crm/acts_as_taggable/tag.rb +81 -0
- data/lib/redmine_crm/acts_as_taggable/tag_list.rb +111 -0
- data/lib/redmine_crm/acts_as_taggable/tagging.rb +16 -0
- data/lib/redmine_crm/acts_as_viewed/rcrm_acts_as_viewed.rb +274 -0
- data/lib/redmine_crm/{rcrm_acts_as_votable.rb → acts_as_votable/rcrm_acts_as_votable.rb} +8 -11
- data/lib/redmine_crm/acts_as_votable/rcrm_acts_as_voter.rb +20 -0
- data/lib/redmine_crm/{votable.rb → acts_as_votable/votable.rb} +36 -47
- data/lib/redmine_crm/{vote.rb → acts_as_votable/vote.rb} +7 -10
- data/lib/redmine_crm/{voter.rb → acts_as_votable/voter.rb} +29 -34
- data/lib/redmine_crm/currency/formatting.rb +0 -3
- data/lib/redmine_crm/currency/heuristics.rb +1 -1
- data/lib/redmine_crm/currency/loader.rb +1 -1
- data/lib/redmine_crm/helpers/tags_helper.rb +1 -3
- data/lib/redmine_crm/helpers/vote_helper.rb +29 -32
- data/lib/redmine_crm/liquid/drops/issues_drop.rb +66 -0
- data/lib/redmine_crm/liquid/drops/news_drop.rb +54 -0
- data/lib/redmine_crm/liquid/drops/projects_drop.rb +86 -0
- data/lib/redmine_crm/liquid/drops/users_drop.rb +72 -0
- data/lib/redmine_crm/liquid/filters/arrays.rb +178 -0
- data/lib/redmine_crm/liquid/filters/base.rb +208 -0
- data/lib/redmine_crm/version.rb +1 -1
- data/redmine_crm.gemspec +1 -1
- data/test/{acts_as_taggable_test.rb → acts_as_taggable/rcrm_acts_as_taggable_test.rb} +114 -151
- data/test/acts_as_taggable/tag_list_test.rb +38 -0
- data/test/acts_as_taggable/tag_test.rb +74 -0
- data/test/acts_as_taggable/tagging_test.rb +15 -0
- data/test/{viewed_test.rb → acts_as_viewed/rcrm_acts_as_viewed_test.rb} +17 -15
- data/test/{votable_test.rb → acts_as_votable/rcrm_acts_as_votable_test.rb} +3 -3
- data/test/acts_as_votable/rcrm_acts_as_voter_test.rb +12 -0
- data/test/{votable_model_test.rb → acts_as_votable/votable_test.rb} +4 -4
- data/test/{voter_model_test.rb → acts_as_votable/voter_test.rb} +7 -7
- data/test/currency_test.rb +10 -10
- data/test/fixtures/issue.rb +6 -2
- data/test/fixtures/issues.yml +13 -1
- data/test/fixtures/news.rb +3 -0
- data/test/fixtures/news.yml +8 -0
- data/test/fixtures/project.rb +8 -0
- data/test/fixtures/projects.yml +10 -0
- data/test/fixtures/user.rb +5 -1
- data/test/fixtures/users.yml +3 -2
- data/test/fixtures/vote_classes.rb +2 -3
- data/test/liquid/drops/issues_drop_test.rb +34 -0
- data/test/liquid/drops/liquid_test.rb +52 -0
- data/test/liquid/drops/news_drop_test.rb +38 -0
- data/test/liquid/drops/projects_drop_test.rb +44 -0
- data/test/liquid/drops/uses_drop_test.rb +36 -0
- data/test/liquid/filters/arrays_filter_test.rb +24 -0
- data/test/liquid/filters/base_filter_test.rb +63 -0
- data/test/liquid/liquid_helper.rb +32 -0
- data/test/money_helper_test.rb +5 -5
- data/test/schema.rb +21 -9
- data/test/test_helper.rb +26 -25
- metadata +76 -28
- data/lib/redmine_crm/rcrm_acts_as_viewed.rb +0 -287
- data/lib/redmine_crm/rcrm_acts_as_voter.rb +0 -27
- data/lib/redmine_crm/tag.rb +0 -81
- data/lib/redmine_crm/tag_list.rb +0 -112
- data/lib/redmine_crm/tagging.rb +0 -20
- data/test/tag_test.rb +0 -64
- data/test/tagging_test.rb +0 -14
@@ -1,27 +0,0 @@
|
|
1
|
-
module RedmineCrm
|
2
|
-
module ActsAsVotable
|
3
|
-
# module Extenders
|
4
|
-
|
5
|
-
module Voter
|
6
|
-
|
7
|
-
def voter?
|
8
|
-
false
|
9
|
-
end
|
10
|
-
|
11
|
-
def rcrm_acts_as_voter(*args)
|
12
|
-
# byebug
|
13
|
-
require 'redmine_crm/voter'
|
14
|
-
include ActsAsVotable::Voter
|
15
|
-
|
16
|
-
class_eval do
|
17
|
-
def self.voter?
|
18
|
-
true
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
# end
|
26
|
-
end
|
27
|
-
end
|
data/lib/redmine_crm/tag.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
module RedmineCrm
|
2
|
-
class Tag < ActiveRecord::Base
|
3
|
-
has_many :taggings, :dependent => :destroy
|
4
|
-
|
5
|
-
validates_presence_of :name
|
6
|
-
# validates_uniqueness_of :name
|
7
|
-
validates :name, :uniqueness => { :message => " not uniq tag" }
|
8
|
-
validates :name, :presence => true
|
9
|
-
cattr_accessor :destroy_unused
|
10
|
-
self.destroy_unused = false
|
11
|
-
|
12
|
-
attr_accessible :name if defined?(ActiveModel::MassAssignmentSecurity)
|
13
|
-
|
14
|
-
# LIKE is used for cross-database case-insensitivity
|
15
|
-
def self.find_or_create_with_like_by_name(name)
|
16
|
-
# find(:first, :conditions => ["name LIKE ?", name]) || create(:name => name)
|
17
|
-
where("LOWER(name) LIKE LOWER(?)", name).first || create(:name => name)
|
18
|
-
end
|
19
|
-
|
20
|
-
def ==(object)
|
21
|
-
super || (object.is_a?(Tag) && name == object.name)
|
22
|
-
end
|
23
|
-
|
24
|
-
def to_s
|
25
|
-
name
|
26
|
-
end
|
27
|
-
|
28
|
-
def count
|
29
|
-
read_attribute(:count).to_i
|
30
|
-
end
|
31
|
-
|
32
|
-
class << self
|
33
|
-
# Calculate the tag counts for all tags.
|
34
|
-
# :start_at - Restrict the tags to those created after a certain time
|
35
|
-
# :end_at - Restrict the tags to those created before a certain time
|
36
|
-
# :conditions - A piece of SQL conditions to add to the query
|
37
|
-
# :limit - The maximum number of tags to return
|
38
|
-
# :order - A piece of SQL to order by. Eg 'count desc' or 'taggings.created_at desc'
|
39
|
-
# :at_least - Exclude tags with a frequency less than the given value
|
40
|
-
# :at_most - Exclude tags with a frequency greater than the given value
|
41
|
-
def counts(options = {})
|
42
|
-
# find(:all, options_for_counts(options))
|
43
|
-
opt = options_for_counts(options)
|
44
|
-
select(opt[:select]).where(opt[:conditions]).joins(opt[:joins]).group(opt[:group])
|
45
|
-
end
|
46
|
-
|
47
|
-
def options_for_counts(options = {})
|
48
|
-
options.assert_valid_keys :start_at, :end_at, :conditions, :at_least, :at_most, :order, :limit, :joins
|
49
|
-
options = options.dup
|
50
|
-
|
51
|
-
start_at = sanitize_sql(["#{Tagging.table_name}.created_at >= ?", options.delete(:start_at)]) if options[:start_at]
|
52
|
-
end_at = sanitize_sql(["#{Tagging.table_name}.created_at <= ?", options.delete(:end_at)]) if options[:end_at]
|
53
|
-
|
54
|
-
conditions = [
|
55
|
-
(sanitize_sql(options.delete(:conditions)) if options[:conditions]),
|
56
|
-
start_at,
|
57
|
-
end_at
|
58
|
-
].compact
|
59
|
-
|
60
|
-
conditions = conditions.join(' AND ') if conditions.any?
|
61
|
-
|
62
|
-
joins = ["INNER JOIN #{Tagging.table_name} ON #{Tag.table_name}.id = #{Tagging.table_name}.tag_id"]
|
63
|
-
joins << options.delete(:joins) if options[:joins]
|
64
|
-
|
65
|
-
at_least = sanitize_sql(['COUNT(*) >= ?', options.delete(:at_least)]) if options[:at_least]
|
66
|
-
at_most = sanitize_sql(['COUNT(*) <= ?', options.delete(:at_most)]) if options[:at_most]
|
67
|
-
having = "COUNT(*) > 0"
|
68
|
-
having = [having, at_least, at_most].compact.join(' AND ')
|
69
|
-
group_by = "#{Tag.table_name}.id, #{Tag.table_name}.name"
|
70
|
-
# group_by << " AND #{having}" unless having.blank?
|
71
|
-
|
72
|
-
{ :select => "#{Tag.table_name}.id, #{Tag.table_name}.name, COUNT(*) AS count",
|
73
|
-
:joins => joins.join(" "),
|
74
|
-
:conditions => conditions,
|
75
|
-
:group => group_by,
|
76
|
-
:having => having
|
77
|
-
}.update(options)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
data/lib/redmine_crm/tag_list.rb
DELETED
@@ -1,112 +0,0 @@
|
|
1
|
-
module RedmineCrm
|
2
|
-
class TagList < Array
|
3
|
-
cattr_accessor :delimiter
|
4
|
-
self.delimiter = ','
|
5
|
-
|
6
|
-
def initialize(*args)
|
7
|
-
add(*args)
|
8
|
-
end
|
9
|
-
|
10
|
-
# Add tags to the tag_list. Duplicate or blank tags will be ignored.
|
11
|
-
#
|
12
|
-
# tag_list.add("Fun", "Happy")
|
13
|
-
#
|
14
|
-
# Use the <tt>:parse</tt> option to add an unparsed tag string.
|
15
|
-
#
|
16
|
-
# tag_list.add("Fun, Happy", :parse => true)
|
17
|
-
def add(*names)
|
18
|
-
extract_and_apply_options!(names)
|
19
|
-
concat(names)
|
20
|
-
clean!
|
21
|
-
self
|
22
|
-
end
|
23
|
-
|
24
|
-
# Remove specific tags from the tag_list.
|
25
|
-
#
|
26
|
-
# tag_list.remove("Sad", "Lonely")
|
27
|
-
#
|
28
|
-
# Like #add, the <tt>:parse</tt> option can be used to remove multiple tags in a string.
|
29
|
-
#
|
30
|
-
# tag_list.remove("Sad, Lonely", :parse => true)
|
31
|
-
def remove(*names)
|
32
|
-
extract_and_apply_options!(names)
|
33
|
-
delete_if { |name| names.include?(name) }
|
34
|
-
self
|
35
|
-
end
|
36
|
-
|
37
|
-
# Toggle the presence of the given tags.
|
38
|
-
# If a tag is already in the list it is removed, otherwise it is added.
|
39
|
-
def toggle(*names)
|
40
|
-
extract_and_apply_options!(names)
|
41
|
-
|
42
|
-
names.each do |name|
|
43
|
-
include?(name) ? delete(name) : push(name)
|
44
|
-
end
|
45
|
-
|
46
|
-
clean!
|
47
|
-
self
|
48
|
-
end
|
49
|
-
|
50
|
-
# Transform the tag_list into a tag string suitable for edting in a form.
|
51
|
-
# The tags are joined with <tt>TagList.delimiter</tt> and quoted if necessary.
|
52
|
-
#
|
53
|
-
# tag_list = TagList.new("Round", "Square,Cube")
|
54
|
-
# tag_list.to_s # 'Round, "Square,Cube"'
|
55
|
-
def to_s
|
56
|
-
clean!
|
57
|
-
|
58
|
-
map do |name|
|
59
|
-
name.include?(delimiter) ? "\"#{name}\"" : name
|
60
|
-
end.join(delimiter.ends_with?(" ") ? delimiter : "#{delimiter} ")
|
61
|
-
end
|
62
|
-
|
63
|
-
private
|
64
|
-
# Remove whitespace, duplicates, and blanks.
|
65
|
-
def clean!
|
66
|
-
reject!(&:blank?)
|
67
|
-
map!(&:strip)
|
68
|
-
uniq!
|
69
|
-
end
|
70
|
-
|
71
|
-
def extract_and_apply_options!(args)
|
72
|
-
options = args.last.is_a?(Hash) ? args.pop : {}
|
73
|
-
options.assert_valid_keys :parse
|
74
|
-
|
75
|
-
if options[:parse]
|
76
|
-
args.map! { |a| self.class.from(a) }
|
77
|
-
end
|
78
|
-
|
79
|
-
args.flatten!
|
80
|
-
end
|
81
|
-
|
82
|
-
class << self
|
83
|
-
# Returns a new TagList using the given tag string.
|
84
|
-
#
|
85
|
-
# tag_list = TagList.from("One , Two, Three")
|
86
|
-
# tag_list # ["One", "Two", "Three"]
|
87
|
-
def from(source)
|
88
|
-
tag_list = new
|
89
|
-
|
90
|
-
case source
|
91
|
-
when Array
|
92
|
-
tag_list.add(source)
|
93
|
-
else
|
94
|
-
string = source.to_s.dup
|
95
|
-
|
96
|
-
# Parse the quoted tags
|
97
|
-
[
|
98
|
-
/\s*#{delimiter}\s*(['"])(.*?)\1\s*/,
|
99
|
-
/^\s*(['"])(.*?)\1\s*#{delimiter}?/
|
100
|
-
].each do |re|
|
101
|
-
string.gsub!(re) { tag_list << $2; "" }
|
102
|
-
end
|
103
|
-
|
104
|
-
tag_list.add(string.split(delimiter))
|
105
|
-
end
|
106
|
-
|
107
|
-
tag_list
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
data/lib/redmine_crm/tagging.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
module RedmineCrm
|
2
|
-
|
3
|
-
class Tagging < ActiveRecord::Base #:nodoc:
|
4
|
-
belongs_to :tag
|
5
|
-
belongs_to :taggable, :polymorphic => true
|
6
|
-
|
7
|
-
after_destroy :destroy_tag_if_unused
|
8
|
-
|
9
|
-
private
|
10
|
-
|
11
|
-
def destroy_tag_if_unused
|
12
|
-
if Tag.destroy_unused
|
13
|
-
if tag.taggings.count.zero?
|
14
|
-
tag.destroy
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
data/test/tag_test.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
|
3
|
-
module RedmineCrm
|
4
|
-
class TagTest < ActiveSupport::TestCase
|
5
|
-
def test_name_required
|
6
|
-
t = Tag.create
|
7
|
-
assert_match /blank/, t.errors[:name].to_s
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_name_unique
|
11
|
-
t = Tag.create!(:name => "My tag")
|
12
|
-
duplicate = t.dup
|
13
|
-
assert !duplicate.save
|
14
|
-
assert_match /not uniq/, duplicate.errors[:name].to_s
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_taggings
|
18
|
-
assert_equivalent [taggings(:tag_for_error), taggings(:tag_for_error1), taggings(:tag_for_error2)
|
19
|
-
], tags(:error).taggings
|
20
|
-
assert_equivalent [taggings(:tag_for_question1), taggings(:tag_for_question2), taggings(:tag_for_question3)], tags(:question).taggings
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_to_s
|
24
|
-
assert_equal tags(:error).name, tags(:error).to_s
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_equality
|
28
|
-
assert_equal tags(:error), tags(:error)
|
29
|
-
assert_equal Tag.find(tags(:error).id), Tag.find(tags(:error).id)
|
30
|
-
assert_equal Tag.new(:name => 'A'), Tag.new(:name => 'A')
|
31
|
-
assert_not_equal Tag.new(:name => 'A'), Tag.new(:name => 'B')
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_taggings_removed_when_tag_destroyed
|
35
|
-
assert_difference("Tagging.count", -Tagging.where(:tag_id => tags(:error).id).count) do
|
36
|
-
assert tags(:error).destroy
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_all_counts
|
41
|
-
assert_tag_counts Tag.counts, :error => 3, :feature => 1, :bug => 1, :question => 3
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_all_counts_with_string_conditions
|
45
|
-
assert_tag_counts Tag.counts(:conditions => 'taggings.created_at >= \'2015-01-01\''),
|
46
|
-
:question => 3, :error => 2, :feature => 1, :bug => 1
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_all_counts_with_array_conditions
|
50
|
-
assert_tag_counts Tag.counts(:conditions => ['taggings.created_at >= ?', '2015-01-01']),
|
51
|
-
:question => 3, :error => 2, :feature => 1, :bug => 1
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_all_counts_with_hash_conditions
|
55
|
-
tag_counts = Tag.counts(
|
56
|
-
:conditions => {
|
57
|
-
:taggings => { :created_at => (DateTime.parse('2014-12-31 23:59') .. DateTime.parse('4000-01-01')) }
|
58
|
-
}
|
59
|
-
)
|
60
|
-
|
61
|
-
assert_tag_counts tag_counts, :question => 3, :error => 2, :feature => 1, :bug => 1
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
data/test/tagging_test.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/test_helper'
|
2
|
-
# require File.dirname(__FILE__) + '/fixtures/issue'
|
3
|
-
|
4
|
-
class TaggingTest < ActiveSupport::TestCase
|
5
|
-
|
6
|
-
def test_tag
|
7
|
-
assert_equal tags(:error), taggings(:tag_for_error).tag
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_taggable
|
11
|
-
assert_equal issues(:first_issue), taggings(:tag_for_error).taggable
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|