redmine_crm 0.0.21 → 0.0.22
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/README.md +12 -0
- data/doc/CHANGELOG +5 -0
- data/lib/redmine_crm/rcrm_acts_as_taggable.rb +2 -2
- data/lib/redmine_crm/rcrm_acts_as_viewed.rb +34 -18
- data/lib/redmine_crm/version.rb +1 -1
- data/test/schema.rb +1 -0
- data/test/viewed_test.rb +6 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d286086a18f1e63d34a1de9756897a3ceb444da1
|
4
|
+
data.tar.gz: 9755c778cb07f932b12e56ace0427ef9069a7125
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94070dfa1ebbff14f11bdacb788d8792e72f1d6315116ed00fdb00feda03cbca972f1c979f70655f615855788e5e829f84f7c4d8034b7b87464f99a01074dada
|
7
|
+
data.tar.gz: 3547f4981f02dd95f2f5c5e4750ccd6cc5d37d8887320bdf61a598dbb0bc8ab3e7deaa8c46377b635ecf035ae9bf3628b8048ebcaca4e16a2a8f0a1c4d4c1f58
|
data/README.md
CHANGED
@@ -34,6 +34,18 @@ Create migration with next code:
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
```
|
37
|
+
For rcrm_acts_as_viewed You may add column for your model
|
38
|
+
with help:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
|
42
|
+
YourModel.add_viewings_columns
|
43
|
+
|
44
|
+
```
|
45
|
+
It will add two column to your table (views and total_views)
|
46
|
+
and view_count will return two number: total view and unique views.
|
47
|
+
Without this migration you will get only unique views.
|
48
|
+
|
37
49
|
Run migration for plugin:
|
38
50
|
|
39
51
|
```
|
data/doc/CHANGELOG
CHANGED
@@ -3,6 +3,11 @@
|
|
3
3
|
Redmine crm gem - general functions for plugins (tags, vote, viewing, currency)
|
4
4
|
Copyright (C) 2011-2015 RedmineCRM
|
5
5
|
http://www.redminecrm.com/
|
6
|
+
|
7
|
+
== 2015-12-13 v0.0.22
|
8
|
+
|
9
|
+
* Added a count for unique views of a object.
|
10
|
+
|
6
11
|
== 2015-10-29 v0.0.21
|
7
12
|
|
8
13
|
* Added space for CHF in currency format
|
@@ -77,11 +77,11 @@ module RedmineCrm
|
|
77
77
|
|
78
78
|
def drop_taggable_table options = {}
|
79
79
|
tag_name_table = options[:tags] || :tags
|
80
|
-
if
|
80
|
+
if self.connection.table_exists?(tag_name_table)
|
81
81
|
self.connection.drop_table tag_name_table
|
82
82
|
end
|
83
83
|
taggings_name_table = options[:taggings] || :taggings
|
84
|
-
if
|
84
|
+
if self.connection.table_exists?(taggings_name_table)
|
85
85
|
self.connection.drop_table taggings_name_table
|
86
86
|
end
|
87
87
|
|
@@ -138,10 +138,22 @@ module RedmineCrm
|
|
138
138
|
# Get the number of viewings for this object based on the views field,
|
139
139
|
# or with a SQL query if the viewed objects doesn't have the views field
|
140
140
|
def view_count
|
141
|
-
return self.views || 0 if attributes.has_key? 'views'
|
141
|
+
return ("#{self.total_views}(#{self.views})" || 0) if attributes.has_key? 'views'
|
142
142
|
viewings.count
|
143
143
|
end
|
144
144
|
|
145
|
+
# Change views count (total_views and views) if it's existing in object
|
146
|
+
# If options[:only_total] == true count of unique views doesn't change
|
147
|
+
def increase_views_count(options)
|
148
|
+
if attributes.has_key?('views') && attributes.has_key?('total_views')
|
149
|
+
target = self
|
150
|
+
target.views = ( (target.views || 0) + 1 ) if !options[:only_total]
|
151
|
+
target.total_views = ( (target.total_views || 0) + 1)
|
152
|
+
target.save(:validate => false)
|
153
|
+
# target.save_without_validation
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
145
157
|
# View the object with or without a viewer - create new or update as needed
|
146
158
|
#
|
147
159
|
# * <tt>ip</tt> - the viewer ip
|
@@ -159,14 +171,12 @@ module RedmineCrm
|
|
159
171
|
view.viewer_id = viewer.id if viewer && !viewer.id.nil?
|
160
172
|
view.ip = ip
|
161
173
|
viewings << view
|
162
|
-
target = self if attributes.has_key? 'views'
|
163
|
-
target.views = ( (target.views || 0) + 1 ) if target
|
164
174
|
view.save
|
165
|
-
|
166
|
-
return true
|
175
|
+
increase_views_count(:only_total => false)
|
167
176
|
else
|
168
|
-
|
177
|
+
increase_views_count(:only_total => true)
|
169
178
|
end
|
179
|
+
true
|
170
180
|
end
|
171
181
|
end
|
172
182
|
|
@@ -199,7 +209,8 @@ module RedmineCrm
|
|
199
209
|
# new tables as it will make it as part of the table creation, and not generate
|
200
210
|
# ALTER TABLE calls after the fact
|
201
211
|
def generate_viewings_columns table
|
202
|
-
table.column :views, :integer
|
212
|
+
table.column :views, :integer #uniq views
|
213
|
+
table.column :total_views, :integer
|
203
214
|
end
|
204
215
|
|
205
216
|
# Create the needed columns for acts_as_viewed.
|
@@ -207,6 +218,7 @@ module RedmineCrm
|
|
207
218
|
def add_viewings_columns
|
208
219
|
if !self.content_columns.find { |c| 'views' == c.name }
|
209
220
|
self.connection.add_column table_name, :views, :integer, :default => '0'
|
221
|
+
self.connection.add_column table_name, :total_views, :integer, :default => '0'
|
210
222
|
self.reset_column_information
|
211
223
|
end
|
212
224
|
end
|
@@ -216,6 +228,7 @@ module RedmineCrm
|
|
216
228
|
def remove_viewings_columns
|
217
229
|
if self.content_columns.find { |c| 'views' == c.name }
|
218
230
|
self.connection.remove_column table_name, :views
|
231
|
+
self.connection.remove_column table_name, :total_views
|
219
232
|
self.reset_column_information
|
220
233
|
end
|
221
234
|
end
|
@@ -226,17 +239,18 @@ module RedmineCrm
|
|
226
239
|
# To be used during migration, but can also be used in other places
|
227
240
|
def create_viewings_table options = {}
|
228
241
|
name = options[:table_name] || :viewings
|
229
|
-
self.connection.
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
self.connection.add_index name, :viewer_id
|
238
|
-
self.connection.add_index name, [:viewed_type, :viewed_id]
|
242
|
+
if !self.connection.table_exists?(name)
|
243
|
+
self.connection.create_table(name) do |t|
|
244
|
+
t.column :viewer_id, :integer
|
245
|
+
t.column :viewed_id, :integer
|
246
|
+
t.column :viewed_type, :string
|
247
|
+
t.column :ip, :string, :limit => '24'
|
248
|
+
t.column :created_at, :datetime
|
249
|
+
end
|
239
250
|
|
251
|
+
self.connection.add_index(name, :viewer_id)
|
252
|
+
self.connection.add_index(name, [:viewed_type, :viewed_id])
|
253
|
+
end
|
240
254
|
end
|
241
255
|
|
242
256
|
# Drop the viewings table.
|
@@ -245,7 +259,9 @@ module RedmineCrm
|
|
245
259
|
# To be used during migration, but can also be used in other places
|
246
260
|
def drop_viewings_table options = {}
|
247
261
|
name = options[:table_name] || :viewings
|
248
|
-
self.connection.
|
262
|
+
if self.connection.table_exists?(name)
|
263
|
+
self.connection.drop_table(name)
|
264
|
+
end
|
249
265
|
end
|
250
266
|
|
251
267
|
# Find all viewings for a specific viewer.
|
data/lib/redmine_crm/version.rb
CHANGED
data/test/schema.rb
CHANGED
@@ -22,6 +22,7 @@ ActiveRecord::Schema.define :version => 0 do
|
|
22
22
|
t.column "cached_tag_list", :string
|
23
23
|
t.column "user_id", :integer
|
24
24
|
t.column "views", :integer, :default => 0
|
25
|
+
t.column "total_views", :integer, :default => 0
|
25
26
|
end
|
26
27
|
|
27
28
|
create_table "votes", :force => true do |t|
|
data/test/viewed_test.rb
CHANGED
@@ -12,12 +12,15 @@ class ViewedTest < ActiveSupport::TestCase
|
|
12
12
|
|
13
13
|
|
14
14
|
def test_zero_of_view_count
|
15
|
-
assert_equal issue.view_count, 0
|
15
|
+
assert_equal issue.view_count, "0(0)"
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_can_view
|
19
19
|
issue.view '127.0.0.1', user
|
20
|
-
assert_equal issue.view_count, 1
|
20
|
+
assert_equal issue.view_count, "1(1)"
|
21
|
+
# second view change only total count
|
22
|
+
issue.view '127.0.0.1', user
|
23
|
+
assert_equal issue.view_count, "2(1)"
|
21
24
|
end
|
22
25
|
|
23
26
|
def test_viewed_by
|
@@ -29,7 +32,7 @@ class ViewedTest < ActiveSupport::TestCase
|
|
29
32
|
def test_twice_view
|
30
33
|
issue.view '127.0.0.1', user
|
31
34
|
issue.view '127.0.0.1', user
|
32
|
-
assert_equal issue.view_count
|
35
|
+
assert_equal "2(1)", issue.view_count
|
33
36
|
end
|
34
37
|
|
35
38
|
def test_viewed?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redmine_crm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- RedmineCRM
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Common libraries for RedmineCRM plugins for Redmine. Requered Redmine
|
14
14
|
from http://redmine.org
|